diff --git a/Source/OCMock/NSInvocation+OCMAdditions.m b/Source/OCMock/NSInvocation+OCMAdditions.m index 46807768..2369d528 100644 --- a/Source/OCMock/NSInvocation+OCMAdditions.m +++ b/Source/OCMock/NSInvocation+OCMAdditions.m @@ -224,78 +224,78 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex [self getArgument:&s atIndex:argIndex]; return [NSValue valueWithBytes:&s objCType:":"]; } - case 'i': + case 'i': { int value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 's': { short value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'l': { long value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'q': { long long value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'c': { char value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'C': { unsigned char value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'I': { unsigned int value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'S': { unsigned short value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'L': { unsigned long value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'Q': { unsigned long long value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'f': { float value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'd': { double value; [self getArgument:&value atIndex:argIndex]; return @(value); - } + } case 'D': { long double value; @@ -324,8 +324,8 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex NSMutableData *argumentData = [[[NSMutableData alloc] initWithLength:argSize] autorelease]; [self getArgument:[argumentData mutableBytes] atIndex:argIndex]; return [NSValue valueWithBytes:[argumentData bytes] objCType:argType]; - } - + } + } [NSException raise:NSInvalidArgumentException format:@"Argument type '%s' not supported", argType]; return nil; @@ -335,10 +335,10 @@ - (NSString *)invocationDescription { NSMethodSignature *methodSignature = [self methodSignature]; NSUInteger numberOfArgs = [methodSignature numberOfArguments]; - + if (numberOfArgs == 2) return NSStringFromSelector([self selector]); - + NSArray *selectorParts = [NSStringFromSelector([self selector]) componentsSeparatedByString:@":"]; NSMutableString *description = [[NSMutableString alloc] init]; NSUInteger i; @@ -347,7 +347,7 @@ - (NSString *)invocationDescription [description appendFormat:@"%@%@:", (i > 2 ? @" " : @""), [selectorParts objectAtIndex:(i - 2)]]; [description appendString:[self argumentDescriptionAtIndex:(NSInteger)i]]; } - + return [description autorelease]; } @@ -378,14 +378,14 @@ - (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex case ':': return [self selectorDescriptionAtIndex:argIndex]; default: return [@""]; // avoid confusion with trigraphs... } - + } - (NSString *)objectDescriptionAtIndex:(NSInteger)anInt { id object; - + [self getArgument:&object atIndex:anInt]; if (object == nil) return @"nil"; @@ -407,9 +407,9 @@ - (NSString *)charDescriptionAtIndex:(NSInteger)anInt { unsigned char buffer[128]; memset(buffer, 0x0, 128); - + [self getArgument:&buffer atIndex:anInt]; - + // If there's only one character in the buffer, and it's 0 or 1, then we have a BOOL if (buffer[1] == '\0' && (buffer[0] == 0 || buffer[0] == 1)) return (buffer[0] == 1 ? @"YES" : @"NO"); @@ -421,7 +421,7 @@ - (NSString *)unsignedCharDescriptionAtIndex:(NSInteger)anInt { unsigned char buffer[128]; memset(buffer, 0x0, 128); - + [self getArgument:&buffer atIndex:anInt]; return [NSString stringWithFormat:@"'%c'", *buffer]; } @@ -429,7 +429,7 @@ - (NSString *)unsignedCharDescriptionAtIndex:(NSInteger)anInt - (NSString *)intDescriptionAtIndex:(NSInteger)anInt { int intValue; - + [self getArgument:&intValue atIndex:anInt]; return [NSString stringWithFormat:@"%d", intValue]; } @@ -437,7 +437,7 @@ - (NSString *)intDescriptionAtIndex:(NSInteger)anInt - (NSString *)unsignedIntDescriptionAtIndex:(NSInteger)anInt { unsigned int intValue; - + [self getArgument:&intValue atIndex:anInt]; return [NSString stringWithFormat:@"%d", intValue]; } @@ -445,7 +445,7 @@ - (NSString *)unsignedIntDescriptionAtIndex:(NSInteger)anInt - (NSString *)shortDescriptionAtIndex:(NSInteger)anInt { short shortValue; - + [self getArgument:&shortValue atIndex:anInt]; return [NSString stringWithFormat:@"%hi", shortValue]; } @@ -453,7 +453,7 @@ - (NSString *)shortDescriptionAtIndex:(NSInteger)anInt - (NSString *)unsignedShortDescriptionAtIndex:(NSInteger)anInt { unsigned short shortValue; - + [self getArgument:&shortValue atIndex:anInt]; return [NSString stringWithFormat:@"%hu", shortValue]; } @@ -461,7 +461,7 @@ - (NSString *)unsignedShortDescriptionAtIndex:(NSInteger)anInt - (NSString *)longDescriptionAtIndex:(NSInteger)anInt { long longValue; - + [self getArgument:&longValue atIndex:anInt]; return [NSString stringWithFormat:@"%ld", longValue]; } @@ -469,7 +469,7 @@ - (NSString *)longDescriptionAtIndex:(NSInteger)anInt - (NSString *)unsignedLongDescriptionAtIndex:(NSInteger)anInt { unsigned long longValue; - + [self getArgument:&longValue atIndex:anInt]; return [NSString stringWithFormat:@"%lu", longValue]; } @@ -477,7 +477,7 @@ - (NSString *)unsignedLongDescriptionAtIndex:(NSInteger)anInt - (NSString *)longLongDescriptionAtIndex:(NSInteger)anInt { long long longLongValue; - + [self getArgument:&longLongValue atIndex:anInt]; return [NSString stringWithFormat:@"%qi", longLongValue]; } @@ -485,7 +485,7 @@ - (NSString *)longLongDescriptionAtIndex:(NSInteger)anInt - (NSString *)unsignedLongLongDescriptionAtIndex:(NSInteger)anInt { unsigned long long longLongValue; - + [self getArgument:&longLongValue atIndex:anInt]; return [NSString stringWithFormat:@"%qu", longLongValue]; } @@ -493,7 +493,7 @@ - (NSString *)unsignedLongLongDescriptionAtIndex:(NSInteger)anInt - (NSString *)doubleDescriptionAtIndex:(NSInteger)anInt { double doubleValue; - + [self getArgument:&doubleValue atIndex:anInt]; return [NSString stringWithFormat:@"%f", doubleValue]; } @@ -501,7 +501,7 @@ - (NSString *)doubleDescriptionAtIndex:(NSInteger)anInt - (NSString *)floatDescriptionAtIndex:(NSInteger)anInt { float floatValue; - + [self getArgument:&floatValue atIndex:anInt]; return [NSString stringWithFormat:@"%f", floatValue]; } @@ -509,7 +509,7 @@ - (NSString *)floatDescriptionAtIndex:(NSInteger)anInt - (NSString *)longDoubleDescriptionAtIndex:(NSInteger)anInt { long double longDoubleValue; - + [self getArgument:&longDoubleValue atIndex:anInt]; return [NSString stringWithFormat:@"%Lf", longDoubleValue]; } @@ -522,7 +522,7 @@ - (NSString *)structDescriptionAtIndex:(NSInteger)anInt - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt { void *buffer; - + [self getArgument:&buffer atIndex:anInt]; return [NSString stringWithFormat:@"%p", buffer]; } @@ -531,7 +531,7 @@ - (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt { char buffer[104]; char *cStringPtr; - + [self getArgument:&cStringPtr atIndex:anInt]; strlcpy(buffer, cStringPtr, sizeof(buffer)); strlcpy(buffer + 100, "...", (sizeof(buffer) - 100)); @@ -541,7 +541,7 @@ - (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt - (NSString *)selectorDescriptionAtIndex:(NSInteger)anInt { SEL selectorValue; - + [self getArgument:&selectorValue atIndex:anInt]; return [NSString stringWithFormat:@"@selector(%@)", NSStringFromSelector(selectorValue)]; } diff --git a/Source/OCMock/NSMethodSignature+OCMAdditions.m b/Source/OCMock/NSMethodSignature+OCMAdditions.m index 10031516..47861ff6 100644 --- a/Source/OCMock/NSMethodSignature+OCMAdditions.m +++ b/Source/OCMock/NSMethodSignature+OCMAdditions.m @@ -29,7 +29,7 @@ + (NSMethodSignature *)signatureForDynamicPropertyAccessedWithSelector:(SEL)sele objc_property_t property = [self propertyMatchingSelector:selector inClass:aClass isGetter:&isGetter]; if(property == NULL) return nil; - + const char *propertyAttributesString = property_getAttributes(property); NSArray *propertyAttributes = [[NSString stringWithCString:propertyAttributesString encoding:NSASCIIStringEncoding] componentsSeparatedByString:@","]; @@ -49,7 +49,7 @@ + (NSMethodSignature *)signatureForDynamicPropertyAccessedWithSelector:(SEL)sele NSRange r = [typeStr rangeOfString:@"\""]; // incomplete workaround to deal with structs if(r.location != NSNotFound) typeStr = [typeStr substringToIndex:r.location]; - + NSString *sigStringFormat = isGetter ? @"%@@:" : @"v@:%@"; const char *sigCString = [[NSString stringWithFormat:sigStringFormat, typeStr] cStringUsingEncoding:NSASCIIStringEncoding]; return [NSMethodSignature signatureWithObjCTypes:sigCString]; @@ -59,7 +59,7 @@ + (NSMethodSignature *)signatureForDynamicPropertyAccessedWithSelector:(SEL)sele + (objc_property_t)propertyMatchingSelector:(SEL)selector inClass:(Class)aClass isGetter:(BOOL *)isGetterPtr { NSString *propertyName = NSStringFromSelector(selector); - + // first try selector as is aassuming it's a getter objc_property_t property = class_getProperty(aClass, [propertyName cStringUsingEncoding:NSASCIIStringEncoding]); if(property != NULL) @@ -83,7 +83,7 @@ + (objc_property_t)propertyMatchingSelector:(SEL)selector inClass:(Class)aClass return property; } } - + // search through properties with custom getter/setter that corresponds to selector unsigned int propertiesCount = 0; objc_property_t *allProperties = class_copyPropertyList(aClass, &propertiesCount); diff --git a/Source/OCMock/NSObject+OCMAdditions.m b/Source/OCMock/NSObject+OCMAdditions.m index 3879c806..e962d3de 100644 --- a/Source/OCMock/NSObject+OCMAdditions.m +++ b/Source/OCMock/NSObject+OCMAdditions.m @@ -27,7 +27,7 @@ + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector #ifndef __arm64__ static NSMutableDictionary *_OCMReturnTypeCache; - + if(_OCMReturnTypeCache == nil) _OCMReturnTypeCache = [[NSMutableDictionary alloc] init]; @@ -50,7 +50,7 @@ + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector if(needsStructureReturn) return class_getMethodImplementation_stret([NSObject class], selectorWithNoImplementation); #endif - + return class_getMethodImplementation([NSObject class], selectorWithNoImplementation); } diff --git a/Source/OCMock/OCClassMockObject.m b/Source/OCMock/OCClassMockObject.m index 72a1259b..997cdb6d 100644 --- a/Source/OCMock/OCClassMockObject.m +++ b/Source/OCMock/OCClassMockObject.m @@ -92,7 +92,7 @@ - (void)prepareClassForClassMethodMocking /* the runtime and OCMock depend on string and array; we don't intercept methods on them to avoid endless loops */ if([[mockedClass class] isSubclassOfClass:[NSString class]] || [[mockedClass class] isSubclassOfClass:[NSArray class]]) return; - + /* trying to replace class methods on NSManagedObject and subclasses of it doesn't work; see #339 */ if([mockedClass isSubclassOfClass:objc_getClass("NSManagedObject")]) return; @@ -234,7 +234,7 @@ - (BOOL)conformsToProtocol:(Protocol *)aProtocol /* taken from: `class-dump -f isNS /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/CoreFoundation.framework` - + @ interface NSObject (__NSIsKinds) - (_Bool)isNSValue__; - (_Bool)isNSTimeZone__; diff --git a/Source/OCMock/OCMArg.m b/Source/OCMock/OCMArg.m index dbe3be07..47b9a0ee 100644 --- a/Source/OCMock/OCMArg.m +++ b/Source/OCMock/OCMArg.m @@ -98,7 +98,7 @@ + (id)invokeBlock + (id)invokeBlockWithArgs:(id)first,... NS_REQUIRES_NIL_TERMINATION { - + NSMutableArray *params = [NSMutableArray array]; va_list args; if(first) @@ -113,7 +113,7 @@ + (id)invokeBlockWithArgs:(id)first,... NS_REQUIRES_NIL_TERMINATION va_end(args); } return [[[OCMBlockArgCaller alloc] initWithBlockArguments:params] autorelease]; - + } + (id)defaultValue diff --git a/Source/OCMock/OCMBlockCaller.m b/Source/OCMock/OCMBlockCaller.m index f8e4def0..2dc74c49 100644 --- a/Source/OCMock/OCMBlockCaller.m +++ b/Source/OCMock/OCMBlockCaller.m @@ -19,17 +19,17 @@ @implementation OCMBlockCaller --(id)initWithCallBlock:(void (^)(NSInvocation *))theBlock +-(id)initWithCallBlock:(void (^)(NSInvocation *))theBlock { if ((self = [super init])) { block = [theBlock copy]; } - + return self; } --(void)dealloc +-(void)dealloc { [block release]; [super dealloc]; diff --git a/Source/OCMock/OCMConstraint.m b/Source/OCMock/OCMConstraint.m index 9b51866b..1615f73d 100644 --- a/Source/OCMock/OCMConstraint.m +++ b/Source/OCMock/OCMConstraint.m @@ -37,7 +37,7 @@ - (id)copyWithZone:(struct _NSZone *)zone + (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject { OCMInvocationConstraint *constraint = [OCMInvocationConstraint constraint]; - NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector]; + NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector]; if(signature == nil) [NSException raise:NSInvalidArgumentException format:@"Unkown selector %@ used in constraint.", NSStringFromSelector(aSelector)]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; @@ -138,7 +138,7 @@ - (instancetype)initWithConstraintBlock:(BOOL (^)(id))aBlock { block = [aBlock copy]; } - + return self; } @@ -147,7 +147,7 @@ - (void)dealloc { [super dealloc]; } -- (BOOL)evaluate:(id)value +- (BOOL)evaluate:(id)value { return block ? block(value) : NO; } diff --git a/Source/OCMock/OCMIndirectReturnValueProvider.m b/Source/OCMock/OCMIndirectReturnValueProvider.m index a74e7294..4dfabe6a 100644 --- a/Source/OCMock/OCMIndirectReturnValueProvider.m +++ b/Source/OCMock/OCMIndirectReturnValueProvider.m @@ -26,7 +26,7 @@ - (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector provider = [aProvider retain]; selector = aSelector; } - + return self; } diff --git a/Source/OCMock/OCMLocation.m b/Source/OCMock/OCMLocation.m index 17173253..6f566b8d 100644 --- a/Source/OCMock/OCMLocation.m +++ b/Source/OCMock/OCMLocation.m @@ -31,7 +31,7 @@ - (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUI file = [aFile retain]; line = aLine; } - + return self; } @@ -63,4 +63,3 @@ - (NSUInteger)line { return [OCMLocation locationWithTestCase:testCase file:[NSString stringWithUTF8String:fileCString] line:line]; } - diff --git a/Source/OCMock/OCMMacroState.m b/Source/OCMock/OCMMacroState.m index 2842ab5d..a372b73c 100644 --- a/Source/OCMock/OCMMacroState.m +++ b/Source/OCMock/OCMMacroState.m @@ -133,7 +133,7 @@ - (id)initWithRecorder:(OCMRecorder *)aRecorder { recorder = [aRecorder retain]; } - + return self; } diff --git a/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m b/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m index c3731dc7..9c84ba45 100644 --- a/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m +++ b/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m @@ -49,4 +49,3 @@ - (void)handleInvocation:(NSInvocation *)anInvocation [anInvocation setReturnValue:&returnValue]; } @end - diff --git a/Source/OCMock/OCMNotificationPoster.m b/Source/OCMock/OCMNotificationPoster.m index 766476f3..819aba4b 100644 --- a/Source/OCMock/OCMNotificationPoster.m +++ b/Source/OCMock/OCMNotificationPoster.m @@ -25,7 +25,7 @@ - (id)initWithNotification:(id)aNotification { notification = [aNotification retain]; } - + return self; } diff --git a/Source/OCMock/OCMObserverRecorder.m b/Source/OCMock/OCMObserverRecorder.m index 46ddd44f..27a4266e 100644 --- a/Source/OCMock/OCMObserverRecorder.m +++ b/Source/OCMock/OCMObserverRecorder.m @@ -71,7 +71,7 @@ - (BOOL)matchesNotification:(NSNotification *)aNotification - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg { if([expectedArg isKindOfClass:[OCMConstraint class]]) - { + { return [expectedArg evaluate:observedArg]; } else if([expectedArg conformsToProtocol:objc_getProtocol("HCMatcher")]) diff --git a/Source/OCMock/OCMPassByRefSetter.m b/Source/OCMock/OCMPassByRefSetter.m index fdd3cfe0..f00e1555 100644 --- a/Source/OCMock/OCMPassByRefSetter.m +++ b/Source/OCMock/OCMPassByRefSetter.m @@ -25,7 +25,7 @@ - (id)initWithValue:(id)aValue { value = [aValue retain]; } - + return self; } diff --git a/Source/OCMock/OCMQuantifier.m b/Source/OCMock/OCMQuantifier.m index f9980743..c6ccddfa 100644 --- a/Source/OCMock/OCMQuantifier.m +++ b/Source/OCMock/OCMQuantifier.m @@ -137,4 +137,3 @@ - (NSString *)description } @end - diff --git a/Source/OCMock/OCMRealObjectForwarder.m b/Source/OCMock/OCMRealObjectForwarder.m index 8f5a643d..72a5243d 100644 --- a/Source/OCMock/OCMRealObjectForwarder.m +++ b/Source/OCMock/OCMRealObjectForwarder.m @@ -22,7 +22,7 @@ @implementation OCMRealObjectForwarder -- (void)handleInvocation:(NSInvocation *)anInvocation +- (void)handleInvocation:(NSInvocation *)anInvocation { id invocationTarget = [anInvocation target]; diff --git a/Source/OCMock/OCMStubRecorder.m b/Source/OCMock/OCMStubRecorder.m index 9756129f..da21969b 100644 --- a/Source/OCMock/OCMStubRecorder.m +++ b/Source/OCMock/OCMStubRecorder.m @@ -34,7 +34,7 @@ - (id)init { if(invocationMatcher != nil) [NSException raise:NSInternalInconsistencyException format:@"** Method init invoked twice on stub recorder. Are you trying to mock the init method? This is currently not supported."]; - + self = [super init]; invocationMatcher = [[OCMInvocationStub alloc] init]; return self; @@ -87,7 +87,7 @@ - (id)andCall:(SEL)selector onObject:(id)anObject return self; } -- (id)andDo:(void (^)(NSInvocation *))aBlock +- (id)andDo:(void (^)(NSInvocation *))aBlock { [[self stub] addInvocationAction:[[[OCMBlockCaller alloc] initWithCallBlock:aBlock] autorelease]]; return self; diff --git a/Source/OCMock/OCMVerifier.m b/Source/OCMock/OCMVerifier.m index c9a06f9d..e077bc82 100644 --- a/Source/OCMock/OCMVerifier.m +++ b/Source/OCMock/OCMVerifier.m @@ -29,7 +29,7 @@ - (id)init { invocationMatcher = [[OCMInvocationMatcher alloc] init]; } - + return self; } diff --git a/Source/OCMock/OCObserverMockObject.m b/Source/OCMock/OCObserverMockObject.m index e613b191..2722e38d 100644 --- a/Source/OCMock/OCObserverMockObject.m +++ b/Source/OCMock/OCObserverMockObject.m @@ -33,7 +33,7 @@ - (id)init recorders = [[NSMutableArray alloc] init]; centers = [[NSMutableArray alloc] init]; } - + return self; } @@ -143,7 +143,7 @@ - (void)handleNotification:(NSNotification *)aNotification @synchronized(recorders) { NSUInteger i, limit; - + limit = expectationOrderMatters ? 1 : [recorders count]; for(i = 0; i < limit; i++) { @@ -154,7 +154,7 @@ - (void)handleNotification:(NSNotification *)aNotification } } } - [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected notification observed: %@", [self description], + [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected notification observed: %@", [self description], [aNotification description]]; } diff --git a/Source/OCMock/OCPartialMockObject.m b/Source/OCMock/OCPartialMockObject.m index fc5837e7..d24dfb73 100644 --- a/Source/OCMock/OCPartialMockObject.m +++ b/Source/OCMock/OCPartialMockObject.m @@ -70,7 +70,7 @@ - (Class)classToSubclassForObject:(id)object * is sometimes overridden, by KVO or CoreData, for example, to return a subclass. * * With KVO, if we replace and subclass the actual class, as returned by object_getClass(), - * we lose notifications. So, in that case only, we return the class reported by the class + * we lose notifications. So, in that case only, we return the class reported by the class * method. */ diff --git a/Source/OCMockTests/NSInvocationOCMAdditionsTests.m b/Source/OCMockTests/NSInvocationOCMAdditionsTests.m index 37c9560b..518d1a00 100644 --- a/Source/OCMockTests/NSInvocationOCMAdditionsTests.m +++ b/Source/OCMockTests/NSInvocationOCMAdditionsTests.m @@ -71,7 +71,7 @@ - (void)testInvocationDescriptionWithObjectArgument // Give it one argument (starts at index 2) NSNumber *argument = @1; [invocation setArgument:&argument atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"isEqualToNumber:%d", 1]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -81,7 +81,7 @@ - (void)testInvocationDescriptionWithNSStringArgument NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(isEqualToString:)]; NSString *argument = @"TEST_STRING"; [invocation setArgument:&argument atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"isEqualToString:@\"%@\"", @"TEST_STRING"]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -93,7 +93,7 @@ - (void)testInvocationDescriptionWithObjectArguments NSString *argumentTwo = @"TEST_STRING"; [invocation setArgument:&argumentOne atIndex:2]; [invocation setArgument:&argumentTwo atIndex:3]; - + NSString *expected = [NSString stringWithFormat:@"setValue:%d forKey:@\"%@\"", 1, @"TEST_STRING"]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -103,7 +103,7 @@ - (void)testInvocationDescriptionWithArrayArgument NSInvocation *invocation = [self invocationForClass:[NSMutableArray class] selector:@selector(addObjectsFromArray:)]; NSArray *argument = @[@"TEST_STRING"]; [invocation setArgument:&argument atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"addObjectsFromArray:%@", [argument description]]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -113,7 +113,7 @@ - (void)testInvocationDescriptionWithIntArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithInt:)]; int argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithInt:%d", 1]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -123,7 +123,7 @@ - (void)testInvocationDescriptionWithUnsignedIntArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithUnsignedInt:)]; unsigned int argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithUnsignedInt:%d", 1]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -133,7 +133,7 @@ - (void)testInvocationDescriptionWithBoolArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithBool:)]; BOOL argumentOne = TRUE; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithBool:YES"]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -143,7 +143,7 @@ - (void)testInvocationDescriptionWithCharArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithChar:)]; char argumentOne = 'd'; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithChar:'%c'", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -153,7 +153,7 @@ - (void)testInvocationDescriptionWithUnsignedCharArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithUnsignedChar:)]; unsigned char argumentOne = 'd'; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithUnsignedChar:'%c'", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -163,7 +163,7 @@ - (void)testInvocationDescriptionWithDoubleArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithDouble:)]; double argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithDouble:%f", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -173,7 +173,7 @@ - (void)testInvocationDescriptionWithFloatArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithFloat:)]; float argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithFloat:%f", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -183,7 +183,7 @@ - (void)testInvocationDescriptionWithLongDoubleArgument NSInvocation *invocation = [self invocationForClass:[NSValue class] selector:@selector(ocmtest_initWithLongDouble:)]; long double argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"ocmtest_initWithLongDouble:%Lf", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -193,7 +193,7 @@ - (void)testInvocationDescriptionWithLongArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithLong:)]; long argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithLong:%ld", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -203,7 +203,7 @@ - (void)testInvocationDescriptionWithUnsignedLongArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithUnsignedLong:)]; unsigned long argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithUnsignedLong:%lu", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -213,7 +213,7 @@ - (void)testInvocationDescriptionWithLongLongArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithLongLong:)]; long long argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithLongLong:%qi", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -223,7 +223,7 @@ - (void)testInvocationDescriptionWithUnsignedLongLongArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithUnsignedLongLong:)]; unsigned long long argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithUnsignedLongLong:%qu", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -233,7 +233,7 @@ - (void)testInvocationDescriptionWithShortArgument NSInvocation *invocation = [self invocationForClass:[NSNumber class] selector:@selector(initWithShort:)]; short argumentOne = 1; [invocation setArgument:&argumentOne atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithShort:%hi", argumentOne]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -255,7 +255,7 @@ - (void)testInvocationDescriptionWithStructArgument range.location = 2; range.length = 4; [invocation setArgument:&range atIndex:2]; - + NSString *expected = @"substringWithRange:(NSRange: {2, 4})"; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -264,7 +264,7 @@ - (void)testInvocationDescriptionWithCStringArgument { NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithUTF8String:)]; NSString *string = @"A string that is longer than 100 characters. 123456789 123456789 123456789 123456789 123456789 123456789"; - const char *cString = [string UTF8String]; + const char *cString = [string UTF8String]; [invocation setArgument:&cString atIndex:2]; NSString *expected = [NSString stringWithFormat:@"initWithUTF8String:\"%@...\"", [string substringToIndex:100]]; @@ -276,7 +276,7 @@ - (void)testInvocationDescriptionWithSelectorArgument NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(respondsToSelector:)]; SEL selectorValue = @selector(testInvocationDescriptionWithSelectorArgument); [invocation setArgument:&selectorValue atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"respondsToSelector:@selector(%@)", NSStringFromSelector(selectorValue)]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } @@ -289,7 +289,7 @@ - (void)testInvocationDescriptionWithPointerArgument NSUInteger length = [data length]; [invocation setArgument:&bytes atIndex:2]; [invocation setArgument:&length atIndex:3]; - + NSString *expected1 = [NSString stringWithFormat:@"initWithBytes:"]; NSString *expected2 = [NSString stringWithFormat:@"length:%lu", (unsigned long)length]; NSString *invocationDescription = [invocation invocationDescription]; @@ -302,7 +302,7 @@ - (void)testInvocationDescriptionWithNilArgument NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithString:)]; NSString *argString = nil; [invocation setArgument:&argString atIndex:2]; - + NSString *expected = [NSString stringWithFormat:@"initWithString:nil"]; XCTAssertEqualObjects(expected, [invocation invocationDescription], @""); } diff --git a/Source/OCMockTests/NSMethodSignatureOCMAdditionsTests.m b/Source/OCMockTests/NSMethodSignatureOCMAdditionsTests.m index 82aa550a..10336505 100644 --- a/Source/OCMockTests/NSMethodSignatureOCMAdditionsTests.m +++ b/Source/OCMockTests/NSMethodSignatureOCMAdditionsTests.m @@ -54,7 +54,7 @@ - (void)testArchDependentSpecialReturns @"Special (stret) return incorrect for type '%s'", enctype); \ } while (0) #define ASSERT_TYPE(expected, type) ASSERT_ENC(expected, @encode(type)) - + #if __x86_64__ ASSERT_TYPE(YES,NSRect); ASSERT_TYPE(NO, NSPoint); diff --git a/Source/OCMockTests/OCMArgTests.m b/Source/OCMockTests/OCMArgTests.m index 3f07eee2..91a02404 100644 --- a/Source/OCMockTests/OCMArgTests.m +++ b/Source/OCMockTests/OCMArgTests.m @@ -51,7 +51,7 @@ - (void)testValueMacroCreatesCorrectValueObjects - (void)testIsKindOfClassCheck { OCMBlockConstraint *constraint = [OCMArg isKindOfClass:[NSString class]]; - + XCTAssertTrue([constraint evaluate:@"foo"], @"Should have accepted \"foo\"."); XCTAssertFalse([constraint evaluate:[NSArray array]], @"Should not have accepted other value."); XCTAssertFalse([constraint evaluate:nil], @"Should not have accepted nil."); @@ -61,7 +61,7 @@ -(void)testResolvesSpecialAnySelectorToAnyConstraint { SEL anySelector = [OCMArg anySelector]; NSValue *anySelectorValue = [NSValue valueWithBytes:&anySelector objCType:@encode(SEL)]; - + XCTAssertTrue([[OCMArg resolveSpecialValues:anySelectorValue] isKindOfClass:[OCMAnyConstraint class]]); } @@ -75,7 +75,7 @@ -(void)testResolvesSpecialAnyPointerToAnyConstraint { void *anyPointer = [OCMArg anyPointer]; NSValue *anyPointerValue = [NSValue valueWithPointer:anyPointer]; - + XCTAssertTrue([[OCMArg resolveSpecialValues:anyPointerValue] isKindOfClass:[OCMAnyConstraint class]]); } diff --git a/Source/OCMockTests/OCMBoxedReturnValueProviderTests.m b/Source/OCMockTests/OCMBoxedReturnValueProviderTests.m index a5f0c2be..7765374b 100644 --- a/Source/OCMockTests/OCMBoxedReturnValueProviderTests.m +++ b/Source/OCMockTests/OCMBoxedReturnValueProviderTests.m @@ -120,7 +120,3 @@ - (void)testCorrectEqualityForStructureWithoutName } @end - - - - diff --git a/Source/OCMockTests/OCMConstraintTests.m b/Source/OCMockTests/OCMConstraintTests.m index dde0fc90..7e0c711d 100644 --- a/Source/OCMockTests/OCMConstraintTests.m +++ b/Source/OCMockTests/OCMConstraintTests.m @@ -44,27 +44,27 @@ - (void)testAnyAcceptsAnything - (void)testIsNilAcceptsOnlyNil { OCMConstraint *constraint = [OCMIsNilConstraint constraint]; - + XCTAssertFalse([constraint evaluate:@"foo"], @"Should not have accepted a value."); - XCTAssertTrue([constraint evaluate:nil], @"Should have accepted nil."); + XCTAssertTrue([constraint evaluate:nil], @"Should have accepted nil."); } - (void)testIsNotNilAcceptsAnythingButNil { OCMConstraint *constraint = [OCMIsNotNilConstraint constraint]; - + XCTAssertTrue([constraint evaluate:@"foo"], @"Should have accepted a value."); - XCTAssertFalse([constraint evaluate:nil], @"Should not have accepted nil."); + XCTAssertFalse([constraint evaluate:nil], @"Should not have accepted nil."); } - (void)testNotEqualAcceptsAnythingButValue { OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constraint]; constraint->testValue = @"foo"; - + XCTAssertFalse([constraint evaluate:@"foo"], @"Should not have accepted value."); - XCTAssertTrue([constraint evaluate:@"bar"], @"Should have accepted other value."); - XCTAssertTrue([constraint evaluate:nil], @"Should have accepted nil."); + XCTAssertTrue([constraint evaluate:@"bar"], @"Should have accepted other value."); + XCTAssertTrue([constraint evaluate:nil], @"Should have accepted nil."); } @@ -119,14 +119,14 @@ -(void)testUsesBlock { return [value isEqualToString:@"foo"]; }; - + OCMBlockConstraint *constraint = [[OCMBlockConstraint alloc] initWithConstraintBlock:checkForFooBlock]; XCTAssertTrue([constraint evaluate:@"foo"], @"Should have accepted foo."); XCTAssertFalse([constraint evaluate:@"bar"], @"Should not have accepted bar."); } --(void)testBlockConstraintCanCaptureArgument +-(void)testBlockConstraintCanCaptureArgument { __block NSString *captured; BOOL (^captureArgBlock)(id) = ^(id value) @@ -134,7 +134,7 @@ -(void)testBlockConstraintCanCaptureArgument captured = value; return YES; }; - + OCMBlockConstraint *constraint = [[OCMBlockConstraint alloc] initWithConstraintBlock:captureArgBlock]; [constraint evaluate:@"foo"]; @@ -146,7 +146,7 @@ -(void)testBlockConstraintCanCaptureArgument - (void)testEvaluateNilBlockReturnsNo { OCMBlockConstraint *constraint = [[OCMBlockConstraint alloc] initWithConstraintBlock:nil]; - + XCTAssertFalse([constraint evaluate:@"foo"]); } diff --git a/Source/OCMockTests/OCMQuantifierTests.m b/Source/OCMockTests/OCMQuantifierTests.m index 44a55595..eb904559 100644 --- a/Source/OCMockTests/OCMQuantifierTests.m +++ b/Source/OCMockTests/OCMQuantifierTests.m @@ -97,30 +97,30 @@ - (void)testExactlyThrowsWhenCountTooLarge - (void)testAtLeastThrowsWhenMinimumCountIsNotReached { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; - + XCTAssertThrows([[[mock verify] withQuantifier:[OCMQuantifier atLeast:2]] doStuff]); } - (void)testAtLeastMatchesMinimumCount { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; [mock doStuff]; - + [[[mock verify] withQuantifier:[OCMQuantifier atLeast:2]] doStuff]; } - (void)testAtLeastMatchesMoreThanMinimumCount { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; [mock doStuff]; [mock doStuff]; - + [[[mock verify] withQuantifier:[OCMQuantifier atLeast:2]] doStuff]; } @@ -133,7 +133,7 @@ - (void)testAtLeastThrowsWhenInitializedWithZeroCount - (void)testAtMostMatchesUpToMaximumCount { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; [[[mock verify] withQuantifier:[OCMQuantifier atMost:1]] doStuff]; @@ -142,10 +142,10 @@ - (void)testAtMostMatchesUpToMaximumCount - (void)testAtMostThrowsWhenMaximumCountIsExceeded { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; [mock doStuff]; - + XCTAssertThrows([[[mock verify] withQuantifier:[OCMQuantifier atMost:1]] doStuff]); } @@ -158,7 +158,7 @@ - (void)testAtMostThrowsWhenInitializedWithZeroCount - (void)testNeverThrowsWhenInvocationsOccurred { id mock = OCMClassMock([TestClassForQuantifiers class]); - + [mock doStuff]; XCTAssertThrows([[[mock verify] withQuantifier:[OCMQuantifier never]] doStuff]); @@ -183,4 +183,3 @@ - (void)testQuantifierMacroFailure } @end - diff --git a/Source/OCMockTests/OCMockObjectClassMethodMockingTests.m b/Source/OCMockTests/OCMockObjectClassMethodMockingTests.m index 7ea2ebf2..6f2797d1 100644 --- a/Source/OCMockTests/OCMockObjectClassMethodMockingTests.m +++ b/Source/OCMockTests/OCMockObjectClassMethodMockingTests.m @@ -105,10 +105,10 @@ - (void)testCanExpectTheSameClassMethodMoreThanOnce - (void)testClassReceivesMethodsAfterStopWasCalled { id mock = [OCMockObject mockForClass:[TestClassWithClassMethods class]]; - + [[[[mock stub] classMethod] andReturn:@"mocked"] foo]; [mock stopMocking]; - + XCTAssertEqualObjects(@"Foo-ClassMethod", [TestClassWithClassMethods foo], @"Should not have stubbed class method."); } @@ -117,7 +117,7 @@ - (void)testClassReceivesMethodAgainWhenExpectedCallOccurred id mock = [OCMockObject mockForClass:[TestClassWithClassMethods class]]; [[[[mock expect] classMethod] andReturn:@"mocked"] foo]; - + XCTAssertEqualObjects(@"mocked", [TestClassWithClassMethods foo], @"Should have stubbed method."); XCTAssertEqualObjects(@"Foo-ClassMethod", [TestClassWithClassMethods foo], @"Should have 'unstubbed' method."); } @@ -191,9 +191,9 @@ - (void)testStubbingIsOnlyActiveAtTheClassItWasAdded - (void)testStubsOnlyClassMethodWhenInstanceMethodWithSameNameExists { id mock = [OCMockObject mockForClass:[TestClassWithClassMethods class]]; - + [[[[mock stub] classMethod] andReturn:@"mocked"] bar]; - + XCTAssertEqualObjects(@"mocked", [TestClassWithClassMethods bar], @"Should have stubbed class method."); XCTAssertThrows([mock bar], @"Should not have stubbed instance method."); } @@ -201,19 +201,19 @@ - (void)testStubsOnlyClassMethodWhenInstanceMethodWithSameNameExists - (void)testStubsClassMethodWhenNoInstanceMethodExistsWithName { id mock = [OCMockObject mockForClass:[TestClassWithClassMethods class]]; - + [[[mock stub] andReturn:@"mocked"] foo]; - + XCTAssertEqualObjects(@"mocked", [TestClassWithClassMethods foo], @"Should have stubbed class method."); } - (void)testStubsCanDistinguishInstanceAndClassMethods { id mock = [OCMockObject mockForClass:[TestClassWithClassMethods class]]; - + [[[[mock stub] classMethod] andReturn:@"mocked-class"] bar]; [[[mock stub] andReturn:@"mocked-instance"] bar]; - + XCTAssertEqualObjects(@"mocked-class", [TestClassWithClassMethods bar], @"Should have stubbed class method."); XCTAssertEqualObjects(@"mocked-instance", [mock bar], @"Should have stubbed instance method."); } @@ -237,15 +237,15 @@ - (void)testRevertsAllStubbedMethodsOnDealloc - (void)testRevertsAllStubbedMethodsOnPartialMockDealloc { id mock = [[OCPartialMockObject alloc] initWithClass:[TestClassWithClassMethods class]]; - + [[[[mock stub] classMethod] andReturn:@"mocked-foo"] foo]; [[[[mock stub] classMethod] andReturn:@"mocked-bar"] bar]; - + XCTAssertEqualObjects(@"mocked-foo", [TestClassWithClassMethods foo], @"Should have stubbed class method 'foo'."); XCTAssertEqualObjects(@"mocked-bar", [TestClassWithClassMethods bar], @"Should have stubbed class method 'bar'."); - + mock = nil; - + XCTAssertEqualObjects(@"Foo-ClassMethod", [TestClassWithClassMethods foo], @"Should have 'unstubbed' class method 'foo'."); XCTAssertEqualObjects(@"Bar-ClassMethod", [TestClassWithClassMethods bar], @"Should have 'unstubbed' class method 'bar'."); } @@ -304,7 +304,7 @@ - (void)testForwardToRealObject NSString *result = [TestClassWithClassMethods foo]; XCTAssertEqualObjects(result, classFooValue); XCTAssertNoThrow([mock verify]); - + [[[mock expect] andForwardToRealObject] foo]; result = [TestClassWithClassMethods foo]; XCTAssertEqualObjects(result, classFooValue); @@ -314,7 +314,7 @@ - (void)testForwardToRealObject result = [TestClassWithClassMethods bar]; XCTAssertEqualObjects(result, classBarValue); XCTAssertNoThrow([mock verify]); - + [[[[mock expect] classMethod] andForwardToRealObject] bar]; XCTAssertThrowsSpecificNamed([mock bar], NSException, NSInternalInconsistencyException, @""); diff --git a/Source/OCMockTests/OCMockObjectMacroTests.m b/Source/OCMockTests/OCMockObjectMacroTests.m index c4ba9f87..ea726b50 100644 --- a/Source/OCMockTests/OCMockObjectMacroTests.m +++ b/Source/OCMockTests/OCMockObjectMacroTests.m @@ -92,13 +92,13 @@ - (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *) - (void)testReportsVerifyFailureWithCorrectLocation { id mock = OCMClassMock([NSString class]); - + [[mock expect] lowercaseString]; - + shouldCaptureFailure = YES; OCMVerifyAll(mock); const char *expectedFile = __FILE__; int expectedLine = __LINE__; shouldCaptureFailure = NO; - + XCTAssertNotNil(reportedDescription, @"Should have recorded a failure with description."); XCTAssertEqualObjects([NSString stringWithUTF8String:expectedFile], reportedFile, @"Should have reported correct file."); XCTAssertEqual(expectedLine, (int)reportedLine, @"Should have reported correct line"); @@ -107,7 +107,7 @@ - (void)testReportsVerifyFailureWithCorrectLocation - (void)testReportsIgnoredExceptionsAtVerifyLocation { id mock = OCMClassMock([NSString class]); - + [[mock reject] lowercaseString]; @try @@ -122,7 +122,7 @@ - (void)testReportsIgnoredExceptionsAtVerifyLocation shouldCaptureFailure = YES; OCMVerifyAll(mock); const char *expectedFile = __FILE__; int expectedLine = __LINE__; shouldCaptureFailure = NO; - + XCTAssertTrue([reportedDescription rangeOfString:@"ignored"].location != NSNotFound, @"Should have reported ignored exceptions."); XCTAssertEqualObjects([NSString stringWithUTF8String:expectedFile], reportedFile, @"Should have reported correct file."); XCTAssertEqual(expectedLine, (int)reportedLine, @"Should have reported correct line"); diff --git a/Source/OCMockTests/OCMockObjectPartialMocksTests.m b/Source/OCMockTests/OCMockObjectPartialMocksTests.m index c1202c4e..6f2fa04d 100644 --- a/Source/OCMockTests/OCMockObjectPartialMocksTests.m +++ b/Source/OCMockTests/OCMockObjectPartialMocksTests.m @@ -357,62 +357,62 @@ - (void)testSettingUpSecondPartialMockForSameClassDoesNotAffectStubs - (void)testMockingManagedObject { // Set up the Core Data stack for the test. - + NSManagedObjectModel *const model = [NSManagedObjectModel mergedModelFromBundles:@[[NSBundle bundleForClass:self.class]]]; NSEntityDescription *const entity = model.entitiesByName[NSStringFromClass([OCTestManagedObject class])]; NSPersistentStoreCoordinator *const coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; [coordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL]; NSManagedObjectContext *const context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; - + // Create and mock a real core data object. - + OCTestManagedObject *const realObject = [[OCTestManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:context]; OCTestManagedObject *const partialMock = [OCMockObject partialMockForObject:realObject]; - + // Verify the subclassing behaviour is as we expect. - + Class const runtimeObjectClass = object_getClass(realObject); Class const reportedClass = [realObject class]; - + // Core Data generates a dynamic subclass at runtime to implement modeled proprerties. // It will look something like "OCTestManagedObject_OCTestManagedObject_". XCTAssertTrue([runtimeObjectClass isSubclassOfClass:reportedClass]); XCTAssertNotEqual(runtimeObjectClass, reportedClass); - + // Verify accessors and setters for attributes work as expected. - + partialMock.name = @"OCMock"; partialMock.sortOrder = 120; - + XCTAssertEqualObjects(partialMock.name, @"OCMock"); XCTAssertEqual(partialMock.sortOrder, 120); - + partialMock.name = nil; partialMock.sortOrder = 0; - + XCTAssertNil(partialMock.name); XCTAssertEqual(partialMock.sortOrder, 0); - + // Verify to-many relationships work as expected. - + OCTestManagedObject *const realObject2 = [[OCTestManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:context]; OCTestManagedObject *const realObject3 = [[OCTestManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:context]; - + [partialMock addToManyRelationshipObject:realObject2]; - + XCTAssertEqualObjects(partialMock.toManyRelationship, [NSSet setWithObject:realObject2]); XCTAssertEqualObjects(realObject2.toManyRelationship, [NSSet setWithObject:realObject]); - + partialMock.toOneRelationship = realObject3; - + XCTAssertEqualObjects(partialMock.toOneRelationship, realObject3); XCTAssertEqualObjects(realObject3.toOneRelationship, realObject); - + // Verify saving the context works as expected. - + NSError *saveError = nil; [context save:&saveError]; - + XCTAssertNil(saveError); } @@ -456,16 +456,16 @@ - (void)testPartialMockOnKVOObserved static char *MyContext; TestClassThatCallsSelf *realObject = [[TestClassThatCallsSelf alloc] init]; Class origClass = [realObject class]; - + [realObject addObserver:self forKeyPath:@"methodInt" options:NSKeyValueObservingOptionNew context:MyContext]; Class kvoClass = object_getClass(realObject); id mock = [OCMockObject partialMockForObject:realObject]; Class ourSubclass = object_getClass(realObject); - + XCTAssertEqualObjects([realObject class], origClass, @"We did not preserve the original [self class]"); XCTAssertFalse(ourSubclass == kvoClass, @"KVO with subclass did not work"); - + /* Due to the way we replace the object's class, the KVO class gets overwritten and KVO notifications stop functioning. If we did not do this, the presence of the mock subclass would cause KVO to crash, at least without further tinkering. */ @@ -536,10 +536,10 @@ - (void)testForwardsToRealObjectWhenSetUpAndCalledOnMock { TestClassWithSimpleMethod *realObject = [[TestClassWithSimpleMethod alloc] init]; id mock = [OCMockObject partialMockForObject:realObject]; - + [[[mock expect] andForwardToRealObject] foo]; XCTAssertEqual(@"Foo", [mock foo], @"Should have called method on real object."); - + [mock verify]; } @@ -547,10 +547,10 @@ - (void)testForwardsToRealObjectWhenSetUpAndCalledOnRealObject { TestClassWithSimpleMethod *realObject = [[TestClassWithSimpleMethod alloc] init]; id mock = [OCMockObject partialMockForObject:realObject]; - + [[[mock expect] andForwardToRealObject] foo]; XCTAssertEqual(@"Foo", [realObject foo], @"Should have called method on real object."); - + [mock verify]; } diff --git a/Source/OCMockTests/OCMockObjectTests.m b/Source/OCMockTests/OCMockObjectTests.m index 33037b43..41be1af0 100644 --- a/Source/OCMockTests/OCMockObjectTests.m +++ b/Source/OCMockTests/OCMockObjectTests.m @@ -335,7 +335,7 @@ - (void)testRaisesExceptionWhenMethodWithWrongPointerArgumentIsCalled - (void)testAcceptsStubbedMethodWithAnyPointerArgument { [[mock stub] getCharacters:[OCMArg anyPointer]]; - + unichar buffer[10]; XCTAssertNoThrow([mock getCharacters:buffer], @"Should have stubbed method."); } @@ -603,7 +603,7 @@ - (void)testReturningMockFromMethodItStubsDoesntCreateRetainCycleWhenUsingMacro OCMStub([mockWithShortLifetime shared]).andReturn(mockWithShortLifetime); } id singleton = [TestClassWithClassMethod shared]; - + XCTAssertEqualObjects(@"foo", [singleton stringValue], @"Should return value from real implementation (because shared is not stubbed anymore)."); } @@ -739,10 +739,10 @@ - (void)testReturnsValuesInNullPassByReferenceArguments - (void)testInvokesBlockWithArgs { - + BOOL bVal = YES, *bPtr = &bVal; [[mock stub] enumerateLinesUsingBlock:[OCMArg invokeBlockWithArgs:@"First param", OCMOCK_VALUE(bPtr), nil]]; - + __block BOOL wasCalled = NO; __block NSString *firstParam; __block BOOL *secondParam; @@ -776,7 +776,7 @@ - (void)testThrowsIfArgTypesMismatch - (void)testThrowsIfArgsLengthMismatch { [[mock stub] enumerateLinesUsingBlock:[OCMArg invokeBlockWithArgs:@"First but no second", nil]]; - + XCTAssertThrowsSpecificNamed([mock enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {}], NSException, NSInvalidArgumentException, @"Should have raised an exception."); } @@ -785,7 +785,7 @@ - (void)testThrowsForUnknownDefaults /// @note Should throw because we don't construct default values for the NSRange struct /// arguments. [[mock stub] enumerateSubstringsInRange:NSMakeRange(0, 10) options:NSStringEnumerationByLines usingBlock:[OCMArg invokeBlock]]; - + XCTAssertThrowsSpecificNamed([mock enumerateSubstringsInRange:NSMakeRange(0, 10) options:NSStringEnumerationByLines usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {}], NSException, NSInvalidArgumentException, @"No exception occurred"); } @@ -794,14 +794,14 @@ - (void)testThrowsForIndividualUnknownDefault /// @note Should throw because of the third argument (we don't construct a default for struct /// values). [[mock stub] enumerateSubstringsInRange:NSMakeRange(0, 10) options:NSStringEnumerationByLines usingBlock:[OCMArg invokeBlockWithArgs:@"String 1", OCMOCK_VALUE(NSMakeRange(0, 10)), [OCMArg defaultValue], [OCMArg defaultValue], nil]]; - + XCTAssertThrowsSpecificNamed([mock enumerateSubstringsInRange:NSMakeRange(0, 10) options:NSStringEnumerationByLines usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {}], NSException, NSInvalidArgumentException, @"No exception occurred"); } - (void)testInvokesBlockWithDefaultArgs { [[mock stub] enumerateLinesUsingBlock:[OCMArg invokeBlockWithArgs:[OCMArg defaultValue], [OCMArg defaultValue], nil]]; - + __block NSString *firstParam; __block BOOL *secondParam; void (^block)(NSString *, BOOL *) = ^(NSString *line, BOOL *stop) @@ -810,7 +810,7 @@ - (void)testInvokesBlockWithDefaultArgs secondParam = stop; }; [mock enumerateLinesUsingBlock:block]; - + XCTAssertNil(firstParam, @"First param does not default to nil"); XCTAssertEqual(secondParam, NULL, @"Second param does not default to NULL"); } @@ -818,7 +818,7 @@ - (void)testInvokesBlockWithDefaultArgs - (void)testInvokesBlockWithAllDefaultArgs { [[mock stub] enumerateLinesUsingBlock:[OCMArg invokeBlock]]; - + __block NSString *firstParam; __block BOOL *secondParam; void (^block)(NSString *, BOOL *) = ^(NSString *line, BOOL *stop) @@ -827,7 +827,7 @@ - (void)testInvokesBlockWithAllDefaultArgs secondParam = stop; }; [mock enumerateLinesUsingBlock:block]; - + XCTAssertNil(firstParam, @"First param does not default to nil"); XCTAssertEqual(secondParam, NULL, @"Second param does not default to NULL"); } @@ -989,10 +989,10 @@ - (void)testAcceptsAndVerifiesExpectedMethodsWithDelay { [[mock expect] lowercaseString]; [[mock expect] uppercaseString]; - + [mock lowercaseString]; [mock uppercaseString]; - + [mock verifyWithDelay:1]; } @@ -1002,7 +1002,7 @@ - (void)testAcceptsAndVerifiesExpectedMethodsWithDelayBlock [NSThread sleepForTimeInterval:0.1]; [self->mock lowercaseString]; }); - + [[mock expect] lowercaseString]; [mock verifyWithDelay:1]; } @@ -1013,7 +1013,7 @@ - (void)testFailsVerifyExpectedMethodsWithoutDelay [NSThread sleepForTimeInterval:0.1]; [self->mock lowercaseString]; }); - + [[mock expect] lowercaseString]; XCTAssertThrows([mock verify], @"Should have raised an exception because method was not called in time."); [mock verifyWithDelay:1]; @@ -1096,5 +1096,3 @@ - (void)testUncalledRejectStubDoesNotCountAsExpectation @end - - diff --git a/Source/OCMockTests/OCObserverMockObjectTests.m b/Source/OCMockTests/OCObserverMockObjectTests.m index d61a5a27..35eab4f7 100644 --- a/Source/OCMockTests/OCObserverMockObjectTests.m +++ b/Source/OCMockTests/OCObserverMockObjectTests.m @@ -34,16 +34,16 @@ @implementation OCObserverMockObjectTest - (void)setUp { center = [[NSNotificationCenter alloc] init]; - mock = [OCMockObject observerMock]; + mock = [OCMockObject observerMock]; } - (void)testAcceptsExpectedNotification { [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]]; - + [center postNotificationName:TestNotificationOne object:self]; - + [mock verify]; } @@ -52,9 +52,9 @@ - (void)testAcceptsExpectedNotificationWithSpecifiedObjectAndUserInfo [center addMockObserver:mock name:TestNotificationOne object:nil]; NSDictionary *info = @{@"key": @"foo"}; [[mock expect] notificationWithName:TestNotificationOne object:self userInfo:info]; - + [center postNotificationName:TestNotificationOne object:self userInfo:info]; - + [mock verify]; } @@ -63,7 +63,7 @@ - (void)testAcceptsNotificationsInAnyOrder [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:self]; [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]]; - + [center postNotificationName:TestNotificationOne object:[NSString string]]; [center postNotificationName:TestNotificationOne object:self]; } @@ -75,7 +75,7 @@ - (void)testAcceptsNotificationsInCorrectOrderWhenOrderMatters [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:self]; [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]]; - + [center postNotificationName:TestNotificationOne object:self]; [center postNotificationName:TestNotificationOne object:[NSString string]]; } @@ -83,11 +83,11 @@ - (void)testAcceptsNotificationsInCorrectOrderWhenOrderMatters - (void)testRaisesExceptionWhenSequenceIsWrongAndOrderMatters { [mock setExpectationOrderMatters:YES]; - + [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:self]; [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]]; - + XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string]], @"Should have complained about sequence."); } @@ -97,7 +97,7 @@ - (void)testRaisesEvenThoughOverlappingExpectationsCouldHaveBeenSatisfied [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]]; [[mock expect] notificationWithName:TestNotificationOne object:self]; - + [center postNotificationName:TestNotificationOne object:self]; XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string]]); } @@ -105,7 +105,7 @@ - (void)testRaisesEvenThoughOverlappingExpectationsCouldHaveBeenSatisfied - (void)testRaisesExceptionWhenUnexpectedNotificationIsReceived { [center addMockObserver:mock name:TestNotificationOne object:nil]; - + XCTAssertThrows([center postNotificationName:TestNotificationOne object:self]); } @@ -113,16 +113,16 @@ - (void)testRaisesWhenNotificationWithWrongObjectIsReceived { [center addMockObserver:mock name:TestNotificationOne object:nil]; [[mock expect] notificationWithName:TestNotificationOne object:self]; - + XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string]]); } - (void)testRaisesWhenNotificationWithWrongUserInfoIsReceived { [center addMockObserver:mock name:TestNotificationOne object:nil]; - [[mock expect] notificationWithName:TestNotificationOne object:self + [[mock expect] notificationWithName:TestNotificationOne object:self userInfo:@{@"key": @"foo"}]; - XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string] + XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string] userInfo:@{@"key": @"bar"}]); } @@ -147,12 +147,12 @@ - (void)testRaisesOnVerifyWhenNotAllNotificationsWereSent - (void)testChecksNotificationNamesCorrectly { NSString *notificationName = @"MyNotification"; - + [center addMockObserver:mock name:notificationName object:nil]; [[mock expect] notificationWithName:[notificationName mutableCopy] object:[OCMArg any]]; - + [center postNotificationName:notificationName object:self]; - + [mock verify]; }