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