1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
3 #include <objc/objc-api.h>
4 #include <objc/Object.h>
8 * Standard Tests For Classes and Objects - abort upon failing; return
9 * normally if all is well.
12 /* Test that `class' is a Class */
13 static void test_is_class (Class
class)
15 if (object_is_class (class) == NO
)
17 printf ("test_is_class failed\n");
21 if (class_is_class (class) == NO
)
23 printf ("test_is_class failed\n");
28 /* Test that the superclass of `class' is `superclass' */
29 static void test_superclass (Class
class, Class superclass
)
31 if (class_get_super_class (class) != superclass
)
33 printf ("test_superclass failed\n");
38 /* Test that the classname of `class' is `classname' */
39 static void test_class_name (Class
class, const char *classname
)
41 if (strcmp (class_get_class_name (class), classname
))
43 printf ("test_class_name failed\n");
48 /* Test that we can allocate instances of `class' */
49 static void test_allocate (Class
class)
51 /* The object we create is leaked but who cares, this is only a test */
52 id object
= class_create_instance (class);
56 printf ("test_allocate failed\n");
61 /* Test that instances of `class' are instances and not classes */
62 static void test_instances (Class
class)
64 id object
= class_create_instance (class);
66 if (object_is_class (object
) == YES
)
68 printf ("test_instances failed\n");
73 /* Test that we can deallocate instances of `class' */
74 static void test_deallocate (Class
class)
76 id object
= class_create_instance (class);
78 object_dispose (object
);
81 /* Test that the object and the class agree on what the class is */
82 static void test_object_class (Class
class)
84 id object
= class_create_instance (class);
86 if (object_get_class (object
) != class)
88 printf ("test_object_class failed\n");
93 /* Test that the object and the class agree on what the superclass is */
94 static void test_object_super_class (Class
class)
96 id object
= class_create_instance (class);
98 if (object_get_super_class (object
) != class_get_super_class (class))
100 printf ("test_object_super_class failed\n");
106 * Runs all the tests in this file for the specified class
108 void test_class_with_superclass (const char *class_name
,
109 const char *superclass_name
)
114 /* We need at least a method call before playing with the internals,
115 so that the runtime will call __objc_resolve_class_links () */
118 /* class_name must be an existing class */
119 class = objc_lookup_class (class_name
);
120 test_is_class (class);
122 /* But superclass_name can be "", which means `Nil' */
123 superclass
= objc_lookup_class (superclass_name
);
124 if (superclass
!= Nil
)
126 test_is_class (superclass
);
130 test_superclass (class, superclass
);
131 test_class_name (class, class_name
);
132 test_allocate (class);
133 test_instances (class);
134 test_deallocate (class);
135 test_object_class (class);
136 test_object_super_class (class);