License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / scroll-view / utc-Dali-ScrollView.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27
28 #include <dali-toolkit-test-suite-utils.h>
29
30 using namespace Dali;
31 using namespace Toolkit;
32
33 static void Startup();
34 static void Cleanup();
35
36 namespace
37 {
38 static bool gObjectCreatedCallBackCalled;
39
40 static void TestCallback(BaseHandle handle)
41 {
42   gObjectCreatedCallBackCalled = true;
43 }
44 } // namespace
45
46 extern "C" {
47   void (*tet_startup)() = Startup;
48   void (*tet_cleanup)() = Cleanup;
49 }
50
51
52 enum {
53   POSITIVE_TC_IDX = 0x01,
54   NEGATIVE_TC_IDX,
55 };
56
57 // Add test functionality for all APIs in the class (Positive and Negative)
58 #define MAX_NUMBER_OF_TESTS 10000
59 extern "C" {
60   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
61 }
62
63 TEST_FUNCTION( UtcDaliScrollViewNew, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliScrollViewDownCast, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliScrollViewScrollToPosition, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliScrollViewScrollToPage, POSITIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliScrollViewScrollToActor, POSITIVE_TC_IDX );
68 TEST_FUNCTION( UtcDaliScrollViewScrollToSnapPoint, POSITIVE_TC_IDX );
69 TEST_FUNCTION( UtcDaliScrollViewRulerScale, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliScrollViewTransformTo, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliScrollViewRefreshInterval, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliScrollViewWrapMode, POSITIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliScrollViewActorAutoSnap, POSITIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliScrollViewSignalsStartComplete, POSITIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliScrollViewSignalsUpdate, POSITIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliScrollViewSignalsClamped, POSITIVE_TC_IDX );
77 TEST_FUNCTION( UtcDaliScrollViewSignalsSnapStart, POSITIVE_TC_IDX );
78 TEST_FUNCTION( UtcDaliScrollViewScrollSensitive, POSITIVE_TC_IDX );
79 TEST_FUNCTION( UtcDaliScrollViewTouchesRequired, POSITIVE_TC_IDX );
80 TEST_FUNCTION( UtcDaliScrollViewAxisAutoLock, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliScrollViewAxisAutoLockGradient, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliScrollViewConstraints, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliScrollViewBind, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliScrollViewOvershoot, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliScrollViewSnapAlphaFunction, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliScrollViewSnapDuration, POSITIVE_TC_IDX );
87 TEST_FUNCTION( UtcDaliRulerEnableDisable, POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliRulerDomainEnableDisable, POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliRulerSnapAndClamp, POSITIVE_TC_IDX );
90 TEST_FUNCTION( UtcDaliRulerFixedRulerSpacing, POSITIVE_TC_IDX );
91 TEST_FUNCTION( UtcDaliScrollViewUIComponent, POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliScrollViewSetMouseWheelScrollDistanceStep, POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliScrollViewGetSet, POSITIVE_TC_IDX );
94
95
96 namespace // unnamed namespace
97 {
98
99 const int MILLISECONDS_PER_SECOND = 1000;
100 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
101 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000;             ///< 1000ms to test animation
102 const int RENDER_DELAY_SCROLL = 1000;                           ///< duration to wait for any scroll to complete.
103
104 // For Clamp Signal testing...
105 const float CLAMP_EXCESS_WIDTH = 200.0f;                        ///< Amount of width that can be panned outside scrollview
106 const float CLAMP_EXCESS_HEIGHT = 200.0f;                       ///< Amount of height that can be panned outside scrollview
107 const int CLAMP_STEP_0_CHECK_NOTCLAMPED = 0;                    ///< FSM: "First check that scrollview isn't clamped"
108 const int CLAMP_STEP_1_CHECK_CLAMPED_WEST = 1;                  ///< FSM: "Next check that scrollview clamps against left side"
109 const int CLAMP_STEP_2_CHECK_CLAMPED_SOUTH_WEST = 2;            ///< FSM: "Then check that scrollview clamps against bottom-left side"
110 const int CLAMP_STEP_3_SUCCESS = 3;                             ///< FSM: "Finished (Success)"
111 const Vector3 CLAMP_START_SCROLL_POSITION(30.0f, 100.0f, 0.0f); ///< Scroll start position for the Clamping tests.
112 const Vector2 CLAMP_TOUCH_START( 100.0f, 100.0f );              ///< Start point to touch from for the Clamping tests.
113 const Vector2 CLAMP_TOUCH_MOVEMENT( 5.0f, -5.0f );              ///< Amount to move touch for each frame for the Clamping tests.
114 const int CLAMP_GESTURE_FRAMES = 100;                           ///< Number of Frames to synthesize a gesture for the Clamping tests.
115 const Vector3 TEST_ACTOR_POSITION(100.0f, 100.0f, 0.0f);        ///< A Test actor position offset (arbitrary value)
116 const Vector3 TEST_CONSTRAINT_OFFSET(1.0f, 2.0f, 0.0f);         ///< A Test constraint offset (arbitrary value to test effects)
117 const float TEST_RATIO_TOLERANCE = 0.05;                        ///< +/-5% tolerance for ratio comparisons.
118
119 const int MAX_FRAMES_TO_TEST_OVERSHOOT = 600;                         ///< 10 seconds (at 60 frames per second).
120 const Vector3 OVERSHOOT_START_SCROLL_POSITION(100.0f, 100.0f, 0.0f);  ///< Scroll start position for the Overshoot tests.
121 const float TEST_DEFAULT_SNAP_OVERSHOOT_DURATION = 0.25f;             ///< 0.25 seconds should be default snap overshoot duration
122 const float TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION = 0.05f;             ///< a Test duration
123 const float TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION = 1.5f;              ///< another Test duration
124 const float TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION = TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * 0.5f; // Same as above, but different alpha function.
125 const float TIME_TOLERANCE = 0.05f;                                   ///< Allow testing tolerance between a 10th of second (+/- 3 frames)
126
127 // Create bitmap image
128 BitmapImage CreateBitmapImage()
129 {
130   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
131
132   PixelBuffer* pixbuf = image.GetBuffer();
133
134   // Using a 4x4 image gives a better blend with the GL implementation
135   // than a 3x3 image
136   for(size_t i=0; i<16; i++)
137   {
138     pixbuf[i*4+0] = 0xFF;
139     pixbuf[i*4+1] = 0xFF;
140     pixbuf[i*4+2] = 0xFF;
141     pixbuf[i*4+3] = 0xFF;
142   }
143
144   return image;
145 }
146
147 // Generate a PanGestureEvent to send to Core
148 Integration::PanGestureEvent GeneratePan(
149     Gesture::State state,
150     const Vector2& previousPosition,
151     const Vector2& currentPosition,
152     unsigned long timeDelta,
153     unsigned int numberOfTouches = 1)
154 {
155   Integration::PanGestureEvent pan(state);
156
157   pan.previousPosition = previousPosition;
158   pan.currentPosition = currentPosition;
159   pan.timeDelta = timeDelta;
160   pan.numberOfTouches = numberOfTouches;
161
162   return pan;
163 }
164
165 /**
166  * Helper to generate PanGestureEvent
167  *
168  * @param[in] application Application instance
169  * @param[in] state The Gesture State
170  * @param[in] pos The current position of touch.
171  */
172 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
173 {
174   static Vector2 last;
175
176   if( (state == Gesture::Started) ||
177       (state == Gesture::Possible) )
178   {
179     last.x = pos.x;
180     last.y = pos.y;
181   }
182
183   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
184
185   last.x = pos.x;
186   last.y = pos.y;
187 }
188
189 /*
190  * Simulate time passed by.
191  *
192  * @note this will always process at least 1 frame (1/60 sec)
193  *
194  * @param application Test application instance
195  * @param duration Time to pass in milliseconds.
196  * @return The actual time passed in milliseconds
197  */
198 int Wait(ToolkitTestApplication& application, int duration = 0)
199 {
200   int time = 0;
201
202   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
203   {
204     application.SendNotification();
205     application.Render(RENDER_FRAME_INTERVAL);
206     time += RENDER_FRAME_INTERVAL;
207   }
208
209   return time;
210 }
211
212 // Callback probes.
213
214 static bool gOnScrollStartCalled;                       ///< Whether the OnScrollStart signal was invoked.
215 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
216 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
217 static bool gOnScrollClampedCalled;                     ///< Whether the OnScrollClamped signal was invoked.
218 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
219 static ClampState3 gLastClampPosition;                  ///< Clamping information from OnScrollClampedEvent.
220 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
221 static Vector3 gConstraintResult;                       ///< Result from constraint.
222
223 /**
224  * Invoked when scrolling starts.
225  *
226  * @param[in] position The current scroll position.
227  */
228 static void OnScrollStart( const Vector3& position )
229 {
230   gOnScrollStartCalled = true;
231 }
232
233 /**
234  * Invoked when scrolling updates (via dragging)
235  *
236  * @param[in] position The current scroll position.
237  */
238 static void OnScrollUpdate( const Vector3& position )
239 {
240   gOnScrollUpdateCalled = true;
241 }
242
243 /**
244  * Invoked when scrolling finishes
245  *
246  * @param[in] position The current scroll position.
247  */
248 static void OnScrollComplete( const Vector3& position )
249 {
250   gOnScrollCompleteCalled = true;
251 }
252
253 /**
254  * Invoked when scrolling clamped.
255  *
256  * @param[in] event The position/scale/rotation axes that were clamped.
257  */
258 static void OnScrollClamped( const ScrollView::ClampEvent& event )
259 {
260   gOnScrollClampedCalled = true;
261   gLastClampPosition = event.position;
262 }
263
264 /**
265  * Invoked when a snap or flick started.
266  *
267  * @param[in] event The type of snap and the target position/scale/rotation.
268  */
269 static void OnSnapStart( const ScrollView::SnapEvent& event )
270 {
271   gOnSnapStartCalled = true;
272   gLastSnapType = event.type;
273 }
274
275 /**
276  * TestSumConstraint
277  *
278  * Summation of current value, property, and offset.
279  *
280  * current' = current + mOffset + property;
281  */
282 struct TestSumConstraint
283 {
284   /**
285    * @param[in] offset The offset to be added to current.
286    */
287   TestSumConstraint(const Vector3& offset)
288   :mOffset(offset)
289   {
290   }
291
292   /**
293    * @param[in] current The current base value
294    * @param[in] property The property to be added to current.
295    * @return The new current Vector.
296    */
297   Vector3 operator()(const Vector3& current)
298   {
299     gConstraintResult = current + mOffset;
300     return gConstraintResult;
301   }
302
303   /**
304    * @param[in] current The current base value
305    * @param[in] property The property to be added to current.
306    * @return The new current Vector.
307    */
308   Vector3 operator()(const Vector3&    current,
309                     const PropertyInput& property)
310   {
311     gConstraintResult = current + property.GetVector3() + mOffset;
312     return gConstraintResult;
313   }
314
315   Vector3 mOffset;
316
317 };
318
319 /**
320  * @param[in] application The application instance
321  * @param[in] scrollView The scrollView instance
322  * @return The time taken for the overshoot to reach origin (zero)
323  */
324 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
325 {
326   Property::Index overshootPropertyX = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
327   Property::Index overshootPropertyY = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
328
329   int timeToReachOrigin = -1;
330   for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
331   {
332     float overshootXValue = scrollView.GetProperty<float>(overshootPropertyX);
333     float overshootYValue = scrollView.GetProperty<float>(overshootPropertyY);
334     if(overshootXValue == 0.0f && overshootYValue == 0.0f)
335     {
336       break;
337     }
338
339     timeToReachOrigin += Wait(application);
340   }
341
342   return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
343 }
344
345 /**
346  * y = 2x alpha function, which is clamped between 0.0f - 1.0f
347  *
348  * Animations should appear to finish (reach 100% point)
349  * at just half the time of a regular Linear AlphaFunction.
350  *
351  * @param[in] progress value (ranges from 0.0f - 1.0f)
352  * @return interpolation value (ranges from 0.0f - 1.0f)
353  */
354 float TestAlphaFunction(float progress)
355 {
356   return std::min( progress * 2.0f, 1.0f );
357 }
358
359 } // unnamed namespace
360
361 // Called only once before first test is run.
362 static void Startup()
363 {
364 }
365
366 // Called only once after last test is run
367 static void Cleanup()
368 {
369 }
370
371 static void UtcDaliScrollViewNew()
372 {
373   ToolkitTestApplication application;
374   tet_infoline(" UtcDaliScrollViewNew");
375
376   ScrollView scrollView;
377
378   DALI_TEST_CHECK( !scrollView );
379
380   scrollView = ScrollView::New();
381
382   DALI_TEST_CHECK( scrollView );
383
384   ScrollView scrollView2(scrollView);
385
386   DALI_TEST_CHECK( scrollView2 == scrollView );
387
388   //Additional check to ensure object is created by checking if it's registered
389   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
390   DALI_TEST_CHECK( registry );
391
392   gObjectCreatedCallBackCalled = false;
393   registry.ObjectCreatedSignal().Connect( &TestCallback );
394   {
395     ScrollView scrollView = ScrollView::New();
396   }
397   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
398 }
399
400 static void UtcDaliScrollViewDownCast()
401 {
402   ToolkitTestApplication application;
403   tet_infoline(" UtcDaliScrollViewDownCast");
404
405   ScrollView scrollView = ScrollView::New();
406   BaseHandle handle(scrollView);
407
408   ScrollView newScrollView = ScrollView::DownCast( handle );
409   DALI_TEST_CHECK( scrollView );
410   DALI_TEST_CHECK( newScrollView == scrollView );
411 }
412
413 static void UtcDaliScrollViewScrollToPosition()
414 {
415   ToolkitTestApplication application;
416   tet_infoline(" UtcDaliScrollViewScrollToPosition");
417
418   // Create the ScrollView actor
419   ScrollView scrollView = ScrollView::New();
420   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
421   scrollView.SetRefreshInterval(0);
422   Stage::GetCurrent().Add( scrollView );
423
424   const Vector3 target = Vector3(100.0f, 200.0f, 0.0f);
425   const Vector3 target2 = Vector3(300.0f, 100.0f, 0.0f);
426
427   scrollView.ScrollTo( target, 0.0f );
428   Wait(application);
429   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
430   scrollView.ScrollTo( target2 );
431   Wait(application, RENDER_DELAY_SCROLL);
432   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
433
434   Wait(application);
435 }
436
437 static void UtcDaliScrollViewScrollToPage()
438 {
439   ToolkitTestApplication application;
440   tet_infoline(" UtcDaliScrollViewScrollToPage");
441
442   ScrollView scrollView = ScrollView::New();
443   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
444   scrollView.SetRefreshInterval(0);
445   Stage::GetCurrent().Add( scrollView );
446   RulerPtr rulerX = new FixedRuler( 100.0f );
447   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
448   RulerPtr rulerY = new FixedRuler( 100.0f );
449   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
450
451   scrollView.SetRulerX( rulerX );
452   scrollView.SetRulerY( rulerY );
453
454   scrollView.ScrollTo( 1, 0.0f );
455   Wait(application);
456   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
457
458   scrollView.ScrollTo( 5, 0.0f );
459   Wait(application);
460   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(500.0f, 0.0f, 0.0f), TEST_LOCATION );
461
462   scrollView.ScrollTo( 10, 0.0f );
463   Wait(application);
464   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(200.0f, 100.0f, 0.0f), TEST_LOCATION );
465
466   scrollView.ScrollTo( 15, 0.0f );
467   Wait(application);
468   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(700.0f, 100.0f, 0.0f), TEST_LOCATION );
469   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
470
471   scrollView.ScrollTo( 3 );
472   Wait(application, RENDER_DELAY_SCROLL);
473   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(300.0f, 0.0f, 0.0f), TEST_LOCATION );
474   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
475
476   scrollView.ScrollTo( 9 );
477   Wait(application, RENDER_DELAY_SCROLL);
478   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 100.0f, 0.0f), TEST_LOCATION );
479   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
480
481   // Apply DefaultRulers instead and see what happens.
482   rulerX = new DefaultRuler();
483   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
484   rulerY = new DefaultRuler();
485   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
486
487   scrollView.SetRulerX( rulerX );
488   scrollView.SetRulerY( rulerY );
489
490   // This time should always scroll to origin (0.0f, 0.0f)
491   scrollView.ScrollTo( 1, 0.0f );
492   Wait(application);
493   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
494   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
495
496   Wait(application);
497 }
498
499 static void UtcDaliScrollViewScrollToActor()
500 {
501   ToolkitTestApplication application;
502   tet_infoline(" UtcDaliScrollViewScrollToActor");
503
504   ScrollView scrollView = ScrollView::New();
505   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
506   scrollView.SetRefreshInterval(0);
507   Stage::GetCurrent().Add( scrollView );
508
509   Actor actorA = Actor::New();
510   const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
511   actorA.SetPosition(positionA);
512   scrollView.Add(actorA);
513
514   Actor actorB = Actor::New();
515   const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
516   actorB.SetPosition(positionB);
517   scrollView.Add(actorB);
518
519   Wait(application);
520
521   scrollView.ScrollTo(actorA, 0.0f);
522   Wait(application);
523   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
524
525   Wait(application);
526   scrollView.ScrollTo(actorB, 0.0f);
527   Wait(application);
528   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
529
530   scrollView.ScrollTo(actorA);
531   Wait(application, RENDER_DELAY_SCROLL);
532   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
533
534   scrollView.ScrollTo(actorB);
535   Wait(application, RENDER_DELAY_SCROLL);
536   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
537 }
538
539 static void UtcDaliScrollViewScrollToSnapPoint()
540 {
541   ToolkitTestApplication application;
542   tet_infoline(" UtcDaliScrollViewScrollToSnapPoint");
543
544   ScrollView scrollView = ScrollView::New();
545   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
546   scrollView.SetRefreshInterval(0);
547   Stage::GetCurrent().Add( scrollView );
548   RulerPtr rulerX = new FixedRuler( 100.0f );
549   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
550   RulerPtr rulerY = new FixedRuler( 100.0f );
551   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
552
553   scrollView.SetRulerX( rulerX );
554   scrollView.SetRulerY( rulerY );
555
556   scrollView.ScrollTo( Vector3(120.0f, 190.0f, 0.0f), 0.0f );
557   Wait(application);
558   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(120.0f, 190.0f, 0.0f), TEST_LOCATION );
559
560   scrollView.ScrollToSnapPoint();
561
562   Wait(application, RENDER_DELAY_SCROLL);
563   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 200.0f, 0.0f), TEST_LOCATION );
564 }
565
566 static void UtcDaliScrollViewRulerScale()
567 {
568   ToolkitTestApplication application;
569   tet_infoline(" UtcDaliScrollViewRulerScale");
570
571   ScrollView scrollView = ScrollView::New();
572   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
573   scrollView.SetRefreshInterval(0);
574   Stage::GetCurrent().Add( scrollView );
575
576   RulerPtr rulerScaleX = new FixedRuler(0.25f);
577   RulerPtr rulerScaleY = new DefaultRuler();
578   rulerScaleX->SetDomain( RulerDomain(0.1f, 0.9f, true) );
579   rulerScaleY->SetDomain( RulerDomain(0.1f, 2.0f, true) );
580   scrollView.SetRulerScaleX(rulerScaleX);
581   scrollView.SetRulerScaleY(rulerScaleY);
582
583   scrollView.Add(Actor::New());
584
585   // Scroll to a position, and then snap.
586   scrollView.ScaleTo(Vector3(1.95f, 1.4f, 1.0f), 0.0f);
587   scrollView.ScrollToSnapPoint();
588   Wait(application, RENDER_DELAY_SCROLL);
589   DALI_TEST_EQUALS( scrollView.GetCurrentScrollScale(), Vector3(0.9f, 1.4f, 1.0f), TEST_LOCATION );
590
591   // Scroll SLOWLY to another position, and then snap.
592   scrollView.ScaleTo(Vector3(0.45f, -1.0f, 1.0f));
593   Wait(application, RENDER_DELAY_SCROLL);
594   scrollView.ScrollToSnapPoint();
595   Wait(application, RENDER_DELAY_SCROLL);
596   DALI_TEST_EQUALS( scrollView.GetCurrentScrollScale(), Vector3(0.5f, 0.1f, 1.0f), TEST_LOCATION );
597
598   // Scroll to another position, and then snap.
599   scrollView.ScaleTo(Vector3(0.71f, 0.71f, 1.0f), 0.0f);
600   scrollView.ScrollToSnapPoint();
601   Wait(application, RENDER_DELAY_SCROLL);
602   DALI_TEST_EQUALS( scrollView.GetCurrentScrollScale(), Vector3(0.75f, 0.71f, 1.0f), TEST_LOCATION );
603 }
604
605 static void UtcDaliScrollViewTransformTo()
606 {
607   ToolkitTestApplication application;
608   tet_infoline(" UtcDaliScrollViewTransformTo");
609
610   ScrollView scrollView = ScrollView::New();
611   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
612   scrollView.SetRefreshInterval(0);
613   Stage::GetCurrent().Add( scrollView );
614
615   // Position rulers.
616   RulerPtr rulerX = new FixedRuler(50.0f);
617   RulerPtr rulerY = new FixedRuler(50.0f);
618   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
619   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
620   scrollView.SetRulerX(rulerX);
621   scrollView.SetRulerY(rulerY);
622
623   // Scale rulers.
624   RulerPtr rulerScaleX = new FixedRuler(0.1f);
625   RulerPtr rulerScaleY = new FixedRuler(0.1f);
626   rulerScaleX->SetDomain( RulerDomain(0.0f, 1.0f, true) );
627   rulerScaleY->SetDomain( RulerDomain(0.0f, 1.0f, true) );
628   scrollView.SetRulerScaleX(rulerScaleX);
629   scrollView.SetRulerScaleY(rulerScaleY);
630
631   // transform to a random position/scale
632   Vector3 targetPosition = Vector3(100.0f, 200.0f, 0.0f);
633   Vector3 targetScale = Vector3(0.44f, 0.58f, 1.0f);
634   float targetRotation = 0.0f;
635   scrollView.TransformTo(targetPosition, targetScale, targetRotation, 0.0f);
636   Wait(application);
637
638   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetPosition, TEST_LOCATION );
639   DALI_TEST_EQUALS( scrollView.GetCurrentScrollScale(), targetScale, TEST_LOCATION );
640
641   // transform to another random position/scale (SLOWLY)
642   targetPosition = Vector3(60.0f, 40.0f, 0.0f);
643   targetScale = Vector3(0.4f, 0.6f, 1.0f);
644   targetRotation = 0.0f;
645   scrollView.TransformTo(targetPosition, targetScale, targetRotation);
646   Wait(application, RENDER_DELAY_SCROLL);
647
648   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetPosition, TEST_LOCATION );
649   DALI_TEST_EQUALS( scrollView.GetCurrentScrollScale(), targetScale, TEST_LOCATION );
650 }
651
652 static void UtcDaliScrollViewRefreshInterval()
653 {
654   ToolkitTestApplication application;
655   tet_infoline(" UtcDaliScrollViewRefreshInterval");
656
657   ScrollView scrollView = ScrollView::New();
658   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
659   scrollView.SetRefreshInterval(0);
660   DALI_TEST_EQUALS( scrollView.GetRefreshInterval(), 0, TEST_LOCATION);
661   scrollView.SetRefreshInterval(10);
662   DALI_TEST_EQUALS( scrollView.GetRefreshInterval(), 10, TEST_LOCATION);
663   scrollView.SetRefreshInterval(1000);
664   DALI_TEST_EQUALS( scrollView.GetRefreshInterval(), 1000, TEST_LOCATION);
665 }
666
667 static void UtcDaliScrollViewWrapMode()
668 {
669   ToolkitTestApplication application;
670   tet_infoline(" UtcDaliScrollViewWrapMode");
671
672   ScrollView scrollView = ScrollView::New();
673   Stage::GetCurrent().Add( scrollView );
674
675   // Position rulers. 4x4 grid.
676   RulerPtr rulerX = new FixedRuler(50.0f);
677   RulerPtr rulerY = new FixedRuler(50.0f);
678   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
679   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
680   scrollView.SetRulerX(rulerX);
681   scrollView.SetRulerY(rulerY);
682
683   scrollView.SetWrapMode(false);
684   scrollView.ScrollTo(Vector3(225.0f, 125.0f, 0.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
685   Wait(application);
686   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
687   scrollView.SetWrapMode(true);
688   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
689 }
690
691 static void UtcDaliScrollViewActorAutoSnap()
692 {
693   ToolkitTestApplication application;
694   tet_infoline(" UtcDaliScrollViewActorAutoSnap");
695
696   ScrollView scrollView = ScrollView::New();
697   Stage::GetCurrent().Add( scrollView );
698   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
699   scrollView.SetRefreshInterval(0);
700
701   // Position rulers.
702   RulerPtr rulerX = new DefaultRuler();
703   RulerPtr rulerY = new DefaultRuler();
704   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
705   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
706   scrollView.SetRulerX(rulerX);
707   scrollView.SetRulerY(rulerY);
708
709   const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
710   Actor a = Actor::New();
711   scrollView.Add(a);
712   a.SetPosition(aPosition);
713
714   const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
715   Actor b = Actor::New();
716   scrollView.Add(b);
717   b.SetPosition(bPosition);
718
719   // Goto a random position, and execute snap (should not move)
720   Vector3 targetScroll = Vector3(500.0f, 500.0f, 0.0f);
721   scrollView.ScrollTo(targetScroll, 0.0f);
722   Wait(application);
723   scrollView.ScrollToSnapPoint();
724   Wait(application, RENDER_DELAY_SCROLL);
725   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
726
727   // Enable ActorAutoSnap, and now try snapping.
728   scrollView.SetActorAutoSnap(true);
729   scrollView.ScrollToSnapPoint();
730   Wait(application, RENDER_DELAY_SCROLL);
731   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition, TEST_LOCATION );
732
733   scrollView.ScrollTo(Vector3(0.0f, 0.0f, 0.0f), 0.0f);
734   Wait(application);
735   scrollView.ScrollToSnapPoint();
736   Wait(application, RENDER_DELAY_SCROLL);
737   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition, TEST_LOCATION );
738 }
739
740 static void UtcDaliScrollViewSignalsStartComplete()
741 {
742   ToolkitTestApplication application;
743   tet_infoline(" UtcDaliScrollViewSignalsStartComplete");
744
745   gOnScrollStartCalled = false;
746   gOnScrollCompleteCalled = false;
747
748   ScrollView scrollView = ScrollView::New();
749   Stage::GetCurrent().Add( scrollView );
750   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
751   scrollView.SetRefreshInterval(0);
752
753   // Position rulers.
754   RulerPtr rulerX = new DefaultRuler();
755   RulerPtr rulerY = new DefaultRuler();
756   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
757   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
758   scrollView.SetRulerX(rulerX);
759   scrollView.SetRulerY(rulerY);
760   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
761   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
762   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
763   scrollView.ScrollTo( 100.0f, 100.0f );
764   Wait(application, RENDER_DELAY_SCROLL);
765
766   DALI_TEST_CHECK(gOnScrollStartCalled);
767   DALI_TEST_CHECK(gOnScrollCompleteCalled);
768 }
769
770 static void UtcDaliScrollViewSignalsUpdate()
771 {
772   ToolkitTestApplication application;
773   tet_infoline(" UtcDaliScrollViewSignalsUpdate");
774
775   gOnScrollStartCalled = false;
776   gOnScrollUpdateCalled = false;
777   gOnScrollCompleteCalled = false;
778
779   ScrollView scrollView = ScrollView::New();
780   Stage::GetCurrent().Add( scrollView );
781   Vector2 stageSize = Stage::GetCurrent().GetSize();
782   scrollView.SetSize(stageSize);
783   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
784   scrollView.SetRefreshInterval(0);
785   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
786   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
787
788   // Position rulers.
789   RulerPtr rulerX = new DefaultRuler();
790   RulerPtr rulerY = new DefaultRuler();
791   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
792   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
793   scrollView.SetRulerX(rulerX);
794   scrollView.SetRulerY(rulerY);
795   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
796   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
797   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
798
799   ImageActor image = CreateSolidColorActor( Color::RED );
800   image.SetSize(stageSize);
801   image.SetParentOrigin(ParentOrigin::TOP_LEFT);
802   image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
803   scrollView.Add(image);
804
805   Wait(application);
806
807   // Do a pan starting from 100,100 and moving down diagonally.
808   Vector2 pos(100.0f, 100.0f);
809   SendPan(application, Gesture::Possible, pos);
810   SendPan(application, Gesture::Started, pos);
811   pos.x += 5.0f;
812   pos.y += 5.0f;
813   Wait(application, 100);
814
815   for(int i = 0;i<20;i++)
816   {
817     SendPan(application, Gesture::Continuing, pos);
818     pos.x += 5.0f;
819     pos.y += 5.0f;
820     Wait(application);
821   }
822
823   SendPan(application, Gesture::Finished, pos);
824   Wait(application, RENDER_DELAY_SCROLL);
825
826   DALI_TEST_CHECK(gOnScrollStartCalled);
827   DALI_TEST_CHECK(gOnScrollUpdateCalled);
828   DALI_TEST_CHECK(gOnScrollCompleteCalled);
829 }
830
831 // Creates a scroll domain slightly bigger than the stage size.
832 // ScrollView is scrolled to center, slightly to the left.
833 // Then a pan gesture is carried out causing the scrollview
834 // to pan South-West direction. Resulting in ClampEvents
835 // to fire (first Western boundary, then both Western and
836 // Southern boundary).
837 static void UtcDaliScrollViewSignalsClamped()
838 {
839   ToolkitTestApplication application;
840   tet_infoline(" UtcDaliScrollViewSignalsClamped");
841
842   gOnScrollUpdateCalled = false;
843   gOnScrollCompleteCalled = false;
844
845   // Set up a scrollView...
846   ScrollView scrollView = ScrollView::New();
847   Stage::GetCurrent().Add( scrollView );
848   Vector2 stageSize = Stage::GetCurrent().GetSize();
849   scrollView.SetSize(stageSize);
850   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
851   scrollView.SetRefreshInterval(0);
852   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
853   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
854
855   // Position rulers.
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);
862   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
863   scrollView.ScrollClampedSignal().Connect( &OnScrollClamped );
864
865   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
866   Wait(application);
867
868   // Now do a pan starting from 100,100 and heading South-West
869   Vector2 pos(CLAMP_TOUCH_START);
870   SendPan(application, Gesture::Possible, pos);
871   SendPan(application, Gesture::Started, pos);
872   pos += CLAMP_TOUCH_MOVEMENT; // Move South-West a little
873   Wait(application);
874
875   int step = CLAMP_STEP_0_CHECK_NOTCLAMPED;
876   // Move 500,500 pixels South-West
877   // should be initially not clamped (0)
878   // then it should clamp against West boundary (X Min) (1)
879   // then it should clamp against South-West boundary (X Min, Y Max) (2)
880   gLastClampPosition.x = Toolkit::NotClamped;
881   gLastClampPosition.y = Toolkit::NotClamped;
882
883   for(int i = 0;i<CLAMP_GESTURE_FRAMES;i++)
884   {
885     SendPan(application, Gesture::Continuing, pos);
886     pos += CLAMP_TOUCH_MOVEMENT; // Move South-West a little
887     Wait(application);
888
889     if((gLastClampPosition.x == Toolkit::NotClamped) && (gLastClampPosition.y == Toolkit::NotClamped) && (step==CLAMP_STEP_0_CHECK_NOTCLAMPED))
890     {
891       step = CLAMP_STEP_1_CHECK_CLAMPED_WEST;
892     }
893     else if((gLastClampPosition.x == Toolkit::ClampedToMin) && (gLastClampPosition.y == Toolkit::NotClamped) && (step==CLAMP_STEP_1_CHECK_CLAMPED_WEST))
894     {
895       step = CLAMP_STEP_2_CHECK_CLAMPED_SOUTH_WEST;
896     }
897     else if((gLastClampPosition.x == Toolkit::ClampedToMin) && (gLastClampPosition.y == Toolkit::ClampedToMax) && (step==CLAMP_STEP_2_CHECK_CLAMPED_SOUTH_WEST))
898     {
899       step = CLAMP_STEP_3_SUCCESS;
900     }
901   }
902
903   SendPan(application, Gesture::Finished, pos);
904   Wait(application);
905
906   DALI_TEST_CHECK( gOnScrollClampedCalled );
907   DALI_TEST_EQUALS( step, CLAMP_STEP_3_SUCCESS, TEST_LOCATION );
908 }
909
910 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
911 {
912   gOnScrollStartCalled = false;
913   gOnScrollUpdateCalled = false;
914   gOnScrollCompleteCalled = false;
915   gOnSnapStartCalled = false;
916
917   // Now do a pan starting from (start) and heading (direction)
918   Vector2 pos(start);
919   SendPan(application, Gesture::Possible, pos);
920   SendPan(application, Gesture::Started, pos);
921   Wait(application);
922
923   for(int i = 0;i<frames;i++)
924   {
925     pos += direction; // Move in this direction
926     SendPan(application, Gesture::Continuing, pos);
927     Wait(application);
928   }
929
930   if(finish)
931   {
932     pos += direction; // Move in this direction.
933     SendPan(application, Gesture::Finished, pos);
934     Wait(application, RENDER_DELAY_SCROLL);
935   }
936
937   return pos;
938 }
939
940 static void UtcDaliScrollViewScrollSensitive()
941 {
942   ToolkitTestApplication application;
943   tet_infoline(" UtcDaliScrollViewScrollSensitive");
944
945   // Set up a scrollView...
946   ScrollView scrollView = ScrollView::New();
947   Stage::GetCurrent().Add( scrollView );
948   Vector2 stageSize = Stage::GetCurrent().GetSize();
949   scrollView.SetSize(stageSize);
950   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
951   scrollView.SetRefreshInterval(0);
952   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
953   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
954
955   // Position rulers.
956   RulerPtr rulerX = new DefaultRuler();
957   RulerPtr rulerY = new DefaultRuler();
958   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
959   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
960   scrollView.SetRulerX(rulerX);
961   scrollView.SetRulerY(rulerY);
962   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
963   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
964   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
965   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
966
967   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
968   Wait(application);
969
970   // First try insensitive swipe.
971   scrollView.SetScrollSensitive(false);
972   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
973
974   DALI_TEST_CHECK( !gOnScrollStartCalled );
975   DALI_TEST_CHECK( !gOnScrollUpdateCalled );
976   DALI_TEST_CHECK( !gOnScrollCompleteCalled );
977   DALI_TEST_CHECK( !gOnSnapStartCalled );
978
979   // Second try sensitive swipe.
980   scrollView.SetScrollSensitive(true);
981   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
982
983   DALI_TEST_CHECK( gOnScrollStartCalled );
984   DALI_TEST_CHECK( gOnScrollUpdateCalled );
985   DALI_TEST_CHECK( gOnScrollCompleteCalled );
986   DALI_TEST_CHECK( gOnSnapStartCalled );
987 }
988
989 static void UtcDaliScrollViewTouchesRequired()
990 {
991   ToolkitTestApplication application;
992   tet_infoline(" UtcDaliScrollViewTouchesRequired");
993
994   // Set up a scrollView...
995   ScrollView scrollView = ScrollView::New();
996   Stage::GetCurrent().Add( scrollView );
997   Vector2 stageSize = Stage::GetCurrent().GetSize();
998   scrollView.SetSize(stageSize);
999   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1000   scrollView.SetRefreshInterval(0);
1001   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1002   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1003
1004   // Position rulers.
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);
1011   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1012   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1013   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1014   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1015
1016   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1017   Wait(application);
1018
1019   // First try touches required being a minimum and maximum of 2.
1020   scrollView.SetTouchesRequiredForPanning(2, 2, true);
1021   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
1022
1023   DALI_TEST_CHECK( !gOnScrollStartCalled );
1024   DALI_TEST_CHECK( !gOnScrollUpdateCalled );
1025   DALI_TEST_CHECK( !gOnScrollCompleteCalled );
1026   DALI_TEST_CHECK( !gOnSnapStartCalled );
1027
1028   // Second try touches required being a minimum and maximum of 1.
1029   scrollView.SetTouchesRequiredForPanning(1, 1, true);
1030   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
1031
1032   DALI_TEST_CHECK( gOnScrollStartCalled );
1033   DALI_TEST_CHECK( gOnScrollUpdateCalled );
1034   DALI_TEST_CHECK( gOnScrollCompleteCalled );
1035   DALI_TEST_CHECK( gOnSnapStartCalled );
1036 }
1037
1038 static void UtcDaliScrollViewAxisAutoLock()
1039 {
1040   ToolkitTestApplication application;
1041   tet_infoline(" UtcDaliScrollViewAxisAutoLock");
1042
1043   // Set up a scrollView...
1044   ScrollView scrollView = ScrollView::New();
1045   Stage::GetCurrent().Add( scrollView );
1046   Vector2 stageSize = Stage::GetCurrent().GetSize();
1047   scrollView.SetSize(stageSize);
1048   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1049   scrollView.SetRefreshInterval(0);
1050   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1051   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1052
1053   // Position rulers.
1054   RulerPtr rulerX = new DefaultRuler();
1055   RulerPtr rulerY = new DefaultRuler();
1056   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1057   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1058   scrollView.SetRulerX(rulerX);
1059   scrollView.SetRulerY(rulerY);
1060   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1061   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1062   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1063
1064   // Normal
1065   scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
1066   Wait(application);
1067   Vector3 startPosition = scrollView.GetCurrentScrollPosition();
1068   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
1069   const Vector3 positionAfterNormal = scrollView.GetCurrentScrollPosition();
1070
1071   // Autolock
1072   scrollView.SetAxisAutoLock(true);
1073   DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
1074
1075   scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
1076   Wait(application);
1077   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
1078   const Vector3 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
1079
1080   // compare how much the Y position has deviated for normal and autolock.
1081   const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
1082   const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
1083
1084   // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
1085   DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
1086
1087   scrollView.SetAxisAutoLock(false);
1088   DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
1089 }
1090
1091 static void UtcDaliScrollViewAxisAutoLockGradient()
1092 {
1093   ToolkitTestApplication application;
1094   tet_infoline(" UtcDaliScrollViewAxisAutoLockGradient");
1095
1096   // Set up a scrollView...
1097   ScrollView scrollView = ScrollView::New();
1098   scrollView.SetAxisAutoLockGradient(0.5f);
1099   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
1100   scrollView.SetAxisAutoLockGradient(1.0f);
1101   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
1102 }
1103
1104 static void UtcDaliScrollViewConstraints()
1105 {
1106   ToolkitTestApplication application;
1107   tet_infoline(" UtcDaliScrollViewConstraints");
1108
1109   // Set up a scrollView...
1110   ScrollView scrollView = ScrollView::New();
1111   Stage::GetCurrent().Add( scrollView );
1112   Vector2 stageSize = Stage::GetCurrent().GetSize();
1113   scrollView.SetSize(stageSize);
1114   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1115   scrollView.SetRefreshInterval(0);
1116   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1117   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1118
1119   // Position rulers.
1120   RulerPtr rulerX = new DefaultRuler();
1121   RulerPtr rulerY = new DefaultRuler();
1122   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1123   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1124   scrollView.SetRulerX(rulerX);
1125   scrollView.SetRulerY(rulerY);
1126
1127   // Add an Actor to ScrollView,
1128   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1129   gConstraintResult = Vector3::ZERO;
1130   Actor a = Actor::New();
1131   scrollView.Add(a);
1132   a.SetPosition( TEST_ACTOR_POSITION );
1133   Wait(application);
1134
1135   Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
1136   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1137                                                        Source(scrollView, scrollPositionProperty),
1138                                                        TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1139   constraint.SetRemoveAction(Constraint::Discard);
1140   scrollView.ApplyConstraintToChildren(constraint);
1141   Wait(application);
1142
1143   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1144
1145   gConstraintResult = Vector3::ZERO;
1146   scrollView.RemoveConstraintsFromChildren();
1147   Wait(application);
1148
1149   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1150 }
1151
1152 static void UtcDaliScrollViewBind()
1153 {
1154   ToolkitTestApplication application;
1155   tet_infoline(" UtcDaliScrollViewBind");
1156
1157   // Set up a scrollView...
1158   ScrollView scrollView = ScrollView::New();
1159   Stage::GetCurrent().Add( scrollView );
1160   Vector2 stageSize = Stage::GetCurrent().GetSize();
1161   scrollView.SetSize(stageSize);
1162   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1163   scrollView.SetRefreshInterval(0);
1164   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1165   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1166
1167   // Position rulers.
1168   RulerPtr rulerX = new DefaultRuler();
1169   RulerPtr rulerY = new DefaultRuler();
1170   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1171   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1172   scrollView.SetRulerX(rulerX);
1173   scrollView.SetRulerY(rulerY);
1174
1175   // Add an Actor to ScrollView,
1176   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1177
1178   gConstraintResult = Vector3::ZERO;
1179   Actor a = Actor::New();
1180   scrollView.Add(a);
1181   a.SetPosition( TEST_ACTOR_POSITION );
1182   Wait(application);
1183
1184   Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
1185   // apply this constraint to scrollview
1186   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1187                                                        Source(scrollView, scrollPositionProperty),
1188                                                        TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1189
1190   constraint.SetRemoveAction(Constraint::Discard);
1191   scrollView.ApplyConstraintToChildren(constraint);
1192
1193   Wait(application);
1194   // Defaulty Bound.
1195   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1196
1197   // UnBind
1198   gConstraintResult = Vector3::ZERO;
1199   scrollView.UnbindActor( a );
1200   Wait(application);
1201   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1202
1203   // Bind
1204   gConstraintResult = Vector3::ZERO;
1205   scrollView.BindActor( a );
1206   Wait(application);
1207   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1208 }
1209
1210 static void UtcDaliRulerEnableDisable()
1211 {
1212   ToolkitTestApplication application;
1213   tet_infoline(" UtcDaliRulerEnableDisable");
1214
1215   RulerPtr ruler = new DefaultRuler();
1216
1217   DALI_TEST_CHECK( ruler->IsEnabled() );
1218   ruler->Disable();
1219   DALI_TEST_CHECK( !ruler->IsEnabled() );
1220   ruler->Enable();
1221   DALI_TEST_CHECK( ruler->IsEnabled() );
1222 }
1223
1224 static void UtcDaliRulerDomainEnableDisable()
1225 {
1226   ToolkitTestApplication application;
1227   tet_infoline(" UtcDaliRulerDomainEnableDisable");
1228
1229   RulerPtr ruler = new DefaultRuler();
1230   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1231
1232
1233   ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
1234   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
1235   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
1236   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
1237
1238   ruler->DisableDomain();
1239   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1240   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
1241   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
1242 }
1243
1244 static void UtcDaliRulerSnapAndClamp()
1245 {
1246   ToolkitTestApplication application;
1247   tet_infoline(" UtcDaliRulerSnapAndClamp");
1248
1249   RulerPtr ruler = new FixedRuler( 50.0f );
1250   ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1251
1252   // default testing. (snap and clamp)
1253   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
1254   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
1255   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
1256   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
1257   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
1258   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
1259
1260   // bias testing.
1261   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1262   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
1263   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1264
1265   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1266   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
1267   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1268
1269   // length testing.
1270   DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
1271   DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
1272   DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
1273   DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
1274   DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
1275
1276   // scale testing.
1277   DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
1278   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
1279   DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
1280   DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
1281
1282   // clamp state testing.
1283   ClampState clamped;
1284   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1285   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1286   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1287   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1288   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1289   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1290   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1291   DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
1292   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1293   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1294   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1295   DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
1296 }
1297
1298 static void UtcDaliRulerFixedRulerSpacing()
1299 {
1300   ToolkitTestApplication application;
1301   tet_infoline(" UtcDaliRulerFixedRulerSpacing");
1302
1303   RulerPtr rulerZero = new FixedRuler( 0.0f );
1304   rulerZero->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1305
1306   RulerPtr rulerNormal = new FixedRuler( 25.0f );
1307   rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1308
1309   unsigned int volume;
1310   float position;
1311
1312   position = rulerZero->GetPositionFromPage(1, volume, true);
1313   DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1314   DALI_TEST_EQUALS( volume, 1u, TEST_LOCATION );
1315
1316   position = rulerNormal->GetPositionFromPage(1, volume, true);
1317   DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
1318   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1319
1320   position = rulerZero->GetPositionFromPage(2, volume, true);
1321   DALI_TEST_EQUALS( position, 10.0f, TEST_LOCATION );
1322   DALI_TEST_EQUALS( volume, 2u, TEST_LOCATION );
1323
1324   position = rulerNormal->GetPositionFromPage(2, volume, true);
1325   DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
1326   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1327 }
1328
1329 static void UtcDaliScrollViewOvershoot()
1330 {
1331   ToolkitTestApplication application;
1332   tet_infoline(" UtcDaliScrollViewOvershoot");
1333
1334   // Set up a scrollView...
1335   ScrollView scrollView = ScrollView::New();
1336   Stage::GetCurrent().Add( scrollView );
1337   Vector2 stageSize = Stage::GetCurrent().GetSize();
1338   scrollView.SetSize(stageSize);
1339   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1340   scrollView.SetRefreshInterval(0);
1341   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1342   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1343
1344   // Position rulers.
1345   RulerPtr rulerX = new DefaultRuler();
1346   RulerPtr rulerY = new DefaultRuler();
1347   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1348   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1349   scrollView.SetRulerX(rulerX);
1350   scrollView.SetRulerY(rulerY);
1351   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1352   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1353   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1354
1355   scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1356   Wait(application);
1357
1358   // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1359   Vector2 currentPos = Vector2(100.0f, 100.0f);
1360   currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1361   Property::Index overshootXProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
1362   Property::Index overshootYProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
1363   Property::Index scrollPositionProperty = scrollView.GetPropertyIndex(ScrollView::SCROLL_POSITION_PROPERTY_NAME);
1364   float overshootXValue = scrollView.GetProperty<float>(overshootXProperty);
1365   float overshootYValue = scrollView.GetProperty<float>(overshootYProperty);
1366   Vector3 positionValue = scrollView.GetProperty<Vector3>(scrollPositionProperty);
1367   DALI_TEST_EQUALS(overshootXValue, -1.0f, TEST_LOCATION);
1368   DALI_TEST_EQUALS(overshootYValue, -1.0f, TEST_LOCATION);
1369   DALI_TEST_EQUALS(positionValue, Vector3::ZERO, TEST_LOCATION);
1370
1371   float timeToReachOrigin;
1372
1373   // Now release touch. Overshoot should snap back to zero.
1374   SendPan(application, Gesture::Finished, currentPos);
1375   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1376
1377   DALI_TEST_CHECK( (timeToReachOrigin > TEST_DEFAULT_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1378                    (timeToReachOrigin < TEST_DEFAULT_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1379
1380   // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1381   scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1382
1383   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1384   // Now release touch. Overshoot should snap back to zero.
1385   SendPan(application, Gesture::Finished, currentPos);
1386   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1387
1388   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1389                    (timeToReachOrigin < TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1390
1391   // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1392   scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1393
1394   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1395   // Now release touch. Overshoot should snap back to zero.
1396   SendPan(application, Gesture::Finished, currentPos);
1397   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1398
1399   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1400                    (timeToReachOrigin < TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1401
1402   // 4. Repeat Scroll, but this time change overshoot function.
1403   scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
1404
1405   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1406   // Now release touch. Overshoot should snap back to zero.
1407   SendPan(application, Gesture::Finished, currentPos);
1408   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1409
1410   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1411                    (timeToReachOrigin < TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1412 }
1413
1414 static void UtcDaliScrollViewSnapAlphaFunction()
1415 {
1416   ToolkitTestApplication application;
1417   tet_infoline(" UtcDaliScrollViewSnapAlphaFunction");
1418
1419   // Set up a scrollView...
1420   ScrollView scrollView = ScrollView::New();
1421   scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseIn );
1422   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseIn );
1423   scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseOut );
1424   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseOut );
1425
1426   scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::Bounce );
1427   DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::Bounce );
1428   scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::BounceBack );
1429   DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::BounceBack );
1430 }
1431
1432 static void UtcDaliScrollViewSnapDuration()
1433 {
1434   ToolkitTestApplication application;
1435   tet_infoline(" UtcDaliScrollViewSnapDuration");
1436
1437   // Set up a scrollView...
1438   ScrollView scrollView = ScrollView::New();
1439   scrollView.SetScrollSnapDuration( 1.0f );
1440   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1441   scrollView.SetScrollSnapDuration( 0.5f );
1442   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1443
1444   scrollView.SetScrollFlickDuration( 2.0f );
1445   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1446   scrollView.SetScrollFlickDuration( 1.5f );
1447   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1448 }
1449
1450 static void UtcDaliScrollViewSignalsSnapStart()
1451 {
1452   ToolkitTestApplication application;
1453   tet_infoline(" UtcDaliScrollViewSignalsSnapStart");
1454
1455   // Set up a scrollView...
1456   ScrollView scrollView = ScrollView::New();
1457   Stage::GetCurrent().Add( scrollView );
1458   Vector2 stageSize = Stage::GetCurrent().GetSize();
1459   scrollView.SetSize(stageSize);
1460   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1461   scrollView.SetRefreshInterval(0);
1462   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1463   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1464
1465   // Position rulers.
1466   RulerPtr rulerX = new DefaultRuler();
1467   RulerPtr rulerY = new DefaultRuler();
1468   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1469   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1470   scrollView.SetRulerX(rulerX);
1471   scrollView.SetRulerY(rulerY);
1472   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1473
1474   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1475   Wait(application);
1476
1477   DALI_TEST_CHECK( !gOnSnapStartCalled );
1478
1479   // First try a snap.
1480   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1481
1482   DALI_TEST_CHECK( gOnSnapStartCalled );
1483   DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1484
1485   // Second try a swipe.
1486   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1487
1488   DALI_TEST_CHECK( gOnSnapStartCalled );
1489   DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1490 }
1491
1492 static void UtcDaliScrollViewUIComponent()
1493 {
1494   ToolkitTestApplication application;
1495   tet_infoline(" UtcDaliScrollViewUIComponent");
1496
1497   // Set up a scrollView...
1498   ScrollView scrollView = ScrollView::New();
1499   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1500   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1501   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1502
1503   scrollView.EnableScrollComponent( Scrollable::VerticalScrollBar );
1504   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1505   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1506   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1507
1508   scrollView.EnableScrollComponent( Scrollable::HorizontalScrollBar );
1509   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1510   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1511   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1512
1513   scrollView.EnableScrollComponent( Scrollable::OvershootIndicator );
1514   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1515   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1516   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1517
1518   scrollView.DisableScrollComponent( Scrollable::VerticalScrollBar );
1519   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1520   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1521   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1522
1523   scrollView.DisableScrollComponent( Scrollable::HorizontalScrollBar );
1524   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1525   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1526   DALI_TEST_CHECK( scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1527
1528   scrollView.DisableScrollComponent( Scrollable::OvershootIndicator );
1529   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::HorizontalScrollBar) );
1530   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::VerticalScrollBar) );
1531   DALI_TEST_CHECK( !scrollView.IsScrollComponentEnabled(Scrollable::OvershootIndicator) );
1532
1533   // Create scroll bar
1534   ScrollBar scrollBar = ScrollBar::New(scrollView, true);
1535   scrollBar.Show();
1536   scrollBar.Hide();
1537
1538   // Check downcast
1539   const ScrollBar scrollBarVertical = ScrollBar(scrollBar);
1540   BaseHandle handle(scrollBarVertical);
1541
1542   ScrollBar newScrollBar = ScrollBar::DownCast( handle );
1543   DALI_TEST_CHECK( scrollBarVertical );
1544   DALI_TEST_CHECK( newScrollBar == scrollBarVertical );
1545
1546   ScrollComponent scrollComponent = ScrollComponent(scrollBarVertical);
1547   handle = scrollComponent;
1548
1549   ScrollComponent newScrollComponent = ScrollComponent::DownCast( handle );
1550   DALI_TEST_CHECK( scrollComponent );
1551   DALI_TEST_CHECK( scrollComponent == scrollComponent );
1552 }
1553
1554 static void UtcDaliScrollViewSetMouseWheelScrollDistanceStep()
1555 {
1556   ToolkitTestApplication application;
1557   tet_infoline(" UtcDaliScrollViewSetMouseWheelScrollDistanceStep");
1558
1559   ScrollView scrollView = ScrollView::New();
1560   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1561   scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1562   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1563   scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1564   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1565 }
1566
1567 static void UtcDaliScrollViewGetSet()
1568 {
1569   ToolkitTestApplication application;
1570   tet_infoline(" UtcDaliScrollViewGetSet");
1571   ScrollView scrollView = ScrollView::New();
1572   scrollView.SetMaxOvershoot(50.0f, 50.0f);
1573   scrollView.SetMaxFlickSpeed(0.5f);
1574   DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1575   scrollView.SetFrictionCoefficient(0.6f);
1576   DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1577   scrollView.SetFlickSpeedCoefficient(0.7f);
1578   DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1579 }