OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc/] [execute/] [class-tests-1.h] - Blame information for rev 307

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 307 jeremybenn
/* Contributed by Nicola Pero on Tue Mar  6 23:05:53 CET 2001 */
2
 
3
#include <stdlib.h>
4
#include "../../objc-obj-c++-shared/Object1.h"
5
#include <objc/objc.h>
6
#include <objc/objc-api.h>
7
 
8
/*
9
 * Standard Tests For Classes and Objects - abort upon failing; return
10
 * normally if all is well.
11
 */
12
 
13
/* Test that `class' is a Class */
14
static void test_is_class (Class class)
15
{
16
  if (object_is_class (class) == NO)
17
    {
18
      printf ("test_is_class failed\n");
19
      abort ();
20
    }
21
 
22
  if (class_is_class (class) == NO)
23
    {
24
      printf ("test_is_class failed\n");
25
      abort ();
26
    }
27
}
28
 
29
/* Test that the superclass of `class' is `superclass' */
30
static void test_superclass (Class class, Class superclass)
31
{
32
  if (class_get_super_class (class) != superclass)
33
    {
34
      printf ("test_superclass failed\n");
35
      abort ();
36
    }
37
}
38
 
39
/* Test that the classname of `class' is `classname' */
40
static void test_class_name (Class class, const char *classname)
41
{
42
  if (strcmp (class_get_class_name (class), classname))
43
    {
44
      printf ("test_class_name failed\n");
45
      abort ();
46
    }
47
}
48
 
49
/* Test that we can allocate instances of `class' */
50
static void test_allocate (Class class)
51
{
52
  /* The object we create is leaked but who cares, this is only a test */
53
  id object = class_create_instance (class);
54
 
55
  if (object == nil)
56
    {
57
      printf ("test_allocate failed\n");
58
      abort ();
59
    }
60
}
61
 
62
/* Test that instances of `class' are instances and not classes */
63
static void test_instances (Class class)
64
{
65
  id object = class_create_instance (class);
66
 
67
  if (object_is_class (object) == YES)
68
    {
69
      printf ("test_instances failed\n");
70
      abort ();
71
    }
72
}
73
 
74
/* Test that we can deallocate instances of `class' */
75
static void test_deallocate (Class class)
76
{
77
  id object = class_create_instance (class);
78
 
79
  object_dispose (object);
80
}
81
 
82
/* Test that the object and the class agree on what the class is */
83
static void test_object_class (Class class)
84
{
85
  id object = class_create_instance (class);
86
 
87
  if (object_get_class (object) != class)
88
    {
89
      printf ("test_object_class failed\n");
90
      abort ();
91
    }
92
}
93
 
94
/* Test that the object and the class agree on what the superclass is */
95
static void test_object_super_class (Class class)
96
{
97
  id object = class_create_instance (class);
98
 
99
  if (object_get_super_class (object) != class_get_super_class (class))
100
    {
101
      printf ("test_object_super_class failed\n");
102
      abort ();
103
    }
104
}
105
 
106
/*
107
 *  Runs all the tests in this file for the specified class
108
 */
109
void test_class_with_superclass (const char *class_name,
110
                                 const char *superclass_name)
111
{
112
  Class class;
113
  Class superclass;
114
 
115
  /* We need at least a method call before playing with the internals,
116
     so that the runtime will call __objc_resolve_class_links () */
117
  [Object class];
118
 
119
  /* class_name must be an existing class */
120
  class = objc_lookup_class (class_name);
121
  test_is_class (class);
122
 
123
  /* But superclass_name can be "", which means `Nil' */
124
  superclass = objc_lookup_class (superclass_name);
125
  if (superclass != Nil)
126
    {
127
      test_is_class (superclass);
128
    }
129
 
130
  /* Now the tests */
131
  test_superclass (class, superclass);
132
  test_class_name (class, class_name);
133
  test_allocate (class);
134
  test_instances (class);
135
  test_deallocate (class);
136
  test_object_class (class);
137
  test_object_super_class (class);
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.