OSDN Git Service

2006-01-16 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / const-str-3.m
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-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
6 /* { dg-do run { target *-*-darwin* } } */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <memory.h>
11 #include <objc/objc.h>
12 #include <objc/Object.h>
13
14 @interface Foo: Object {
15   char *cString;
16   unsigned int len;
17 }
18 - (char *)customString;
19 @end
20
21 struct objc_class _FooClassReference;
22
23 @implementation Foo : Object
24 - (char *)customString {
25   return cString;
26 }
27 @end
28
29 int main () {
30   Foo *string = @"bla";
31   Foo *string2 = @"bla";
32
33   if(string != string2)
34     abort();
35   printf("Strings are being uniqued properly\n");
36
37   /* This memcpy has to be done before the first message is sent to a
38      constant string object. Can't be moved to +initialize since _that_
39      is already a message. */
40
41   memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
42   if (strcmp ([string customString], "bla")) {
43     abort ();
44   }
45
46   printf([@"This is a working constant string object\n" customString]);
47   return 0;
48 }