Debian Codegraph @

gcc/testsuite/objc.dg/gnu-api-2-objc_msg_lookup.m

raw
1 /* Test the Modern GNU Objective-C Runtime API.
2
3 This is test 'objc_msg_lookup', covering objc_msg_lookup(),
4 objc_msg_lookup_super() and struct objc_super. */
5
6 /* { dg-do run } */
7 /* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
8 /* { dg-additional-options "-Wno-objc-root-class" } */
9
10 /* To get the modern GNU Objective-C Runtime API, you include
11 objc/runtime.h. */
12 #include <objc/runtime.h>
13
14 /* For objc_msg_lookup(), objc_msg_lookup_super() and struct
15 objc_super. */
16 #include <objc/message.h>
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21
22 @interface MyRootClass
23 { Class isa; }
24 + alloc;
25 - init;
26 - (int) test;
27 @end
28
29 @implementation MyRootClass
30 + alloc { return class_createInstance (self, 0); }
31 - init { return self; }
32 - (int) test { return 20; }
33 @end
34
35 @interface MySubClass : MyRootClass
36 - (int) test;
37 @end
38
39 @implementation MySubClass
40 - (int) test { return 11; }
41 @end
42
43 int main (int argc, void **args)
44 {
45 /* Functions are tested in alphabetical order. */
46
47 printf ("Testing objc_msg_lookup ()...\n");
48 {
49 MySubClass *object = [[MySubClass alloc] init];
50 int (* test_IMP) (id receiver, SEL selector);
51
52 test_IMP = (int (*)(id, SEL))objc_msg_lookup (object, @selector (test));
53
54 if (test_IMP (object, @selector (test)) != 11)
55 abort ();
56 }
57
58 printf ("Testing objc_msg_lookup_super ()...\n");
59 {
60 MySubClass *object = [[MySubClass alloc] init];
61 struct objc_super super = { 0, 0 };
62 int (* test_IMP) (id receiver, SEL selector);
63
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. */
67 super.self = object;
68 super.super_class = class_getSuperclass (object_getClass (object));
69 test_IMP = (int (*)(id, SEL))objc_msg_lookup_super (&super, @selector (test));
70
71 /* Invoke it. The method in MyRootClass, not the one in
72 MySubClass, should be invoked. */
73 if (test_IMP (object, @selector (test)) != 20)
74 abort ();
75 }
76
77 return 0;
78 }