1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
5 #include "../../objc-obj-c++-shared/runtime.h"
7 extern int strcmp(const char *, const char *);
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 (class_isMetaClass (object_getClass (class)) == NO
)
19 printf ("test_is_class failed\n");
24 /* Test that the superclass of `class' is `superclass' */
25 static void test_superclass (Class
class, Class superclass
)
27 if (class_getSuperclass (class) != superclass
)
29 printf ("test_superclass failed\n");
34 /* Test that the classname of `class' is `classname' */
35 static void test_class_name (Class
class, const char *classname
)
37 if (strcmp (class_getName (class), classname
))
39 printf ("test_class_name failed\n");
44 /* Test that we can allocate instances of `class' */
45 static void test_allocate (Class
class)
47 /* The object we create is leaked but who cares, this is only a test */
48 id object
= class_createInstance (class, 0);
52 printf ("test_allocate failed\n");
57 /* Test that instances of `class' are instances and not classes */
58 static void test_instances (Class
class)
60 id object
= class_createInstance (class, 0);
62 if (class_isMetaClass (object_getClass (object
)) == YES
)
64 printf ("test_instances failed\n");
69 /* Test that we can deallocate instances of `class' */
70 static void test_deallocate (Class
class)
72 id object
= class_createInstance (class, 0);
74 object_dispose (object
);
77 /* Test that the object and the class agree on what the class is */
78 static void test_object_class (Class
class)
80 id object
= class_createInstance (class, 0);
82 if (object_getClass (object
) != class)
84 printf ("test_object_class failed\n");
90 * Runs all the tests in this file for the specified class
92 void test_class_with_superclass (const char *class_name
,
93 const char *superclass_name
)
98 /* class_name must be an existing class */
99 class = objc_getClass (class_name
);
100 test_is_class (class);
102 /* But superclass_name can be "", which means `Nil' */
103 superclass
= objc_getClass (superclass_name
);
104 if (superclass
!= Nil
)
106 test_is_class (superclass
);
110 test_superclass (class, superclass
);
111 test_class_name (class, class_name
);
112 test_allocate (class);
113 test_instances (class);
114 test_deallocate (class);
115 test_object_class (class);