ObjFW  Check-in [249eda6023]

Overview
Comment:Add tests for -[forwardingTargetForSelector:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 249eda60232720a756fb2fe58861bb260604a56b6ce079ae103aab6b8cb610fc
User & Date: js on 2013-07-11 11:55:33
Other Links: manifest | tags
Context
2013-07-11
12:33
Use section .ctors instead of .init_array. check-in: aeb47d24b5 user: js tags: trunk
11:55
Add tests for -[forwardingTargetForSelector:]. check-in: 249eda6023 user: js tags: trunk
10:54
OFXMLElementBuilderTests: Use OF_ENSURE(). check-in: b91ce5dba8 user: js tags: trunk
Changes

Modified tests/ForwardingTests.m from [d9a0d74b25] to [821ca2e4ae].

11
12
13
14
15
16
17


18
19
20


21
22
23
24
25
26





27
28
29
30
31
32
33






34
35
36
37
38
39
40
 * 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"



#import "OFString.h"
#import "OFAutoreleasePool.h"



#import "TestsAppDelegate.h"

static OFString *module = @"Forwarding";
static size_t forwardings = 0;
static bool success = false;






@interface ForwardingTest: OFObject
@end

@interface ForwardingTest (Test)
+ (void)test;
- (void)test;






@end

static void
test(id self, SEL _cmd)
{
	success = true;
}







>
>



>
>






>
>
>
>
>







>
>
>
>
>
>







11
12
13
14
15
16
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
 * 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 <string.h>

#import "OFString.h"
#import "OFAutoreleasePool.h"

#import "macros.h"

#import "TestsAppDelegate.h"

static OFString *module = @"Forwarding";
static size_t forwardings = 0;
static bool success = false;
static id target = nil;

struct stret_test {
	char s[27];
};

@interface ForwardingTest: OFObject
@end

@interface ForwardingTest (Test)
+ (void)test;
- (void)test;
- (OFString*)forwardingTargetTest: (OFConstantString*)fmt, ...;
- (long double)forwardingTargetFPRetTest;
- (struct stret_test)forwardingTargetStRetTest;
@end

@interface ForwardingTarget: OFObject
@end

static void
test(id self, SEL _cmd)
{
	success = true;
}
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
			 withImplementation: (IMP)test
			       typeEncoding: "v@:"];
		return true;
	}

	return false;
}













































@end

@implementation TestsAppDelegate (ForwardingTests)
- (void)forwardingTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	TEST(@"Forwarding a message and adding a class method",
	    R([ForwardingTest test]) && success &&
	    R([ForwardingTest test]) && forwardings == 1);

	ForwardingTest *t = [[[ForwardingTest alloc] init] autorelease];

	success = false;
	forwardings = 0;

	TEST(@"Forwarding a message and adding an instance method",
	    R([t test]) && success && R([t test]) && forwardings == 1);
















	[pool drain];
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
			 withImplementation: (IMP)test
			       typeEncoding: "v@:"];
		return true;
	}

	return false;
}

- (id)forwardingTargetForSelector: (SEL)selector
{
	if (sel_isEqual(selector, @selector(forwardingTargetTest:)) ||
	    sel_isEqual(selector, @selector(forwardingTargetFPRetTest)) ||
	    sel_isEqual(selector, @selector(forwardingTargetStRetTest)))
		return target;

	return nil;
}
@end

@implementation ForwardingTarget
- (OFString*)forwardingTargetTest: (OFConstantString*)fmt, ...
{
	va_list args;
	OFString *ret;

	OF_ENSURE(self == target);

	va_start(args, fmt);
	ret = [[[OFString alloc] initWithFormat: fmt
				      arguments: args] autorelease];
	va_end(args);

	return ret;
}

- (long double)forwardingTargetFPRetTest
{
	OF_ENSURE(self == target);

	return 12345678.00006103515625;
}

- (struct stret_test)forwardingTargetStRetTest
{
	struct stret_test ret;

	OF_ENSURE(self == target);

	memcpy(ret.s, "abcdefghijklmnopqrstuvwxyz", 27);

	return ret;
}
@end

@implementation TestsAppDelegate (ForwardingTests)
- (void)forwardingTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	TEST(@"Forwarding a message and adding a class method",
	    R([ForwardingTest test]) && success &&
	    R([ForwardingTest test]) && forwardings == 1);

	ForwardingTest *t = [[[ForwardingTest alloc] init] autorelease];

	success = false;
	forwardings = 0;

	TEST(@"Forwarding a message and adding an instance method",
	    R([t test]) && success && R([t test]) && forwardings == 1);

#ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
	target = [[[ForwardingTarget alloc] init] autorelease];
	TEST(@"-[forwardingTargetForSelector:]",
	   [([t forwardingTargetTest: @"%@ %@ %@ %@ %@ %@ %@ %@ %@", @"1", @"2",
				     @"3", @"4", @"5", @"6", @"7", @"8", @"9"])
	   isEqual: @"1 2 3 4 5 6 7 8 9"])
	TEST(@"-[forwardingTargetForSelector:] with fp return",
	    [t forwardingTargetFPRetTest] == 12345678.00006103515625)
# ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
	TEST(@"-[forwardingTargetForSelector:] with struct return",
	    !memcmp([t forwardingTargetStRetTest].s,
	    "abcdefghijklmnopqrstuvwxyz", 27))
# endif
#endif

	[pool drain];
}
@end