OSDN Git Service

2010-11-29 Richard Henderson <rth@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / strings-2.mm
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, 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 /* { dg-additional-sources "../objc-obj-c++-shared/Object1.mm" } */
9
10 #include "../objc-obj-c++-shared/Object1.h"
11 #include "../objc-obj-c++-shared/next-mapping.h"
12
13 #include <stdlib.h> /* For abort() */
14
15 @interface MyTestString : Object
16 {
17   char *string;
18   unsigned int len;
19 }
20 /* All strings should contain the C string 'test'.  Call -check to
21    test that this is true.  */
22 - (void) check;
23 @end
24
25 @implementation MyTestString
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 int main (void)
35 {
36   MyTestString *test_valid1 = @"test";
37   MyTestString *test_valid2 = @"te" @"st";
38   MyTestString *test_valid3 = @"te" @"s" @"t";
39   MyTestString *test_valid4 = @ "t" @ "e" @ "s" @ "t";
40   MyTestString *test_valid5 = @ "t" "e" "s" "t";
41   MyTestString *test_valid6 = @ "t" "e" "s" @ "t";
42
43   [test_valid1 check];
44   [test_valid2 check];
45   [test_valid3 check];
46   [test_valid4 check];
47   [test_valid5 check];
48   [test_valid6 check];
49
50   return 0;
51 }