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" } { "" } } */
9 /* To get the modern GNU Objective-C Runtime API, you include
11 #include <objc/runtime.h>
13 /* For objc_msg_lookup(), objc_msg_lookup_super() and struct
15 #include <objc/message.h>
21 @interface MyRootClass
28 @implementation MyRootClass
29 + alloc { return class_createInstance (self, 0); }
30 - init { return self; }
31 - (int) test { return 20; }
34 @interface MySubClass : MyRootClass
38 @implementation MySubClass
39 - (int) test { return 11; }
44 /* Functions are tested in alphabetical order. */
46 std::cout << "Testing objc_msg_lookup () ...\n";
48 MySubClass *object = [[MySubClass alloc] init];
49 int (* test_IMP) (id receiver, SEL selector);
51 test_IMP = (int (*)(id, SEL))objc_msg_lookup (object, @selector (test));
53 if (test_IMP (object, @selector (test)) != 11)
57 std::cout << "Testing objc_msg_lookup_super () ...\n";
59 MySubClass *object = [[MySubClass alloc] init];
60 struct objc_super super = { 0, 0 };
61 int (* test_IMP) (id receiver, SEL selector);
63 /* Get the implementation of -test for the superclass of object -
64 as if we were calling [super test] inside a method
65 implementation of object. */
67 super.super_class = class_getSuperclass (object_getClass (object));
68 test_IMP = (int (*)(id, SEL))objc_msg_lookup_super (&super, @selector (test));
70 /* Invoke it. The method in MyRootClass, not the one in
71 MySubClass, should be invoked. */
72 if (test_IMP (object, @selector (test)) != 20)