From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm | 163 +++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm (limited to 'gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm') diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm new file mode 100644 index 000000000..9a2ceca13 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-protocol.mm @@ -0,0 +1,163 @@ +/* Test the Modern GNU Objective-C Runtime API. + + This is test 'protocol', covering all functions starting with 'protocol'. */ + +/* { dg-do run } */ +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include +#include +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; ++ initialize; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } ++ initialize { return self; } +@end + +@protocol MyProtocol +- (id) variable; +@end + +@protocol MySecondProtocol +- (id) setVariable: (id)value; +@end + +@protocol MyThirdProtocol +- (id) setAnotherVariable: (id)value; +@end + +@interface MySubClass : MyRootClass +{ 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 () +{ + /* Functions are tested in alphabetical order. */ + + std::cout << "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 (); + } + + std::cout << "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 (std::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). */ + std::cout << "Testing protocol_copyPropertyList ()...\n"; + { + unsigned int count; + objc_property_t *list; + + list = protocol_copyPropertyList (@protocol (MyProtocol), &count); + + if (count != 0 || list != NULL) + abort (); + } + + std::cout << "Testing protocol_copyProtocolList ()...\n"; + { + unsigned int count; + Protocol **list; + + list = protocol_copyProtocolList (@protocol (MyThirdProtocol), &count); + + if (count != 1) + abort (); + + if (std::strcmp (protocol_getName (list[0]), "MySecondProtocol") != 0) + abort (); + + if (list[1] != NULL) + abort (); + } + + std::cout << "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 (std::strcmp (sel_getName (description.name), "setVariable:") != 0) + abort (); + } + + std::cout << "Testing protocol_getName ()...\n"; + { + if (std::strcmp (protocol_getName (@protocol (MyProtocol)), "MyProtocol") != 0) + abort (); + } + + /* TODO: Test new ABI (when available). */ + std::cout << "Testing protocol_getProperty ()...\n"; + { + objc_property_t property; + + property = protocol_getProperty (objc_getProtocol ("MyProtocol"), "someProperty", + YES, YES); + + if (property != NULL) + abort (); + } + + std::cout << "Testing protocol_isEqual ()...\n"; + { + if (!protocol_isEqual (@protocol (MyProtocol), + @protocol (MyProtocol))) + abort (); + + if (!protocol_isEqual (@protocol (MyProtocol), + objc_getProtocol ("MyProtocol"))) + abort (); + } + + return (0); +} -- cgit v1.2.3