aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-17 19:33:19 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-17 19:33:19 +0000
commit5b8b526e694bca2034af4cdeb8ad15e356446a98 (patch)
tree21e63a2c01fdd1ab461d151039afa15a5bfe542e /gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm
parent91b90ead334deba8a963afbf1cb6947ca16bf2ff (diff)
downloadgcc-5b8b526e694bca2034af4cdeb8ad15e356446a98.zip
gcc-5b8b526e694bca2034af4cdeb8ad15e356446a98.tar.gz
gcc-5b8b526e694bca2034af4cdeb8ad15e356446a98.tar.bz2
In gcc/: 2010-10-17 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/: 2010-10-17 Nicola Pero <nicola.pero@meta-innovation.com> * doc/objc.texi (GNU Objective-C runtime API): New section. (Modern GNU Objective-C runtime API): New section. (Traditional GNU Objective-C runtime API): New section. (Executing code before main): Mention that this section is specific to the GNU Objective-C runtime. (Garbage Collection): Same. In gcc/testsuite/: 2010-10-17 Nicola Pero <nicola.pero@meta-innovation.com> * obj-c++.dg/gnu-api-2-class.mm: New. * obj-c++.dg/gnu-api-2-ivar.mm: New. * obj-c++.dg/gnu-api-2-method.mm: New. * obj-c++.dg/gnu-api-2-objc.mm: New. * obj-c++.dg/gnu-api-2-object.mm: New. * obj-c++.dg/gnu-api-2-property.mm: New. * obj-c++.dg/gnu-api-2-protocol.mm: New. * obj-c++.dg/gnu-api-2-sel.mm: New. In libobjc/: 2010-10-17 Nicola Pero <nicola.pero@meta-innovation.com> * objc/message.h: Moved initial includes outside of extern "C". * objc/runtime.h: Add extern "C" for Objective-C++. From-SVN: r165595
Diffstat (limited to 'gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm')
-rw-r--r--gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm161
1 files changed, 161 insertions, 0 deletions
diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm
new file mode 100644
index 0000000..2a54447
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-object.mm
@@ -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 <iostream>
+#include <cstring>
+
+@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 ()
+{
+ /* Functions are tested in alphabetical order. */
+
+ std::cout << "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 ();
+ }
+
+ std::cout << "Testing object_dispose () ...\n";
+ {
+ MySubClass *object = [[MySubClass alloc] init];
+
+ object_dispose (object);
+ }
+
+ std::cout << "Testing object_getClass () ...\n";
+ {
+ MyRootClass *o = [[MySubClass alloc] init];
+
+ if (object_getClass (o) != objc_getClass ("MySubClass"))
+ abort ();
+ }
+
+ std::cout << "Testing object_getClassName () ...\n";
+ {
+ MyRootClass *o = [[MyRootClass alloc] init];
+
+ if (std::strcmp (object_getClassName (o), "MyRootClass") != 0)
+ abort ();
+ }
+
+ std::cout << "Testing object_getIndexedIvars () ...\n";
+ {
+ if (object_getIndexedIvars ([[MyRootClass alloc] init]) == NULL)
+ abort ();
+ }
+
+ std::cout << "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 ();
+ }
+
+ std::cout << "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 ();
+ }
+
+ std::cout << "Testing object_setClass () ...\n";
+ {
+ MySubClass *o = [[MySubClass alloc] init];
+
+ object_setClass (o, objc_getClass ("MySubSubClass"));
+
+ if ([(MySubSubClass *)o test] != o)
+ abort ();
+ }
+
+ std::cout << "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 ();
+ }
+
+ std::cout << "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);
+}