1 //---------------------------------------------------------------------------------------
3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
6 #import <objc/runtime.h>
7 #import <OCMock/OCMConstraint.h>
8 #import "NSInvocation+OCMAdditions.h"
9 #import "OCMObserverRecorder.h"
11 @interface NSObject(HCMatcherDummy)
12 - (BOOL)matches:(id)item;
18 @implementation OCMObserverRecorder
20 #pragma mark Initialisers, description, accessors, etc.
24 [recordedNotification release];
29 #pragma mark Recording
31 - (void)notificationWithName:(NSString *)name object:(id)sender
33 recordedNotification = [[NSNotification notificationWithName:name object:sender] retain];
36 - (void)notificationWithName:(NSString *)name object:(id)sender userInfo:(NSDictionary *)userInfo
38 recordedNotification = [[NSNotification notificationWithName:name object:sender userInfo:userInfo] retain];
42 #pragma mark Verification
44 - (BOOL)matchesNotification:(NSNotification *)aNotification
46 return [self argument:[recordedNotification name] matchesArgument:[aNotification name]] &&
47 [self argument:[recordedNotification object] matchesArgument:[aNotification object]] &&
48 [self argument:[recordedNotification userInfo] matchesArgument:[aNotification userInfo]];
51 - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg
53 if([expectedArg isKindOfClass:[OCMConstraint class]])
55 if([expectedArg evaluate:observedArg] == NO)
58 else if([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")])
60 if([expectedArg matches:observedArg] == NO)
65 if([expectedArg class] != [observedArg class])
67 if(([expectedArg isEqual:observedArg] == NO) &&
68 !((expectedArg == nil) && (observedArg == nil)))