]> git.saurik.com Git - apple/objc4.git/blob - test/createInstance.m
objc4-551.1.tar.gz
[apple/objc4.git] / test / createInstance.m
1 // TEST_CONFIG MEM=mrc,gc
2 // TEST_CFLAGS -Wno-deprecated-declarations
3
4 #import <objc/runtime.h>
5 #import <objc/objc-auto.h>
6 #ifndef OBJC_NO_GC
7 #include <auto_zone.h>
8 #else
9 static void* objc_collectableZone(void) { return NULL; }
10 static BOOL auto_zone_is_valid_pointer(void *a, void *b) { return a||b; }
11 #endif
12 #include "test.h"
13
14 OBJC_ROOT_CLASS
15 @interface Super { @public id isa; } @end
16 @implementation Super
17 +(void) initialize { }
18 +(Class) class { return self; }
19 @end
20
21 @interface Sub : Super { int array[128]; } @end
22 @implementation Sub @end
23
24 int main()
25 {
26 Super *s;
27
28 s = class_createInstance([Super class], 0);
29 testassert(s);
30 testassert(object_getClass(s) == [Super class]);
31 testassert(malloc_size(s) >= class_getInstanceSize([Super class]));
32 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
33
34 object_dispose(s);
35
36 s = class_createInstance([Sub class], 0);
37 testassert(s);
38 testassert(object_getClass(s) == [Sub class]);
39 testassert(malloc_size(s) >= class_getInstanceSize([Sub class]));
40 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
41
42 object_dispose(s);
43
44 s = class_createInstance([Super class], 100);
45 testassert(s);
46 testassert(object_getClass(s) == [Super class]);
47 testassert(malloc_size(s) >= class_getInstanceSize([Super class]) + 100);
48 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
49
50 object_dispose(s);
51
52 s = class_createInstance([Sub class], 100);
53 testassert(s);
54 testassert(object_getClass(s) == [Sub class]);
55 testassert(malloc_size(s) >= class_getInstanceSize([Sub class]) + 100);
56 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
57
58 object_dispose(s);
59
60 s = class_createInstance(Nil, 0);
61 testassert(!s);
62
63 succeed(__FILE__);
64 }