X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-PanGestureDetector.cpp;h=dc0a402263175aa0d1265af695a20ed4e13e36be;hb=197334092bf0d0a91cd3b28db7d346e2a024cb64;hp=a902e9fdbe0a11cddf0014edd18a6cec8be5a9ff;hpb=e424c13b4dd452d36ce86a29e1e3c6943cd07714;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp index a902e9f..dc0a402 100644 --- a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -21,8 +21,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -43,8 +42,6 @@ void utc_dali_pan_gesture_detector_cleanup(void) /////////////////////////////////////////////////////////////////////////////// namespace { -typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType; - const int PAN_EVENT_TIME_DELTA = 8; const int PAN_GESTURE_UPDATE_COUNT = 50; @@ -133,7 +130,8 @@ struct TouchEventFunctor struct ConstraintData { ConstraintData() - : called(false) + : panning( false ), + called( false ) { } @@ -143,11 +141,13 @@ struct ConstraintData Vector2 localPosition; Vector2 localDisplacement; Vector2 localVelocity; + bool panning; bool called; void Reset() { screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO; + panning = false; called = false; } }; @@ -157,47 +157,22 @@ struct PanConstraint { PanConstraint( ConstraintData& data ) : constraintData(data) { } - Vector3 operator()(const Vector3& current, - const PropertyInput& screenPositionProperty, - const PropertyInput& screenDisplacementProperty, - const PropertyInput& screenVelocityProperty, - const PropertyInput& localPositionProperty, - const PropertyInput& localDisplacementProperty, - const PropertyInput& localVelocityProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - constraintData.screenPosition = screenPositionProperty.GetVector2(); - constraintData.screenDisplacement = screenDisplacementProperty.GetVector2(); - constraintData.screenVelocity = screenVelocityProperty.GetVector2(); - constraintData.localPosition = localPositionProperty.GetVector2(); - constraintData.localDisplacement = localDisplacementProperty.GetVector2(); - constraintData.localVelocity = localVelocityProperty.GetVector2(); + constraintData.screenPosition = inputs[0]->GetVector2(); + constraintData.screenDisplacement = inputs[1]->GetVector2(); + constraintData.screenVelocity = inputs[2]->GetVector2(); + constraintData.localPosition = inputs[3]->GetVector2(); + constraintData.localDisplacement = inputs[4]->GetVector2(); + constraintData.localVelocity = inputs[5]->GetVector2(); + constraintData.panning = inputs[6]->GetBoolean(); constraintData.called = true; - return Vector3::ZERO; + current = Vector3::ZERO; } ConstraintData& constraintData; }; -// Generate a PanGestureEvent to send to Core -Integration::PanGestureEvent GeneratePan( - Gesture::State state, - Vector2 previousPosition, - Vector2 currentPosition, - unsigned long timeDelta, - unsigned int numberOfTouches = 1, - unsigned int time = 1u) -{ - Integration::PanGestureEvent pan(state); - - pan.previousPosition = previousPosition; - pan.currentPosition = currentPosition; - pan.timeDelta = timeDelta; - pan.numberOfTouches = numberOfTouches; - pan.time = time; - - return pan; -} - // Generate a PanGesture PanGesture GeneratePan( unsigned int time, Gesture::State state, @@ -227,74 +202,45 @@ PanGesture GeneratePan( unsigned int time, return pan; } -/** - * Helper to generate PanGestureEvent - * - * @param[in] application Application instance - * @param[in] state The Gesture State - * @param[in] pos The current position of touch. - */ -static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos) -{ - static Vector2 last; - static int LastTime = 0; +} // anon namespace - if( (state == Gesture::Started) || - (state == Gesture::Possible) ) - { - last.x = pos.x; - last.y = pos.y; - } +/////////////////////////////////////////////////////////////////////////////// - application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA)); +// Positive test case for a method +int UtcDaliPanGestureDetectorConstructor(void) +{ + TestApplication application; - last.x = pos.x; - last.y = pos.y; - LastTime += PAN_EVENT_TIME_DELTA; + PanGestureDetector detector; + DALI_TEST_CHECK(!detector); + END_TEST; } -static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true) +int UtcDaliPanGestureDetectorCopyConstructorP(void) { - // Now do a pan starting from (start) and heading (direction) - Vector2 pos(start); - SendPan(application, Gesture::Possible, pos); - SendPan(application, Gesture::Started, pos); - application.SendNotification(); - application.Render(); - - for(int i = 0;i(1), TEST_LOCATION ); - for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter ) + DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION ); + bool found = false; + for( size_t i = 0; i < detector.GetAngleCount(); i++) { - if ( iter->first == PanGestureDetector::DIRECTION_LEFT ) + if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT ) { tet_result( TET_PASS ); + found = true; break; } + } - if ( iter == endIter ) - { - tet_printf("%s, angle not added\n", TEST_LOCATION ); - tet_result( TET_FAIL ); - } + if(!found ) + { + tet_printf("%s, angle not added\n", TEST_LOCATION ); + tet_result( TET_FAIL ); } detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) ); - DALI_TEST_EQUALS( angles.size(), static_cast(2), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION ); // Remove something not in the container. detector.RemoveAngle( PanGestureDetector::DIRECTION_UP ); - DALI_TEST_EQUALS( angles.size(), static_cast(2), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION ); detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT ); - DALI_TEST_EQUALS( angles.size(), static_cast(1), TEST_LOCATION ); - for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter ) + DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION ); + for ( size_t i = 0; i < detector.GetAngleCount(); i++) { - if ( iter->first == PanGestureDetector::DIRECTION_RIGHT ) + if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT ) { tet_printf("%s, angle not removed\n", TEST_LOCATION ); tet_result( TET_FAIL ); @@ -1764,7 +1539,34 @@ int UtcDaliPanGestureAngleHandling(void) } detector.ClearAngles(); - DALI_TEST_EQUALS( angles.size(), static_cast(0), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPanGestureGetAngle(void) +{ + TestApplication application; + + PanGestureDetector detector = PanGestureDetector::New(); + DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION ); + + detector.AddAngle( PanGestureDetector::DIRECTION_LEFT ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION ); + + detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION ); + + detector.AddAngle( PanGestureDetector::DIRECTION_UP ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION ); + + detector.AddAngle( PanGestureDetector::DIRECTION_DOWN ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION ); + + DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION ); + END_TEST; } @@ -1778,39 +1580,38 @@ int UtcDaliPanGestureAngleOutOfRange(void) TestApplication application; PanGestureDetector detector = PanGestureDetector::New(); - const PanGestureDetector::AngleContainer& angles( detector.GetAngles() ); - DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION ); // // Angle // detector.AddAngle( Degree(180.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(190.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(-190.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(350.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(-350.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(370.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( Degree(-370.0f) ); - DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); // @@ -1818,19 +1619,19 @@ int UtcDaliPanGestureAngleOutOfRange(void) // detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) ); - DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) ); - DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) ); - DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) ); - DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION ); detector.ClearAngles(); END_TEST; } @@ -1870,38 +1671,46 @@ int UtcDaliPanGestureAngleProcessing(void) childDetector.DetectedSignal().Connect(&application, childFunctor); // Generate an Up pan gesture, only parent should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) ); + uint32_t time = 100; + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time ); + DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 4.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Right pan gesture, only child should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(4.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Down pan gesture, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 36.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Left pan gesture, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(4.0f, 20.0f), time ); parentData.Reset(); childData.Reset(); END_TEST; @@ -1912,47 +1721,51 @@ int UtcDaliPanGestureDirectionHandling(void) TestApplication application; PanGestureDetector detector = PanGestureDetector::New(); - const PanGestureDetector::AngleContainer& angles( detector.GetAngles() ); - DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION ); detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) ); - DALI_TEST_EQUALS( angles.size(), static_cast(2), TEST_LOCATION ); - for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter ) + DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION ); + bool found = false; + for ( size_t i = 0; detector.GetAngleCount(); i++) { - if ( iter->first == PanGestureDetector::DIRECTION_LEFT ) + if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT ) { tet_result( TET_PASS ); + found = true; break; } - if ( iter == endIter ) - { - tet_printf("%s, angle not added\n", TEST_LOCATION ); - tet_result( TET_FAIL ); - } } - for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter ) + if (!found ) + { + tet_printf("%s, angle not added\n", TEST_LOCATION ); + tet_result( TET_FAIL ); + } + + found = false; + for( size_t i = 0; i < detector.GetAngleCount(); i++) { - if ( iter->first == PanGestureDetector::DIRECTION_RIGHT ) + if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT ) { tet_result( TET_PASS ); + found = true; break; } + } - if ( iter == endIter ) - { - tet_printf("%s, angle not added\n", TEST_LOCATION ); - tet_result( TET_FAIL ); - } + if(!found ) + { + tet_printf("%s, angle not added\n", TEST_LOCATION ); + tet_result( TET_FAIL ); } // Remove something not in the container. detector.RemoveDirection( PanGestureDetector::DIRECTION_UP ); - DALI_TEST_EQUALS( angles.size(), static_cast(2), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION ); detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT ); - DALI_TEST_EQUALS( angles.size(), static_cast(0), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION ); END_TEST; } @@ -1991,74 +1804,79 @@ int UtcDaliPanGestureDirectionProcessing(void) childDetector.DetectedSignal().Connect(&application, childFunctor); // Generate an Up pan gesture, only parent should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) ); + uint32_t time = 100; + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time ); + DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Right pan gesture, only child should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Down pan gesture, only parent should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time ); + DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a Left pan gesture, only child should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a pan at -45 degrees, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a pan at 45 degrees, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) ); - DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); - DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); - parentData.Reset(); - childData.Reset(); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time ); - // Generate a pan at 135 degrees, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) ); DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); + time += TestGetFrameInterval(); parentData.Reset(); childData.Reset(); // Generate a pan at -135 degrees, no one should receive it. - application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) ); + TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time ); + DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION ); - application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) ); + + TestEndPan( application, Vector2(20.0f, 20.0f), time ); parentData.Reset(); childData.Reset(); END_TEST; @@ -2085,21 +1903,39 @@ int UtcDaliPanGestureNoPredictionNoSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); // Render and notify application.SendNotification(); application.Render(); - Vector2 direction(Vector2::XAXIS * -5.0f); Vector2 startPosition( 1.0f, 1.0f ); - PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true); + Vector2 position( -14.0f, 1.0f ); + Vector2 direction(Vector2::XAXIS * -5.0f); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 47; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION ); @@ -2130,26 +1966,44 @@ int UtcDaliPanGestureNoPredictionSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); // Render and notify application.SendNotification(); application.Render(); + Vector2 startPosition( 1.0f, 1.0f ); + Vector2 position( -14.0f, 1.0f ); Vector2 direction(Vector2::XAXIS * -5.0f); - Vector2 previousPosition( 20.0f, 20.0f ); - Vector2 currentPosition( 20.0f, 10.0f ); - PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 47; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); - DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION ); - DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION ); + // Take into account resampling done when prediction is off. + DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION ); constraintData.Reset(); END_TEST; @@ -2176,22 +2030,39 @@ int UtcDaliPanGesturePredictionNoSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); // Render and notify application.SendNotification(); application.Render(); + Vector2 startPosition( 1.0f, 1.0f ); + Vector2 position( -1.0f, 1.0f ); Vector2 direction(Vector2::XAXIS * -1.0f); - Vector2 previousPosition( 20.0f, 20.0f ); - Vector2 currentPosition( 20.0f, 10.0f ); - PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 47; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION ); @@ -2201,7 +2072,7 @@ int UtcDaliPanGesturePredictionNoSmoothing(void) END_TEST; } -int UtcDaliPanGesturePredictionSmoothing(void) +int UtcDaliPanGesturePredictionSmoothing01(void) { TestApplication application; Integration::SetPanGesturePredictionMode(1); @@ -2222,26 +2093,426 @@ int UtcDaliPanGesturePredictionSmoothing(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); // Render and notify application.SendNotification(); application.Render(); + Vector2 startPosition( 1.0f, 1.0f ); + Vector2 position( -1.0f, 1.0f ); Vector2 direction(Vector2::XAXIS * -1.0f); - Vector2 previousPosition( 20.0f, 20.0f ); - Vector2 currentPosition( 20.0f, 10.0f ); - PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true); - DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); - DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); - DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION ); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 47; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION ); + + constraintData.Reset(); + END_TEST; +} + +int UtcDaliPanGesturePredictionSmoothing02(void) +{ + TestApplication application; + Integration::SetPanGesturePredictionMode( 1 ); + Integration::SetPanGestureMaximumPredictionAmount( 1 ); + Integration::SetPanGesturePredictionAmountAdjustment( 2 ); + Integration::SetPanGestureSmoothingMode( 1 ); + Integration::SetPanGestureSmoothingAmount( 0.25f ); + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Add a pan detector + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach( actor ); + SignalData data; + GestureReceivedFunctor functor( data ); + detector.DetectedSignal().Connect( &application, functor ); + + Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); + + ConstraintData constraintData; + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector2 startPosition( 2.0f, 2.0f ); + Vector2 position( 4.0f, 2.0f ); + Vector2 directionX(Vector2::XAXIS); + Vector2 directionY(Vector2::YAXIS); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 7; i++ ) + { + position += directionX; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + position += directionX * 10.0f; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + for(int i = 0; i < 2; i++ ) + { + position += ( directionX * -1.0f ); + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + position += directionX; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + position += directionY; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + + constraintData.Reset(); + END_TEST; +} + +int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void) +{ + TestApplication application; + + Integration::SetPanGesturePredictionMode( 2 ); + Integration::SetPanGesturePredictionAmount( 57 ); + Integration::SetPanGestureSmoothingMode( 2 ); + Integration::SetPanGestureUseActualTimes( false ); + Integration::SetPanGestureInterpolationTimeRange( 10 ); + Integration::SetPanGestureScalarOnlyPredictionEnabled( false ); + Integration::SetPanGestureTwoPointPredictionEnabled( true ); + Integration::SetPanGestureTwoPointInterpolatePastTime( 42 ); + Integration::SetPanGestureTwoPointVelocityBias( 0.35f ); + Integration::SetPanGestureTwoPointAccelerationBias( 0.10f ); + Integration::SetPanGestureMultitapSmoothingRange( 34 ); + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Add a pan detector + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach( actor ); + SignalData data; + GestureReceivedFunctor functor( data ); + detector.DetectedSignal().Connect( &application, functor ); + + Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); + + ConstraintData constraintData; + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector2 startPosition( 2.0f, 2.0f ); + Vector2 position( -1.0f, 2.0f ); + Vector2 direction(Vector2::XAXIS * -1.0f); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 27; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + + constraintData.Reset(); + END_TEST; +} + +int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void) +{ + TestApplication application; + + Integration::SetPanGesturePredictionMode( 2 ); + Integration::SetPanGestureSmoothingMode( 2 ); + Integration::SetPanGestureUseActualTimes( true ); + Integration::SetPanGestureInterpolationTimeRange( 10 ); + Integration::SetPanGestureScalarOnlyPredictionEnabled( true ); + Integration::SetPanGestureTwoPointPredictionEnabled( true ); + Integration::SetPanGestureTwoPointInterpolatePastTime( 42 ); + Integration::SetPanGestureTwoPointVelocityBias( 0.35f ); + Integration::SetPanGestureTwoPointAccelerationBias( 0.10f ); + Integration::SetPanGestureMultitapSmoothingRange( 34 ); + + Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE ); + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Add a pan detector + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach( actor ); + SignalData data; + GestureReceivedFunctor functor( data ); + detector.DetectedSignal().Connect( &application, functor ); + + Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); + + ConstraintData constraintData; + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector2 startPosition( 2.0f, 2.0f ); + Vector2 position( 17.0f, 2.0f ); + Vector2 direction(Vector2::XAXIS * -1.0f); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 10; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + + constraintData.Reset(); + END_TEST; +} + +int UtcDaliPanGesturePrediction2Smoothing(void) +{ + TestApplication application; + + Integration::SetPanGesturePredictionMode( 2 ); + Integration::SetPanGesturePredictionAmount( 57 ); + Integration::SetPanGestureSmoothingMode( 1 ); + Integration::SetPanGestureUseActualTimes( false ); + Integration::SetPanGestureInterpolationTimeRange( 10 ); + Integration::SetPanGestureScalarOnlyPredictionEnabled( true ); + Integration::SetPanGestureTwoPointPredictionEnabled( true ); + Integration::SetPanGestureTwoPointInterpolatePastTime( 42 ); + Integration::SetPanGestureTwoPointVelocityBias( 0.35f ); + Integration::SetPanGestureTwoPointAccelerationBias( 0.10f ); + Integration::SetPanGestureMultitapSmoothingRange( 34 ); + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Add a pan detector + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach( actor ); + SignalData data; + GestureReceivedFunctor functor( data ); + detector.DetectedSignal().Connect( &application, functor ); + + Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); + + ConstraintData constraintData; + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector2 startPosition( 2.0f, 2.0f ); + Vector2 position( 17.0f, 2.0f ); + Vector2 direction(Vector2::XAXIS * -1.0f); + uint32_t time = 100; + + TestStartPan( application, startPosition, position, time ); + + for(int i = 0; i < 10; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + for(int i = 0; i < 5; i++ ) + { + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + for(int i = 0; i < 10; i++ ) + { + position += direction; + TestMovePan( application, position, time ); + time += TestGetFrameInterval(); + application.SendNotification(); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + } + + TestEndPan( application, position, time ); + application.Render(TestApplication::DEFAULT_RENDER_INTERVAL); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION ); constraintData.Reset(); END_TEST; @@ -2267,15 +2538,19 @@ int UtcDaliPanGestureSetProperties(void) detector.DetectedSignal().Connect( &application, functor ); Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); + Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.AddSource( Source( detector, animatableGestureProperty ) ); + constraint.Apply(); // Render and notify application.SendNotification(); @@ -2329,22 +2604,23 @@ int UtcDaliPanGestureSetPropertiesAlreadyPanning(void) Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO ); ConstraintData constraintData; - actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), - Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), - Source( detector, PanGestureDetector::SCREEN_VELOCITY ), - Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), - Source( detector, PanGestureDetector::LOCAL_VELOCITY ), - PanConstraint( constraintData ) ) ); + Constraint constraint = Constraint::New( actor, property, PanConstraint( constraintData ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) ); + constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) ); + constraint.Apply(); // Render and notify application.SendNotification(); application.Render(); - Vector2 previousPosition( 20.0f, 20.0f ); - Vector2 currentPosition( 20.0f, 10.0f ); - application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) ); - application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) ); + Vector2 currentPosition( 20.0f, 4.0f ); + uint32_t time = 100; + TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); Vector2 screenPosition( 100.0f, 20.0f ); @@ -2370,8 +2646,109 @@ int UtcDaliPanGesturePropertyIndices(void) Property::IndexContainer indices; detector.GetPropertyIndices( indices ); - DALI_TEST_CHECK( ! indices.empty() ); - DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION ); + DALI_TEST_CHECK( indices.Size() ); + DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION ); + END_TEST; +} + +namespace +{ +struct PropertyStringIndex +{ + const char * const name; + const Property::Index index; + const Property::Type type; + const Property::Value value; +}; + +const PropertyStringIndex PROPERTY_TABLE[] = +{ + { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO }, + { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO }, + { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO }, + { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO }, + { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO }, + { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO }, + { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false }, +}; +const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] ); +} // unnamed namespace + + +int UtcDaliPanGestureProperties(void) +{ + TestApplication application; + PanGestureDetector detector = PanGestureDetector::New(); + + for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i ) + { + DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION ); + detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage + } + + END_TEST; +} + +int UtcDaliPanGestureGetProperty(void) +{ + TestApplication application; + PanGestureDetector detector = PanGestureDetector::New(); + + for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i ) + { + if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 ) + { + bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >(); + DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION ); + } + else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN ) + { + Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >(); + DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION ); + } + } + + END_TEST; +} + +int UtcDaliPanGestureGetPropertyWithSceneObject(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Add a pan detector + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach( actor ); + + // Render and notify + application.SendNotification(); + application.Render(); + + for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i ) + { + detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage + + if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 ) + { + bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >(); + DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION ); + } + else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN ) + { + Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >(); + DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION ); + } + } + END_TEST; } @@ -2403,9 +2780,11 @@ int UtcDaliPanGestureLayerConsumesTouch(void) application.Render(); // Emit signals, should receive - application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); - application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); - application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); + uint32_t time = 100; + TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time ); + TestEndPan( application, Vector2(26.0f, 20.0f), time ); + time += TestGetFrameInterval(); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); data.Reset(); @@ -2417,9 +2796,9 @@ int UtcDaliPanGestureLayerConsumesTouch(void) application.Render(); // Emit the same signals again, should not receive - application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); - application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); - application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10)); + TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time ); + TestEndPan( application, Vector2(26.0f, 20.0f), time ); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); data.Reset(); @@ -2446,10 +2825,13 @@ int UtcDaliPanGestureNoTimeDiff(void) application.SendNotification(); application.Render(); - // Emit signals, should receive - application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0)); - application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0)); - application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0)); + // As normal helper function adds intervals between presses we must generate the sequence + // using other helper functions + TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event + TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); + TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger + TestEndPan( application, Vector2(26.0f, 20.0f), 100 ); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) ); DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );