1 // TEST_CFLAGS -Wno-deprecated-declarations -Wl,-no_objc_category_merging
5 #include <objc/runtime.h>
7 #include <objc/objc-auto.h>
15 -(void)instanceMethod;
18 @interface Super : TestRoot <Proto> {
31 -(void)instanceMethod {
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
43 @implementation Super (Category)
49 -(void)instanceMethod {
56 #pragma clang diagnostic pop
68 clone = objc_duplicateClass(cls, "Super_copy", 0);
70 if (objc_collectingEnabled()) {
71 testassert(auto_zone_size(objc_collectableZone(), objc_unretainedPointer(clone)));
72 // objc_duplicateClass() doesn't duplicate the metaclass
73 // no: testassert(auto_zone_size(objc_collectableZone(), clone->isa));
77 testassert(clone != cls);
78 testassert(object_getClass(clone) == object_getClass(cls));
79 testassert(class_getSuperclass(clone) == class_getSuperclass(cls));
80 testassert(class_getVersion(clone) == class_getVersion(cls));
81 testassert(class_isMetaClass(clone) == class_isMetaClass(cls));
82 testassert(class_getIvarLayout(clone) == class_getIvarLayout(cls));
83 testassert(class_getWeakIvarLayout(clone) == class_getWeakIvarLayout(cls));
85 testassert((clone->info & (CLS_CLASS|CLS_META)) == (cls->info & (CLS_CLASS|CLS_META)));
90 m1 = class_copyMethodList(cls, NULL);
91 m2 = class_copyMethodList(clone, NULL);
94 for (i = 0; m1[i] && m2[i]; i++) {
95 testassert(m1[i] != m2[i]); // method list must be deep-copied
96 testassert(method_getName(m1[i]) == method_getName(m2[i]));
97 testassert(method_getImplementation(m1[i]) == method_getImplementation(m2[i]));
98 testassert(method_getTypeEncoding(m1[i]) == method_getTypeEncoding(m2[i]));
100 testassert(m1[i] == NULL && m2[i] == NULL);
105 Ivar *i1 = class_copyIvarList(cls, NULL);
106 Ivar *i2 = class_copyIvarList(clone, NULL);
109 for (i = 0; i1[i] && i2[i]; i++) {
110 testassert(i1[i] == i2[i]); // ivars are not deep-copied
112 testassert(i1[i] == NULL && i2[i] == NULL);
116 // Check protocol list
117 Protocol * __unsafe_unretained *p1 = class_copyProtocolList(cls, NULL);
118 Protocol * __unsafe_unretained *p2 = class_copyProtocolList(clone, NULL);
121 for (i = 0; p1[i] && p2[i]; i++) {
122 testassert(p1[i] == p2[i]); // protocols are not deep-copied
124 testassert(p1[i] == NULL && p2[i] == NULL);
128 // Check property list
129 objc_property_t *o1 = class_copyPropertyList(cls, NULL);
130 objc_property_t *o2 = class_copyPropertyList(clone, NULL);
133 for (i = 0; o1[i] && o2[i]; i++) {
134 testassert(o1[i] == o2[i]); // properties are not deep-copied
136 testassert(o1[i] == NULL && o2[i] == NULL);
140 // Check method calls
144 testassert(state == 2);
147 testassert(state == 2);
149 // #4511660 Make sure category implementation is still the preferred one
153 [obj instanceMethod];
154 testassert(state == 4);
159 [obj instanceMethod];
160 testassert(state == 4);