diff options
Diffstat (limited to 'SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m')
-rw-r--r-- | SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 162 |
1 files changed, 143 insertions, 19 deletions
diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index 25fad6316..24a06dcb0 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -31,6 +31,55 @@ @property (nonatomic, assign) CGFloat previousPinchDistance; @property (nonatomic, strong, nullable) SDLPinchGesture *currentPinchGesture; @property (nonatomic, strong, nullable) dispatch_source_t singleTapTimer; + +@end + +@interface TestGroup : NSObject + ++ (void)testTouchesWithTimeout:(CGFloat)timeoutTime + numTimesCalled:(NSUInteger)numTimesHandlerCalled expected:(NSUInteger)expectedNumTimesHandlerCalled + singleTap:(BOOL)didCallSingleTap expected:(BOOL)expectedDidCallSingleTap + doubleTap:(BOOL)didCallDoubleTap expected:(BOOL)expectedDidCallDoubleTap + beginPan:(BOOL)didCallBeginPan expected:(BOOL)expectedDidCallBeginPan + movePan:(BOOL)didCallMovePan expected:(BOOL)expectedDidCallMovePan + endPan:(BOOL)didCallEndPan expected:(BOOL)expectedDidCallEndPan + cancelPan:(BOOL)didCallCancelPan expected:(BOOL)expectedDidCallCancelPan + beginPinch:(BOOL)didCallBeginPinch expected:(BOOL)expectedDidCallBeginPinch + movePinch:(BOOL)didCallMovePinch expected:(BOOL)expectedDidCallMovePinch + endPinch:(BOOL)didCallEndPinch expected:(BOOL)expectedDidCallEndPinch + cancelPinch:(BOOL)didCallCancelPinch expected:(BOOL)expectedDidCallCancelPinch; + +@end + +@implementation TestGroup + ++ (void)testTouchesWithTimeout:(CGFloat)timeoutTime + numTimesCalled:(NSUInteger)numTimesHandlerCalled expected:(NSUInteger)expectedNumTimesHandlerCalled + singleTap:(BOOL)didCallSingleTap expected:(BOOL)expectedDidCallSingleTap + doubleTap:(BOOL)didCallDoubleTap expected:(BOOL)expectedDidCallDoubleTap + beginPan:(BOOL)didCallBeginPan expected:(BOOL)expectedDidCallBeginPan + movePan:(BOOL)didCallMovePan expected:(BOOL)expectedDidCallMovePan + endPan:(BOOL)didCallEndPan expected:(BOOL)expectedDidCallEndPan + cancelPan:(BOOL)didCallCancelPan expected:(BOOL)expectedDidCallCancelPan + beginPinch:(BOOL)didCallBeginPinch expected:(BOOL)expectedDidCallBeginPinch + movePinch:(BOOL)didCallMovePinch expected:(BOOL)expectedDidCallMovePinch + endPinch:(BOOL)didCallEndPinch expected:(BOOL)expectedDidCallEndPinch + cancelPinch:(BOOL)didCallCancelPinch expected:(BOOL)expectedDidCallCancelPinch +{ + expect(didCallSingleTap).withTimeout(timeoutTime).toEventually(expectedDidCallSingleTap ? beTrue() : beFalse()); + expect(didCallDoubleTap).withTimeout(timeoutTime).toEventually(expectedDidCallDoubleTap ? beTrue() : beFalse()); + expect(didCallBeginPan).withTimeout(timeoutTime).toEventually(expectedDidCallBeginPan ? beTrue() : beFalse()); + expect(didCallMovePan).withTimeout(timeoutTime).toEventually(expectedDidCallMovePan ? beTrue() : beFalse()); + expect(didCallEndPan).withTimeout(timeoutTime).toEventually(expectedDidCallEndPan ? beTrue() : beFalse()); + expect(didCallCancelPan).withTimeout(timeoutTime).toEventually(expectedDidCallCancelPan ? beTrue() : beFalse()); + expect(didCallBeginPinch).withTimeout(timeoutTime).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout(timeoutTime).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout(timeoutTime).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout(timeoutTime).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); +} + @end QuickSpecBegin(SDLTouchManagerSpec) @@ -255,6 +304,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallSingleTap = YES; expectedNumTimesHandlerCalled = 2; + + expect(didCallSingleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallSingleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -302,6 +355,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallSingleTap = YES; expectedNumTimesHandlerCalled = 3; + + expect(didCallSingleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallSingleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -356,6 +413,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallDoubleTap = YES; expectedNumTimesHandlerCalled = 4; + + expect(didCallDoubleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallDoubleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -376,6 +437,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallDoubleTap = NO; expectedNumTimesHandlerCalled = 4; + + expect(didCallDoubleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallDoubleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); }); @@ -410,6 +475,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallSingleTap = NO; expectedNumTimesHandlerCalled = 2; + + expect(didCallSingleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallSingleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -441,6 +510,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallDoubleTap = NO; expectedNumTimesHandlerCalled = 4; + + expect(didCallDoubleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallDoubleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); it(@"should not issue delegate callbacks when a double tap is canceled before the start of the second tap", ^{ @@ -452,6 +525,10 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallDoubleTap = NO; expectedNumTimesHandlerCalled = 3; + + expect(didCallDoubleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallDoubleTap ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -604,6 +681,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPan = YES; expectedDidCallCancelPan = NO; expectedNumTimesHandlerCalled = 4; + + expect(didCallBeginPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPan ? beTrue() : beFalse()); + expect(didCallMovePan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePan ? beTrue() : beFalse()); + expect(didCallEndPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPan ? beTrue() : beFalse()); + expect(didCallCancelPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPan ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -638,6 +722,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPan = NO; expectedDidCallCancelPan = YES; expectedNumTimesHandlerCalled = 3; + + expect(didCallBeginPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPan ? beTrue() : beFalse()); + expect(didCallMovePan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePan ? beTrue() : beFalse()); + expect(didCallEndPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPan ? beTrue() : beFalse()); + expect(didCallCancelPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPan ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); it(@"should issue a cancel pan delegate callback when a pan is canceled right after second move detected", ^{ @@ -685,6 +776,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPan = NO; expectedDidCallCancelPan = YES; expectedNumTimesHandlerCalled = 4; + + expect(didCallBeginPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPan ? beTrue() : beFalse()); + expect(didCallMovePan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePan ? beTrue() : beFalse()); + expect(didCallEndPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPan ? beTrue() : beFalse()); + expect(didCallCancelPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPan ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); it(@"should not issue a cancel pan delegate callback if the cancel onTouchEvent is received while a pan gesture is not in progress", ^{ @@ -695,6 +793,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPan = NO; expectedDidCallCancelPan = NO; expectedNumTimesHandlerCalled = 1; + + expect(didCallBeginPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPan ? beTrue() : beFalse()); + expect(didCallMovePan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePan ? beTrue() : beFalse()); + expect(didCallEndPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPan ? beTrue() : beFalse()); + expect(didCallCancelPan).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPan ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); afterEach(^{ @@ -815,7 +920,7 @@ describe(@"SDLTouchManager Tests", ^{ [invocation getArgument:&point atIndex:4]; expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, pinchStartCenter))).to(beTruthy()); + expect(@(CGPointEqualToPoint(point, pinchStartCenter))).to(beTrue()); }; pinchMoveTests = ^(NSInvocation* invocation) { @@ -828,7 +933,7 @@ describe(@"SDLTouchManager Tests", ^{ [invocation getArgument:&scale atIndex:4]; expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, pinchMoveCenter))).to(beTruthy()); + expect(@(CGPointEqualToPoint(point, pinchMoveCenter))).to(beTrue()); expect(@(scale)).to(beCloseTo(@(pinchMoveScale)).within(0.0001)); }; @@ -840,7 +945,7 @@ describe(@"SDLTouchManager Tests", ^{ [invocation getArgument:&point atIndex:4]; expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, pinchEndCenter))).to(beTruthy()); + expect(@(CGPointEqualToPoint(point, pinchEndCenter))).to(beTrue()); }; performTouchEvent(touchManager, pinchStartFirstFingerOnTouchEvent); @@ -854,6 +959,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPinch = YES; expectedDidCallCancelPinch = NO; expectedNumTimesHandlerCalled = 4; + + expect(didCallBeginPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -905,6 +1017,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPinch = YES; expectedDidCallCancelPinch = NO; expectedNumTimesHandlerCalled = 4; + + expect(didCallBeginPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); @@ -939,6 +1058,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPinch = NO; expectedDidCallCancelPinch = YES; expectedNumTimesHandlerCalled = 3; + + expect(didCallBeginPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); it(@"should notify delegates if pinch is canceled while it is in progress", ^{ @@ -986,6 +1112,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPinch = NO; expectedDidCallCancelPinch = YES; expectedNumTimesHandlerCalled = 4; + + expect(didCallBeginPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); it(@"should not issue a cancel pinch delegate callback if the cancel onTouchEvent is received while a pinch gesture is not in progress", ^{ @@ -996,6 +1129,13 @@ describe(@"SDLTouchManager Tests", ^{ expectedDidCallEndPinch = NO; expectedDidCallCancelPinch = NO; expectedNumTimesHandlerCalled = 1; + + expect(didCallBeginPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallBeginPinch ? beTrue() : beFalse()); + expect(didCallMovePinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallMovePinch ? beTrue() : beFalse()); + expect(didCallEndPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallEndPinch ? beTrue() : beFalse()); + expect(didCallCancelPinch).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallCancelPinch ? beTrue() : beFalse()); + + expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); afterEach(^{ @@ -1003,22 +1143,6 @@ describe(@"SDLTouchManager Tests", ^{ }); }); }); - - afterEach(^{ - CGFloat timeoutTime = touchManager.tapTimeThreshold + additionalWaitTime; - expect(@(didCallSingleTap)).withTimeout(timeoutTime).toEventually(expectedDidCallSingleTap ? beTruthy() : beFalsy()); - expect(@(didCallDoubleTap)).withTimeout(timeoutTime).toEventually(expectedDidCallDoubleTap ? beTruthy() : beFalsy()); - expect(@(didCallBeginPan)).withTimeout(timeoutTime).toEventually(expectedDidCallBeginPan ? beTruthy() : beFalsy()); - expect(@(didCallMovePan)).withTimeout(timeoutTime).toEventually(expectedDidCallMovePan ? beTruthy() : beFalsy()); - expect(@(didCallEndPan)).withTimeout(timeoutTime).toEventually(expectedDidCallEndPan ? beTruthy() : beFalsy()); - expect(@(didCallCancelPan)).withTimeout(timeoutTime).toEventually(expectedDidCallCancelPan ? beTruthy() : beFalsy()); - expect(@(didCallBeginPinch)).withTimeout(timeoutTime).toEventually(expectedDidCallBeginPinch ? beTruthy() : beFalsy()); - expect(@(didCallMovePinch)).withTimeout(timeoutTime).toEventually(expectedDidCallMovePinch ? beTruthy() : beFalsy()); - expect(@(didCallEndPinch)).withTimeout(timeoutTime).toEventually(expectedDidCallEndPinch ? beTruthy() : beFalsy()); - expect(@(didCallCancelPinch)).withTimeout(timeoutTime).toEventually(expectedDidCallCancelPinch ? beTruthy() : beFalsy()); - - expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); - }); }); }); |