@@ -19,77 +19,90 @@ #if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) # include #endif -#import "TestsAppDelegate.h" +#import "ObjFW.h" +#import "ObjFWTest.h" -static OFString *const module = @"OFInvocation"; +@interface OFInvocationTests: OTTestCase +{ + OFInvocation *_invocation; +} +@end struct TestStruct { unsigned char c; unsigned int i; }; -@implementation TestsAppDelegate (OFInvocationTests) +@implementation OFInvocationTests - (struct TestStruct)invocationTestMethod1: (unsigned char)c : (unsigned int)i - : (struct TestStruct *)ptr - : (struct TestStruct)st + : (struct TestStruct *)testStructPtr + : (struct TestStruct)testStruct +{ + return testStruct; +} + +- (void)setUp +{ + SEL selector = @selector(invocationTestMethod1::::); + OFMethodSignature *signature = + [self methodSignatureForSelector: selector]; + + _invocation = [[OFInvocation alloc] initWithMethodSignature: signature]; +} + +- (void)dealloc +{ + [_invocation release]; + + [super dealloc]; +} + +- (void)testSetAndGetReturnValue { - return st; + struct TestStruct testStruct, testStruct2; + + memset(&testStruct, 0xFF, sizeof(testStruct)); + testStruct.c = 0x55; + testStruct.i = 0xAAAAAAAA; + + [_invocation setReturnValue: &testStruct]; + [_invocation getReturnValue: &testStruct2]; + OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } -- (void)invocationTests +- (void)testSetAndGetArgumentAtIndex { - void *pool = objc_autoreleasePoolPush(); - SEL selector = @selector(invocationTestMethod1::::); - OFMethodSignature *sig = [self methodSignatureForSelector: selector]; - OFInvocation *invocation; - struct TestStruct st, st2, *stp = &st, *stp2; + struct TestStruct testStruct, testStruct2; + struct TestStruct *testStructPtr = &testStruct, *testStructPtr2; unsigned const char c = 0xAA; unsigned char c2; const unsigned int i = 0x55555555; unsigned int i2; - memset(&st, '\xFF', sizeof(st)); - st.c = 0x55; - st.i = 0xAAAAAAAA; - - TEST(@"+[invocationWithMethodSignature:]", - (invocation = [OFInvocation invocationWithMethodSignature: sig])) - - TEST(@"-[setReturnValue]", R([invocation setReturnValue: &st])) - - TEST(@"-[getReturnValue]", R([invocation getReturnValue: &st2]) && - memcmp(&st, &st2, sizeof(st)) == 0) - - memset(&st2, '\0', sizeof(st2)); - - TEST(@"-[setArgument:atIndex:] #1", - R([invocation setArgument: &c atIndex: 2])) - - TEST(@"-[setArgument:atIndex:] #2", - R([invocation setArgument: &i atIndex: 3])) - - TEST(@"-[setArgument:atIndex:] #3", - R([invocation setArgument: &stp atIndex: 4])) - - TEST(@"-[setArgument:atIndex:] #4", - R([invocation setArgument: &st atIndex: 5])) - - TEST(@"-[getArgument:atIndex:] #1", - R([invocation getArgument: &c2 atIndex: 2]) && c == c2) - - TEST(@"-[getArgument:atIndex:] #2", - R([invocation getArgument: &i2 atIndex: 3]) && i == i2) - - TEST(@"-[getArgument:atIndex:] #3", - R([invocation getArgument: &stp2 atIndex: 4]) && stp == stp2) - - TEST(@"-[getArgument:atIndex:] #4", - R([invocation getArgument: &st2 atIndex: 5]) && - memcmp(&st, &st2, sizeof(st)) == 0) - - objc_autoreleasePoolPop(pool); + memset(&testStruct, 0xFF, sizeof(testStruct)); + testStruct.c = 0x55; + testStruct.i = 0xAAAAAAAA; + + memset(&testStruct2, 0, sizeof(testStruct2)); + + [_invocation setArgument: &c atIndex: 2]; + [_invocation setArgument: &i atIndex: 3]; + [_invocation setArgument: &testStructPtr atIndex: 4]; + [_invocation setArgument: &testStruct atIndex: 5]; + + [_invocation getArgument: &c2 atIndex: 2]; + OTAssertEqual(c, c2); + + [_invocation getArgument: &i2 atIndex: 3]; + OTAssertEqual(i, i2); + + [_invocation getArgument: &testStructPtr2 atIndex: 4]; + OTAssertEqual(testStructPtr, testStructPtr2); + + [_invocation getArgument: &testStruct2 atIndex: 5]; + OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } @end