1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
5 #include "../../objc-obj-c++-shared/Object1.h"
7 #include <objc/objc-api.h>
10 * Standard Tests For Classes and Objects - abort upon failing; return
11 * normally if all is well.
14 /* Test that `class' is a Class */
15 static void test_is_class (Class
class)
17 if (object_is_class (class) == NO
)
19 printf ("test_is_class failed\n");
23 if (class_is_class (class) == NO
)
25 printf ("test_is_class failed\n");
30 /* Test that the superclass of `class' is `superclass' */
31 static void test_superclass (Class
class, Class superclass
)
33 if (class_get_super_class (class) != superclass
)
35 printf ("test_superclass failed\n");
40 /* Test that the classname of `class' is `classname' */
41 static void test_class_name (Class
class, const char *classname
)
43 if (strcmp (class_get_class_name (class), classname
))
45 printf ("test_class_name failed\n");
50 /* Test that we can allocate instances of `class' */
51 static void test_allocate (Class
class)
53 /* The object we create is leaked but who cares, this is only a test */
54 id object
= class_create_instance (class);
58 printf ("test_allocate failed\n");
63 /* Test that instances of `class' are instances and not classes */
64 static void test_instances (Class
class)
66 id object
= class_create_instance (class);
68 if (object_is_class (object
) == YES
)
70 printf ("test_instances failed\n");
75 /* Test that we can deallocate instances of `class' */
76 static void test_deallocate (Class
class)
78 id object
= class_create_instance (class);
80 object_dispose (object
);
83 /* Test that the object and the class agree on what the class is */
84 static void test_object_class (Class
class)
86 id object
= class_create_instance (class);
88 if (object_get_class (object
) != class)
90 printf ("test_object_class failed\n");
95 /* Test that the object and the class agree on what the superclass is */
96 static void test_object_super_class (Class
class)
98 id object
= class_create_instance (class);
100 if (object_get_super_class (object
) != class_get_super_class (class))
102 printf ("test_object_super_class failed\n");
108 * Runs all the tests in this file for the specified class
110 void test_class_with_superclass (const char *class_name
,
111 const char *superclass_name
)
116 /* We need at least a method call before playing with the internals,
117 so that the runtime will call __objc_resolve_class_links () */
120 /* class_name must be an existing class */
121 class = objc_lookup_class (class_name
);
122 test_is_class (class);
124 /* But superclass_name can be "", which means `Nil' */
125 superclass
= objc_lookup_class (superclass_name
);
126 if (superclass
!= Nil
)
128 test_is_class (superclass
);
132 test_superclass (class, superclass
);
133 test_class_name (class, class_name
);
134 test_allocate (class);
135 test_instances (class);
136 test_deallocate (class);
137 test_object_class (class);
138 test_object_super_class (class);