2 * Copyright (c) 2014 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 Vector3 CLAMP_START_SCROLL_POSITION(30.0f, 100.0f, 0.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 int MAX_FRAMES_TO_TEST_OVERSHOOT = 600; ///< 10 seconds (at 60 frames per second).
69 const Vector3 OVERSHOOT_START_SCROLL_POSITION(100.0f, 100.0f, 0.0f); ///< Scroll start position for the Overshoot tests.
70 const float TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION = 0.05f; ///< a Test duration
71 const float TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION = 1.5f; ///< another Test duration
72 const float TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION = TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * 0.5f; // Same as above, but different alpha function.
73 const float TIME_TOLERANCE = 0.05f; ///< Allow testing tolerance between a 10th of second (+/- 3 frames)
76 // Generate a PanGestureEvent to send to Core
77 Integration::PanGestureEvent GeneratePan(
79 const Vector2& previousPosition,
80 const Vector2& currentPosition,
81 unsigned long timeDelta,
82 unsigned int numberOfTouches = 1)
84 Integration::PanGestureEvent pan(state);
86 pan.previousPosition = previousPosition;
87 pan.currentPosition = currentPosition;
88 pan.timeDelta = timeDelta;
89 pan.numberOfTouches = numberOfTouches;
95 * Helper to generate PanGestureEvent
97 * @param[in] application Application instance
98 * @param[in] state The Gesture State
99 * @param[in] pos The current position of touch.
101 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
105 if( (state == Gesture::Started) ||
106 (state == Gesture::Possible) )
112 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
119 * Simulate time passed by.
121 * @note this will always process at least 1 frame (1/60 sec)
123 * @param application Test application instance
124 * @param duration Time to pass in milliseconds.
125 * @return The actual time passed in milliseconds
127 int Wait(ToolkitTestApplication& application, int duration = 0)
131 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
133 application.SendNotification();
134 application.Render(RENDER_FRAME_INTERVAL);
135 time += RENDER_FRAME_INTERVAL;
143 static bool gOnScrollStartCalled; ///< Whether the OnScrollStart signal was invoked.
144 static bool gOnScrollUpdateCalled; ///< Whether the OnScrollUpdate signal was invoked.
145 static bool gOnScrollCompleteCalled; ///< Whether the OnScrollComplete signal was invoked.
146 static bool gOnScrollClampedCalled; ///< Whether the OnScrollClamped signal was invoked.
147 static bool gOnSnapStartCalled; ///< Whether the OnSnapStart signal was invoked.
148 static ClampState3 gLastClampPosition; ///< Clamping information from OnScrollClampedEvent.
149 static SnapType gLastSnapType; ///< Snaping information from SnapEvent.
150 static Vector3 gConstraintResult; ///< Result from constraint.
153 * Invoked when scrolling starts.
155 * @param[in] position The current scroll position.
157 static void OnScrollStart( const Vector3& position )
159 gOnScrollStartCalled = true;
163 * Invoked when scrolling updates (via dragging)
165 * @param[in] position The current scroll position.
167 static void OnScrollUpdate( const Vector3& position )
169 gOnScrollUpdateCalled = true;
173 * Invoked when scrolling finishes
175 * @param[in] position The current scroll position.
177 static void OnScrollComplete( const Vector3& position )
179 gOnScrollCompleteCalled = true;
183 * Invoked when scrolling clamped.
185 * @param[in] event The position/scale/rotation axes that were clamped.
187 static void OnScrollClamped( const ScrollView::ClampEvent& event )
189 gOnScrollClampedCalled = true;
190 gLastClampPosition = event.position;
194 * Invoked when a snap or flick started.
196 * @param[in] event The type of snap and the target position/scale/rotation.
198 static void OnSnapStart( const ScrollView::SnapEvent& event )
200 gOnSnapStartCalled = true;
201 gLastSnapType = event.type;
207 * Summation of current value, property, and offset.
209 * current' = current + mOffset + property;
211 struct TestSumConstraint
214 * @param[in] offset The offset to be added to current.
216 TestSumConstraint(const Vector3& offset)
222 * @param[in] current The current base value
223 * @param[in] property The property to be added to current.
224 * @return The new current Vector.
226 Vector3 operator()(const Vector3& current)
228 gConstraintResult = current + mOffset;
229 return gConstraintResult;
233 * @param[in] current The current base value
234 * @param[in] property The property to be added to current.
235 * @return The new current Vector.
237 Vector3 operator()(const Vector3& current,
238 const PropertyInput& property)
240 gConstraintResult = current + property.GetVector3() + mOffset;
241 return gConstraintResult;
249 * @param[in] application The application instance
250 * @param[in] scrollView The scrollView instance
251 * @return The time taken for the overshoot to reach origin (zero)
253 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
255 Property::Index overshootPropertyX = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
256 Property::Index overshootPropertyY = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
258 int timeToReachOrigin = -1;
259 for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
261 float overshootXValue = scrollView.GetProperty<float>(overshootPropertyX);
262 float overshootYValue = scrollView.GetProperty<float>(overshootPropertyY);
263 if(overshootXValue == 0.0f && overshootYValue == 0.0f)
268 timeToReachOrigin += Wait(application);
271 return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
275 * y = 2x alpha function, which is clamped between 0.0f - 1.0f
277 * Animations should appear to finish (reach 100% point)
278 * at just half the time of a regular Linear AlphaFunction.
280 * @param[in] progress value (ranges from 0.0f - 1.0f)
281 * @return interpolation value (ranges from 0.0f - 1.0f)
283 float TestAlphaFunction(float progress)
285 return std::min( progress * 2.0f, 1.0f );
288 } // unnamed namespace
291 int UtcDaliScrollViewNew(void)
293 ToolkitTestApplication application;
294 tet_infoline(" UtcDaliScrollViewNew");
296 ScrollView scrollView;
298 DALI_TEST_CHECK( !scrollView );
300 scrollView = ScrollView::New();
302 DALI_TEST_CHECK( scrollView );
304 ScrollView scrollView2(scrollView);
306 DALI_TEST_CHECK( scrollView2 == scrollView );
308 //Additional check to ensure object is created by checking if it's registered
309 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
310 DALI_TEST_CHECK( registry );
312 gObjectCreatedCallBackCalled = false;
313 registry.ObjectCreatedSignal().Connect( &TestCallback );
315 ScrollView scrollView = ScrollView::New();
317 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
321 int UtcDaliScrollViewDownCast(void)
323 ToolkitTestApplication application;
324 tet_infoline(" UtcDaliScrollViewDownCast");
326 ScrollView scrollView = ScrollView::New();
327 BaseHandle handle(scrollView);
329 ScrollView newScrollView = ScrollView::DownCast( handle );
330 DALI_TEST_CHECK( scrollView );
331 DALI_TEST_CHECK( newScrollView == scrollView );
335 int UtcDaliScrollViewScrollToPosition(void)
337 ToolkitTestApplication application;
338 tet_infoline(" UtcDaliScrollViewScrollToPosition");
340 // Create the ScrollView actor
341 ScrollView scrollView = ScrollView::New();
342 Stage::GetCurrent().Add( scrollView );
344 const Vector3 target = Vector3(100.0f, 200.0f, 0.0f);
345 const Vector3 target2 = Vector3(300.0f, 100.0f, 0.0f);
347 scrollView.ScrollTo( target, 0.0f );
349 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
350 scrollView.ScrollTo( target2 );
351 Wait(application, RENDER_DELAY_SCROLL);
352 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
358 int UtcDaliScrollViewScrollToPage(void)
360 ToolkitTestApplication application;
361 tet_infoline(" UtcDaliScrollViewScrollToPage");
363 ScrollView scrollView = ScrollView::New();
364 Stage::GetCurrent().Add( scrollView );
365 RulerPtr rulerX = new FixedRuler( 100.0f );
366 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
367 RulerPtr rulerY = new FixedRuler( 100.0f );
368 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
370 scrollView.SetRulerX( rulerX );
371 scrollView.SetRulerY( rulerY );
373 scrollView.ScrollTo( 1, 0.0f );
375 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
377 scrollView.ScrollTo( 5, 0.0f );
379 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(500.0f, 0.0f, 0.0f), TEST_LOCATION );
381 scrollView.ScrollTo( 10, 0.0f );
383 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(200.0f, 100.0f, 0.0f), TEST_LOCATION );
385 scrollView.ScrollTo( 15, 0.0f );
387 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(700.0f, 100.0f, 0.0f), TEST_LOCATION );
388 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
390 scrollView.ScrollTo( 3 );
391 Wait(application, RENDER_DELAY_SCROLL);
392 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(300.0f, 0.0f, 0.0f), TEST_LOCATION );
393 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
395 scrollView.ScrollTo( 9 );
396 Wait(application, RENDER_DELAY_SCROLL);
397 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 100.0f, 0.0f), TEST_LOCATION );
398 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
400 // Apply DefaultRulers instead and see what happens.
401 rulerX = new DefaultRuler();
402 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
403 rulerY = new DefaultRuler();
404 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
406 scrollView.SetRulerX( rulerX );
407 scrollView.SetRulerY( rulerY );
409 // This time should always scroll to origin (0.0f, 0.0f)
410 scrollView.ScrollTo( 1, 0.0f );
412 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
413 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
419 int UtcDaliScrollViewScrollToActor(void)
421 ToolkitTestApplication application;
422 tet_infoline(" UtcDaliScrollViewScrollToActor");
424 ScrollView scrollView = ScrollView::New();
425 Stage::GetCurrent().Add( scrollView );
427 Actor actorA = Actor::New();
428 const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
429 actorA.SetPosition(positionA);
430 scrollView.Add(actorA);
432 Actor actorB = Actor::New();
433 const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
434 actorB.SetPosition(positionB);
435 scrollView.Add(actorB);
439 scrollView.ScrollTo(actorA, 0.0f);
441 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
444 scrollView.ScrollTo(actorB, 0.0f);
446 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
448 scrollView.ScrollTo(actorA);
449 Wait(application, RENDER_DELAY_SCROLL);
450 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
452 scrollView.ScrollTo(actorB);
453 Wait(application, RENDER_DELAY_SCROLL);
454 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
458 int UtcDaliScrollViewScrollToSnapPoint(void)
460 ToolkitTestApplication application;
461 tet_infoline(" UtcDaliScrollViewScrollToSnapPoint");
463 ScrollView scrollView = ScrollView::New();
464 Stage::GetCurrent().Add( scrollView );
465 RulerPtr rulerX = new FixedRuler( 100.0f );
466 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
467 RulerPtr rulerY = new FixedRuler( 100.0f );
468 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
470 scrollView.SetRulerX( rulerX );
471 scrollView.SetRulerY( rulerY );
473 scrollView.ScrollTo( Vector3(120.0f, 190.0f, 0.0f), 0.0f );
475 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(120.0f, 190.0f, 0.0f), TEST_LOCATION );
477 scrollView.ScrollToSnapPoint();
479 Wait(application, RENDER_DELAY_SCROLL);
480 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 200.0f, 0.0f), TEST_LOCATION );
484 int UtcDaliScrollViewSetScrollUpdateDistance(void)
486 ToolkitTestApplication application;
487 tet_infoline(" UtcDaliScrollViewRefreshInterval");
489 ScrollView scrollView = ScrollView::New();
491 scrollView.SetScrollUpdateDistance(0);
492 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 0, TEST_LOCATION);
493 scrollView.SetScrollUpdateDistance(10);
494 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 10, TEST_LOCATION);
495 scrollView.SetScrollUpdateDistance(1000);
496 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 1000, TEST_LOCATION);
500 int UtcDaliScrollViewWrapMode(void)
502 ToolkitTestApplication application;
503 tet_infoline(" UtcDaliScrollViewWrapMode");
505 ScrollView scrollView = ScrollView::New();
506 Stage::GetCurrent().Add( scrollView );
508 // Position rulers. 4x4 grid.
509 RulerPtr rulerX = new FixedRuler(50.0f);
510 RulerPtr rulerY = new FixedRuler(50.0f);
511 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
512 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
513 scrollView.SetRulerX(rulerX);
514 scrollView.SetRulerY(rulerY);
516 scrollView.SetWrapMode(false);
517 scrollView.ScrollTo(Vector3(225.0f, 125.0f, 0.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
519 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
520 scrollView.SetWrapMode(true);
521 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
525 int UtcDaliScrollViewActorAutoSnap(void)
527 ToolkitTestApplication application;
528 tet_infoline(" UtcDaliScrollViewActorAutoSnap");
530 ScrollView scrollView = ScrollView::New();
531 Stage::GetCurrent().Add( scrollView );
534 RulerPtr rulerX = new DefaultRuler();
535 RulerPtr rulerY = new DefaultRuler();
536 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
537 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
538 scrollView.SetRulerX(rulerX);
539 scrollView.SetRulerY(rulerY);
541 const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
542 Actor a = Actor::New();
544 a.SetPosition(aPosition);
546 const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
547 Actor b = Actor::New();
549 b.SetPosition(bPosition);
551 // Goto a random position, and execute snap (should not move)
552 Vector3 targetScroll = Vector3(500.0f, 500.0f, 0.0f);
553 scrollView.ScrollTo(targetScroll, 0.0f);
555 scrollView.ScrollToSnapPoint();
556 Wait(application, RENDER_DELAY_SCROLL);
557 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
559 // Enable ActorAutoSnap, and now try snapping.
560 scrollView.SetActorAutoSnap(true);
561 scrollView.ScrollToSnapPoint();
562 Wait(application, RENDER_DELAY_SCROLL);
563 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition, TEST_LOCATION );
565 scrollView.ScrollTo(Vector3(0.0f, 0.0f, 0.0f), 0.0f);
567 scrollView.ScrollToSnapPoint();
568 Wait(application, RENDER_DELAY_SCROLL);
569 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition, TEST_LOCATION );
573 int UtcDaliScrollViewSignalsStartComplete(void)
575 ToolkitTestApplication application;
576 tet_infoline(" UtcDaliScrollViewSignalsStartComplete");
578 gOnScrollStartCalled = false;
579 gOnScrollCompleteCalled = false;
581 ScrollView scrollView = ScrollView::New();
582 Stage::GetCurrent().Add( scrollView );
585 RulerPtr rulerX = new DefaultRuler();
586 RulerPtr rulerY = new DefaultRuler();
587 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
588 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
589 scrollView.SetRulerX(rulerX);
590 scrollView.SetRulerY(rulerY);
591 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
592 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
593 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
594 scrollView.ScrollTo( Vector3(100.0f, 100.0f, 0.0f) );
595 Wait(application, RENDER_DELAY_SCROLL);
597 DALI_TEST_CHECK(gOnScrollStartCalled);
598 DALI_TEST_CHECK(gOnScrollCompleteCalled);
602 int UtcDaliScrollViewSignalsUpdate(void)
604 ToolkitTestApplication application;
605 tet_infoline(" UtcDaliScrollViewSignalsUpdate");
607 gOnScrollStartCalled = false;
608 gOnScrollUpdateCalled = false;
609 gOnScrollCompleteCalled = false;
611 ScrollView scrollView = ScrollView::New();
612 Stage::GetCurrent().Add( scrollView );
613 Vector2 stageSize = Stage::GetCurrent().GetSize();
614 scrollView.SetSize(stageSize);
615 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
616 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
619 RulerPtr rulerX = new DefaultRuler();
620 RulerPtr rulerY = new DefaultRuler();
621 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
622 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
623 scrollView.SetRulerX(rulerX);
624 scrollView.SetRulerY(rulerY);
625 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
626 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
627 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
629 ImageActor image = CreateSolidColorActor( Color::RED );
630 image.SetSize(stageSize);
631 image.SetParentOrigin(ParentOrigin::TOP_LEFT);
632 image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
633 scrollView.Add(image);
637 // Do a pan starting from 100,100 and moving down diagonally.
638 Vector2 pos(100.0f, 100.0f);
639 SendPan(application, Gesture::Possible, pos);
640 SendPan(application, Gesture::Started, pos);
643 Wait(application, 100);
645 for(int i = 0;i<20;i++)
647 SendPan(application, Gesture::Continuing, pos);
653 SendPan(application, Gesture::Finished, pos);
654 Wait(application, RENDER_DELAY_SCROLL);
656 DALI_TEST_CHECK(gOnScrollStartCalled);
657 DALI_TEST_CHECK(gOnScrollUpdateCalled);
658 DALI_TEST_CHECK(gOnScrollCompleteCalled);
662 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
664 gOnScrollStartCalled = false;
665 gOnScrollUpdateCalled = false;
666 gOnScrollCompleteCalled = false;
667 gOnSnapStartCalled = false;
669 // Now do a pan starting from (start) and heading (direction)
671 SendPan(application, Gesture::Possible, pos);
672 SendPan(application, Gesture::Started, pos);
675 for(int i = 0;i<frames;i++)
677 pos += direction; // Move in this direction
678 SendPan(application, Gesture::Continuing, pos);
684 pos += direction; // Move in this direction.
685 SendPan(application, Gesture::Finished, pos);
686 Wait(application, RENDER_DELAY_SCROLL);
692 int UtcDaliScrollViewScrollSensitive(void)
694 ToolkitTestApplication application;
695 tet_infoline(" UtcDaliScrollViewScrollSensitive");
697 // Set up a scrollView...
698 ScrollView scrollView = ScrollView::New();
699 Stage::GetCurrent().Add( scrollView );
700 Vector2 stageSize = Stage::GetCurrent().GetSize();
701 scrollView.SetSize(stageSize);
702 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
703 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
706 RulerPtr rulerX = new DefaultRuler();
707 RulerPtr rulerY = new DefaultRuler();
708 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
709 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
710 scrollView.SetRulerX(rulerX);
711 scrollView.SetRulerY(rulerY);
712 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
713 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
714 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
715 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
717 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
720 // First try insensitive swipe.
721 scrollView.SetScrollSensitive(false);
722 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
724 DALI_TEST_CHECK( !gOnScrollStartCalled );
725 DALI_TEST_CHECK( !gOnScrollCompleteCalled );
726 DALI_TEST_CHECK( !gOnSnapStartCalled );
728 // Second try sensitive swipe.
729 scrollView.SetScrollSensitive(true);
730 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
732 DALI_TEST_CHECK( gOnScrollStartCalled );
733 DALI_TEST_CHECK( gOnScrollCompleteCalled );
734 DALI_TEST_CHECK( gOnSnapStartCalled );
738 int UtcDaliScrollViewTouchesRequired(void)
740 ToolkitTestApplication application;
741 tet_infoline(" UtcDaliScrollViewTouchesRequired");
743 // Set up a scrollView...
744 ScrollView scrollView = ScrollView::New();
745 Stage::GetCurrent().Add( scrollView );
746 Vector2 stageSize = Stage::GetCurrent().GetSize();
747 scrollView.SetSize(stageSize);
748 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
749 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
752 RulerPtr rulerX = new DefaultRuler();
753 RulerPtr rulerY = new DefaultRuler();
754 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
755 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
756 scrollView.SetRulerX(rulerX);
757 scrollView.SetRulerY(rulerY);
758 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
759 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
760 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
761 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
763 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
766 // First try touches required being a minimum and maximum of 2.
767 scrollView.SetTouchesRequiredForPanning(2, 2, true);
768 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
770 DALI_TEST_CHECK( !gOnScrollStartCalled );
771 DALI_TEST_CHECK( !gOnScrollUpdateCalled );
772 DALI_TEST_CHECK( !gOnScrollCompleteCalled );
773 DALI_TEST_CHECK( !gOnSnapStartCalled );
775 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
778 // Second try touches required being a minimum and maximum of 1.
779 scrollView.SetTouchesRequiredForPanning(1, 1, true);
780 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT * 0.1f, CLAMP_GESTURE_FRAMES * 0.1f, true);
782 DALI_TEST_CHECK( gOnScrollStartCalled );
783 DALI_TEST_CHECK( gOnScrollUpdateCalled );
784 DALI_TEST_CHECK( gOnScrollCompleteCalled );
785 DALI_TEST_CHECK( gOnSnapStartCalled );
789 int UtcDaliScrollViewAxisAutoLock(void)
791 ToolkitTestApplication application;
792 tet_infoline(" UtcDaliScrollViewAxisAutoLock");
794 // Set up a scrollView...
795 ScrollView scrollView = ScrollView::New();
796 Stage::GetCurrent().Add( scrollView );
797 Vector2 stageSize = Stage::GetCurrent().GetSize();
798 scrollView.SetSize(stageSize);
799 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
800 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
803 RulerPtr rulerX = new DefaultRuler();
804 RulerPtr rulerY = new DefaultRuler();
805 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
806 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
807 scrollView.SetRulerX(rulerX);
808 scrollView.SetRulerY(rulerY);
809 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
810 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
811 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
814 scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
816 Vector3 startPosition = scrollView.GetCurrentScrollPosition();
817 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
818 const Vector3 positionAfterNormal = scrollView.GetCurrentScrollPosition();
821 scrollView.SetAxisAutoLock(true);
822 DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
824 scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
826 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
827 const Vector3 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
829 // compare how much the Y position has deviated for normal and autolock.
830 const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
831 const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
833 // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
834 DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
836 scrollView.SetAxisAutoLock(false);
837 DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
841 int UtcDaliScrollViewAxisAutoLockGradient(void)
843 ToolkitTestApplication application;
844 tet_infoline(" UtcDaliScrollViewAxisAutoLockGradient");
846 // Set up a scrollView...
847 ScrollView scrollView = ScrollView::New();
848 scrollView.SetAxisAutoLockGradient(0.5f);
849 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
850 scrollView.SetAxisAutoLockGradient(1.0f);
851 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
855 int UtcDaliScrollViewConstraints(void)
857 ToolkitTestApplication application;
858 tet_infoline(" UtcDaliScrollViewConstraints");
860 // Set up a scrollView...
861 ScrollView scrollView = ScrollView::New();
862 Stage::GetCurrent().Add( scrollView );
863 Vector2 stageSize = Stage::GetCurrent().GetSize();
864 scrollView.SetSize(stageSize);
865 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
866 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
869 RulerPtr rulerX = new DefaultRuler();
870 RulerPtr rulerY = new DefaultRuler();
871 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
872 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
873 scrollView.SetRulerX(rulerX);
874 scrollView.SetRulerY(rulerY);
876 // Add an Actor to ScrollView,
877 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
878 gConstraintResult = Vector3::ZERO;
879 Actor a = Actor::New();
881 a.SetPosition( TEST_ACTOR_POSITION );
884 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
885 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
886 Source(scrollView, scrollPositionProperty),
887 TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
888 constraint.SetRemoveAction(Constraint::Discard);
889 scrollView.ApplyConstraintToChildren(constraint);
892 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
894 gConstraintResult = Vector3::ZERO;
895 scrollView.RemoveConstraintsFromChildren();
898 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
902 int UtcDaliScrollViewBind(void)
904 ToolkitTestApplication application;
905 tet_infoline(" UtcDaliScrollViewBind");
907 // Set up a scrollView...
908 ScrollView scrollView = ScrollView::New();
909 Stage::GetCurrent().Add( scrollView );
910 Vector2 stageSize = Stage::GetCurrent().GetSize();
911 scrollView.SetSize(stageSize);
912 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
913 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
916 RulerPtr rulerX = new DefaultRuler();
917 RulerPtr rulerY = new DefaultRuler();
918 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
919 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
920 scrollView.SetRulerX(rulerX);
921 scrollView.SetRulerY(rulerY);
923 // Add an Actor to ScrollView,
924 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
926 gConstraintResult = Vector3::ZERO;
927 Actor a = Actor::New();
929 a.SetPosition( TEST_ACTOR_POSITION );
932 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
933 // apply this constraint to scrollview
934 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
935 Source(scrollView, scrollPositionProperty),
936 TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
938 constraint.SetRemoveAction(Constraint::Discard);
939 scrollView.ApplyConstraintToChildren(constraint);
943 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
946 gConstraintResult = Vector3::ZERO;
947 scrollView.UnbindActor( a );
949 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
952 gConstraintResult = Vector3::ZERO;
953 scrollView.BindActor( a );
955 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
959 int UtcDaliRulerEnableDisable(void)
961 ToolkitTestApplication application;
962 tet_infoline(" UtcDaliRulerEnableDisable");
964 RulerPtr ruler = new DefaultRuler();
966 DALI_TEST_CHECK( ruler->IsEnabled() );
968 DALI_TEST_CHECK( !ruler->IsEnabled() );
970 DALI_TEST_CHECK( ruler->IsEnabled() );
974 int UtcDaliRulerDomainEnableDisable(void)
976 ToolkitTestApplication application;
977 tet_infoline(" UtcDaliRulerDomainEnableDisable");
979 RulerPtr ruler = new DefaultRuler();
980 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
983 ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
984 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
985 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
986 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
988 ruler->DisableDomain();
989 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
990 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
991 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
995 int UtcDaliRulerSnapAndClamp(void)
997 ToolkitTestApplication application;
998 tet_infoline(" UtcDaliRulerSnapAndClamp");
1000 RulerPtr ruler = new FixedRuler( 50.0f );
1001 ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1003 // default testing. (snap and clamp)
1004 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
1005 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
1006 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
1007 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
1008 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
1009 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
1012 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1013 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
1014 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1016 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1017 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
1018 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1021 DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
1022 DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
1023 DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
1024 DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
1025 DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
1028 DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
1029 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
1030 DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
1031 DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
1033 // clamp state testing.
1035 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1036 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1037 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1038 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1039 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1040 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1041 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1042 DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
1043 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1044 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1045 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1046 DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
1050 int UtcDaliRulerFixedRulerSpacing(void)
1052 ToolkitTestApplication application;
1053 tet_infoline(" UtcDaliRulerFixedRulerSpacing");
1055 RulerPtr rulerZero = new FixedRuler( 0.0f );
1056 rulerZero->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1058 RulerPtr rulerNormal = new FixedRuler( 25.0f );
1059 rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1061 unsigned int volume;
1064 position = rulerZero->GetPositionFromPage(1, volume, true);
1065 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1066 DALI_TEST_EQUALS( volume, 1u, TEST_LOCATION );
1068 position = rulerNormal->GetPositionFromPage(1, volume, true);
1069 DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
1070 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1072 position = rulerZero->GetPositionFromPage(2, volume, true);
1073 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1074 DALI_TEST_EQUALS( volume, 2u, TEST_LOCATION );
1076 position = rulerNormal->GetPositionFromPage(2, volume, true);
1077 DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
1078 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1082 int UtcDaliScrollViewOvershoot(void)
1084 ToolkitTestApplication application;
1085 tet_infoline(" UtcDaliScrollViewOvershoot");
1087 // Set up a scrollView...
1088 ScrollView scrollView = ScrollView::New();
1089 Stage::GetCurrent().Add( scrollView );
1090 Vector2 stageSize = Stage::GetCurrent().GetSize();
1091 scrollView.SetSize(stageSize);
1092 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1093 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1096 RulerPtr rulerX = new DefaultRuler();
1097 RulerPtr rulerY = new DefaultRuler();
1098 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1099 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1100 scrollView.SetRulerX(rulerX);
1101 scrollView.SetRulerY(rulerY);
1102 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1103 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1104 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1106 scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1109 // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1110 Vector2 currentPos = Vector2(100.0f, 100.0f);
1111 currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1112 Property::Index overshootXProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
1113 Property::Index overshootYProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
1114 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
1115 float overshootXValue = scrollView.GetProperty<float>(overshootXProperty);
1116 float overshootYValue = scrollView.GetProperty<float>(overshootYProperty);
1117 Vector3 positionValue = scrollView.GetProperty<Vector3>(scrollPositionProperty);
1118 DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1119 DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1120 DALI_TEST_EQUALS(positionValue, Vector3::ZERO, TEST_LOCATION);
1122 float timeToReachOrigin;
1124 // Now release touch. Overshoot should snap back to zero.
1125 SendPan(application, Gesture::Finished, currentPos);
1126 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1128 DALI_TEST_CHECK( (timeToReachOrigin > Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1129 (timeToReachOrigin < Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1131 // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1132 scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1134 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1135 // Now release touch. Overshoot should snap back to zero.
1136 SendPan(application, Gesture::Finished, currentPos);
1137 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1139 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1140 (timeToReachOrigin < TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1142 // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1143 scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1145 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1146 // Now release touch. Overshoot should snap back to zero.
1147 SendPan(application, Gesture::Finished, currentPos);
1148 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1150 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1151 (timeToReachOrigin < TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1153 // 4. Repeat Scroll, but this time change overshoot function.
1154 scrollView.SetSnapOvershootDuration(TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION);
1155 scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
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 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1163 (timeToReachOrigin < TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1167 int UtcDaliScrollViewSnapAlphaFunction(void)
1169 ToolkitTestApplication application;
1170 tet_infoline(" UtcDaliScrollViewSnapAlphaFunction");
1172 // Set up a scrollView...
1173 ScrollView scrollView = ScrollView::New();
1174 scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseIn );
1175 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseIn );
1176 scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseOut );
1177 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseOut );
1179 scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::Bounce );
1180 DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::Bounce );
1181 scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::BounceBack );
1182 DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::BounceBack );
1186 int UtcDaliScrollViewSnapDuration(void)
1188 ToolkitTestApplication application;
1189 tet_infoline(" UtcDaliScrollViewSnapDuration");
1191 // Set up a scrollView...
1192 ScrollView scrollView = ScrollView::New();
1193 scrollView.SetScrollSnapDuration( 1.0f );
1194 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1195 scrollView.SetScrollSnapDuration( 0.5f );
1196 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1198 scrollView.SetScrollFlickDuration( 2.0f );
1199 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1200 scrollView.SetScrollFlickDuration( 1.5f );
1201 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1205 int UtcDaliScrollViewSignalsSnapStart(void)
1207 ToolkitTestApplication application;
1208 tet_infoline(" UtcDaliScrollViewSignalsSnapStart");
1210 // Set up a scrollView...
1211 ScrollView scrollView = ScrollView::New();
1212 Stage::GetCurrent().Add( scrollView );
1213 Vector2 stageSize = Stage::GetCurrent().GetSize();
1214 scrollView.SetSize(stageSize);
1215 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1216 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1219 RulerPtr rulerX = new DefaultRuler();
1220 RulerPtr rulerY = new DefaultRuler();
1221 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1222 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1223 scrollView.SetRulerX(rulerX);
1224 scrollView.SetRulerY(rulerY);
1225 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1227 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1230 // First try a snap.
1231 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1233 DALI_TEST_CHECK( gOnSnapStartCalled );
1234 DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1236 // Second try a swipe.
1237 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1239 DALI_TEST_CHECK( gOnSnapStartCalled );
1240 DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1245 int UtcDaliScrollViewSetMouseWheelScrollDistanceStep(void)
1247 ToolkitTestApplication application;
1248 tet_infoline(" UtcDaliScrollViewSetMouseWheelScrollDistanceStep");
1250 ScrollView scrollView = ScrollView::New();
1251 // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1252 scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1253 DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1254 scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1255 DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1259 int UtcDaliScrollViewGetSet(void)
1261 ToolkitTestApplication application;
1262 tet_infoline(" UtcDaliScrollViewGetSet");
1263 ScrollView scrollView = ScrollView::New();
1264 scrollView.SetMaxOvershoot(50.0f, 50.0f);
1265 scrollView.SetMaxFlickSpeed(0.5f);
1266 DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1267 scrollView.SetFrictionCoefficient(0.6f);
1268 DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1269 scrollView.SetFlickSpeedCoefficient(0.7f);
1270 DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);