2 #include <objc/objc-runtime.h>
4 #include <objc/objc-auto.h>
14 @interface Super<Proto> {
25 +class { return self; }
26 +new { return class_createInstance(self, 0); }
27 -(void)dealloc { object_dispose(self); }
33 -(void)instanceMethod {
40 @implementation Super (Category)
46 -(void)instanceMethod {
61 clone = objc_duplicateClass(cls, "Super_copy", 0);
63 if (objc_collecting_enabled()) {
64 testassert(auto_zone_size(auto_zone(), clone));
65 // objc_duplicateClass() doesn't duplicate the metaclass
66 // no: testassert(auto_zone_size(auto_zone(), clone->isa));
70 testassert(clone != cls);
71 testassert(clone->isa == cls->isa);
72 testassert(class_getSuperclass(clone) == class_getSuperclass(cls));
73 testassert(class_getVersion(clone) == class_getVersion(cls));
74 testassert(class_isMetaClass(clone) == class_isMetaClass(cls));
75 testassert(class_getIvarLayout(clone) == class_getIvarLayout(cls));
76 testassert(class_getWeakIvarLayout(clone) == class_getWeakIvarLayout(cls));
78 testassert((clone->info & (CLS_CLASS|CLS_META)) == (cls->info & (CLS_CLASS|CLS_META)));
83 m1 = class_copyMethodList(cls, NULL);
84 m2 = class_copyMethodList(clone, NULL);
87 for (i = 0; m1[i] && m2[i]; i++) {
88 testassert(m1[i] != m2[i]); // method list must be deep-copied
89 testassert(method_getName(m1[i]) == method_getName(m2[i]));
90 testassert(method_getImplementation(m1[i]) == method_getImplementation(m2[i]));
91 testassert(method_getTypeEncoding(m1[i]) == method_getTypeEncoding(m2[i]));
93 testassert(m1[i] == NULL && m2[i] == NULL);
98 Ivar *i1 = class_copyIvarList(cls, NULL);
99 Ivar *i2 = class_copyIvarList(clone, NULL);
102 for (i = 0; i1[i] && i2[i]; i++) {
103 testassert(i1[i] == i2[i]); // ivars are not deep-copied
105 testassert(i1[i] == NULL && i2[i] == NULL);
109 // Check protocol list
110 Protocol **p1 = class_copyProtocolList(cls, NULL);
111 Protocol **p2 = class_copyProtocolList(clone, NULL);
114 for (i = 0; p1[i] && p2[i]; i++) {
115 testassert(p1[i] == p2[i]); // protocols are not deep-copied
117 testassert(p1[i] == NULL && p2[i] == NULL);
121 // Check property list
122 objc_property_t *o1 = class_copyPropertyList(cls, NULL);
123 objc_property_t *o2 = class_copyPropertyList(clone, NULL);
126 for (i = 0; o1[i] && o2[i]; i++) {
127 testassert(o1[i] == o2[i]); // properties are not deep-copied
129 testassert(o1[i] == NULL && o2[i] == NULL);
133 // Check method calls
137 testassert(state == 2);
140 testassert(state == 2);
142 // #4511660 Make sure category implementation is still the preferred one
146 [obj instanceMethod];
147 testassert(state == 4);
152 [obj instanceMethod];
153 testassert(state == 4);