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