]> git.saurik.com Git - apple/objc4.git/blob - test/nsobject.m
objc4-680.tar.gz
[apple/objc4.git] / test / nsobject.m
1 // TEST_CONFIG MEM=mrc,gc
2
3 #include "test.h"
4
5 #import <Foundation/NSObject.h>
6
7 @interface Sub : NSObject @end
8 @implementation Sub
9 +(id)allocWithZone:(NSZone *)zone {
10 testprintf("in +[Sub alloc]\n");
11 return [super allocWithZone:zone];
12 }
13 -(void)dealloc {
14 testprintf("in -[Sub dealloc]\n");
15 [super dealloc];
16 }
17 @end
18
19
20 // These declarations and definitions can be used
21 // to check the compile-time type of an object.
22 @interface NSObject (Checker)
23 // fixme this isn't actually enforced
24 +(void)NSObjectInstance __attribute__((unavailable));
25 @end
26 @implementation NSObject (Checker)
27 -(void)NSObjectInstance { }
28 +(void)NSObjectClass { }
29 @end
30 @interface Sub (Checker)
31 -(void)NSObjectInstance __attribute__((unavailable));
32 +(void)NSObjectClass __attribute__((unavailable));
33 @end
34 @implementation Sub (Checker)
35 -(void)SubInstance { }
36 +(void)SubClass { }
37 @end
38
39 int main()
40 {
41 PUSH_POOL {
42 [[Sub new] autorelease];
43 } POP_POOL;
44
45 // Verify that dot syntax on class objects works with some instance methods
46 // (void)NSObject.self; fixme
47 (void)NSObject.class;
48 (void)NSObject.superclass;
49 (void)NSObject.hash;
50 (void)NSObject.description;
51 (void)NSObject.debugDescription;
52
53 // Verify that some methods return the correct type.
54 Class cls;
55 NSObject *nsobject = nil;
56 Sub *subobject = nil;
57
58 cls = [NSObject self];
59 cls = [Sub self];
60 nsobject = [nsobject self];
61 subobject = [subobject self];
62 [[NSObject self] NSObjectClass];
63 [[nsobject self] NSObjectInstance];
64 [[Sub self] SubClass];
65 [[subobject self] SubInstance];
66
67 // fixme
68 // cls = NSObject.self;
69 // cls = Sub.self;
70 // [NSObject.self NSObjectClass];
71 // [nsobject.self NSObjectInstance];
72 // [Sub.self SubClass];
73 // [subobject.self SubInstance];
74
75 cls = [NSObject class];
76 cls = [nsobject class];
77 cls = [Sub class];
78 cls = [subobject class];
79 [[NSObject class] NSObjectClass];
80 [[nsobject class] NSObjectClass];
81 [[Sub class] SubClass];
82 [[subobject class] SubClass];
83
84 cls = NSObject.class;
85 cls = nsobject.class;
86 cls = Sub.class;
87 cls = subobject.class;
88 [NSObject.class NSObjectClass];
89 [nsobject.class NSObjectClass];
90 [Sub.class SubClass];
91 [subobject.class SubClass];
92
93
94 cls = [NSObject superclass];
95 cls = [nsobject superclass];
96 cls = [Sub superclass];
97 cls = [subobject superclass];
98 [[NSObject superclass] NSObjectClass];
99 [[nsobject superclass] NSObjectClass];
100 [[Sub superclass] NSObjectClass];
101 [[subobject superclass] NSObjectClass];
102
103 cls = NSObject.superclass;
104 cls = nsobject.superclass;
105 cls = Sub.superclass;
106 cls = subobject.superclass;
107 [NSObject.superclass NSObjectClass];
108 [nsobject.superclass NSObjectClass];
109 [Sub.superclass NSObjectClass];
110 [subobject.superclass NSObjectClass];
111
112
113 succeed(__FILE__);
114 }