mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[ReactNative] Move unit tests to UIExplorer
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 OCObserverMockObject;
|
||||
|
||||
|
||||
@interface NSNotificationCenter(OCMAdditions)
|
||||
|
||||
- (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender;
|
||||
|
||||
@end
|
||||
53
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMArg.h
Normal file
53
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMArg.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
@interface OCMArg : NSObject
|
||||
|
||||
// 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
|
||||
|
||||
+ (id)resolveSpecialValues:(NSValue *)value;
|
||||
|
||||
@end
|
||||
|
||||
#define OCMOCK_ANY [OCMArg any]
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
+ (instancetype)constraint;
|
||||
- (BOOL)evaluate:(id)value;
|
||||
|
||||
// if you are looking for any, isNil, etc, they have moved to OCMArg
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@interface OCMAnyConstraint : OCMConstraint
|
||||
@end
|
||||
|
||||
@interface OCMIsNilConstraint : OCMConstraint
|
||||
@end
|
||||
|
||||
@interface OCMIsNotNilConstraint : OCMConstraint
|
||||
@end
|
||||
|
||||
@interface OCMIsNotEqualConstraint : OCMConstraint
|
||||
{
|
||||
@public
|
||||
id testValue;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface OCMInvocationConstraint : OCMConstraint
|
||||
{
|
||||
@public
|
||||
NSInvocation *invocation;
|
||||
}
|
||||
|
||||
@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)]
|
||||
36
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMLocation.h
Normal file
36
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMLocation.h
Normal file
@@ -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);
|
||||
@@ -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
|
||||
39
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMRecorder.h
Normal file
39
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMRecorder.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
84
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMock.h
Normal file
84
Examples/UIExplorer/UIExplorerUnitTests/OCMock/OCMock.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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/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") \
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 *stubs;
|
||||
NSMutableArray *expectations;
|
||||
NSMutableArray *exceptions;
|
||||
NSMutableArray *invocations;
|
||||
}
|
||||
|
||||
+ (id)mockForClass:(Class)aClass;
|
||||
+ (id)mockForProtocol:(Protocol *)aProtocol;
|
||||
+ (id)partialMockForObject:(NSObject *)anObject;
|
||||
|
||||
+ (id)niceMockForClass:(Class)aClass;
|
||||
+ (id)niceMockForProtocol:(Protocol *)aProtocol;
|
||||
|
||||
+ (id)observerMock;
|
||||
|
||||
- (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)stopMocking;
|
||||
|
||||
// internal use only
|
||||
|
||||
- (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
|
||||
|
||||
Reference in New Issue
Block a user