2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc / execute / load-3.m
blobe7543930a73ac5a043638c20d06889110947c67f
1 /*
2     load-3.m
4     Author: Ovidiu Predescu <ovidiu@cup.hp.com>
5     Date: June  3, 2001
7     Test if the +load methods are invoked, and are invoked in the
8     proper order.
9  */
11 #include <objc/objc.h>
12 #include <objc/Object.h>
14 @interface A : Object
15 @end
17 @interface B : A
18 @end
20 static a_load = 0;
21 static b_load = 0;
22 static a_category_load = 0;
23 static b_category_load = 0;
25 @implementation A (Category)
26 + (void)load
28   a_category_load = 1;
29   printf("+[A(Category) load]\n");
31   if (a_load != 1)
32     {
33       printf("+load for A(Category) invoked before A's!\n");
34       abort();
35     }
37 @end
39 @implementation B(Category)
40 + (void)load
42   b_category_load = 1;
43   printf("+[B(Category) load]\n");
45   if (b_load != 1)
46     {
47       printf ("+load for B(Category) invoked before B!\n");
48       abort();
49     }
51 @end
53 @implementation B
54 + (void)load
56   b_load = 1;
57   printf("+[B load]\n");
59   if (a_load != 1)
60     {
61       printf("+load for B invoked before A's!\n");
62       abort();
63     }
65   if (b_category_load != 0)
66     {
67       printf("+load for B invoked after B(Category)!\n");
68       abort();
69     }
71 @end
73 @implementation A
74 + (void)load
76   a_load = 1;
77   printf("+[A load]\n");
79   if (a_category_load != 0)
80     {
81       printf("+load for A(Category) invoked before A!\n");
82       abort();
83     }
85   if (b_load != 0)
86     {
87       printf("+load for A invoked after B!\n");
88       abort();
89     }
91   if (b_category_load != 0)
92     {
93       printf("+load for B(Category) invoked before A and B!\n");
94       abort();
95     }
97 @end
99 int main (void)
101   if (a_load + b_load + a_category_load + b_category_load != 4)
102     {
103       printf("Not all +load methods invoked!\n");
104       abort();
105     }
107   return 0;