3 .*getMethod.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
4 .*getMethod.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
5 .*getMethod.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
6 .*getMethod.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
12 #include <objc/runtime.h>
13 #include <objc/message.h>
17 @interface Super : TestRoot @end
19 +(void)classMethod { state = 1; }
20 -(void)instanceMethod { state = 4; }
21 +(void)classMethodSuperOnly { state = 3; }
22 -(void)instanceMethodSuperOnly { state = 6; }
25 @interface Sub : Super @end
27 +(void)classMethod { state = 2; }
28 -(void)instanceMethod { state = 5; }
31 typedef void (*imp_t)(id, SEL);
35 Class Super_cls, Sub_cls;
41 id bufobj = (__bridge_transfer id)(void*)buf;
43 // don't use [Super class] to check laziness handing
44 Super_cls = objc_getClass("Super");
45 Sub_cls = objc_getClass("Sub");
47 sel = sel_registerName("classMethod");
48 m = class_getClassMethod(Super_cls, sel);
50 testassert(sel == method_getName(m));
51 imp = method_getImplementation(m);
52 testassert(imp == class_getMethodImplementation(object_getClass(Super_cls), sel));
53 testassert(imp == object_getMethodImplementation(Super_cls, sel));
55 (*(imp_t)imp)(Super_cls, sel);
56 testassert(state == 1);
58 sel = sel_registerName("classMethod");
59 m = class_getClassMethod(Sub_cls, sel);
61 testassert(sel == method_getName(m));
62 imp = method_getImplementation(m);
63 testassert(imp == class_getMethodImplementation(object_getClass(Sub_cls), sel));
64 testassert(imp == object_getMethodImplementation(Sub_cls, sel));
66 (*(imp_t)imp)(Sub_cls, sel);
67 testassert(state == 2);
69 sel = sel_registerName("classMethodSuperOnly");
70 m = class_getClassMethod(Sub_cls, sel);
72 testassert(sel == method_getName(m));
73 imp = method_getImplementation(m);
74 testassert(imp == class_getMethodImplementation(object_getClass(Sub_cls), sel));
75 testassert(imp == object_getMethodImplementation(Sub_cls, sel));
77 (*(imp_t)imp)(Sub_cls, sel);
78 testassert(state == 3);
80 sel = sel_registerName("instanceMethod");
81 m = class_getInstanceMethod(Super_cls, sel);
83 testassert(sel == method_getName(m));
84 imp = method_getImplementation(m);
85 testassert(imp == class_getMethodImplementation(Super_cls, sel));
87 testassert(imp == object_getMethodImplementation(bufobj, sel));
89 (*(imp_t)imp)(bufobj, sel);
90 testassert(state == 4);
92 sel = sel_registerName("instanceMethod");
93 m = class_getInstanceMethod(Sub_cls, sel);
95 testassert(sel == method_getName(m));
96 imp = method_getImplementation(m);
97 testassert(imp == class_getMethodImplementation(Sub_cls, sel));
99 testassert(imp == object_getMethodImplementation(bufobj, sel));
101 (*(imp_t)imp)(bufobj, sel);
102 testassert(state == 5);
104 sel = sel_registerName("instanceMethodSuperOnly");
105 m = class_getInstanceMethod(Sub_cls, sel);
107 testassert(sel == method_getName(m));
108 imp = method_getImplementation(m);
109 testassert(imp == class_getMethodImplementation(Sub_cls, sel));
111 testassert(imp == object_getMethodImplementation(bufobj, sel));
113 (*(imp_t)imp)(bufobj, sel);
114 testassert(state == 6);
116 // check class_getClassMethod(cls) == class_getInstanceMethod(cls->isa)
117 sel = sel_registerName("classMethod");
118 testassert(class_getClassMethod(Sub_cls, sel) == class_getInstanceMethod(object_getClass(Sub_cls), sel));
120 sel = sel_registerName("nonexistent");
121 testassert(! class_getInstanceMethod(Sub_cls, sel));
122 testassert(! class_getClassMethod(Sub_cls, sel));
123 testassert(class_getMethodImplementation(Sub_cls, sel) == (IMP)&_objc_msgForward);
125 testassert(object_getMethodImplementation(bufobj, sel) == (IMP)&_objc_msgForward);
127 testassert(class_getMethodImplementation_stret(Sub_cls, sel) == (IMP)&_objc_msgForward_stret);
128 testassert(object_getMethodImplementation_stret(bufobj, sel) == (IMP)&_objc_msgForward_stret);
131 testassert(! class_getInstanceMethod(NULL, NULL));
132 testassert(! class_getInstanceMethod(NULL, sel));
133 testassert(! class_getInstanceMethod(Sub_cls, NULL));
134 testassert(! class_getClassMethod(NULL, NULL));
135 testassert(! class_getClassMethod(NULL, sel));
136 testassert(! class_getClassMethod(Sub_cls, NULL));