Debian Codegraph @

gcc/testsuite/objc.dg/special/load-category-3.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, December 2010. */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4 /* { dg-additional-options "-Wno-objc-root-class" } */
5
6 /* This test is identical to load-category-2, but the classes and
7 categories are created in inverted order in the modules, to test
8 that you can load classes first, or categories first, and it all
9 still works in both cases. */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <objc/objc.h>
14
15 #include "load-category-3.h"
16
17 @implementation TestClass2 (Category)
18 + load
19 {
20 printf ("[TestClass2(Category) +load]\n");
21
22 /* Check that the corresponding class's +load was done. */
23 check_that_load_step_was_completed (1);
24
25 complete_load_step (4);
26 }
27 @end
28
29 @implementation TestClass3 (Category)
30 + load
31 {
32 printf ("[TestClass3(Category) +load]\n");
33
34 /* Check that the corresponding class's +load was done. */
35 check_that_load_step_was_completed (2);
36
37 complete_load_step (5);
38 }
39 @end
40
41 @implementation TestClass1 (Category)
42 + load
43 {
44 printf ("[TestClass1(Category) +load]\n");
45
46 /* Check that the corresponding class's +load was done. */
47 check_that_load_step_was_completed (0);
48
49 complete_load_step (3);
50 }
51 @end
52
53 static BOOL load_step_completed[6] = { NO, NO, NO, NO, NO, NO };
54
55 void complete_load_step (int load_step)
56 {
57 load_step_completed[load_step] = YES;
58 }
59
60 void check_that_load_step_was_completed (int load_step)
61 {
62 if (load_step_completed[load_step] == NO)
63 {
64 printf ("Load step %d was not completed but should have been\n", load_step);
65 abort ();
66 }
67 }
68
69 void check_that_load_step_was_not_completed (int load_step)
70 {
71 if (load_step_completed[load_step] == YES)
72 {
73 printf ("Load step %d was completed but shouldn't have been\n", load_step);
74 abort ();
75 }
76 }
77
78 int main (void)
79 {
80 check_that_load_step_was_completed (0);
81 check_that_load_step_was_completed (1);
82 check_that_load_step_was_completed (2);
83 check_that_load_step_was_completed (3);
84 check_that_load_step_was_completed (4);
85 check_that_load_step_was_completed (5);
86
87 return 0;
88 }