2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / testsuite / objc.dg / const-str-3.m
blob7d4f80863d28d0bc64b074cc380c1c934c620b2e
1 /* Test the -fconstant-string-class=Foo option under the NeXT
2    runtime.  */
3 /* Developed by Markus Hitter <mah@jump-ing.de>.  */
5 /* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
6 /* { dg-do run { target *-*-darwin* } } */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <memory.h>
11 #include <objc/objc.h>
12 #include <objc/Object.h>
14 @interface Foo: Object {
15   char *cString;
16   unsigned int len;
18 - (char *)customString;
19 @end
21 struct objc_class _FooClassReference;
23 @implementation Foo : Object
24 - (char *)customString {
25   return cString;
27 @end
29 int main () {
30   Foo *string = @"bla";
31   Foo *string2 = @"bla";
33   if(string != string2)
34     abort();
35   printf("Strings are being uniqued properly\n");
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. */
41   memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
42   if (strcmp ([string customString], "bla")) {
43     abort ();
44   }
46   printf([@"This is a working constant string object\n" customString]);
47   return 0;