Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -4,10 +4,11 @@ PROG_NOINST = tests${PROG_SUFFIX} SRCS = OFCharacterSetTests.m \ OFColorTests.m \ OFIRITests.m \ + OFInvocationTests.m \ OFMethodSignatureTests.m \ OFNumberTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ ADDED new_tests/OFInvocationTests.m Index: new_tests/OFInvocationTests.m ================================================================== --- new_tests/OFInvocationTests.m +++ new_tests/OFInvocationTests.m @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) +# include +#endif + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFInvocationTests: OTTestCase +{ + OFInvocation *_invocation; +} +@end + +struct TestStruct { + unsigned char c; + unsigned int i; +}; + +@implementation OFInvocationTests +- (struct TestStruct)invocationTestMethod1: (unsigned char)c + : (unsigned int)i + : (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 +{ + 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)testSetAndGetArgumentAtIndex +{ + 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(&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 Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -22,11 +22,10 @@ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFHMACTests.m \ OFINIFileTests.m \ - OFInvocationTests.m \ OFJSONTests.m \ OFListTests.m \ OFLocaleTests.m \ OFMD5HashTests.m \ OFMatrix4x4Tests.m \ DELETED tests/OFInvocationTests.m Index: tests/OFInvocationTests.m ================================================================== --- tests/OFInvocationTests.m +++ tests/OFInvocationTests.m @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) -# include -#endif - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFInvocation"; - -struct TestStruct { - unsigned char c; - unsigned int i; -}; - -@implementation TestsAppDelegate (OFInvocationTests) -- (struct TestStruct)invocationTestMethod1: (unsigned char)c - : (unsigned int)i - : (struct TestStruct *)ptr - : (struct TestStruct)st -{ - return st; -} - -- (void)invocationTests -{ - void *pool = objc_autoreleasePoolPush(); - SEL selector = @selector(invocationTestMethod1::::); - OFMethodSignature *sig = [self methodSignatureForSelector: selector]; - OFInvocation *invocation; - struct TestStruct st, st2, *stp = &st, *stp2; - 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); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -109,14 +109,10 @@ @interface TestsAppDelegate (OFIPXSocketTests) - (void)IPXSocketTests; @end -@interface TestsAppDelegate (OFInvocationTests) -- (void)invocationTests; -@end - @interface TestsAppDelegate (OFJSONTests) - (void)JSONTests; @end @interface TestsAppDelegate (OFHMACTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -373,11 +373,10 @@ [self runtimeTests]; #ifdef COMPILER_SUPPORTS_ARC [self runtimeARCTests]; #endif [self objectTests]; - [self invocationTests]; [self forwardingTests]; #ifdef OF_HAVE_BLOCKS [self blockTests]; #endif [self stringTests];