Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ScrollView.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #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 Vector3 CLAMP_START_SCROLL_POSITION(30.0f, 100.0f, 0.0f); ///< Scroll start position for the Clamping tests.
61 const Vector2 CLAMP_TOUCH_START( 100.0f, 100.0f );              ///< Start point to touch from for the Clamping tests.
62 const Vector2 CLAMP_TOUCH_MOVEMENT( 5.0f, -5.0f );              ///< Amount to move touch for each frame for the Clamping tests.
63 const int CLAMP_GESTURE_FRAMES = 100;                           ///< Number of Frames to synthesize a gesture for the Clamping tests.
64 const Vector3 TEST_ACTOR_POSITION(100.0f, 100.0f, 0.0f);        ///< A Test actor position offset (arbitrary value)
65 const Vector3 TEST_CONSTRAINT_OFFSET(1.0f, 2.0f, 0.0f);         ///< A Test constraint offset (arbitrary value to test effects)
66 const float TEST_RATIO_TOLERANCE = 0.05;                        ///< +/-5% tolerance for ratio comparisons.
67
68 const int MAX_FRAMES_TO_TEST_OVERSHOOT = 600;                         ///< 10 seconds (at 60 frames per second).
69 const Vector3 OVERSHOOT_START_SCROLL_POSITION(100.0f, 100.0f, 0.0f);  ///< Scroll start position for the Overshoot tests.
70 const float TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION = 0.05f;             ///< a Test duration
71 const float TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION = 1.5f;              ///< another Test duration
72 const float TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION = TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION * 0.5f; // Same as above, but different alpha function.
73 const float TIME_TOLERANCE = 0.05f;                                   ///< Allow testing tolerance between a 10th of second (+/- 3 frames)
74
75
76 // Generate a PanGestureEvent to send to Core
77 Integration::PanGestureEvent GeneratePan(
78     Gesture::State state,
79     const Vector2& previousPosition,
80     const Vector2& currentPosition,
81     unsigned long timeDelta,
82     unsigned int numberOfTouches = 1)
83 {
84   Integration::PanGestureEvent pan(state);
85
86   pan.previousPosition = previousPosition;
87   pan.currentPosition = currentPosition;
88   pan.timeDelta = timeDelta;
89   pan.numberOfTouches = numberOfTouches;
90
91   return pan;
92 }
93
94 /**
95  * Helper to generate PanGestureEvent
96  *
97  * @param[in] application Application instance
98  * @param[in] state The Gesture State
99  * @param[in] pos The current position of touch.
100  */
101 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
102 {
103   static Vector2 last;
104
105   if( (state == Gesture::Started) ||
106       (state == Gesture::Possible) )
107   {
108     last.x = pos.x;
109     last.y = pos.y;
110   }
111
112   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
113
114   last.x = pos.x;
115   last.y = pos.y;
116 }
117
118 /*
119  * Simulate time passed by.
120  *
121  * @note this will always process at least 1 frame (1/60 sec)
122  *
123  * @param application Test application instance
124  * @param duration Time to pass in milliseconds.
125  * @return The actual time passed in milliseconds
126  */
127 int Wait(ToolkitTestApplication& application, int duration = 0)
128 {
129   int time = 0;
130
131   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
132   {
133     application.SendNotification();
134     application.Render(RENDER_FRAME_INTERVAL);
135     time += RENDER_FRAME_INTERVAL;
136   }
137
138   return time;
139 }
140
141 // Callback probes.
142
143 static bool gOnScrollStartCalled;                       ///< Whether the OnScrollStart signal was invoked.
144 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
145 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
146 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
147 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
148 static Vector3 gConstraintResult;                       ///< Result from constraint.
149
150 /**
151  * Invoked when scrolling starts.
152  *
153  * @param[in] position The current scroll position.
154  */
155 static void OnScrollStart( const Vector3& position )
156 {
157   gOnScrollStartCalled = true;
158 }
159
160 /**
161  * Invoked when scrolling updates (via dragging)
162  *
163  * @param[in] position The current scroll position.
164  */
165 static void OnScrollUpdate( const Vector3& position )
166 {
167   gOnScrollUpdateCalled = true;
168 }
169
170 /**
171  * Invoked when scrolling finishes
172  *
173  * @param[in] position The current scroll position.
174  */
175 static void OnScrollComplete( const Vector3& position )
176 {
177   gOnScrollCompleteCalled = true;
178 }
179
180 /**
181  * Invoked when a snap or flick started.
182  *
183  * @param[in] event The type of snap and the target position/scale/rotation.
184  */
185 static void OnSnapStart( const ScrollView::SnapEvent& event )
186 {
187   gOnSnapStartCalled = true;
188   gLastSnapType = event.type;
189 }
190
191 /**
192  * TestSumConstraint
193  *
194  * Summation of current value, property, and offset.
195  *
196  * current' = current + mOffset + property;
197  */
198 struct TestSumConstraint
199 {
200   /**
201    * @param[in] offset The offset to be added to current.
202    */
203   TestSumConstraint(const Vector3& offset)
204   :mOffset(offset)
205   {
206   }
207
208   /**
209    * @param[in] current The current base value
210    * @param[in] inputs Contains the property to be added to current.
211    * @return The new current Vector.
212    */
213   void operator()( Vector3& current, const PropertyInputContainer& inputs )
214   {
215     gConstraintResult = current + inputs[0]->GetVector3() + mOffset;
216     current = gConstraintResult;
217   }
218
219   Vector3 mOffset;
220
221 };
222
223 /**
224  * @param[in] application The application instance
225  * @param[in] scrollView The scrollView instance
226  * @return The time taken for the overshoot to reach origin (zero)
227  */
228 static float TestOvershootSnapDuration(ToolkitTestApplication &application, ScrollView scrollView)
229 {
230   int timeToReachOrigin = -1;
231   for(int i = 0;i<MAX_FRAMES_TO_TEST_OVERSHOOT;i++)
232   {
233     float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
234     float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
235     if(overshootXValue == 0.0f && overshootYValue == 0.0f)
236     {
237       break;
238     }
239
240     timeToReachOrigin += Wait(application);
241   }
242
243   return static_cast<float>(timeToReachOrigin) * 0.001f; // return in seconds not ms.
244 }
245
246 /**
247  * y = 2x alpha function, which is clamped between 0.0f - 1.0f
248  *
249  * Animations should appear to finish (reach 100% point)
250  * at just half the time of a regular Linear AlphaFunction.
251  *
252  * @param[in] progress value (ranges from 0.0f - 1.0f)
253  * @return interpolation value (ranges from 0.0f - 1.0f)
254  */
255 float TestAlphaFunction(float progress)
256 {
257   return std::min( progress * 2.0f, 1.0f );
258 }
259
260 } // unnamed namespace
261
262
263 int UtcDaliScrollViewNew(void)
264 {
265   ToolkitTestApplication application;
266   tet_infoline(" UtcDaliScrollViewNew");
267
268   ScrollView scrollView;
269
270   DALI_TEST_CHECK( !scrollView );
271
272   scrollView = ScrollView::New();
273
274   DALI_TEST_CHECK( scrollView );
275
276   ScrollView scrollView2(scrollView);
277
278   DALI_TEST_CHECK( scrollView2 == scrollView );
279
280   //Additional check to ensure object is created by checking if it's registered
281   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
282   DALI_TEST_CHECK( registry );
283
284   gObjectCreatedCallBackCalled = false;
285   registry.ObjectCreatedSignal().Connect( &TestCallback );
286   {
287     ScrollView scrollView = ScrollView::New();
288   }
289   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
290   END_TEST;
291 }
292
293 int UtcDaliScrollViewDownCast(void)
294 {
295   ToolkitTestApplication application;
296   tet_infoline(" UtcDaliScrollViewDownCast");
297
298   ScrollView scrollView = ScrollView::New();
299   BaseHandle handle(scrollView);
300
301   ScrollView newScrollView = ScrollView::DownCast( handle );
302   DALI_TEST_CHECK( scrollView );
303   DALI_TEST_CHECK( newScrollView == scrollView );
304   END_TEST;
305 }
306
307 int UtcDaliScrollViewScrollToPosition(void)
308 {
309   ToolkitTestApplication application;
310   tet_infoline(" UtcDaliScrollViewScrollToPosition");
311
312   // Create the ScrollView actor
313   ScrollView scrollView = ScrollView::New();
314   Stage::GetCurrent().Add( scrollView );
315
316   const Vector3 target = Vector3(100.0f, 200.0f, 0.0f);
317   const Vector3 target2 = Vector3(300.0f, 100.0f, 0.0f);
318
319   scrollView.ScrollTo( target, 0.0f );
320   Wait(application);
321   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target, TEST_LOCATION );
322   scrollView.ScrollTo( target2 );
323   Wait(application, RENDER_DELAY_SCROLL);
324   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), target2, TEST_LOCATION );
325
326   Wait(application);
327   END_TEST;
328 }
329
330 int UtcDaliScrollViewScrollToPage(void)
331 {
332   ToolkitTestApplication application;
333   tet_infoline(" UtcDaliScrollViewScrollToPage");
334
335   ScrollView scrollView = ScrollView::New();
336   Stage::GetCurrent().Add( scrollView );
337   RulerPtr rulerX = new FixedRuler( 100.0f );
338   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
339   RulerPtr rulerY = new FixedRuler( 100.0f );
340   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
341
342   scrollView.SetRulerX( rulerX );
343   scrollView.SetRulerY( rulerY );
344
345   scrollView.ScrollTo( 1, 0.0f );
346   Wait(application);
347   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
348
349   scrollView.ScrollTo( 5, 0.0f );
350   Wait(application);
351   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(500.0f, 0.0f, 0.0f), TEST_LOCATION );
352
353   scrollView.ScrollTo( 10, 0.0f );
354   Wait(application);
355   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(200.0f, 100.0f, 0.0f), TEST_LOCATION );
356
357   scrollView.ScrollTo( 15, 0.0f );
358   Wait(application);
359   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(700.0f, 100.0f, 0.0f), TEST_LOCATION );
360   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 15, TEST_LOCATION );
361
362   scrollView.ScrollTo( 3 );
363   Wait(application, RENDER_DELAY_SCROLL);
364   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(300.0f, 0.0f, 0.0f), TEST_LOCATION );
365   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 3, TEST_LOCATION );
366
367   scrollView.ScrollTo( 9 );
368   Wait(application, RENDER_DELAY_SCROLL);
369   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 100.0f, 0.0f), TEST_LOCATION );
370   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 9, TEST_LOCATION );
371
372   // Apply DefaultRulers instead and see what happens.
373   rulerX = new DefaultRuler();
374   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
375   rulerY = new DefaultRuler();
376   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
377
378   scrollView.SetRulerX( rulerX );
379   scrollView.SetRulerY( rulerY );
380
381   // This time should always scroll to origin (0.0f, 0.0f)
382   scrollView.ScrollTo( 1, 0.0f );
383   Wait(application);
384   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
385   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 0, TEST_LOCATION );
386
387   Wait(application);
388   END_TEST;
389 }
390
391 int UtcDaliScrollViewScrollToActor(void)
392 {
393   ToolkitTestApplication application;
394   tet_infoline(" UtcDaliScrollViewScrollToActor");
395
396   ScrollView scrollView = ScrollView::New();
397   Stage::GetCurrent().Add( scrollView );
398
399   Actor actorA = Actor::New();
400   const Vector3 positionA = Vector3(100.0f, 400.0f, 0.0f);
401   actorA.SetPosition(positionA);
402   scrollView.Add(actorA);
403
404   Actor actorB = Actor::New();
405   const Vector3 positionB = Vector3(500.0f, 200.0f, 0.0f);
406   actorB.SetPosition(positionB);
407   scrollView.Add(actorB);
408
409   Wait(application);
410
411   scrollView.ScrollTo(actorA, 0.0f);
412   Wait(application);
413   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
414
415   Wait(application);
416   scrollView.ScrollTo(actorB, 0.0f);
417   Wait(application);
418   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
419
420   scrollView.ScrollTo(actorA);
421   Wait(application, RENDER_DELAY_SCROLL);
422   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionA, TEST_LOCATION );
423
424   scrollView.ScrollTo(actorB);
425   Wait(application, RENDER_DELAY_SCROLL);
426   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), positionB, TEST_LOCATION );
427   END_TEST;
428 }
429
430 int UtcDaliScrollViewScrollToSnapPoint(void)
431 {
432   ToolkitTestApplication application;
433   tet_infoline(" UtcDaliScrollViewScrollToSnapPoint");
434
435   ScrollView scrollView = ScrollView::New();
436   Stage::GetCurrent().Add( scrollView );
437   RulerPtr rulerX = new FixedRuler( 100.0f );
438   rulerX->SetDomain( RulerDomain(0.0f, 800.0f, true) );
439   RulerPtr rulerY = new FixedRuler( 100.0f );
440   rulerY->SetDomain( RulerDomain(0.0f, 400.0f, true) );
441
442   scrollView.SetRulerX( rulerX );
443   scrollView.SetRulerY( rulerY );
444
445   scrollView.ScrollTo( Vector3(120.0f, 190.0f, 0.0f), 0.0f );
446   Wait(application);
447   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(120.0f, 190.0f, 0.0f), TEST_LOCATION );
448
449   scrollView.ScrollToSnapPoint();
450
451   Wait(application, RENDER_DELAY_SCROLL);
452   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), Vector3(100.0f, 200.0f, 0.0f), TEST_LOCATION );
453   END_TEST;
454 }
455
456 int UtcDaliScrollViewSetScrollUpdateDistance(void)
457 {
458   ToolkitTestApplication application;
459   tet_infoline(" UtcDaliScrollViewRefreshInterval");
460
461   ScrollView scrollView = ScrollView::New();
462
463   scrollView.SetScrollUpdateDistance(0);
464   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 0, TEST_LOCATION);
465   scrollView.SetScrollUpdateDistance(10);
466   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 10, TEST_LOCATION);
467   scrollView.SetScrollUpdateDistance(1000);
468   DALI_TEST_EQUALS( scrollView.GetScrollUpdateDistance(), 1000, TEST_LOCATION);
469   END_TEST;
470 }
471
472 int UtcDaliScrollViewWrapMode(void)
473 {
474   ToolkitTestApplication application;
475   tet_infoline(" UtcDaliScrollViewWrapMode");
476
477   ScrollView scrollView = ScrollView::New();
478   Stage::GetCurrent().Add( scrollView );
479
480   // Position rulers. 4x4 grid.
481   RulerPtr rulerX = new FixedRuler(50.0f);
482   RulerPtr rulerY = new FixedRuler(50.0f);
483   rulerX->SetDomain( RulerDomain(0.0f, 200.0f, false) );
484   rulerY->SetDomain( RulerDomain(0.0f, 200.0f, false) );
485   scrollView.SetRulerX(rulerX);
486   scrollView.SetRulerY(rulerY);
487
488   scrollView.SetWrapMode(false);
489   scrollView.ScrollTo(Vector3(225.0f, 125.0f, 0.0f), 0.0f); // 5th (1st) page across, and 3rd (3rd) page down. (wrapped)
490   Wait(application);
491   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 17, TEST_LOCATION );
492   scrollView.SetWrapMode(true);
493   DALI_TEST_EQUALS( static_cast<int>(scrollView.GetCurrentPage()), 13, TEST_LOCATION );
494   END_TEST;
495 }
496
497 int UtcDaliScrollViewActorAutoSnap(void)
498 {
499   ToolkitTestApplication application;
500   tet_infoline(" UtcDaliScrollViewActorAutoSnap");
501
502   ScrollView scrollView = ScrollView::New();
503   Stage::GetCurrent().Add( scrollView );
504
505   // Position rulers.
506   RulerPtr rulerX = new DefaultRuler();
507   RulerPtr rulerY = new DefaultRuler();
508   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
509   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
510   scrollView.SetRulerX(rulerX);
511   scrollView.SetRulerY(rulerY);
512
513   const Vector3 aPosition = Vector3(200.0f, 50.0f, 0.0f);
514   Actor a = Actor::New();
515   scrollView.Add(a);
516   a.SetPosition(aPosition);
517
518   const Vector3 bPosition = Vector3(600.0f, 600.0f, 0.0f);
519   Actor b = Actor::New();
520   scrollView.Add(b);
521   b.SetPosition(bPosition);
522
523   // Goto a random position, and execute snap (should not move)
524   Vector3 targetScroll = Vector3(500.0f, 500.0f, 0.0f);
525   scrollView.ScrollTo(targetScroll, 0.0f);
526   Wait(application);
527   scrollView.ScrollToSnapPoint();
528   Wait(application, RENDER_DELAY_SCROLL);
529   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), targetScroll, TEST_LOCATION );
530
531   // Enable ActorAutoSnap, and now try snapping.
532   scrollView.SetActorAutoSnap(true);
533   scrollView.ScrollToSnapPoint();
534   Wait(application, RENDER_DELAY_SCROLL);
535   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), bPosition, TEST_LOCATION );
536
537   scrollView.ScrollTo(Vector3(0.0f, 0.0f, 0.0f), 0.0f);
538   Wait(application);
539   scrollView.ScrollToSnapPoint();
540   Wait(application, RENDER_DELAY_SCROLL);
541   DALI_TEST_EQUALS( scrollView.GetCurrentScrollPosition(), aPosition, TEST_LOCATION );
542   END_TEST;
543 }
544
545 int UtcDaliScrollViewSignalsStartComplete(void)
546 {
547   ToolkitTestApplication application;
548   tet_infoline(" UtcDaliScrollViewSignalsStartComplete");
549
550   gOnScrollStartCalled = false;
551   gOnScrollCompleteCalled = false;
552
553   ScrollView scrollView = ScrollView::New();
554   Stage::GetCurrent().Add( scrollView );
555
556   // Position rulers.
557   RulerPtr rulerX = new DefaultRuler();
558   RulerPtr rulerY = new DefaultRuler();
559   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
560   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
561   scrollView.SetRulerX(rulerX);
562   scrollView.SetRulerY(rulerY);
563   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
564   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
565   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
566   scrollView.ScrollTo( Vector3(100.0f, 100.0f, 0.0f) );
567   Wait(application, RENDER_DELAY_SCROLL);
568
569   DALI_TEST_CHECK(gOnScrollStartCalled);
570   DALI_TEST_CHECK(gOnScrollCompleteCalled);
571   END_TEST;
572 }
573
574 int UtcDaliScrollViewSignalsUpdate(void)
575 {
576   ToolkitTestApplication application;
577   tet_infoline(" UtcDaliScrollViewSignalsUpdate");
578
579   gOnScrollStartCalled = false;
580   gOnScrollUpdateCalled = false;
581   gOnScrollCompleteCalled = false;
582
583   ScrollView scrollView = ScrollView::New();
584   Stage::GetCurrent().Add( scrollView );
585   Vector2 stageSize = Stage::GetCurrent().GetSize();
586   scrollView.SetSize(stageSize);
587   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
588   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
589
590   // Position rulers.
591   RulerPtr rulerX = new DefaultRuler();
592   RulerPtr rulerY = new DefaultRuler();
593   rulerX->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
594   rulerY->SetDomain( RulerDomain(0.0f, 1000.0f, false) );
595   scrollView.SetRulerX(rulerX);
596   scrollView.SetRulerY(rulerY);
597   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
598   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
599   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
600
601   ImageActor image = CreateSolidColorActor( Color::RED );
602   image.SetSize(stageSize);
603   image.SetParentOrigin(ParentOrigin::TOP_LEFT);
604   image.SetAnchorPoint(AnchorPoint::TOP_LEFT);
605   scrollView.Add(image);
606
607   Wait(application);
608
609   // Do a pan starting from 100,100 and moving down diagonally.
610   Vector2 pos(100.0f, 100.0f);
611   SendPan(application, Gesture::Possible, pos);
612   SendPan(application, Gesture::Started, pos);
613   pos.x += 5.0f;
614   pos.y += 5.0f;
615   Wait(application, 100);
616
617   for(int i = 0;i<20;i++)
618   {
619     SendPan(application, Gesture::Continuing, pos);
620     pos.x += 5.0f;
621     pos.y += 5.0f;
622     Wait(application);
623   }
624
625   SendPan(application, Gesture::Finished, pos);
626   Wait(application, RENDER_DELAY_SCROLL);
627
628   DALI_TEST_CHECK(gOnScrollStartCalled);
629   DALI_TEST_CHECK(gOnScrollUpdateCalled);
630   DALI_TEST_CHECK(gOnScrollCompleteCalled);
631   END_TEST;
632 }
633
634 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
635 {
636   gOnScrollStartCalled = false;
637   gOnScrollUpdateCalled = false;
638   gOnScrollCompleteCalled = false;
639   gOnSnapStartCalled = false;
640
641   // Now do a pan starting from (start) and heading (direction)
642   Vector2 pos(start);
643   SendPan(application, Gesture::Possible, pos);
644   SendPan(application, Gesture::Started, pos);
645   Wait(application);
646
647   for(int i = 0;i<frames;i++)
648   {
649     pos += direction; // Move in this direction
650     SendPan(application, Gesture::Continuing, pos);
651     Wait(application);
652   }
653
654   if(finish)
655   {
656     pos += direction; // Move in this direction.
657     SendPan(application, Gesture::Finished, pos);
658     Wait(application, RENDER_DELAY_SCROLL);
659   }
660
661   return pos;
662 }
663
664 int UtcDaliScrollViewScrollSensitive(void)
665 {
666   ToolkitTestApplication application;
667   tet_infoline(" UtcDaliScrollViewScrollSensitive");
668
669   // Set up a scrollView...
670   ScrollView scrollView = ScrollView::New();
671   Stage::GetCurrent().Add( scrollView );
672   Vector2 stageSize = Stage::GetCurrent().GetSize();
673   scrollView.SetSize(stageSize);
674   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
675   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
676
677   // Position rulers.
678   RulerPtr rulerX = new DefaultRuler();
679   RulerPtr rulerY = new DefaultRuler();
680   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
681   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
682   scrollView.SetRulerX(rulerX);
683   scrollView.SetRulerY(rulerY);
684   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
685   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
686   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
687   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
688
689   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
690   Wait(application);
691
692   // First try insensitive swipe.
693   scrollView.SetScrollSensitive(false);
694   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
695
696   DALI_TEST_CHECK( !gOnScrollStartCalled );
697   DALI_TEST_CHECK( !gOnScrollCompleteCalled );
698   DALI_TEST_CHECK( !gOnSnapStartCalled );
699
700   // Second try sensitive swipe.
701   scrollView.SetScrollSensitive(true);
702   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, CLAMP_TOUCH_MOVEMENT, CLAMP_GESTURE_FRAMES, true);
703
704   DALI_TEST_CHECK( gOnScrollStartCalled );
705   DALI_TEST_CHECK( gOnScrollCompleteCalled );
706   DALI_TEST_CHECK( gOnSnapStartCalled );
707   END_TEST;
708 }
709
710 int UtcDaliScrollViewAxisAutoLock(void)
711 {
712   ToolkitTestApplication application;
713   tet_infoline(" UtcDaliScrollViewAxisAutoLock");
714
715   // Set up a scrollView...
716   ScrollView scrollView = ScrollView::New();
717   Stage::GetCurrent().Add( scrollView );
718   Vector2 stageSize = Stage::GetCurrent().GetSize();
719   scrollView.SetSize(stageSize);
720   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
721   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
722
723   // Position rulers.
724   RulerPtr rulerX = new DefaultRuler();
725   RulerPtr rulerY = new DefaultRuler();
726   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
727   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
728   scrollView.SetRulerX(rulerX);
729   scrollView.SetRulerY(rulerY);
730   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
731   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
732   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
733
734   // Normal
735   scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
736   Wait(application);
737   Vector3 startPosition = scrollView.GetCurrentScrollPosition();
738   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
739   const Vector3 positionAfterNormal = scrollView.GetCurrentScrollPosition();
740
741   // Autolock
742   scrollView.SetAxisAutoLock(true);
743   DALI_TEST_CHECK(scrollView.GetAxisAutoLock());
744
745   scrollView.ScrollTo(Vector3(100.0f, 100.0f, 0.0f), 0.0f); // move in a little.
746   Wait(application);
747   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(5.0f, 1.0f), 50, true); // mostly horizontal
748   const Vector3 positionAfterAutoLock = scrollView.GetCurrentScrollPosition();
749
750   // compare how much the Y position has deviated for normal and autolock.
751   const float devianceNormal = fabsf(startPosition.y - positionAfterNormal.y);
752   const float devianceAutoLock = fabsf(startPosition.y - positionAfterAutoLock.y);
753
754   // in auto-lock it should be a mostly horizontal pan (thus deviance should be much lower)
755   DALI_TEST_CHECK(devianceAutoLock < devianceNormal);
756
757   scrollView.SetAxisAutoLock(false);
758   DALI_TEST_CHECK(!scrollView.GetAxisAutoLock());
759   END_TEST;
760 }
761
762 int UtcDaliScrollViewAxisAutoLockGradient(void)
763 {
764   ToolkitTestApplication application;
765   tet_infoline(" UtcDaliScrollViewAxisAutoLockGradient");
766
767   // Set up a scrollView...
768   ScrollView scrollView = ScrollView::New();
769   scrollView.SetAxisAutoLockGradient(0.5f);
770   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 0.5f, TEST_LOCATION);
771   scrollView.SetAxisAutoLockGradient(1.0f);
772   DALI_TEST_EQUALS(scrollView.GetAxisAutoLockGradient(), 1.0f, TEST_LOCATION);
773   END_TEST;
774 }
775
776 int UtcDaliScrollViewConstraints(void)
777 {
778   ToolkitTestApplication application;
779   tet_infoline(" UtcDaliScrollViewConstraints");
780
781   // Set up a scrollView...
782   ScrollView scrollView = ScrollView::New();
783   Stage::GetCurrent().Add( scrollView );
784   Vector2 stageSize = Stage::GetCurrent().GetSize();
785   scrollView.SetSize(stageSize);
786   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
787   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
788
789   // Position rulers.
790   RulerPtr rulerX = new DefaultRuler();
791   RulerPtr rulerY = new DefaultRuler();
792   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
793   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
794   scrollView.SetRulerX(rulerX);
795   scrollView.SetRulerY(rulerY);
796
797   // Add an Actor to ScrollView,
798   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
799   gConstraintResult = Vector3::ZERO;
800   Actor a = Actor::New();
801   scrollView.Add(a);
802   a.SetPosition( TEST_ACTOR_POSITION );
803   Wait(application);
804
805   Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
806   constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
807   constraint.SetRemoveAction(Constraint::Discard);
808   scrollView.ApplyConstraintToChildren(constraint);
809   Wait(application);
810
811   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
812
813   gConstraintResult = Vector3::ZERO;
814   scrollView.RemoveConstraintsFromChildren();
815   Wait(application);
816
817   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
818   END_TEST;
819 }
820
821 int UtcDaliScrollViewBind(void)
822 {
823   ToolkitTestApplication application;
824   tet_infoline(" UtcDaliScrollViewBind");
825
826   // Set up a scrollView...
827   ScrollView scrollView = ScrollView::New();
828   Stage::GetCurrent().Add( scrollView );
829   Vector2 stageSize = Stage::GetCurrent().GetSize();
830   scrollView.SetSize(stageSize);
831   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
832   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
833
834   // Position rulers.
835   RulerPtr rulerX = new DefaultRuler();
836   RulerPtr rulerY = new DefaultRuler();
837   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
838   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
839   scrollView.SetRulerX(rulerX);
840   scrollView.SetRulerY(rulerY);
841
842   // Add an Actor to ScrollView,
843   // Apply TestSumConstraint to ScrollView's children (includes this Actor)
844
845   gConstraintResult = Vector3::ZERO;
846   Actor a = Actor::New();
847   scrollView.Add(a);
848   a.SetPosition( TEST_ACTOR_POSITION );
849   Wait(application);
850
851   // apply this constraint to scrollview
852   Constraint constraint = Constraint::New<Vector3>( scrollView, Actor::Property::POSITION, TestSumConstraint( TEST_CONSTRAINT_OFFSET ) );
853   constraint.AddSource( Source(scrollView, ScrollView::Property::SCROLL_POSITION) );
854   constraint.SetRemoveAction(Constraint::Discard);
855   scrollView.ApplyConstraintToChildren(constraint);
856
857   Wait(application);
858   // Defaulty Bound.
859   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
860
861   // UnBind
862   gConstraintResult = Vector3::ZERO;
863   scrollView.UnbindActor( a );
864   Wait(application);
865   DALI_TEST_EQUALS( gConstraintResult, Vector3::ZERO, TEST_LOCATION );
866
867   // Bind
868   gConstraintResult = Vector3::ZERO;
869   scrollView.BindActor( a );
870   Wait(application);
871   DALI_TEST_EQUALS( gConstraintResult, TEST_ACTOR_POSITION + TEST_CONSTRAINT_OFFSET, TEST_LOCATION );
872   END_TEST;
873 }
874
875 int UtcDaliRulerEnableDisable(void)
876 {
877   ToolkitTestApplication application;
878   tet_infoline(" UtcDaliRulerEnableDisable");
879
880   RulerPtr ruler = new DefaultRuler();
881
882   DALI_TEST_CHECK( ruler->IsEnabled() );
883   ruler->Disable();
884   DALI_TEST_CHECK( !ruler->IsEnabled() );
885   ruler->Enable();
886   DALI_TEST_CHECK( ruler->IsEnabled() );
887   END_TEST;
888 }
889
890 int UtcDaliRulerDomainEnableDisable(void)
891 {
892   ToolkitTestApplication application;
893   tet_infoline(" UtcDaliRulerDomainEnableDisable");
894
895   RulerPtr ruler = new DefaultRuler();
896   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
897
898
899   ruler->SetDomain( RulerDomain(0.0f, 100.0f, true) );
900   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 100.0f, TEST_LOCATION );
901   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), 0.0f, TEST_LOCATION );
902   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 100.0f, TEST_LOCATION );
903
904   ruler->DisableDomain();
905   DALI_TEST_EQUALS( ruler->GetDomain().GetSize(), 1.0f, TEST_LOCATION );
906   DALI_TEST_EQUALS( ruler->Clamp(-200.0f), -200.0f, TEST_LOCATION );
907   DALI_TEST_EQUALS( ruler->Clamp(200.0f), 200.0f, TEST_LOCATION );
908   END_TEST;
909 }
910
911 int UtcDaliRulerSnapAndClamp(void)
912 {
913   ToolkitTestApplication application;
914   tet_infoline(" UtcDaliRulerSnapAndClamp");
915
916   RulerPtr ruler = new FixedRuler( 50.0f );
917   ruler->SetDomain( RulerDomain(0.0f, 400.0f, true) );
918
919   // default testing. (snap and clamp)
920   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f), 50.0f, TEST_LOCATION);
921   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f), 50.0f, TEST_LOCATION);
922   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f), 0.0f, TEST_LOCATION);
923   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f), 0.0f, TEST_LOCATION);
924   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f), 400.0f, TEST_LOCATION);
925   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f), 400.0f, TEST_LOCATION);
926
927   // bias testing.
928   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
929   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 0.5f), 50.0f, TEST_LOCATION); // No Flick
930   DALI_TEST_EQUALS( ruler->SnapAndClamp(40.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
931
932   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.0f), 0.0f, TEST_LOCATION); // Flick Left
933   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 0.5f), 0.0f, TEST_LOCATION); // No Flick
934   DALI_TEST_EQUALS( ruler->SnapAndClamp(20.0f, 1.0f), 50.0f, TEST_LOCATION); // Flick Right
935
936   // length testing.
937   DALI_TEST_EQUALS( ruler->SnapAndClamp(-10.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (over left boundary)
938   DALI_TEST_EQUALS( ruler->SnapAndClamp(-5.0f, 0.5f, 10.0f), 0.0f, TEST_LOCATION); // 10 units long (slightly ovr left boundary)
939   DALI_TEST_EQUALS( ruler->SnapAndClamp(300.0f, 0.5f, 10.0f), 300.0f, TEST_LOCATION); // 10 units long (not over a boundary)
940   DALI_TEST_EQUALS( ruler->SnapAndClamp(395.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (slightly over right boundary)
941   DALI_TEST_EQUALS( ruler->SnapAndClamp(500.0f, 0.5f, 10.0f), 390.0f, TEST_LOCATION); // 10 units long (over right boundary)
942
943   // scale testing.
944   DALI_TEST_EQUALS( ruler->SnapAndClamp(-100.0f, 0.5f, 0.0f, 2.0f), 0.0f, TEST_LOCATION);
945   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 2.0f), 50.0f, TEST_LOCATION);
946   DALI_TEST_EQUALS( ruler->SnapAndClamp(700.0f, 0.5f, 0.0f, 2.0f), 700.0f, TEST_LOCATION);
947   DALI_TEST_EQUALS( ruler->SnapAndClamp(850.0f, 0.5f, 0.0f, 2.0f), 800.0f, TEST_LOCATION);
948
949   // clamp state testing.
950   ClampState clamped;
951   DALI_TEST_EQUALS( ruler->SnapAndClamp(50.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
952   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
953   DALI_TEST_EQUALS( ruler->SnapAndClamp(30.0f, 0.5f, 0.0f, 1.0f, clamped), 50.0f, TEST_LOCATION);
954   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
955   DALI_TEST_EQUALS( ruler->SnapAndClamp(10.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
956   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
957   DALI_TEST_EQUALS( ruler->SnapAndClamp(-40.0f, 0.5f, 0.0f, 1.0f, clamped), 0.0f, TEST_LOCATION);
958   DALI_TEST_EQUALS( clamped, ClampedToMin, TEST_LOCATION );
959   DALI_TEST_EQUALS( ruler->SnapAndClamp(390.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
960   DALI_TEST_EQUALS( clamped, NotClamped, TEST_LOCATION );
961   DALI_TEST_EQUALS( ruler->SnapAndClamp(430.0f, 0.5f, 0.0f, 1.0f, clamped), 400.0f, TEST_LOCATION);
962   DALI_TEST_EQUALS( clamped, ClampedToMax, TEST_LOCATION );
963   END_TEST;
964 }
965
966 int UtcDaliRulerFixedRulerSpacing(void)
967 {
968   ToolkitTestApplication application;
969   tet_infoline(" UtcDaliRulerFixedRulerSpacing");
970
971   RulerPtr rulerNormal = new FixedRuler( 25.0f );
972   rulerNormal->SetDomain( RulerDomain(10.0f, 90.0f, true) );
973
974   unsigned int volume;
975   float position;
976
977   position = rulerNormal->GetPositionFromPage(1, volume, true);
978   DALI_TEST_EQUALS( position, 35.0f, TEST_LOCATION );
979   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
980
981   position = rulerNormal->GetPositionFromPage(2, volume, true);
982   DALI_TEST_EQUALS( position, 60.0f, TEST_LOCATION );
983   DALI_TEST_EQUALS( volume, 0u, TEST_LOCATION );
984   END_TEST;
985 }
986
987 int UtcDaliScrollViewOvershoot(void)
988 {
989   ToolkitTestApplication application;
990   tet_infoline(" UtcDaliScrollViewOvershoot");
991
992   // Set up a scrollView...
993   ScrollView scrollView = ScrollView::New();
994   Stage::GetCurrent().Add( scrollView );
995   Vector2 stageSize = Stage::GetCurrent().GetSize();
996   scrollView.SetSize(stageSize);
997   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
998   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
999
1000   // Position rulers.
1001   RulerPtr rulerX = new DefaultRuler();
1002   RulerPtr rulerY = new DefaultRuler();
1003   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1004   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1005   scrollView.SetRulerX(rulerX);
1006   scrollView.SetRulerY(rulerY);
1007   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
1008   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1009   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
1010
1011   scrollView.ScrollTo(OVERSHOOT_START_SCROLL_POSITION, 0.0f); // move in a little.
1012   Wait(application);
1013
1014   // 1. Scroll page in NW (-500,-500 pixels), then inspect overshoot. (don't release touch)
1015   Vector2 currentPos = Vector2(100.0f, 100.0f);
1016   currentPos = PerformGestureDiagonalSwipe(application, currentPos, Vector2(5.0f, 5.0f), 100, false);
1017   float overshootXValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_X);
1018   float overshootYValue = scrollView.GetProperty<float>(ScrollView::Property::OVERSHOOT_Y);
1019   Vector3 positionValue = scrollView.GetProperty<Vector3>(ScrollView::Property::SCROLL_POSITION);
1020   DALI_TEST_EQUALS(overshootXValue, 1.0f, TEST_LOCATION);
1021   DALI_TEST_EQUALS(overshootYValue, 1.0f, TEST_LOCATION);
1022   DALI_TEST_EQUALS(positionValue, Vector3::ZERO, TEST_LOCATION);
1023
1024   float timeToReachOrigin;
1025
1026   // Now release touch. Overshoot should snap back to zero.
1027   SendPan(application, Gesture::Finished, currentPos);
1028   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1029
1030   DALI_TEST_CHECK( (timeToReachOrigin > Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1031                    (timeToReachOrigin < Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1032
1033   // 2. Repeat Scroll, but this time change overshoot snap duration to shorter time
1034   scrollView.SetSnapOvershootDuration(TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION);
1035
1036   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1037   // Now release touch. Overshoot should snap back to zero.
1038   SendPan(application, Gesture::Finished, currentPos);
1039   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1040
1041   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1042                    (timeToReachOrigin < TEST_CUSTOM1_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1043
1044   // 3. Repeat Scroll, but this time change overshoot snap duration to longer time.
1045   scrollView.SetSnapOvershootDuration(TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION);
1046
1047   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1048   // Now release touch. Overshoot should snap back to zero.
1049   SendPan(application, Gesture::Finished, currentPos);
1050   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1051
1052   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1053                    (timeToReachOrigin < TEST_CUSTOM2_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1054
1055   // 4. Repeat Scroll, but this time change overshoot function.
1056   scrollView.SetSnapOvershootDuration(TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION);
1057   scrollView.SetSnapOvershootAlphaFunction(TestAlphaFunction);
1058
1059   currentPos = PerformGestureDiagonalSwipe(application, Vector2(100.0f, 100.0f), Vector2(5.0f, 5.0f), 100, false);
1060   // Now release touch. Overshoot should snap back to zero.
1061   SendPan(application, Gesture::Finished, currentPos);
1062   timeToReachOrigin = TestOvershootSnapDuration(application, scrollView);
1063
1064   DALI_TEST_CHECK( (timeToReachOrigin > TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION - TIME_TOLERANCE) &&
1065                    (timeToReachOrigin < TEST_CUSTOM3_SNAP_OVERSHOOT_DURATION + TIME_TOLERANCE) );
1066   END_TEST;
1067 }
1068
1069 int UtcDaliScrollViewSnapAlphaFunction(void)
1070 {
1071   ToolkitTestApplication application;
1072   tet_infoline(" UtcDaliScrollViewSnapAlphaFunction");
1073
1074   // Set up a scrollView...
1075   ScrollView scrollView = ScrollView::New();
1076   scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseIn );
1077   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseIn );
1078   scrollView.SetScrollSnapAlphaFunction( AlphaFunctions::EaseOut );
1079   DALI_TEST_CHECK( scrollView.GetScrollSnapAlphaFunction() == AlphaFunctions::EaseOut );
1080
1081   scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::Bounce );
1082   DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::Bounce );
1083   scrollView.SetScrollFlickAlphaFunction( AlphaFunctions::BounceBack );
1084   DALI_TEST_CHECK( scrollView.GetScrollFlickAlphaFunction() == AlphaFunctions::BounceBack );
1085   END_TEST;
1086 }
1087
1088 int UtcDaliScrollViewSnapDuration(void)
1089 {
1090   ToolkitTestApplication application;
1091   tet_infoline(" UtcDaliScrollViewSnapDuration");
1092
1093   // Set up a scrollView...
1094   ScrollView scrollView = ScrollView::New();
1095   scrollView.SetScrollSnapDuration( 1.0f );
1096   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 1.0f, TEST_LOCATION );
1097   scrollView.SetScrollSnapDuration( 0.5f );
1098   DALI_TEST_EQUALS( scrollView.GetScrollSnapDuration(), 0.5f, TEST_LOCATION );
1099
1100   scrollView.SetScrollFlickDuration( 2.0f );
1101   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 2.0f, TEST_LOCATION );
1102   scrollView.SetScrollFlickDuration( 1.5f );
1103   DALI_TEST_EQUALS( scrollView.GetScrollFlickDuration(), 1.5f, TEST_LOCATION );
1104   END_TEST;
1105 }
1106
1107 int UtcDaliScrollViewSignalsSnapStart(void)
1108 {
1109   ToolkitTestApplication application;
1110   tet_infoline(" UtcDaliScrollViewSignalsSnapStart");
1111
1112   // Set up a scrollView...
1113   ScrollView scrollView = ScrollView::New();
1114   Stage::GetCurrent().Add( scrollView );
1115   Vector2 stageSize = Stage::GetCurrent().GetSize();
1116   scrollView.SetSize(stageSize);
1117   scrollView.SetParentOrigin(ParentOrigin::TOP_LEFT);
1118   scrollView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1119
1120   // Position rulers.
1121   RulerPtr rulerX = new DefaultRuler();
1122   RulerPtr rulerY = new DefaultRuler();
1123   rulerX->SetDomain( RulerDomain(0.0f, stageSize.width + CLAMP_EXCESS_WIDTH, true) );
1124   rulerY->SetDomain( RulerDomain(0.0f, stageSize.height + CLAMP_EXCESS_HEIGHT, true) );
1125   scrollView.SetRulerX(rulerX);
1126   scrollView.SetRulerY(rulerY);
1127   scrollView.SnapStartedSignal().Connect( &OnSnapStart );
1128
1129   scrollView.ScrollTo(CLAMP_START_SCROLL_POSITION, 0.0f); // move in a little.
1130   Wait(application);
1131
1132   // First try a snap.
1133   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(0.5f, 0.0f), 60, true);
1134
1135   DALI_TEST_CHECK( gOnSnapStartCalled );
1136   DALI_TEST_CHECK( gLastSnapType == Toolkit::Snap );
1137
1138   // Second try a swipe.
1139   PerformGestureDiagonalSwipe(application, CLAMP_TOUCH_START, Vector2(20.0f, 0.0f), 60, true);
1140
1141   DALI_TEST_CHECK( gOnSnapStartCalled );
1142   DALI_TEST_CHECK( gLastSnapType == Toolkit::Flick );
1143   END_TEST;
1144 }
1145
1146
1147 int UtcDaliScrollViewSetMouseWheelScrollDistanceStep(void)
1148 {
1149   ToolkitTestApplication application;
1150   tet_infoline(" UtcDaliScrollViewSetMouseWheelScrollDistanceStep");
1151
1152   ScrollView scrollView = ScrollView::New();
1153   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
1154   scrollView.SetMouseWheelScrollDistanceStep(Vector2(30.0f, 15.0f));
1155   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(30.0f, 15.0f), TEST_LOCATION );
1156   scrollView.SetMouseWheelScrollDistanceStep(Vector2(60.0f, 30.0f));
1157   DALI_TEST_EQUALS( scrollView.GetMouseWheelScrollDistanceStep(), Vector2(60.0f, 30.0f), TEST_LOCATION);
1158   END_TEST;
1159 }
1160
1161 int UtcDaliScrollViewGetSet(void)
1162 {
1163   ToolkitTestApplication application;
1164   tet_infoline(" UtcDaliScrollViewGetSet");
1165   ScrollView scrollView = ScrollView::New();
1166   scrollView.SetMaxOvershoot(50.0f, 50.0f);
1167   scrollView.SetMaxFlickSpeed(0.5f);
1168   DALI_TEST_EQUALS(scrollView.GetMaxFlickSpeed(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1169   scrollView.SetFrictionCoefficient(0.6f);
1170   DALI_TEST_EQUALS(scrollView.GetFrictionCoefficient(), 0.6f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1171   scrollView.SetFlickSpeedCoefficient(0.7f);
1172   DALI_TEST_EQUALS(scrollView.GetFlickSpeedCoefficient(), 0.7f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
1173   END_TEST;
1174 }