[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-toolkit.git] / automated-tests / dali-test-suite / scroll-view / utc-Dali-ScrollViewEffect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/pan-gesture-event.h>
26
27 #include <dali-toolkit-test-suite-utils.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 static void Startup();
33 static void Cleanup();
34
35 namespace
36 {
37 static bool gObjectCreatedCallBackCalled;
38
39 static void TestCallback(BaseHandle handle)
40 {
41   gObjectCreatedCallBackCalled = true;
42 }
43 } // namespace
44
45 extern "C" {
46   void (*tet_startup)() = Startup;
47   void (*tet_cleanup)() = Cleanup;
48 }
49
50 static void UtcDaliScrollViewCustomEffectSetup();
51 static void UtcDaliScrollViewCubeEffectSetup();
52 static void UtcDaliScrollViewPageCubeEffectSetup();
53 static void UtcDaliScrollViewSpiralEffectSetup();
54 static void UtcDaliScrollViewPageCarouselEffectSetup();
55 static void UtcDaliScrollViewCarouselEffectSetup();
56 static void UtcDaliScrollViewDepthEffectSetup();
57 static void UtcDaliScrollViewSlideEffectSetup();
58 static void UtcDaliScrollViewTwistEffectSetup();
59
60 static void UtcDaliScrollViewCubeEffectTest();
61 static void UtcDaliScrollViewPageCubeEffectTest();
62 static void UtcDaliScrollViewSpiralEffectTest();
63 static void UtcDaliScrollViewPageCarouselEffectTest();
64 static void UtcDaliScrollViewCarouselEffectTest();
65 static void UtcDaliScrollViewDepthEffectTest();
66 static void UtcDaliScrollViewSlideEffectTest();
67 static void UtcDaliScrollViewTwistEffectTest();
68 static void UtcDaliScrollViewCustomEffectTest();
69
70 enum {
71   POSITIVE_TC_IDX = 0x01,
72   NEGATIVE_TC_IDX,
73 };
74
75 // Add test functionality for all APIs in the class (Positive and Negative)
76 extern "C" {
77   struct tet_testlist tet_testlist[] = {
78     { UtcDaliScrollViewCustomEffectSetup, POSITIVE_TC_IDX },
79     { UtcDaliScrollViewCubeEffectSetup, POSITIVE_TC_IDX },
80     { UtcDaliScrollViewPageCubeEffectSetup, POSITIVE_TC_IDX },
81     { UtcDaliScrollViewSpiralEffectSetup, POSITIVE_TC_IDX },
82     { UtcDaliScrollViewPageCarouselEffectSetup, POSITIVE_TC_IDX },
83     { UtcDaliScrollViewCarouselEffectSetup, POSITIVE_TC_IDX },
84     { UtcDaliScrollViewDepthEffectSetup, POSITIVE_TC_IDX },
85     { UtcDaliScrollViewSlideEffectSetup, POSITIVE_TC_IDX },
86     { UtcDaliScrollViewTwistEffectSetup, POSITIVE_TC_IDX },
87     { UtcDaliScrollViewCubeEffectTest, POSITIVE_TC_IDX },
88     { UtcDaliScrollViewPageCubeEffectTest, POSITIVE_TC_IDX },
89     { UtcDaliScrollViewSpiralEffectTest, POSITIVE_TC_IDX },
90     { UtcDaliScrollViewPageCarouselEffectTest, POSITIVE_TC_IDX },
91     { UtcDaliScrollViewCarouselEffectTest, POSITIVE_TC_IDX },
92     { UtcDaliScrollViewDepthEffectTest, POSITIVE_TC_IDX },
93     { UtcDaliScrollViewSlideEffectTest, POSITIVE_TC_IDX },
94     { UtcDaliScrollViewTwistEffectTest, POSITIVE_TC_IDX },
95     { UtcDaliScrollViewCustomEffectTest, POSITIVE_TC_IDX },
96     { NULL, 0 }
97   };
98 }
99
100 namespace // unnamed namespace
101 {
102
103 const int MILLISECONDS_PER_SECOND = 1000;
104 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
105 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000;             ///< 1000ms to test animation
106 const int RENDER_DELAY_SCROLL = 1000;                           ///< duration to wait for any scroll to complete.
107
108 /*
109  * Simulate time passed by.
110  *
111  * @note this will always process at least 1 frame (1/60 sec)
112  *
113  * @param application Test application instance
114  * @param duration Time to pass in milliseconds.
115  * @return The actual time passed in milliseconds
116  */
117 int Wait(ToolkitTestApplication& application, int duration = 0)
118 {
119   int time = 0;
120
121   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
122   {
123     application.SendNotification();
124     application.Render(RENDER_FRAME_INTERVAL);
125     time += RENDER_FRAME_INTERVAL;
126   }
127
128   return time;
129 }
130
131 /**
132  * Creates a Ruler that snaps to a specified grid size.
133  * If that grid size is 0.0 then this ruler does not
134  * snap.
135  *
136  * @param[in] gridSize (optional) The grid size for the ruler,
137  * (Default = 0.0 i.e. no snapping)
138  * @return The ruler is returned.
139  */
140 RulerPtr CreateRuler(float gridSize = 0.0f)
141 {
142   if(gridSize <= Math::MACHINE_EPSILON_0)
143   {
144       return new DefaultRuler();
145   }
146   return new FixedRuler(gridSize);
147 }
148
149 // Callback probes.
150
151 static bool gOnScrollStartCalled;                       ///< Whether the OnScrollStart signal was invoked.
152 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
153 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
154 static bool gOnScrollClampedCalled;                     ///< Whether the OnScrollClamped signal was invoked.
155 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
156 static ClampState3 gLastClampPosition;                  ///< Clamping information from OnScrollClampedEvent.
157 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
158 static Vector3 gConstraintResult;                       ///< Result from constraint.
159
160 static ActorContainer gPages;                                ///< Keeps track of all the pages for applying effects.
161
162 static void ResetScrollCallbackResults()
163 {
164   gOnScrollStartCalled = false;
165   gOnScrollUpdateCalled = false;
166   gOnScrollCompleteCalled = false;
167 }
168
169 /**
170  * Invoked when scrolling starts.
171  *
172  * @param[in] position The current scroll position.
173  */
174 static void OnScrollStart( const Vector3& position )
175 {
176   gOnScrollStartCalled = true;
177 }
178
179 /**
180  * Invoked when scrolling updates (via dragging)
181  *
182  * @param[in] position The current scroll position.
183  */
184 static void OnScrollUpdate( const Vector3& position )
185 {
186   gOnScrollUpdateCalled = true;
187 }
188
189 /**
190  * Invoked when scrolling finishes
191  *
192  * @param[in] position The current scroll position.
193  */
194 static void OnScrollComplete( const Vector3& position )
195 {
196   gOnScrollCompleteCalled = true;
197 }
198
199 /**
200  * Invoked when scrolling clamped.
201  *
202  * @param[in] event The position/scale/rotation axes that were clamped.
203  */
204 static void OnScrollClamped( const ScrollView::ClampEvent& event )
205 {
206   gOnScrollClampedCalled = true;
207   gLastClampPosition = event.position;
208 }
209
210 /**
211  * Invoked when a snap or flick started.
212  *
213  * @param[in] event The type of snap and the target position/scale/rotation.
214  */
215 static void OnSnapStart( const ScrollView::SnapEvent& event )
216 {
217   gOnSnapStartCalled = true;
218   gLastSnapType = event.type;
219 }
220
221 ScrollView SetupTestScrollView(int rows, int columns, Vector2 size)
222 {
223   ScrollView scrollView = ScrollView::New();
224   scrollView.SetSize(size);
225   scrollView.SetAnchorPoint(AnchorPoint::CENTER);
226   scrollView.SetParentOrigin(ParentOrigin::CENTER);
227   scrollView.ApplyConstraint( Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
228   // Disable Refresh signal (TET environment cannot use adaptor's Timer)
229   scrollView.SetWrapMode(false);
230   scrollView.SetRefreshInterval(0);
231   scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
232   scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
233   scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
234   Stage::GetCurrent().Add( scrollView );
235   RulerPtr rulerX = CreateRuler(size.width);
236   RulerPtr rulerY = CreateRuler(size.height);
237   if(columns > 1)
238   {
239     rulerX->SetDomain(RulerDomain(0.0f, size.width * columns));
240   }
241   else
242   {
243     rulerX->Disable();
244   }
245   if(rows > 1)
246   {
247     rulerY->SetDomain(RulerDomain(0.0f, size.width * rows));
248   }
249   else
250   {
251     rulerY->Disable();
252   }
253
254   scrollView.SetRulerX( rulerX );
255   scrollView.SetRulerY( rulerY );
256   Stage::GetCurrent().Add( scrollView );
257
258   Actor container = Actor::New();
259   container.SetParentOrigin(ParentOrigin::CENTER);
260   container.SetAnchorPoint(AnchorPoint::CENTER);
261   container.SetSize( size );
262   scrollView.Add( container );
263   container.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
264
265   gPages.clear();
266   for(int row = 0;row<rows;row++)
267   {
268     for(int column = 0;column<columns;column++)
269     {
270       Actor page = Actor::New();
271       page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
272       page.SetParentOrigin( ParentOrigin::CENTER );
273       page.SetAnchorPoint( AnchorPoint::CENTER );
274       page.SetPosition( column * size.x, row * size.y );
275       container.Add(page);
276
277       gPages.push_back(page);
278     }
279   }
280
281   ResetScrollCallbackResults();
282   return scrollView;
283 }
284
285 void CleanupTest()
286 {
287   gPages.clear();
288   ResetScrollCallbackResults();
289 }
290
291 Actor AddActorToPage(Actor page, float x, float y, float cols, float rows)
292 {
293   Stage stage = Stage::GetCurrent();
294   Vector2 stageSize = stage.GetSize();
295
296   const float margin = 10.0f;
297   const Vector2 actorSize((stageSize.x / cols) - margin, (stageSize.y / rows) - margin);
298
299   Actor actor = Actor::New();
300   actor.SetParentOrigin( ParentOrigin::CENTER );
301   actor.SetAnchorPoint( AnchorPoint::CENTER );
302
303   Vector3 position( margin * 0.5f + (actorSize.x + margin) * x - stageSize.width * 0.5f,
304                     margin * 0.5f + (actorSize.y + margin) * y - stageSize.height * 0.5f,
305                     0.0f);
306   Vector3 positionEnd( margin * 0.5f + (actorSize.x + margin) * (x + cols) - stageSize.width * 0.5f - margin,
307                        margin * 0.5f + (actorSize.y + margin) * (y + rows) - stageSize.height * 0.5f - margin,
308                        0.0f);
309   Vector3 size(positionEnd - position);
310   actor.SetPosition( position + size * 0.5f);
311   actor.SetSize( positionEnd - position );
312   page.Add(actor);
313   return actor;
314 }
315
316 } // unnamed namespace
317
318 // Called only once before first test is run.
319 static void Startup()
320 {
321 }
322
323 // Called only once after last test is run
324 static void Cleanup()
325 {
326 }
327
328 static void UtcDaliScrollViewCustomEffectSetup()
329 {
330   tet_infoline(" UtcDaliScrollViewCustomEffectSetup");
331
332   ScrollViewCustomEffect effect;
333
334   DALI_TEST_CHECK( !effect );
335
336   BaseHandle handle = ScrollViewCustomEffect::New();
337
338   DALI_TEST_CHECK( handle );
339
340   effect = ScrollViewCustomEffect::DownCast(handle);
341
342   DALI_TEST_CHECK( effect );
343
344 }
345
346 static void UtcDaliScrollViewCubeEffectSetup()
347 {
348   tet_infoline(" UtcDaliScrollViewCubeEffectSetup");
349
350   ScrollViewCubeEffect effect;
351
352   DALI_TEST_CHECK( !effect );
353
354   BaseHandle handle = ScrollViewCubeEffect::New();
355
356   DALI_TEST_CHECK( handle );
357
358   effect = ScrollViewCubeEffect::DownCast(handle);
359
360   DALI_TEST_CHECK( effect );
361 }
362
363 static void UtcDaliScrollViewPageCubeEffectSetup()
364 {
365   tet_infoline(" UtcDaliScrollViewPageCubeEffectSetup");
366
367   ScrollViewPageCubeEffect effect;
368
369   DALI_TEST_CHECK( !effect );
370
371   BaseHandle handle = ScrollViewPageCubeEffect::New();
372
373   DALI_TEST_CHECK( handle );
374
375   effect = ScrollViewPageCubeEffect::DownCast(handle);
376
377   DALI_TEST_CHECK( effect );
378 }
379
380 static void UtcDaliScrollViewSpiralEffectSetup()
381 {
382   tet_infoline(" UtcDaliScrollViewSpiralEffectSetup");
383
384   ScrollViewPageSpiralEffect effect;
385
386   DALI_TEST_CHECK( !effect );
387
388   BaseHandle handle = ScrollViewPageSpiralEffect::New();
389
390   DALI_TEST_CHECK( handle );
391
392   effect = ScrollViewPageSpiralEffect::DownCast(handle);
393
394   DALI_TEST_CHECK( effect );
395 }
396
397 static void UtcDaliScrollViewPageCarouselEffectSetup()
398 {
399   tet_infoline(" UtcDaliScrollViewCarouselEffectSetup");
400
401   ScrollViewPageCarouselEffect effect;
402
403   DALI_TEST_CHECK( !effect );
404
405   BaseHandle handle = ScrollViewPageCarouselEffect::New();
406
407   DALI_TEST_CHECK( handle );
408
409   effect = ScrollViewPageCarouselEffect::DownCast(handle);
410
411   DALI_TEST_CHECK( effect );
412 }
413
414 static void UtcDaliScrollViewCarouselEffectSetup()
415 {
416   tet_infoline(" UtcDaliScrollViewCarouselEffectSetup");
417
418   ScrollViewCarouselEffect effect;
419
420   DALI_TEST_CHECK( !effect );
421
422   BaseHandle handle = ScrollViewCarouselEffect::New();
423
424   DALI_TEST_CHECK( handle );
425
426   effect = ScrollViewCarouselEffect::DownCast(handle);
427
428   DALI_TEST_CHECK( effect );
429 }
430
431 static void UtcDaliScrollViewDepthEffectSetup()
432 {
433   tet_infoline(" UtcDaliScrollViewDepthEffectSetup");
434
435   ScrollViewDepthEffect effect;
436
437   DALI_TEST_CHECK( !effect );
438
439   BaseHandle handle = ScrollViewDepthEffect::New();
440
441   DALI_TEST_CHECK( handle );
442
443   effect = ScrollViewDepthEffect::DownCast(handle);
444
445   DALI_TEST_CHECK( effect );
446 }
447
448 static void UtcDaliScrollViewSlideEffectSetup()
449 {
450   tet_infoline(" UtcDaliScrollViewSlideEffectSetup");
451
452   ScrollViewSlideEffect effect;
453
454   DALI_TEST_CHECK( !effect );
455
456   BaseHandle handle = ScrollViewSlideEffect::New();
457
458   DALI_TEST_CHECK( handle );
459
460   effect = ScrollViewSlideEffect::DownCast(handle);
461
462   DALI_TEST_CHECK( effect );
463 }
464
465 static void UtcDaliScrollViewTwistEffectSetup()
466 {
467   tet_infoline(" UtcDaliScrollViewTwistEffectSetup");
468
469   ScrollViewTwistEffect effect;
470
471   DALI_TEST_CHECK( !effect );
472
473   BaseHandle handle = ScrollViewTwistEffect::New();
474
475   DALI_TEST_CHECK( handle );
476
477   effect = ScrollViewTwistEffect::DownCast(handle);
478
479   DALI_TEST_CHECK( effect );
480 }
481
482 static void UtcDaliScrollViewCubeEffectTest()
483 {
484   ToolkitTestApplication application;
485   tet_infoline(" UtcDaliScrollViewCubeEffectTest");
486
487   Vector2 size = Stage::GetCurrent().GetSize();
488
489   ScrollView scrollView = SetupTestScrollView(1, 3, size);
490   Actor page = gPages[1];
491   Wait(application, 500);
492
493   ScrollViewCubeEffect effect = ScrollViewCubeEffect::New();
494   scrollView.ApplyEffect(effect);
495
496   Actor actor = AddActorToPage(page, 0.5f, 0.5f, 3, 3);
497   Wait(application);
498   Vector3 actorPrePosition = actor.GetCurrentPosition();
499
500   effect.ApplyToActor(actor, page, Vector3(-105.0f, 30.0f, -240.0f), Vector2(Math::PI * 0.5f, Math::PI * 0.5f), Vector2(0.25f, 0.25f) * size);
501
502   Actor actor2 = AddActorToPage(page, 0.5f, 0.5f, 3, 3);
503   effect.ApplyToActor(actor2, Vector3(-105.0f, 30.0f, -240.0f), Vector2(Math::PI * 0.5f, Math::PI * 0.5f), Vector2(0.25f, 0.25f) * size);
504
505   scrollView.ScrollTo(1);
506   while(!gOnScrollCompleteCalled)
507   {
508     Wait(application);
509   }
510   // test that the first page has reached centre of screen
511   Vector3 actorPostPosition = actor.GetCurrentPosition();
512   // just check the actor has moved
513   DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
514   CleanupTest();
515 }
516
517 static void UtcDaliScrollViewPageCubeEffectTest()
518 {
519   ToolkitTestApplication application;
520   tet_infoline(" UtcDaliScrollViewPageCubeEffectTest");
521
522   Vector2 size = Stage::GetCurrent().GetSize();
523
524   ScrollView scrollView = SetupTestScrollView(1, 3, size);
525   Actor testPage = gPages[1];
526   Wait(application, 500);
527
528   ScrollViewPageCubeEffect effect = ScrollViewPageCubeEffect::New();
529   scrollView.ApplyEffect(effect);
530
531   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
532   {
533     Actor page = *pageIter;
534     page.RemoveConstraints();
535     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
536     effect.ApplyToPage(page, Vector2(Math::PI_2, 0.0f));
537   }
538   Wait(application);
539
540   scrollView.ScrollTo(1);
541   while(!gOnScrollCompleteCalled)
542   {
543     Wait(application);
544   }
545   // test that the first page has reached centre of screen
546   Vector3 pagePos = testPage.GetCurrentPosition();
547   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
548   CleanupTest();
549 }
550
551 static void UtcDaliScrollViewSpiralEffectTest()
552 {
553   ToolkitTestApplication application;
554   tet_infoline(" UtcDaliScrollViewSpiralEffectTest");
555
556   Vector2 size = Stage::GetCurrent().GetSize();
557
558   ScrollView scrollView = SetupTestScrollView(1, 3, size);
559   Actor testPage = gPages[1];
560   Wait(application, 500);
561
562   ScrollViewPageSpiralEffect effect = ScrollViewPageSpiralEffect::New();
563   scrollView.ApplyEffect(effect);
564
565   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
566   {
567     Actor page = *pageIter;
568     page.RemoveConstraints();
569     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
570     effect.ApplyToPage(page, Vector2(Math::PI_2, 0.0f));
571   }
572   Wait(application);
573
574   scrollView.ScrollTo(1);
575   while(!gOnScrollCompleteCalled)
576   {
577     Wait(application);
578   }
579   // test that the first page has reached centre of screen
580   Vector3 pagePos = testPage.GetCurrentPosition();
581   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
582   CleanupTest();
583 }
584
585 static void UtcDaliScrollViewPageCarouselEffectTest()
586 {
587   ToolkitTestApplication application;
588   tet_infoline(" UtcDaliScrollViewPageCarouselEffectTest");
589
590   Vector2 size = Stage::GetCurrent().GetSize();
591
592   ScrollView scrollView = SetupTestScrollView(1, 3, size);
593   Actor testPage = gPages[1];
594   Wait(application, 500);
595
596   ScrollViewPageCarouselEffect effect = ScrollViewPageCarouselEffect::New();
597   scrollView.ApplyEffect(effect);
598
599   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
600   {
601     Actor page = *pageIter;
602     page.RemoveConstraints();
603     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
604     effect.ApplyToPage(page);
605   }
606   Wait(application);
607
608   scrollView.ScrollTo(1, 0.5f, DirectionBiasNone);
609   while(!gOnScrollCompleteCalled)
610   {
611     Wait(application);
612   }
613   // test that the first page has reached centre of screen
614   Vector3 pagePos = testPage.GetCurrentPosition();
615   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
616   CleanupTest();
617 }
618
619 static void UtcDaliScrollViewCarouselEffectTest()
620 {
621   ToolkitTestApplication application;
622   tet_infoline(" UtcDaliScrollViewCarouselEffectTest");
623
624   Vector2 size = Stage::GetCurrent().GetSize();
625
626   ScrollView scrollView = SetupTestScrollView(1, 3, size);
627   Actor testPage = gPages[1];
628   Wait(application, 500);
629
630   ScrollViewCarouselEffect effect = ScrollViewCarouselEffect::New();
631   scrollView.ApplyEffect(effect);
632
633   Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
634   Wait(application);
635   Vector3 actorPrePosition = actor.GetCurrentPosition();
636
637   effect.ApplyToActor( actor, Vector2(1.2f, 1.2f) );
638
639   scrollView.ScrollTo(Vector3(size.x, 0.0f, 0.0f), 0.5f, DirectionBiasNone, DirectionBiasNone);
640   while(!gOnScrollCompleteCalled)
641   {
642     Wait(application);
643   }
644   // test that the first page has reached centre of screen
645   Vector3 actorPostPosition = actor.GetCurrentPosition();
646   // just check the actor has moved
647   DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
648   CleanupTest();
649 }
650
651 static void UtcDaliScrollViewDepthEffectTest()
652 {
653   ToolkitTestApplication application;
654   tet_infoline(" UtcDaliScrollViewDepthEffectTest");
655
656   Vector2 size = Stage::GetCurrent().GetSize();
657
658   ScrollView scrollView = SetupTestScrollView(1, 3, size);
659   Actor testPage = gPages[1];
660   Wait(application, 500);
661
662   ScrollViewDepthEffect effect = ScrollViewDepthEffect::New();
663   scrollView.ApplyEffect(effect);
664
665   Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
666   Wait(application);
667   Vector3 actorPrePosition = actor.GetCurrentPosition();
668
669   const Vector2 positionExtent(0.5f, 2.5f);
670   const Vector2 offsetExtent(1.0f, 1.0f);
671   const float positionScale(1.5f);
672   const float scaleExtent(0.5f);
673
674   effect.ApplyToActor( actor, positionExtent, offsetExtent, positionScale, scaleExtent );
675
676   scrollView.ScrollTo(1);
677   while(!gOnScrollCompleteCalled)
678   {
679     Wait(application);
680   }
681   // test that the first page has reached centre of screen
682   Vector3 actorPostPosition = actor.GetCurrentPosition();
683   // just check the actor has moved
684   DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
685   CleanupTest();
686 }
687
688 static void UtcDaliScrollViewSlideEffectTest()
689 {
690   ToolkitTestApplication application;
691   tet_infoline(" UtcDaliScrollViewSlideEffectTest");
692
693   Vector2 size = Stage::GetCurrent().GetSize();
694   Vector3 pageSize(size.x, size.y, 0.0f);
695
696   ScrollView scrollView = SetupTestScrollView(1, 3, size);
697   Actor testPage = gPages[1];
698   Wait(application, 500);
699
700   ScrollViewSlideEffect effect = ScrollViewSlideEffect::New();
701   effect.SetDelayReferenceOffset(pageSize * 0.25);
702   DALI_TEST_EQUALS(effect.GetDelayReferenceOffset(), pageSize * 0.25, Math::MACHINE_EPSILON_0, TEST_LOCATION);
703   effect.SetMaxDelayDuration(0.5f);
704   DALI_TEST_EQUALS(effect.GetMaxDelayDuration(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
705   effect.SetSlideDirection(false);
706   DALI_TEST_CHECK(!effect.GetSlideDirection());
707
708   scrollView.ApplyEffect(effect);
709
710   Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
711   Wait(application);
712   Vector3 actorPrePosition = actor.GetCurrentPosition();
713
714   effect.ApplyToActor(actor, 0.0f, 0.5f);
715
716   scrollView.ScrollTo(1);
717   while(!gOnScrollCompleteCalled)
718   {
719     Wait(application);
720   }
721   // test that the first page has reached centre of screen
722   Vector3 actorPostPosition = actor.GetCurrentPosition();
723   // just check the actor has moved
724   DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
725   CleanupTest();
726 }
727
728 static void UtcDaliScrollViewTwistEffectTest()
729 {
730   ToolkitTestApplication application;
731   tet_infoline(" UtcDaliScrollViewTwistEffectTest");
732
733   Vector2 size = Stage::GetCurrent().GetSize();
734
735   ScrollView scrollView = SetupTestScrollView(1, 3, size);
736   Actor testPage = gPages[1];
737   Wait(application, 500);
738
739   ScrollViewTwistEffect effect = ScrollViewTwistEffect::New();
740   float shrinkDist = 0.2f;
741   effect.SetMinimumDistanceForShrink(shrinkDist);
742   DALI_TEST_CHECK((shrinkDist - effect.GetMinimumDistanceForShrink()) < Math::MACHINE_EPSILON_0);
743   effect.EnableEffect(true);
744   scrollView.ApplyEffect(effect);
745
746   Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
747   Wait(application);
748   Vector3 actorPrePosition = actor.GetCurrentPosition();
749
750   effect.ApplyToActor( actor,
751       true,
752       Vector2(Math::PI_2, Math::PI_2),
753       0.0f);
754
755   scrollView.ScrollTo(1);
756   while(!gOnScrollCompleteCalled)
757   {
758     Wait(application);
759   }
760   // test that the first page has reached centre of screen
761   Vector3 actorPostPosition = actor.GetCurrentPosition();
762   // just check the actor has moved
763   DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
764   CleanupTest();
765 }
766
767 static void UtcDaliScrollViewCustomEffectTest()
768 {
769   ToolkitTestApplication application;
770   tet_infoline(" UtcDaliScrollViewCustomEffectTest");
771
772   Vector2 size = Stage::GetCurrent().GetSize();
773   Vector3 pageSize(size.x, size.y, 0.0f);
774
775   ScrollView scrollView = SetupTestScrollView(1, 3, size);
776   Actor testPage = gPages[1];
777   Wait(application, 500);
778   Vector3 pageStartPos, pagePos;
779   pageStartPos = pagePos = testPage.GetCurrentPosition();
780   //scrollView.RemoveConstraintsFromChildren();
781
782   ScrollViewCustomEffect effect = ScrollViewCustomEffect::DownCast(scrollView.ApplyEffect(ScrollView::PageEffectCarousel));
783
784   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
785   {
786     Actor page = *pageIter;
787     page.RemoveConstraints();
788     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
789     effect.ApplyToPage(page, pageSize);
790   }
791   Wait(application);
792   pagePos = testPage.GetCurrentPosition();
793   DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
794
795   scrollView.ScrollTo(1);
796   while(!gOnScrollCompleteCalled)
797   {
798     Wait(application);
799   }
800   ResetScrollCallbackResults();
801   // test that the first page has reached centre of screen
802   pagePos = testPage.GetCurrentPosition();
803   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
804
805   // scroll back to page 0
806   scrollView.ScrollTo(0);
807   while(!gOnScrollCompleteCalled)
808   {
809     Wait(application);
810   }
811   ResetScrollCallbackResults();
812   pagePos = testPage.GetCurrentPosition();
813   DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
814
815   scrollView.RemoveEffect(effect);
816
817   effect = ScrollViewCustomEffect::New();
818   effect.SetPageTranslation(Vector3(20.0f, 20.0f, 5.0f));
819   effect.SetPageTranslation(Vector3(20.0f, 20.0f, 5.0f), Vector3(20.0f, 20.0f, -5.0f));
820   effect.SetPageTranslationIn(Vector3(20.0f, 20.0f, 5.0f));
821   effect.SetPageTranslationOut(Vector3(20.0f, 20.0f, -5.0f));
822   effect.SetPageTranslation(Vector3(20.0f, 0.0f, 0.0f));
823   effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
824   effect.SetPageSpacing(Vector2(20.0f, 20.0f));
825   scrollView.ApplyEffect(effect);
826
827   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
828   {
829     Actor page = *pageIter;
830     page.RemoveConstraints();
831     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
832     effect.ApplyToPage(page, pageSize);
833   }
834   Wait(application);
835   pagePos = testPage.GetCurrentPosition();
836   DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
837
838   scrollView.ScrollTo(1);
839   while(!gOnScrollCompleteCalled)
840   {
841     Wait(application);
842   }
843   ResetScrollCallbackResults();
844   // test that the first page has reached centre of screen
845   pagePos = testPage.GetCurrentPosition();
846   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
847
848   // scroll back to page 0
849   scrollView.ScrollTo(0);
850   while(!gOnScrollCompleteCalled)
851   {
852     Wait(application);
853   }
854   ResetScrollCallbackResults();
855   pagePos = testPage.GetCurrentPosition();
856   DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
857
858   scrollView.RemoveEffect(effect);
859   effect = ScrollViewCustomEffect::New();
860   effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
861   effect.SetSwingAnchor(AnchorPoint::CENTER_LEFT);
862   effect.SetPageTranslation(Vector3(size.x, size.y, 0));
863   effect.SetOpacityThreshold(0.66f);
864   scrollView.ApplyEffect(effect);
865
866   for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
867   {
868     Actor page = *pageIter;
869     page.RemoveConstraints();
870     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
871     effect.ApplyToPage(page, pageSize);
872   }
873   Wait(application);
874
875   scrollView.ScrollTo(1);
876   while(!gOnScrollCompleteCalled)
877   {
878     Wait(application);
879   }
880   ResetScrollCallbackResults();
881   // test that the first page has reached centre of screen
882   pagePos = testPage.GetCurrentPosition();
883   DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
884
885   // scroll back to page 0
886   scrollView.ScrollTo(0);
887   while(!gOnScrollCompleteCalled)
888   {
889     Wait(application);
890   }
891   ResetScrollCallbackResults();
892   pagePos = testPage.GetCurrentPosition();
893   DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
894   scrollView.RemoveEffect(effect);
895
896
897   effect.SetPageTranslateAlphaFunction(AlphaFunctions::Linear);
898   effect.SetPageTranslateAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
899   effect.SetPageTranslateAlphaFunctionIn(AlphaFunctions::Linear);
900   effect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::Linear);
901   effect.SetGlobalPageRotation(Math::PI, Vector3::YAXIS);
902   effect.SetAngledOriginPageRotation(Vector3(Math::PI, Math::PI, 0.0f));
903   effect.SetGlobalPageRotation(Math::PI, Vector3::YAXIS, Math::PI, Vector3::YAXIS);
904   effect.SetGlobalPageRotationIn(Math::PI, Vector3::YAXIS);
905   effect.SetGlobalPageRotationOut(Math::PI, Vector3::YAXIS);
906   effect.SetGlobalPageRotationOrigin(Vector3::ZERO);
907   effect.SetGlobalPageRotationOrigin(Vector3::ZERO, Vector3::ZERO);
908   effect.SetGlobalPageRotationOriginIn(Vector3::ZERO);
909   effect.SetGlobalPageRotationOriginOut(Vector3::ZERO);
910   effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
911   effect.SetSwingAngle(Math::PI, Vector3::YAXIS, Math::PI, Vector3::YAXIS);
912   effect.SetSwingAngleIn(Math::PI, Vector3::YAXIS);
913   effect.SetSwingAngleOut(Math::PI, Vector3::YAXIS);
914   effect.SetSwingAngleAlphaFunction(AlphaFunctions::Linear);
915   effect.SetSwingAngleAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
916   effect.SetSwingAngleAlphaFunctionIn(AlphaFunctions::Linear);
917   effect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::Linear);
918   effect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
919   effect.SetSwingAnchorIn(AnchorPoint::CENTER);
920   effect.SetSwingAnchorOut(AnchorPoint::CENTER);
921   effect.SetSwingAnchorAlphaFunction(AlphaFunctions::Linear);
922   effect.SetSwingAnchorAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
923   effect.SetSwingAnchorAlphaFunctionIn(AlphaFunctions::Linear);
924   effect.SetSwingAnchorAlphaFunctionOut(AlphaFunctions::Linear);
925   effect.SetOpacityThreshold(0.5f);
926   effect.SetOpacityThreshold(0.5f, 0.5f);
927   effect.SetOpacityThresholdIn(0.5f);
928   effect.SetOpacityThresholdOut(0.5f);
929   effect.SetOpacityAlphaFunction(AlphaFunctions::Linear);
930   effect.SetOpacityAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
931   effect.SetOpacityAlphaFunctionIn(AlphaFunctions::Linear);
932   effect.SetOpacityAlphaFunctionOut(AlphaFunctions::Linear);
933   CleanupTest();
934 }