From 5750872c618185a2f1161d24510ad2be8669338a Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Fri, 24 Dec 2010 17:00:19 +0000 Subject: In libobjc/: 2010-12-24 Nicola Pero In libobjc/: 2010-12-24 Nicola Pero * objc/runtime.h (sel_getType): Renamed to sel_getTypeEncoding to be consistent with method_getTypeEncoding and ivar_getTypeEncoding. (sel_copyTypedSelectorList, sel_getTypedSelector): New. * selector.c (sel_getType): Renamed to sel_getTypeEncoding. (sel_copyTypedSelectorList, sel_getTypedSelector): New. (sel_get_type): Updated call to sel_getType. In gcc/testsuite/: 2010-12-24 Nicola Pero * objc.dg/gnu-api-2-sel.m: Updated for renaming of sel_getType to sel_getTypeEncoding. Test that sel_getTypeEncoding returns NULL when called with a NULL argument. Added test for sel_copyTypedSelectorList and sel_getTypedSelector. * obj-c++.dg/gnu-api-2-sel.mm: Same changes. From-SVN: r168229 --- gcc/testsuite/ChangeLog | 8 ++++ gcc/testsuite/obj-c++.dg/gnu-api-2-sel.mm | 70 +++++++++++++++++++++++++++++-- gcc/testsuite/objc.dg/gnu-api-2-sel.m | 68 ++++++++++++++++++++++++++++-- 3 files changed, 139 insertions(+), 7 deletions(-) (limited to 'gcc') diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 87bc46f..0140ced 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2010-12-24 Nicola Pero + + * objc.dg/gnu-api-2-sel.m: Updated for renaming of sel_getType to + sel_getTypeEncoding. Test that sel_getTypeEncoding returns NULL + when called with a NULL argument. Added test for + sel_copyTypedSelectorList and sel_getTypedSelector. + * obj-c++.dg/gnu-api-2-sel.mm: Same changes. + 2010-12-24 Eric Botcazou * gnat.dg/opt13_pkg.ad[sb]: Fix line ending. diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-sel.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-sel.mm index 66cf072..956ba29 100644 --- a/gcc/testsuite/obj-c++.dg/gnu-api-2-sel.mm +++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-sel.mm @@ -35,11 +35,13 @@ { id variable_ivar; } - (void) setVariable: (id)value; - (id) variable; +- (void) method; @end @implementation MySubClass - (void) setVariable: (id)value { variable_ivar = value; } - (id) variable { return variable_ivar; } +- (void) method { return; } @end @@ -47,6 +49,30 @@ int main () { /* Functions are tested in alphabetical order. */ + std::cout << "Testing sel_copyTypedSelectorList ()...\n"; + { + unsigned int count; + SEL * list = sel_copyTypedSelectorList ("method", &count); + + /* There should only be two, since 'method' is referenced twice, + once with types and once without (in this very test). */ + if (count != 2) + abort (); + + /* Check that both selectors are not-NULL, and have the correct + name. We use @selector() here, which wouldn't really be + needed, just to register a second, untyped selector with name + 'method'. */ + if (std::strcmp (sel_getName (list[0]), sel_getName (@selector (method))) != 0) + abort (); + + if (std::strcmp (sel_getName (list[1]), sel_getName (@selector (method))) != 0) + abort (); + + if (list[2] != NULL) + abort (); + } + std::cout << "Testing sel_getName () ...\n"; { if (std::strcmp (sel_getName (@selector (variable)), "variable") != 0) @@ -56,14 +82,50 @@ int main () abort (); } - std::cout << "Testing sel_getType () ...\n"; + std::cout << "Testing sel_getTypeEncoding () ...\n"; { /* Get a selector from a real class, so it has interesting types. */ Method method = class_getInstanceMethod (objc_getClass ("MySubClass"), @selector (variable)); - if (std::strcmp (sel_getType (method_getName (method)), method_getTypeEncoding (method)) != 0) + if (std::strcmp (sel_getTypeEncoding (method_getName (method)), + method_getTypeEncoding (method)) != 0) + abort (); + + if (sel_getTypeEncoding (NULL) != NULL) + abort (); + } + + std::cout << "Testing sel_getTypedSelector () ...\n"; + { + /* First try with a selector where we know that a typed one has + been registered. */ + SEL selector = sel_getTypedSelector ("variable"); + + if (selector == NULL) + abort (); + + if (sel_getTypeEncoding (selector) == NULL) + abort (); + + /* Now try a selector which was never registered. */ + selector = sel_getTypedSelector ("not_registered"); + + if (selector != NULL) + abort (); + + /* Now try registering a selector with no types. The following + line is just a way to have an unused '@selector()' expression + without the compiler complaining. */ + if (@selector (registered_with_no_types) == NULL) + abort (); + + /* Try getting it. Nothing should be returned because it is + untyped. */ + selector = sel_getTypedSelector ("registered_with_no_types"); + + if (selector != NULL) abort (); } @@ -91,11 +153,11 @@ int main () (objc_getClass ("MySubClass"), @selector (variable))); SEL selector = sel_registerTypedName ("aMethod", types); - + if (std::strcmp (sel_getName (selector), "aMethod") != 0) abort (); - if (std::strcmp (sel_getType (selector), types) != 0) + if (std::strcmp (sel_getTypeEncoding (selector), types) != 0) abort (); } diff --git a/gcc/testsuite/objc.dg/gnu-api-2-sel.m b/gcc/testsuite/objc.dg/gnu-api-2-sel.m index e710083..db2dcd3 100644 --- a/gcc/testsuite/objc.dg/gnu-api-2-sel.m +++ b/gcc/testsuite/objc.dg/gnu-api-2-sel.m @@ -35,11 +35,13 @@ { id variable_ivar; } - (void) setVariable: (id)value; - (id) variable; +- (void) method; @end @implementation MySubClass - (void) setVariable: (id)value { variable_ivar = value; } - (id) variable { return variable_ivar; } +- (void) method { return; } @end @@ -47,6 +49,30 @@ int main(int argc, void **args) { /* Functions are tested in alphabetical order. */ + printf ("Testing sel_copyTypedSelectorList ()...\n"); + { + unsigned int count; + SEL * list = sel_copyTypedSelectorList ("method", &count); + + /* There should only be two, since 'method' is referenced twice, + once with types and once without (in this very test). */ + if (count != 2) + abort (); + + /* Check that both selectors are not-NULL, and have the correct + name. We use @selector() here, which wouldn't really be + needed, just to register a second, untyped selector with name + 'method'. */ + if (strcmp (sel_getName (list[0]), sel_getName (@selector (method))) != 0) + abort (); + + if (strcmp (sel_getName (list[1]), sel_getName (@selector (method))) != 0) + abort (); + + if (list[2] != NULL) + abort (); + } + printf ("Testing sel_getName () ...\n"); { if (strcmp (sel_getName (@selector (variable)), "variable") != 0) @@ -56,14 +82,50 @@ int main(int argc, void **args) abort (); } - printf ("Testing sel_getType () ...\n"); + printf ("Testing sel_getTypeEncoding () ...\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) + if (strcmp (sel_getTypeEncoding (method_getName (method)), + method_getTypeEncoding (method)) != 0) + abort (); + + if (sel_getTypeEncoding (NULL) != NULL) + abort (); + } + + printf ("Testing sel_getTypedSelector () ...\n"); + { + /* First try with a selector where we know that a typed one has + been registered. */ + SEL selector = sel_getTypedSelector ("variable"); + + if (selector == NULL) + abort (); + + if (sel_getTypeEncoding (selector) == NULL) + abort (); + + /* Now try a selector which was never registered. */ + selector = sel_getTypedSelector ("not_registered"); + + if (selector != NULL) + abort (); + + /* Now try registering a selector with no types. The following + line is just a way to have an unused '@selector()' expression + without the compiler complaining. */ + if (@selector (registered_with_no_types) == NULL) + abort (); + + /* Try getting it. Nothing should be returned because it is + untyped. */ + selector = sel_getTypedSelector ("registered_with_no_types"); + + if (selector != NULL) abort (); } @@ -95,7 +157,7 @@ int main(int argc, void **args) if (strcmp (sel_getName (selector), "aMethod") != 0) abort (); - if (strcmp (sel_getType (selector), types) != 0) + if (strcmp (sel_getTypeEncoding (selector), types) != 0) abort (); } -- cgit v1.1