OSDN Git Service

In gcc/testsuite/:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 16 Oct 2010 14:07:29 +0000 (14:07 +0000)
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 16 Oct 2010 14:07:29 +0000 (14:07 +0000)
2010-10-16  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc.dg/gnu-api-2-ivar.m: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165543 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/gnu-api-2-ivar.m [new file with mode: 0644]

index 2556f00..4a3aa42 100644 (file)
@@ -1,3 +1,7 @@
+2010-10-16  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc.dg/gnu-api-2-ivar.m: New.
+
 2010-10-15  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * objc.dg/gnu-api-2-property.m: New.
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-ivar.m b/gcc/testsuite/objc.dg/gnu-api-2-ivar.m
new file mode 100644 (file)
index 0000000..914a439
--- /dev/null
@@ -0,0 +1,80 @@
+/* Test the Modern GNU Objective-C Runtime API.
+
+  This is test 'ivar', covering all functions starting with 'ivar'.  */
+
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
+
+/* To get the modern GNU Objective-C Runtime API, you include
+   objc/runtime.h.  */
+#include <objc/runtime.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@interface MyRootClass
+{ Class isa; }
++ alloc;
+- init;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init  { return self; }
+@end
+
+@protocol MyProtocol
+- (id) variable;
+@end
+
+@protocol MySecondProtocol
+- (id) setVariable: (id)value;
+@end
+
+@interface MySubClass : MyRootClass <MyProtocol>
+{ id variable_ivar; }
+- (void) setVariable: (id)value;
+- (id) variable;
+@end
+
+@implementation MySubClass
+- (void) setVariable: (id)value { variable_ivar = value; }
+- (id) variable { return variable_ivar; }
+@end
+
+
+int main(int argc, void **args)
+{
+  /* Functions are tested in alphabetical order.  */
+
+  printf ("Testing ivar_getName () ...\n");
+  {
+    Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
+                                          "variable_ivar");
+   if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
+      abort ();
+
+   ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
+                                    "variable");
+   if (ivar != 0)
+      abort ();
+  }
+
+  printf ("Testing ivar_getOffset () ...\n");
+  {
+    Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
+                                          "isa");
+    if (ivar_getOffset (ivar) != 0)
+      abort ();
+  }
+
+  printf ("Testing ivar_getTypeEncoding () ...\n");
+  {
+    Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
+                                          "variable_ivar");
+    if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)
+      abort ();
+  }
+
+  return 0;
+}