]> git.saurik.com Git - apple/objc4.git/blob - test/createInstance.m
objc4-532.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 @interface Super { @public id isa; } @end
15 @implementation Super
16 +(void) initialize { }
17 +(Class) class { return self; }
18 @end
19
20 @interface Sub : Super { int array[128]; } @end
21 @implementation Sub @end
22
23 int main()
24 {
25 Super *s;
26
27 s = class_createInstance([Super class], 0);
28 testassert(s);
29 testassert(s->isa == [Super class]);
30 testassert(malloc_size(s) >= class_getInstanceSize([Super class]));
31 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
32
33 object_dispose(s);
34
35 s = class_createInstance([Sub class], 0);
36 testassert(s);
37 testassert(s->isa == [Sub class]);
38 testassert(malloc_size(s) >= class_getInstanceSize([Sub class]));
39 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
40
41 object_dispose(s);
42
43 s = class_createInstance([Super class], 100);
44 testassert(s);
45 testassert(s->isa == [Super class]);
46 testassert(malloc_size(s) >= class_getInstanceSize([Super class]) + 100);
47 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
48
49 object_dispose(s);
50
51 s = class_createInstance([Sub class], 100);
52 testassert(s);
53 testassert(s->isa == [Sub class]);
54 testassert(malloc_size(s) >= class_getInstanceSize([Sub class]) + 100);
55 if (objc_collectingEnabled()) testassert(auto_zone_is_valid_pointer(objc_collectableZone(), s));
56
57 object_dispose(s);
58
59 s = class_createInstance(Nil, 0);
60 testassert(!s);
61
62 succeed(__FILE__);
63 }