ObjFW  Diff

Differences From Artifact [23f57f7d3a]:

To Artifact [860bceb260]:


17
18
19
20
21
22
23
24


25


26



27
28
29
30
31
32
33

34
35
36
37


38
39

40
41
42

43
44
45

46
47
48





























49
50
51
52
53
54
55
56



57
58
59
60

61
62
63
64
65
66
67
68
69

70
71
72

73
74
75

76
77
78

79
80
81


82
83
84


85
86
87


88
89
90

91
92

93
94
95
17
18
19
20
21
22
23

24
25
26
27
28

29
30
31
32
33
34
35
36
37

38
39
40


41
42
43

44
45
46

47
48

49
50



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84



85
86
87
88



89

90







91



92



93



94
95


96
97
98


99
100
101


102
103
104


105


106

107
108







-
+
+

+
+
-
+
+
+






-
+


-
-
+
+

-
+


-
+

-

+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
-
+
+
+

-
-
-
+
-

-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
-
-
+
-



#include <string.h>

#if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__)
# include <complex.h>
#endif

#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"

@interface OFInvocationTests: OTTestCase
{
static OFString *const module = @"OFInvocation";
	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 st;
	return testStruct;
}

- (void)invocationTests
- (void)setUp
{
	void *pool = objc_autoreleasePoolPush();
	SEL selector = @selector(invocationTestMethod1::::);
	OFMethodSignature *signature =
	OFMethodSignature *sig = [self methodSignatureForSelector: selector];
	OFInvocation *invocation;
	struct TestStruct st, st2, *stp = &st, *stp2;
	    [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(&st, '\xFF', sizeof(st));
	st.c = 0x55;
	st.i = 0xAAAAAAAA;
	memset(&testStruct, 0xFF, sizeof(testStruct));
	testStruct.c = 0x55;
	testStruct.i = 0xAAAAAAAA;

	TEST(@"+[invocationWithMethodSignature:]",
	    (invocation = [OFInvocation invocationWithMethodSignature: sig]))

	memset(&testStruct2, 0, sizeof(testStruct2));
	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]))
	[_invocation setArgument: &c atIndex: 2];

	TEST(@"-[setArgument:atIndex:] #2",
	    R([invocation setArgument: &i atIndex: 3]))
	[_invocation setArgument: &i atIndex: 3];

	TEST(@"-[setArgument:atIndex:] #3",
	    R([invocation setArgument: &stp atIndex: 4]))
	[_invocation setArgument: &testStructPtr atIndex: 4];

	TEST(@"-[setArgument:atIndex:] #4",
	    R([invocation setArgument: &st atIndex: 5]))
	[_invocation setArgument: &testStruct atIndex: 5];

	TEST(@"-[getArgument:atIndex:] #1",
	    R([invocation getArgument: &c2 atIndex: 2]) && c == c2)
	[_invocation getArgument: &c2 atIndex: 2];
	OTAssertEqual(c, c2);

	TEST(@"-[getArgument:atIndex:] #2",
	    R([invocation getArgument: &i2 atIndex: 3]) && i == i2)
	[_invocation getArgument: &i2 atIndex: 3];
	OTAssertEqual(i, i2);

	TEST(@"-[getArgument:atIndex:] #3",
	    R([invocation getArgument: &stp2 atIndex: 4]) && stp == stp2)
	[_invocation getArgument: &testStructPtr2 atIndex: 4];
	OTAssertEqual(testStructPtr, testStructPtr2);

	TEST(@"-[getArgument:atIndex:] #4",
	    R([invocation getArgument: &st2 atIndex: 5]) &&
	[_invocation getArgument: &testStruct2 atIndex: 5];
	    memcmp(&st, &st2, sizeof(st)) == 0)

	OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0);
	objc_autoreleasePoolPop(pool);
}
@end