Revise -mdisable-fpregs option and add new -msoft-mult option
[official-gcc.git] / gcc / testsuite / objc.dg / gnu-api-2-objc_msg_lookup.m
blobd417225cdfb094ad6145db913fd0dc556dfbd3a4
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.  */
6 /* { dg-do run } */
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
11    objc/runtime.h.  */
12 #include <objc/runtime.h>
14 /* For objc_msg_lookup(), objc_msg_lookup_super() and struct
15    objc_super.  */
16 #include <objc/message.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
22 @interface MyRootClass
23 { Class isa; }
24 + alloc;
25 - init;
26 - (int) test;
27 @end
29 @implementation MyRootClass
30 + alloc { return class_createInstance (self, 0); }
31 - init  { return self; }
32 - (int) test { return 20; }
33 @end
35 @interface MySubClass : MyRootClass
36 - (int) test;
37 @end
39 @implementation MySubClass
40 - (int) test { return 11; }
41 @end
43 int main (int argc, void **args)
45   /* Functions are tested in alphabetical order.  */
47   printf ("Testing objc_msg_lookup ()...\n");
48   {
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));    
53     
54     if (test_IMP (object, @selector (test)) != 11)
55       abort ();
56   }
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);
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));
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   }
77   return 0;