Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / ocmock / OCMock / OCMObserverRecorder.m
blobe50be50c2ab2d8d4ae98747c55045c6d8d381276
1 //---------------------------------------------------------------------------------------
2 //  $Id$
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;
13 @end
15 #pragma mark -
18 @implementation OCMObserverRecorder
20 #pragma mark  Initialisers, description, accessors, etc.
22 - (void)dealloc
24         [recordedNotification release];
25         [super dealloc];
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]])
54         {       
55                 if([expectedArg evaluate:observedArg] == NO)
56                         return NO;
57         }
58         else if([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")])
59         {
60                 if([expectedArg matches:observedArg] == NO)
61                         return NO;
62         }
63         else
64         {
65                 if([expectedArg class] != [observedArg class])
66                         return NO;
67                 if(([expectedArg isEqual:observedArg] == NO) &&
68                    !((expectedArg == nil) && (observedArg == nil)))
69                         return NO;
70         }
71         return YES;
75 @end