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