Added more test cases.

This commit is contained in:
theraven 2013-01-09 21:42:16 +00:00
parent bcf6e32311
commit ef5f8b744d
2 changed files with 54 additions and 13 deletions

View File

@ -8,6 +8,7 @@ set(TESTS
BlockImpTest.m BlockImpTest.m
PropertyIntrospectionTest.m PropertyIntrospectionTest.m
ProtocolCreation.m ProtocolCreation.m
RuntimeTest.m
) )
#ExceptionTest.m #ExceptionTest.m

View File

@ -1,5 +1,7 @@
#import <Foundation/Foundation.h> #include "objc/runtime.h"
#include <objc/runtime.h> #include <stdio.h>
#include <string.h>
#include <unistd.h>
static int exitStatus = 0; static int exitStatus = 0;
@ -18,6 +20,47 @@ static int stringsEqual(const char *a, const char *b)
return 0 == strcmp(a,b); return 0 == strcmp(a,b);
} }
@protocol NSCoding
@end
#ifdef __has_attribute
#if __has_attribute(objc_root_class)
__attribute__((objc_root_class))
#endif
#endif
@interface NSObject <NSCoding>
{
id isa;
int refcount;
}
@end
@implementation NSObject
- (id)class
{
return object_getClass(self);
}
+ (id)class
{
return self;
}
+ (id)new
{
return class_createInstance(self, 0);
}
- (void)release
{
if (refcount == 0)
{
object_dispose(self);
}
refcount--;
}
- (id)retain
{
refcount++;
return self;
}
@end
@interface Foo : NSObject @interface Foo : NSObject
@ -43,6 +86,7 @@ static int stringsEqual(const char *a, const char *b)
- (id) aBool: (BOOL)d andAnInt: (int) w; - (id) aBool: (BOOL)d andAnInt: (int) w;
@end @end
id exceptionObj = @"Exception";
@implementation Foo @implementation Foo
- (void) aMethod - (void) aMethod
@ -70,7 +114,7 @@ static int stringsEqual(const char *a, const char *b)
} }
- (void) throwException - (void) throwException
{ {
@throw [NSException exceptionWithName: @"RuntimeTestException" reason: @"" userInfo: nil]; @throw exceptionObj;
} }
- (BOOL) basicThrowAndCatchException - (BOOL) basicThrowAndCatchException
{ {
@ -78,9 +122,9 @@ static int stringsEqual(const char *a, const char *b)
{ {
[self throwException]; [self throwException];
} }
@catch (NSException *e) @catch (id e)
{ {
NSLog(@"Caught %@", e); test(e == exceptionObj);
} }
@finally @finally
{ {
@ -181,9 +225,6 @@ void testMultiTypedSelector()
Method intMethod = class_getInstanceMethod([Foo class], @selector(manyTypes)); Method intMethod = class_getInstanceMethod([Foo class], @selector(manyTypes));
Method idMethod = class_getInstanceMethod([Bar class], @selector(manyTypes)); Method idMethod = class_getInstanceMethod([Bar class], @selector(manyTypes));
test(method_getName(intMethod) == @selector(manyTypes));
test(method_getName(idMethod) == @selector(manyTypes));
test(sel_isEqual(method_getName(intMethod), @selector(manyTypes))); test(sel_isEqual(method_getName(intMethod), @selector(manyTypes)));
test(sel_isEqual(method_getName(idMethod), @selector(manyTypes))); test(sel_isEqual(method_getName(idMethod), @selector(manyTypes)));
@ -252,12 +293,13 @@ void testRegisterAlias()
printf("testRegisterAlias() ran\n"); printf("testRegisterAlias() ran\n");
} }
@interface SlowInit1 @interface SlowInit1 : NSObject
+ (void)doNothing; + (void)doNothing;
@end @end
@interface SlowInit2 @interface SlowInit2 : NSObject
+ (void)doNothing; + (void)doNothing;
@end @end
@implementation SlowInit1 @implementation SlowInit1
+ (void)initialize + (void)initialize
{ {
@ -267,7 +309,7 @@ void testRegisterAlias()
+ (void)doNothing {} + (void)doNothing {}
@end @end
static int initCount; static int initCount;
@implementation SlowInit1 @implementation SlowInit2
+ (void)initialize + (void)initialize
{ {
sleep(1); sleep(1);
@ -288,11 +330,9 @@ int main (int argc, const char * argv[])
testAllocateClass(); testAllocateClass();
printf("Instance of NSObject: %p\n", class_createInstance([NSObject class], 0)); printf("Instance of NSObject: %p\n", class_createInstance([NSObject class], 0));
NSAutoreleasePool *pool = [NSAutoreleasePool new];
testSynchronized(); testSynchronized();
testExceptions(); testExceptions();
testRegisterAlias(); testRegisterAlias();
[pool release];
return exitStatus; return exitStatus;
} }