5 #include <objc/objc-runtime.h>
9 @interface Super { id isa; } @end
12 +class { return self; }
13 -(void)instancemethod { fail("-instancemethod not overridden by category"); }
14 +(void)method { fail("+method not overridden by category"); }
17 @interface Super (Category) @end
18 @implementation Super (Category)
20 testprintf("in [Super(Category) method]\n");
21 testassert(self == [Super class]);
22 testassert(state == 0);
25 -(void)instancemethod {
26 testprintf("in [Super(Category) instancemethod]\n");
27 testassert(self->isa == [Super class]);
28 testassert(state == 1);
33 @interface Super (PropertyCategory)
36 @implementation Super (PropertyCategory)
37 - (int)i { return 0; }
38 - (void)setI:(int)value { (void)value; }
41 // rdar://5086110 memory smasher in category with class method and property
42 @interface Super (r5086110)
43 @property int property5086110;
45 @implementation Super (r5086110)
46 +(void)method5086110 {
47 fail("method method5086110 called!");
49 - (int)property5086110 { fail("property5086110 called!"); return 0; }
50 - (void)setProperty5086110:(int)value { fail("setProperty5086110 called!"); (void)value; }
54 @interface PropertyClass : Super {
57 @property(readonly) int q;
59 @implementation PropertyClass
63 @interface PropertyClass (PropertyCategory)
66 @implementation PropertyClass (PropertyCategory)
75 // methods introduced by category
78 buf[0] = [Super class];
79 [(Super *)buf instancemethod];
80 testassert(state == 2);
82 // property introduced by category
83 objc_property_t p = class_getProperty([Super class], "i");
85 testassert(0 == strcmp(property_getName(p), "i"));
86 testassert(property_getAttributes(p));
88 // methods introduced by category's property
90 m = class_getInstanceMethod([Super class], @selector(i));
92 m = class_getInstanceMethod([Super class], @selector(setI:));
95 // class's property shadowed by category's property
96 objc_property_t *plist = class_copyPropertyList([PropertyClass class], NULL);
99 testassert(0 == strcmp(property_getName(plist[0]), "q"));
100 testassert(0 == strcmp(property_getAttributes(plist[0]), "Ti,D"));
101 testassert(plist[1]);
102 testassert(0 == strcmp(property_getName(plist[1]), "q"));
103 testassert(0 == strcmp(property_getAttributes(plist[1]), "Ti,R,Vq"));
104 testassert(!plist[2]);