- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / ocmock / OCMock / OCMObserverRecorder.m
1 //---------------------------------------------------------------------------------------
2 //  $Id$
3 //  Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
5
6 #import <objc/runtime.h>
7 #import <OCMock/OCMConstraint.h>
8 #import "NSInvocation+OCMAdditions.h"
9 #import "OCMObserverRecorder.h"
10
11 @interface NSObject(HCMatcherDummy)
12 - (BOOL)matches:(id)item;
13 @end
14
15 #pragma mark -
16
17
18 @implementation OCMObserverRecorder
19
20 #pragma mark  Initialisers, description, accessors, etc.
21
22 - (void)dealloc
23 {
24         [recordedNotification release];
25         [super dealloc];
26 }
27
28
29 #pragma mark  Recording
30
31 - (void)notificationWithName:(NSString *)name object:(id)sender
32 {
33         recordedNotification = [[NSNotification notificationWithName:name object:sender] retain];
34 }
35
36 - (void)notificationWithName:(NSString *)name object:(id)sender userInfo:(NSDictionary *)userInfo
37 {
38         recordedNotification = [[NSNotification notificationWithName:name object:sender userInfo:userInfo] retain];
39 }
40
41
42 #pragma mark  Verification
43
44 - (BOOL)matchesNotification:(NSNotification *)aNotification
45 {
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]];
49 }
50
51 - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg
52 {
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;
72 }
73
74
75 @end