In gcc/testsuite/: 2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com>
[gcc.git] / gcc / testsuite / obj-c++.dg / 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-options "-fconstant-string-class=Foo" } */
6 /* { dg-do run { target *-*-darwin* } } */
7 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8
9 #import "../objc-obj-c++-shared/Object1.h"
10 #import "../objc-obj-c++-shared/next-mapping.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <memory.h>
14 #include <objc/objc.h>
15 #ifndef __NEXT_RUNTIME__
16 #include <objc/objc-api.h>
17 #endif
18
19 @interface Foo: Object {
20 char *cString;
21 unsigned int len;
22 }
23 - (char *)customString;
24 @end
25
26 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
27 struct fudge_objc_class _FooClassReference;
28 #else
29 struct objc_class _FooClassReference;
30 #endif
31
32 @implementation Foo : Object
33 - (char *)customString {
34 return cString;
35 }
36 @end
37
38 int main () {
39 Foo *string = @"bla";
40 Foo *string2 = @"bla";
41
42 if(string != string2)
43 abort();
44 printf("Strings are being uniqued properly\n");
45
46 /* This memcpy has to be done before the first message is sent to a
47 constant string object. Can't be moved to +initialize since _that_
48 is already a message. */
49
50 memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference));
51 if (strcmp ([string customString], "bla")) {
52 abort ();
53 }
54
55 printf([@"This is a working constant string object\n" customString]);
56 return 0;
57 }
58 #include "../objc-obj-c++-shared/Object1-implementation.h"