Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / obj-c++.dg / strings / strings-2.mm
blob09d7a7f1f3205d6cba490652a15d972b7aca6c2d
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
3 /* { dg-do run } */
4 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* { dg-options "-fconstant-string-class=MyTestString" } */
6 /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */
8 /* { dg-additional-sources "../../objc-obj-c++-shared/Object1.mm" } */
10 #include "../../objc-obj-c++-shared/Object1.h"
11 #include "../../objc-obj-c++-shared/next-mapping.h"
13 #include <stdlib.h> /* For abort() */
15 @interface MyTestString : Object
17   char *string;
18   unsigned int len;
20 /* All strings should contain the C string 'test'.  Call -check to
21    test that this is true.  */
22 - (void) check;
23 @end
25 @implementation MyTestString
26 - (void) check
28   if (len != 4 || string[0] != 't' || string[1] != 'e'
29       || string[2] != 's' || string[3] != 't' || string[4] != '\0')
30     abort ();
32 @end
34 #ifdef __NEXT_RUNTIME__
35 #  ifdef NEXT_OBJC_USE_NEW_INTERFACE
36 struct fudge_objc_class _MyTestStringClassReference;
37 #  else
38 struct objc_class _MyTestStringClassReference;
39 #  endif
40 #endif
42 int main (void)
44   MyTestString *test_valid1 = @"test";
45   MyTestString *test_valid2 = @"te" @"st";
46   MyTestString *test_valid3 = @"te" @"s" @"t";
47   MyTestString *test_valid4 = @ "t" @ "e" @ "s" @ "t";
48   MyTestString *test_valid5 = @ "t" "e" "s" "t";
49   MyTestString *test_valid6 = @ "t" "e" "s" @ "t";
51   [test_valid1 check];
52   [test_valid2 check];
53   [test_valid3 check];
54   [test_valid4 check];
55   [test_valid5 check];
56   [test_valid6 check];
58   return 0;
61 #ifdef __NEXT_RUNTIME__
62 /* The MyTestString metaclass will need to be initialized before we can
63    send messages to strings.  */
65 void testsuite_mytest_string_init (void) __attribute__((constructor));
66 void testsuite_mytest_string_init (void) {
67   memcpy (&_MyTestStringClassReference,
68           objc_getClass ("MyTestString"),
69           sizeof (_MyTestStringClassReference));
71 #endif