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