const-str-[1-9].mm: New tests.
authorZiemowit Laski <zlaski@apple.com>
Tue, 21 Jun 2005 21:13:46 +0000 (21:13 +0000)
committerZiemowit Laski <zlaski@gcc.gnu.org>
Tue, 21 Jun 2005 21:13:46 +0000 (21:13 +0000)
[gcc/testsuite/ChangeLog]
2005-06-21  Ziemowit Laski  <zlaski@apple.com>

        * obj-c++.dg/const-str-[1-9].mm: New tests.

From-SVN: r101237

gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/const-str-1.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-2.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-3.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-4.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-5.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-6.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-7.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-8.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/const-str-9.mm [new file with mode: 0644]

index 293bb29dbba2a5adb4c2d751940f74cbdd09fab8..bef45eba983a2247fdb87c5114113bc34164c9de 100644 (file)
@@ -1,3 +1,7 @@
+2005-06-21  Ziemowit Laski  <zlaski@apple.com>
+
+       * obj-c++.dg/const-str-[1-9].mm: New tests.
+
 2005-06-21  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/22010
diff --git a/gcc/testsuite/obj-c++.dg/const-str-1.mm b/gcc/testsuite/obj-c++.dg/const-str-1.mm
new file mode 100644 (file)
index 0000000..e4cac2e
--- /dev/null
@@ -0,0 +1,25 @@
+/* Test errors for constant strings.  */
+/* { dg-do compile } */
+/* { dg-options "-fgnu-runtime" } */
+
+#ifdef __cplusplus
+extern void baz(...);
+#endif
+
+void foo()
+{
+  baz(@"hiya");  /* { dg-error "annot find interface declaration" } */
+}
+
+@interface NXConstantString
+{
+  void *isa;
+  char *str;
+  int len;
+}
+@end
+
+void bar()
+{
+  baz(@"howdah");
+}
diff --git a/gcc/testsuite/obj-c++.dg/const-str-2.mm b/gcc/testsuite/obj-c++.dg/const-str-2.mm
new file mode 100644 (file)
index 0000000..c406665
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test the -fconstant-string-class flag error.  */
+/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=" } */
+
+{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 }
+
+void foo () {}
diff --git a/gcc/testsuite/obj-c++.dg/const-str-3.mm b/gcc/testsuite/obj-c++.dg/const-str-3.mm
new file mode 100644 (file)
index 0000000..7d4f808
--- /dev/null
@@ -0,0 +1,48 @@
+/* Test the -fconstant-string-class=Foo option under the NeXT
+   runtime.  */
+/* Developed by Markus Hitter <mah@jump-ing.de>.  */
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
+- (char *)customString;
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Foo : Object
+- (char *)customString {
+  return cString;
+}
+@end
+
+int main () {
+  Foo *string = @"bla";
+  Foo *string2 = @"bla";
+
+  if(string != string2)
+    abort();
+  printf("Strings are being uniqued properly\n");
+
+  /* This memcpy has to be done before the first message is sent to a
+     constant string object. Can't be moved to +initialize since _that_
+     is already a message. */
+
+  memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
+  if (strcmp ([string customString], "bla")) {
+    abort ();
+  }
+
+  printf([@"This is a working constant string object\n" customString]);
+  return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/const-str-4.mm b/gcc/testsuite/obj-c++.dg/const-str-4.mm
new file mode 100644 (file)
index 0000000..df53c23
--- /dev/null
@@ -0,0 +1,31 @@
+/* Ensure that the preprocessor handles ObjC string constants gracefully. */
+/* Author: Ziemowit Laski <zlaski@apple.com> */
+/* { dg-options "-fnext-runtime -fconstant-string-class=MyString -lobjc" } */ 
+/* { dg-do run { target *-*-darwin* } } */
+
+extern "C" void abort(void);
+
+@interface MyString
+{
+  void *isa;
+  char *str;
+  int len;
+}
+@end
+
+#define kMyStringMacro1 "My String"
+#define kMyStringMacro2 @"My String"
+
+void *_MyStringClassReference;
+
+@implementation MyString
+@end
+
+int main(void) {
+  MyString* aString1 = @kMyStringMacro1;
+  MyString* aString2 = kMyStringMacro2;
+  if(aString1 != aString2) {
+    abort();
+  }
+  return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/const-str-5.mm b/gcc/testsuite/obj-c++.dg/const-str-5.mm
new file mode 100644 (file)
index 0000000..186edcf
--- /dev/null
@@ -0,0 +1,27 @@
+/* Positive test case for constant string layout.  */
+/* Contributed by Ziemowit Laski  <zlaski@apple.com>.  */
+
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-do compile } */
+
+@interface MyBase {
+  const char *p;
+}
+@end
+
+@interface MyConstantString: MyBase {
+  union {
+    void     *u;
+    unsigned char   *c;
+  } _contents;
+  unsigned int  _count;
+}
+@end
+
+/* The NeXT runtime initializes the 'isa' pointer of string constants at
+   compile time.  */
+#ifdef __NEXT_RUNTIME__
+extern void *_MyConstantStringClassReference;
+#endif
+
+MyConstantString *str = @"Hello";
diff --git a/gcc/testsuite/obj-c++.dg/const-str-6.mm b/gcc/testsuite/obj-c++.dg/const-str-6.mm
new file mode 100644 (file)
index 0000000..a7cbbf7
--- /dev/null
@@ -0,0 +1,27 @@
+/* Negative test case for constant string layout.  */
+/* Contributed by Ziemowit Laski  <zlaski@apple.com>.  */
+
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-do compile } */
+
+@interface MyBase {
+  char p;
+}
+@end
+
+@interface MyConstantString: MyBase {
+  union {
+    void     *u;
+    unsigned char   *c;
+  } _contents;
+  char  _count;
+}
+@end
+
+/* The NeXT runtime initializes the 'isa' pointer of string constants at
+   compile time.  */
+#ifdef __NEXT_RUNTIME__
+extern void *_MyConstantStringClassReference;
+#endif
+
+MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */
diff --git a/gcc/testsuite/obj-c++.dg/const-str-7.mm b/gcc/testsuite/obj-c++.dg/const-str-7.mm
new file mode 100644 (file)
index 0000000..3691579
--- /dev/null
@@ -0,0 +1,46 @@
+/* Test to make sure that the const objc strings are the same across
+   scopes.  */
+/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */
+
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
+- (char *)customString;
+@end
+
+struct objc_class _FooClassReference;
+
+
+@implementation Foo : Object
+- (char *)customString {
+  return cString;
+}
+@end
+
+
+int main () {
+  Foo *string = @"bla";
+  {
+    Foo *string2 = @"bla";
+
+
+    if(string != string2)
+      abort();
+    printf("Strings are being uniqued properly\n");
+   }
+  return 0;
+}
+
diff --git a/gcc/testsuite/obj-c++.dg/const-str-8.mm b/gcc/testsuite/obj-c++.dg/const-str-8.mm
new file mode 100644 (file)
index 0000000..60abcbd
--- /dev/null
@@ -0,0 +1,39 @@
+/* Test for assigning compile-time constant-string objects to static variables.  */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>  */
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdlib.h>
+#include <objc/Object.h>
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Foo : Object
+- (char *)customString {
+  return cString;
+}
+@end
+
+static const Foo *appKey = @"MyApp";
+static int CFPreferencesSynchronize (const Foo *ref) {
+  return ref == appKey;
+}
+
+static void PrefsSynchronize(void)
+{
+  if(!CFPreferencesSynchronize(appKey))
+    abort();
+}
+
+int main () {
+  PrefsSynchronize();
+  return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/const-str-9.mm b/gcc/testsuite/obj-c++.dg/const-str-9.mm
new file mode 100644 (file)
index 0000000..97d49e9
--- /dev/null
@@ -0,0 +1,20 @@
+/* Test if ObjC constant strings get placed in the correct section.  */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>  */
+
+/* { dg-options "-fnext-runtime" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+#include <objc/Object.h>
+
+@interface NSConstantString: Object {
+  char *cString;
+  unsigned int len;
+}
+@end
+
+extern struct objc_class _NSConstantStringClassReference;
+
+const NSConstantString *appKey = @"MyApp";
+
+/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */
+/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */