blob: e50be50c2ab2d8d4ae98747c55045c6d8d381276 (
plain)
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
|
//---------------------------------------------------------------------------------------
// $Id$
// Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------
#import <objc/runtime.h>
#import <OCMock/OCMConstraint.h>
#import "NSInvocation+OCMAdditions.h"
#import "OCMObserverRecorder.h"
@interface NSObject(HCMatcherDummy)
- (BOOL)matches:(id)item;
@end
#pragma mark -
@implementation OCMObserverRecorder
#pragma mark Initialisers, description, accessors, etc.
- (void)dealloc
{
[recordedNotification release];
[super dealloc];
}
#pragma mark Recording
- (void)notificationWithName:(NSString *)name object:(id)sender
{
recordedNotification = [[NSNotification notificationWithName:name object:sender] retain];
}
- (void)notificationWithName:(NSString *)name object:(id)sender userInfo:(NSDictionary *)userInfo
{
recordedNotification = [[NSNotification notificationWithName:name object:sender userInfo:userInfo] retain];
}
#pragma mark Verification
- (BOOL)matchesNotification:(NSNotification *)aNotification
{
return [self argument:[recordedNotification name] matchesArgument:[aNotification name]] &&
[self argument:[recordedNotification object] matchesArgument:[aNotification object]] &&
[self argument:[recordedNotification userInfo] matchesArgument:[aNotification userInfo]];
}
- (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg
{
if([expectedArg isKindOfClass:[OCMConstraint class]])
{
if([expectedArg evaluate:observedArg] == NO)
return NO;
}
else if([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")])
{
if([expectedArg matches:observedArg] == NO)
return NO;
}
else
{
if([expectedArg class] != [observedArg class])
return NO;
if(([expectedArg isEqual:observedArg] == NO) &&
!((expectedArg == nil) && (observedArg == nil)))
return NO;
}
return YES;
}
@end
|