summaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm')
-rw-r--r--gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm101
1 files changed, 101 insertions, 0 deletions
diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
new file mode 100644
index 000000000..953e9bb15
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
@@ -0,0 +1,101 @@
+/* Test the Modern GNU Objective-C Runtime API.
+
+ This is test 'property', covering all functions starting with 'property'. */
+
+/* { dg-do run } */
+/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-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;
++ initialize;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init { return self; }
++ initialize { return self; }
+@end
+
+@interface MySubClass : MyRootClass
+{
+ id propertyA;
+ id propertyB;
+}
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign, nonatomic) id propertyB;
+@end
+
+@implementation MySubClass
+@synthesize propertyA;
+@synthesize propertyB;
+@end
+
+
+int main ()
+{
+ /* Functions are tested in alphabetical order. */
+
+ std::cout << "Testing property_getAttributes () ...\n";
+ {
+ /* The Apple/NeXT runtime seems to crash on the following. */
+#ifdef __GNU_LIBOBJC__
+ if (property_getAttributes (NULL) != NULL)
+ abort ();
+#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (std::strcmp (property_getAttributes (property),
+ "T@,GgetP,SsetP:,VpropertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (std::strcmp (property_getAttributes (property),
+ "T@,N,VpropertyB") != 0)
+ abort ();
+ }
+#endif
+ }
+
+ std::cout << "Testing property_getName () ...\n";
+ {
+ /* The Apple/NeXT runtime seems to crash on the following. */
+#ifdef __GNU_LIBOBJC__
+
+ if (property_getName (NULL) != NULL)
+ abort ();
+#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (std::strcmp (property_getName (property), "propertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (std::strcmp (property_getName (property), "propertyB") != 0)
+ abort ();
+ }
+#endif
+ }
+
+ return (0);
+}