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 gOnSnapStartCalled; ///< Whether the OnSnapStart signal was invoked.
147 static SnapType gLastSnapType; ///< Snaping information from SnapEvent.
148 static Vector3 gConstraintResult; ///< Result from constraint.
151 * Invoked when scrolling starts.
153 * @param[in] position The current scroll position.
155 static void OnScrollStart( const Vector3& position )
157 gOnScrollStartCalled = true;
161 * Invoked when scrolling updates (via dragging)
163 * @param[in] position The current scroll position.
165 static void OnScrollUpdate( const Vector3& position )
167 gOnScrollUpdateCalled = true;
171 * Invoked when scrolling finishes
173 * @param[in] position The current scroll position.
175 static void OnScrollComplete( const Vector3& position )
177 gOnScrollCompleteCalled = true;
181 * Invoked when a snap or flick started.
183 * @param[in] event The type of snap and the target position/scale/rotation.
185 static void OnSnapStart( const ScrollView::SnapEvent& event )
187 gOnSnapStartCalled = true;
188 gLastSnapType = event.type;
194 * Summation of current value, property, and offset.
196 * current' = current + mOffset + property;
198 struct TestSumConstraint
201 * @param[in] offset The offset to be added to current.
203 TestSumConstraint(const Vector3& offset)
209 * @param[in] current The current base value
210 * @param[in] property The property to be added to current.
211 * @return The new current Vector.
213 Vector3 operator()(const Vector3& current)
215 gConstraintResult = current + mOffset;
216 return gConstraintResult;
220 * @param[in] current The current base value
221 * @param[in] property The property to be added to current.
222 * @return The new current Vector.
224 Vector3 operator()(const Vector3& current,
225 const PropertyInput& property)
227 gConstraintResult = current + property.GetVector3() + mOffset;
228 return gConstraintResult;
236 * @param[in] application The application instance
237 * @param[in] scrollView The scrollView instance
238 * @return The time taken for the overshoot to reach origin (zero)
240 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
242 Property::Index overshootPropertyX = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
243 Property::Index overshootPropertyY = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
245 int timeToReachOrigin = -1;
246 for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
248 float overshootXValue = scrollView.GetProperty<float>(overshootPropertyX);
249 float overshootYValue = scrollView.GetProperty<float>(overshootPropertyY);
250 if(overshootXValue == 0.0f && overshootYValue == 0.0f)
255 timeToReachOrigin += Wait(application);
258 return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
262 * y = 2x alpha function, which is clamped between 0.0f - 1.0f
264 * Animations should appear to finish (reach 100% point)
265 * at just half the time of a regular Linear AlphaFunction.
267 * @param[in] progress value (ranges from 0.0f - 1.0f)
268 * @return interpolation value (ranges from 0.0f - 1.0f)
270 float TestAlphaFunction(float progress)
272 return std::min( progress * 2.0f, 1.0f );
275 } // unnamed namespace
278 int UtcDaliScrollViewNew(void)
280 ToolkitTestApplication application;
281 tet_infoline(" UtcDaliScrollViewNew");
283 ScrollView scrollView;
285 DALI_TEST_CHECK( !scrollView );
287 scrollView = ScrollView::New();
289 DALI_TEST_CHECK( scrollView );
291 ScrollView scrollView2(scrollView);
293 DALI_TEST_CHECK( scrollView2 == scrollView );
295 //Additional check to ensure object is created by checking if it's registered
296 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
297 DALI_TEST_CHECK( registry );
299 gObjectCreatedCallBackCalled = false;
300 registry.ObjectCreatedSignal().Connect( &TestCallback );
302 ScrollView scrollView = ScrollView::New();
304 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
308 int UtcDaliScrollViewDownCast(void)
310 ToolkitTestApplication application;
311 tet_infoline(" UtcDaliScrollViewDownCast");
313 ScrollView scrollView = ScrollView::New();
314 BaseHandle handle(scrollView);
316 ScrollView newScrollView = ScrollView::DownCast( handle );
317 DALI_TEST_CHECK( scrollView );
318 DALI_TEST_CHECK( newScrollView == scrollView );
322 int UtcDaliScrollViewScrollToPosition(void)
324 ToolkitTestApplication application;
325 tet_infoline(" UtcDaliScrollViewScrollToPosition");
327 // Create the ScrollView actor
328 ScrollView scrollView = ScrollView::New();
329 Stage::GetCurrent().Add( scrollView );
331 const Vector3 target = Vector3(100.0f, 200.0f, 0.0f);
332 const Vector3 target2 = Vector3(300.0f, 100.0f, 0.0f);
334 scrollView.ScrollTo( target, 0.0f );
336 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
337 scrollView.ScrollTo( target2 );
338 Wait(application, RENDER_DELAY_SCROLL);
339 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
345 int UtcDaliScrollViewScrollToPage(void)
347 ToolkitTestApplication application;
348 tet_infoline(" UtcDaliScrollViewScrollToPage");
350 ScrollView scrollView = ScrollView::New();
351 Stage::GetCurrent().Add( scrollView );
352 RulerPtr rulerX = new FixedRuler( 100.0f );
353 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
354 RulerPtr rulerY = new FixedRuler( 100.0f );
355 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
357 scrollView.SetRulerX( rulerX );
358 scrollView.SetRulerY( rulerY );
360 scrollView.ScrollTo( 1, 0.0f );
362 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
364 scrollView.ScrollTo( 5, 0.0f );
366 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(500.0f, 0.0f, 0.0f), TEST_LOCATION );
368 scrollView.ScrollTo( 10, 0.0f );
370 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(200.0f, 100.0f, 0.0f), TEST_LOCATION );
372 scrollView.ScrollTo( 15, 0.0f );
374 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(700.0f, 100.0f, 0.0f), TEST_LOCATION );
375 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
377 scrollView.ScrollTo( 3 );
378 Wait(application, RENDER_DELAY_SCROLL);
379 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(300.0f, 0.0f, 0.0f), TEST_LOCATION );
380 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
382 scrollView.ScrollTo( 9 );
383 Wait(application, RENDER_DELAY_SCROLL);
384 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 100.0f, 0.0f), TEST_LOCATION );
385 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
387 // Apply DefaultRulers instead and see what happens.
388 rulerX = new DefaultRuler();
389 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
390 rulerY = new DefaultRuler();
391 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
393 scrollView.SetRulerX( rulerX );
394 scrollView.SetRulerY( rulerY );
396 // This time should always scroll to origin (0.0f, 0.0f)
397 scrollView.ScrollTo( 1, 0.0f );
399 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
400 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
406 int UtcDaliScrollViewScrollToActor(void)
408 ToolkitTestApplication application;
409 tet_infoline(" UtcDaliScrollViewScrollToActor");
411 ScrollView scrollView = ScrollView::New();
412 Stage::GetCurrent().Add( scrollView );
414 Actor actorA = Actor::New();
415 const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
416 actorA.SetPosition(positionA);
417 scrollView.Add(actorA);
419 Actor actorB = Actor::New();
420 const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
421 actorB.SetPosition(positionB);
422 scrollView.Add(actorB);
426 scrollView.ScrollTo(actorA, 0.0f);
428 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
431 scrollView.ScrollTo(actorB, 0.0f);
433 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
435 scrollView.ScrollTo(actorA);
436 Wait(application, RENDER_DELAY_SCROLL);
437 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
439 scrollView.ScrollTo(actorB);
440 Wait(application, RENDER_DELAY_SCROLL);
441 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
445 int UtcDaliScrollViewScrollToSnapPoint(void)
447 ToolkitTestApplication application;
448 tet_infoline(" UtcDaliScrollViewScrollToSnapPoint");
450 ScrollView scrollView = ScrollView::New();
451 Stage::GetCurrent().Add( scrollView );
452 RulerPtr rulerX = new FixedRuler( 100.0f );
453 rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
454 RulerPtr rulerY = new FixedRuler( 100.0f );
455 rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
457 scrollView.SetRulerX( rulerX );
458 scrollView.SetRulerY( rulerY );
460 scrollView.ScrollTo( Vector3(120.0f, 190.0f, 0.0f), 0.0f );
462 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(120.0f, 190.0f, 0.0f), TEST_LOCATION );
464 scrollView.ScrollToSnapPoint();
466 Wait(application, RENDER_DELAY_SCROLL);
467 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 200.0f, 0.0f), TEST_LOCATION );
471 int UtcDaliScrollViewSetScrollUpdateDistance(void)
473 ToolkitTestApplication application;
474 tet_infoline(" UtcDaliScrollViewRefreshInterval");
476 ScrollView scrollView = ScrollView::New();
478 scrollView.SetScrollUpdateDistance(0);
479 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 0, TEST_LOCATION);
480 scrollView.SetScrollUpdateDistance(10);
481 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 10, TEST_LOCATION);
482 scrollView.SetScrollUpdateDistance(1000);
483 DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 1000, TEST_LOCATION);
487 int UtcDaliScrollViewWrapMode(void)
489 ToolkitTestApplication application;
490 tet_infoline(" UtcDaliScrollViewWrapMode");
492 ScrollView scrollView = ScrollView::New();
493 Stage::GetCurrent().Add( scrollView );
495 // Position rulers. 4x4 grid.
496 RulerPtr rulerX = new FixedRuler(50.0f);
497 RulerPtr rulerY = new FixedRuler(50.0f);
498 rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
499 rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
500 scrollView.SetRulerX(rulerX);
501 scrollView.SetRulerY(rulerY);
503 scrollView.SetWrapMode(false);
504 scrollView.ScrollTo(Vector3(225.0f, 125.0f, 0.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
506 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
507 scrollView.SetWrapMode(true);
508 DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
512 int UtcDaliScrollViewActorAutoSnap(void)
514 ToolkitTestApplication application;
515 tet_infoline(" UtcDaliScrollViewActorAutoSnap");
517 ScrollView scrollView = ScrollView::New();
518 Stage::GetCurrent().Add( scrollView );
521 RulerPtr rulerX = new DefaultRuler();
522 RulerPtr rulerY = new DefaultRuler();
523 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
524 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
525 scrollView.SetRulerX(rulerX);
526 scrollView.SetRulerY(rulerY);
528 const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
529 Actor a = Actor::New();
531 a.SetPosition(aPosition);
533 const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
534 Actor b = Actor::New();
536 b.SetPosition(bPosition);
538 // Goto a random position, and execute snap (should not move)
539 Vector3 targetScroll = Vector3(500.0f, 500.0f, 0.0f);
540 scrollView.ScrollTo(targetScroll, 0.0f);
542 scrollView.ScrollToSnapPoint();
543 Wait(application, RENDER_DELAY_SCROLL);
544 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
546 // Enable ActorAutoSnap, and now try snapping.
547 scrollView.SetActorAutoSnap(true);
548 scrollView.ScrollToSnapPoint();
549 Wait(application, RENDER_DELAY_SCROLL);
550 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition, TEST_LOCATION );
552 scrollView.ScrollTo(Vector3(0.0f, 0.0f, 0.0f), 0.0f);
554 scrollView.ScrollToSnapPoint();
555 Wait(application, RENDER_DELAY_SCROLL);
556 DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition, TEST_LOCATION );
560 int UtcDaliScrollViewSignalsStartComplete(void)
562 ToolkitTestApplication application;
563 tet_infoline(" UtcDaliScrollViewSignalsStartComplete");
565 gOnScrollStartCalled = false;
566 gOnScrollCompleteCalled = false;
568 ScrollView scrollView = ScrollView::New();
569 Stage::GetCurrent().Add( scrollView );
572 RulerPtr rulerX = new DefaultRuler();
573 RulerPtr rulerY = new DefaultRuler();
574 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
575 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
576 scrollView.SetRulerX(rulerX);
577 scrollView.SetRulerY(rulerY);
578 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
579 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
580 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
581 scrollView.ScrollTo( Vector3(100.0f, 100.0f, 0.0f) );
582 Wait(application, RENDER_DELAY_SCROLL);
584 DALI_TEST_CHECK(gOnScrollStartCalled);
585 DALI_TEST_CHECK(gOnScrollCompleteCalled);
589 int UtcDaliScrollViewSignalsUpdate(void)
591 ToolkitTestApplication application;
592 tet_infoline(" UtcDaliScrollViewSignalsUpdate");
594 gOnScrollStartCalled = false;
595 gOnScrollUpdateCalled = false;
596 gOnScrollCompleteCalled = false;
598 ScrollView scrollView = ScrollView::New();
599 Stage::GetCurrent().Add( scrollView );
600 Vector2 stageSize = Stage::GetCurrent().GetSize();
601 scrollView.SetSize(stageSize);
602 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
603 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
606 RulerPtr rulerX = new DefaultRuler();
607 RulerPtr rulerY = new DefaultRuler();
608 rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
609 rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
610 scrollView.SetRulerX(rulerX);
611 scrollView.SetRulerY(rulerY);
612 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
613 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
614 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
616 ImageActor image = CreateSolidColorActor( Color::RED );
617 image.SetSize(stageSize);
618 image.SetParentOrigin(ParentOrigin::TOP_LEFT);
619 image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
620 scrollView.Add(image);
624 // Do a pan starting from 100,100 and moving down diagonally.
625 Vector2 pos(100.0f, 100.0f);
626 SendPan(application, Gesture::Possible, pos);
627 SendPan(application, Gesture::Started, pos);
630 Wait(application, 100);
632 for(int i = 0;i<20;i++)
634 SendPan(application, Gesture::Continuing, pos);
640 SendPan(application, Gesture::Finished, pos);
641 Wait(application, RENDER_DELAY_SCROLL);
643 DALI_TEST_CHECK(gOnScrollStartCalled);
644 DALI_TEST_CHECK(gOnScrollUpdateCalled);
645 DALI_TEST_CHECK(gOnScrollCompleteCalled);
649 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
651 gOnScrollStartCalled = false;
652 gOnScrollUpdateCalled = false;
653 gOnScrollCompleteCalled = false;
654 gOnSnapStartCalled = false;
656 // Now do a pan starting from (start) and heading (direction)
658 SendPan(application, Gesture::Possible, pos);
659 SendPan(application, Gesture::Started, pos);
662 for(int i = 0;i<frames;i++)
664 pos += direction; // Move in this direction
665 SendPan(application, Gesture::Continuing, pos);
671 pos += direction; // Move in this direction.
672 SendPan(application, Gesture::Finished, pos);
673 Wait(application, RENDER_DELAY_SCROLL);
679 int UtcDaliScrollViewScrollSensitive(void)
681 ToolkitTestApplication application;
682 tet_infoline(" UtcDaliScrollViewScrollSensitive");
684 // Set up a scrollView...
685 ScrollView scrollView = ScrollView::New();
686 Stage::GetCurrent().Add( scrollView );
687 Vector2 stageSize = Stage::GetCurrent().GetSize();
688 scrollView.SetSize(stageSize);
689 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
690 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
693 RulerPtr rulerX = new DefaultRuler();
694 RulerPtr rulerY = new DefaultRuler();
695 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
696 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
697 scrollView.SetRulerX(rulerX);
698 scrollView.SetRulerY(rulerY);
699 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
700 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
701 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
702 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
704 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
707 // First try insensitive swipe.
708 scrollView.SetScrollSensitive(false);
709 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
711 DALI_TEST_CHECK( !gOnScrollStartCalled );
712 DALI_TEST_CHECK( !gOnScrollCompleteCalled );
713 DALI_TEST_CHECK( !gOnSnapStartCalled );
715 // Second try sensitive swipe.
716 scrollView.SetScrollSensitive(true);
717 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
719 DALI_TEST_CHECK( gOnScrollStartCalled );
720 DALI_TEST_CHECK( gOnScrollCompleteCalled );
721 DALI_TEST_CHECK( gOnSnapStartCalled );
725 int UtcDaliScrollViewTouchesRequired(void)
727 ToolkitTestApplication application;
728 tet_infoline(" UtcDaliScrollViewTouchesRequired");
730 // Set up a scrollView...
731 ScrollView scrollView = ScrollView::New();
732 Stage::GetCurrent().Add( scrollView );
733 Vector2 stageSize = Stage::GetCurrent().GetSize();
734 scrollView.SetSize(stageSize);
735 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
736 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
739 RulerPtr rulerX = new DefaultRuler();
740 RulerPtr rulerY = new DefaultRuler();
741 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
742 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
743 scrollView.SetRulerX(rulerX);
744 scrollView.SetRulerY(rulerY);
745 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
746 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
747 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
748 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
750 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
753 // First try touches required being a minimum and maximum of 2.
754 scrollView.SetTouchesRequiredForPanning(2, 2, true);
755 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
757 DALI_TEST_CHECK( !gOnScrollStartCalled );
758 DALI_TEST_CHECK( !gOnScrollUpdateCalled );
759 DALI_TEST_CHECK( !gOnScrollCompleteCalled );
760 DALI_TEST_CHECK( !gOnSnapStartCalled );
762 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
765 // Second try touches required being a minimum and maximum of 1.
766 scrollView.SetTouchesRequiredForPanning(1, 1, true);
767 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT * 0.1f, CLAMP_GESTURE_FRAMES * 0.1f, true);
769 DALI_TEST_CHECK( gOnScrollStartCalled );
770 DALI_TEST_CHECK( gOnScrollUpdateCalled );
771 DALI_TEST_CHECK( gOnScrollCompleteCalled );
772 DALI_TEST_CHECK( gOnSnapStartCalled );
776 int UtcDaliScrollViewAxisAutoLock(void)
778 ToolkitTestApplication application;
779 tet_infoline(" UtcDaliScrollViewAxisAutoLock");
781 // Set up a scrollView...
782 ScrollView scrollView = ScrollView::New();
783 Stage::GetCurrent().Add( scrollView );
784 Vector2 stageSize = Stage::GetCurrent().GetSize();
785 scrollView.SetSize(stageSize);
786 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
787 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
790 RulerPtr rulerX = new DefaultRuler();
791 RulerPtr rulerY = new DefaultRuler();
792 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
793 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
794 scrollView.SetRulerX(rulerX);
795 scrollView.SetRulerY(rulerY);
796 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
797 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
798 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
801 scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
803 Vector3 startPosition = scrollView.GetCurrentScrollPosition();
804 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
805 const Vector3 positionAfterNormal = scrollView.GetCurrentScrollPosition();
808 scrollView.SetAxisAutoLock(true);
809 DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
811 scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
813 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
814 const Vector3 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
816 // compare how much the Y position has deviated for normal and autolock.
817 const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
818 const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
820 // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
821 DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
823 scrollView.SetAxisAutoLock(false);
824 DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
828 int UtcDaliScrollViewAxisAutoLockGradient(void)
830 ToolkitTestApplication application;
831 tet_infoline(" UtcDaliScrollViewAxisAutoLockGradient");
833 // Set up a scrollView...
834 ScrollView scrollView = ScrollView::New();
835 scrollView.SetAxisAutoLockGradient(0.5f);
836 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
837 scrollView.SetAxisAutoLockGradient(1.0f);
838 DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
842 int UtcDaliScrollViewConstraints(void)
844 ToolkitTestApplication application;
845 tet_infoline(" UtcDaliScrollViewConstraints");
847 // Set up a scrollView...
848 ScrollView scrollView = ScrollView::New();
849 Stage::GetCurrent().Add( scrollView );
850 Vector2 stageSize = Stage::GetCurrent().GetSize();
851 scrollView.SetSize(stageSize);
852 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
853 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
856 RulerPtr rulerX = new DefaultRuler();
857 RulerPtr rulerY = new DefaultRuler();
858 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
859 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
860 scrollView.SetRulerX(rulerX);
861 scrollView.SetRulerY(rulerY);
863 // Add an Actor to ScrollView,
864 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
865 gConstraintResult = Vector3::ZERO;
866 Actor a = Actor::New();
868 a.SetPosition( TEST_ACTOR_POSITION );
871 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
872 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
873 Source(scrollView, scrollPositionProperty),
874 TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
875 constraint.SetRemoveAction(Constraint::Discard);
876 scrollView.ApplyConstraintToChildren(constraint);
879 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
881 gConstraintResult = Vector3::ZERO;
882 scrollView.RemoveConstraintsFromChildren();
885 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
889 int UtcDaliScrollViewBind(void)
891 ToolkitTestApplication application;
892 tet_infoline(" UtcDaliScrollViewBind");
894 // Set up a scrollView...
895 ScrollView scrollView = ScrollView::New();
896 Stage::GetCurrent().Add( scrollView );
897 Vector2 stageSize = Stage::GetCurrent().GetSize();
898 scrollView.SetSize(stageSize);
899 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
900 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
903 RulerPtr rulerX = new DefaultRuler();
904 RulerPtr rulerY = new DefaultRuler();
905 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
906 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
907 scrollView.SetRulerX(rulerX);
908 scrollView.SetRulerY(rulerY);
910 // Add an Actor to ScrollView,
911 // Apply TestSumConstraint to ScrollView's children (includes this Actor)
913 gConstraintResult = Vector3::ZERO;
914 Actor a = Actor::New();
916 a.SetPosition( TEST_ACTOR_POSITION );
919 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
920 // apply this constraint to scrollview
921 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
922 Source(scrollView, scrollPositionProperty),
923 TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
925 constraint.SetRemoveAction(Constraint::Discard);
926 scrollView.ApplyConstraintToChildren(constraint);
930 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
933 gConstraintResult = Vector3::ZERO;
934 scrollView.UnbindActor( a );
936 DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
939 gConstraintResult = Vector3::ZERO;
940 scrollView.BindActor( a );
942 DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
946 int UtcDaliRulerEnableDisable(void)
948 ToolkitTestApplication application;
949 tet_infoline(" UtcDaliRulerEnableDisable");
951 RulerPtr ruler = new DefaultRuler();
953 DALI_TEST_CHECK( ruler->IsEnabled() );
955 DALI_TEST_CHECK( !ruler->IsEnabled() );
957 DALI_TEST_CHECK( ruler->IsEnabled() );
961 int UtcDaliRulerDomainEnableDisable(void)
963 ToolkitTestApplication application;
964 tet_infoline(" UtcDaliRulerDomainEnableDisable");
966 RulerPtr ruler = new DefaultRuler();
967 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
970 ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
971 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
972 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
973 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
975 ruler->DisableDomain();
976 DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
977 DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
978 DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
982 int UtcDaliRulerSnapAndClamp(void)
984 ToolkitTestApplication application;
985 tet_infoline(" UtcDaliRulerSnapAndClamp");
987 RulerPtr ruler = new FixedRuler( 50.0f );
988 ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
990 // default testing. (snap and clamp)
991 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
992 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
993 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
994 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
995 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
996 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
999 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1000 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
1001 DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1003 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1004 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
1005 DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1008 DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
1009 DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
1010 DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
1011 DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
1012 DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
1015 DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
1016 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
1017 DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
1018 DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
1020 // clamp state testing.
1022 DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1023 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1024 DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1025 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1026 DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1027 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1028 DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1029 DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
1030 DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1031 DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1032 DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1033 DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
1037 int UtcDaliRulerFixedRulerSpacing(void)
1039 ToolkitTestApplication application;
1040 tet_infoline(" UtcDaliRulerFixedRulerSpacing");
1042 RulerPtr rulerZero = new FixedRuler( 0.0f );
1043 rulerZero->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1045 RulerPtr rulerNormal = new FixedRuler( 25.0f );
1046 rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1048 unsigned int volume;
1051 position = rulerZero->GetPositionFromPage(1, volume, true);
1052 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1053 DALI_TEST_EQUALS( volume, 1u, TEST_LOCATION );
1055 position = rulerNormal->GetPositionFromPage(1, volume, true);
1056 DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
1057 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1059 position = rulerZero->GetPositionFromPage(2, volume, true);
1060 DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1061 DALI_TEST_EQUALS( volume, 2u, TEST_LOCATION );
1063 position = rulerNormal->GetPositionFromPage(2, volume, true);
1064 DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
1065 DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1069 int UtcDaliScrollViewOvershoot(void)
1071 ToolkitTestApplication application;
1072 tet_infoline(" UtcDaliScrollViewOvershoot");
1074 // Set up a scrollView...
1075 ScrollView scrollView = ScrollView::New();
1076 Stage::GetCurrent().Add( scrollView );
1077 Vector2 stageSize = Stage::GetCurrent().GetSize();
1078 scrollView.SetSize(stageSize);
1079 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1080 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1083 RulerPtr rulerX = new DefaultRuler();
1084 RulerPtr rulerY = new DefaultRuler();
1085 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1086 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1087 scrollView.SetRulerX(rulerX);
1088 scrollView.SetRulerY(rulerY);
1089 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1090 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1091 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1093 scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1096 // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1097 Vector2 currentPos = Vector2(100.0f, 100.0f);
1098 currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1099 Property::Index overshootXProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
1100 Property::Index overshootYProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
1101 Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
1102 float overshootXValue = scrollView.GetProperty<float>(overshootXProperty);
1103 float overshootYValue = scrollView.GetProperty<float>(overshootYProperty);
1104 Vector3 positionValue = scrollView.GetProperty<Vector3>(scrollPositionProperty);
1105 DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1106 DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1107 DALI_TEST_EQUALS(positionValue, Vector3::ZERO, TEST_LOCATION);
1109 float timeToReachOrigin;
1111 // Now release touch. Overshoot should snap back to zero.
1112 SendPan(application, Gesture::Finished, currentPos);
1113 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1115 DALI_TEST_CHECK( (timeToReachOrigin > Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1116 (timeToReachOrigin < Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1118 // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1119 scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1121 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1122 // Now release touch. Overshoot should snap back to zero.
1123 SendPan(application, Gesture::Finished, currentPos);
1124 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1126 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1127 (timeToReachOrigin < TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1129 // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1130 scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1132 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1133 // Now release touch. Overshoot should snap back to zero.
1134 SendPan(application, Gesture::Finished, currentPos);
1135 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1137 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1138 (timeToReachOrigin < TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1140 // 4. Repeat Scroll, but this time change overshoot function.
1141 scrollView.SetSnapOvershootDuration(TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION);
1142 scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
1144 currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1145 // Now release touch. Overshoot should snap back to zero.
1146 SendPan(application, Gesture::Finished, currentPos);
1147 timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1149 DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1150 (timeToReachOrigin < TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1154 int UtcDaliScrollViewSnapAlphaFunction(void)
1156 ToolkitTestApplication application;
1157 tet_infoline(" UtcDaliScrollViewSnapAlphaFunction");
1159 // Set up a scrollView...
1160 ScrollView scrollView = ScrollView::New();
1161 scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseIn );
1162 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseIn );
1163 scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseOut );
1164 DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseOut );
1166 scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::Bounce );
1167 DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::Bounce );
1168 scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::BounceBack );
1169 DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::BounceBack );
1173 int UtcDaliScrollViewSnapDuration(void)
1175 ToolkitTestApplication application;
1176 tet_infoline(" UtcDaliScrollViewSnapDuration");
1178 // Set up a scrollView...
1179 ScrollView scrollView = ScrollView::New();
1180 scrollView.SetScrollSnapDuration( 1.0f );
1181 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1182 scrollView.SetScrollSnapDuration( 0.5f );
1183 DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1185 scrollView.SetScrollFlickDuration( 2.0f );
1186 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1187 scrollView.SetScrollFlickDuration( 1.5f );
1188 DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1192 int UtcDaliScrollViewSignalsSnapStart(void)
1194 ToolkitTestApplication application;
1195 tet_infoline(" UtcDaliScrollViewSignalsSnapStart");
1197 // Set up a scrollView...
1198 ScrollView scrollView = ScrollView::New();
1199 Stage::GetCurrent().Add( scrollView );
1200 Vector2 stageSize = Stage::GetCurrent().GetSize();
1201 scrollView.SetSize(stageSize);
1202 scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1203 scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1206 RulerPtr rulerX = new DefaultRuler();
1207 RulerPtr rulerY = new DefaultRuler();
1208 rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1209 rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1210 scrollView.SetRulerX(rulerX);
1211 scrollView.SetRulerY(rulerY);
1212 scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1214 scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1217 // First try a snap.
1218 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1220 DALI_TEST_CHECK( gOnSnapStartCalled );
1221 DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1223 // Second try a swipe.
1224 PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1226 DALI_TEST_CHECK( gOnSnapStartCalled );
1227 DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1232 int UtcDaliScrollViewSetMouseWheelScrollDistanceStep(void)
1234 ToolkitTestApplication application;
1235 tet_infoline(" UtcDaliScrollViewSetMouseWheelScrollDistanceStep");
1237 ScrollView scrollView = ScrollView::New();
1238 // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1239 scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1240 DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1241 scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1242 DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1246 int UtcDaliScrollViewGetSet(void)
1248 ToolkitTestApplication application;
1249 tet_infoline(" UtcDaliScrollViewGetSet");
1250 ScrollView scrollView = ScrollView::New();
1251 scrollView.SetMaxOvershoot(50.0f, 50.0f);
1252 scrollView.SetMaxFlickSpeed(0.5f);
1253 DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1254 scrollView.SetFrictionCoefficient(0.6f);
1255 DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1256 scrollView.SetFlickSpeedCoefficient(0.7f);
1257 DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);