1 // TEST_CFLAGS -Wno-deprecated-declarations -Wl,-no_objc_category_merging
5 #include <objc/runtime.h>
11 -(void)instanceMethod;
14 @interface Super : TestRoot <Proto> {
27 -(void)instanceMethod {
35 #pragma clang diagnostic push
36 #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
39 @implementation Super (Category)
45 -(void)instanceMethod {
52 #pragma clang diagnostic pop
64 clone = objc_duplicateClass(cls, "Super_copy", 0);
66 testassert(clone != cls);
67 testassert(object_getClass(clone) == object_getClass(cls));
68 testassert(class_getSuperclass(clone) == class_getSuperclass(cls));
69 testassert(class_getVersion(clone) == class_getVersion(cls));
70 testassert(class_isMetaClass(clone) == class_isMetaClass(cls));
71 testassert(class_getIvarLayout(clone) == class_getIvarLayout(cls));
72 testassert(class_getWeakIvarLayout(clone) == class_getWeakIvarLayout(cls));
76 m1 = class_copyMethodList(cls, NULL);
77 m2 = class_copyMethodList(clone, NULL);
80 for (i = 0; m1[i] && m2[i]; i++) {
81 testassert(m1[i] != m2[i]); // method list must be deep-copied
82 testassert(method_getName(m1[i]) == method_getName(m2[i]));
83 testassert(method_getImplementation(m1[i]) == method_getImplementation(m2[i]));
84 testassert(method_getTypeEncoding(m1[i]) == method_getTypeEncoding(m2[i]));
86 testassert(m1[i] == NULL && m2[i] == NULL);
91 Ivar *i1 = class_copyIvarList(cls, NULL);
92 Ivar *i2 = class_copyIvarList(clone, NULL);
95 for (i = 0; i1[i] && i2[i]; i++) {
96 testassert(i1[i] == i2[i]); // ivars are not deep-copied
98 testassert(i1[i] == NULL && i2[i] == NULL);
102 // Check protocol list
103 Protocol * __unsafe_unretained *p1 = class_copyProtocolList(cls, NULL);
104 Protocol * __unsafe_unretained *p2 = class_copyProtocolList(clone, NULL);
107 for (i = 0; p1[i] && p2[i]; i++) {
108 testassert(p1[i] == p2[i]); // protocols are not deep-copied
110 testassert(p1[i] == NULL && p2[i] == NULL);
114 // Check property list
115 objc_property_t *o1 = class_copyPropertyList(cls, NULL);
116 objc_property_t *o2 = class_copyPropertyList(clone, NULL);
119 for (i = 0; o1[i] && o2[i]; i++) {
120 testassert(o1[i] == o2[i]); // properties are not deep-copied
122 testassert(o1[i] == NULL && o2[i] == NULL);
126 // Check method calls
130 testassert(state == 2);
133 testassert(state == 2);
135 // #4511660 Make sure category implementation is still the preferred one
139 [obj instanceMethod];
140 testassert(state == 4);
145 [obj instanceMethod];
146 testassert(state == 4);