Added test cases for ScrollView
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ScrollView.cpp
1 /*
2  * Copyright (c) 2015 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 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 void scroll_view_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void scroll_view_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40 static bool gObjectCreatedCallBackCalled;
41
42 static void TestCallback(BaseHandle handle)
43 {
44   gObjectCreatedCallBackCalled = true;
45 }
46
47
48 const int MILLISECONDS_PER_SECOND = 1000;
49 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
50 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000;             ///< 1000ms to test animation
51 const int RENDER_DELAY_SCROLL = 1000;                           ///< duration to wait for any scroll to complete.
52
53 // For Clamp Signal testing...
54 const float CLAMP_EXCESS_WIDTH = 200.0f;                        ///< Amount of width that can be panned outside scrollview
55 const float CLAMP_EXCESS_HEIGHT = 200.0f;                       ///< Amount of height that can be panned outside scrollview
56 const int CLAMP_STEP_0_CHECK_NOTCLAMPED = 0;                    ///< FSM: "First check that scrollview isn't clamped"
57 const int CLAMP_STEP_1_CHECK_CLAMPED_WEST = 1;                  ///< FSM: "Next check that scrollview clamps against left side"
58 const int CLAMP_STEP_2_CHECK_CLAMPED_SOUTH_WEST = 2;            ///< FSM: "Then check that scrollview clamps against bottom-left side"
59 const int CLAMP_STEP_3_SUCCESS = 3;                             ///< FSM: "Finished (Success)"
60 const Vector2 CLAMP_START_SCROLL_POSITION(30.0f, 100.0f);       ///< Scroll start position for the Clamping tests.
61 const Vector2 CLAMP_TOUCH_START( 100.0f, 100.0f );              ///< Start point to touch from for the Clamping tests.
62 const Vector2 CLAMP_TOUCH_MOVEMENT( 5.0f, -5.0f );              ///< Amount to move touch for each frame for the Clamping tests.
63 const int CLAMP_GESTURE_FRAMES = 100;                           ///< Number of Frames to synthesize a gesture for the Clamping tests.
64 const Vector3 TEST_ACTOR_POSITION(100.0f, 100.0f, 0.0f);        ///< A Test actor position offset (arbitrary value)
65 const Vector3 TEST_CONSTRAINT_OFFSET(1.0f, 2.0f, 0.0f);         ///< A Test constraint offset (arbitrary value to test effects)
66 const float TEST_RATIO_TOLERANCE = 0.05;                        ///< +/-5% tolerance for ratio comparisons.
67
68 const float DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);                  ///< Default overshoot snapping animation time.
69 const float DEFAULT_MAX_OVERSHOOT(100.0f);                          ///< Default maximum allowed overshoot in pixels
70
71 const int MAX_FRAMES_TO_TEST_OVERSHOOT = 600;                       ///< 10 seconds (at 60 frames per second).
72 const Vector2 OVERSHOOT_START_SCROLL_POSITION(100.0f, 100.0f);       ///< Scroll start position for the Overshoot tests.
73 const float SCROLL_ANIMATION_DURATION(0.33f);                       ///< Duration of scroll animation in Overshoot tests (i.e. 100 pixels of overshoot in the speed of 500 pixels per 100 frames, 100/(500/(100/60)) = 0.33)
74 const Vector2 SNAP_POSITION_WITH_DECELERATED_VELOCITY(74.0f, 74.0f); ///< the snap position for Overshoot tests with the decelerated velocity (i.e. Decelerated from 500 pixels per 100 frames).
75 const float TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION = 0.05f;           ///< a Test duration
76 const float TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION = 1.5f;            ///< another Test duration
77 const float TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION = TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * 0.5f; // Same as above, but different alpha function.
78 const float TIME_TOLERANCE = 0.05f;                                 ///< Allow testing tolerance between a 10th of second (+/- 3 frames)
79
80
81 // Generate a PanGestureEvent to send to Core
82 Integration::PanGestureEvent GeneratePan(
83     Gesture::State state,
84     const Vector2& previousPosition,
85     const Vector2& currentPosition,
86     unsigned long timeDelta,
87     unsigned int numberOfTouches = 1)
88 {
89   Integration::PanGestureEvent pan(state);
90
91   pan.previousPosition = previousPosition;
92   pan.currentPosition = currentPosition;
93   pan.timeDelta = timeDelta;
94   pan.numberOfTouches = numberOfTouches;
95
96   return pan;
97 }
98
99 /**
100  * Helper to generate PanGestureEvent
101  *
102  * @param[in] application Application instance
103  * @param[in] state The Gesture State
104  * @param[in] pos The current position of touch.
105  */
106 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
107 {
108   static Vector2 last;
109
110   if( (state == Gesture::Started) ||
111       (state == Gesture::Possible) )
112   {
113     last.x = pos.x;
114     last.y = pos.y;
115   }
116
117   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
118
119   last.x = pos.x;
120   last.y = pos.y;
121 }
122
123 /*
124  * Simulate time passed by.
125  *
126  * @note this will always process at least 1 frame (1/60 sec)
127  *
128  * @param application Test application instance
129  * @param duration Time to pass in milliseconds.
130  * @return The actual time passed in milliseconds
131  */
132 int Wait(ToolkitTestApplication& application, int duration = 0)
133 {
134   int time = 0;
135
136   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
137   {
138     application.SendNotification();
139     application.Render(RENDER_FRAME_INTERVAL);
140     time += RENDER_FRAME_INTERVAL;
141   }
142
143   return time;
144 }
145
146 // Callback probes.
147
148 static bool gOnScrollStartCalled;                       ///< Whether the OnScrollStart signal was invoked.
149 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
150 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
151 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
152 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
153 static Vector3 gConstraintResult;                       ///< Result from constraint.
154
155 /**
156  * Invoked when scrolling starts.
157  *
158  * @param[in] position The current scroll position.
159  */
160 static void OnScrollStart( const Vector2& position )
161 {
162   gOnScrollStartCalled = true;
163 }
164
165 /**
166  * Invoked when scrolling updates (via dragging)
167  *
168  * @param[in] position The current scroll position.
169  */
170 static void OnScrollUpdate( const Vector2& position )
171 {
172   gOnScrollUpdateCalled = true;
173 }
174
175 /**
176  * Invoked when scrolling finishes
177  *
178  * @param[in] position The current scroll position.
179  */
180 static void OnScrollComplete( const Vector2& position )
181 {
182   gOnScrollCompleteCalled = true;
183 }
184
185 /**
186  * Invoked when a snap or flick started.
187  *
188  * @param[in] event The type of snap and the target position/scale/rotation.
189  */
190 static void OnSnapStart( const ScrollView::SnapEvent& event )
191 {
192   gOnSnapStartCalled = true;
193   gLastSnapType = event.type;
194 }
195
196 /**
197  * TestSumConstraint
198  *
199  * Summation of current value, property, and offset.
200  *
201  * current' = current + mOffset + property;
202  */
203 struct TestSumConstraint
204 {
205   /**
206    * @param[in] offset The offset to be added to current.
207    */
208   TestSumConstraint(const Vector3& offset)
209   :mOffset(offset)
210   {
211   }
212
213   /**
214    * @param[in] current The current base value
215    * @param[in] inputs Contains the property to be added to current.
216    * @return The new current Vector.
217    */
218   void operator()( Vector3& current, const PropertyInputContainer& inputs )
219   {
220     gConstraintResult = current + Vector3(inputs[0]->GetVector2()) + mOffset;
221     current = gConstraintResult;
222   }
223
224   Vector3 mOffset;
225
226 };
227
228 /**
229  * @param[in] application The application instance
230  * @param[in] scrollView The scrollView instance
231  * @return The time taken for the overshoot to reach origin (zero)
232  */
233 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
234 {
235   int timeToReachOrigin = -1;
236   for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
237   {
238     float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
239     float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
240     if(overshootXValue == 0.0f && overshootYValue == 0.0f)
241     {
242       break;
243     }
244
245     timeToReachOrigin += Wait(application);
246   }
247
248   return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
249 }
250
251 /**
252  * y = 2x alpha function, which is clamped between 0.0f - 1.0f
253  *
254  * Animations should appear to finish (reach 100% point)
255  * at just half the time of a regular Linear AlphaFunction.
256  *
257  * @param[in] progress value (ranges from 0.0f - 1.0f)
258  * @return interpolation value (ranges from 0.0f - 1.0f)
259  */
260 float TestAlphaFunction(float progress)
261 {
262   return std::min( progress * 2.0f, 1.0f );
263 }
264
265 } // unnamed namespace
266
267
268 int UtcDaliToolkitScrollViewConstructorP(void)
269 {
270   ToolkitTestApplication application;
271
272   ScrollView scrollView;
273   DALI_TEST_CHECK( !scrollView );
274   END_TEST;
275 }
276
277 int UtcDaliToolkitScrollViewCopyConstructorP(void)
278 {
279   ToolkitTestApplication application;
280
281   ScrollView scrollView = ScrollView::New();
282   scrollView.SetProperty( ScrollView::Property::SCROLL_POSITION, Vector2(10.0f, 10.0f) );
283
284   ScrollView copy( scrollView );
285   DALI_TEST_CHECK( copy );
286   DALI_TEST_CHECK( copy.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) == scrollView.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) );
287   END_TEST;
288 }
289
290 int UtcDaliToolkitScrollViewAssignmentOperatorP(void)
291 {
292   ToolkitTestApplication application;
293
294   ScrollView scrollView = ScrollView::New();
295   scrollView.SetProperty( ScrollView::Property::SCROLL_POSITION, Vector2(10.0f, 10.0f) );
296
297   ScrollView copy = scrollView;
298   DALI_TEST_CHECK( copy );
299   DALI_TEST_CHECK( copy.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) == scrollView.GetProperty<Vector2>( ScrollView::Property::SCROLL_POSITION ) );
300   END_TEST;
301 }
302
303 int UtcDaliScrollViewDestructorP(void)
304 {
305   ToolkitTestApplication application;
306
307   ScrollView* scrollView = new ScrollView();
308   delete scrollView;
309
310   DALI_TEST_CHECK( true );
311   END_TEST;
312 }
313
314 int UtcDaliToolkitScrollViewNewP(void)
315 {
316   ToolkitTestApplication application;
317   tet_infoline(" UtcDaliToolkitScrollViewNewP");
318
319   ScrollView scrollView;
320
321   DALI_TEST_CHECK( !scrollView );
322
323   scrollView = ScrollView::New();
324
325   DALI_TEST_CHECK( scrollView );
326
327   ScrollView scrollView2(scrollView);
328
329   DALI_TEST_CHECK( scrollView2 == scrollView );
330
331   //Additional check to ensure object is created by checking if it's registered
332   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
333   DALI_TEST_CHECK( registry );
334
335   gObjectCreatedCallBackCalled = false;
336   registry.ObjectCreatedSignal().Connect( &TestCallback );
337   {
338     ScrollView scrollView = ScrollView::New();
339   }
340   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
341   END_TEST;
342 }
343
344 int UtcDaliToolkitScrollViewDownCastP(void)
345 {
346   ToolkitTestApplication application;
347   tet_infoline(" UtcDaliToolkitScrollViewDownCastP");
348
349   ScrollView scrollView = ScrollView::New();
350   BaseHandle handle(scrollView);
351
352   ScrollView newScrollView = ScrollView::DownCast( handle );
353   DALI_TEST_CHECK( scrollView );
354   DALI_TEST_CHECK( newScrollView == scrollView );
355   END_TEST;
356 }
357
358 int UtcDaliToolkitScrollViewScrollToPositionP(void)
359 {
360   ToolkitTestApplication application;
361   tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionP");
362
363   // Create the ScrollView actor
364   ScrollView scrollView = ScrollView::New();
365   Stage::GetCurrent().Add( scrollView );
366
367   const Vector2 target = Vector2(100.0f, 200.0f);
368   const Vector2 target2 = Vector2(300.0f, 100.0f);
369
370   scrollView.ScrollTo( target, 0.0f );
371   Wait(application);
372   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
373   scrollView.ScrollTo( target2 );
374   Wait(application, RENDER_DELAY_SCROLL);
375   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
376
377   END_TEST;
378 }
379
380 int UtcDaliToolkitScrollViewScrollToPositionWithDirectionBiasP(void)
381 {
382   ToolkitTestApplication application;
383   tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithDirectionBiasP");
384
385   ScrollView scrollView = ScrollView::New();
386   Stage::GetCurrent().Add( scrollView );
387   RulerPtr rulerX = new FixedRuler( 100.0f );
388   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
389   RulerPtr rulerY = new FixedRuler( 100.0f );
390   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
391
392   scrollView.SetRulerX( rulerX );
393   scrollView.SetRulerY( rulerY );
394
395   scrollView.SetWrapMode(true);
396
397   const Vector2 target = Vector2(50.0f, 50.0f);
398   const Vector2 target2 = Vector2(150.0f, 150.0f);
399
400   scrollView.ScrollTo( target, 0.0f );
401   Wait(application, RENDER_DELAY_SCROLL);
402   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
403
404   scrollView.ScrollTo( target2, 0.25f, Dali::Toolkit::DirectionBiasLeft, Dali::Toolkit::DirectionBiasLeft );
405   Wait(application, RENDER_DELAY_SCROLL);
406   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2::ZERO, TEST_LOCATION );
407
408   scrollView.ScrollTo( target, 0.0f );
409   Wait(application, RENDER_DELAY_SCROLL);
410   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
411
412   scrollView.ScrollTo( target2, 0.25f, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
413   Wait(application, RENDER_DELAY_SCROLL);
414   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
415
416   END_TEST;
417 }
418
419 int UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionP(void)
420 {
421   ToolkitTestApplication application;
422   tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionP");
423
424   // Create the ScrollView actor
425   ScrollView scrollView = ScrollView::New();
426   Stage::GetCurrent().Add( scrollView );
427
428   const Vector2 target = Vector2(100.0f, 200.0f);
429   const Vector2 target2 = Vector2(300.0f, 100.0f);
430
431   scrollView.ScrollTo( target, 0.5f, TestAlphaFunction );
432   Wait(application, 250);
433   // Check that the scroll animation should finish within just half of the specified duration with the above alpha function
434   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
435
436   scrollView.ScrollTo( target2, 0.5f, AlphaFunction::LINEAR );
437   Wait(application, 250);
438   // Check that the scroll animation has not finished within half of the specified duration with the linear alpha function
439   DALI_TEST_CHECK( scrollView.GetCurrentScrollPosition() != target2 );
440
441   // Wait till the end of the specified duration
442   Wait(application, 250);
443   // Check that the scroll animation has finished
444   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
445
446   END_TEST;
447 }
448
449 int UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionAndDirectionBiasP(void)
450 {
451   ToolkitTestApplication application;
452   tet_infoline(" UtcDaliToolkitScrollViewScrollToPositionWithAlphaFunctionAndDirectionBiasP");
453
454   ScrollView scrollView = ScrollView::New();
455   Stage::GetCurrent().Add( scrollView );
456   RulerPtr rulerX = new FixedRuler( 100.0f );
457   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
458   RulerPtr rulerY = new FixedRuler( 100.0f );
459   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
460
461   scrollView.SetRulerX( rulerX );
462   scrollView.SetRulerY( rulerY );
463
464   scrollView.SetWrapMode(true);
465
466   const Vector2 target = Vector2(50.0f, 50.0f);
467   const Vector2 target2 = Vector2(150.0f, 150.0f);
468
469   scrollView.ScrollTo( target, 0.0f );
470   Wait(application, RENDER_DELAY_SCROLL);
471   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
472
473   scrollView.ScrollTo( target2, 0.25f, AlphaFunction::LINEAR, Dali::Toolkit::DirectionBiasLeft, Dali::Toolkit::DirectionBiasLeft );
474   Wait(application, RENDER_DELAY_SCROLL);
475   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2::ZERO, TEST_LOCATION );
476
477   scrollView.ScrollTo( target, 0.0f );
478   Wait(application, RENDER_DELAY_SCROLL);
479   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
480
481   scrollView.ScrollTo( target2, 0.25f, AlphaFunction::LINEAR, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
482   Wait(application, RENDER_DELAY_SCROLL);
483   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
484
485   scrollView.ScrollTo( target, 0.0f );
486   Wait(application, RENDER_DELAY_SCROLL);
487   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
488
489   scrollView.ScrollTo( target2, 0.25f, TestAlphaFunction, Dali::Toolkit::DirectionBiasRight, Dali::Toolkit::DirectionBiasRight );
490   Wait(application, 125);
491   // Check that the scroll animation should finish within just half of the specified duration with the above alpha function
492   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
493
494   END_TEST;
495 }
496
497 int UtcDaliToolkitScrollViewScrollToPageP(void)
498 {
499   ToolkitTestApplication application;
500   tet_infoline(" UtcDaliToolkitScrollViewScrollToPageP");
501
502   ScrollView scrollView = ScrollView::New();
503   Stage::GetCurrent().Add( scrollView );
504   RulerPtr rulerX = new FixedRuler( 100.0f );
505   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
506   RulerPtr rulerY = new FixedRuler( 100.0f );
507   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
508
509   scrollView.SetRulerX( rulerX );
510   scrollView.SetRulerY( rulerY );
511
512   scrollView.ScrollTo( 1, 0.0f );
513   Wait(application);
514   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 0.0f), TEST_LOCATION );
515
516   scrollView.ScrollTo( 5, 0.0f );
517   Wait(application);
518   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(500.0f, 0.0f), TEST_LOCATION );
519
520   scrollView.ScrollTo( 10, 0.0f );
521   Wait(application);
522   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(200.0f, 100.0f), TEST_LOCATION );
523
524   scrollView.ScrollTo( 15, 0.0f );
525   Wait(application);
526   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(700.0f, 100.0f), TEST_LOCATION );
527   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
528
529   scrollView.ScrollTo( 3 );
530   Wait(application, RENDER_DELAY_SCROLL);
531   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(300.0f, 0.0f), TEST_LOCATION );
532   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
533
534   scrollView.ScrollTo( 9 );
535   Wait(application, RENDER_DELAY_SCROLL);
536   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 100.0f), TEST_LOCATION );
537   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
538
539   // Apply DefaultRulers instead and see what happens.
540   rulerX = new DefaultRuler();
541   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
542   rulerY = new DefaultRuler();
543   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
544
545   scrollView.SetRulerX( rulerX );
546   scrollView.SetRulerY( rulerY );
547
548   // This time should always scroll to origin (0.0f, 0.0f)
549   scrollView.ScrollTo( 1, 0.0f );
550   Wait(application);
551   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
552   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
553
554   END_TEST;
555 }
556
557 int UtcDaliToolkitScrollViewScrollToPageWithDirectionBiasP(void)
558 {
559   ToolkitTestApplication application;
560   tet_infoline(" UtcDaliToolkitScrollViewScrollToPageWithDirectionBiasP");
561
562   ScrollView scrollView = ScrollView::New();
563   Stage::GetCurrent().Add( scrollView );
564   RulerPtr rulerX = new FixedRuler( 100.0f );
565   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, true) );
566   RulerPtr rulerY = new FixedRuler( 100.0f );
567   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
568
569   scrollView.SetRulerX( rulerX );
570   scrollView.SetRulerY( rulerY );
571
572   scrollView.SetWrapMode(true);
573
574   scrollView.ScrollTo( 0, 0.25, Dali::Toolkit::DirectionBiasLeft );
575
576   Wait(application, RENDER_FRAME_INTERVAL); // Wait for one frame
577   // Check that the scroll position remains the same
578   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
579
580   Wait(application, RENDER_DELAY_SCROLL); // Wait for one second
581   // Check that it stays at the same page (i.e. the same scroll position)
582   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
583   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
584
585   scrollView.ScrollTo( 0, 0.25, Dali::Toolkit::DirectionBiasRight );
586
587   Wait(application, RENDER_FRAME_INTERVAL); // Wait for one frame
588   // Check that it scrolls towards the right
589   DALI_TEST_CHECK( scrollView.GetCurrentScrollPosition().x > 0.0f );
590
591   Wait(application, RENDER_DELAY_SCROLL); // Wait for one second
592   // Check that it scrolls back to the same page (i.e. the same scroll position)
593   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
594   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 0.0f), TEST_LOCATION );
595
596   END_TEST;
597 }
598
599 int UtcDaliToolkitScrollViewScrollToActorP(void)
600 {
601   ToolkitTestApplication application;
602   tet_infoline(" UtcDaliToolkitScrollViewScrollToActorP");
603
604   ScrollView scrollView = ScrollView::New();
605   Stage::GetCurrent().Add( scrollView );
606
607   Actor actorA = Actor::New();
608   const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
609   actorA.SetPosition(positionA);
610   scrollView.Add(actorA);
611
612   Actor actorB = Actor::New();
613   const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
614   actorB.SetPosition(positionB);
615   scrollView.Add(actorB);
616
617   Wait(application);
618
619   scrollView.ScrollTo(actorA, 0.0f);
620   Wait(application);
621   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA.GetVectorXY(), TEST_LOCATION );
622
623   Wait(application);
624   scrollView.ScrollTo(actorB, 0.0f);
625   Wait(application);
626   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB.GetVectorXY(), TEST_LOCATION );
627
628   scrollView.ScrollTo(actorA);
629   Wait(application, RENDER_DELAY_SCROLL);
630   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA.GetVectorXY(), TEST_LOCATION );
631
632   scrollView.ScrollTo(actorB);
633   Wait(application, RENDER_DELAY_SCROLL);
634   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB.GetVectorXY(), TEST_LOCATION );
635   END_TEST;
636 }
637
638 int UtcDaliToolkitScrollViewScrollToSnapPointP(void)
639 {
640   ToolkitTestApplication application;
641   tet_infoline(" UtcDaliToolkitScrollViewScrollToSnapPointP");
642
643   ScrollView scrollView = ScrollView::New();
644   Stage::GetCurrent().Add( scrollView );
645   RulerPtr rulerX = new FixedRuler( 100.0f );
646   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
647   RulerPtr rulerY = new FixedRuler( 100.0f );
648   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
649
650   scrollView.SetRulerX( rulerX );
651   scrollView.SetRulerY( rulerY );
652
653   scrollView.ScrollTo( Vector2(120.0f, 190.0f), 0.0f );
654   Wait(application);
655   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(120.0f, 190.0f), TEST_LOCATION );
656
657   scrollView.ScrollToSnapPoint();
658
659   Wait(application, RENDER_DELAY_SCROLL);
660   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 200.0f), TEST_LOCATION );
661   END_TEST;
662 }
663
664 int UtcDaliToolkitScrollViewSetScrollUpdateDistanceP(void)
665 {
666   ToolkitTestApplication application;
667   tet_infoline(" UtcDaliToolkitScrollViewSetScrollUpdateDistanceP");
668
669   ScrollView scrollView = ScrollView::New();
670
671   scrollView.SetScrollUpdateDistance(0);
672   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 0, TEST_LOCATION);
673   scrollView.SetScrollUpdateDistance(10);
674   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 10, TEST_LOCATION);
675   scrollView.SetScrollUpdateDistance(1000);
676   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 1000, TEST_LOCATION);
677   END_TEST;
678 }
679
680 int UtcDaliToolkitScrollViewSetWrapModeP(void)
681 {
682   ToolkitTestApplication application;
683   tet_infoline(" UtcDaliToolkitScrollViewSetWrapModeP");
684
685   ScrollView scrollView = ScrollView::New();
686   Stage::GetCurrent().Add( scrollView );
687
688   // Position rulers. 4x4 grid.
689   RulerPtr rulerX = new FixedRuler(50.0f);
690   RulerPtr rulerY = new FixedRuler(50.0f);
691   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
692   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
693   scrollView.SetRulerX(rulerX);
694   scrollView.SetRulerY(rulerY);
695
696   scrollView.SetWrapMode(false);
697   scrollView.ScrollTo(Vector2(225.0f, 125.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
698   Wait(application);
699   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
700   scrollView.SetWrapMode(true);
701   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
702   END_TEST;
703 }
704
705 int UtcDaliToolkitScrollViewActorAutoSnap(void)
706 {
707   ToolkitTestApplication application;
708   tet_infoline(" UtcDaliToolkitScrollViewActorAutoSnap");
709
710   ScrollView scrollView = ScrollView::New();
711   Stage::GetCurrent().Add( scrollView );
712
713   // Position rulers.
714   RulerPtr rulerX = new DefaultRuler();
715   RulerPtr rulerY = new DefaultRuler();
716   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
717   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
718   scrollView.SetRulerX(rulerX);
719   scrollView.SetRulerY(rulerY);
720
721   const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
722   Actor a = Actor::New();
723   scrollView.Add(a);
724   a.SetPosition(aPosition);
725
726   const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
727   Actor b = Actor::New();
728   scrollView.Add(b);
729   b.SetPosition(bPosition);
730
731   // Goto a random position, and execute snap (should not move)
732   Vector2 targetScroll = Vector2(500.0f, 500.0f);
733   scrollView.ScrollTo(targetScroll, 0.0f);
734   Wait(application);
735   scrollView.ScrollToSnapPoint();
736   Wait(application, RENDER_DELAY_SCROLL);
737   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
738
739   // Enable ActorAutoSnap, and now try snapping.
740   scrollView.SetActorAutoSnap(true);
741   scrollView.ScrollToSnapPoint();
742   Wait(application, RENDER_DELAY_SCROLL);
743   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition.GetVectorXY(), TEST_LOCATION );
744
745   scrollView.ScrollTo(Vector2(0.0f, 0.0f), 0.0f);
746   Wait(application);
747   scrollView.ScrollToSnapPoint();
748   Wait(application, RENDER_DELAY_SCROLL);
749   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition.GetVectorXY(), TEST_LOCATION );
750   END_TEST;
751 }
752
753 int UtcDaliToolkitScrollViewSignalsStartComplete(void)
754 {
755   ToolkitTestApplication application;
756   tet_infoline(" UtcDaliToolkitScrollViewSignalsStartComplete");
757
758   gOnScrollStartCalled = false;
759   gOnScrollCompleteCalled = false;
760
761   ScrollView scrollView = ScrollView::New();
762   Stage::GetCurrent().Add( scrollView );
763
764   // Position rulers.
765   RulerPtr rulerX = new DefaultRuler();
766   RulerPtr rulerY = new DefaultRuler();
767   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
768   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
769   scrollView.SetRulerX(rulerX);
770   scrollView.SetRulerY(rulerY);
771   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
772   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
773   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
774   scrollView.ScrollTo( Vector2(100.0f, 100.0f) );
775   Wait(application, RENDER_DELAY_SCROLL);
776
777   DALI_TEST_CHECK(gOnScrollStartCalled);
778   DALI_TEST_CHECK(gOnScrollCompleteCalled);
779   END_TEST;
780 }
781
782 int UtcDaliToolkitScrollViewSignalsUpdate(void)
783 {
784   ToolkitTestApplication application;
785   tet_infoline(" UtcDaliToolkitScrollViewSignalsUpdate");
786
787   gOnScrollStartCalled = false;
788   gOnScrollUpdateCalled = false;
789   gOnScrollCompleteCalled = false;
790
791   ScrollView scrollView = ScrollView::New();
792   Stage::GetCurrent().Add( scrollView );
793   Vector2 stageSize = Stage::GetCurrent().GetSize();
794   scrollView.SetSize(stageSize);
795   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
796   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
797
798   // Position rulers.
799   RulerPtr rulerX = new DefaultRuler();
800   RulerPtr rulerY = new DefaultRuler();
801   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
802   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
803   scrollView.SetRulerX(rulerX);
804   scrollView.SetRulerY(rulerY);
805   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
806   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
807   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
808
809   ImageActor image = CreateSolidColorActor( Color::RED );
810   image.SetSize(stageSize);
811   image.SetParentOrigin(ParentOrigin::TOP_LEFT);
812   image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
813   scrollView.Add(image);
814
815   Wait(application);
816
817   // Do a pan starting from 100,100 and moving down diagonally.
818   Vector2 pos(100.0f, 100.0f);
819   SendPan(application, Gesture::Possible, pos);
820   SendPan(application, Gesture::Started, pos);
821   pos.x += 5.0f;
822   pos.y += 5.0f;
823   Wait(application, 100);
824
825   for(int i = 0;i<20;i++)
826   {
827     SendPan(application, Gesture::Continuing, pos);
828     pos.x += 5.0f;
829     pos.y += 5.0f;
830     Wait(application);
831   }
832
833   SendPan(application, Gesture::Finished, pos);
834   Wait(application, RENDER_DELAY_SCROLL);
835
836   DALI_TEST_CHECK(gOnScrollStartCalled);
837   DALI_TEST_CHECK(gOnScrollUpdateCalled);
838   DALI_TEST_CHECK(gOnScrollCompleteCalled);
839   END_TEST;
840 }
841
842 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
843 {
844   gOnScrollStartCalled = false;
845   gOnScrollUpdateCalled = false;
846   gOnScrollCompleteCalled = false;
847   gOnSnapStartCalled = false;
848
849   // Now do a pan starting from (start) and heading (direction)
850   Vector2 pos(start);
851   SendPan(application, Gesture::Possible, pos);
852   SendPan(application, Gesture::Started, pos);
853   Wait(application);
854
855   for(int i = 0;i<frames;i++)
856   {
857     pos += direction; // Move in this direction
858     SendPan(application, Gesture::Continuing, pos);
859     Wait(application);
860   }
861
862   if(finish)
863   {
864     pos += direction; // Move in this direction.
865     SendPan(application, Gesture::Finished, pos);
866     Wait(application, RENDER_DELAY_SCROLL);
867   }
868
869   return pos;
870 }
871
872 int UtcDaliToolkitScrollViewScrollSensitive(void)
873 {
874   ToolkitTestApplication application;
875   tet_infoline(" UtcDaliToolkitScrollViewScrollSensitive");
876
877   // Set up a scrollView...
878   ScrollView scrollView = ScrollView::New();
879   Stage::GetCurrent().Add( scrollView );
880   Vector2 stageSize = Stage::GetCurrent().GetSize();
881   scrollView.SetSize(stageSize);
882   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
883   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
884
885   // Position rulers.
886   RulerPtr rulerX = new DefaultRuler();
887   RulerPtr rulerY = new DefaultRuler();
888   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
889   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
890   scrollView.SetRulerX(rulerX);
891   scrollView.SetRulerY(rulerY);
892   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
893   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
894   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
895   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
896
897   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
898   Wait(application);
899
900   // First try insensitive swipe.
901   scrollView.SetScrollSensitive(false);
902   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
903
904   DALI_TEST_CHECK( !gOnScrollStartCalled );
905   DALI_TEST_CHECK( !gOnScrollCompleteCalled );
906   DALI_TEST_CHECK( !gOnSnapStartCalled );
907
908   // Second try sensitive swipe.
909   scrollView.SetScrollSensitive(true);
910   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
911
912   DALI_TEST_CHECK( gOnScrollStartCalled );
913   DALI_TEST_CHECK( gOnScrollCompleteCalled );
914   DALI_TEST_CHECK( gOnSnapStartCalled );
915   END_TEST;
916 }
917
918 int UtcDaliToolkitScrollViewAxisAutoLock(void)
919 {
920   ToolkitTestApplication application;
921   tet_infoline(" UtcDaliToolkitScrollViewAxisAutoLock");
922
923   // Set up a scrollView...
924   ScrollView scrollView = ScrollView::New();
925   Stage::GetCurrent().Add( scrollView );
926   Vector2 stageSize = Stage::GetCurrent().GetSize();
927   scrollView.SetSize(stageSize);
928   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
929   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
930
931   // Position rulers.
932   RulerPtr rulerX = new DefaultRuler();
933   RulerPtr rulerY = new DefaultRuler();
934   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
935   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
936   scrollView.SetRulerX(rulerX);
937   scrollView.SetRulerY(rulerY);
938   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
939   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
940   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
941
942   // Normal
943   scrollView.ScrollTo(Vector2(100.0f, 100.0f), 0.0f); // move in a little.
944   Wait(application);
945   Vector2 startPosition = scrollView.GetCurrentScrollPosition();
946   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
947   const Vector2 positionAfterNormal = scrollView.GetCurrentScrollPosition();
948
949   // Autolock
950   scrollView.SetAxisAutoLock(true);
951   DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
952
953   scrollView.ScrollTo(Vector2(100.0f, 100.0f), 0.0f); // move in a little.
954   Wait(application);
955   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
956   const Vector2 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
957
958   // compare how much the Y position has deviated for normal and autolock.
959   const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
960   const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
961
962   // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
963   DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
964
965   scrollView.SetAxisAutoLock(false);
966   DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
967   END_TEST;
968 }
969
970 int UtcDaliToolkitScrollViewAxisAutoLockGradient(void)
971 {
972   ToolkitTestApplication application;
973   tet_infoline(" UtcDaliToolkitScrollViewAxisAutoLockGradient");
974
975   // Set up a scrollView...
976   ScrollView scrollView = ScrollView::New();
977   scrollView.SetAxisAutoLockGradient(0.5f);
978   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
979   scrollView.SetAxisAutoLockGradient(1.0f);
980   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
981   END_TEST;
982 }
983
984 int UtcDaliToolkitScrollViewConstraints(void)
985 {
986   ToolkitTestApplication application;
987   tet_infoline(" UtcDaliToolkitScrollViewConstraints");
988
989   // Set up a scrollView...
990   ScrollView scrollView = ScrollView::New();
991   Stage::GetCurrent().Add( scrollView );
992   Vector2 stageSize = Stage::GetCurrent().GetSize();
993   scrollView.SetSize(stageSize);
994   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
995   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
996
997   // Position rulers.
998   RulerPtr rulerX = new DefaultRuler();
999   RulerPtr rulerY = new DefaultRuler();
1000   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1001   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1002   scrollView.SetRulerX(rulerX);
1003   scrollView.SetRulerY(rulerY);
1004
1005   // Add an Actor to ScrollView,
1006   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1007   gConstraintResult = Vector3::ZERO;
1008   Actor a = Actor::New();
1009   scrollView.Add(a);
1010   a.SetPosition( TEST_ACTOR_POSITION );
1011   Wait(application);
1012
1013   Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1014   constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
1015   constraint.SetRemoveAction(Constraint::Discard);
1016   scrollView.ApplyConstraintToChildren(constraint);
1017   Wait(application);
1018
1019   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1020
1021   gConstraintResult = Vector3::ZERO;
1022   scrollView.RemoveConstraintsFromChildren();
1023   Wait(application);
1024
1025   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1026   END_TEST;
1027 }
1028
1029 int UtcDaliToolkitScrollViewBind(void)
1030 {
1031   ToolkitTestApplication application;
1032   tet_infoline(" UtcDaliToolkitScrollViewBind");
1033
1034   // Set up a scrollView...
1035   ScrollView scrollView = ScrollView::New();
1036   Stage::GetCurrent().Add( scrollView );
1037   Vector2 stageSize = Stage::GetCurrent().GetSize();
1038   scrollView.SetSize(stageSize);
1039   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1040   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1041
1042   // Position rulers.
1043   RulerPtr rulerX = new DefaultRuler();
1044   RulerPtr rulerY = new DefaultRuler();
1045   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1046   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1047   scrollView.SetRulerX(rulerX);
1048   scrollView.SetRulerY(rulerY);
1049
1050   // Add an Actor to ScrollView,
1051   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
1052
1053   gConstraintResult = Vector3::ZERO;
1054   Actor a = Actor::New();
1055   scrollView.Add(a);
1056   a.SetPosition( TEST_ACTOR_POSITION );
1057   Wait(application);
1058
1059   // apply this constraint to scrollview
1060   Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
1061   constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
1062   constraint.SetRemoveAction(Constraint::Discard);
1063   scrollView.ApplyConstraintToChildren(constraint);
1064
1065   Wait(application);
1066   // Defaulty Bound.
1067   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1068
1069   // UnBind
1070   gConstraintResult = Vector3::ZERO;
1071   scrollView.UnbindActor( a );
1072   Wait(application);
1073   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
1074
1075   // Bind
1076   gConstraintResult = Vector3::ZERO;
1077   scrollView.BindActor( a );
1078   Wait(application);
1079   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
1080   END_TEST;
1081 }
1082
1083 int UtcDaliToolkitScrollViewOvershoot(void)
1084 {
1085   ToolkitTestApplication application;
1086   tet_infoline(" UtcDaliToolkitScrollViewOvershoot");
1087
1088   // Set up a scrollView...
1089   ScrollView scrollView = ScrollView::New();
1090   Stage::GetCurrent().Add( scrollView );
1091   Vector2 stageSize = Stage::GetCurrent().GetSize();
1092   scrollView.SetSize(stageSize);
1093   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1094   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1095
1096   // Position rulers.
1097   RulerPtr rulerX = new DefaultRuler();
1098   RulerPtr rulerY = new DefaultRuler();
1099   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1100   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1101   scrollView.SetRulerX(rulerX);
1102   scrollView.SetRulerY(rulerY);
1103   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1104   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1105   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1106
1107   scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1108   Wait(application);
1109
1110   // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1111   Vector2 currentPos = Vector2(100.0f, 100.0f);
1112   currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1113   float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1114   float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1115   Vector2 positionValue = scrollView.GetProperty<Vector2>(ScrollView::Property::SCROLL_POSITION);
1116   DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1117   DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1118   DALI_TEST_EQUALS(positionValue, Vector2::ZERO, TEST_LOCATION);
1119
1120   float timeToReachOrigin;
1121
1122   // Now release touch. Overshoot should snap back to zero.
1123   SendPan(application, Gesture::Finished, currentPos);
1124   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1125
1126   float minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + DEFAULT_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1127   float maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + DEFAULT_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1128
1129   DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1130                    (timeToReachOrigin < maxTimeToReachOrigin) );
1131
1132   // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1133   scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1134
1135   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1136   // Now release touch. Overshoot should snap back to zero.
1137   SendPan(application, Gesture::Finished, currentPos);
1138   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1139
1140   minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1141   maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1142
1143   DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1144                    (timeToReachOrigin < maxTimeToReachOrigin) );
1145
1146   // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1147   scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1148
1149   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1150   // Now release touch. Overshoot should snap back to zero.
1151   SendPan(application, Gesture::Finished, currentPos);
1152   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1153
1154   minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1155   maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1156
1157   DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1158                    (timeToReachOrigin < maxTimeToReachOrigin) );
1159
1160   // 4. Repeat Scroll, but this time change overshoot function.
1161   scrollView.SetSnapOvershootDuration(TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION);
1162   scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
1163
1164   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1165   // Now release touch. Overshoot should snap back to zero.
1166   SendPan(application, Gesture::Finished, currentPos);
1167   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1168
1169   minTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) - TIME_TOLERANCE;
1170   maxTimeToReachOrigin = SCROLL_ANIMATION_DURATION + TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION * (SNAP_POSITION_WITH_DECELERATED_VELOCITY.x / DEFAULT_MAX_OVERSHOOT) + TIME_TOLERANCE;
1171
1172   DALI_TEST_CHECK( (timeToReachOrigin > minTimeToReachOrigin) &&
1173                    (timeToReachOrigin < maxTimeToReachOrigin) );
1174   END_TEST;
1175 }
1176
1177 int UtcDaliToolkitScrollViewSnapAlphaFunction(void)
1178 {
1179   ToolkitTestApplication application;
1180   tet_infoline(" UtcDaliToolkitScrollViewSnapAlphaFunction");
1181
1182   // Set up a scrollView...
1183   ScrollView scrollView = ScrollView::New();
1184   scrollView.SetScrollSnapAlphaFunction( AlphaFunction::EASE_IN );
1185   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction().GetBuiltinFunction() == AlphaFunction::EASE_IN );
1186   scrollView.SetScrollSnapAlphaFunction( AlphaFunction::EASE_OUT );
1187   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction().GetBuiltinFunction() == AlphaFunction::EASE_OUT );
1188
1189   scrollView.SetScrollFlickAlphaFunction( AlphaFunction::BOUNCE );
1190   DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction().GetBuiltinFunction() == AlphaFunction::BOUNCE );
1191
1192   END_TEST;
1193 }
1194
1195 int UtcDaliToolkitScrollViewSnapDuration(void)
1196 {
1197   ToolkitTestApplication application;
1198   tet_infoline(" UtcDaliToolkitScrollViewSnapDuration");
1199
1200   // Set up a scrollView...
1201   ScrollView scrollView = ScrollView::New();
1202   scrollView.SetScrollSnapDuration( 1.0f );
1203   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1204   scrollView.SetScrollSnapDuration( 0.5f );
1205   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1206
1207   scrollView.SetScrollFlickDuration( 2.0f );
1208   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1209   scrollView.SetScrollFlickDuration( 1.5f );
1210   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1211   END_TEST;
1212 }
1213
1214 int UtcDaliToolkitScrollViewSnapStartedSignalP(void)
1215 {
1216   ToolkitTestApplication application;
1217   tet_infoline(" UtcDaliToolkitScrollViewSnapStartedSignalP");
1218
1219   // Set up a scrollView...
1220   ScrollView scrollView = ScrollView::New();
1221   Stage::GetCurrent().Add( scrollView );
1222   Vector2 stageSize = Stage::GetCurrent().GetSize();
1223   scrollView.SetSize(stageSize);
1224   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1225   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1226
1227   // Position rulers.
1228   RulerPtr rulerX = new DefaultRuler();
1229   RulerPtr rulerY = new DefaultRuler();
1230   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1231   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1232   scrollView.SetRulerX(rulerX);
1233   scrollView.SetRulerY(rulerY);
1234   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1235
1236   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1237   Wait(application);
1238
1239   // First try a snap.
1240   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1241
1242   DALI_TEST_CHECK( gOnSnapStartCalled );
1243   DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1244
1245   // Second try a swipe.
1246   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1247
1248   DALI_TEST_CHECK( gOnSnapStartCalled );
1249   DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1250   END_TEST;
1251 }
1252
1253 int UtcDaliToolkitScrollViewGetCurrentPageP(void)
1254 {
1255   ToolkitTestApplication application;
1256   tet_infoline(" UtcDaliToolkitScrollViewGetCurrentPageP");
1257
1258   ScrollView scrollView = ScrollView::New();
1259   Stage::GetCurrent().Add( scrollView );
1260   RulerPtr rulerX = new FixedRuler( 100.0f );
1261   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1262   RulerPtr rulerY = new FixedRuler( 100.0f );
1263   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1264
1265   scrollView.SetRulerX( rulerX );
1266   scrollView.SetRulerY( rulerY );
1267
1268   scrollView.ScrollTo( 15 );
1269   Wait(application, RENDER_DELAY_SCROLL);
1270   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
1271
1272   scrollView.ScrollTo( 3 );
1273   Wait(application, RENDER_DELAY_SCROLL);
1274   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
1275
1276   scrollView.ScrollTo( 9 );
1277   Wait(application, RENDER_DELAY_SCROLL);
1278   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
1279
1280   END_TEST;
1281 }
1282
1283 int UtcDaliToolkitScrollViewSetMaxOvershootP(void)
1284 {
1285   ToolkitTestApplication application;
1286   tet_infoline(" UtcDaliToolkitScrollViewSetMaxOvershootP");
1287
1288   // Set up a scrollView...
1289   ScrollView scrollView = ScrollView::New();
1290   Stage::GetCurrent().Add( scrollView );
1291   Vector2 stageSize = Stage::GetCurrent().GetSize();
1292   scrollView.SetSize(stageSize);
1293   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1294   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1295
1296   // Position rulers.
1297   RulerPtr rulerX = new DefaultRuler();
1298   RulerPtr rulerY = new DefaultRuler();
1299   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1300   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1301   scrollView.SetRulerX(rulerX);
1302   scrollView.SetRulerY(rulerY);
1303
1304   // Set the max overshoot to be 50 pixels in both X axis and Y axis
1305   scrollView.SetMaxOvershoot(50.0f, 50.0f);
1306
1307   scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1308   Wait(application);
1309
1310   // Scroll page in NW (-20,-20 pixels), then check that overshoot should be 0. (don't release touch)
1311   Vector2 currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 20, false);
1312   float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1313   float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1314   DALI_TEST_EQUALS(overshootXValue, 0.0f, TEST_LOCATION);
1315   DALI_TEST_EQUALS(overshootYValue, 0.0f, TEST_LOCATION);
1316
1317   // Scroll page further in NW (-105,-105 pixels), then check that overshoot should be around 0.5. (don't release touch)
1318   currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 105, false);
1319   overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1320   overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1321   DALI_TEST_CHECK(overshootXValue > 0.49f && overshootXValue < 0.51f);
1322   DALI_TEST_CHECK(overshootYValue > 0.49f && overshootYValue < 0.51f);
1323
1324   // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch)
1325   currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false);
1326   overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1327   overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1328   DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1329   DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1330
1331   // Change the max overshoot to be 100 pixels in both X axis and Y axis
1332   scrollView.SetMaxOvershoot(100.0f, 100.0f);
1333   Wait(application);
1334
1335   // Check that overshoot should be now around 0.8.
1336   overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1337   overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1338   DALI_TEST_CHECK(overshootXValue > 0.79f && overshootXValue < 0.81f);
1339   DALI_TEST_CHECK(overshootYValue > 0.79f && overshootYValue < 0.81f);
1340
1341   // Scroll page further in NW (-30,-30 pixels), then check that overshoot should be now 1.0. (don't release touch)
1342   currentPos = PerformGestureDiagonalSwipe(application, OVERSHOOT_START_SCROLL_POSITION, Vector2(1.0f, 1.0f), 30, false);
1343   overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1344   overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1345   DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1346   DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1347
1348   END_TEST;
1349 }
1350
1351 int UtcDaliToolkitScrollViewSetScrollingDirectionP(void)
1352 {
1353   ToolkitTestApplication application;
1354   tet_infoline(" UtcDaliToolkitScrollViewSetScrollingDirectionP");
1355
1356   // Set up a scrollView...
1357   ScrollView scrollView = ScrollView::New();
1358   Stage::GetCurrent().Add( scrollView );
1359   Vector2 stageSize = Stage::GetCurrent().GetSize();
1360   scrollView.SetSize(stageSize);
1361   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1362   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1363
1364   Vector2 START_POSITION = Vector2(10.0f, 10.0f);
1365
1366   scrollView.ScrollTo(START_POSITION, 0.0f);
1367   Wait(application);
1368   // Try a vertical swipe.
1369   PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1370   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION );
1371
1372   scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1373
1374   scrollView.ScrollTo(START_POSITION, 0.0f);
1375   Wait(application);
1376   // Try a vertical swipe.
1377   PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1378   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), START_POSITION, TEST_LOCATION );
1379
1380   scrollView.RemoveScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1381
1382   scrollView.ScrollTo(Vector2(10.0f, 10.0f), 0.0f);
1383   Wait(application);
1384   // Try a vertical swipe.
1385   PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1386   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION );
1387
1388   END_TEST;
1389 }
1390
1391 int UtcDaliToolkitScrollViewRemoveScrollingDirectionP(void)
1392 {
1393   ToolkitTestApplication application;
1394   tet_infoline(" UtcDaliToolkitScrollViewRemoveScrollingDirectionP");
1395
1396   // Set up a scrollView...
1397   ScrollView scrollView = ScrollView::New();
1398   Stage::GetCurrent().Add( scrollView );
1399   Vector2 stageSize = Stage::GetCurrent().GetSize();
1400   scrollView.SetSize(stageSize);
1401   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1402   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1403
1404   Vector2 START_POSITION = Vector2(10.0f, 10.0f);
1405
1406   scrollView.SetScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1407
1408   scrollView.ScrollTo(START_POSITION, 0.0f);
1409   Wait(application);
1410   // Try a vertical swipe.
1411   PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1412   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), START_POSITION, TEST_LOCATION );
1413
1414   scrollView.RemoveScrollingDirection(Dali::PanGestureDetector::DIRECTION_VERTICAL);
1415
1416   scrollView.ScrollTo(Vector2(10.0f, 10.0f), 0.0f);
1417   Wait(application);
1418   // Try a vertical swipe.
1419   PerformGestureDiagonalSwipe(application, START_POSITION, Vector2(0.0f, 1.0f), 60, true);
1420   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(10.0f, -50.0f), TEST_LOCATION );
1421
1422   END_TEST;
1423 }
1424
1425 int UtcDaliToolkitScrollViewSetRulerXP(void)
1426 {
1427   ToolkitTestApplication application;
1428   tet_infoline(" UtcDaliToolkitScrollViewSetRulerXP");
1429
1430   ScrollView scrollView = ScrollView::New();
1431   Stage::GetCurrent().Add( scrollView );
1432   RulerPtr rulerX = new FixedRuler( 100.0f );
1433   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1434
1435   scrollView.SetRulerX( rulerX );
1436
1437   scrollView.ScrollTo( 1, 0.0f );
1438   Wait(application);
1439   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(100.0f, 0.0f), TEST_LOCATION );
1440
1441   RulerPtr newRulerX = new FixedRuler( 200.0f );
1442   newRulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
1443
1444   scrollView.SetRulerX( newRulerX );
1445
1446   scrollView.ScrollTo( 1, 0.0f );
1447   Wait(application);
1448   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(200.0f, 0.0f), TEST_LOCATION );
1449
1450   END_TEST;
1451 }
1452
1453 int UtcDaliToolkitScrollViewSetRulerYP(void)
1454 {
1455   ToolkitTestApplication application;
1456   tet_infoline(" UtcDaliToolkitScrollViewSetRulerYP");
1457
1458   ScrollView scrollView = ScrollView::New();
1459   Stage::GetCurrent().Add( scrollView );
1460
1461   RulerPtr rulerY = new FixedRuler( 200.0f );
1462   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1463
1464   scrollView.SetRulerY( rulerY );
1465
1466   scrollView.ScrollTo( Vector2(0.0f, 350.0f), 0.0f );
1467   Wait(application);
1468   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 350.0f), TEST_LOCATION );
1469
1470   RulerPtr newRulerY = new FixedRuler( 100.0f );
1471   newRulerY->SetDomain( RulerDomain(0.0f, 200.0f, true) );
1472   scrollView.SetRulerY( newRulerY );
1473
1474   scrollView.ScrollTo( Vector2(0.0f, 350.0f), 0.0f );
1475   Wait(application);
1476   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector2(0.0f, 200.0f), TEST_LOCATION );
1477
1478   END_TEST;
1479 }
1480
1481 int UtcDaliToolkitScrollViewSetMinimumSpeedForFlickP(void)
1482 {
1483   ToolkitTestApplication application;
1484   tet_infoline(" UtcDaliToolkitScrollViewSetMinimumSpeedForFlickP");
1485
1486   ScrollView scrollView = ScrollView::New();
1487   scrollView.SetMinimumSpeedForFlick(25.0f);
1488   DALI_TEST_EQUALS( scrollView.GetMinimumSpeedForFlick(), 25.0f, TEST_LOCATION );
1489   scrollView.SetMinimumSpeedForFlick(60.0f);
1490   DALI_TEST_EQUALS( scrollView.GetMinimumSpeedForFlick(), 60.0f, TEST_LOCATION );
1491   END_TEST;
1492 }
1493
1494 int UtcDaliToolkitScrollViewSetMinimumDistanceForFlickP(void)
1495 {
1496   ToolkitTestApplication application;
1497   tet_infoline(" UtcDaliToolkitScrollViewSetMinimumDistanceForFlick");
1498
1499   ScrollView scrollView = ScrollView::New();
1500
1501   scrollView.SetMinimumDistanceForFlick(Vector2(30.0f, 15.0f));
1502   DALI_TEST_EQUALS( scrollView.GetMinimumDistanceForFlick(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1503   scrollView.SetMinimumDistanceForFlick(Vector2(60.0f, 30.0f));
1504   DALI_TEST_EQUALS( scrollView.GetMinimumDistanceForFlick(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1505   END_TEST;
1506 }
1507
1508 int UtcDaliToolkitScrollViewSetMouseWheelScrollDistanceStepP(void)
1509 {
1510   ToolkitTestApplication application;
1511   tet_infoline(" UtcDaliToolkitScrollViewSetMouseWheelScrollDistanceStepP");
1512
1513   ScrollView scrollView = ScrollView::New();
1514   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1515   scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1516   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1517   scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1518   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1519   END_TEST;
1520 }
1521
1522 int UtcDaliToolkitScrollViewApplyEffectP(void)
1523 {
1524   ToolkitTestApplication application;
1525   tet_infoline(" UtcDaliToolkitScrollViewApplyEffectP");
1526
1527   // Create a ScrollView
1528   ScrollView scrollView = ScrollView::New();
1529
1530   // Create two scroll view effects
1531   Dali::Path path = Dali::Path::New();
1532   ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1533   ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1534
1535   // Apply both effects
1536   scrollView.ApplyEffect(effect);
1537   scrollView.ApplyEffect(newEffect);
1538
1539   DALI_TEST_CHECK( true );
1540
1541   END_TEST;
1542 }
1543
1544 int UtcDaliToolkitScrollViewApplyEffectN(void)
1545 {
1546   ToolkitTestApplication application;
1547   tet_infoline(" UtcDaliToolkitScrollViewApplyEffectN");
1548
1549   // Create a ScrollView
1550   ScrollView scrollView = ScrollView::New();
1551
1552   // Create two scroll view effects
1553   Dali::Path path = Dali::Path::New();
1554   ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1555   ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1556
1557   // Apply both effects
1558   scrollView.ApplyEffect(effect);
1559   scrollView.ApplyEffect(newEffect);
1560
1561   // Attempt to apply the same effect again
1562   try
1563   {
1564     scrollView.ApplyEffect(newEffect);
1565     tet_result( TET_FAIL );
1566   }
1567   catch ( DaliException& e )
1568   {
1569     DALI_TEST_ASSERT( e, "!effectAlreadyExistsInScrollView", TEST_LOCATION );
1570   }
1571
1572   END_TEST;
1573 }
1574
1575 int UtcDaliToolkitScrollViewRemoveEffectP(void)
1576 {
1577   ToolkitTestApplication application;
1578   tet_infoline(" UtcDaliToolkitScrollViewRemoveEffectP");
1579
1580   // Create a ScrollView
1581   ScrollView scrollView = ScrollView::New();
1582
1583   // Create two scroll view effects
1584   Dali::Path path = Dali::Path::New();
1585   ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1586   ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1587
1588   // Apply both effects
1589   scrollView.ApplyEffect(effect);
1590   scrollView.ApplyEffect(newEffect);
1591
1592   // Remove both effects
1593   scrollView.RemoveEffect(effect);
1594   scrollView.RemoveEffect(newEffect);
1595
1596   DALI_TEST_CHECK( true );
1597
1598   END_TEST;
1599 }
1600
1601 int UtcDaliToolkitScrollViewRemoveEffectN(void)
1602 {
1603   ToolkitTestApplication application;
1604   tet_infoline(" UtcDaliToolkitScrollViewRemoveEffectN");
1605
1606   // Create a ScrollView
1607   ScrollView scrollView = ScrollView::New();
1608
1609   // Create two scroll view effects
1610   Dali::Path path = Dali::Path::New();
1611   ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1612   ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1613
1614   // Apply the first effect
1615   scrollView.ApplyEffect(effect);
1616
1617   // Attempt to remove the second effect which has not been applied to scroll view
1618   try
1619   {
1620     scrollView.RemoveEffect(newEffect);
1621     tet_result( TET_FAIL );
1622   }
1623   catch ( DaliException& e )
1624   {
1625     DALI_TEST_ASSERT( e, "effectExistedInScrollView", TEST_LOCATION );
1626   }
1627
1628   END_TEST;
1629 }
1630
1631 int UtcDaliToolkitScrollViewRemoveAllEffectsP(void)
1632 {
1633   ToolkitTestApplication application;
1634   tet_infoline(" UtcDaliToolkitScrollViewRemoveAllEffectsP");
1635
1636   // Create a ScrollView
1637   ScrollView scrollView = ScrollView::New();
1638
1639   // Create two scroll view effects
1640   Dali::Path path = Dali::Path::New();
1641   ScrollViewEffect effect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(100.0f, 100.0f, 0.0f), 2);
1642   ScrollViewEffect newEffect = ScrollViewPagePathEffect::New(path, Vector3(-1.0f, 1.0f, 1.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(200.0f, 150.0f, 0.0f), 5);
1643
1644   // Apply both effects
1645   scrollView.ApplyEffect(effect);
1646   scrollView.ApplyEffect(newEffect);
1647
1648   // Attempt to apply the same first effect again
1649   try
1650   {
1651     scrollView.ApplyEffect(effect);
1652     tet_result( TET_FAIL );
1653   }
1654   catch ( DaliException& e )
1655   {
1656     DALI_TEST_ASSERT( e, "!effectAlreadyExistsInScrollView", TEST_LOCATION );
1657   }
1658
1659   // Remove both effects
1660   scrollView.RemoveAllEffects();
1661
1662   // Apply both effects again
1663   scrollView.ApplyEffect(effect);
1664   scrollView.ApplyEffect(newEffect);
1665
1666   DALI_TEST_CHECK( true );
1667
1668   END_TEST;
1669 }
1670
1671 int UtcDaliToolkitScrollViewRemoveAllEffectsN(void)
1672 {
1673   ToolkitTestApplication application;
1674   tet_infoline(" UtcDaliToolkitScrollViewRemoveAllEffectsN");
1675
1676   // Create a ScrollView
1677   ScrollView scrollView = ScrollView::New();
1678
1679   // Remove effects when there is no effect applied previously
1680   scrollView.RemoveAllEffects();
1681
1682   DALI_TEST_CHECK( true );
1683
1684   END_TEST;
1685 }
1686
1687 int UtcDaliToolkitScrollViewGetSet(void)
1688 {
1689   ToolkitTestApplication application;
1690   tet_infoline(" UtcDaliToolkitScrollViewGetSet");
1691   ScrollView scrollView = ScrollView::New();
1692   scrollView.SetMaxFlickSpeed(0.5f);
1693   DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1694   scrollView.SetFrictionCoefficient(0.6f);
1695   DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1696   scrollView.SetFlickSpeedCoefficient(0.7f);
1697   DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1698   END_TEST;
1699 }
1700
1701 int UtcDaliToolkitScrollViewRulerDomainConstructorP(void)
1702 {
1703   ToolkitTestApplication application;
1704
1705   RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1706   DALI_TEST_EQUALS( domainX.min, 0.0f, TEST_LOCATION);
1707   DALI_TEST_EQUALS( domainX.max, 200.0f, TEST_LOCATION);
1708   DALI_TEST_EQUALS( domainX.enabled, true, TEST_LOCATION);
1709
1710   RulerDomain domainY = RulerDomain(100.0f, 500.0f, false);
1711   DALI_TEST_EQUALS( domainY.min, 100.0f, TEST_LOCATION);
1712   DALI_TEST_EQUALS( domainY.max, 500.0f, TEST_LOCATION);
1713   DALI_TEST_EQUALS( domainY.enabled, false, TEST_LOCATION);
1714
1715   END_TEST;
1716 }
1717
1718 int UtcDaliToolkitScrollViewRulerDomainGetSizeP(void)
1719 {
1720   ToolkitTestApplication application;
1721
1722   RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1723   DALI_TEST_EQUALS( domainX.GetSize(), 200.0f, TEST_LOCATION);
1724
1725   RulerDomain domainY = RulerDomain(100.0f, 500.0f, false);
1726   DALI_TEST_EQUALS( domainY.GetSize(), 400.0f, TEST_LOCATION);
1727
1728   END_TEST;
1729 }
1730
1731 int UtcDaliToolkitScrollViewRulerDomainClampP(void)
1732 {
1733   ToolkitTestApplication application;
1734
1735   RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1736
1737   float value = domainX.Clamp(50.0f, 100.0f, 1.0f);
1738   DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION);
1739
1740   value = domainX.Clamp(300.0f, 20.0f, 1.0f);
1741   DALI_TEST_EQUALS( value, 180.0f, TEST_LOCATION);
1742
1743   value = domainX.Clamp(300.0f, 20.0f, 0.5f);
1744   DALI_TEST_EQUALS( value, 80.0f, TEST_LOCATION);
1745
1746   value = domainX.Clamp(250.0f, 200.0f, 2.0f);
1747   DALI_TEST_EQUALS( value, 200.0f, TEST_LOCATION);
1748
1749   END_TEST;
1750 }
1751
1752 int UtcDaliToolkitScrollViewRulerDomainClampWithStateP(void)
1753 {
1754   ToolkitTestApplication application;
1755
1756   RulerDomain domainX = RulerDomain(0.0f, 200.0f, true);
1757
1758   ClampState clamped;
1759   float value = domainX.Clamp(50.0f, 100.0f, 1.0f, clamped);
1760   DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION);
1761   DALI_TEST_EQUALS( clamped, Dali::Toolkit::NotClamped, TEST_LOCATION);
1762
1763   value = domainX.Clamp(-100.0f, 200.0f, 1.0f, clamped);
1764   DALI_TEST_EQUALS( value, 0.0f, TEST_LOCATION);
1765   DALI_TEST_EQUALS( clamped, Dali::Toolkit::ClampedToMin, TEST_LOCATION);
1766
1767   value = domainX.Clamp(300.0f, 20.0f, 1.0f, clamped);
1768   DALI_TEST_EQUALS( value, 180.0f, TEST_LOCATION);
1769   DALI_TEST_EQUALS( clamped, Dali::Toolkit::ClampedToMax, TEST_LOCATION);
1770
1771   END_TEST;
1772 }
1773
1774 int UtcDaliToolkitScrollViewDefaultRulerConstructorP(void)
1775 {
1776   ToolkitTestApplication application;
1777   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerConstructorP");
1778
1779   RulerPtr defaultRuler = new DefaultRuler();
1780   DALI_TEST_CHECK( defaultRuler );
1781
1782   END_TEST;
1783 }
1784
1785 int UtcDaliToolkitScrollViewDefaultRulerDestructorP(void)
1786 {
1787   ToolkitTestApplication application;
1788   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerDestructorP");
1789
1790   RulerPtr defaultRuler = new DefaultRuler();
1791
1792   DALI_TEST_CHECK( true );
1793   END_TEST;
1794 }
1795
1796 int UtcDaliToolkitScrollViewFixedRulerConstructorP(void)
1797 {
1798   ToolkitTestApplication application;
1799   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerConstructorP");
1800
1801   RulerPtr fixedRuler = new FixedRuler( 100.0f );
1802   DALI_TEST_CHECK( fixedRuler );
1803
1804   END_TEST;
1805 }
1806
1807 int UtcDaliToolkitScrollViewFixedRulerDestructorP(void)
1808 {
1809   ToolkitTestApplication application;
1810   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerDestructorP");
1811
1812   RulerPtr fixedRuler = new FixedRuler( 100.0f );
1813
1814   DALI_TEST_CHECK( true );
1815   END_TEST;
1816 }
1817
1818 int UtcDaliToolkitScrollViewRulerGetTypeP(void)
1819 {
1820   ToolkitTestApplication application;
1821   tet_infoline(" UtcDaliToolkitScrollViewRulerGetTypeP");
1822
1823   RulerPtr defaultRuler = new DefaultRuler();
1824   DALI_TEST_CHECK( defaultRuler );
1825   DALI_TEST_EQUALS( defaultRuler->GetType(), Dali::Toolkit::Ruler::Free, TEST_LOCATION);
1826
1827   RulerPtr fixedRuler = new FixedRuler( 100.0f );
1828   DALI_TEST_CHECK( fixedRuler );
1829   DALI_TEST_EQUALS( fixedRuler->GetType(), Dali::Toolkit::Ruler::Fixed, TEST_LOCATION);
1830
1831   END_TEST;
1832 }
1833
1834 int UtcDaliToolkitScrollViewRulerEnableDisable(void)
1835 {
1836   ToolkitTestApplication application;
1837   tet_infoline(" UtcDaliToolkitScrollViewRulerEnableDisable");
1838
1839   RulerPtr ruler = new DefaultRuler();
1840
1841   DALI_TEST_CHECK( ruler->IsEnabled() );
1842   ruler->Disable();
1843   DALI_TEST_CHECK( !ruler->IsEnabled() );
1844   ruler->Enable();
1845   DALI_TEST_CHECK( ruler->IsEnabled() );
1846   END_TEST;
1847 }
1848
1849 int UtcDaliToolkitScrollViewRulerDomainEnableDisable(void)
1850 {
1851   ToolkitTestApplication application;
1852   tet_infoline(" UtcDaliToolkitScrollViewRulerDomainEnableDisable");
1853
1854   RulerPtr ruler = new DefaultRuler();
1855   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1856
1857   ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
1858   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
1859   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
1860   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
1861
1862   ruler->DisableDomain();
1863   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
1864   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
1865   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
1866   END_TEST;
1867 }
1868
1869 int UtcDaliToolkitScrollViewRulerSnapAndClamp(void)
1870 {
1871   ToolkitTestApplication application;
1872   tet_infoline(" UtcDaliToolkitScrollViewRulerSnapAndClamp");
1873
1874   RulerPtr ruler = new FixedRuler( 50.0f );
1875   ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
1876
1877   // default testing. (snap and clamp)
1878   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
1879   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
1880   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
1881   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
1882   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
1883   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
1884
1885   // bias testing.
1886   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1887   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
1888   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1889
1890   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
1891   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
1892   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
1893
1894   // length testing.
1895   DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
1896   DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
1897   DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
1898   DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
1899   DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
1900
1901   // scale testing.
1902   DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
1903   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
1904   DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
1905   DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
1906
1907   // clamp state testing.
1908   ClampState clamped;
1909   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1910   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1911   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
1912   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1913   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1914   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1915   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
1916   DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
1917   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1918   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
1919   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
1920   DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
1921   END_TEST;
1922 }
1923
1924 int UtcDaliToolkitScrollViewFixedRulerGetPositionFromPageP(void)
1925 {
1926   ToolkitTestApplication application;
1927   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetPositionFromPageP");
1928
1929   RulerPtr rulerNormal = new FixedRuler( 25.0f );
1930   rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
1931
1932   unsigned int volume;
1933   float position;
1934
1935   position = rulerNormal->GetPositionFromPage(1, volume, true);
1936   DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
1937   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1938
1939   position = rulerNormal->GetPositionFromPage(2, volume, true);
1940   DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
1941   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
1942   END_TEST;
1943 }
1944
1945 int UtcDaliToolkitScrollViewDefaultRulerGetTotalPagesP(void)
1946 {
1947   ToolkitTestApplication application;
1948   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetTotalPagesP");
1949
1950   RulerPtr defaultRuler = new DefaultRuler();
1951   DALI_TEST_CHECK( defaultRuler );
1952   DALI_TEST_EQUALS( defaultRuler->GetTotalPages(), 1u, TEST_LOCATION);
1953
1954   END_TEST;
1955 }
1956
1957 int UtcDaliToolkitScrollViewDefaultRulerGetPageFromPositionP(void)
1958 {
1959   ToolkitTestApplication application;
1960   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetPageFromPositionP");
1961
1962   RulerPtr defaultRuler = new DefaultRuler();
1963   DALI_TEST_CHECK( defaultRuler );
1964   DALI_TEST_EQUALS( defaultRuler->GetPageFromPosition(100.0f, true), 0u, TEST_LOCATION);
1965   DALI_TEST_EQUALS( defaultRuler->GetPageFromPosition(-300.0f, false), 0u, TEST_LOCATION);
1966
1967   END_TEST;
1968 }
1969
1970 int UtcDaliToolkitScrollViewDefaultRulerGetPositionFromPageP(void)
1971 {
1972   ToolkitTestApplication application;
1973   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerGetPositionFromPageP");
1974
1975   RulerPtr defaultRuler = new DefaultRuler();
1976   DALI_TEST_CHECK( defaultRuler );
1977
1978   unsigned int volume;
1979   DALI_TEST_EQUALS( defaultRuler->GetPositionFromPage(0, volume, true), 0.0f, TEST_LOCATION);
1980   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION);
1981
1982   DALI_TEST_EQUALS( defaultRuler->GetPositionFromPage(3, volume, false), 0.0f, TEST_LOCATION);
1983   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION);
1984
1985   END_TEST;
1986 }
1987
1988 int UtcDaliToolkitScrollViewDefaultRulerSnapP(void)
1989 {
1990   ToolkitTestApplication application;
1991   tet_infoline(" UtcDaliToolkitScrollViewDefaultRulerSnapP");
1992
1993   RulerPtr defaultRuler = new DefaultRuler();
1994   DALI_TEST_CHECK( defaultRuler );
1995
1996   DALI_TEST_EQUALS( defaultRuler->Snap(50.0f, 0.5f), 50.0f, TEST_LOCATION);
1997   DALI_TEST_EQUALS( defaultRuler->Snap(-120.0f, 1.0f), -120.0f, TEST_LOCATION);
1998
1999   END_TEST;
2000 }
2001
2002 int UtcDaliToolkitScrollViewFixedRulerGetTotalPagesP(void)
2003 {
2004   ToolkitTestApplication application;
2005   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetTotalPagesP");
2006
2007   RulerPtr fixedRuler = new FixedRuler( 100.0f );
2008   fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2009
2010   fixedRuler->Enable();
2011   DALI_TEST_EQUALS( fixedRuler->GetTotalPages(), 4u, TEST_LOCATION);
2012
2013   fixedRuler->Disable();
2014   DALI_TEST_EQUALS( fixedRuler->GetTotalPages(), 1u, TEST_LOCATION);
2015
2016   END_TEST;
2017 }
2018
2019 int UtcDaliToolkitScrollViewFixedRulerGetPageFromPositionP(void)
2020 {
2021   ToolkitTestApplication application;
2022   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerGetPageFromPositionP");
2023
2024   RulerPtr fixedRuler = new FixedRuler( 100.0f );
2025   fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2026
2027   fixedRuler->Enable();
2028   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 3u, TEST_LOCATION);
2029   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 3u, TEST_LOCATION);
2030   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 1u, TEST_LOCATION);
2031   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2032
2033   fixedRuler->Disable();
2034   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, true), 0u, TEST_LOCATION);
2035   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(250.0f, false), 0u, TEST_LOCATION);
2036   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, true), 0u, TEST_LOCATION);
2037   DALI_TEST_EQUALS( fixedRuler->GetPageFromPosition(-350.0f, false), 0u, TEST_LOCATION);
2038
2039   END_TEST;
2040 }
2041
2042 int UtcDaliToolkitScrollViewFixedRulerSnapP(void)
2043 {
2044   ToolkitTestApplication application;
2045   tet_infoline(" UtcDaliToolkitScrollViewFixedRulerSnapP");
2046
2047   RulerPtr fixedRuler = new FixedRuler( 100.0f );
2048   fixedRuler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
2049
2050   DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 0.0f), -100.0f, TEST_LOCATION);
2051   DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 0.0f), -100.0f, TEST_LOCATION);
2052   DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 0.0f), -200.0f, TEST_LOCATION);
2053   DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 0.0f), -500.0f, TEST_LOCATION);
2054   DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 0.0f), 0.0f, TEST_LOCATION);
2055   DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 0.0f), 0.0f, TEST_LOCATION);
2056   DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 0.0f), 0.0f, TEST_LOCATION);
2057   DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 0.0f), 100.0f, TEST_LOCATION);
2058   DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 0.0f), 100.0f, TEST_LOCATION);
2059   DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 0.0f), 200.0f, TEST_LOCATION);
2060   DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 0.0f), 600.0f, TEST_LOCATION);
2061
2062   DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 0.5f), 0.0f, TEST_LOCATION);
2063   DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 0.5f), -100.0f, TEST_LOCATION);
2064   DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 0.5f), -100.0f, TEST_LOCATION);
2065   DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 0.5f), -500.0f, TEST_LOCATION);
2066   DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 0.5f), 0.0f, TEST_LOCATION);
2067   DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 0.5f), 100.0f, TEST_LOCATION);
2068   DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 0.5f), 100.0f, TEST_LOCATION);
2069   DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 0.5f), 100.0f, TEST_LOCATION);
2070   DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 0.5f), 100.0f, TEST_LOCATION);
2071   DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 0.5f), 300.0f, TEST_LOCATION);
2072   DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 0.5f), 600.0f, TEST_LOCATION);
2073
2074   DALI_TEST_EQUALS( fixedRuler->Snap(-30.0f, 1.0f), 0.0f, TEST_LOCATION);
2075   DALI_TEST_EQUALS( fixedRuler->Snap(-70.0f, 1.0f), 0.0f, TEST_LOCATION);
2076   DALI_TEST_EQUALS( fixedRuler->Snap(-120.0f, 1.0f), -100.0f, TEST_LOCATION);
2077   DALI_TEST_EQUALS( fixedRuler->Snap(-480.0f, 1.0f), -400.0f, TEST_LOCATION);
2078   DALI_TEST_EQUALS( fixedRuler->Snap(20.0f, 1.0f), 100.0f, TEST_LOCATION);
2079   DALI_TEST_EQUALS( fixedRuler->Snap(50.0f, 1.0f), 100.0f, TEST_LOCATION);
2080   DALI_TEST_EQUALS( fixedRuler->Snap(80.0f, 1.0f), 100.0f, TEST_LOCATION);
2081   DALI_TEST_EQUALS( fixedRuler->Snap(100.0f, 1.0f), 200.0f, TEST_LOCATION);
2082   DALI_TEST_EQUALS( fixedRuler->Snap(120.0f, 1.0f), 200.0f, TEST_LOCATION);
2083   DALI_TEST_EQUALS( fixedRuler->Snap(250.0f, 1.0f), 300.0f, TEST_LOCATION);
2084   DALI_TEST_EQUALS( fixedRuler->Snap(620.0f, 1.0f), 700.0f, TEST_LOCATION);
2085
2086   END_TEST;
2087 }
2088
2089
2090
2091