mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-05 14:59:45 +08:00
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
This commit is contained in:
parent
f7185d4791
commit
28c3bb954a
@ -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
|
||||
|
160
gcc/testsuite/objc.dg/gnu-api-2-protocol.m
Normal file
160
gcc/testsuite/objc.dg/gnu-api-2-protocol.m
Normal file
@ -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;
|
||||
}
|
103
gcc/testsuite/objc.dg/gnu-api-2-sel.m
Normal file
103
gcc/testsuite/objc.dg/gnu-api-2-sel.m
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user