diff options
author | Ziemowit Laski <zlaski@apple.com> | 2005-06-21 21:13:46 +0000 |
---|---|---|
committer | Ziemowit Laski <zlaski@gcc.gnu.org> | 2005-06-21 21:13:46 +0000 |
commit | 01277dc46a55d9695702d0008ddcd9eb8e193fec (patch) | |
tree | 61c56dde40a34c1ff009e67f112f753eeea2695c /gcc | |
parent | 3a32ec1e37259c70a481e001a2965d42df8adaea (diff) | |
download | gcc-01277dc46a55d9695702d0008ddcd9eb8e193fec.zip gcc-01277dc46a55d9695702d0008ddcd9eb8e193fec.tar.gz gcc-01277dc46a55d9695702d0008ddcd9eb8e193fec.tar.bz2 |
const-str-[1-9].mm: New tests.
[gcc/testsuite/ChangeLog]
2005-06-21 Ziemowit Laski <zlaski@apple.com>
* obj-c++.dg/const-str-[1-9].mm: New tests.
From-SVN: r101237
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-1.mm | 25 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-2.mm | 7 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-3.mm | 48 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-4.mm | 31 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-5.mm | 27 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-6.mm | 27 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-7.mm | 46 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-8.mm | 39 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-9.mm | 20 |
10 files changed, 274 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 293bb29..bef45eb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..e4cac2e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-1.mm @@ -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 index 0000000..c406665 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-2.mm @@ -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 index 0000000..7d4f808 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-3.mm @@ -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 index 0000000..df53c23 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-4.mm @@ -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 index 0000000..186edcf --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-5.mm @@ -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 index 0000000..a7cbbf7 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-6.mm @@ -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 index 0000000..3691579 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-7.mm @@ -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 index 0000000..60abcbd --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-8.mm @@ -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 index 0000000..97d49e9 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-9.mm @@ -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" } } */ |