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
10#include "../../../objc-obj-c++-shared/objc-test-suite-types.h"
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16@interface Foo {
17  void *dummy_class_ref;
18  char *cString;
19  unsigned int len;
20}
21+ initialize;
22- (char *)customString;
23@end
24
25TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT.  */
26
27@implementation Foo
28+ initialize {return self;}
29- (char *)customString {
30  return cString;
31}
32@end
33
34int main () {
35  Foo *string = @"bla";
36  Foo *string2 = @"bla";
37
38  if(string != string2)
39    abort();
40  printf("Strings are being uniqued properly\n");
41
42#ifdef __NEXT_RUNTIME__
43  /* This memcpy has to be done before the first message is sent to a
44     constant string object. Can't be moved to +initialize since _that_
45     is already a message. */
46
47  memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
48#endif
49
50  if (strcmp ([string customString], "bla")) {
51    abort ();
52  }
53
54  printf([@"This is a working constant string object\n" customString]);
55  return 0;
56}
57
58