summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc/execute/load-3.m
blob: 15dfc0b485d60c69d3a97cc4e13fb966c2c5e965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    load-3.m

    Author: Ovidiu Predescu <ovidiu@cup.hp.com>
    Date: June  3, 2001

    Test if the +load methods are invoked, and are invoked in the
    proper order.
 */

#include <stdlib.h>
#import "../../objc-obj-c++-shared/Object1.h"
#include <objc/objc.h>

@interface A : Object
@end

@interface B : A
@end

static a_load = 0;
static b_load = 0;
static a_category_load = 0;
static b_category_load = 0;

@implementation A (Category)
+ (void)load
{
  a_category_load = 1;
  printf("+[A(Category) load]\n");

  if (a_load != 1)
    {
      printf("+load for A(Category) invoked before A's!\n");
      abort();
    }
}
@end

@implementation B(Category)
+ (void)load
{
  b_category_load = 1;
  printf("+[B(Category) load]\n");

  if (b_load != 1)
    {
      printf ("+load for B(Category) invoked before B!\n");
      abort();
    }
}
@end

@implementation B
+ (void)load
{
  b_load = 1;
  printf("+[B load]\n");

  if (a_load != 1)
    {
      printf("+load for B invoked before A's!\n");
      abort();
    }

  if (b_category_load != 0)
    {
      printf("+load for B invoked after B(Category)!\n");
      abort();
    }
}
@end

@implementation A
+ (void)load
{
  a_load = 1;
  printf("+[A load]\n");

  if (a_category_load != 0)
    {
      printf("+load for A(Category) invoked before A!\n");
      abort();
    }

  if (b_load != 0)
    {
      printf("+load for A invoked after B!\n");
      abort();
    }

  if (b_category_load != 0)
    {
      printf("+load for B(Category) invoked before A and B!\n");
      abort();
    }
}
@end

int main (void)
{
  if (a_load + b_load + a_category_load + b_category_load != 4)
    {
      printf("Not all +load methods invoked!\n");
      abort();
    }

  return 0;
}