1 // TEST_CFLAGS -Wl,-no_objc_category_merging
6 #include <objc/runtime.h>
10 @interface Super : TestRoot @end
12 -(void)instancemethod { fail("-instancemethod not overridden by category"); }
13 +(void)method { fail("+method not overridden by category"); }
16 @interface Super (Category) @end
17 @implementation Super (Category)
19 testprintf("in [Super(Category) method]\n");
20 testassert(self == [Super class]);
21 testassert(state == 0);
24 -(void)instancemethod {
25 testprintf("in [Super(Category) instancemethod]\n");
26 testassert(self->isa == [Super class]);
27 testassert(state == 1);
32 @interface Super (PropertyCategory)
35 @implementation Super (PropertyCategory)
36 - (int)i { return 0; }
37 - (void)setI:(int)value { (void)value; }
40 // rdar://5086110 memory smasher in category with class method and property
41 @interface Super (r5086110)
42 @property int property5086110;
44 @implementation Super (r5086110)
45 +(void)method5086110 {
46 fail("method method5086110 called!");
48 - (int)property5086110 { fail("property5086110 called!"); return 0; }
49 - (void)setProperty5086110:(int)value { fail("setProperty5086110 called!"); (void)value; }
53 @interface PropertyClass : Super {
56 @property(readonly) int q;
58 @implementation PropertyClass
62 @interface PropertyClass (PropertyCategory)
65 @implementation PropertyClass (PropertyCategory)
72 // methods introduced by category
75 [[Super new] instancemethod];
76 testassert(state == 2);
78 // property introduced by category
79 objc_property_t p = class_getProperty([Super class], "i");
81 testassert(0 == strcmp(property_getName(p), "i"));
82 testassert(property_getAttributes(p));
84 // methods introduced by category's property
86 m = class_getInstanceMethod([Super class], @selector(i));
88 m = class_getInstanceMethod([Super class], @selector(setI:));
91 // class's property shadowed by category's property
92 objc_property_t *plist = class_copyPropertyList([PropertyClass class], NULL);
95 testassert(0 == strcmp(property_getName(plist[0]), "q"));
96 testassert(0 == strcmp(property_getAttributes(plist[0]), "Ti,D"));
98 testassert(0 == strcmp(property_getName(plist[1]), "q"));
99 testassert(0 == strcmp(property_getAttributes(plist[1]), "Ti,R,Vq"));
100 testassert(!plist[2]);