diff options
18 files changed, 503 insertions, 78 deletions
diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/NSNotificationCenter+OCMAdditions.h b/Frameworks/OCMock.framework/Versions/A/Headers/NSNotificationCenter+OCMAdditions.h index ae2e37d0..c20a9c2b 100644 --- a/Frameworks/OCMock.framework/Versions/A/Headers/NSNotificationCenter+OCMAdditions.h +++ b/Frameworks/OCMock.framework/Versions/A/Headers/NSNotificationCenter+OCMAdditions.h @@ -1,15 +1,26 @@ -//--------------------------------------------------------------------------------------- -// $Id: NSNotificationCenter+OCMAdditions.h$ -// Copyright (c) 2009 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- +/* + * Copyright (c) 2009-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ #import <Foundation/Foundation.h> -@class OCMockObserver; +@class OCObserverMockObject; @interface NSNotificationCenter(OCMAdditions) -- (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; +- (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; @end diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMArg.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMArg.h index a775f39f..d53437cb 100644 --- a/Frameworks/OCMock.framework/Versions/A/Headers/OCMArg.h +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMArg.h @@ -1,7 +1,18 @@ -//--------------------------------------------------------------------------------------- -// $Id$ -// Copyright (c) 2009 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- +/* + * Copyright (c) 2009-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ #import <Foundation/Foundation.h> @@ -10,15 +21,21 @@ // constraining arguments + (id)any; ++ (SEL)anySelector; + (void *)anyPointer; ++ (id __autoreleasing *)anyObjectRef; + (id)isNil; + (id)isNotNil; ++ (id)isEqual:(id)value; + (id)isNotEqual:(id)value; ++ (id)isKindOfClass:(Class)cls; + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; ++ (id)checkWithBlock:(BOOL (^)(id obj))block; // manipulating arguments + (id *)setTo:(id)value; ++ (void *)setToValue:(NSValue *)value; // internal use only @@ -27,4 +44,10 @@ @end #define OCMOCK_ANY [OCMArg any] -#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(typeof(variable))] + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) + #define OCMOCK_VALUE(variable) \ + ({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; }) +#else + #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] +#endif diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMConstraint.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMConstraint.h index 0bab7775..777966ab 100644 --- a/Frameworks/OCMock.framework/Versions/A/Headers/OCMConstraint.h +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMConstraint.h @@ -1,21 +1,34 @@ -//--------------------------------------------------------------------------------------- -// $Id$ -// Copyright (c) 2007-2009 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- +/* + * Copyright (c) 2007-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ #import <Foundation/Foundation.h> + @interface OCMConstraint : NSObject -+ (id)constraint; ++ (instancetype)constraint; - (BOOL)evaluate:(id)value; // if you are looking for any, isNil, etc, they have moved to OCMArg -+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; -+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; +// try to use [OCMArg checkWith...] instead of the constraintWith... methods below + ++ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; ++ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; -// try to use [OCMArg checkWith...] instead of constraintWithSelector in here @end @@ -44,5 +57,15 @@ @end +@interface OCMBlockConstraint : OCMConstraint +{ + BOOL (^block)(id); +} + +- (instancetype)initWithConstraintBlock:(BOOL (^)(id))block; + +@end + + #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMLocation.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMLocation.h new file mode 100644 index 00000000..e510db7a --- /dev/null +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMLocation.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#import <Foundation/Foundation.h> + +@interface OCMLocation : NSObject +{ + id testCase; + NSString *file; + NSUInteger line; +} + ++ (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; + +- (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; + +- (id)testCase; +- (NSString *)file; +- (NSUInteger)line; + +@end + +extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line); diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMMacroState.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMMacroState.h new file mode 100644 index 00000000..4b2d6350 --- /dev/null +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMMacroState.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#import <Foundation/Foundation.h> + +@class OCMLocation; +@class OCMRecorder; +@class OCMStubRecorder; +@class OCMockObject; + + +@interface OCMMacroState : NSObject +{ + OCMRecorder *recorder; +} + ++ (void)beginStubMacro; ++ (OCMStubRecorder *)endStubMacro; + ++ (void)beginExpectMacro; ++ (OCMStubRecorder *)endExpectMacro; + ++ (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation; ++ (void)endVerifyMacro; + ++ (OCMMacroState *)globalState; + +- (OCMRecorder *)recorder; + +- (void)switchToClassMethod; + +@end diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMRecorder.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMRecorder.h new file mode 100644 index 00000000..f56d2ca4 --- /dev/null +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMRecorder.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#import <Foundation/Foundation.h> + +@class OCMockObject; +@class OCMInvocationMatcher; + + +@interface OCMRecorder : NSProxy +{ + OCMockObject *mockObject; + OCMInvocationMatcher *invocationMatcher; +} + +- (instancetype)init; +- (instancetype)initWithMockObject:(OCMockObject *)aMockObject; + +- (void)setMockObject:(OCMockObject *)aMockObject; + +- (OCMInvocationMatcher *)invocationMatcher; + +- (id)classMethod; +- (id)ignoringNonObjectArgs; + +@end diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMStubRecorder.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMStubRecorder.h new file mode 100644 index 00000000..890c9ef3 --- /dev/null +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMStubRecorder.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +#import "OCMRecorder.h" + + +@interface OCMStubRecorder : OCMRecorder + +- (id)andReturn:(id)anObject; +- (id)andReturnValue:(NSValue *)aValue; +- (id)andThrow:(NSException *)anException; +- (id)andPost:(NSNotification *)aNotification; +- (id)andCall:(SEL)selector onObject:(id)anObject; +- (id)andDo:(void (^)(NSInvocation *invocation))block; +- (id)andForwardToRealObject; + +@end + + +@interface OCMStubRecorder (Properties) + +#define andReturn(aValue) _andReturn(({ __typeof__(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(__typeof__(_v))]; })) +@property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *); + +#define andThrow(anException) _andThrow(anException) +@property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *); + +#define andPost(aNotification) _andPost(aNotification) +@property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *); + +#define andCall(anObject, aSelector) _andCall(anObject, aSelector) +@property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL); + +#define andDo(aBlock) _andDo(aBlock) +@property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *)); + +#define andForwardToRealObject() _andForwardToRealObject() +@property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void); + +@end + + + diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMock.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMock.h index e18de58a..f0083b35 100644 --- a/Frameworks/OCMock.framework/Versions/A/Headers/OCMock.h +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMock.h @@ -1,10 +1,84 @@ -//--------------------------------------------------------------------------------------- -// $Id$ -// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- +/* + * Copyright (c) 2004-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ #import <OCMock/OCMockObject.h> -#import <OCMock/OCMockRecorder.h> +#import <OCMock/OCMRecorder.h> +#import <OCMock/OCMStubRecorder.h> #import <OCMock/OCMConstraint.h> #import <OCMock/OCMArg.h> +#import <OCMock/OCMLocation.h> +#import <OCMock/OCMMacroState.h> #import <OCMock/NSNotificationCenter+OCMAdditions.h> + + +#define OCMClassMock(cls) [OCMockObject niceMockForClass:cls] + +#define OCMStrictClassMock(cls) [OCMockObject mockForClass:cls] + +#define OCMProtocolMock(protocol) [OCMockObject niceMockForProtocol:protocol] + +#define OCMStrictProtocolMock(protocol) [OCMockObject mockForProtocol:protocol] + +#define OCMPartialMock(obj) [OCMockObject partialMockForObject:obj] + +#define OCMObserverMock() [OCMockObject observerMock] + + +#define OCMStub(invocation) \ +({ \ + _OCMSilenceWarnings( \ + [OCMMacroState beginStubMacro]; \ + invocation; \ + [OCMMacroState endStubMacro]; \ + ); \ +}) + +#define OCMExpect(invocation) \ +({ \ + _OCMSilenceWarnings( \ + [OCMMacroState beginExpectMacro]; \ + invocation; \ + [OCMMacroState endExpectMacro]; \ + ); \ +}) + +#define ClassMethod(invocation) \ + _OCMSilenceWarnings( \ + [[OCMMacroState globalState] switchToClassMethod]; \ + invocation; \ + ); + + +#define OCMVerifyAll(mock) [mock verifyAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)] + +#define OCMVerifyAllWithDelay(mock, delay) [mock verifyWithDelay:delay atLocation:OCMMakeLocation(self, __FILE__, __LINE__)] + +#define OCMVerify(invocation) \ +({ \ + _OCMSilenceWarnings( \ + [OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \ + invocation; \ + [OCMMacroState endVerifyMacro]; \ + ); \ +}) + +#define _OCMSilenceWarnings(macro) \ +({ \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wunused-value\"") \ + macro \ + _Pragma("clang diagnostic pop") \ +}) diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMockObject.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMockObject.h index 87e7b82e..63f2bae2 100644 --- a/Frameworks/OCMock.framework/Versions/A/Headers/OCMockObject.h +++ b/Frameworks/OCMock.framework/Versions/A/Headers/OCMockObject.h @@ -1,17 +1,36 @@ -//--------------------------------------------------------------------------------------- -// $Id$ -// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- +/* + * Copyright (c) 2004-2014 Erik Doernenburg and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use these files except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ #import <Foundation/Foundation.h> +@class OCMLocation; +@class OCMInvocationStub; +@class OCMStubRecorder; +@class OCMInvocationMatcher; +@class OCMInvocationExpectation; + + @interface OCMockObject : NSProxy { BOOL isNice; BOOL expectationOrderMatters; - NSMutableArray *recorders; + NSMutableArray *stubs; NSMutableArray *expectations; NSMutableArray *exceptions; + NSMutableArray *invocations; } + (id)mockForClass:(Class)aClass; @@ -23,19 +42,33 @@ + (id)observerMock; -- (id)init; +- (instancetype)init; - (void)setExpectationOrderMatters:(BOOL)flag; - (id)stub; - (id)expect; +- (id)reject; + +- (id)verify; +- (id)verifyAtLocation:(OCMLocation *)location; + +- (void)verifyWithDelay:(NSTimeInterval)delay; +- (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location; -- (void)verify; +- (void)stopMocking; // internal use only -- (id)getNewRecorder; +- (void)addStub:(OCMInvocationStub *)aStub; +- (void)addExpectation:(OCMInvocationExpectation *)anExpectation; + - (BOOL)handleInvocation:(NSInvocation *)anInvocation; - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; +- (BOOL)handleSelector:(SEL)sel; + +- (void)verifyInvocation:(OCMInvocationMatcher *)matcher; +- (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location; @end + diff --git a/Frameworks/OCMock.framework/Versions/A/Headers/OCMockRecorder.h b/Frameworks/OCMock.framework/Versions/A/Headers/OCMockRecorder.h deleted file mode 100644 index 7463a3f4..00000000 --- a/Frameworks/OCMock.framework/Versions/A/Headers/OCMockRecorder.h +++ /dev/null @@ -1,28 +0,0 @@ -//--------------------------------------------------------------------------------------- -// $Id$ -// Copyright (c) 2004-2009 by Mulle Kybernetik. See License file for details. -//--------------------------------------------------------------------------------------- - -#import <Foundation/Foundation.h> - -@interface OCMockRecorder : NSProxy -{ - id signatureResolver; - NSInvocation *recordedInvocation; - NSMutableArray *invocationHandlers; -} - -- (id)initWithSignatureResolver:(id)anObject; - -- (BOOL)matchesInvocation:(NSInvocation *)anInvocation; -- (void)releaseInvocation; - -- (id)andReturn:(id)anObject; -- (id)andReturnValue:(NSValue *)aValue; -- (id)andThrow:(NSException *)anException; -- (id)andPost:(NSNotification *)aNotification; -- (id)andCall:(SEL)selector onObject:(id)anObject; - -- (NSArray *)invocationHandlers; - -@end diff --git a/Frameworks/OCMock.framework/Versions/A/OCMock b/Frameworks/OCMock.framework/Versions/A/OCMock Binary files differindex 303e9337..3fb5afb5 100755 --- a/Frameworks/OCMock.framework/Versions/A/OCMock +++ b/Frameworks/OCMock.framework/Versions/A/OCMock diff --git a/Frameworks/OCMock.framework/Versions/A/Resources/Info.plist b/Frameworks/OCMock.framework/Versions/A/Resources/Info.plist index 4634d14c..20bc2603 100644 --- a/Frameworks/OCMock.framework/Versions/A/Resources/Info.plist +++ b/Frameworks/OCMock.framework/Versions/A/Resources/Info.plist @@ -2,6 +2,8 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> + <key>BuildMachineOSBuild</key> + <string>13F34</string> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> @@ -15,12 +17,26 @@ <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleShortVersionString</key> - <string>1.29</string> + <string>1.0</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1</string> + <key>DTCompiler</key> + <string>com.apple.compilers.llvm.clang.1_0</string> + <key>DTPlatformBuild</key> + <string>6A2008a</string> + <key>DTPlatformVersion</key> + <string>GM</string> + <key>DTSDKBuild</key> + <string>14A382</string> + <key>DTSDKName</key> + <string>macosx10.10</string> + <key>DTXcode</key> + <string>0611</string> + <key>DTXcodeBuild</key> + <string>6A2008a</string> <key>NSHumanReadableCopyright</key> - <string>Copyright © 2004-2009 Mulle Kybernetik.</string> + <string>Copyright © 2004-2013 Mulle Kybernetik.</string> </dict> </plist> diff --git a/Frameworks/OCMock.framework/Versions/A/Resources/License.txt b/Frameworks/OCMock.framework/Versions/A/Resources/License.txt deleted file mode 100644 index e2c13960..00000000 --- a/Frameworks/OCMock.framework/Versions/A/Resources/License.txt +++ /dev/null @@ -1,15 +0,0 @@ - - Copyright (c) 2004-2009 by Mulle Kybernetik. All rights reserved. - - Permission to use, copy, modify and distribute this software and its documentation - is hereby granted, provided that both the copyright notice and this permission - notice appear in all copies of the software, derivative works or modified versions, - and any portions thereof, and that both notices appear in supporting documentation, - and that credit is given to Mulle Kybernetik in all documents and publicity - pertaining to direct or indirect use of this code or its derivatives. - - THIS IS EXPERIMENTAL SOFTWARE AND IT IS KNOWN TO HAVE BUGS, SOME OF WHICH MAY HAVE - SERIOUS CONSEQUENCES. THE COPYRIGHT HOLDER ALLOWS FREE USE OF THIS SOFTWARE IN ITS - "AS IS" CONDITION. THE COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY - DAMAGES WHATSOEVER RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE - OR OF ANY DERIVATIVE WORK.
\ No newline at end of file diff --git a/Frameworks/OCMock.framework/Versions/A/Resources/en.lproj/InfoPlist.strings b/Frameworks/OCMock.framework/Versions/A/Resources/en.lproj/InfoPlist.strings Binary files differnew file mode 100644 index 00000000..5e45963c --- /dev/null +++ b/Frameworks/OCMock.framework/Versions/A/Resources/en.lproj/InfoPlist.strings diff --git a/Source/SPConstants.h b/Source/SPConstants.h index a2df5bde..728d213a 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -642,3 +642,6 @@ void _SPClear(id *addr); #if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_10 typedef NSUInteger NSCellHitResult; #endif + +// Stolen from Stack Overflow: http://stackoverflow.com/questions/969130 +#define SPLog(fmt, ...) NSLog((@"%s:%d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) diff --git a/Source/SPDatabaseAction.m b/Source/SPDatabaseAction.m index c7f5dbf9..413e2378 100644 --- a/Source/SPDatabaseAction.m +++ b/Source/SPDatabaseAction.m @@ -65,7 +65,10 @@ - (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation { - NSParameterAssert(database != nil && [database length] > 0); + if(![database length]) { + SPLog(@"'database' should not be nil or empty!"); + return NO; + } NSMutableString *query = [NSMutableString stringWithFormat:@"CREATE DATABASE %@", [database backtickQuotedString]]; diff --git a/UnitTests/SPDatabaseActionTest.m b/UnitTests/SPDatabaseActionTest.m new file mode 100644 index 00000000..f7704df5 --- /dev/null +++ b/UnitTests/SPDatabaseActionTest.m @@ -0,0 +1,92 @@ +// +// SPDatabaseActionTest.m +// sequel-pro +// +// Created by Max Lohrmann on 12.03.15. +// Copyright (c) 2015 Max Lohrmann. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at <https://github.com/sequelpro/sequelpro> + +#import <OCMock/OCMock.h> +#import <SenTestingKit/SenTestingKit.h> + + +#import "SPDatabaseAction.h" +#import <SPMySQL/SPMySQL.h> + + +@interface SPDatabaseActionTest : SenTestCase + +- (void)testCreateDatabase_01_emptyName; +- (void)testCreateDatabase_02_allParams; +- (void)testCreateDatabase_03_nameOnly; + +@end + +@implementation SPDatabaseActionTest + +- (void)testCreateDatabase_01_emptyName +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + //OCMStrictClassMock would fail on any call, which is desired here + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + STAssertFalse([createDb createDatabase:@"" withEncoding:nil collation:nil],@"create database = NO with empty db name"); + + OCMVerifyAll(mockConnection); +} + + +- (void)testCreateDatabase_02_allParams +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + + OCMExpect([mockConnection queryString:@"CREATE DATABASE `target_name` DEFAULT CHARACTER SET = `utf8` DEFAULT COLLATE = `utf8_bin_ci`"]); + OCMStub([mockConnection queryErrored]).andReturn(NO); + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + + STAssertTrue([createDb createDatabase:@"target_name" withEncoding:@"utf8" collation:@"utf8_bin_ci"], @"create database return"); + + OCMVerifyAll(mockConnection); +} + +- (void)testCreateDatabase_03_nameOnly +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + + OCMExpect([mockConnection queryString:@"CREATE DATABASE `target_name`"]); + OCMStub([mockConnection queryErrored]).andReturn(NO); + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + + STAssertTrue([createDb createDatabase:@"target_name" withEncoding:@"" collation:nil], @"create database return"); + + OCMVerifyAll(mockConnection); +} + +@end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 8c3d5989..afc3e3f3 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -188,6 +188,12 @@ 50D3C35D1A77217800B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; }; 50E217B318174246009D3580 /* SPColorSelectorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B218174246009D3580 /* SPColorSelectorView.m */; }; 50E217B618174280009D3580 /* SPFavoriteColorSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */; }; + 50EA92641AB23EAD008D3C4F /* SPDatabaseCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1198F5B21174EDD500670590 /* SPDatabaseCopy.m */; }; + 50EA92651AB23EC8008D3C4F /* SPDatabaseAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 11B55BFD1189E3B2009EF465 /* SPDatabaseAction.m */; }; + 50EA92661AB23ED3008D3C4F /* SPMySQL.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 584D876815140D3500F24774 /* SPMySQL.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 50EA92671AB23EE1008D3C4F /* SPMySQL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 584D876815140D3500F24774 /* SPMySQL.framework */; }; + 50EA92681AB23EFC008D3C4F /* SPTableCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1141A388117BBFF200126A28 /* SPTableCopy.m */; }; + 50EA926A1AB246B8008D3C4F /* SPDatabaseActionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EA92691AB246B8008D3C4F /* SPDatabaseActionTest.m */; }; 50EAB5B81A8FBB08008F627A /* SPOSInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */; }; 5806B76411A991EC00813A88 /* SPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5806B76311A991EC00813A88 /* SPDocumentController.m */; }; 580E8DB711EA774B000D8427 /* SequelProTabClose_Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 580E8DAB11EA772C000D8427 /* SequelProTabClose_Pressed.png */; }; @@ -551,6 +557,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 50EA92661AB23ED3008D3C4F /* SPMySQL.framework in Copy Frameworks */, 17E20E0012D660C3007F75A6 /* OCMock.framework in Copy Frameworks */, ); name = "Copy Frameworks"; @@ -900,6 +907,7 @@ 50E217B218174246009D3580 /* SPColorSelectorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPColorSelectorView.m; sourceTree = "<group>"; }; 50E217B418174280009D3580 /* SPFavoriteColorSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoriteColorSupport.h; sourceTree = "<group>"; }; 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoriteColorSupport.m; sourceTree = "<group>"; }; + 50EA92691AB246B8008D3C4F /* SPDatabaseActionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDatabaseActionTest.m; sourceTree = "<group>"; }; 50EAB5B61A8FBB08008F627A /* SPOSInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPOSInfo.h; sourceTree = "<group>"; }; 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPOSInfo.m; sourceTree = "<group>"; }; 5806B76211A991EC00813A88 /* SPDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDocumentController.h; sourceTree = "<group>"; }; @@ -1265,6 +1273,7 @@ files = ( 1717F9DB1558114D0065C036 /* OCMock.framework in Frameworks */, 1717FA43155831600065C036 /* libicucore.dylib in Frameworks */, + 50EA92671AB23EE1008D3C4F /* SPMySQL.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1378,6 +1387,7 @@ 1198F5C31174EF3F00670590 /* SPDatabaseCopyTest.m */, 11C210DD1180E9B800758039 /* SPDatabaseRenameTest.h */, 11C210DE1180E9B800758039 /* SPDatabaseRenameTest.m */, + 50EA92691AB246B8008D3C4F /* SPDatabaseActionTest.m */, ); name = "Database Actions"; sourceTree = "<group>"; @@ -3050,6 +3060,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 50EA92681AB23EFC008D3C4F /* SPTableCopy.m in Sources */, + 50EA926A1AB246B8008D3C4F /* SPDatabaseActionTest.m in Sources */, + 50EA92651AB23EC8008D3C4F /* SPDatabaseAction.m in Sources */, + 50EA92641AB23EAD008D3C4F /* SPDatabaseCopy.m in Sources */, 50D3C35D1A77217800B5429C /* SPParserUtils.c in Sources */, 380F4EF50FC0B68F00B0BFD7 /* SPStringAdditionsTests.m in Sources */, 1760599F1336199D0098E162 /* SPMenuAdditionsTests.m in Sources */, |