2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
26 using namespace Toolkit;
28 void scroll_view_startup(void)
30 test_return_value = TET_UNDEF;
33 void scroll_view_cleanup(void)
35 test_return_value = TET_PASS;
40 static bool gObjectCreatedCallBackCalled;
42 static void TestCallback(BaseHandle handle)
44 gObjectCreatedCallBackCalled = true;
48 const int MILLISECONDS_PER_SECOND = 1000;
49 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
50 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
51 const int RENDER_DELAY_SCROLL = 1000; ///< duration to wait for any scroll to complete.
53 // For Clamp Signal testing...
54 const float CLAMP_EXCESS_WIDTH = 200.0f; ///< Amount of width that can be panned outside scrollview
55 const float CLAMP_EXCESS_HEIGHT = 200.0f; ///< Amount of height that can be panned outside scrollview
56 const int CLAMP_STEP_0_CHECK_NOTCLAMPED = 0; ///< FSM: "First check that scrollview isn't clamped"
57 const int CLAMP_STEP_1_CHECK_CLAMPED_WEST = 1; ///< FSM: "Next check that scrollview clamps against left side"
58 const int CLAMP_STEP_2_CHECK_CLAMPED_SOUTH_WEST = 2; ///< FSM: "Then check that scrollview clamps against bottom-left side"
59 const int CLAMP_STEP_3_SUCCESS = 3; ///< FSM: "Finished (Success)"
60 const Vector2 CLAMP_START_SCROLL_POSITION(30.0f, 100.0f); ///< Scroll start position for the Clamping tests.
61 const Vector2 CLAMP_TOUCH_START( 100.0f, 100.0f ); ///< Start point to touch from for the Clamping tests.
62 const Vector2 CLAMP_TOUCH_MOVEMENT( 5.0f, -5.0f ); ///< Amount to move touch for each frame for the Clamping tests.
63 const int CLAMP_GESTURE_FRAMES = 100; ///< Number of Frames to synthesize a gesture for the Clamping tests.
64 const Vector3 TEST_ACTOR_POSITION(100.0f, 100.0f, 0.0f); ///< A Test actor position offset (arbitrary value)
65 const Vector3 TEST_CONSTRAINT_OFFSET(1.0f, 2.0f, 0.0f); ///< A Test constraint offset (arbitrary value to test effects)
66 const float TEST_RATIO_TOLERANCE = 0.05; ///< +/-5% tolerance for ratio comparisons.
68 const float DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f); ///< Default overshoot snapping animation time.
69 const float DEFAULT_MAX_OVERSHOOT(100.0f); ///< Default maximum allowed overshoot in pixels
71 const int MAX_FRAMES_TO_TEST_OVERSHOOT = 600; ///< 10 seconds (at 60 frames per second).
72 const Vector2 OVERSHOOT_START_SCROLL_POSITION(100.0f, 100.0f); ///< Scroll start position for the Overshoot tests.
73 const float SCROLL_ANIMATION_DURATION(0.33f); ///< Duration of scroll animation in Overshoot tests (i.e. 100 pixels of overshoot in the speed of 500 pixels per 100 frames, 100/(500/(100/60)) = 0.33)
74 const Vector2 SNAP_POSITION_WITH_DECELERATED_VELOCITY(74.0f, 74.0f); ///< the snap position for Overshoot tests with the decelerated velocity (i.e. Decelerated from 500 pixels per 100 frames).
75 const float TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION = 0.05f; ///< a Test duration
76 const float TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION = 1.5f; ///< another Test duration
77 const float TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION = TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * 0.5f; // Same as above, but different alpha function.
78 const float TIME_TOLERANCE = 0.05f; ///< Allow testing tolerance between a 10th of second (+/- 3 frames)
81 // Generate a PanGestureEvent to send to Core
82 Integration::PanGestureEvent GeneratePan(
84 const Vector2& previousPosition,
85 const Vector2& currentPosition,
86 unsigned long timeDelta,
87 unsigned int numberOfTouches = 1)
89 Integration::PanGestureEvent pan(state);
91 pan.previousPosition = previousPosition;
92 pan.currentPosition = currentPosition;
93 pan.timeDelta = timeDelta;
94 pan.numberOfTouches = numberOfTouches;
100 * Helper to generate PanGestureEvent
102 * @param[in] application Application instance
103 * @param[in] state The Gesture State
104 * @param[in] pos The current position of touch.
106 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
110 if( (state == Gesture::Started) ||
111 (state == Gesture::Possible) )
117 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
124 * Simulate time passed by.
126 * @note this will always process at least 1 frame (1/60 sec)
128 * @param application Test application instance
129 * @param duration Time to pass in milliseconds.
130 * @return The actual time passed in milliseconds
132 int Wait(ToolkitTestApplication& application, int duration = 0)
136 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
138 application.SendNotification();
139 application.Render(RENDER_FRAME_INTERVAL);
140 time += RENDER_FRAME_INTERVAL;
148 static bool gOnScrollStartCalled; ///< Whether the OnScrollStart signal was invoked.
149 static bool gOnScrollUpdateCalled; ///< Whether the OnScrollUpdate signal was invoked.
150 static bool gOnScrollCompleteCalled; ///< Whether the OnScrollComplete signal was invoked.
151 static bool gOnSnapStartCalled; ///< Whether the OnSnapStart signal was invoked.
152 static SnapType gLastSnapType; ///< Snaping information from SnapEvent.
153 static Vector3 gConstraintResult; ///< Result from constraint.
156 * Invoked when scrolling starts.
158 * @param[in] position The current scroll position.
160 static void OnScrollStart( const Vector2& position )
162 gOnScrollStartCalled = true;
166 * Invoked when scrolling updates (via dragging)
168 * @param[in] position The current scroll position.
170 static void OnScrollUpdate( const Vector2& position )
172 gOnScrollUpdateCalled = true;
176 * Invoked when scrolling finishes
178 * @param[in] position The current scroll position.
180 static void OnScrollComplete( const Vector2& position )
182 gOnScrollCompleteCalled = true;
186 * Invoked when a snap or flick started.
188 * @param[in] event The type of snap and the target position/scale/rotation.
190 static void OnSnapStart( const ScrollView::SnapEvent& event )
192 gOnSnapStartCalled = true;
193 gLastSnapType = event.type;
199 * Summation of current value, property, and offset.
201 * current' = current + mOffset + property;
203 struct TestSumConstraint
206 * @param[in] offset The offset to be added to current.
208 TestSumConstraint(const Vector3& offset)
214 * @param[in] current The current base value
215 * @param[in] inputs Contains the property to be added to current.
216 * @return The new current Vector.
218 void operator()( Vector3& current, const PropertyInputContainer& inputs )
220 gConstraintResult = current + Vector3(inputs[0]->GetVector2()) + mOffset;
221 current = gConstraintResult;
229 * @param[in] application The application instance
230 * @param[in] scrollView The scrollView instance
231 * @return The time taken for the overshoot to reach origin (zero)
233 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
235 int timeToReachOrigin = -1;
236 for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
238 float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
239 float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
240 if(overshootXValue == 0.0f && overshootYValue == 0.0f)
245 timeToReachOrigin += Wait(application);
248 return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
252 * y = 2x alpha function, which is clamped between 0.0f - 1.0f
254 * Animations should appear to finish (reach 100% point)
255 * at just half the time of a regular Linear AlphaFunction.
257 * @param[in] progress value (ranges from 0.0f - 1.0f)
258 * @return interpolation value (ranges from 0.0f - 1.0f)
260 float TestAlphaFunction(float progress)
262 return std::min( progress * 2.0f, 1.0f );
265 } // unnamed namespace
268 int UtcDaliToolkitScrollViewConstructorP(void)
270 ToolkitTestApplication application;
272 ScrollView scrollView;
273 DALI_TEST_CHECK( !scrollView );
277 int UtcDaliToolkitScrollViewCopyConstructorP(void)
279 ToolkitTestApplication application;
281 ScrollView scrollView = ScrollView::New();
282 scrollView.SetProperty( ScrollView::Property::SCROLL_POSITION, Vector2(10.0f, 10.0f) );
284 ScrollView copy( scrollView );
285 DALI_TEST_CHECK( copy );
286 DALI_TEST_CHECK( copy.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) == scrollView.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) );
290 int UtcDaliToolkitScrollViewAssignmentOperatorP(void)
292 ToolkitTestApplication application;
294 ScrollView scrollView = ScrollView::New();
295 scrollView.SetProperty( ScrollView::Property::SCROLL_POSITION, Vector2(10.0f, 10.0f) );
297 ScrollView copy = scrollView;
298 DALI_TEST_CHECK( copy );
299 DALI_TEST_CHECK( copy.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) == scrollView.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) );
303 int UtcDaliScrollViewDestructorP(void)
305 ToolkitTestApplication application;
307 ScrollView* scrollView = new ScrollView();
310 DALI_TEST_CHECK( true );
314 int UtcDaliToolkitScrollViewNewP(void)
316 ToolkitTestApplication application;
317 tet_infoline(" UtcDaliToolkitScrollViewNewP");
319 ScrollView scrollView;
321 DALI_TEST_CHECK( !scrollView );
323 scrollView = ScrollView::New();
325 DALI_TEST_CHECK( scrollView );
327 ScrollView scrollView2(scrollView);
329 DALI_TEST_CHECK( scrollView2 == scrollView );
331 //Additional check to ensure object is created by checking if it's registered
332 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
333 DALI_TEST_CHECK( registry );
335 gObjectCreatedCallBackCalled = false;
336 registry.ObjectCreatedSignal().Connect( &TestCallback );
338 ScrollView scrollView = ScrollView::New();
340 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
344 int UtcDaliToolkitScrollViewDownCastP(void)
346 ToolkitTestApplication application;
347 tet_infoline(" UtcDaliToolkitScrollViewDownCastP");
349 ScrollView scrollView = ScrollView::New();
350 BaseHandle handle(scrollView);
352 ScrollView newScrollView = ScrollView::DownCast( handle );
353 DALI_TEST_CHECK( scrollView );
354 DALI_TEST_CHECK( newScrollView == scrollView );
358 int UtcDaliToolkitScrollViewScrollToPositionP(void)
360 ToolkitTestApplication application;
361 tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionP");
363 // Create the ScrollView actor
364 ScrollView scrollView = ScrollView::New();
365 Stage::GetCurrent().Add( scrollView );
367 const Vector2 target = Vector2(100.0f, 200.0f);
368 const Vector2 target2 = Vector2(300.0f, 100.0f);
370 scrollView.ScrollTo( target, 0.0f );
372 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
373 scrollView.ScrollTo( target2 );
374 Wait(application, RENDER_DELAY_SCROLL);
375 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
380 int UtcDaliToolkitScrollViewScrollToPositionWithDirectionBiasP(void)
382 ToolkitTestApplication application;
383 tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithDirectionBiasP");
385 ScrollView scrollView = ScrollView::New();
386 Stage::GetCurrent().Add( scrollView );
387 RulerPtr rulerX = new FixedRuler( 100.0f );
388 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
389 RulerPtr rulerY = new FixedRuler( 100.0f );
390 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
392 scrollView.SetRulerX( rulerX );
393 scrollView.SetRulerY( rulerY );
395 scrollView.SetWrapMode(true);
397 const Vector2 target = Vector2(50.0f, 50.0f);
398 const Vector2 target2 = Vector2(150.0f, 150.0f);
400 scrollView.ScrollTo( target, 0.0f );
401 Wait(application, RENDER_DELAY_SCROLL);
402 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
404 scrollView.ScrollTo( target2, 0.25f, Dali::Toolkit::DirectionBiasLeft, Dali::Toolkit::DirectionBiasLeft );
405 Wait(application, RENDER_DELAY_SCROLL);
406 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2::ZERO, TEST_LOCATION );
408 scrollView.ScrollTo( target, 0.0f );
409 Wait(application, RENDER_DELAY_SCROLL);
410 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
412 scrollView.ScrollTo( target2, 0.25f, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
413 Wait(application, RENDER_DELAY_SCROLL);
414 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
419 int UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionP(void)
421 ToolkitTestApplication application;
422 tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionP");
424 // Create the ScrollView actor
425 ScrollView scrollView = ScrollView::New();
426 Stage::GetCurrent().Add( scrollView );
428 const Vector2 target = Vector2(100.0f, 200.0f);
429 const Vector2 target2 = Vector2(300.0f, 100.0f);
431 scrollView.ScrollTo( target, 0.5f, TestAlphaFunction );
432 Wait(application, 250);
433 // Check that the scroll animation should finish within just half of the specified duration with the above alpha function
434 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
436 scrollView.ScrollTo( target2, 0.5f, AlphaFunction::LINEAR );
437 Wait(application, 250);
438 // Check that the scroll animation has not finished within half of the specified duration with the linear alpha function
439 DALI_TEST_CHECK( scrollView.GetCurrentScrollPosition() != target2 );
441 // Wait till the end of the specified duration
442 Wait(application, 250);
443 // Check that the scroll animation has finished
444 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
449 int UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionAndDirectionBiasP(void)
451 ToolkitTestApplication application;
452 tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionAndDirectionBiasP");
454 ScrollView scrollView = ScrollView::New();
455 Stage::GetCurrent().Add( scrollView );
456 RulerPtr rulerX = new FixedRuler( 100.0f );
457 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
458 RulerPtr rulerY = new FixedRuler( 100.0f );
459 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
461 scrollView.SetRulerX( rulerX );
462 scrollView.SetRulerY( rulerY );
464 scrollView.SetWrapMode(true);
466 const Vector2 target = Vector2(50.0f, 50.0f);
467 const Vector2 target2 = Vector2(150.0f, 150.0f);
469 scrollView.ScrollTo( target, 0.0f );
470 Wait(application, RENDER_DELAY_SCROLL);
471 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
473 scrollView.ScrollTo( target2, 0.25f, AlphaFunction::LINEAR, Dali::Toolkit::DirectionBiasLeft, Dali::Toolkit::DirectionBiasLeft );
474 Wait(application, RENDER_DELAY_SCROLL);
475 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2::ZERO, TEST_LOCATION );
477 scrollView.ScrollTo( target, 0.0f );
478 Wait(application, RENDER_DELAY_SCROLL);
479 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
481 scrollView.ScrollTo( target2, 0.25f, AlphaFunction::LINEAR, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
482 Wait(application, RENDER_DELAY_SCROLL);
483 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
485 scrollView.ScrollTo( target, 0.0f );
486 Wait(application, RENDER_DELAY_SCROLL);
487 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
489 scrollView.ScrollTo( target2, 0.25f, TestAlphaFunction, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
490 Wait(application, 125);
491 // Check that the scroll animation should finish within just half of the specified duration with the above alpha function
492 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
497 int UtcDaliToolkitScrollViewScrollToPageP(void)
499 ToolkitTestApplication application;
500 tet_infoline(" UtcDaliToolkitScrollViewScrollToPageP");
502 ScrollView scrollView = ScrollView::New();
503 Stage::GetCurrent().Add( scrollView );
504 RulerPtr rulerX = new FixedRuler( 100.0f );
505 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
506 RulerPtr rulerY = new FixedRuler( 100.0f );
507 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
509 scrollView.SetRulerX( rulerX );
510 scrollView.SetRulerY( rulerY );
512 scrollView.ScrollTo( 1, 0.0f );
514 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 0.0f), TEST_LOCATION );
516 scrollView.ScrollTo( 5, 0.0f );
518 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(500.0f, 0.0f), TEST_LOCATION );
520 scrollView.ScrollTo( 10, 0.0f );
522 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(200.0f, 100.0f), TEST_LOCATION );
524 scrollView.ScrollTo( 15, 0.0f );
526 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(700.0f, 100.0f), TEST_LOCATION );
527 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
529 scrollView.ScrollTo( 3 );
530 Wait(application, RENDER_DELAY_SCROLL);
531 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(300.0f, 0.0f), TEST_LOCATION );
532 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
534 scrollView.ScrollTo( 9 );
535 Wait(application, RENDER_DELAY_SCROLL);
536 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 100.0f), TEST_LOCATION );
537 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
539 // Apply DefaultRulers instead and see what happens.
540 rulerX = new DefaultRuler();
541 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
542 rulerY = new DefaultRuler();
543 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
545 scrollView.SetRulerX( rulerX );
546 scrollView.SetRulerY( rulerY );
548 // This time should always scroll to origin (0.0f, 0.0f)
549 scrollView.ScrollTo( 1, 0.0f );
551 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
552 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
557 int UtcDaliToolkitScrollViewScrollToPageWithDirectionBiasP(void)
559 ToolkitTestApplication application;
560 tet_infoline(" UtcDaliToolkitScrollViewScrollToPageWithDirectionBiasP");
562 ScrollView scrollView = ScrollView::New();
563 Stage::GetCurrent().Add( scrollView );
564 RulerPtr rulerX = new FixedRuler( 100.0f );
565 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
566 RulerPtr rulerY = new FixedRuler( 100.0f );
567 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
569 scrollView.SetRulerX( rulerX );
570 scrollView.SetRulerY( rulerY );
572 scrollView.SetWrapMode(true);
574 scrollView.ScrollTo( 0, 0.25, Dali::Toolkit::DirectionBiasLeft );
576 Wait(application, RENDER_FRAME_INTERVAL); // Wait for one frame
577 // Check that the scroll position remains the same
578 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
580 Wait(application, RENDER_DELAY_SCROLL); // Wait for one second
581 // Check that it stays at the same page (i.e. the same scroll position)
582 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
583 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
585 scrollView.ScrollTo( 0, 0.25, Dali::Toolkit::DirectionBiasRight );
587 Wait(application, RENDER_FRAME_INTERVAL); // Wait for one frame
588 // Check that it scrolls towards the right
589 DALI_TEST_CHECK( scrollView.GetCurrentScrollPosition().x > 0.0f );
591 Wait(application, RENDER_DELAY_SCROLL); // Wait for one second
592 // Check that it scrolls back to the same page (i.e. the same scroll position)
593 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
594 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
599 int UtcDaliToolkitScrollViewScrollToActorP(void)
601 ToolkitTestApplication application;
602 tet_infoline(" UtcDaliToolkitScrollViewScrollToActorP");
604 ScrollView scrollView = ScrollView::New();
605 Stage::GetCurrent().Add( scrollView );
607 Actor actorA = Actor::New();
608 const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
609 actorA.SetPosition(positionA);
610 scrollView.Add(actorA);
612 Actor actorB = Actor::New();
613 const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
614 actorB.SetPosition(positionB);
615 scrollView.Add(actorB);
619 scrollView.ScrollTo(actorA, 0.0f);
621 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA.GetVectorXY(), TEST_LOCATION );
624 scrollView.ScrollTo(actorB, 0.0f);
626 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB.GetVectorXY(), TEST_LOCATION );
628 scrollView.ScrollTo(actorA);
629 Wait(application, RENDER_DELAY_SCROLL);
630 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA.GetVectorXY(), TEST_LOCATION );
632 scrollView.ScrollTo(actorB);
633 Wait(application, RENDER_DELAY_SCROLL);
634 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB.GetVectorXY(), TEST_LOCATION );
638 int UtcDaliToolkitScrollViewScrollToSnapPointP(void)
640 ToolkitTestApplication application;
641 tet_infoline(" UtcDaliToolkitScrollViewScrollToSnapPointP");
643 ScrollView scrollView = ScrollView::New();
644 Stage::GetCurrent().Add( scrollView );
645 RulerPtr rulerX = new FixedRuler( 100.0f );
646 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
647 RulerPtr rulerY = new FixedRuler( 100.0f );
648 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
650 scrollView.SetRulerX( rulerX );
651 scrollView.SetRulerY( rulerY );
653 scrollView.ScrollTo( Vector2(120.0f, 190.0f), 0.0f );
655 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(120.0f, 190.0f), TEST_LOCATION );
657 scrollView.ScrollToSnapPoint();
659 Wait(application, RENDER_DELAY_SCROLL);
660 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 200.0f), TEST_LOCATION );
664 int UtcDaliToolkitScrollViewSetScrollUpdateDistanceP(void)
666 ToolkitTestApplication application;
667 tet_infoline(" UtcDaliToolkitScrollViewSetScrollUpdateDistanceP");
669 ScrollView scrollView = ScrollView::New();
671 scrollView.SetScrollUpdateDistance(0);
672 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 0, TEST_LOCATION);
673 scrollView.SetScrollUpdateDistance(10);
674 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 10, TEST_LOCATION);
675 scrollView.SetScrollUpdateDistance(1000);
676 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 1000, TEST_LOCATION);
680 int UtcDaliToolkitScrollViewSetWrapModeP(void)
682 ToolkitTestApplication application;
683 tet_infoline(" UtcDaliToolkitScrollViewSetWrapModeP");
685 ScrollView scrollView = ScrollView::New();
686 Stage::GetCurrent().Add( scrollView );
688 Actor actor = Actor::New();
689 scrollView.Add( actor );
691 // Position rulers. 4x4 grid.
692 RulerPtr rulerX = new FixedRuler(50.0f);
693 RulerPtr rulerY = new FixedRuler(50.0f);
694 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
695 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
696 scrollView.SetRulerX(rulerX);
697 scrollView.SetRulerY(rulerY);
699 scrollView.SetWrapMode(false);
700 scrollView.ScrollTo(Vector2(225.0f, 125.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
702 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
704 scrollView.SetWrapMode(true);
705 scrollView.ScrollTo(Vector2(230.0f, 130.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
707 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
711 int UtcDaliToolkitScrollViewActorAutoSnap(void)
713 ToolkitTestApplication application;
714 tet_infoline(" UtcDaliToolkitScrollViewActorAutoSnap");
716 ScrollView scrollView = ScrollView::New();
717 Stage::GetCurrent().Add( scrollView );
720 RulerPtr rulerX = new DefaultRuler();
721 RulerPtr rulerY = new DefaultRuler();
722 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
723 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
724 scrollView.SetRulerX(rulerX);
725 scrollView.SetRulerY(rulerY);
727 const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
728 Actor a = Actor::New();
730 a.SetPosition(aPosition);
732 const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
733 Actor b = Actor::New();
735 b.SetPosition(bPosition);
737 // Goto a random position, and execute snap (should not move)
738 Vector2 targetScroll = Vector2(500.0f, 500.0f);
739 scrollView.ScrollTo(targetScroll, 0.0f);
741 scrollView.ScrollToSnapPoint();
742 Wait(application, RENDER_DELAY_SCROLL);
743 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
745 // Enable ActorAutoSnap, and now try snapping.
746 scrollView.SetActorAutoSnap(true);
747 scrollView.ScrollToSnapPoint();
748 Wait(application, RENDER_DELAY_SCROLL);
749 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition.GetVectorXY(), TEST_LOCATION );
751 scrollView.ScrollTo(Vector2(0.0f, 0.0f), 0.0f);
753 scrollView.ScrollToSnapPoint();
754 Wait(application, RENDER_DELAY_SCROLL);
755 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition.GetVectorXY(), TEST_LOCATION );
759 int UtcDaliToolkitScrollViewSignalsStartComplete(void)
761 ToolkitTestApplication application;
762 tet_infoline(" UtcDaliToolkitScrollViewSignalsStartComplete");
764 gOnScrollStartCalled = false;
765 gOnScrollCompleteCalled = false;
767 ScrollView scrollView = ScrollView::New();
768 Stage::GetCurrent().Add( scrollView );
771 RulerPtr rulerX = new DefaultRuler();
772 RulerPtr rulerY = new DefaultRuler();
773 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
774 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
775 scrollView.SetRulerX(rulerX);
776 scrollView.SetRulerY(rulerY);
777 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
778 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
779 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
780 scrollView.ScrollTo( Vector2(100.0f, 100.0f) );
781 Wait(application, RENDER_DELAY_SCROLL);
783 DALI_TEST_CHECK(gOnScrollStartCalled);
784 DALI_TEST_CHECK(gOnScrollCompleteCalled);
788 int UtcDaliToolkitScrollViewSignalsUpdate(void)
790 ToolkitTestApplication application;
791 tet_infoline(" UtcDaliToolkitScrollViewSignalsUpdate");
793 gOnScrollStartCalled = false;
794 gOnScrollUpdateCalled = false;
795 gOnScrollCompleteCalled = false;
797 ScrollView scrollView = ScrollView::New();
798 Stage::GetCurrent().Add( scrollView );
799 Vector2 stageSize = Stage::GetCurrent().GetSize();
800 scrollView.SetSize(stageSize);
801 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
802 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
805 RulerPtr rulerX = new DefaultRuler();
806 RulerPtr rulerY = new DefaultRuler();
807 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
808 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
809 scrollView.SetRulerX(rulerX);
810 scrollView.SetRulerY(rulerY);
811 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
812 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
813 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
815 ImageActor image = CreateSolidColorActor( Color::RED );
816 image.SetSize(stageSize);
817 image.SetParentOrigin(ParentOrigin::TOP_LEFT);
818 image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
819 scrollView.Add(image);
823 // Do a pan starting from 100,100 and moving down diagonally.
824 Vector2 pos(100.0f, 100.0f);
825 SendPan(application, Gesture::Possible, pos);
826 SendPan(application, Gesture::Started, pos);
829 Wait(application, 100);
831 for(int i = 0;i<20;i++)
833 SendPan(application, Gesture::Continuing, pos);
839 SendPan(application, Gesture::Finished, pos);
840 Wait(application, RENDER_DELAY_SCROLL);
842 DALI_TEST_CHECK(gOnScrollStartCalled);
843 DALI_TEST_CHECK(gOnScrollUpdateCalled);
844 DALI_TEST_CHECK(gOnScrollCompleteCalled);
848 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
850 gOnScrollStartCalled = false;
851 gOnScrollUpdateCalled = false;
852 gOnScrollCompleteCalled = false;
853 gOnSnapStartCalled = false;
855 // Now do a pan starting from (start) and heading (direction)
857 SendPan(application, Gesture::Possible, pos);
858 SendPan(application, Gesture::Started, pos);
861 for(int i = 0;i<frames;i++)
863 pos += direction; // Move in this direction
864 SendPan(application, Gesture::Continuing, pos);
870 pos += direction; // Move in this direction.
871 SendPan(application, Gesture::Finished, pos);
872 Wait(application, RENDER_DELAY_SCROLL);
878 int UtcDaliToolkitScrollViewScrollSensitive(void)
880 ToolkitTestApplication application;
881 tet_infoline(" UtcDaliToolkitScrollViewScrollSensitive");
883 // Set up a scrollView...
884 ScrollView scrollView = ScrollView::New();
885 scrollView.SetOvershootEnabled(true);
886 Stage::GetCurrent().Add( scrollView );
887 Vector2 stageSize = Stage::GetCurrent().GetSize();
888 scrollView.SetSize(stageSize);
889 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
890 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
893 RulerPtr rulerX = new DefaultRuler();
894 RulerPtr rulerY = new DefaultRuler();
895 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
896 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
897 scrollView.SetRulerX(rulerX);
898 scrollView.SetRulerY(rulerY);
899 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
900 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
901 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
902 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
904 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
907 // First try insensitive swipe.
908 scrollView.SetScrollSensitive(false);
909 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
911 DALI_TEST_CHECK( !gOnScrollStartCalled );
912 DALI_TEST_CHECK( !gOnScrollCompleteCalled );
913 DALI_TEST_CHECK( !gOnSnapStartCalled );
915 // Second try sensitive swipe.
916 scrollView.SetScrollSensitive(true);
917 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
919 DALI_TEST_CHECK( gOnScrollStartCalled );
920 DALI_TEST_CHECK( gOnScrollCompleteCalled );
921 DALI_TEST_CHECK( gOnSnapStartCalled );
925 int UtcDaliToolkitScrollViewAxisAutoLock(void)
927 ToolkitTestApplication application;
928 tet_infoline(" UtcDaliToolkitScrollViewAxisAutoLock");
930 // Set up a scrollView...
931 ScrollView scrollView = ScrollView::New();
932 Stage::GetCurrent().Add( scrollView );
933 Vector2 stageSize = Stage::GetCurrent().GetSize();
934 scrollView.SetSize(stageSize);
935 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
936 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
939 RulerPtr rulerX = new DefaultRuler();
940 RulerPtr rulerY = new DefaultRuler();
941 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
942 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
943 scrollView.SetRulerX(rulerX);
944 scrollView.SetRulerY(rulerY);
945 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
946 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
947 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
950 scrollView.ScrollTo(Vector2(100.0f, 100.0f), 0.0f); // move in a little.
952 Vector2 startPosition = scrollView.GetCurrentScrollPosition();
953 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
954 const Vector2 positionAfterNormal = scrollView.GetCurrentScrollPosition();
957 scrollView.SetAxisAutoLock(true);
958 DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
960 scrollView.ScrollTo(Vector2(100.0f, 100.0f), 0.0f); // move in a little.
962 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
963 const Vector2 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
965 // compare how much the Y position has deviated for normal and autolock.
966 const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
967 const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
969 // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
970 DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
972 scrollView.SetAxisAutoLock(false);
973 DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
977 int UtcDaliToolkitScrollViewAxisAutoLockGradient(void)
979 ToolkitTestApplication application;
980 tet_infoline(" UtcDaliToolkitScrollViewAxisAutoLockGradient");
982 // Set up a scrollView...
983 ScrollView scrollView = ScrollView::New();
984 scrollView.SetAxisAutoLockGradient(0.5f);
985 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
986 scrollView.SetAxisAutoLockGradient(1.0f);
987 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
991 int UtcDaliToolkitScrollViewConstraints(void)
993 ToolkitTestApplication application;
994 tet_infoline(" UtcDaliToolkitScrollViewConstraints");
996 // Set up a scrollView...
997 ScrollView scrollView = ScrollView::New();
998 Stage::GetCurrent().Add( scrollView );
999 Vector2 stageSize = Stage::GetCurrent().GetSize();
1000 scrollView.SetSize(stageSize);
1001 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1002 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1005 RulerPtr rulerX = new DefaultRuler();
1006 RulerPtr rulerY = new DefaultRuler();
1007 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1008 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1009 scrollView.SetRulerX(rulerX);
1010 scrollView.SetRulerY(rulerY);
1012 // Add an Actor to ScrollView,
1013 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1014 gConstraintResult = Vector3::ZERO;
1015 Actor a = Actor::New();
1017 a.SetPosition( TEST_ACTOR_POSITION );
1020 Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1021 constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
1022 constraint.SetRemoveAction(Constraint::Discard);
1023 scrollView.ApplyConstraintToChildren(constraint);
1026 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1028 gConstraintResult = Vector3::ZERO;
1029 scrollView.RemoveConstraintsFromChildren();
1032 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1036 int UtcDaliToolkitScrollViewBind(void)
1038 ToolkitTestApplication application;
1039 tet_infoline(" UtcDaliToolkitScrollViewBind");
1041 // Set up a scrollView...
1042 ScrollView scrollView = ScrollView::New();
1043 Stage::GetCurrent().Add( scrollView );
1044 Vector2 stageSize = Stage::GetCurrent().GetSize();
1045 scrollView.SetSize(stageSize);
1046 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1047 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1050 RulerPtr rulerX = new DefaultRuler();
1051 RulerPtr rulerY = new DefaultRuler();
1052 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1053 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1054 scrollView.SetRulerX(rulerX);
1055 scrollView.SetRulerY(rulerY);
1057 // Add an Actor to ScrollView,
1058 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1060 gConstraintResult = Vector3::ZERO;
1061 Actor a = Actor::New();
1063 a.SetPosition( TEST_ACTOR_POSITION );
1066 // apply this constraint to scrollview
1067 Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1068 constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
1069 constraint.SetRemoveAction(Constraint::Discard);
1070 scrollView.ApplyConstraintToChildren(constraint);
1074 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1077 gConstraintResult = Vector3::ZERO;
1078 scrollView.UnbindActor( a );
1080 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1083 gConstraintResult = Vector3::ZERO;
1084 scrollView.BindActor( a );
1086 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1090 int UtcDaliToolkitScrollViewOvershoot(void)
1092 ToolkitTestApplication application;
1093 tet_infoline(" UtcDaliToolkitScrollViewOvershoot");
1095 // Set up a scrollView...
1096 ScrollView scrollView = ScrollView::New();
1097 scrollView.SetOvershootEnabled(true);
1098 Stage::GetCurrent().Add( scrollView );
1099 Vector2 stageSize = Stage::GetCurrent().GetSize();
1100 scrollView.SetSize(stageSize);
1101 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1102 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1105 RulerPtr rulerX = new DefaultRuler();
1106 RulerPtr rulerY = new DefaultRuler();
1107 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1108 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1109 scrollView.SetRulerX(rulerX);
1110 scrollView.SetRulerY(rulerY);
1111 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1112 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1113 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1115 scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1118 // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1119 Vector2 currentPos = Vector2(100.0f, 100.0f);
1120 currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1121 float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1122 float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1123 Vector2 positionValue = scrollView.GetProperty<Vector2>(ScrollView::Property::SCROLL_POSITION);
1124 DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1125 DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1126 DALI_TEST_EQUALS(positionValue, Vector2::ZERO, TEST_LOCATION);
1128 float timeToReachOrigin;
1130 // Now release touch. Overshoot should snap back to zero.
1131 SendPan(application, Gesture::Finished, currentPos);
1132 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1134 float minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + DEFAULT_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1135 float maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + DEFAULT_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1137 DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1138 (timeToReachOrigin < maxTimeToReachOrigin) );
1140 // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1141 scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1143 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1144 // Now release touch. Overshoot should snap back to zero.
1145 SendPan(application, Gesture::Finished, currentPos);
1146 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1148 minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1149 maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1151 DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1152 (timeToReachOrigin < maxTimeToReachOrigin) );
1154 // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1155 scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1157 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1158 // Now release touch. Overshoot should snap back to zero.
1159 SendPan(application, Gesture::Finished, currentPos);
1160 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1162 minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1163 maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1165 DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1166 (timeToReachOrigin < maxTimeToReachOrigin) );
1168 // 4. Repeat Scroll, but this time change overshoot function.
1169 scrollView.SetSnapOvershootDuration(TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION);
1170 scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
1172 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1173 // Now release touch. Overshoot should snap back to zero.
1174 SendPan(application, Gesture::Finished, currentPos);
1175 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1177 minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1178 maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1180 DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1181 (timeToReachOrigin < maxTimeToReachOrigin) );
1185 int UtcDaliToolkitScrollViewSnapAlphaFunction(void)
1187 ToolkitTestApplication application;
1188 tet_infoline(" UtcDaliToolkitScrollViewSnapAlphaFunction");
1190 // Set up a scrollView...
1191 ScrollView scrollView = ScrollView::New();
1192 scrollView.SetScrollSnapAlphaFunction( AlphaFunction::EASE_IN );
1193 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction().GetBuiltinFunction() == AlphaFunction::EASE_IN );
1194 scrollView.SetScrollSnapAlphaFunction( AlphaFunction::EASE_OUT );
1195 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction().GetBuiltinFunction() == AlphaFunction::EASE_OUT );
1197 scrollView.SetScrollFlickAlphaFunction( AlphaFunction::BOUNCE );
1198 DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction().GetBuiltinFunction() == AlphaFunction::BOUNCE );
1203 int UtcDaliToolkitScrollViewSnapDuration(void)
1205 ToolkitTestApplication application;
1206 tet_infoline(" UtcDaliToolkitScrollViewSnapDuration");
1208 // Set up a scrollView...
1209 ScrollView scrollView = ScrollView::New();
1210 scrollView.SetScrollSnapDuration( 1.0f );
1211 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1212 scrollView.SetScrollSnapDuration( 0.5f );
1213 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1215 scrollView.SetScrollFlickDuration( 2.0f );
1216 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1217 scrollView.SetScrollFlickDuration( 1.5f );
1218 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1222 int UtcDaliToolkitScrollViewSnapStartedSignalP(void)
1224 ToolkitTestApplication application;
1225 tet_infoline(" UtcDaliToolkitScrollViewSnapStartedSignalP");
1227 // Set up a scrollView...
1228 ScrollView scrollView = ScrollView::New();
1229 Stage::GetCurrent().Add( scrollView );
1230 Vector2 stageSize = Stage::GetCurrent().GetSize();
1231 scrollView.SetSize(stageSize);
1232 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1233 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1236 RulerPtr rulerX = new DefaultRuler();
1237 RulerPtr rulerY = new DefaultRuler();
1238 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1239 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1240 scrollView.SetRulerX(rulerX);
1241 scrollView.SetRulerY(rulerY);
1242 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1244 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1247 // First try a snap.
1248 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1250 DALI_TEST_CHECK( gOnSnapStartCalled );
1251 DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1253 // Second try a swipe.
1254 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1256 DALI_TEST_CHECK( gOnSnapStartCalled );
1257 DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1261 int UtcDaliToolkitScrollViewGetCurrentPageP(void)
1263 ToolkitTestApplication application;
1264 tet_infoline(" UtcDaliToolkitScrollViewGetCurrentPageP");
1266 ScrollView scrollView = ScrollView::New();
1267 Stage::GetCurrent().Add( scrollView );
1268 RulerPtr rulerX = new FixedRuler( 100.0f );
1269 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1270 RulerPtr rulerY = new FixedRuler( 100.0f );
1271 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1273 scrollView.SetRulerX( rulerX );
1274 scrollView.SetRulerY( rulerY );
1276 scrollView.ScrollTo( 15 );
1277 Wait(application, RENDER_DELAY_SCROLL);
1278 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
1280 scrollView.ScrollTo( 3 );
1281 Wait(application, RENDER_DELAY_SCROLL);
1282 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
1284 scrollView.ScrollTo( 9 );
1285 Wait(application, RENDER_DELAY_SCROLL);
1286 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
1291 int UtcDaliToolkitScrollViewSetMaxOvershootP(void)
1293 ToolkitTestApplication application;
1294 tet_infoline(" UtcDaliToolkitScrollViewSetMaxOvershootP");
1296 // Set up a scrollView...
1297 ScrollView scrollView = ScrollView::New();
1298 Stage::GetCurrent().Add( scrollView );
1299 Vector2 stageSize = Stage::GetCurrent().GetSize();
1300 scrollView.SetSize(stageSize);
1301 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1302 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1305 RulerPtr rulerX = new DefaultRuler();
1306 RulerPtr rulerY = new DefaultRuler();
1307 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1308 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1309 scrollView.SetRulerX(rulerX);
1310 scrollView.SetRulerY(rulerY);
1312 // Set the max overshoot to be 50 pixels in both X axis and Y axis
1313 scrollView.SetMaxOvershoot(50.0f, 50.0f);
1315 scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1318 // Scroll page in NW (-20,-20 pixels), then check that overshoot should be 0. (don't release touch)
1319 Vector2 currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 20, false);
1320 float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1321 float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1322 DALI_TEST_EQUALS(overshootXValue, 0.0f, TEST_LOCATION);
1323 DALI_TEST_EQUALS(overshootYValue, 0.0f, TEST_LOCATION);
1325 // Scroll page further in NW (-105,-105 pixels), then check that overshoot should be around 0.5. (don't release touch)
1326 currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 105, false);
1327 overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1328 overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1329 // The overshoot value is a 0.0f - 1.0f ranged value of the amount overshot related to the maximum overshoot.
1330 // EG. If we move 105, max overshoot is 50, then we overshot 50 / 105.
1331 float correctOvershootValue = 50.0f / 105.f;
1332 DALI_TEST_EQUALS( overshootXValue, correctOvershootValue, 0.001f, TEST_LOCATION );
1333 DALI_TEST_EQUALS( overshootYValue, correctOvershootValue, 0.001f, TEST_LOCATION );
1335 // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch)
1336 currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false);
1337 overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1338 overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1339 DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1340 DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1342 // Change the max overshoot to be 100 pixels in both X axis and Y axis
1343 scrollView.SetMaxOvershoot(100.0f, 100.0f);
1346 // Check that overshoot should be now around 0.8.
1347 overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1348 overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1349 DALI_TEST_CHECK(overshootXValue > 0.79f && overshootXValue < 0.81f);
1350 DALI_TEST_CHECK(overshootYValue > 0.79f && overshootYValue < 0.81f);
1352 // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch)
1353 currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false);
1354 overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1355 overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1356 DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1357 DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1362 int UtcDaliToolkitScrollViewSetScrollingDirectionP(void)
1364 ToolkitTestApplication application;
1365 tet_infoline(" UtcDaliToolkitScrollViewSetScrollingDirectionP");
1367 // Set up a scrollView...
1368 ScrollView scrollView = ScrollView::New();
1369 Stage::GetCurrent().Add( scrollView );
1370 Vector2 stageSize = Stage::GetCurrent().GetSize();
1371 scrollView.SetSize(stageSize);
1372 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1373 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1375 Vector2 START_POSITION = Vector2(10.0f, 10.0f);
1377 scrollView.ScrollTo(START_POSITION, 0.0f);
1379 // Try a vertical swipe.
1380 PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1381 // Take into account resampling done when prediction is off.
1382 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION );
1384 scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1386 scrollView.ScrollTo(START_POSITION, 0.0f);
1388 // Try a vertical swipe.
1389 PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1390 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), START_POSITION, TEST_LOCATION );
1392 scrollView.RemoveScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1394 scrollView.ScrollTo(Vector2(10.0f, 10.0f), 0.0f);
1396 // Try a vertical swipe.
1397 PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1398 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION );
1403 int UtcDaliToolkitScrollViewRemoveScrollingDirectionP(void)
1405 ToolkitTestApplication application;
1406 tet_infoline(" UtcDaliToolkitScrollViewRemoveScrollingDirectionP");
1408 // Set up a scrollView...
1409 ScrollView scrollView = ScrollView::New();
1410 Stage::GetCurrent().Add( scrollView );
1411 Vector2 stageSize = Stage::GetCurrent().GetSize();
1412 scrollView.SetSize(stageSize);
1413 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1414 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1416 Vector2 START_POSITION = Vector2(10.0f, 10.0f);
1418 scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1420 scrollView.ScrollTo(START_POSITION, 0.0f);
1422 // Try a vertical swipe.
1423 PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1424 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), START_POSITION, TEST_LOCATION );
1426 scrollView.RemoveScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1428 scrollView.ScrollTo(Vector2(10.0f, 10.0f), 0.0f);
1430 // Try a vertical swipe.
1431 PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1432 // Take into account resampling done when prediction is off.
1433 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition() - Vector2(0.0f, 0.5f), Vector2(10.0f, -50.0f), 0.25f, TEST_LOCATION );
1438 int UtcDaliToolkitScrollViewSetRulerXP(void)
1440 ToolkitTestApplication application;
1441 tet_infoline(" UtcDaliToolkitScrollViewSetRulerXP");
1443 ScrollView scrollView = ScrollView::New();
1444 Stage::GetCurrent().Add( scrollView );
1445 RulerPtr rulerX = new FixedRuler( 100.0f );
1446 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1448 scrollView.SetRulerX( rulerX );
1450 scrollView.ScrollTo( 1, 0.0f );
1452 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 0.0f), TEST_LOCATION );
1454 RulerPtr newRulerX = new FixedRuler( 200.0f );
1455 newRulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1457 scrollView.SetRulerX( newRulerX );
1459 scrollView.ScrollTo( 1, 0.0f );
1461 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(200.0f, 0.0f), TEST_LOCATION );
1466 int UtcDaliToolkitScrollViewSetRulerYP(void)
1468 ToolkitTestApplication application;
1469 tet_infoline(" UtcDaliToolkitScrollViewSetRulerYP");
1471 ScrollView scrollView = ScrollView::New();
1472 Stage::GetCurrent().Add( scrollView );
1474 RulerPtr rulerY = new FixedRuler( 200.0f );
1475 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1477 scrollView.SetRulerY( rulerY );
1479 scrollView.ScrollTo( Vector2(0.0f, 350.0f), 0.0f );
1481 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 350.0f), TEST_LOCATION );
1483 RulerPtr newRulerY = new FixedRuler( 100.0f );
1484 newRulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
1485 scrollView.SetRulerY( newRulerY );
1487 scrollView.ScrollTo( Vector2(0.0f, 350.0f), 0.0f );
1489 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 200.0f), TEST_LOCATION );
1494 int UtcDaliToolkitScrollViewSetMinimumSpeedForFlickP(void)
1496 ToolkitTestApplication application;
1497 tet_infoline(" UtcDaliToolkitScrollViewSetMinimumSpeedForFlickP");
1499 ScrollView scrollView = ScrollView::New();
1500 scrollView.SetMinimumSpeedForFlick(25.0f);
1501 DALI_TEST_EQUALS( scrollView.GetMinimumSpeedForFlick(), 25.0f, TEST_LOCATION );
1502 scrollView.SetMinimumSpeedForFlick(60.0f);
1503 DALI_TEST_EQUALS( scrollView.GetMinimumSpeedForFlick(), 60.0f, TEST_LOCATION );
1507 int UtcDaliToolkitScrollViewSetMinimumDistanceForFlickP(void)
1509 ToolkitTestApplication application;
1510 tet_infoline(" UtcDaliToolkitScrollViewSetMinimumDistanceForFlick");
1512 ScrollView scrollView = ScrollView::New();
1514 scrollView.SetMinimumDistanceForFlick(Vector2(30.0f, 15.0f));
1515 DALI_TEST_EQUALS( scrollView.GetMinimumDistanceForFlick(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1516 scrollView.SetMinimumDistanceForFlick(Vector2(60.0f, 30.0f));
1517 DALI_TEST_EQUALS( scrollView.GetMinimumDistanceForFlick(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1521 int UtcDaliToolkitScrollViewSetWheelScrollDistanceStepP(void)
1523 ToolkitTestApplication application;
1524 tet_infoline(" UtcDaliToolkitScrollViewSetWheelScrollDistanceStepP");
1526 ScrollView scrollView = ScrollView::New();
1527 // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1528 scrollView.SetWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1529 DALI_TEST_EQUALS( scrollView.GetWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1530 scrollView.SetWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1531 DALI_TEST_EQUALS( scrollView.GetWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1535 int UtcDaliToolkitScrollViewApplyEffectP(void)
1537 ToolkitTestApplication application;
1538 tet_infoline(" UtcDaliToolkitScrollViewApplyEffectP");
1540 // Create a ScrollView
1541 ScrollView scrollView = ScrollView::New();
1543 // Create two scroll view effects
1544 Dali::Path path = Dali::Path::New();
1545 ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1546 ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1548 // Apply both effects
1549 scrollView.ApplyEffect(effect);
1550 scrollView.ApplyEffect(newEffect);
1552 DALI_TEST_CHECK( true );
1557 int UtcDaliToolkitScrollViewApplyEffectN(void)
1559 ToolkitTestApplication application;
1560 tet_infoline(" UtcDaliToolkitScrollViewApplyEffectN");
1562 // Create a ScrollView
1563 ScrollView scrollView = ScrollView::New();
1565 // Create two scroll view effects
1566 Dali::Path path = Dali::Path::New();
1567 ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1568 ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1570 // Apply both effects
1571 scrollView.ApplyEffect(effect);
1572 scrollView.ApplyEffect(newEffect);
1574 // Attempt to apply the same effect again
1577 scrollView.ApplyEffect(newEffect);
1578 tet_result( TET_FAIL );
1580 catch ( DaliException& e )
1582 DALI_TEST_ASSERT( e, "!effectAlreadyExistsInScrollView", TEST_LOCATION );
1588 int UtcDaliToolkitScrollViewRemoveEffectP(void)
1590 ToolkitTestApplication application;
1591 tet_infoline(" UtcDaliToolkitScrollViewRemoveEffectP");
1593 // Create a ScrollView
1594 ScrollView scrollView = ScrollView::New();
1596 // Create two scroll view effects
1597 Dali::Path path = Dali::Path::New();
1598 ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1599 ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1601 // Apply both effects
1602 scrollView.ApplyEffect(effect);
1603 scrollView.ApplyEffect(newEffect);
1605 // Remove both effects
1606 scrollView.RemoveEffect(effect);
1607 scrollView.RemoveEffect(newEffect);
1609 DALI_TEST_CHECK( true );
1614 int UtcDaliToolkitScrollViewRemoveEffectN(void)
1616 ToolkitTestApplication application;
1617 tet_infoline(" UtcDaliToolkitScrollViewRemoveEffectN");
1619 // Create a ScrollView
1620 ScrollView scrollView = ScrollView::New();
1622 // Create two scroll view effects
1623 Dali::Path path = Dali::Path::New();
1624 ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1625 ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1627 // Apply the first effect
1628 scrollView.ApplyEffect(effect);
1630 // Attempt to remove the second effect which has not been applied to scroll view
1633 scrollView.RemoveEffect(newEffect);
1634 tet_result( TET_FAIL );
1636 catch ( DaliException& e )
1638 DALI_TEST_ASSERT( e, "effectExistedInScrollView", TEST_LOCATION );
1644 int UtcDaliToolkitScrollViewRemoveAllEffectsP(void)
1646 ToolkitTestApplication application;
1647 tet_infoline(" UtcDaliToolkitScrollViewRemoveAllEffectsP");
1649 // Create a ScrollView
1650 ScrollView scrollView = ScrollView::New();
1652 // Create two scroll view effects
1653 Dali::Path path = Dali::Path::New();
1654 ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1655 ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1657 // Apply both effects
1658 scrollView.ApplyEffect(effect);
1659 scrollView.ApplyEffect(newEffect);
1661 // Attempt to apply the same first effect again
1664 scrollView.ApplyEffect(effect);
1665 tet_result( TET_FAIL );
1667 catch ( DaliException& e )
1669 DALI_TEST_ASSERT( e, "!effectAlreadyExistsInScrollView", TEST_LOCATION );
1672 // Remove both effects
1673 scrollView.RemoveAllEffects();
1675 // Apply both effects again
1676 scrollView.ApplyEffect(effect);
1677 scrollView.ApplyEffect(newEffect);
1679 DALI_TEST_CHECK( true );
1684 int UtcDaliToolkitScrollViewRemoveAllEffectsN(void)
1686 ToolkitTestApplication application;
1687 tet_infoline(" UtcDaliToolkitScrollViewRemoveAllEffectsN");
1689 // Create a ScrollView
1690 ScrollView scrollView = ScrollView::New();
1692 // Remove effects when there is no effect applied previously
1693 scrollView.RemoveAllEffects();
1695 DALI_TEST_CHECK( true );
1700 int UtcDaliToolkitScrollViewSetOvershootEnabledP(void)
1702 ToolkitTestApplication application;
1703 tet_infoline(" UtcDaliToolkitScrollViewSetOvershootEnabledP");
1705 ScrollView scrollView = ScrollView::New();
1707 scrollView.SetOvershootEnabled(true);
1708 DALI_TEST_CHECK(scrollView.IsOvershootEnabled());
1710 scrollView.SetOvershootEnabled(false);
1711 DALI_TEST_CHECK(!scrollView.IsOvershootEnabled());
1716 int UtcDaliToolkitScrollViewSetOvershootEffectColorP(void)
1718 ToolkitTestApplication application;
1719 tet_infoline(" UtcDaliToolkitScrollViewSetOvershootEffectColorP");
1721 ScrollView scrollView = ScrollView::New();
1723 scrollView.SetOvershootEffectColor(Dali::Color::RED);
1724 DALI_TEST_EQUALS(scrollView.GetOvershootEffectColor(), Dali::Color::RED, TEST_LOCATION);
1726 scrollView.SetOvershootEffectColor(Dali::Color::YELLOW);
1727 DALI_TEST_EQUALS(scrollView.GetOvershootEffectColor(), Dali::Color::YELLOW, TEST_LOCATION);
1732 int UtcDaliToolkitScrollViewSetOvershootAnimationSpeedP(void)
1734 ToolkitTestApplication application;
1735 tet_infoline(" UtcDaliToolkitScrollViewSetOvershootAnimationSpeedP");
1737 ScrollView scrollView = ScrollView::New();
1739 scrollView.SetOvershootAnimationSpeed(55.0f);
1740 DALI_TEST_EQUALS(scrollView.GetOvershootAnimationSpeed(), 55.0f, TEST_LOCATION);
1742 scrollView.SetOvershootAnimationSpeed(120.0f);
1743 DALI_TEST_EQUALS(scrollView.GetOvershootAnimationSpeed(), 120.0f, TEST_LOCATION);
1748 int UtcDaliToolkitScrollViewGetSet(void)
1750 ToolkitTestApplication application;
1751 tet_infoline(" UtcDaliToolkitScrollViewGetSet");
1752 ScrollView scrollView = ScrollView::New();
1753 scrollView.SetMaxFlickSpeed(0.5f);
1754 DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1755 scrollView.SetFrictionCoefficient(0.6f);
1756 DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1757 scrollView.SetFlickSpeedCoefficient(0.7f);
1758 DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1762 int UtcDaliToolkitScrollViewRulerDomainConstructorP(void)
1764 ToolkitTestApplication application;
1766 RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1767 DALI_TEST_EQUALS( domainX.min, 0.0f, TEST_LOCATION);
1768 DALI_TEST_EQUALS( domainX.max, 200.0f, TEST_LOCATION);
1769 DALI_TEST_EQUALS( domainX.enabled, true, TEST_LOCATION);
1771 RulerDomain domainY = RulerDomain(100.0f, 500.0f, false);
1772 DALI_TEST_EQUALS( domainY.min, 100.0f, TEST_LOCATION);
1773 DALI_TEST_EQUALS( domainY.max, 500.0f, TEST_LOCATION);
1774 DALI_TEST_EQUALS( domainY.enabled, false, TEST_LOCATION);
1779 int UtcDaliToolkitScrollViewRulerDomainGetSizeP(void)
1781 ToolkitTestApplication application;
1783 RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1784 DALI_TEST_EQUALS( domainX.GetSize(), 200.0f, TEST_LOCATION);
1786 RulerDomain domainY = RulerDomain(100.0f, 500.0f, false);
1787 DALI_TEST_EQUALS( domainY.GetSize(), 400.0f, TEST_LOCATION);
1792 int UtcDaliToolkitScrollViewRulerDomainClampP(void)
1794 ToolkitTestApplication application;
1796 RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1798 float value = domainX.Clamp(50.0f, 100.0f, 1.0f);
1799 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION);
1801 value = domainX.Clamp(300.0f, 20.0f, 1.0f);
1802 DALI_TEST_EQUALS( value, 180.0f, TEST_LOCATION);
1804 value = domainX.Clamp(300.0f, 20.0f, 0.5f);
1805 DALI_TEST_EQUALS( value, 80.0f, TEST_LOCATION);
1807 value = domainX.Clamp(250.0f, 200.0f, 2.0f);
1808 DALI_TEST_EQUALS( value, 200.0f, TEST_LOCATION);
1813 int UtcDaliToolkitScrollViewRulerDomainClampWithStateP(void)
1815 ToolkitTestApplication application;
1817 RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1820 float value = domainX.Clamp(50.0f, 100.0f, 1.0f, clamped);
1821 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION);
1822 DALI_TEST_EQUALS( clamped, Dali::Toolkit::NotClamped, TEST_LOCATION);
1824 value = domainX.Clamp(-100.0f, 200.0f, 1.0f, clamped);
1825 DALI_TEST_EQUALS( value, 0.0f, TEST_LOCATION);
1826 DALI_TEST_EQUALS( clamped, Dali::Toolkit::ClampedToMin, TEST_LOCATION);
1828 value = domainX.Clamp(300.0f, 20.0f, 1.0f, clamped);
1829 DALI_TEST_EQUALS( value, 180.0f, TEST_LOCATION);
1830 DALI_TEST_EQUALS( clamped, Dali::Toolkit::ClampedToMax, TEST_LOCATION);
1835 int UtcDaliToolkitScrollViewDefaultRulerConstructorP(void)
1837 ToolkitTestApplication application;
1838 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerConstructorP");
1840 RulerPtr defaultRuler = new DefaultRuler();
1841 DALI_TEST_CHECK( defaultRuler );
1846 int UtcDaliToolkitScrollViewDefaultRulerDestructorP(void)
1848 ToolkitTestApplication application;
1849 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerDestructorP");
1851 RulerPtr defaultRuler = new DefaultRuler();
1853 DALI_TEST_CHECK( true );
1857 int UtcDaliToolkitScrollViewFixedRulerConstructorP(void)
1859 ToolkitTestApplication application;
1860 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerConstructorP");
1862 RulerPtr fixedRuler = new FixedRuler( 100.0f );
1863 DALI_TEST_CHECK( fixedRuler );
1865 fixedRuler = new FixedRuler( 0.0f );
1866 DALI_TEST_CHECK( fixedRuler );
1871 int UtcDaliToolkitScrollViewFixedRulerDestructorP(void)
1873 ToolkitTestApplication application;
1874 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerDestructorP");
1876 RulerPtr fixedRuler = new FixedRuler( 100.0f );
1878 DALI_TEST_CHECK( true );
1882 int UtcDaliToolkitScrollViewRulerGetTypeP(void)
1884 ToolkitTestApplication application;
1885 tet_infoline(" UtcDaliToolkitScrollViewRulerGetTypeP");
1887 RulerPtr defaultRuler = new DefaultRuler();
1888 DALI_TEST_CHECK( defaultRuler );
1889 DALI_TEST_EQUALS( defaultRuler->GetType(), Dali::Toolkit::Ruler::Free, TEST_LOCATION);
1891 RulerPtr fixedRuler = new FixedRuler( 100.0f );
1892 DALI_TEST_CHECK( fixedRuler );
1893 DALI_TEST_EQUALS( fixedRuler->GetType(), Dali::Toolkit::Ruler::Fixed, TEST_LOCATION);
1898 int UtcDaliToolkitScrollViewRulerGetExtensionP(void)
1900 ToolkitTestApplication application;
1901 tet_infoline(" UtcDaliToolkitScrollViewRulerGetExtensionP");
1903 RulerPtr defaultRuler = new DefaultRuler();
1904 DALI_TEST_CHECK( defaultRuler );
1905 DALI_TEST_CHECK( !defaultRuler->GetExtension() );
1907 RulerPtr fixedRuler = new FixedRuler( 100.0f );
1908 DALI_TEST_CHECK( fixedRuler );
1909 DALI_TEST_CHECK( !fixedRuler->GetExtension() );
1914 int UtcDaliToolkitScrollViewRulerEnableDisable(void)
1916 ToolkitTestApplication application;
1917 tet_infoline(" UtcDaliToolkitScrollViewRulerEnableDisable");
1919 RulerPtr ruler = new DefaultRuler();
1921 DALI_TEST_CHECK( ruler->IsEnabled() );
1923 DALI_TEST_CHECK( !ruler->IsEnabled() );
1925 DALI_TEST_CHECK( ruler->IsEnabled() );
1929 int UtcDaliToolkitScrollViewRulerDomainEnableDisable(void)
1931 ToolkitTestApplication application;
1932 tet_infoline(" UtcDaliToolkitScrollViewRulerDomainEnableDisable");
1934 RulerPtr ruler = new DefaultRuler();
1935 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1937 ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
1938 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
1939 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
1940 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
1942 ruler->DisableDomain();
1943 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1944 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
1945 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
1949 int UtcDaliToolkitScrollViewRulerSnapAndClamp(void)
1951 ToolkitTestApplication application;
1952 tet_infoline(" UtcDaliToolkitScrollViewRulerSnapAndClamp");
1954 RulerPtr ruler = new FixedRuler( 50.0f );
1955 ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1957 // default testing. (snap and clamp)
1958 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
1959 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
1960 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
1961 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
1962 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
1963 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
1966 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1967 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
1968 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1970 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1971 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
1972 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1975 DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
1976 DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
1977 DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
1978 DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
1979 DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
1982 DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
1983 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
1984 DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
1985 DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
1987 // clamp state testing.
1989 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1990 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1991 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1992 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1993 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1994 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1995 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1996 DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
1997 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1998 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1999 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
2000 DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
2004 int UtcDaliToolkitScrollViewFixedRulerGetPositionFromPageP(void)
2006 ToolkitTestApplication application;
2007 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetPositionFromPageP");
2009 RulerPtr rulerNormal = new FixedRuler( 25.0f );
2010 rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
2012 unsigned int volume;
2015 position = rulerNormal->GetPositionFromPage(1, volume, true);
2016 DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
2017 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
2019 position = rulerNormal->GetPositionFromPage(2, volume, true);
2020 DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
2021 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
2023 // Disable the ruler
2024 rulerNormal->Disable();
2026 position = rulerNormal->GetPositionFromPage(1, volume, true);
2027 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
2028 DALI_TEST_EQUALS( volume, 1u, TEST_LOCATION );
2030 position = rulerNormal->GetPositionFromPage(2, volume, true);
2031 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
2032 DALI_TEST_EQUALS( volume, 2u, TEST_LOCATION );
2037 int UtcDaliToolkitScrollViewDefaultRulerGetTotalPagesP(void)
2039 ToolkitTestApplication application;
2040 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetTotalPagesP");
2042 RulerPtr defaultRuler = new DefaultRuler();
2043 DALI_TEST_CHECK( defaultRuler );
2044 DALI_TEST_EQUALS( defaultRuler->GetTotalPages(), 1u, TEST_LOCATION);
2049 int UtcDaliToolkitScrollViewDefaultRulerGetPageFromPositionP(void)
2051 ToolkitTestApplication application;
2052 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetPageFromPositionP");
2054 RulerPtr defaultRuler = new DefaultRuler();
2055 DALI_TEST_CHECK( defaultRuler );
2056 DALI_TEST_EQUALS( defaultRuler->GetPageFromPosition(100.0f, true), 0u, TEST_LOCATION);
2057 DALI_TEST_EQUALS( defaultRuler->GetPageFromPosition(-300.0f, false), 0u, TEST_LOCATION);
2062 int UtcDaliToolkitScrollViewDefaultRulerGetPositionFromPageP(void)
2064 ToolkitTestApplication application;
2065 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetPositionFromPageP");
2067 RulerPtr defaultRuler = new DefaultRuler();
2068 DALI_TEST_CHECK( defaultRuler );
2070 unsigned int volume;
2071 DALI_TEST_EQUALS( defaultRuler->GetPositionFromPage(0, volume, true), 0.0f, TEST_LOCATION);
2072 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION);
2074 DALI_TEST_EQUALS( defaultRuler->GetPositionFromPage(3, volume, false), 0.0f, TEST_LOCATION);
2075 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION);
2080 int UtcDaliToolkitScrollViewDefaultRulerSnapP(void)
2082 ToolkitTestApplication application;
2083 tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerSnapP");
2085 RulerPtr defaultRuler = new DefaultRuler();
2086 DALI_TEST_CHECK( defaultRuler );
2088 DALI_TEST_EQUALS( defaultRuler->Snap(50.0f, 0.5f), 50.0f, TEST_LOCATION);
2089 DALI_TEST_EQUALS( defaultRuler->Snap(-120.0f, 1.0f), -120.0f, TEST_LOCATION);
2094 int UtcDaliToolkitScrollViewFixedRulerGetTotalPagesP(void)
2096 ToolkitTestApplication application;
2097 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetTotalPagesP");
2099 RulerPtr fixedRuler = new FixedRuler( 100.0f );
2100 fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2102 fixedRuler->Enable();
2103 DALI_TEST_EQUALS( fixedRuler->GetTotalPages(), 4u, TEST_LOCATION);
2105 fixedRuler->Disable();
2106 DALI_TEST_EQUALS( fixedRuler->GetTotalPages(), 1u, TEST_LOCATION);
2111 int UtcDaliToolkitScrollViewFixedRulerGetPageFromPositionP(void)
2113 ToolkitTestApplication application;
2114 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetPageFromPositionP");
2116 RulerPtr fixedRuler = new FixedRuler( 100.0f );
2117 fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2119 fixedRuler->Enable();
2120 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 3u, TEST_LOCATION);
2121 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 3u, TEST_LOCATION);
2122 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 1u, TEST_LOCATION);
2123 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2125 fixedRuler->Disable();
2126 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION);
2127 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 0u, TEST_LOCATION);
2128 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION);
2129 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2131 // Set domain size to be smaller than the ruler space
2132 fixedRuler->SetDomain( RulerDomain(0.0f, 50.0f, true) );
2134 fixedRuler->Enable();
2135 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION);
2136 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 3u, TEST_LOCATION);
2137 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION);
2138 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2140 fixedRuler->Disable();
2141 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION);
2142 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 0u, TEST_LOCATION);
2143 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION);
2144 DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2149 int UtcDaliToolkitScrollViewFixedRulerSnapP(void)
2151 ToolkitTestApplication application;
2152 tet_infoline(" UtcDaliToolkitScrollViewFixedRulerSnapP");
2154 RulerPtr fixedRuler = new FixedRuler( 100.0f );
2155 fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2157 DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 0.0f), -100.0f, TEST_LOCATION);
2158 DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 0.0f), -100.0f, TEST_LOCATION);
2159 DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 0.0f), -200.0f, TEST_LOCATION);
2160 DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 0.0f), -500.0f, TEST_LOCATION);
2161 DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 0.0f), 0.0f, TEST_LOCATION);
2162 DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 0.0f), 0.0f, TEST_LOCATION);
2163 DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 0.0f), 0.0f, TEST_LOCATION);
2164 DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 0.0f), 100.0f, TEST_LOCATION);
2165 DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 0.0f), 100.0f, TEST_LOCATION);
2166 DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 0.0f), 200.0f, TEST_LOCATION);
2167 DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 0.0f), 600.0f, TEST_LOCATION);
2169 DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 0.5f), 0.0f, TEST_LOCATION);
2170 DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 0.5f), -100.0f, TEST_LOCATION);
2171 DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 0.5f), -100.0f, TEST_LOCATION);
2172 DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 0.5f), -500.0f, TEST_LOCATION);
2173 DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 0.5f), 0.0f, TEST_LOCATION);
2174 DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 0.5f), 100.0f, TEST_LOCATION);
2175 DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 0.5f), 100.0f, TEST_LOCATION);
2176 DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 0.5f), 100.0f, TEST_LOCATION);
2177 DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 0.5f), 100.0f, TEST_LOCATION);
2178 DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 0.5f), 300.0f, TEST_LOCATION);
2179 DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 0.5f), 600.0f, TEST_LOCATION);
2181 DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 1.0f), 0.0f, TEST_LOCATION);
2182 DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 1.0f), 0.0f, TEST_LOCATION);
2183 DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 1.0f), -100.0f, TEST_LOCATION);
2184 DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 1.0f), -400.0f, TEST_LOCATION);
2185 DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 1.0f), 100.0f, TEST_LOCATION);
2186 DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 1.0f), 100.0f, TEST_LOCATION);
2187 DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 1.0f), 100.0f, TEST_LOCATION);
2188 DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 1.0f), 200.0f, TEST_LOCATION);
2189 DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 1.0f), 200.0f, TEST_LOCATION);
2190 DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 1.0f), 300.0f, TEST_LOCATION);
2191 DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 1.0f), 700.0f, TEST_LOCATION);
2196 int UtcDaliToolkitScrollViewConstraintsMove(void)
2198 ToolkitTestApplication application;
2199 tet_infoline(" UtcDaliToolkitScrollViewConstraintsMove");
2201 // Set up a scrollView...
2202 ScrollView scrollView = ScrollView::New();
2203 Stage::GetCurrent().Add( scrollView );
2204 Vector2 stageSize = Stage::GetCurrent().GetSize();
2205 scrollView.SetSize(stageSize);
2206 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
2207 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2210 RulerPtr rulerX = new DefaultRuler();
2211 RulerPtr rulerY = new DefaultRuler();
2212 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
2213 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
2214 scrollView.SetRulerX(rulerX);
2215 scrollView.SetRulerY(rulerY);
2217 // Add an Actor to ScrollView,
2218 Actor a = Actor::New();
2220 a.SetPosition( TEST_ACTOR_POSITION );
2223 const Vector2 target = Vector2(100.0f, 100.0f);
2224 const Vector2 target2 = Vector2(200.0f, 200.0f);
2226 Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, MoveActorConstraint );
2227 constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
2228 constraint.SetRemoveAction(Constraint::Discard);
2229 scrollView.ApplyConstraintToChildren(constraint);
2231 scrollView.ScrollTo( target, 0.0f );
2233 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
2234 scrollView.ScrollTo( target2 );
2235 Wait(application, RENDER_DELAY_SCROLL);
2236 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
2241 int UtcDaliToolkitScrollViewConstraintsWrap(void)
2243 ToolkitTestApplication application;
2244 tet_infoline(" UtcDaliToolkitScrollViewConstraintsWrap");
2246 // Set up a scrollView...
2247 ScrollView scrollView = ScrollView::New();
2248 Stage::GetCurrent().Add( scrollView );
2249 Vector2 stageSize = Stage::GetCurrent().GetSize();
2250 scrollView.SetSize(stageSize);
2251 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
2252 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2255 RulerPtr rulerX = new DefaultRuler();
2256 RulerPtr rulerY = new DefaultRuler();
2257 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
2258 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
2259 scrollView.SetRulerX(rulerX);
2260 scrollView.SetRulerY(rulerY);
2262 // Add an Actor to ScrollView,
2263 Actor a = Actor::New();
2265 a.SetPosition( TEST_ACTOR_POSITION );
2268 const Vector2 target = Vector2(100.0f, 100.0f);
2269 const Vector2 target2 = Vector2(200.0f, 200.0f);
2271 Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, WrapActorConstraint );
2272 constraint.AddSource( LocalSource( Actor::Property::SCALE ) );
2273 constraint.AddSource( LocalSource( Actor::Property::ANCHOR_POINT ) );
2274 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
2275 constraint.AddSource( Source( scrollView, Toolkit::Scrollable::Property::SCROLL_POSITION_MIN ) );
2276 constraint.AddSource( Source( scrollView, Toolkit::Scrollable::Property::SCROLL_POSITION_MAX ) );
2277 constraint.AddSource( Source( scrollView, Toolkit::ScrollView::Property::WRAP ) );
2278 constraint.SetRemoveAction(Constraint::Discard);
2279 scrollView.ApplyConstraintToChildren(constraint);
2281 scrollView.ScrollTo( target, 0.0f );
2283 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
2284 scrollView.ScrollTo( target2 );
2285 Wait(application, RENDER_DELAY_SCROLL);
2286 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
2291 // Non-API test (so no P or N variant).
2292 int UtcDaliToolkitScrollViewGesturePageLimit(void)
2294 ToolkitTestApplication application;
2295 tet_infoline( " UtcDaliToolkitScrollViewGesturePageLimit" );
2297 // Set up a scrollView.
2298 ScrollView scrollView = ScrollView::New();
2300 // Do not rely on stage size for UTC tests.
2301 Vector2 pageSize( 720.0f, 1280.0f );
2302 scrollView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
2303 scrollView.SetSize( pageSize );
2304 scrollView.SetParentOrigin( ParentOrigin::CENTER );
2305 scrollView.SetAnchorPoint( AnchorPoint::CENTER );
2306 scrollView.SetPosition( 0.0f, 0.0f, 0.0f );
2309 // We set the X ruler to fixed to give us pages to snap to.
2310 Dali::Toolkit::FixedRuler* rulerX = new Dali::Toolkit::FixedRuler( pageSize.width );
2311 // Note: The 3x page width is arbitary, but we need enough to show that we are
2312 // capping page movement by the page limiter, and not the domain.
2313 rulerX->SetDomain( Dali::Toolkit::RulerDomain( 0.0f, pageSize.width * 3.0f, false ) );
2314 Dali::Toolkit::RulerPtr rulerY = new Dali::Toolkit::DefaultRuler();
2316 scrollView.SetRulerX( rulerX );
2317 scrollView.SetRulerY( rulerY );
2319 scrollView.SetWrapMode( false );
2320 scrollView.SetScrollSensitive( true );
2322 Stage::GetCurrent().Add( scrollView );
2324 // Set up a gesture to perform.
2325 Vector2 startPos( 50.0f, 0.0f );
2326 Vector2 direction( -5.0f, 0.0f );
2329 // Force starting position.
2330 scrollView.ScrollTo( startPos, 0.0f );
2331 Wait( application );
2333 // Deliberately skip the "Finished" part of the gesture, so we can read the coordinates before the snap begins.
2334 Vector2 currentPos( PerformGestureDiagonalSwipe( application, startPos, direction, frames - 1, false ) );
2336 // Confirm the final X coord has not moved more than one page from the start X position.
2337 DALI_TEST_GREATER( ( startPos.x + pageSize.width ), scrollView.GetCurrentScrollPosition().x, TEST_LOCATION );
2339 // Finish the gesture and wait for the snap.
2340 currentPos += direction;
2341 SendPan( application, Gesture::Finished, currentPos );
2342 // We add RENDER_FRAME_INTERVAL on to wait for an extra frame (for the last "finished" gesture to complete first.
2343 Wait( application, RENDER_DELAY_SCROLL + RENDER_FRAME_INTERVAL );
2345 // Confirm the final X coord has snapped to exactly one page ahead of the start page.
2346 DALI_TEST_EQUALS( pageSize.width, scrollView.GetCurrentScrollPosition().x, Math::MACHINE_EPSILON_0, TEST_LOCATION );