X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ScrollView.cpp;h=3f9879ef257711937bce9513f3573b465ad99c68;hp=fd01efe3f6812bb17e4ab97aa0afd01985469191;hb=647305c7fc201b837f0643bf7994c46c4546801f;hpb=2fcbbac038816efeeed3ea7717cdd823d46d9c2c diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp index fd01efe..3f9879e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp @@ -685,6 +685,9 @@ int UtcDaliToolkitScrollViewSetWrapModeP(void) ScrollView scrollView = ScrollView::New(); Stage::GetCurrent().Add( scrollView ); + Actor actor = Actor::New(); + scrollView.Add( actor ); + // Position rulers. 4x4 grid. RulerPtr rulerX = new FixedRuler(50.0f); RulerPtr rulerY = new FixedRuler(50.0f); @@ -697,7 +700,10 @@ int UtcDaliToolkitScrollViewSetWrapModeP(void) scrollView.ScrollTo(Vector2(225.0f, 125.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped) Wait(application); DALI_TEST_EQUALS( static_cast(scrollView.GetCurrentPage()), 17, TEST_LOCATION ); + scrollView.SetWrapMode(true); + scrollView.ScrollTo(Vector2(230.0f, 130.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped) + Wait(application); DALI_TEST_EQUALS( static_cast(scrollView.GetCurrentPage()), 13, TEST_LOCATION ); END_TEST; } @@ -876,6 +882,7 @@ int UtcDaliToolkitScrollViewScrollSensitive(void) // Set up a scrollView... ScrollView scrollView = ScrollView::New(); + scrollView.SetOvershootEnabled(true); Stage::GetCurrent().Add( scrollView ); Vector2 stageSize = Stage::GetCurrent().GetSize(); scrollView.SetSize(stageSize); @@ -1087,6 +1094,7 @@ int UtcDaliToolkitScrollViewOvershoot(void) // Set up a scrollView... ScrollView scrollView = ScrollView::New(); + scrollView.SetOvershootEnabled(true); Stage::GetCurrent().Add( scrollView ); Vector2 stageSize = Stage::GetCurrent().GetSize(); scrollView.SetSize(stageSize); @@ -1318,8 +1326,11 @@ int UtcDaliToolkitScrollViewSetMaxOvershootP(void) currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 105, false); overshootXValue = scrollView.GetProperty(ScrollView::Property::OVERSHOOT_X); overshootYValue = scrollView.GetProperty(ScrollView::Property::OVERSHOOT_Y); - DALI_TEST_CHECK(overshootXValue > 0.49f && overshootXValue < 0.51f); - DALI_TEST_CHECK(overshootYValue > 0.49f && overshootYValue < 0.51f); + // The overshoot value is a 0.0f - 1.0f ranged value of the amount overshot related to the maximum overshoot. + // EG. If we move 105, max overshoot is 50, then we overshot 50 / 105. + float correctOvershootValue = 50.0f / 105.f; + DALI_TEST_EQUALS( overshootXValue, correctOvershootValue, 0.001f, TEST_LOCATION ); + DALI_TEST_EQUALS( overshootYValue, correctOvershootValue, 0.001f, TEST_LOCATION ); // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch) currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false); @@ -1367,7 +1378,8 @@ int UtcDaliToolkitScrollViewSetScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + // Take into account resampling done when prediction is off. + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL); @@ -1383,7 +1395,7 @@ int UtcDaliToolkitScrollViewSetScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); END_TEST; } @@ -1417,7 +1429,8 @@ int UtcDaliToolkitScrollViewRemoveScrollingDirectionP(void) Wait(application); // Try a vertical swipe. PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true); - DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION ); + // Take into account resampling done when prediction is off. + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION ); END_TEST; } @@ -1505,17 +1518,17 @@ int UtcDaliToolkitScrollViewSetMinimumDistanceForFlickP(void) END_TEST; } -int UtcDaliToolkitScrollViewSetMouseWheelScrollDistanceStepP(void) +int UtcDaliToolkitScrollViewSetWheelScrollDistanceStepP(void) { ToolkitTestApplication application; - tet_infoline(" UtcDaliToolkitScrollViewSetMouseWheelScrollDistanceStepP"); + tet_infoline(" UtcDaliToolkitScrollViewSetWheelScrollDistanceStepP"); ScrollView scrollView = ScrollView::New(); // Disable Refresh signal (TET environment cannot use adaptor's Timer) - scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f)); - DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION ); - scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f)); - DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION); + scrollView.SetWheelScrollDistanceStep(Vector2(30.0f, 15.0f)); + DALI_TEST_EQUALS( scrollView.GetWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION ); + scrollView.SetWheelScrollDistanceStep(Vector2(60.0f, 30.0f)); + DALI_TEST_EQUALS( scrollView.GetWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION); END_TEST; } @@ -2006,6 +2019,18 @@ int UtcDaliToolkitScrollViewFixedRulerGetPositionFromPageP(void) position = rulerNormal->GetPositionFromPage(2, volume, true); DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION ); DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION ); + + // Disable the ruler + rulerNormal->Disable(); + + position = rulerNormal->GetPositionFromPage(1, volume, true); + DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( volume, 1u, TEST_LOCATION ); + + position = rulerNormal->GetPositionFromPage(2, volume, true); + DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( volume, 2u, TEST_LOCATION ); + END_TEST; } @@ -2103,6 +2128,21 @@ int UtcDaliToolkitScrollViewFixedRulerGetPageFromPositionP(void) DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION); DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION); + // Set domain size to be smaller than the ruler space + fixedRuler->SetDomain( RulerDomain(0.0f, 50.0f, true) ); + + fixedRuler->Enable(); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 3u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION); + + fixedRuler->Disable(); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 0u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION); + DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION); + END_TEST; } @@ -2153,6 +2193,157 @@ int UtcDaliToolkitScrollViewFixedRulerSnapP(void) END_TEST; } +int UtcDaliToolkitScrollViewConstraintsMove(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitScrollViewConstraintsMove"); + // Set up a scrollView... + ScrollView scrollView = ScrollView::New(); + Stage::GetCurrent().Add( scrollView ); + Vector2 stageSize = Stage::GetCurrent().GetSize(); + scrollView.SetSize(stageSize); + scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT); + scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT); + + // Position rulers. + RulerPtr rulerX = new DefaultRuler(); + RulerPtr rulerY = new DefaultRuler(); + rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) ); + rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) ); + scrollView.SetRulerX(rulerX); + scrollView.SetRulerY(rulerY); + + // Add an Actor to ScrollView, + Actor a = Actor::New(); + scrollView.Add(a); + a.SetPosition( TEST_ACTOR_POSITION ); + Wait(application); + + const Vector2 target = Vector2(100.0f, 100.0f); + const Vector2 target2 = Vector2(200.0f, 200.0f); + + Constraint constraint = Constraint::New( scrollView, Actor::Property::POSITION, MoveActorConstraint ); + constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) ); + constraint.SetRemoveAction(Constraint::Discard); + scrollView.ApplyConstraintToChildren(constraint); + scrollView.ScrollTo( target, 0.0f ); + Wait(application); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION ); + scrollView.ScrollTo( target2 ); + Wait(application, RENDER_DELAY_SCROLL); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION ); + + END_TEST; +} +int UtcDaliToolkitScrollViewConstraintsWrap(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitScrollViewConstraintsWrap"); + + // Set up a scrollView... + ScrollView scrollView = ScrollView::New(); + Stage::GetCurrent().Add( scrollView ); + Vector2 stageSize = Stage::GetCurrent().GetSize(); + scrollView.SetSize(stageSize); + scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT); + scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT); + + // Position rulers. + RulerPtr rulerX = new DefaultRuler(); + RulerPtr rulerY = new DefaultRuler(); + rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) ); + rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) ); + scrollView.SetRulerX(rulerX); + scrollView.SetRulerY(rulerY); + + // Add an Actor to ScrollView, + Actor a = Actor::New(); + scrollView.Add(a); + a.SetPosition( TEST_ACTOR_POSITION ); + Wait(application); + + const Vector2 target = Vector2(100.0f, 100.0f); + const Vector2 target2 = Vector2(200.0f, 200.0f); + + Constraint constraint = Constraint::New( scrollView, Actor::Property::POSITION, WrapActorConstraint ); + constraint.AddSource( LocalSource( Actor::Property::SCALE ) ); + constraint.AddSource( LocalSource( Actor::Property::ANCHOR_POINT ) ); + constraint.AddSource( LocalSource( Actor::Property::SIZE ) ); + constraint.AddSource( Source( scrollView, Toolkit::Scrollable::Property::SCROLL_POSITION_MIN ) ); + constraint.AddSource( Source( scrollView, Toolkit::Scrollable::Property::SCROLL_POSITION_MAX ) ); + constraint.AddSource( Source( scrollView, Toolkit::ScrollView::Property::WRAP ) ); + constraint.SetRemoveAction(Constraint::Discard); + scrollView.ApplyConstraintToChildren(constraint); + + scrollView.ScrollTo( target, 0.0f ); + Wait(application); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION ); + scrollView.ScrollTo( target2 ); + Wait(application, RENDER_DELAY_SCROLL); + DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION ); + + END_TEST; +} + +// Non-API test (so no P or N variant). +int UtcDaliToolkitScrollViewGesturePageLimit(void) +{ + ToolkitTestApplication application; + tet_infoline( " UtcDaliToolkitScrollViewGesturePageLimit" ); + + // Set up a scrollView. + ScrollView scrollView = ScrollView::New(); + + // Do not rely on stage size for UTC tests. + Vector2 pageSize( 720.0f, 1280.0f ); + scrollView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + scrollView.SetSize( pageSize ); + scrollView.SetParentOrigin( ParentOrigin::CENTER ); + scrollView.SetAnchorPoint( AnchorPoint::CENTER ); + scrollView.SetPosition( 0.0f, 0.0f, 0.0f ); + + // Position rulers. + // We set the X ruler to fixed to give us pages to snap to. + Dali::Toolkit::FixedRuler* rulerX = new Dali::Toolkit::FixedRuler( pageSize.width ); + // Note: The 3x page width is arbitary, but we need enough to show that we are + // capping page movement by the page limiter, and not the domain. + rulerX->SetDomain( Dali::Toolkit::RulerDomain( 0.0f, pageSize.width * 3.0f, false ) ); + Dali::Toolkit::RulerPtr rulerY = new Dali::Toolkit::DefaultRuler(); + rulerY->Disable(); + scrollView.SetRulerX( rulerX ); + scrollView.SetRulerY( rulerY ); + + scrollView.SetWrapMode( false ); + scrollView.SetScrollSensitive( true ); + + Stage::GetCurrent().Add( scrollView ); + + // Set up a gesture to perform. + Vector2 startPos( 50.0f, 0.0f ); + Vector2 direction( -5.0f, 0.0f ); + int frames = 200; + + // Force starting position. + scrollView.ScrollTo( startPos, 0.0f ); + Wait( application ); + + // Deliberately skip the "Finished" part of the gesture, so we can read the coordinates before the snap begins. + Vector2 currentPos( PerformGestureDiagonalSwipe( application, startPos, direction, frames - 1, false ) ); + + // Confirm the final X coord has not moved more than one page from the start X position. + DALI_TEST_GREATER( ( startPos.x + pageSize.width ), scrollView.GetCurrentScrollPosition().x, TEST_LOCATION ); + + // Finish the gesture and wait for the snap. + currentPos += direction; + SendPan( application, Gesture::Finished, currentPos ); + // We add RENDER_FRAME_INTERVAL on to wait for an extra frame (for the last "finished" gesture to complete first. + Wait( application, RENDER_DELAY_SCROLL + RENDER_FRAME_INTERVAL ); + + // Confirm the final X coord has snapped to exactly one page ahead of the start page. + DALI_TEST_EQUALS( pageSize.width, scrollView.GetCurrentScrollPosition().x, Math::MACHINE_EPSILON_0, TEST_LOCATION ); + + END_TEST; +}