| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
|
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 5 |
/* { dg-options "-fconstant-string-class=MyTestString" } */ |
| 6 |
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ |
| 7 |
|
| 8 |
#include "../../objc-obj-c++-shared/objc-test-suite-types.h" |
| 9 |
|
| 10 |
#include <stdlib.h> /* For abort() */ |
| 11 |
|
| 12 |
@interface MyTestString |
| 13 |
{ |
| 14 |
void *dummy_class_ptr; |
| 15 |
char *string; |
| 16 |
unsigned int len; |
| 17 |
} |
| 18 |
+ initialize; |
| 19 |
/* All strings should contain the C string 'test'. Call -check to |
| 20 |
test that this is true. */ |
| 21 |
- (void) check; |
| 22 |
@end |
| 23 |
|
| 24 |
@implementation MyTestString |
| 25 |
+ initialize {return self;} |
| 26 |
- (void) check |
| 27 |
{ |
| 28 |
if (len != 4 || string[0] != 't' || string[1] != 'e' |
| 29 |
|| string[2] != 's' || string[3] != 't' || string[4] != '\0') |
| 30 |
abort (); |
| 31 |
} |
| 32 |
@end |
| 33 |
|
| 34 |
TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ |
| 35 |
|
| 36 |
int main (void) |
| 37 |
{ |
| 38 |
MyTestString *test_valid1 = @"test"; |
| 39 |
MyTestString *test_valid2 = @"te" @"st"; |
| 40 |
MyTestString *test_valid3 = @"te" @"s" @"t"; |
| 41 |
MyTestString *test_valid4 = @ "t" @ "e" @ "s" @ "t"; |
| 42 |
MyTestString *test_valid5 = @ "t" "e" "s" "t"; |
| 43 |
MyTestString *test_valid6 = @ "t" "e" "s" @ "t"; |
| 44 |
|
| 45 |
[test_valid1 check]; |
| 46 |
[test_valid2 check]; |
| 47 |
[test_valid3 check]; |
| 48 |
[test_valid4 check]; |
| 49 |
[test_valid5 check]; |
| 50 |
[test_valid6 check]; |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
#ifdef __NEXT_RUNTIME__ |
| 56 |
#include <string.h> |
| 57 |
/* The MyTestString metaclass will need to be initialized before we can |
| 58 |
send messages to strings. */ |
| 59 |
|
| 60 |
void testsuite_mytest_string_init (void) __attribute__((constructor)); |
| 61 |
void testsuite_mytest_string_init (void) { |
| 62 |
memcpy (&_MyTestStringClassReference, |
| 63 |
objc_getClass ("MyTestString"), |
| 64 |
sizeof (_MyTestStringClassReference)); |
| 65 |
} |
| 66 |
#endif |