| OLD | NEW |
| 1 //------------------------------------------------------------------------------
--------- | 1 /* |
| 2 // $Id$ | 2 * Copyright (c) 2009-2015 Erik Doernenburg and contributors |
| 3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. | 3 * |
| 4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
| 5 | 16 |
| 6 #import <objc/runtime.h> | 17 #import <objc/runtime.h> |
| 7 #import <OCMock/OCMConstraint.h> | 18 #import <OCMock/OCMConstraint.h> |
| 8 #import "NSInvocation+OCMAdditions.h" | 19 #import "NSInvocation+OCMAdditions.h" |
| 9 #import "OCMObserverRecorder.h" | 20 #import "OCMObserverRecorder.h" |
| 10 | 21 |
| 11 @interface NSObject(HCMatcherDummy) | 22 @interface NSObject(HCMatcherDummy) |
| 12 - (BOOL)matches:(id)item; | 23 - (BOOL)matches:(id)item; |
| 13 @end | 24 @end |
| 14 | 25 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 43 | 54 |
| 44 - (BOOL)matchesNotification:(NSNotification *)aNotification | 55 - (BOOL)matchesNotification:(NSNotification *)aNotification |
| 45 { | 56 { |
| 46 return [self argument:[recordedNotification name] matchesArgument:[aNoti
fication name]] && | 57 return [self argument:[recordedNotification name] matchesArgument:[aNoti
fication name]] && |
| 47 [self argument:[recordedNotification object] matchesArgument:[aNotificat
ion object]] && | 58 [self argument:[recordedNotification object] matchesArgument:[aNotificat
ion object]] && |
| 48 [self argument:[recordedNotification userInfo] matchesArgument:[aNotific
ation userInfo]]; | 59 [self argument:[recordedNotification userInfo] matchesArgument:[aNotific
ation userInfo]]; |
| 49 } | 60 } |
| 50 | 61 |
| 51 - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg | 62 - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg |
| 52 { | 63 { |
| 53 » if([expectedArg isKindOfClass:[OCMConstraint class]]) | 64 if ([expectedArg isKindOfClass:[OCMConstraint class]]) { |
| 54 » {» | 65 return [expectedArg evaluate:observedArg]; |
| 55 » » if([expectedArg evaluate:observedArg] == NO) | 66 } else if ([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")]) { |
| 56 » » » return NO; | 67 return [expectedArg matches:observedArg]; |
| 57 » } | 68 } else if (expectedArg == observedArg) { |
| 58 » else if([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")]) | 69 return YES; |
| 59 » { | 70 } else if (expectedArg == nil || observedArg == nil) { |
| 60 » » if([expectedArg matches:observedArg] == NO) | 71 return NO; |
| 61 » » » return NO; | 72 } else { |
| 62 » } | 73 return [expectedArg isEqual:observedArg]; |
| 63 » else | 74 } |
| 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 } | 75 } |
| 73 | 76 |
| 74 | 77 |
| 75 @end | 78 @end |
| OLD | NEW |