2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / objc / execute / class-tests-1.h
blobcfdd72b4748a1f35e8c2f49d585d473b697fbd39
1 /* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "../../objc-obj-c++-shared/runtime.h"
7 /*
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");
18 abort ();
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");
28 abort ();
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");
38 abort ();
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);
48 if (object == nil)
50 printf ("test_allocate failed\n");
51 abort ();
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");
63 abort ();
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");
83 abort ();
87 /*
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)
93 Class class;
94 Class superclass;
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);
107 /* Now the tests */
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);