aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-15 23:00:22 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-15 23:00:22 +0000
commitd527c90aa56dfdcf6798f58ca0199e1a56043981 (patch)
tree92f69f57b2657e83cb7aefef2920f3c52105285e /gcc
parent28395a0239de38fd77e6c07d9fd5f7fc939c2f5b (diff)
downloadgcc-d527c90aa56dfdcf6798f58ca0199e1a56043981.zip
gcc-d527c90aa56dfdcf6798f58ca0199e1a56043981.tar.gz
gcc-d527c90aa56dfdcf6798f58ca0199e1a56043981.tar.bz2
In gcc/testsuite/: 2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/testsuite/: 2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/gnu-api-2-object.m: New. From-SVN: r165529
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/objc.dg/gnu-api-2-object.m161
2 files changed, 165 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 86675d8..43f2aa0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com>
+ * objc.dg/gnu-api-2-object.m: New.
+
+2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com>
+
* objc.dg/gnu-api-2-method.m: New.
2010-10-15 Jason Merrill <jason@redhat.com>
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-object.m b/gcc/testsuite/objc.dg/gnu-api-2-object.m
new file mode 100644
index 0000000..6068411
--- /dev/null
+++ b/gcc/testsuite/objc.dg/gnu-api-2-object.m
@@ -0,0 +1,161 @@
+/* Test the Modern GNU Objective-C Runtime API.
+
+ This is test 'object', covering all functions starting with 'object'. */
+
+/* { 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
+
+@interface MySubSubClass : MySubClass
+- (id) test;
+@end
+
+@implementation MySubSubClass
+- (id) test { return self; }
+@end
+
+
+
+int main(int argc, void **args)
+{
+ /* Functions are tested in alphabetical order. */
+
+ printf ("Testing object_copy () ...\n");
+ {
+ MySubClass *object_a = [[MySubClass alloc] init];
+ MySubClass *object_b = object_copy (object_a, 0);
+
+ [object_b setVariable: object_a];
+ if ([object_b variable] != object_a)
+ abort ();
+ }
+
+ printf ("Testing object_dispose () ...\n");
+ {
+ MySubClass *object = [[MySubClass alloc] init];
+
+ object_dispose (object);
+ }
+
+ printf ("Testing object_getClass () ...\n");
+ {
+ MyRootClass *o = [[MySubClass alloc] init];
+
+ if (object_getClass (o) != objc_getClass ("MySubClass"))
+ abort ();
+ }
+
+ printf ("Testing object_getClassName () ...\n");
+ {
+ MyRootClass *o = [[MyRootClass alloc] init];
+
+ if (strcmp (object_getClassName (o), "MyRootClass") != 0)
+ abort ();
+ }
+
+ printf ("Testing object_getIndexedIvars () ...\n");
+ {
+ if (object_getIndexedIvars ([[MyRootClass alloc] init]) == NULL)
+ abort ();
+ }
+
+ printf ("Testing object_getInstanceVariable () ...\n");
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+ id value;
+
+ [o setVariable: o];
+
+ if (object_getInstanceVariable (o, "variable_ivar", (void **)&value) == NULL)
+ abort ();
+
+ if (value != o)
+ abort ();
+ }
+
+ printf ("Testing object_getIvar () ...\n");
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+ Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"), "variable_ivar");
+
+ [o setVariable: o];
+
+ if (object_getIvar (o, ivar) != o)
+ abort ();
+ }
+
+ printf ("Testing object_setClass () ...\n");
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+
+ object_setClass (o, objc_getClass ("MySubSubClass"));
+
+ if ([(MySubSubClass *)o test] != o)
+ abort ();
+ }
+
+ printf ("Testing object_setInstanceVariable () ...\n");
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+
+ [o setVariable: nil];
+
+ if (object_setInstanceVariable (o, "variable_ivar", (void *)o) == NULL)
+ abort ();
+
+ if ([o variable] != o)
+ abort ();
+ }
+
+ printf ("Testing object_setIvar () ...\n");
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+ MySubClass *value = [[MySubClass alloc] init];
+ Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"), "variable_ivar");
+
+ [o setVariable: o];
+
+ object_setIvar (o, ivar, value);
+
+ if ([o variable] != value)
+ abort ();
+ }
+
+ return 0;
+}