OSDN Git Service

In gcc/objc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / category-1.m
1 /* Test class methods inside categories.  */
2 /* Author: Ziemowit Laski <zlaski@apple.com>.  */
3
4 /* { dg-do run } */
5 /* { dg-xfail-run-if "need OBJC2 ABI" { *-*-darwin* && { lp64 &&  { ! objc2 } } } { "-fnext-runtime" } { "" } } */
6
7 #include "../objc-obj-c++-shared/Object1.h"
8 extern int strcmp(const char *s1, const char *s2);
9 extern void abort(void);
10
11 #ifdef __NEXT_RUNTIME__
12 #define SUPERCLASS superclass
13 #else
14 #define SUPERCLASS superClass
15 #endif
16
17 #define CHECK_IF(expr) if(!(expr)) abort()
18
19 @interface MyObject: Object
20 + (Class)whatever1;
21 @end
22
23 @implementation MyObject
24 + (Class)whatever1 { return [super SUPERCLASS]; }
25 @end
26
27 @interface MyObject (ThisWontCompile)
28 +(Class)whatever2;
29 @end
30  
31 @implementation MyObject (ThisWontCompile)
32 +(Class)whatever2 { return [super SUPERCLASS]; }
33 @end
34
35 int main (int argc, const char * argv[])
36 {
37   Class w1 = [MyObject whatever1];
38   Class w2 = [MyObject whatever2];
39
40 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
41   CHECK_IF(!strcmp( object_getClassName( w1 ), "Object"));
42   CHECK_IF(!strcmp( object_getClassName( w2 ), "Object"));
43 #else
44   CHECK_IF(!strcmp(w1->name, "Object"));
45   CHECK_IF(!strcmp(w2->name, "Object"));
46 #endif
47
48   return 0;
49 }
50
51 #include "../objc-obj-c++-shared/Object1-implementation.h"