1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010. */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
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
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);
34 @implementation TestClass3
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);
51 @implementation TestClass1
52 + initialize { return self; }
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);
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)
81 printf ("Load step %d was not completed but should have been\n", load_step);
86 void check_that_load_step_was_not_completed (int load_step)
88 if (load_step_completed[load_step] == YES)
90 printf ("Load step %d was completed but shouldn't have been\n", load_step);
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);