diff options
author | Muller, Alexander (A.) <amulle19@ford.com> | 2016-06-28 14:50:50 -0700 |
---|---|---|
committer | Muller, Alexander (A.) <amulle19@ford.com> | 2016-06-28 14:50:50 -0700 |
commit | b11680bcd591572baec21d9638bb799ce93fa5c6 (patch) | |
tree | c158bf43f16c80c17af71d395e4e55bf150c00b6 | |
parent | 565d10fdda67169d9f3117e86fab98c3e3de0b0b (diff) | |
download | sdl_ios-b11680bcd591572baec21d9638bb799ce93fa5c6.tar.gz |
Added tests for all touch events.
-rw-r--r-- | SmartDeviceLinkTests/SDLTouchManagerSpec.m | 514 |
1 files changed, 510 insertions, 4 deletions
diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index 4052e6e58..0bf22f41e 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -10,8 +10,13 @@ #import <Quick/Quick.h> #import <Nimble/Nimble.h> +#import <OCMock/OCMock.h> +#import "SDLOnTouchEvent.h" +#import "SDLTouchCoord.h" +#import "SDLTouchEvent.h" #import "SDLTouchManager.h" +#import "SDLTouchType.h" #import "CGPoint_Util.h" #import "SDLTouch.h" #import "SDLPinchGesture.h" @@ -19,6 +24,8 @@ QuickSpecBegin(SDLTouchManagerSpec) +typedef void (^DelegateCallbackBlock)(NSInvocation* invocation); + describe(@"CGPoint_Util Tests", ^{ __block CGPoint first; __block CGPoint second; @@ -227,7 +234,7 @@ describe(@"SDLPinchGesture Tests", ^{ expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); - expect(@(pinchGesture.distance)).to(beCloseTo(@(141.4213)).within(0.0001)); + expect(@(pinchGesture.distance)).to(beCloseTo(@141.4213).within(0.0001)); expect(@(pinchGesture.center.x)).to(equal(@150)); expect(@(pinchGesture.center.y)).to(equal(@250)); }); @@ -284,7 +291,7 @@ describe(@"SDLPinchGesture Tests", ^{ expect(@(pinchGesture.secondTouch.location.y)).to(equal(@250)); expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(newTimeStamp))); - expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); + expect(@(pinchGesture.distance)).to(beCloseTo(@70.7107).within(0.0001)); expect(@(pinchGesture.center.x)).to(equal(@125)); expect(@(pinchGesture.center.y)).to(equal(@225)); }); @@ -298,7 +305,7 @@ describe(@"dispatch_timer Tests", ^{ __block double currentTime = [[NSDate date] timeIntervalSince1970]; dispatch_create_timer(2.5, false, ^{ double difference = [[NSDate date] timeIntervalSince1970] - currentTime; - expect(@(difference)).to(beCloseTo(@(2.5)).within(0.1)); + expect(@(difference)).to(beCloseTo(@2.5).within(0.1)); done(); }); }); @@ -314,9 +321,508 @@ describe(@"dispatch_timer Tests", ^{ dispatch_stop_timer(timer); done(); }); - expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@(0))); + expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@0)); }); }); }); +describe(@"SDLTouchManager Tests", ^{ + + __block SDLTouchManager* touchManager; + __block id delegateMock; + __block NSUInteger timeStamp; + __block CGPoint controlPoint; + __block SDLTouchCoord* touchCoord; + __block SDLTouchEvent* touchEvent; + __block SDLOnTouchEvent* beginOnTouchEvent; + __block SDLOnTouchEvent* moveOnTouchEvent; + __block SDLOnTouchEvent* endOnTouchEvent; + __block BOOL didCallSingleTap; + __block BOOL didCallDoubleTap; + __block BOOL didCallBeginPan; + __block BOOL didCallMovePan; + __block BOOL didCallEndPan; + __block BOOL didCallBeginPinch; + __block BOOL didCallMovePinch; + __block BOOL didCallEndPinch; + + __block DelegateCallbackBlock singleTapTests; + __block DelegateCallbackBlock doubleTapTests; + __block DelegateCallbackBlock panStartTests; + __block DelegateCallbackBlock panMoveTests; + __block DelegateCallbackBlock panEndTests; + __block DelegateCallbackBlock pinchStartTests; + __block DelegateCallbackBlock pinchMoveTests; + __block DelegateCallbackBlock pinchEndTests; + + __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) { + SEL onOnTouchEvent = @selector(onOnTouchEvent:); + ((void (*)(id, SEL, id))[touchManager methodForSelector:onOnTouchEvent])(touchManager, onOnTouchEvent, onTouchEvent); + }; + + context(@"Initializing", ^{ + it(@"should correctly have default properties", ^{ + SDLTouchManager* touchManager = [[SDLTouchManager alloc] init]; + expect(touchManager.touchEventListener).to(beNil()); + expect(@(touchManager.tapDistanceThreshold)).to(equal(@50)); + expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001)); + expect(@(touchManager.panTimeThreshold)).to(equal(@50)); + expect(@(touchManager.isTouchEnabled)).to(beTruthy()); + }); + + }); + describe(@"touch events", ^{ + beforeEach(^{ + touchManager = [[SDLTouchManager alloc] init]; + delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerListener)); + touchManager.touchEventListener = delegateMock; + timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + controlPoint = CGPointMake(100, 200); + + touchCoord = [[SDLTouchCoord alloc] init]; + touchCoord.x = @(controlPoint.x); + touchCoord.y = @(controlPoint.y); + + touchEvent = [[SDLTouchEvent alloc] init]; + touchEvent.touchEventId = @0; + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + beginOnTouchEvent.type = SDLTouchType.BEGIN; + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + + moveOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + moveOnTouchEvent.type = SDLTouchType.MOVE; + + endOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + endOnTouchEvent.type = SDLTouchType.END; + + didCallSingleTap = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallSingleTap = YES; + + singleTapTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceiveSingleTapAtPoint:CGPointZero]; + + singleTapTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallDoubleTap = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallDoubleTap = YES; + + doubleTapTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceiveDoubleTapAtPoint:CGPointZero]; + + doubleTapTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallBeginPan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallBeginPan = YES; + + panStartTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] panningDidStartAtPoint:CGPointZero]; + + panStartTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallMovePan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallMovePan = YES; + + panMoveTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceivePanningFromPoint:CGPointZero toPoint:CGPointZero]; + + panMoveTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallEndPan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallEndPan = YES; + + panEndTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] panningDidEndAtPoint:CGPointZero]; + + panEndTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallBeginPinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallBeginPinch = YES; + + pinchStartTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] pinchDidStartAtCenterPoint:CGPointZero]; + + pinchStartTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallMovePinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallMovePinch = YES; + + pinchMoveTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceivePinchAtCenterPoint:CGPointZero withScale:0]; + + pinchMoveTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallEndPinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallEndPinch = YES; + + pinchEndTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] pinchDidEndAtCenterPoint:CGPointZero]; + + pinchEndTests = ^(NSInvocation* invocation) { + fail(); + }; + }); + + context(@"when receiving a single tap", ^{ + it(@"should correctly handle a single tap", ^{ + singleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); + }; + + // Begin Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + + context(@"when receiving a double tap", ^{ + it(@"should correctly handle a double tap near same point", ^{ + __block CGPoint averagePoint; + + doubleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, averagePoint))).to(beTruthy()); + }; + + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End First Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + // Start Second Touch + touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold); + touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold); + + averagePoint = CGPointAverageOfPoints(controlPoint, + CGPointMake(touchCoord.x.floatValue, + touchCoord.y.floatValue)); + + timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; + + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Second Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + + it(@"should correctly not handle a double tap", ^{ + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End First Touch + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + // Start Second Touch + timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; + + touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold + 1); + touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold + 1); + + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Second Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + context(@"when receiving a pan", ^{ + __block CGPoint panStartPoint; + __block CGPoint panMovePoint; + __block CGPoint panEndPoint; + + it(@"should correctly give all pan callbacks", ^{ + __block CGFloat distanceMoveX = 10; + __block CGFloat distanceMoveY = 20; + + panStartTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, panStartPoint))).to(beTruthy()); + }; + + panMoveTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint startPoint; + CGPoint endPoint; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&startPoint atIndex:3]; + [invocation getArgument:&endPoint atIndex:4]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(startPoint, panStartPoint))).to(beTruthy()); + expect(@(CGPointEqualToPoint(endPoint, panMovePoint))).to(beTruthy()); + }; + + panEndTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, panEndPoint))).to(beTruthy()); + }; + + // Begin Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // Move Touch + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panStartPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // Move Touch 2 + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panMovePoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // End Touch + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panEndPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + context(@"when receiving a pinch", ^{ + it(@"should correctly give all pinch callbacks", ^{ + __block CGPoint pinchStartCenter; + __block CGPoint pinchMoveCenter; + __block CGFloat pinchMoveScale; + __block CGPoint pinchEndCenter; + + pinchStartTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchStartCenter))).to(beTruthy()); + }; + + pinchMoveTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + CGFloat scale; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + [invocation getArgument:&scale atIndex:4]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchMoveCenter))).to(beTruthy()); + expect(@(scale)).to(beCloseTo(@(pinchMoveScale)).within(0.0001)); + }; + + pinchEndTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchEndCenter))).to(beTruthy()); + }; + + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // Begin Second Touch + SDLTouchCoord* secondTouchCoord = [[SDLTouchCoord alloc] init]; + secondTouchCoord.x = @(controlPoint.x + 100); + secondTouchCoord.y = @(controlPoint.y + 100); + + CGPoint firstPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + CGPoint secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchStartCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + CGFloat pinchStartDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); + + touchEvent.touchEventId = @1; + touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + + // Move Second Finger + secondTouchCoord.x = @(secondTouchCoord.x.floatValue - 30); + secondTouchCoord.y = @(secondTouchCoord.y.floatValue - 40); + + secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchMoveCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + CGFloat pinchMoveDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); + pinchMoveScale = pinchMoveDistance / pinchStartDistance; + + timeStamp += touchManager.panTimeThreshold * 1000; + + touchEvent.touchEventId = @1; + touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // End First Finger + timeStamp += touchManager.panTimeThreshold * 1000; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchEndCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + }); + }); + }); +}); + QuickSpecEnd |