ObjFW  Check-in [4bcfe4d4bc]

Overview
Comment:Add forwarding tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4bcfe4d4bc089db6d37bb6ae632aaea252712db485f7e6f0079808d1f2a76ce2
User & Date: js on 2012-08-04 00:00:03
Other Links: manifest | tags
Context
2012-08-04
00:16
Add new files to Xcode project. check-in: b652a7e3a0 user: js tags: trunk
00:00
Add forwarding tests. check-in: 4bcfe4d4bc user: js tags: trunk
2012-08-03
22:37
Implement basic forwarding. check-in: 285e1138bc user: js tags: trunk
Changes

Added tests/ForwardingTests.m version [e826c9d596].




























































































1
2
3
4
5
6
7
8
9
10
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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"

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

#import "TestsAppDelegate.h"

static OFString *module = @"Forwarding";
static size_t forwardings = 0;
static BOOL success = NO;

@interface ForwardingTest: OFObject
@end

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

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

@implementation ForwardingTest
+ (BOOL)resolveClassMethod: (SEL)selector
{
	forwardings++;

	if (sel_isEqual(selector, @selector(test))) {
		[self replaceClassMethod: @selector(test)
		      withImplementation: (IMP)test
			    typeEncoding: "v@:"];
		return YES;
	}

	return NO;
}

+ (BOOL)resolveInstanceMethod: (SEL)selector
{
	forwardings++;

	if (sel_isEqual(selector, @selector(test))) {
		[self replaceInstanceMethod: @selector(test)
			 withImplementation: (IMP)test
			       typeEncoding: "v@:"];
		return YES;
	}

	return NO;
}
@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 = NO;
	forwardings = 0;

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

	[pool drain];
}
@end

Modified tests/Makefile from [2bea34c765] to [733a9bd398].

1
2
3
4
5

6

7
8
9
10
11
12
13
1
2
3
4
5
6

7
8
9
10
11
12
13
14





+
-
+







include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = ForwardingTests.m		\
SRCS = OFArrayTests.m			\
       OFArrayTests.m			\
       ${OFBLOCKTESTS_M}		\
       OFDataArrayTests.m		\
       OFDateTests.m			\
       OFDictionaryTests.m		\
       ${OFHTTPREQUESTTESTS_M}		\
       OFJSONTests.m			\
       OFListTests.m			\

Modified tests/TestsAppDelegate.h from [4331305c00] to [bae42d2e23].

87
88
89
90
91
92
93




94
95
96
97
98
99
100
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104







+
+
+
+







@interface TestsAppDelegate (OFDateTests)
- (void)dateTests;
@end

@interface TestsAppDelegate (OFDictionaryTests)
- (void)dictionaryTests;
@end

@interface TestsAppDelegate (ForwardingTests)
- (void)forwardingTests;
@end

@interface TestsAppDelegate (OFHTTPRequestTests)
- (void)HTTPRequestTests;
@end

@interface TestsAppDelegate (OFJSONTests)
- (void)JSONTests;

Modified tests/TestsAppDelegate.m from [f78ac3ef9d] to [969c91a20e].

140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155







+








	[self XMLNodeTests];
	[self XMLElementBuilderTests];
	[self serializationTests];
	[self JSONTests];
#ifdef OF_PLUGINS
	[self pluginTests];
#endif
	[self forwardingTests];
#ifdef OF_HAVE_PROPERTIES
	[self propertiesTests];
#endif

	if (fails > 0)
		[OFApplication terminateWithStatus: fails];
}
@end