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
This commit is contained in:
parent
3a32ec1e37
commit
01277dc46a
10 changed files with 274 additions and 0 deletions
|
@ -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
|
||||
|
|
25
gcc/testsuite/obj-c++.dg/const-str-1.mm
Normal file
25
gcc/testsuite/obj-c++.dg/const-str-1.mm
Normal file
|
@ -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");
|
||||
}
|
7
gcc/testsuite/obj-c++.dg/const-str-2.mm
Normal file
7
gcc/testsuite/obj-c++.dg/const-str-2.mm
Normal file
|
@ -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 () {}
|
48
gcc/testsuite/obj-c++.dg/const-str-3.mm
Normal file
48
gcc/testsuite/obj-c++.dg/const-str-3.mm
Normal file
|
@ -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;
|
||||
}
|
31
gcc/testsuite/obj-c++.dg/const-str-4.mm
Normal file
31
gcc/testsuite/obj-c++.dg/const-str-4.mm
Normal file
|
@ -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;
|
||||
}
|
27
gcc/testsuite/obj-c++.dg/const-str-5.mm
Normal file
27
gcc/testsuite/obj-c++.dg/const-str-5.mm
Normal file
|
@ -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";
|
27
gcc/testsuite/obj-c++.dg/const-str-6.mm
Normal file
27
gcc/testsuite/obj-c++.dg/const-str-6.mm
Normal file
|
@ -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" } */
|
46
gcc/testsuite/obj-c++.dg/const-str-7.mm
Normal file
46
gcc/testsuite/obj-c++.dg/const-str-7.mm
Normal file
|
@ -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;
|
||||
}
|
||||
|
39
gcc/testsuite/obj-c++.dg/const-str-8.mm
Normal file
39
gcc/testsuite/obj-c++.dg/const-str-8.mm
Normal file
|
@ -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;
|
||||
}
|
20
gcc/testsuite/obj-c++.dg/const-str-9.mm
Normal file
20
gcc/testsuite/obj-c++.dg/const-str-9.mm
Normal file
|
@ -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" } } */
|
Loading…
Add table
Reference in a new issue