Merged r157653 through r157895 into branch.
[official-gcc.git] / gcc / testsuite / objc / execute / class-tests-1.h
blobebc49b66c221d765d3e976961cdef3eb5534e28b
1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
3 #include <stdlib.h>
4 #include "../../objc-obj-c++-shared/Object1.h"
5 #include <objc/objc.h>
6 #include <objc/objc-api.h>
8 /*
9 * Standard Tests For Classes and Objects - abort upon failing; return
10 * normally if all is well.
13 /* Test that `class' is a Class */
14 static void test_is_class (Class class)
16 if (object_is_class (class) == NO)
18 printf ("test_is_class failed\n");
19 abort ();
22 if (class_is_class (class) == NO)
24 printf ("test_is_class failed\n");
25 abort ();
29 /* Test that the superclass of `class' is `superclass' */
30 static void test_superclass (Class class, Class superclass)
32 if (class_get_super_class (class) != superclass)
34 printf ("test_superclass failed\n");
35 abort ();
39 /* Test that the classname of `class' is `classname' */
40 static void test_class_name (Class class, const char *classname)
42 if (strcmp (class_get_class_name (class), classname))
44 printf ("test_class_name failed\n");
45 abort ();
49 /* Test that we can allocate instances of `class' */
50 static void test_allocate (Class class)
52 /* The object we create is leaked but who cares, this is only a test */
53 id object = class_create_instance (class);
55 if (object == nil)
57 printf ("test_allocate failed\n");
58 abort ();
62 /* Test that instances of `class' are instances and not classes */
63 static void test_instances (Class class)
65 id object = class_create_instance (class);
67 if (object_is_class (object) == YES)
69 printf ("test_instances failed\n");
70 abort ();
74 /* Test that we can deallocate instances of `class' */
75 static void test_deallocate (Class class)
77 id object = class_create_instance (class);
79 object_dispose (object);
82 /* Test that the object and the class agree on what the class is */
83 static void test_object_class (Class class)
85 id object = class_create_instance (class);
87 if (object_get_class (object) != class)
89 printf ("test_object_class failed\n");
90 abort ();
94 /* Test that the object and the class agree on what the superclass is */
95 static void test_object_super_class (Class class)
97 id object = class_create_instance (class);
99 if (object_get_super_class (object) != class_get_super_class (class))
101 printf ("test_object_super_class failed\n");
102 abort ();
107 * Runs all the tests in this file for the specified class
109 void test_class_with_superclass (const char *class_name,
110 const char *superclass_name)
112 Class class;
113 Class superclass;
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];
119 /* class_name must be an existing class */
120 class = objc_lookup_class (class_name);
121 test_is_class (class);
123 /* But superclass_name can be "", which means `Nil' */
124 superclass = objc_lookup_class (superclass_name);
125 if (superclass != Nil)
127 test_is_class (superclass);
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);