2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc.dg / encode-4.m
blob1f179e1dad5ef01e138b3748eb07fd09e1c29b3b
1 /* Encoding tests for ObjC class layouts.  */
2 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
3 /* { dg-options "-lobjc" } */
4 /* { dg-do run } */
6 #include <objc/Object.h>
7 #ifdef __NEXT_RUNTIME__
8 #include <objc/objc-class.h>
9 #define OBJC_GETCLASS objc_getClass
10 #else
11 #include <objc/objc-api.h>
12 #define OBJC_GETCLASS objc_get_class
13 #endif
15 extern void abort(void);
16 extern int strcmp(const char *s1, const char *s2);
17 #define CHECK_IF(expr) if(!(expr)) abort()
19 @class Int1, Int2;
20 struct Nested;
22 struct Innermost {
23   unsigned char a, b;
24   struct Nested *encl;
27 struct Nested {
28   float a, b;
29   Int1 *next;
30   struct Innermost innermost;
33 @interface Int1: Object {
34   char a, b;
35   Int2 *int2;
36   struct Nested nested;
38 @end
40 @interface Int2: Int1 {
41   struct Innermost *innermost;
42   Int1 *base;
44 @end
46 @implementation Int1
47 @end
49 @implementation Int2
50 @end
52 struct objc_ivar *ivar;
54 static void check_ivar(const char *name, const char *type) {
55   CHECK_IF(!strcmp(ivar->ivar_name, name));
56   CHECK_IF(!strcmp(ivar->ivar_type, type));
57   ivar++;
60 int main(void) {
61   ivar = ((Class)OBJC_GETCLASS("Int1"))->ivars->ivar_list;
62   check_ivar("a", "c");
63   check_ivar("b", "c");
64   check_ivar("int2", "@\"Int2\"");
65   check_ivar("nested", 
66     "{Nested=\"a\"f\"b\"f\"next\"@\"Int1\"\"innermost\"{Innermost=\"a\"C\"b\"C\"encl\"^{Nested}}}");
67     
68   ivar = ((Class)OBJC_GETCLASS("Int2"))->ivars->ivar_list;
69   check_ivar("innermost", "^{Innermost=CC^{Nested}}");
70   check_ivar("base", "@\"Int1\"");
71   
72   return 0;