2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / objc / execute / load-3.m
blobd27b3c97c69bb098c9e6ee8fe28bfbcbe8cc7c47
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 <stdlib.h>
12 #include "../../objc-obj-c++-shared/TestsuiteObject.m"
13 #include <objc/objc.h>
15 @interface A : TestsuiteObject
16 @end
18 @interface B : A
19 @end
21 static a_load = 0;
22 static b_load = 0;
23 static a_category_load = 0;
24 static b_category_load = 0;
26 @implementation A (Category)
27 + (void)load
29   a_category_load = 1;
30   printf("+[A(Category) load]\n");
32   if (a_load != 1)
33     {
34       printf("+load for A(Category) invoked before A's!\n");
35       abort();
36     }
38 @end
40 @implementation B(Category)
41 + (void)load
43   b_category_load = 1;
44   printf("+[B(Category) load]\n");
46   if (b_load != 1)
47     {
48       printf ("+load for B(Category) invoked before B!\n");
49       abort();
50     }
52 @end
54 @implementation B
55 + (void)load
57   b_load = 1;
58   printf("+[B load]\n");
60   if (a_load != 1)
61     {
62       printf("+load for B invoked before A's!\n");
63       abort();
64     }
66   if (b_category_load != 0)
67     {
68       printf("+load for B invoked after B(Category)!\n");
69       abort();
70     }
72 @end
74 @implementation A
75 + (void)load
77   a_load = 1;
78   printf("+[A load]\n");
80   if (a_category_load != 0)
81     {
82       printf("+load for A(Category) invoked before A!\n");
83       abort();
84     }
86   if (b_load != 0)
87     {
88       printf("+load for A invoked after B!\n");
89       abort();
90     }
92   if (b_category_load != 0)
93     {
94       printf("+load for B(Category) invoked before A and B!\n");
95       abort();
96     }
98 @end
100 int main (void)
102   if (a_load + b_load + a_category_load + b_category_load != 4)
103     {
104       printf("Not all +load methods invoked!\n");
105       abort();
106     }
108   return 0;