X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-LongPressGestureDetector.cpp;h=2f9773ec273450d4adcf5cebcb0757b4a29ac857;hb=a4eb68faf1e75d213c951a7d4d1b67727247917a;hp=f825c7986ad8433778a225a2c6834036bf30eab1;hpb=3354d0934d49f671df97f5cc033be51d56f5f5ea;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp index f825c79..2f9773e 100644 --- a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp @@ -1,27 +1,30 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * + */ #include #include -#include +#include #include -#include -#include +#include +#include +#include #include +#include using namespace Dali; @@ -58,7 +61,7 @@ struct SignalData receivedGesture.screenPoint = Vector2(0.0f, 0.0f); receivedGesture.localPoint = Vector2(0.0f, 0.0f); - pressedActor = NULL; + pressedActor.Reset(); } bool functorCalled; @@ -72,7 +75,7 @@ struct GestureReceivedFunctor { GestureReceivedFunctor(SignalData& data) : signalData(data) { } - void operator()(Actor actor, LongPressGesture longPress) + void operator()(Actor actor, const LongPressGesture& longPress) { signalData.functorCalled = true; signalData.receivedGesture = longPress; @@ -96,7 +99,7 @@ struct UnstageActorFunctor : public GestureReceivedFunctor { } - void operator()( Actor actor, LongPressGesture longPress ) + void operator()( Actor actor, const LongPressGesture& longPress ) { GestureReceivedFunctor::operator()( actor, longPress ); @@ -125,27 +128,13 @@ struct TouchEventFunctor } }; -// Generate a LongPressGestureEvent to send to Core -Integration::LongPressGestureEvent GenerateLongPress( - Gesture::State state, - unsigned int numberOfTouches, - Vector2 point) -{ - Integration::LongPressGestureEvent longPress( state ); - - longPress.numberOfTouches = numberOfTouches; - longPress.point = point; - - return longPress; -} - } // anon namespace /////////////////////////////////////////////////////////////////////////////// // Positive test case for a method -int UtcDaliLongPressGestureDetectorConstructor(void) +int UtcDaliLongPressGestureDetectorConstructorP(void) { TestApplication application; @@ -154,6 +143,31 @@ int UtcDaliLongPressGestureDetectorConstructor(void) END_TEST; } +int UtcDaliLongPressGestureDetectorCopyConstructorP(void) +{ + TestApplication application; + + LongPressGestureDetector detector = LongPressGestureDetector::New();; + + LongPressGestureDetector copy( detector ); + DALI_TEST_CHECK( detector ); + END_TEST; +} + +int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void) +{ + TestApplication application; + + LongPressGestureDetector detector; + detector = LongPressGestureDetector::New();; + + LongPressGestureDetector copy; + copy = detector; + DALI_TEST_CHECK( detector ); + + DALI_TEST_CHECK( detector == copy ); + END_TEST; +} int UtcDaliLongPressGestureDetectorNew(void) { @@ -196,7 +210,10 @@ int UtcDaliLongPressGestureDetectorNew(void) actor.TouchedSignal().Connect(&application, touchFunctor); Integration::TouchEvent touchEvent(1); - TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f); + Integration::Point point; + point.SetDeviceId( 1 ); + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 20.0f, 20.0f ) ); touchEvent.AddPoint(point); application.ProcessEvent(touchEvent); @@ -237,121 +254,6 @@ int UtcDaliLongPressGestureDetectorDownCast(void) END_TEST; } -int UtcDaliLongPressGestureSetTouchesRequired01(void) -{ - TestApplication application; - - LongPressGestureDetector detector = LongPressGestureDetector::New(); - - unsigned int touches = 3; - - DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired()); - DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired()); - - detector.SetTouchesRequired(touches); - - DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION); - DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION); - - // Attach an actor and change the required touches - - Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); - - // Render and notify - application.SendNotification(); - application.Render(); - - SignalData data; - GestureReceivedFunctor functor(data); - - detector.Attach(actor); - detector.DetectedSignal().Connect(&application, functor); - - TestGestureManager& gestureManager = application.GetGestureManager(); - gestureManager.Initialize(); - - detector.SetTouchesRequired(4); - - // Gesture detection should have been updated only - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - - // Reset values - gestureManager.Initialize(); - - // Create a second gesture detector that requires even less maximum touches - LongPressGestureDetector secondDetector = LongPressGestureDetector::New(); - secondDetector.Attach(actor); - - // Gesture detection should have been updated - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - END_TEST; -} - -int UtcDaliLongPressGestureSetTouchesRequired02(void) -{ - TestApplication application; - - LongPressGestureDetector detector = LongPressGestureDetector::New(); - - unsigned int min = 3; - unsigned int max = 5; - - DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired()); - DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired()); - - detector.SetTouchesRequired(min, max); - - DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION); - DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION); - - // Attach an actor and change the maximum touches - - Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); - - // Render and notify - application.SendNotification(); - application.Render(); - - SignalData data; - GestureReceivedFunctor functor(data); - - detector.Attach(actor); - detector.DetectedSignal().Connect(&application, functor); - - TestGestureManager& gestureManager = application.GetGestureManager(); - gestureManager.Initialize(); - - detector.SetTouchesRequired(4, 5); - - // Gesture detection should have been updated only - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - - // Reset values - gestureManager.Initialize(); - - // Create a second gesture detector that requires even less maximum touches - LongPressGestureDetector secondDetector = LongPressGestureDetector::New(); - secondDetector.Attach(actor); - - // Gesture detection should have been updated - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - END_TEST; -} - int UtcDaliLongPressGestureGetMinimumTouchesRequired(void) { TestApplication application; @@ -391,9 +293,9 @@ int UtcDaliLongPressGestureSignalReceptionNegative(void) detector.DetectedSignal().Connect(&application, functor); // Do a long press outside actor's area - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) ); + TestGenerateLongPress( application, 112.0f, 112.0f ); + TestEndLongPress( application, 112.0f, 112.0f); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -419,12 +321,11 @@ int UtcDaliLongPressGestureSignalReceptionPositive(void) detector.DetectedSignal().Connect(&application, functor); // Do a long press inside actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f))); + TestGenerateLongPress( application, 50.0f, 50.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION); DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f))); + TestEndLongPress( application, 50.0f, 50.0f); END_TEST; } @@ -449,31 +350,28 @@ int UtcDaliLongPressGestureSignalReceptionDetach(void) detector.DetectedSignal().Connect(&application, functor); // Start long press within the actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f))); + TestGenerateLongPress( application, 20.0f, 20.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION); DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f))); + TestEndLongPress( application, 20.0f, 20.0f); // repeat the long press within the actor's area - we should still receive the signal data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f))); + TestGenerateLongPress( application, 50.0f, 50.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION); DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f))); + TestEndLongPress( application, 50.0f, 50.0f); // Detach actor detector.DetachAll(); // Ensure we are no longer signalled data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f))); + TestGenerateLongPress( application, 20.0f, 20.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f))); + TestEndLongPress( application, 50.0f, 50.0f); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -502,8 +400,7 @@ int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void) detector.Attach(actor); // Start long press within the actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f))); + TestGenerateLongPress( application, 20.0f, 20.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); // Remove the actor from stage and reset the data @@ -517,7 +414,7 @@ int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void) // Actor should now have been destroyed data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f))); + TestEndLongPress( application, 20.0f, 20.0f); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -528,7 +425,7 @@ int UtcDaliLongPressGestureSignalReceptionRotatedActor(void) Actor actor = Actor::New(); actor.SetSize(100.0f, 100.0f); - actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS); + actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS); Stage::GetCurrent().Add(actor); // Render and notify @@ -543,37 +440,34 @@ int UtcDaliLongPressGestureSignalReceptionRotatedActor(void) detector.DetectedSignal().Connect(&application, functor); // Do a long press - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f))); + TestGenerateLongPress( application, 5.0f, 5.0f ); + TestEndLongPress( application, 5.0f, 5.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION); DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION); // Rotate actor again and render - actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS); + actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS); application.SendNotification(); application.Render(); // Do another long press, should still receive event data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f))); + TestGenerateLongPress( application, 5.0f, 5.0f ); + TestEndLongPress( application, 5.0f, 5.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION); DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION); // Rotate actor again and render - actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS); + actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS); application.SendNotification(); application.Render(); // Do a long press, inside where the actor used to be, Should not receive the event data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f))); + TestGenerateLongPress( application, 70.0f, 70.0f ); + TestEndLongPress( application, 70.0f, 70.0f); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -594,7 +488,7 @@ int UtcDaliLongPressGestureSignalReceptionChildHit(void) child.SetSize(100.0f, 100.0f); child.SetAnchorPoint(AnchorPoint::CENTER); child.SetParentOrigin(ParentOrigin::CENTER); - child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS); + child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS); parent.Add(child); TouchEventFunctor touchFunctor; @@ -612,9 +506,8 @@ int UtcDaliLongPressGestureSignalReceptionChildHit(void) detector.DetectedSignal().Connect(&application, functor); // Do long press - hits child area but parent should still receive it - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f))); + TestGenerateLongPress( application, 50.0f, 50.0f ); + TestEndLongPress( application, 50.0f, 50.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION); DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION); @@ -626,9 +519,8 @@ int UtcDaliLongPressGestureSignalReceptionChildHit(void) // Do an entire long press, only check finished value data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f))); + TestGenerateLongPress( application, 51.0f, 51.0f ); + TestEndLongPress( application, 51.0f, 51.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION); DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION); @@ -663,17 +555,15 @@ int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void) detector.DetectedSignal().Connect(&application, functor); // LongPress within second actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f))); + TestGenerateLongPress( application, 120.0f, 10.0f ); + TestEndLongPress( application, 120.0f, 10.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION); // LongPress within first actor's area data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f))); + TestGenerateLongPress( application, 20.0f, 10.0f ); + TestEndLongPress( application, 20.0f, 10.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION); @@ -682,16 +572,14 @@ int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void) // second actor shouldn't receive event data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f))); + TestGenerateLongPress( application, 120.0f, 10.0f ); + TestEndLongPress( application, 120.0f, 10.0f); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // first actor should continue receiving event data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f))); + TestGenerateLongPress( application, 20.0f, 10.0f ); + TestEndLongPress( application, 20.0f, 10.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -717,9 +605,8 @@ int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void) detector.DetectedSignal().Connect(&application, functor); // LongPress in actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); + TestEndLongPress( application, 50.0f, 10.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); // Actor becomes invisible - actor should not receive the next long press @@ -731,94 +618,12 @@ int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void) // LongPress in the same area, shouldn't receive event data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); + TestEndLongPress( application, 50.0f, 10.0f); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } -int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void) -{ - TestApplication application; - Dali::TestGestureManager& gestureManager = application.GetGestureManager(); - - Actor first = Actor::New(); - first.SetSize(100.0f, 100.0f); - first.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(first); - - Actor second = Actor::New(); - second.SetSize(100.0f, 100.0f); - second.SetAnchorPoint(AnchorPoint::TOP_LEFT); - second.SetX(100.0f); - first.Add(second); - - // Render and notify - application.SendNotification(); - application.Render(); - - SignalData data; - GestureReceivedFunctor functor(data); - - LongPressGestureDetector firstDetector = LongPressGestureDetector::New(); - firstDetector.Attach(first); - firstDetector.DetectedSignal().Connect(&application, functor); - - // secondDetector is scoped - { - // Reset gestureManager statistics - gestureManager.Initialize(); - - LongPressGestureDetector secondDetector = LongPressGestureDetector::New(); - secondDetector.SetTouchesRequired(2); - secondDetector.Attach(second); - secondDetector.DetectedSignal().Connect(&application, functor); - - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - - // LongPress within second actor's area - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f))); - DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); - DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION); - - // LongPress continues as single touch gesture - we should not receive any gesture - data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - - // Single touch long press starts - first actor should receive gesture - data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); - DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION); - - // long press changes to double-touch - we shouldn't receive event - data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - - // Reset gesture manager statistics - gestureManager.Initialize(); - } - - // secondDetector has now been deleted. Gesture detection should have been updated only - DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION); - DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION); - END_TEST; -} - int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void) { TestApplication application; @@ -847,8 +652,7 @@ int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void) secondDetector.DetectedSignal().Connect(&application, secondFunctor); // LongPress in actor's area - both detector's functors should be called - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION); DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION); END_TEST; @@ -875,7 +679,7 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) detector.DetectedSignal().Connect( &application, functor ); // LongPress possible in actor's area. - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); + TestStartLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Move actor somewhere else @@ -886,12 +690,12 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) application.Render(); // Emit Started event, we should not receive the long press. - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestTriggerLongPress( application ); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // LongPress possible in empty area. - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); + TestStartLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Move actor in to the long press position. @@ -902,137 +706,17 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) application.Render(); // Emit Started event, we should not receive the long press. - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestTriggerLongPress( application ); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Normal long press in actor's area for completeness. - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); + TestEndLongPress( application, 50.0f, 10.0f); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); END_TEST; } -int UtcDaliLongPressGestureEmitIncorrecteStateClear(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); - - // Render and notify - application.SendNotification(); - application.Render(); - - // Attach actor to detector - SignalData data; - GestureReceivedFunctor functor( data ); - LongPressGestureDetector detector = LongPressGestureDetector::New(); - detector.Attach(actor); - detector.DetectedSignal().Connect( &application, functor ); - - // Try a Clear state - try - { - application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f))); - tet_result(TET_FAIL); - } - catch ( Dali::DaliException& e ) - { - DALI_TEST_ASSERT( e, "false", TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); - - // Render and notify - application.SendNotification(); - application.Render(); - - // Attach actor to detector - SignalData data; - GestureReceivedFunctor functor( data ); - LongPressGestureDetector detector = LongPressGestureDetector::New(); - detector.Attach(actor); - detector.DetectedSignal().Connect( &application, functor ); - - // Try a Continuing state - try - { - application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f))); - tet_result(TET_FAIL); - } - catch ( Dali::DaliException& e ) - { - DALI_TEST_ASSERT( e, "false", TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliLongPressGestureRepeatedState(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); - - // Render and notify - application.SendNotification(); - application.Render(); - - // Attach actor to detector - SignalData data; - GestureReceivedFunctor functor( data ); - LongPressGestureDetector detector = LongPressGestureDetector::New(); - detector.Attach(actor); - detector.DetectedSignal().Connect( &application, functor ); - - // Two possibles - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - - // ... Send some finished states, still no signal - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - - // Send two Started states, should be signalled - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); - data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); - data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); - data.Reset(); - - // Send two cancelled states, should not be signalled - application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f))); - DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - END_TEST; -} - int UtcDaliLongPressGesturePossibleCancelled(void) { TestApplication application; @@ -1054,9 +738,9 @@ int UtcDaliLongPressGesturePossibleCancelled(void) detector.DetectedSignal().Connect( &application, functor ); // Send a possible followed by a cancel, we should not be signalled - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); + TestStartLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); - application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f))); + TestMovePan( application, Vector2( 50.0f, 10.0f ) ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -1082,8 +766,7 @@ int UtcDaliLongPressGestureDetachAfterStarted(void) detector.DetectedSignal().Connect( &application, functor ); // Emit initial signal - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); @@ -1091,7 +774,7 @@ int UtcDaliLongPressGestureDetachAfterStarted(void) detector.Detach(actor); // Emit Finished, no signal - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } @@ -1120,11 +803,10 @@ int UtcDaliLongPressGestureActorUnstaged(void) detector.DetectedSignal().Connect( &application, functor ); // Emit signals - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Render and notify @@ -1142,11 +824,10 @@ int UtcDaliLongPressGestureActorUnstaged(void) stateToUnstage = Gesture::Finished; // Emit signals - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully. END_TEST; @@ -1188,8 +869,7 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) // position, we should still not be signalled. // Emit signals - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); @@ -1205,15 +885,14 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) application.Render(); // Continue signal emission - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); data.Reset(); // Here we delete an actor in started, we should not receive any subsequent signalling. // Emit signals - application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f))); - application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f))); + TestGenerateLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); @@ -1222,45 +901,96 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) application.Render(); // Delete actor as well - actor = NULL; + actor.Reset(); // Render and notify application.SendNotification(); application.Render(); // Continue signal emission - application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f))); + TestEndLongPress( application, 50.0f, 10.0f ); DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); END_TEST; } -int UtcDaliLongPressGestureSystemOverlay(void) +int UtcDaliLongPressGestureLayerConsumesTouch(void) { TestApplication application; - Dali::Integration::Core& core = application.GetCore(); - Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() ); - systemOverlay.GetOverlayRenderTasks().CreateTask(); Actor actor = Actor::New(); actor.SetSize(100.0f, 100.0f); actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - systemOverlay.Add(actor); + Stage::GetCurrent().Add(actor); + + // Add a detector + SignalData data; + GestureReceivedFunctor functor(data); + LongPressGestureDetector detector = LongPressGestureDetector::New(); + detector.Attach(actor); + detector.DetectedSignal().Connect( &application, functor ); + + // Add a layer to overlap the actor + Layer layer = Layer::New(); + layer.SetSize(100.0f, 100.0f); + layer.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add( layer ); + layer.RaiseToTop(); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit signals, should receive + TestGenerateLongPress( application, 50.0f, 50.0f ); + TestEndLongPress( application, 50.0f, 50.0f ); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Set layer to consume all touch + layer.SetTouchConsumed( true ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit the same signals again, should not receive + TestGenerateLongPress( application, 50.0f, 50.0f ); + TestEndLongPress( application, 50.0f, 50.0f ); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + data.Reset(); + + END_TEST; +} + +int UtcDaliLongPressGestureSetMinimumHoldingTime(void) +{ + TestApplication application; + + const uint32_t kMinumumHolding1 = 5000; + const uint32_t kMinumumHolding2 = 3000; + + Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 ); + + Actor actor = Actor::New(); + actor.SetSize( 100.0f, 100.0f ); + actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage::GetCurrent().Add( actor ); // Render and notify application.SendNotification(); application.Render(); SignalData data; - GestureReceivedFunctor functor(data); + GestureReceivedFunctor functor( data ); LongPressGestureDetector detector = LongPressGestureDetector::New(); detector.Attach(actor); detector.DetectedSignal().Connect(&application, functor); - // Do a long press inside actor's area - Vector2 screenCoords( 50.0f, 50.0f ); - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) ); - DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION ); + + Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 ); + DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION ); + END_TEST; }