Daily bump.
[official-gcc.git] / gcc / testsuite / objc.dg / special / load-category-2.m
blob7dc74595206e81a7fd23ad12dd90c46930a6608d
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <objc/objc.h>
9 #include "load-category-2.h"
11 /* This test tests that +load is called in the correct order for
12    classes and categories.  +load needs to be called in superclasses
13    before subclasses, and in the main class before categories.  */
15 /* Compile the classes in random order to prevent the runtime from
16    sending +load in the correct order just because the classes happen
17    to have been compiled in that order.  */
18 @implementation TestClass2
19 + load
21   printf ("[TestClass2 +load]\n");
22   /* Check superclasses/subclasses +load order.  */
23   check_that_load_step_was_completed (0);
24   check_that_load_step_was_not_completed (1);
25   check_that_load_step_was_not_completed (2);
27   /* Check that the corresponding category's +load was not done.  */
28   check_that_load_step_was_not_completed (4);
30   complete_load_step (1);
32 @end
34 @implementation TestClass3
35 + load
37   printf ("[TestClass3 +load]\n");
39   /* Check superclasses/subclasses +load order.  */
40   check_that_load_step_was_completed (0);
41   check_that_load_step_was_completed (1);
42   check_that_load_step_was_not_completed (2);
44   /* Check that the corresponding category's +load was not done.  */
45   check_that_load_step_was_not_completed (5);
47   complete_load_step (2);
49 @end
51 @implementation TestClass1
52 + initialize { return self; }
53 + load
55   printf ("[TestClass1 +load]\n");
57   /* Check superclasses/subclasses +load order.  */
58   check_that_load_step_was_not_completed (0);
59   check_that_load_step_was_not_completed (1);
60   check_that_load_step_was_not_completed (2);
62   /* Check that the corresponding category's +load was not done.  */
63   check_that_load_step_was_not_completed (3);
65   complete_load_step (0);
67 @end
70 static BOOL load_step_completed[6] = { NO, NO, NO, NO, NO, NO };
72 void complete_load_step (int load_step)
74   load_step_completed[load_step] = YES;
77 void check_that_load_step_was_completed (int load_step)
79   if (load_step_completed[load_step] == NO)
80     {
81       printf ("Load step %d was not completed but should have been\n", load_step);
82       abort ();
83     }
86 void check_that_load_step_was_not_completed (int load_step)
88   if (load_step_completed[load_step] == YES)
89     {
90       printf ("Load step %d was completed but shouldn't have been\n", load_step);
91       abort ();
92     }
95 int main (void)
97   check_that_load_step_was_completed (0);
98   check_that_load_step_was_completed (1);
99   check_that_load_step_was_completed (2);
100   check_that_load_step_was_completed (3);
101   check_that_load_step_was_completed (4);
102   check_that_load_step_was_completed (5);
104   return 0;