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(object_getClass(self) == [Super class]);
27 testassert(state == 1);
32 @interface Super (PropertyCategory)
34 @property(class) int i;
36 @implementation Super (PropertyCategory)
37 - (int)i { return 0; }
38 - (void)setI:(int)value { (void)value; }
39 + (int)i { return 0; }
40 + (void)setI:(int)value { (void)value; }
43 // rdar://5086110 memory smasher in category with class method and property
44 @interface Super (r5086110)
45 @property int property5086110;
47 @implementation Super (r5086110)
48 +(void)method5086110 {
49 fail("method method5086110 called!");
51 - (int)property5086110 { fail("property5086110 called!"); return 0; }
52 - (void)setProperty5086110:(int)value { fail("setProperty5086110 called!"); (void)value; }
55 // rdar://25605427 incorrect handling of class properties in 10.11 and earlier
56 @interface Super25605427 : TestRoot
57 @property(class, readonly) int i;
59 @implementation Super25605427
63 @interface Super25605427 (r25605427a)
64 @property(readonly) int r25605427a1;
66 @implementation Super25605427 (r25605427a)
67 -(int)r25605427a1 { return 0; }
68 +(int)r25605427a2 { return 0; }
71 @interface Super25605427 (r25605427b)
72 @property(readonly) int r25605427b1;
74 @implementation Super25605427 (r25605427b)
75 -(int)r25605427b1 { return 0; }
76 +(int)r25605427b2 { return 0; }
79 @interface Super25605427 (r25605427c)
80 @property(readonly) int r25605427c1;
82 @implementation Super25605427 (r25605427c)
83 -(int)r25605427c1 { return 0; }
84 +(int)r25605427c2 { return 0; }
87 @interface Super25605427 (r25605427d)
88 @property(readonly) int r25605427d1;
90 @implementation Super25605427 (r25605427d)
91 -(int)r25605427d1 { return 0; }
92 +(int)r25605427d2 { return 0; }
96 @interface PropertyClass : Super {
99 @property(readonly) int q;
101 @implementation PropertyClass
105 @interface PropertyClass (PropertyCategory)
108 @implementation PropertyClass (PropertyCategory)
116 // rdar://25605427 bugs in 10.11 and earlier when metaclass
117 // has a property and category has metaclass additions.
118 // Memory smasher in buildPropertyList (caught by guard malloc)
119 Class cls = [Super25605427 class];
120 // Incorrect attachment of instance properties from category to metacls
121 testassert(class_getProperty(cls, "r25605427d1"));
122 testassert(! class_getProperty(object_getClass(cls), "r25605427d1"));
125 // methods introduced by category
128 [[Super new] instancemethod];
129 testassert(state == 2);
131 // property introduced by category
132 objc_property_t p = class_getProperty([Super class], "i");
134 testassert(0 == strcmp(property_getName(p), "i"));
135 testassert(property_getAttributes(p));
137 objc_property_t p2 = class_getProperty(object_getClass([Super class]), "i");
140 testassert(0 == strcmp(property_getName(p2), "i"));
141 testassert(property_getAttributes(p2));
143 // methods introduced by category's property
145 m = class_getInstanceMethod([Super class], @selector(i));
147 m = class_getInstanceMethod([Super class], @selector(setI:));
150 m = class_getClassMethod([Super class], @selector(i));
152 m = class_getClassMethod([Super class], @selector(setI:));
155 // class's property shadowed by category's property
156 objc_property_t *plist = class_copyPropertyList([PropertyClass class], NULL);
158 testassert(plist[0]);
159 testassert(0 == strcmp(property_getName(plist[0]), "q"));
160 testassert(0 == strcmp(property_getAttributes(plist[0]), "Ti,D"));
161 testassert(plist[1]);
162 testassert(0 == strcmp(property_getName(plist[1]), "q"));
163 testassert(0 == strcmp(property_getAttributes(plist[1]), "Ti,R,Vq"));
164 testassert(!plist[2]);