aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-15 10:37:33 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-15 10:37:33 +0000
commit28c3bb954a5068c8e586587b79b01b7a72be35b1 (patch)
treecd28d783965945732411d0b6c7945cbbfc234269
parentf7185d479171342a33ffc2bc76226e86d400a785 (diff)
downloadgcc-28c3bb954a5068c8e586587b79b01b7a72be35b1.zip
gcc-28c3bb954a5068c8e586587b79b01b7a72be35b1.tar.gz
gcc-28c3bb954a5068c8e586587b79b01b7a72be35b1.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-protocol.m: New. * objc.dg/gnu-api-2-sel.m: New. From-SVN: r165500
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/objc.dg/gnu-api-2-protocol.m160
-rw-r--r--gcc/testsuite/objc.dg/gnu-api-2-sel.m103
3 files changed, 268 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4f2df7c..306aed3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * objc.dg/gnu-api-2-protocol.m: New.
+ * objc.dg/gnu-api-2-sel.m: New.
+
2010-10-15 Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
* g++.dg/torture/stackalign/eh-vararg-2.C: Fix dg-options for
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-protocol.m b/gcc/testsuite/objc.dg/gnu-api-2-protocol.m
new file mode 100644
index 0000000..537e5df
--- /dev/null
+++ b/gcc/testsuite/objc.dg/gnu-api-2-protocol.m
@@ -0,0 +1,160 @@
+/* Test the Modern GNU Objective-C Runtime API.
+
+ This is test 'protocol', covering all functions starting with 'protocol'. */
+
+/* { 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
+
+@protocol MyThirdProtocol <MySecondProtocol>
+- (id) setAnotherVariable: (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 protocol_conformsToProtocol ()...\n");
+ {
+ if (!protocol_conformsToProtocol (@protocol (MyProtocol),
+ @protocol (MyProtocol)))
+ abort ();
+
+ if (!protocol_conformsToProtocol (@protocol (MyThirdProtocol),
+ @protocol (MySecondProtocol)))
+ abort ();
+
+ if (protocol_conformsToProtocol (@protocol (MyProtocol),
+ @protocol (MySecondProtocol)))
+ abort ();
+ }
+
+ printf ("Testing protocol_copyMethodDescriptionList ()...\n");
+ {
+ unsigned int count;
+ struct objc_method_description *list;
+
+ list = protocol_copyMethodDescriptionList (@protocol (MyThirdProtocol),
+ YES, YES, &count);
+
+ if (count != 1)
+ abort ();
+
+ if (strcmp (sel_getName (list[0].name), "setAnotherVariable:") != 0)
+ abort ();
+
+ if (list[1].name != NULL && list[1].types != NULL)
+ abort ();
+ }
+
+ /* TODO: Test new ABI (when available). */
+ printf ("Testing protocol_copyPropertyList ()...\n");
+ {
+ unsigned int count;
+ Property *list;
+
+ list = protocol_copyPropertyList (@protocol (MyProtocol), &count);
+
+ if (count != 0 || list != NULL)
+ abort ();
+ }
+
+ printf ("Testing protocol_copyProtocolList ()...\n");
+ {
+ unsigned int count;
+ Protocol **list;
+
+ list = protocol_copyProtocolList (@protocol (MyThirdProtocol), &count);
+
+ if (count != 1)
+ abort ();
+
+ if (strcmp (protocol_getName (list[0]), "MySecondProtocol") != 0)
+ abort ();
+
+ if (list[1] != NULL)
+ abort ();
+ }
+
+ printf ("Testing protocol_getMethodDescription ()...\n");
+ {
+ struct objc_method_description description;
+
+ description = protocol_getMethodDescription (@protocol (MySecondProtocol),
+ @selector (setVariable:),
+ YES, YES);
+ if (description.name == NULL && description.types == NULL)
+ abort ();
+
+ if (strcmp (sel_getName (description.name), "setVariable:") != 0)
+ abort ();
+ }
+
+ printf ("Testing protocol_getName ()...\n");
+ {
+ if (strcmp (protocol_getName (@protocol (MyProtocol)), "MyProtocol") != 0)
+ abort ();
+ }
+
+ /* TODO: Test new ABI (when available). */
+ printf ("Testing protocol_getProperty ()...\n");
+ {
+ Property property;
+
+ property = protocol_getProperty (objc_getProtocol ("MyProtocol"), "someProperty",
+ YES, YES);
+
+ if (property != NULL)
+ abort ();
+ }
+
+ printf ("Testing protocol_isEqual ()...\n");
+ {
+ if (!protocol_isEqual (@protocol (MyProtocol),
+ @protocol (MyProtocol)))
+ abort ();
+
+ if (!protocol_isEqual (@protocol (MyProtocol),
+ objc_getProtocol ("MyProtocol")))
+ abort ();
+ }
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-sel.m b/gcc/testsuite/objc.dg/gnu-api-2-sel.m
new file mode 100644
index 0000000..e710083
--- /dev/null
+++ b/gcc/testsuite/objc.dg/gnu-api-2-sel.m
@@ -0,0 +1,103 @@
+/* Test the Modern GNU Objective-C Runtime API.
+
+ This is test 'sel', covering all functions starting with 'sel'. */
+
+/* { 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 sel_getName () ...\n");
+ {
+ if (strcmp (sel_getName (@selector (variable)), "variable") != 0)
+ abort ();
+
+ if (strcmp (sel_getName (NULL), "<null selector>") != 0)
+ abort ();
+ }
+
+ printf ("Testing sel_getType () ...\n");
+ {
+ /* Get a selector from a real class, so it has interesting
+ types. */
+ Method method = class_getInstanceMethod (objc_getClass ("MySubClass"),
+ @selector (variable));
+
+ if (strcmp (sel_getType (method_getName (method)), method_getTypeEncoding (method)) != 0)
+ abort ();
+ }
+
+ printf ("Testing sel_getUid () ...\n");
+ {
+ if (strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0)
+ abort ();
+ }
+
+ printf ("Testing sel_isEqual () ...\n");
+ {
+ if (! sel_isEqual (@selector (setVariable:), @selector (setVariable:)))
+ abort ();
+ }
+
+ printf ("Testing sel_registerName () ...\n");
+ {
+ if (strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0)
+ abort ();
+ }
+
+ printf ("Testing set_registerTypedName () ...\n");
+ {
+ const char *types = method_getTypeEncoding (class_getInstanceMethod
+ (objc_getClass ("MySubClass"),
+ @selector (variable)));
+ SEL selector = sel_registerTypedName ("aMethod", types);
+
+ if (strcmp (sel_getName (selector), "aMethod") != 0)
+ abort ();
+
+ if (strcmp (sel_getType (selector), types) != 0)
+ abort ();
+ }
+
+ return 0;
+}