OSDN Git Service

CFStrings for Darwin.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / torture / strings / const-str-3.mm
1 /* Test the -fconstant-string-class=Foo option under the NeXT
2    runtime.  */
3 /* Developed by Markus Hitter <mah@jump-ing.de>.  */
4
5 /* { dg-do run { target *-*-darwin* } } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7 /* { dg-options "-fconstant-string-class=Foo" } */
8 /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
9 /* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
10
11 #import "../../../objc-obj-c++-shared/Object1.h"
12 #import "../../../objc-obj-c++-shared/next-mapping.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <memory.h>
16 #include <objc/objc.h>
17 #ifndef __NEXT_RUNTIME__
18 #include <objc/objc-api.h>
19 #endif
20
21 @interface Foo: Object {
22   char *cString;
23   unsigned int len;
24 }
25 - (char *)customString;
26 @end
27
28 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
29 struct fudge_objc_class _FooClassReference;
30 #else
31 struct objc_class _FooClassReference;
32 #endif
33
34 @implementation Foo : Object
35 - (char *)customString {
36   return cString;
37 }
38 @end
39
40 int main () {
41   Foo *string = @"bla";
42   Foo *string2 = @"bla";
43
44   if(string != string2)
45     abort();
46   printf("Strings are being uniqued properly\n");
47
48   /* This memcpy has to be done before the first message is sent to a
49      constant string object. Can't be moved to +initialize since _that_
50      is already a message. */
51
52   memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference));
53   if (strcmp ([string customString], "bla")) {
54     abort ();
55   }
56
57   printf([@"This is a working constant string object\n" customString]);
58   return 0;
59 }
60