File tree 4 files changed +58
-25
lines changed
4 files changed +58
-25
lines changed Original file line number Diff line number Diff line change @@ -39,16 +39,16 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
39
39
40
40
if ((strlen (argType) > 1 ) && (strchr (" {^" , argType[0 ]) == NULL ) && (strcmp (" @?" , argType) != 0 ))
41
41
[NSException raise :NSInvalidArgumentException format: @" Cannot handle argument type '%s '." , argType];
42
-
43
- switch (argType[0 ])
42
+
43
+ if (OCMIsObjectType (argType))
44
+ {
45
+ id value;
46
+ [self getArgument: &value atIndex: argIndex];
47
+ return value;
48
+ }
49
+
50
+ switch (argType[0 ])
44
51
{
45
- case ' #' :
46
- case ' @' :
47
- {
48
- id value;
49
- [self getArgument: &value atIndex: argIndex];
50
- return value;
51
- }
52
52
case ' :' :
53
53
{
54
54
SEL s = (SEL )0 ;
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ BOOL OCMIsObjectType(const char *objCType)
49
49
if ([regex numberOfMatchesInString: type options: 0 range: NSMakeRange (0 , type.length)] > 0 )
50
50
return YES ;
51
51
52
+ // if the return type is a block we treat it like an object
53
+ // TODO: if the runtime were to encode the block's argument and/or return types, this test would not be sufficient
54
+ if (strcmp (objCType, @encode (void (^)())) == 0 )
55
+ return YES ;
56
+
52
57
return NO ;
53
58
}
54
59
Original file line number Diff line number Diff line change @@ -35,6 +35,23 @@ - (void)aSpecialMethod:(byref in __unused void *)someArg
35
35
@end
36
36
37
37
38
+ typedef NSString TypedefString;
39
+
40
+ @interface TestClassWithTypedefObjectArgument : NSObject
41
+
42
+ - (NSString *)stringForTypedef : (TypedefString *)string ;
43
+
44
+ @end
45
+
46
+ @implementation TestClassWithTypedefObjectArgument
47
+
48
+ - (NSString *)stringForTypedef : (TypedefString *)string
49
+ {
50
+ return @" Whatever. Doesn't matter." ;
51
+ }
52
+ @end
53
+
54
+
38
55
@interface TestDelegate : NSObject
39
56
40
57
- (void )go ;
@@ -116,6 +133,15 @@ - (void)testWorksWithTypeQualifiers
116
133
XCTAssertNoThrow ([myMock aSpecialMethod: " foo" ], @" Should not complain about method with type qualifiers." );
117
134
}
118
135
136
+ - (void )testWorksWithTypedefsToObjects
137
+ {
138
+ id myMock = [OCMockObject mockForClass: [TestClassWithTypedefObjectArgument class ]];
139
+ [[[myMock stub ] andReturn: @" stubbed" ] stringForTypedef: [OCMArg any ]];
140
+ id actualReturn = [myMock stringForTypedef: @" Some arg that shouldn't matter" ];
141
+ XCTAssertEqualObjects (actualReturn, @" stubbed" , @" Should have matched invocation." );
142
+ }
143
+
144
+
119
145
#if 0 // can't test this with ARC
120
146
- (void)testAdjustsRetainCountWhenStubbingMethodsThatCreateObjects
121
147
{
Original file line number Diff line number Diff line change @@ -63,6 +63,24 @@ - (OpaquePtr)opaquePtrValue;
63
63
64
64
@end
65
65
66
+ @implementation TestClassWithOpaquePointerMethod
67
+
68
+ typedef struct TestOpaque {
69
+ int i;
70
+ int j;
71
+ } TestOpaque;
72
+
73
+ TestOpaque myOpaque;
74
+
75
+ - (OpaquePtr)opaquePtrValue
76
+ {
77
+ myOpaque.i = 3 ;
78
+ myOpaque.i = 4 ;
79
+ return &myOpaque;
80
+ }
81
+
82
+ @end
83
+
66
84
@interface TestClassWithProperty : NSObject
67
85
68
86
@property (nonatomic , retain ) NSString *title;
@@ -889,20 +907,4 @@ - (void)testCanCreateExpectationsAfterInvocations
889
907
890
908
@end
891
909
892
- @implementation TestClassWithOpaquePointerMethod
893
-
894
- typedef struct TestOpaque {
895
- int i;
896
- int j;
897
- } TestOpaque;
898
-
899
- TestOpaque myOpaque;
900
910
901
- - (OpaquePtr)opaquePtrValue
902
- {
903
- myOpaque.i = 3 ;
904
- myOpaque.i = 4 ;
905
- return &myOpaque;
906
- }
907
-
908
- @end
You can’t perform that action at this time.
0 commit comments