aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/objc.dg/special/load-category-3.m
blob: b89d8f15286034f06fb35c38c1139ca04dcf1bef (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
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */

/* This test is identical to load-category-2, but the classes and
   categories are created in inverted order in the modules, to test
   that you can load classes first, or categories first, and it all
   still works in both cases.  */

#include <stdio.h>
#include <stdlib.h>
#include <objc/objc.h>

#include "load-category-3.h"

@implementation TestClass2 (Category)
+ load
{
  printf ("[TestClass2(Category) +load]\n");

  /* Check that the corresponding class's +load was done.  */
  check_that_load_step_was_completed (1);

  complete_load_step (4);
}
@end

@implementation TestClass3 (Category)
+ load
{
  printf ("[TestClass3(Category) +load]\n");

  /* Check that the corresponding class's +load was done.  */
  check_that_load_step_was_completed (2);

  complete_load_step (5);
}
@end

@implementation TestClass1 (Category)
+ load
{
  printf ("[TestClass1(Category) +load]\n");

  /* Check that the corresponding class's +load was done.  */
  check_that_load_step_was_completed (0);

  complete_load_step (3);
}
@end

static BOOL load_step_completed[6] = { NO, NO, NO, NO, NO, NO };

void complete_load_step (int load_step)
{
  load_step_completed[load_step] = YES;
}

void check_that_load_step_was_completed (int load_step)
{
  if (load_step_completed[load_step] == NO)
    {
      printf ("Load step %d was not completed but should have been\n", load_step);
      abort ();
    }
}

void check_that_load_step_was_not_completed (int load_step)
{
  if (load_step_completed[load_step] == YES)
    {
      printf ("Load step %d was completed but shouldn't have been\n", load_step);
      abort ();
    }
}

int main (void)
{
  check_that_load_step_was_completed (0);
  check_that_load_step_was_completed (1);
  check_that_load_step_was_completed (2);
  check_that_load_step_was_completed (3);
  check_that_load_step_was_completed (4);
  check_that_load_step_was_completed (5);

  return 0;
}