diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 20:33:14 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 20:33:14 +0000 |
commit | 05a6a89d5c81770ed543d3eccf87c6495b42a869 (patch) | |
tree | 58f507fcbebd847de40dec5b3d1ab5956f4ea700 /third_party/ocmock/OCMock/OCObserverMockObject.m | |
parent | 48283f82ca649df36f46b3618ad45f86a6fc412d (diff) | |
download | chromium_src-05a6a89d5c81770ed543d3eccf87c6495b42a869.zip chromium_src-05a6a89d5c81770ed543d3eccf87c6495b42a869.tar.gz chromium_src-05a6a89d5c81770ed543d3eccf87c6495b42a869.tar.bz2 |
Move OCMock from third_party/ocmock to third_party/ocmock/OCMock
"...may be suffering from what we in the soft sciences call 'Obsessive
Compulsive Disorder,' or the 'The O.C. Disorder.'"
Here's what we're doing:
mkdir OCMock
svn add OCMock
for i in * ; do
if [ "${i}" != "OCMock" ] && [ "${i}" != "README.chromium" ] ; then
svn move "${i}" OCMock
fi
done
and make the SVN URL in README.chromium a tiny bit more specific.
Review URL: http://codereview.chromium.org/220017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/ocmock/OCMock/OCObserverMockObject.m')
-rw-r--r-- | third_party/ocmock/OCMock/OCObserverMockObject.m | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/third_party/ocmock/OCMock/OCObserverMockObject.m b/third_party/ocmock/OCMock/OCObserverMockObject.m new file mode 100644 index 0000000..7e410c2 --- /dev/null +++ b/third_party/ocmock/OCMock/OCObserverMockObject.m @@ -0,0 +1,83 @@ +//--------------------------------------------------------------------------------------- +// $Id$ +// Copyright (c) 2009 by Mulle Kybernetik. See License file for details. +//--------------------------------------------------------------------------------------- + +#import "OCObserverMockObject.h" +#import "OCMObserverRecorder.h" + + +@implementation OCObserverMockObject + +#pragma mark Initialisers, description, accessors, etc. + +- (id)init +{ + [super init]; + recorders = [[NSMutableArray alloc] init]; + return self; +} + +- (void)dealloc +{ + [recorders release]; + [super dealloc]; +} + +- (NSString *)description +{ + return @"OCMockObserver"; +} + +- (void)setExpectationOrderMatters:(BOOL)flag +{ + expectationOrderMatters = flag; +} + + +#pragma mark Public API + +- (id)expect +{ + OCMObserverRecorder *recorder = [[[OCMObserverRecorder alloc] init] autorelease]; + [recorders addObject:recorder]; + return recorder; +} + +- (void)verify +{ + if([recorders count] == 1) + { + [NSException raise:NSInternalInconsistencyException format:@"%@: expected notification was not observed: %@", + [self description], [[recorders lastObject] description]]; + } + if([recorders count] > 0) + { + [NSException raise:NSInternalInconsistencyException format:@"%@ : %d expected notifications were not observed.", + [self description], [recorders count]]; + } +} + + + +#pragma mark Receiving notifications + +- (void)handleNotification:(NSNotification *)aNotification +{ + int i, limit; + + limit = expectationOrderMatters ? 1 : [recorders count]; + for(i = 0; i < limit; i++) + { + if([[recorders objectAtIndex:i] matchesNotification:aNotification]) + { + [recorders removeObjectAtIndex:i]; + return; + } + } + [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected notification observed: %@", [self description], + [aNotification description]]; +} + + +@end |