Skip to content

Commit

Permalink
Partial mocks now work on object reference and self. Sorry for also c…
Browse files Browse the repository at this point in the history
…hanging the section headers in the same commit.

git-svn-id: http://svn.mulle-kybernetik.com/OCMock/trunk@45 12620d81-68e2-0310-ae40-e3f550779089
  • Loading branch information
erik committed May 26, 2009
1 parent c4a5067 commit 4d9fa02
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 180 deletions.
6 changes: 6 additions & 0 deletions Source/Changes.txt
@@ -1,6 +1,12 @@
Chronological listing of changes. If a particular SVN revision has no entry, that
check-in did not involve any code or feature changes.


2009-05-26 (r45)

* Partial mocks now work on object reference and self (thanks to Mike Mangino)


2009-04-24 (r43)

* Added partial mocks (calls to the original object reference cannot be mocked)
Expand Down
18 changes: 2 additions & 16 deletions Source/OCClassMockObject.m
Expand Up @@ -8,9 +8,7 @@

@implementation OCClassMockObject

//---------------------------------------------------------------------------------------
// init and dealloc
//---------------------------------------------------------------------------------------
#pragma mark Initialisers, description, accessors, etc.

- (id)initWithClass:(Class)aClass
{
Expand All @@ -19,30 +17,18 @@ - (id)initWithClass:(Class)aClass
return self;
}


//---------------------------------------------------------------------------------------
// description override
//---------------------------------------------------------------------------------------

- (NSString *)description
{
return [NSString stringWithFormat:@"OCMockObject[%@]", NSStringFromClass(mockedClass)];
}


//---------------------------------------------------------------------------------------
// accessors
//---------------------------------------------------------------------------------------

- (Class)mockedClass
{
return mockedClass;
}


//---------------------------------------------------------------------------------------
// proxy api
//---------------------------------------------------------------------------------------
#pragma mark Proxy API

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
Expand Down
29 changes: 10 additions & 19 deletions Source/OCMConstraint.m
Expand Up @@ -6,10 +6,6 @@
#import <OCMock/OCMConstraint.h>


//---------------------------------------------------------------------------------------
// OCMConstraint
//---------------------------------------------------------------------------------------

@implementation OCMConstraint

+ (id)constraint
Expand Down Expand Up @@ -48,9 +44,8 @@ + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)
@end


//---------------------------------------------------------------------------------------
// OCMAnyConstraint
//---------------------------------------------------------------------------------------

#pragma mark -

@implementation OCMAnyConstraint

Expand All @@ -62,9 +57,8 @@ - (BOOL)evaluate:(id)value
@end


//---------------------------------------------------------------------------------------
// OCMIsNilConstraint
//---------------------------------------------------------------------------------------

#pragma mark -

@implementation OCMIsNilConstraint

Expand All @@ -76,9 +70,8 @@ - (BOOL)evaluate:(id)value
@end


//---------------------------------------------------------------------------------------
// OCMIsNotNilConstraint
//---------------------------------------------------------------------------------------

#pragma mark -

@implementation OCMIsNotNilConstraint

Expand All @@ -90,9 +83,8 @@ - (BOOL)evaluate:(id)value
@end


//---------------------------------------------------------------------------------------
// OCMIsNotEqualConstraint
//---------------------------------------------------------------------------------------

#pragma mark -

@implementation OCMIsNotEqualConstraint

Expand All @@ -104,9 +96,8 @@ - (BOOL)evaluate:(id)value
@end


//---------------------------------------------------------------------------------------
// OCMInvocationConstraint
//---------------------------------------------------------------------------------------

#pragma mark -

@implementation OCMInvocationConstraint

Expand Down
15 changes: 5 additions & 10 deletions Source/OCMObserverRecorder.m
Expand Up @@ -12,12 +12,12 @@ @interface NSObject(HCMatcherDummy)
- (BOOL)matches:(id)item;
@end

#pragma mark -


@implementation OCMObserverRecorder

//---------------------------------------------------------------------------------------
// init and dealloc
//---------------------------------------------------------------------------------------
#pragma mark Initialisers, description, accessors, etc.

- (void)dealloc
{
Expand All @@ -26,9 +26,7 @@ - (void)dealloc
}


//---------------------------------------------------------------------------------------
// recording
//---------------------------------------------------------------------------------------
#pragma mark Recording

- (void)notificationWithName:(NSString *)name object:(id)sender
{
Expand All @@ -41,9 +39,7 @@ - (void)notificationWithName:(NSString *)name object:(id)sender userInfo:(NSDict
}


//---------------------------------------------------------------------------------------
// verification
//---------------------------------------------------------------------------------------
#pragma mark Verification

- (BOOL)matchesNotification:(NSNotification *)aNotification
{
Expand Down Expand Up @@ -76,5 +72,4 @@ - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg
}



@end
100 changes: 75 additions & 25 deletions Source/OCMock.xcodeproj/project.pbxproj
Expand Up @@ -23,6 +23,9 @@
037860E20F6A3D4600A4D9A0 /* OCMPassByRefSetter.m in Sources */ = {isa = PBXBuildFile; fileRef = 037860E10F6A3D4600A4D9A0 /* OCMPassByRefSetter.m */; };
037860E30F6A3D4600A4D9A0 /* OCMPassByRefSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = 037860E00F6A3D4600A4D9A0 /* OCMPassByRefSetter.h */; };
037860E40F6A3D4600A4D9A0 /* OCMPassByRefSetter.m in Sources */ = {isa = PBXBuildFile; fileRef = 037860E10F6A3D4600A4D9A0 /* OCMPassByRefSetter.m */; };
037C13440FCC474D00257C8C /* OCPartialMockRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 037C13430FCC474D00257C8C /* OCPartialMockRecorder.m */; };
037C13450FCC474D00257C8C /* OCPartialMockRecorder.h in Headers */ = {isa = PBXBuildFile; fileRef = 037C13420FCC474D00257C8C /* OCPartialMockRecorder.h */; };
037C13460FCC474D00257C8C /* OCPartialMockRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 037C13430FCC474D00257C8C /* OCPartialMockRecorder.m */; };
03A2D0CB09F01D13008A1AFD /* NSInvocation+OCMAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 03A2D0C909F01D13008A1AFD /* NSInvocation+OCMAdditions.h */; settings = {ATTRIBUTES = (); }; };
03A2D0CC09F01D13008A1AFD /* NSInvocation+OCMAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 03A2D0CA09F01D13008A1AFD /* NSInvocation+OCMAdditions.m */; };
03BF2D4008F1C6BA00978C59 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03BF2D1B08F1C26700978C59 /* SenTestingKit.framework */; };
Expand Down Expand Up @@ -88,6 +91,8 @@
0378606C0F6A32F800A4D9A0 /* OCMArg.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCMArg.m; sourceTree = "<group>"; };
037860E00F6A3D4600A4D9A0 /* OCMPassByRefSetter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMPassByRefSetter.h; sourceTree = "<group>"; };
037860E10F6A3D4600A4D9A0 /* OCMPassByRefSetter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCMPassByRefSetter.m; sourceTree = "<group>"; };
037C13420FCC474D00257C8C /* OCPartialMockRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCPartialMockRecorder.h; sourceTree = "<group>"; };
037C13430FCC474D00257C8C /* OCPartialMockRecorder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCPartialMockRecorder.m; sourceTree = "<group>"; };
03A2D0C909F01D13008A1AFD /* NSInvocation+OCMAdditions.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = "NSInvocation+OCMAdditions.h"; sourceTree = "<group>"; };
03A2D0CA09F01D13008A1AFD /* NSInvocation+OCMAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+OCMAdditions.m"; sourceTree = "<group>"; };
03A2D1F809F1533C008A1AFD /* NSInvocationOCMAdditionsTests.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSInvocationOCMAdditionsTests.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +158,68 @@
name = Products;
sourceTree = "<group>";
};
037C13470FCC475500257C8C /* Core Mocks */ = {
isa = PBXGroup;
children = (
03DE1F5406DB911300E5A2A8 /* OCMockObject.h */,
03DE1F5506DB911300E5A2A8 /* OCMockObject.m */,
0338A99607BE7C100066DE8A /* OCClassMockObject.h */,
0338A99707BE7C100066DE8A /* OCClassMockObject.m */,
0338A9EE07BE83B50066DE8A /* OCProtocolMockObject.h */,
0338A9EF07BE83B50066DE8A /* OCProtocolMockObject.m */,
03DE1F5606DB911300E5A2A8 /* OCMockRecorder.h */,
03DE1F5706DB911300E5A2A8 /* OCMockRecorder.m */,
);
name = "Core Mocks";
sourceTree = "<group>";
};
037C13480FCC478500257C8C /* Partial Mocks */ = {
isa = PBXGroup;
children = (
03D8822D0FA151E10087D071 /* OCPartialMockObject.h */,
03D8822E0FA151E20087D071 /* OCPartialMockObject.m */,
037C13420FCC474D00257C8C /* OCPartialMockRecorder.h */,
037C13430FCC474D00257C8C /* OCPartialMockRecorder.m */,
);
name = "Partial Mocks";
sourceTree = "<group>";
};
037C13490FCC479D00257C8C /* Observer Mocks */ = {
isa = PBXGroup;
children = (
03D8805E0F8C81DE0087D071 /* OCObserverMockObject.h */,
03D8805F0F8C81DE0087D071 /* OCObserverMockObject.m */,
03D881070F8DB0BB0087D071 /* OCMObserverRecorder.h */,
03D8815A0F8DB37B0087D071 /* OCMObserverRecorder.m */,
);
name = "Observer Mocks";
sourceTree = "<group>";
};
037C134A0FCC47B500257C8C /* Argument Handling */ = {
isa = PBXGroup;
children = (
0378606B0F6A32F800A4D9A0 /* OCMArg.h */,
0378606C0F6A32F800A4D9A0 /* OCMArg.m */,
0343133B0CCA771800A2E080 /* OCMConstraint.h */,
0343133C0CCA771800A2E080 /* OCMConstraint.m */,
037860E00F6A3D4600A4D9A0 /* OCMPassByRefSetter.h */,
037860E10F6A3D4600A4D9A0 /* OCMPassByRefSetter.m */,
);
name = "Argument Handling";
sourceTree = "<group>";
};
037C134B0FCC47CA00257C8C /* Foundation Additions */ = {
isa = PBXGroup;
children = (
03A2D0C909F01D13008A1AFD /* NSInvocation+OCMAdditions.h */,
03A2D0CA09F01D13008A1AFD /* NSInvocation+OCMAdditions.m */,
03D880D30F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.h */,
03D880D40F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.m */,
0338AA1007BE866F0066DE8A /* NSMethodSignature+Private.h */,
);
name = "Foundation Additions";
sourceTree = "<group>";
};
03DE1F5D06DB911C00E5A2A8 /* Tests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -217,31 +284,11 @@
08FB77AEFE84172EC02AAC07 /* Implementation */ = {
isa = PBXGroup;
children = (
03DE1F5406DB911300E5A2A8 /* OCMockObject.h */,
03DE1F5506DB911300E5A2A8 /* OCMockObject.m */,
0338A99607BE7C100066DE8A /* OCClassMockObject.h */,
0338A99707BE7C100066DE8A /* OCClassMockObject.m */,
0338A9EE07BE83B50066DE8A /* OCProtocolMockObject.h */,
0338A9EF07BE83B50066DE8A /* OCProtocolMockObject.m */,
03D8822D0FA151E10087D071 /* OCPartialMockObject.h */,
03D8822E0FA151E20087D071 /* OCPartialMockObject.m */,
03DE1F5606DB911300E5A2A8 /* OCMockRecorder.h */,
03DE1F5706DB911300E5A2A8 /* OCMockRecorder.m */,
03D8805E0F8C81DE0087D071 /* OCObserverMockObject.h */,
03D8805F0F8C81DE0087D071 /* OCObserverMockObject.m */,
03D881070F8DB0BB0087D071 /* OCMObserverRecorder.h */,
03D8815A0F8DB37B0087D071 /* OCMObserverRecorder.m */,
0378606B0F6A32F800A4D9A0 /* OCMArg.h */,
0378606C0F6A32F800A4D9A0 /* OCMArg.m */,
0343133B0CCA771800A2E080 /* OCMConstraint.h */,
0343133C0CCA771800A2E080 /* OCMConstraint.m */,
037860E00F6A3D4600A4D9A0 /* OCMPassByRefSetter.h */,
037860E10F6A3D4600A4D9A0 /* OCMPassByRefSetter.m */,
03A2D0C909F01D13008A1AFD /* NSInvocation+OCMAdditions.h */,
03A2D0CA09F01D13008A1AFD /* NSInvocation+OCMAdditions.m */,
03D880D30F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.h */,
03D880D40F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.m */,
0338AA1007BE866F0066DE8A /* NSMethodSignature+Private.h */,
037C13470FCC475500257C8C /* Core Mocks */,
037C13480FCC478500257C8C /* Partial Mocks */,
037C13490FCC479D00257C8C /* Observer Mocks */,
037C134A0FCC47B500257C8C /* Argument Handling */,
037C134B0FCC47CA00257C8C /* Foundation Additions */,
);
name = Implementation;
sourceTree = "<group>";
Expand Down Expand Up @@ -293,6 +340,7 @@
03D880D50F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.h in Headers */,
03D881090F8DB0BB0087D071 /* OCMObserverRecorder.h in Headers */,
03D8822F0FA151E20087D071 /* OCPartialMockObject.h in Headers */,
037C13450FCC474D00257C8C /* OCPartialMockRecorder.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -438,6 +486,7 @@
03D880D70F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.m in Sources */,
03D8815C0F8DB37B0087D071 /* OCMObserverRecorder.m in Sources */,
03D882310FA151E20087D071 /* OCPartialMockObject.m in Sources */,
037C13440FCC474D00257C8C /* OCPartialMockRecorder.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -457,6 +506,7 @@
03D880D60F8DA4750087D071 /* NSNotificationCenter+OCMAdditions.m in Sources */,
03D8815B0F8DB37B0087D071 /* OCMObserverRecorder.m in Sources */,
03D882300FA151E20087D071 /* OCPartialMockObject.m in Sources */,
037C13460FCC474D00257C8C /* OCPartialMockRecorder.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions Source/OCMockObject.h
Expand Up @@ -29,4 +29,7 @@

- (void)verify;

- (BOOL)handleInvocation:(NSInvocation *)anInvocation;
- (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation;

@end

0 comments on commit 4d9fa02

Please sign in to comment.