1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
5 #include "../../objc-obj-c++-shared/runtime.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 (class_isMetaClass (object_getClass (class)) == NO
)
17 printf ("test_is_class failed\n");
22 /* Test that the superclass of `class' is `superclass' */
23 static void test_superclass (Class
class, Class superclass
)
25 if (class_getSuperclass (class) != superclass
)
27 printf ("test_superclass failed\n");
32 /* Test that the classname of `class' is `classname' */
33 static void test_class_name (Class
class, const char *classname
)
35 if (strcmp (class_getName (class), classname
))
37 printf ("test_class_name failed\n");
42 /* Test that we can allocate instances of `class' */
43 static void test_allocate (Class
class)
45 /* The object we create is leaked but who cares, this is only a test */
46 id object
= class_createInstance (class, 0);
50 printf ("test_allocate failed\n");
55 /* Test that instances of `class' are instances and not classes */
56 static void test_instances (Class
class)
58 id object
= class_createInstance (class, 0);
60 if (class_isMetaClass (object_getClass (object
)) == YES
)
62 printf ("test_instances failed\n");
67 /* Test that we can deallocate instances of `class' */
68 static void test_deallocate (Class
class)
70 id object
= class_createInstance (class, 0);
72 object_dispose (object
);
75 /* Test that the object and the class agree on what the class is */
76 static void test_object_class (Class
class)
78 id object
= class_createInstance (class, 0);
80 if (object_getClass (object
) != class)
82 printf ("test_object_class failed\n");
88 * Runs all the tests in this file for the specified class
90 void test_class_with_superclass (const char *class_name
,
91 const char *superclass_name
)
96 /* class_name must be an existing class */
97 class = objc_getClass (class_name
);
98 test_is_class (class);
100 /* But superclass_name can be "", which means `Nil' */
101 superclass
= objc_getClass (superclass_name
);
102 if (superclass
!= Nil
)
104 test_is_class (superclass
);
108 test_superclass (class, superclass
);
109 test_class_name (class, class_name
);
110 test_allocate (class);
111 test_instances (class);
112 test_deallocate (class);
113 test_object_class (class);