X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-LongPressGestureDetector.cpp;h=a95c166385fdef255de6ded167424483dd3d1ad3;hb=0e446efe2d2c2a430d3d413b9c473be53508a2b3;hp=2f9773ec273450d4adcf5cebcb0757b4a29ac857;hpb=d17c2b9faad776ca79495faa954ec4139b61f3eb;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 2f9773e..a95c166 100644 --- a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -24,7 +24,7 @@ #include #include #include -#include +#include using namespace Dali; @@ -93,9 +93,10 @@ struct GestureReceivedFunctor // Functor that removes the gestured actor from stage struct UnstageActorFunctor : public GestureReceivedFunctor { - UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage ) + UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene ) : GestureReceivedFunctor( data ), - stateToUnstage( stateToUnstage ) + stateToUnstage( stateToUnstage ), + scene( scene ) { } @@ -105,24 +106,24 @@ struct UnstageActorFunctor : public GestureReceivedFunctor if ( longPress.state == stateToUnstage ) { - Stage::GetCurrent().Remove( actor ); + scene.Remove( actor ); } } Gesture::State& stateToUnstage; + Integration::Scene scene; }; // Functor for receiving a touch event -struct TouchEventFunctor +struct TouchDataFunctor { - bool operator()(Actor actor, const TouchEvent& touch) + bool operator()(Actor actor, Dali::TouchData touch) { //For line coverage unsigned int points = touch.GetPointCount(); if( points > 0) { - const TouchPoint& touchPoint = touch.GetPoint(0); - tet_printf("Touch Point state = %d\n", touchPoint.state); + tet_printf("Touch Point state = %d\n", touch.GetState(0)); } return false; } @@ -196,9 +197,9 @@ int UtcDaliLongPressGestureDetectorNew(void) // Attach an actor and emit a touch event on the actor to ensure complete line coverage Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -206,8 +207,8 @@ int UtcDaliLongPressGestureDetectorNew(void) detector.Attach(actor); - TouchEventFunctor touchFunctor; - actor.TouchedSignal().Connect(&application, touchFunctor); + TouchDataFunctor touchFunctor; + actor.TouchSignal().Connect(&application, touchFunctor); Integration::TouchEvent touchEvent(1); Integration::Point point; @@ -221,8 +222,6 @@ int UtcDaliLongPressGestureDetectorNew(void) application.SendNotification(); application.Render(); - // For line coverage, Initialise default constructor - TouchEvent touchEvent2; END_TEST; } @@ -277,9 +276,9 @@ int UtcDaliLongPressGestureSignalReceptionNegative(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -305,9 +304,9 @@ int UtcDaliLongPressGestureSignalReceptionPositive(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -334,9 +333,9 @@ int UtcDaliLongPressGestureSignalReceptionDetach(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -389,9 +388,9 @@ int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void) // Actor lifetime is scoped { Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -404,7 +403,7 @@ int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void) DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); // Remove the actor from stage and reset the data - Stage::GetCurrent().Remove(actor); + application.GetScene().Remove(actor); // Render and notify application.SendNotification(); @@ -424,9 +423,9 @@ int UtcDaliLongPressGestureSignalReceptionRotatedActor(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) ); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -447,7 +446,7 @@ int UtcDaliLongPressGestureSignalReceptionRotatedActor(void) DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION); // Rotate actor again and render - actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS); + actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) ); application.SendNotification(); application.Render(); @@ -460,7 +459,7 @@ int UtcDaliLongPressGestureSignalReceptionRotatedActor(void) DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION); // Rotate actor again and render - actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS); + actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) ); application.SendNotification(); application.Render(); @@ -477,23 +476,20 @@ int UtcDaliLongPressGestureSignalReceptionChildHit(void) TestApplication application; Actor parent = Actor::New(); - parent.SetSize(100.0f, 100.0f); - parent.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(parent); + parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(parent); // Set child to completely cover parent. // Change rotation of child to be different from parent so that we can check if our local coordinate // conversion of the parent actor is correct. Actor child = Actor::New(); - child.SetSize(100.0f, 100.0f); - child.SetAnchorPoint(AnchorPoint::CENTER); - child.SetParentOrigin(ParentOrigin::CENTER); - child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS); + child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) ); parent.Add(child); - TouchEventFunctor touchFunctor; - child.TouchedSignal().Connect(&application, touchFunctor); - // Render and notify application.SendNotification(); application.Render(); @@ -532,15 +528,15 @@ int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void) TestApplication application; Actor first = Actor::New(); - first.SetSize(100.0f, 100.0f); - first.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(first); + first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(first); Actor second = Actor::New(); - second.SetSize(100.0f, 100.0f); - second.SetX(100.0f); - second.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(second); + second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + second.SetProperty( Actor::Property::POSITION_X, 100.0f); + second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(second); // Render and notify application.SendNotification(); @@ -589,9 +585,9 @@ int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -610,7 +606,7 @@ int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void) DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); // Actor becomes invisible - actor should not receive the next long press - actor.SetVisible(false); + actor.SetProperty( Actor::Property::VISIBLE,false); // Render and notify application.SendNotification(); @@ -629,9 +625,9 @@ int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -663,9 +659,9 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -683,7 +679,7 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Move actor somewhere else - actor.SetPosition( 100.0f, 100.0f ); + actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f )); // Render and notify application.SendNotification(); @@ -699,7 +695,7 @@ int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void) DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); // Move actor in to the long press position. - actor.SetPosition( 0.0f, 0.0f ); + actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f )); // Render and notify application.SendNotification(); @@ -722,9 +718,9 @@ int UtcDaliLongPressGesturePossibleCancelled(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -750,9 +746,9 @@ int UtcDaliLongPressGestureDetachAfterStarted(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -784,9 +780,9 @@ int UtcDaliLongPressGestureActorUnstaged(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -797,7 +793,7 @@ int UtcDaliLongPressGestureActorUnstaged(void) // Attach actor to detector SignalData data; - UnstageActorFunctor functor( data, stateToUnstage ); + UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() ); LongPressGestureDetector detector = LongPressGestureDetector::New(); detector.Attach(actor); detector.DetectedSignal().Connect( &application, functor ); @@ -814,7 +810,7 @@ int UtcDaliLongPressGestureActorUnstaged(void) application.Render(); // Re-add actor to stage - Stage::GetCurrent().Add(actor); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -838,16 +834,16 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Create and add a second actor so that GestureDetector destruction does not come into play. Actor dummyActor( Actor::New() ); - dummyActor.SetSize( 100.0f, 100.0f ); - dummyActor.SetPosition( 100.0f, 100.0f ); - dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(dummyActor); + dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f )); + dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(dummyActor); // Render and notify application.SendNotification(); @@ -858,7 +854,7 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) // Attach actor to detector SignalData data; - UnstageActorFunctor functor( data, stateToUnstage ); + UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() ); LongPressGestureDetector detector = LongPressGestureDetector::New(); detector.Attach(actor); detector.Attach(dummyActor); @@ -878,7 +874,7 @@ int UtcDaliLongPressGestureActorStagedAndDestroyed(void) application.Render(); // Re add to the stage, we should not be signalled - Stage::GetCurrent().Add(actor); + application.GetScene().Add(actor); // Render and notify application.SendNotification(); @@ -918,9 +914,9 @@ int UtcDaliLongPressGestureLayerConsumesTouch(void) TestApplication application; Actor actor = Actor::New(); - actor.SetSize(100.0f, 100.0f); - actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); - Stage::GetCurrent().Add(actor); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); // Add a detector SignalData data; @@ -931,9 +927,9 @@ int UtcDaliLongPressGestureLayerConsumesTouch(void) // 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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add( layer ); layer.RaiseToTop(); // Render and notify @@ -947,7 +943,7 @@ int UtcDaliLongPressGestureLayerConsumesTouch(void) data.Reset(); // Set layer to consume all touch - layer.SetTouchConsumed( true ); + layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true ); // Render and notify application.SendNotification(); @@ -972,9 +968,9 @@ int UtcDaliLongPressGestureSetMinimumHoldingTime(void) Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 ); Actor actor = Actor::New(); - actor.SetSize( 100.0f, 100.0f ); - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( actor ); // Render and notify application.SendNotification(); @@ -994,3 +990,95 @@ int UtcDaliLongPressGestureSetMinimumHoldingTime(void) END_TEST; } + +int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + bool consume = false; + TouchDataFunctorConsumeSetter touchFunctor(consume); + actor.TouchSignal().Connect(&application,touchFunctor); + + // Render and notify + application.SendNotification(); + application.Render(); + + SignalData data; + GestureReceivedFunctor functor(data); + + LongPressGestureDetector detector = LongPressGestureDetector::New(); + detector.Attach(actor); + detector.DetectedSignal().Connect(&application, functor); + + // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed + TestGenerateLongPress( application, 50.0f, 50.0f ); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + TestEndLongPress(application, 50.0f,50.0f); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Another gesture in the same location, this time we will not receive it as touch is being consumed + consume = true; + TestGenerateLongPress( application, 50.0f, 50.0f ); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + data.Reset(); + TestEndLongPress(application, 50.0f,50.0f); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void) +{ + // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached + + TestApplication application; + + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); + actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + // Add a detector + LongPressGestureDetector detector = LongPressGestureDetector::New(); + bool functorCalled = false; + detector.Attach( actor ); + detector.DetectedSignal().Connect( + &application, + [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture) + { + if( gesture.state == Gesture::Finished ) + { + detector.Detach(actor); + functorCalled = true; + } + }); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Try the gesture, should not crash + try + { + TestGenerateLongPress( application, 50.0f, 10.0f ); + TestEndLongPress( application, 50.0f, 10.0f ); + + DALI_TEST_CHECK( true ); // No crash, test has passed + DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION); + } + catch(...) + { + DALI_TEST_CHECK( false ); // If we crash, the test has failed + } + + END_TEST; +} + +