1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'objc_msg_lookup', covering objc_msg_lookup(),
4 objc_msg_lookup_super() and struct objc_super. */
7 /* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
8 /* { dg-additional-options "-Wno-objc-root-class" } */
10 /* To get the modern GNU Objective-C Runtime API, you include
12 #include <objc/runtime.h>
14 /* For objc_msg_lookup(), objc_msg_lookup_super() and struct
16 #include <objc/message.h>
22 @interface MyRootClass
29 @implementation MyRootClass
30 + alloc { return class_createInstance (self, 0); }
31 - init { return self; }
32 - (int) test { return 20; }
35 @interface MySubClass : MyRootClass
39 @implementation MySubClass
40 - (int) test { return 11; }
43 int main (int argc, void **args)
45 /* Functions are tested in alphabetical order. */
47 printf ("Testing objc_msg_lookup ()...\n");
49 MySubClass *object = [[MySubClass alloc] init];
50 int (* test_IMP) (id receiver, SEL selector);
52 test_IMP = (int (*)(id, SEL))objc_msg_lookup (object, @selector (test));
54 if (test_IMP (object, @selector (test)) != 11)
58 printf ("Testing objc_msg_lookup_super ()...\n");
60 MySubClass *object = [[MySubClass alloc] init];
61 struct objc_super super = { 0, 0 };
62 int (* test_IMP) (id receiver, SEL selector);
64 /* Get the implementation of -test for the superclass of object -
65 as if we were calling [super test] inside a method
66 implementation of object. */
68 super.super_class = class_getSuperclass (object_getClass (object));
69 test_IMP = (int (*)(id, SEL))objc_msg_lookup_super (&super, @selector (test));
71 /* Invoke it. The method in MyRootClass, not the one in
72 MySubClass, should be invoked. */
73 if (test_IMP (object, @selector (test)) != 20)