3 #include <objc/objc-runtime.h>
7 @interface Super { id isa; } @end
10 +class { return self; }
11 -(void)instancemethod { fail("-instancemethod not overridden by category"); }
12 +(void)method { fail("+method not overridden by category"); }
15 @interface Super (Category) @end
16 @implementation Super (Category)
18 testprintf("in [Super(Category) method]\n");
19 testassert(self == [Super class]);
20 testassert(state == 0);
23 -(void)instancemethod {
24 testprintf("in [Super(Category) instancemethod]\n");
25 testassert(self->isa == [Super class]);
26 testassert(state == 1);
31 @interface Super (PropertyCategory)
34 @implementation Super (PropertyCategory)
35 - (int)i { return 0; }
36 - (void)setI:(int)value { (void)value; }
39 // rdar://5086110 memory smasher in category with class method and property
40 @interface Super (r5086110)
41 @property int property5086110;
43 @implementation Super (r5086110)
44 +(void)method5086110 {
45 fail("method method5086110 called!");
47 - (int)property5086110 { fail("property5086110 called!"); return 0; }
48 - (void)setProperty5086110:(int)value { fail("setProperty5086110 called!"); (void)value; }
52 @interface PropertyClass : Super {
55 @property(readonly) int q;
57 @implementation PropertyClass
61 @interface PropertyClass (PropertyCategory)
64 @implementation PropertyClass (PropertyCategory)
73 // methods introduced by category
76 buf[0] = [Super class];
77 [(Super *)buf instancemethod];
78 testassert(state == 2);
80 // property introduced by category
81 objc_property_t p = class_getProperty([Super class], "i");
83 testassert(0 == strcmp(property_getName(p), "i"));
84 testassert(property_getAttributes(p));
86 // methods introduced by category's property
88 m = class_getInstanceMethod([Super class], @selector(i));
90 m = class_getInstanceMethod([Super class], @selector(setI:));
93 // class's property shadowed by category's property
94 objc_property_t *plist = class_copyPropertyList([PropertyClass class], NULL);
97 testassert(0 == strcmp(property_getName(plist[0]), "q"));
98 testassert(0 == strcmp(property_getAttributes(plist[0]), "Ti,D"));
100 testassert(0 == strcmp(property_getName(plist[1]), "q"));
101 testassert(0 == strcmp(property_getAttributes(plist[1]), "Ti,R,Vq"));
102 testassert(!plist[2]);