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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "TestsAppDelegate.h"
static OFString *module = @"Forwarding";
static size_t forwardings = 0;
static BOOL success = NO;
static bool success = false;
@interface ForwardingTest: OFObject
@end
@interface ForwardingTest (Test)
+ (void)test;
- (void)test;
@end
static void
test(id self, SEL _cmd)
{
success = YES;
success = true;
}
@implementation ForwardingTest
+ (BOOL)resolveClassMethod: (SEL)selector
+ (bool)resolveClassMethod: (SEL)selector
{
forwardings++;
if (sel_isEqual(selector, @selector(test))) {
[self replaceClassMethod: @selector(test)
withImplementation: (IMP)test
typeEncoding: "v#:"];
return YES;
return true;
}
return NO;
return false;
}
+ (BOOL)resolveInstanceMethod: (SEL)selector
+ (bool)resolveInstanceMethod: (SEL)selector
{
forwardings++;
if (sel_isEqual(selector, @selector(test))) {
[self replaceInstanceMethod: @selector(test)
withImplementation: (IMP)test
typeEncoding: "v@:"];
return YES;
return true;
}
return NO;
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 = NO;
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
|