Skip to content

Commit 496b245

Browse files
author
Ben Asher
committed
merged master
2 parents 197b35f + 4c39808 commit 496b245

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

Source/OCMock/NSInvocation+OCMAdditions.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
131131
{
132132
long double value;
133133
[self getArgument:&value atIndex:argIndex];
134-
return [NSValue valueWithBytes:&value objCType:@encode(typeof(value))];
134+
return [NSValue valueWithBytes:&value objCType:@encode(__typeof__(value))];
135135
}
136136
case 'B':
137137
{

Source/OCMock/OCMStubRecorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@interface OCMStubRecorder (Properties)
3434

35-
#define andReturn(aValue) _andReturn(({ typeof(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(typeof(_v))]; }))
35+
#define andReturn(aValue) _andReturn(({ __typeof__(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(__typeof__(_v))]; }))
3636
@property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *);
3737

3838
#define andThrow(anException) _andThrow(anException)

Source/OCMock/OCMockObject.m

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,6 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation
266266
}
267267
}
268268

269-
- (OCMInvocationExpectation *)_firstNonNeverExpectation
270-
{
271-
for (OCMInvocationExpectation *expectation in expectations)
272-
{
273-
if (![expectation isMatchAndReject])
274-
{
275-
return expectation;
276-
}
277-
}
278-
return nil;
279-
}
280-
281269
- (BOOL)handleInvocation:(NSInvocation *)anInvocation
282270
{
283271
[invocations addObject:anInvocation];
@@ -294,25 +282,35 @@ - (BOOL)handleInvocation:(NSInvocation *)anInvocation
294282
if(stub == nil)
295283
return NO;
296284

297-
if([expectations containsObject:stub])
298-
{
299-
OCMInvocationExpectation *expectation = [self _firstNonNeverExpectation];
300-
if(expectationOrderMatters && expectation && (expectation != stub))
301-
{
302-
[NSException raise:NSInternalInconsistencyException format:@"%@: unexpected method invoked: %@\n\texpected:\t%@", [self description], [stub description], [[expectations objectAtIndex:0] description]];
303-
}
304-
305-
// We can't check isSatisfied yet, since the stub won't be satisfied until we call handleInvocation:, and we don't want to call handleInvocation: yes for the reason in the comment above, since we'll still have the current expectation in the expectations array, which will cause an exception if expectationOrderMatters is YES and we're not ready for any future expected methods to be called yet
306-
if(![(OCMInvocationExpectation *)stub isMatchAndReject])
307-
{
308-
[expectations removeObject:stub];
309-
[stubs removeObject:stub];
310-
}
311-
}
312-
[stub handleInvocation:anInvocation];
313-
[stub release];
285+
if([expectations containsObject:stub])
286+
{
287+
OCMInvocationExpectation *expectation = [self _nextExptectedInvocation];
288+
if(expectationOrderMatters && (expectation != stub))
289+
{
290+
[NSException raise:NSInternalInconsistencyException format:@"%@: unexpected method invoked: %@\n\texpected:\t%@",
291+
[self description], [stub description], [[expectations objectAtIndex:0] description]];
292+
}
293+
294+
// We can't check isSatisfied yet, since the stub won't be satisfied until we call handleInvocation:, and we don't want to call handleInvocation: yes for the reason in the comment above, since we'll still have the current expectation in the expectations array, which will cause an exception if expectationOrderMatters is YES and we're not ready for any future expected methods to be called yet
295+
if(![(OCMInvocationExpectation *)stub isMatchAndReject])
296+
{
297+
[expectations removeObject:stub];
298+
[stubs removeObject:stub];
299+
}
300+
}
301+
[stub handleInvocation:anInvocation];
302+
[stub release];
303+
304+
return YES;
305+
}
314306

315-
return YES;
307+
308+
- (OCMInvocationExpectation *)_nextExptectedInvocation
309+
{
310+
for(OCMInvocationExpectation *expectation in expectations)
311+
if(![expectation isMatchAndReject])
312+
return expectation;
313+
return nil;
316314
}
317315

318316
- (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation

Source/OCMockTests/NSInvocationOCMAdditionsTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ @implementation NSValue(OCMTestAdditions)
2222

2323
- (id)ocmtest_initWithLongDouble:(long double)ldbl
2424
{
25-
return [self initWithBytes:&ldbl objCType:@encode(typeof(ldbl))];
25+
return [self initWithBytes:&ldbl objCType:@encode(__typeof__(ldbl))];
2626
}
2727

2828
@end

Source/OCMockTests/OCMockObjectPartialMocksTests.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,6 @@ - (void)testRefusesToCreatePartialMockForTollFreeBridgedClasses
245245
@"should throw NSInvalidArgumentException exception");
246246
}
247247

248-
- (void)testRejectThenExpectWithExpectationOrdering
249-
{
250-
TestClassThatCallsSelf *object = [[TestClassThatCallsSelf alloc] init];
251-
id mock = OCMPartialMock(object);
252-
[mock setExpectationOrderMatters:YES];
253-
[[mock reject] method1];
254-
[[mock expect] method2];
255-
XCTAssertNoThrow([object method2], @"Since method1 should be rejected, we shouldn't expect it to be called before method2.");
256-
}
257-
258248
- (void)testExpectedMethodCallsExpectedMethodWithExpectationOrdering {
259249
TestClassThatCallsSelf *object = [[TestClassThatCallsSelf alloc] init];
260250
id mock = OCMPartialMock(object);

Source/OCMockTests/OCMockObjectTests.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,15 @@ - (void)testRaisesExceptionWhenSequenceIsWrongAndOrderMatters
824824
XCTAssertThrows([mock uppercaseString], @"Should have complained about wrong sequence.");
825825
}
826826

827+
- (void)testRejectThenExpectWithExpectationOrdering
828+
{
829+
[mock setExpectationOrderMatters:YES];
830+
[[mock reject] lowercaseString];
831+
[[mock expect] uppercaseString];
832+
XCTAssertNoThrow([mock uppercaseString], @"Since lowercaseString should be rejected, we shouldn't expect it to be called before uppercaseString.");
833+
}
834+
835+
827836

828837
// --------------------------------------------------------------------------------------
829838
// nice mocks don't complain about unknown methods, unless told to

0 commit comments

Comments
 (0)