2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/pan-gesture-event.h>
31 using namespace Toolkit;
33 void utc_dali_toolkit_scroll_view_effect_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_scroll_view_effect_cleanup(void)
40 test_return_value = TET_PASS;
46 const int MILLISECONDS_PER_SECOND = 1000;
47 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
48 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
49 const int RENDER_DELAY_SCROLL = 1000; ///< duration to wait for any scroll to complete.
52 * Simulate time passed by.
54 * @note this will always process at least 1 frame (1/60 sec)
56 * @param application Test application instance
57 * @param duration Time to pass in milliseconds.
58 * @return The actual time passed in milliseconds
60 int Wait(ToolkitTestApplication& application, int duration = 0)
64 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
66 application.SendNotification();
67 application.Render(RENDER_FRAME_INTERVAL);
68 time += RENDER_FRAME_INTERVAL;
75 * Creates a Ruler that snaps to a specified grid size.
76 * If that grid size is 0.0 then this ruler does not
79 * @param[in] gridSize (optional) The grid size for the ruler,
80 * (Default = 0.0 i.e. no snapping)
81 * @return The ruler is returned.
83 RulerPtr CreateRuler(float gridSize = 0.0f)
85 if(gridSize <= Math::MACHINE_EPSILON_0)
87 return new DefaultRuler();
89 return new FixedRuler(gridSize);
94 static bool gOnScrollStartCalled; ///< Whether the OnScrollStart signal was invoked.
95 static bool gOnScrollUpdateCalled; ///< Whether the OnScrollUpdate signal was invoked.
96 static bool gOnScrollCompleteCalled; ///< Whether the OnScrollComplete signal was invoked.
97 static Vector3 gConstraintResult; ///< Result from constraint.
99 static ActorContainer gPages; ///< Keeps track of all the pages for applying effects.
101 static void ResetScrollCallbackResults()
103 gOnScrollStartCalled = false;
104 gOnScrollUpdateCalled = false;
105 gOnScrollCompleteCalled = false;
109 * Invoked when scrolling starts.
111 * @param[in] position The current scroll position.
113 static void OnScrollStart( const Vector3& position )
115 gOnScrollStartCalled = true;
119 * Invoked when scrolling updates (via dragging)
121 * @param[in] position The current scroll position.
123 static void OnScrollUpdate( const Vector3& position )
125 gOnScrollUpdateCalled = true;
129 * Invoked when scrolling finishes
131 * @param[in] position The current scroll position.
133 static void OnScrollComplete( const Vector3& position )
135 gOnScrollCompleteCalled = true;
138 ScrollView SetupTestScrollView(int rows, int columns, Vector2 size)
140 ScrollView scrollView = ScrollView::New();
141 scrollView.SetSize(size);
142 scrollView.SetAnchorPoint(AnchorPoint::CENTER);
143 scrollView.SetParentOrigin(ParentOrigin::CENTER);
144 scrollView.ApplyConstraint( Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
145 scrollView.SetWrapMode(false);
146 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
147 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
148 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
149 Stage::GetCurrent().Add( scrollView );
150 RulerPtr rulerX = CreateRuler(size.width);
151 RulerPtr rulerY = CreateRuler(size.height);
154 rulerX->SetDomain(RulerDomain(0.0f, size.width * columns));
162 rulerY->SetDomain(RulerDomain(0.0f, size.width * rows));
169 scrollView.SetRulerX( rulerX );
170 scrollView.SetRulerY( rulerY );
171 Stage::GetCurrent().Add( scrollView );
173 Actor container = Actor::New();
174 container.SetParentOrigin(ParentOrigin::CENTER);
175 container.SetAnchorPoint(AnchorPoint::CENTER);
176 container.SetSize( size );
177 scrollView.Add( container );
178 container.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
181 for(int row = 0;row<rows;row++)
183 for(int column = 0;column<columns;column++)
185 Actor page = Actor::New();
186 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
187 page.SetParentOrigin( ParentOrigin::CENTER );
188 page.SetAnchorPoint( AnchorPoint::CENTER );
189 page.SetPosition( column * size.x, row * size.y );
192 gPages.push_back(page);
196 ResetScrollCallbackResults();
203 ResetScrollCallbackResults();
206 Actor AddActorToPage(Actor page, float x, float y, float cols, float rows)
208 Stage stage = Stage::GetCurrent();
209 Vector2 stageSize = stage.GetSize();
211 const float margin = 10.0f;
212 const Vector2 actorSize((stageSize.x / cols) - margin, (stageSize.y / rows) - margin);
214 Actor actor = Actor::New();
215 actor.SetParentOrigin( ParentOrigin::CENTER );
216 actor.SetAnchorPoint( AnchorPoint::CENTER );
218 Vector3 position( margin * 0.5f + (actorSize.x + margin) * x - stageSize.width * 0.5f,
219 margin * 0.5f + (actorSize.y + margin) * y - stageSize.height * 0.5f,
221 Vector3 positionEnd( margin * 0.5f + (actorSize.x + margin) * (x + cols) - stageSize.width * 0.5f - margin,
222 margin * 0.5f + (actorSize.y + margin) * (y + rows) - stageSize.height * 0.5f - margin,
224 Vector3 size(positionEnd - position);
225 actor.SetPosition( position + size * 0.5f);
226 actor.SetSize( positionEnd - position );
231 } // unnamed namespace
234 int UtcDaliScrollViewCustomEffectSetup(void)
236 tet_infoline(" UtcDaliScrollViewCustomEffectSetup");
238 ScrollViewCustomEffect effect;
240 DALI_TEST_CHECK( !effect );
242 BaseHandle handle = ScrollViewCustomEffect::New();
244 DALI_TEST_CHECK( handle );
246 effect = ScrollViewCustomEffect::DownCast(handle);
248 DALI_TEST_CHECK( effect );
253 int UtcDaliScrollViewCubeEffectSetup(void)
255 tet_infoline(" UtcDaliScrollViewCubeEffectSetup");
257 ScrollViewCubeEffect effect;
259 DALI_TEST_CHECK( !effect );
261 BaseHandle handle = ScrollViewCubeEffect::New();
263 DALI_TEST_CHECK( handle );
265 effect = ScrollViewCubeEffect::DownCast(handle);
267 DALI_TEST_CHECK( effect );
271 int UtcDaliScrollViewSpiralEffectSetup(void)
273 tet_infoline(" UtcDaliScrollViewSpiralEffectSetup");
275 ScrollViewPageSpiralEffect effect;
277 DALI_TEST_CHECK( !effect );
279 BaseHandle handle = ScrollViewPageSpiralEffect::New();
281 DALI_TEST_CHECK( handle );
283 effect = ScrollViewPageSpiralEffect::DownCast(handle);
285 DALI_TEST_CHECK( effect );
292 int UtcDaliScrollViewSlideEffectSetup(void)
294 tet_infoline(" UtcDaliScrollViewSlideEffectSetup");
296 ScrollViewSlideEffect effect;
298 DALI_TEST_CHECK( !effect );
300 BaseHandle handle = ScrollViewSlideEffect::New();
302 DALI_TEST_CHECK( handle );
304 effect = ScrollViewSlideEffect::DownCast(handle);
306 DALI_TEST_CHECK( effect );
310 int UtcDaliScrollViewTwistEffectSetup(void)
312 tet_infoline(" UtcDaliScrollViewTwistEffectSetup");
314 ScrollViewTwistEffect effect;
316 DALI_TEST_CHECK( !effect );
318 BaseHandle handle = ScrollViewTwistEffect::New();
320 DALI_TEST_CHECK( handle );
322 effect = ScrollViewTwistEffect::DownCast(handle);
324 DALI_TEST_CHECK( effect );
328 int UtcDaliScrollViewCubeEffectTest(void)
330 ToolkitTestApplication application;
331 tet_infoline(" UtcDaliScrollViewCubeEffectTest");
333 Vector2 size = Stage::GetCurrent().GetSize();
335 ScrollView scrollView = SetupTestScrollView(1, 3, size);
336 Actor page = gPages[1];
337 Wait(application, 500);
339 ScrollViewCubeEffect effect = ScrollViewCubeEffect::New();
340 scrollView.ApplyEffect(effect);
342 Actor actor = AddActorToPage(page, 0.5f, 0.5f, 3, 3);
344 Vector3 actorPrePosition = actor.GetCurrentPosition();
346 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);
348 Actor actor2 = AddActorToPage(page, 0.5f, 0.5f, 3, 3);
349 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);
351 scrollView.ScrollTo(1);
352 while(!gOnScrollCompleteCalled)
356 // test that the first page has reached centre of screen
357 Vector3 actorPostPosition = actor.GetCurrentPosition();
358 // just check the actor has moved
359 DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
365 int UtcDaliScrollViewSpiralEffectTest(void)
367 ToolkitTestApplication application;
368 tet_infoline(" UtcDaliScrollViewSpiralEffectTest");
370 Vector2 size = Stage::GetCurrent().GetSize();
372 ScrollView scrollView = SetupTestScrollView(1, 3, size);
373 Actor testPage = gPages[1];
374 Wait(application, 500);
376 ScrollViewPageSpiralEffect effect = ScrollViewPageSpiralEffect::New();
377 scrollView.ApplyEffect(effect);
379 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
381 Actor page = *pageIter;
382 page.RemoveConstraints();
383 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
384 effect.ApplyToPage(page, Vector2(Math::PI_2, 0.0f));
388 scrollView.ScrollTo(1);
389 while(!gOnScrollCompleteCalled)
393 // test that the first page has reached centre of screen
394 Vector3 pagePos = testPage.GetCurrentPosition();
395 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
402 int UtcDaliScrollViewSlideEffectTest(void)
404 ToolkitTestApplication application;
405 tet_infoline(" UtcDaliScrollViewSlideEffectTest");
407 Vector2 size = Stage::GetCurrent().GetSize();
408 Vector3 pageSize(size.x, size.y, 0.0f);
410 ScrollView scrollView = SetupTestScrollView(1, 3, size);
411 Actor testPage = gPages[1];
412 Wait(application, 500);
414 ScrollViewSlideEffect effect = ScrollViewSlideEffect::New();
415 effect.SetDelayReferenceOffset(pageSize * 0.25);
416 DALI_TEST_EQUALS(effect.GetDelayReferenceOffset(), pageSize * 0.25, Math::MACHINE_EPSILON_0, TEST_LOCATION);
417 effect.SetMaxDelayDuration(0.5f);
418 DALI_TEST_EQUALS(effect.GetMaxDelayDuration(), 0.5f, Math::MACHINE_EPSILON_0, TEST_LOCATION);
419 effect.SetSlideDirection(false);
420 DALI_TEST_CHECK(!effect.GetSlideDirection());
422 scrollView.ApplyEffect(effect);
424 Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
426 Vector3 actorPrePosition = actor.GetCurrentPosition();
428 effect.ApplyToActor(actor, 0.0f, 0.5f);
430 scrollView.ScrollTo(1);
431 while(!gOnScrollCompleteCalled)
435 // test that the first page has reached centre of screen
436 Vector3 actorPostPosition = actor.GetCurrentPosition();
437 // just check the actor has moved
438 DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
443 int UtcDaliScrollViewTwistEffectTest(void)
445 ToolkitTestApplication application;
446 tet_infoline(" UtcDaliScrollViewTwistEffectTest");
448 Vector2 size = Stage::GetCurrent().GetSize();
450 ScrollView scrollView = SetupTestScrollView(1, 3, size);
451 Actor testPage = gPages[1];
452 Wait(application, 500);
454 ScrollViewTwistEffect effect = ScrollViewTwistEffect::New();
455 float shrinkDist = 0.2f;
456 effect.SetMinimumDistanceForShrink(shrinkDist);
457 DALI_TEST_CHECK((shrinkDist - effect.GetMinimumDistanceForShrink()) < Math::MACHINE_EPSILON_0);
458 effect.EnableEffect(true);
459 scrollView.ApplyEffect(effect);
461 Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
463 Vector3 actorPrePosition = actor.GetCurrentPosition();
465 effect.ApplyToActor( actor,
467 Vector2(Math::PI_2, Math::PI_2),
470 scrollView.ScrollTo(1);
471 while(!gOnScrollCompleteCalled)
475 // test that the first page has reached centre of screen
476 Vector3 actorPostPosition = actor.GetCurrentPosition();
477 // just check the actor has moved
478 DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
483 int UtcDaliScrollViewCustomEffectTest(void)
485 ToolkitTestApplication application;
486 tet_infoline(" UtcDaliScrollViewCustomEffectTest");
488 Vector2 size = Stage::GetCurrent().GetSize();
489 Vector3 pageSize(size.x, size.y, 0.0f);
491 ScrollView scrollView = SetupTestScrollView(1, 3, size);
492 Actor testPage = gPages[1];
493 Wait(application, 500);
494 Vector3 pageStartPos, pagePos;
495 pageStartPos = pagePos = testPage.GetCurrentPosition();
496 //scrollView.RemoveConstraintsFromChildren();
498 ScrollViewCustomEffect effect = ScrollViewCustomEffect::DownCast(scrollView.ApplyEffect(ScrollView::PageEffectCarousel));
500 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
502 Actor page = *pageIter;
503 page.RemoveConstraints();
504 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
505 effect.ApplyToPage(page, pageSize);
508 pagePos = testPage.GetCurrentPosition();
509 DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
511 scrollView.ScrollTo(1);
512 while(!gOnScrollCompleteCalled)
516 ResetScrollCallbackResults();
517 // test that the first page has reached centre of screen
518 pagePos = testPage.GetCurrentPosition();
519 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
521 // scroll back to page 0
522 scrollView.ScrollTo(0);
523 while(!gOnScrollCompleteCalled)
527 ResetScrollCallbackResults();
528 pagePos = testPage.GetCurrentPosition();
529 DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
531 scrollView.RemoveEffect(effect);
533 effect = ScrollViewCustomEffect::New();
534 effect.SetPageTranslation(Vector3(20.0f, 20.0f, 5.0f));
535 effect.SetPageTranslation(Vector3(20.0f, 20.0f, 5.0f), Vector3(20.0f, 20.0f, -5.0f));
536 effect.SetPageTranslationIn(Vector3(20.0f, 20.0f, 5.0f));
537 effect.SetPageTranslationOut(Vector3(20.0f, 20.0f, -5.0f));
538 effect.SetPageTranslation(Vector3(20.0f, 0.0f, 0.0f));
539 effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
540 effect.SetPageSpacing(Vector2(20.0f, 20.0f));
541 scrollView.ApplyEffect(effect);
543 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
545 Actor page = *pageIter;
546 page.RemoveConstraints();
547 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
548 effect.ApplyToPage(page, pageSize);
551 pagePos = testPage.GetCurrentPosition();
552 DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
554 scrollView.ScrollTo(1);
555 while(!gOnScrollCompleteCalled)
559 ResetScrollCallbackResults();
560 // test that the first page has reached centre of screen
561 pagePos = testPage.GetCurrentPosition();
562 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
564 // scroll back to page 0
565 scrollView.ScrollTo(0);
566 while(!gOnScrollCompleteCalled)
570 ResetScrollCallbackResults();
571 pagePos = testPage.GetCurrentPosition();
572 DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
574 scrollView.RemoveEffect(effect);
575 effect = ScrollViewCustomEffect::New();
576 effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
577 effect.SetSwingAnchor(AnchorPoint::CENTER_LEFT);
578 effect.SetPageTranslation(Vector3(size.x, size.y, 0));
579 effect.SetOpacityThreshold(0.66f);
580 scrollView.ApplyEffect(effect);
582 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
584 Actor page = *pageIter;
585 page.RemoveConstraints();
586 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
587 effect.ApplyToPage(page, pageSize);
591 scrollView.ScrollTo(1);
592 while(!gOnScrollCompleteCalled)
596 ResetScrollCallbackResults();
597 // test that the first page has reached centre of screen
598 pagePos = testPage.GetCurrentPosition();
599 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
601 // scroll back to page 0
602 scrollView.ScrollTo(0);
603 while(!gOnScrollCompleteCalled)
607 ResetScrollCallbackResults();
608 pagePos = testPage.GetCurrentPosition();
609 DALI_TEST_EQUALS(pagePos, pageStartPos, Math::MACHINE_EPSILON_0, TEST_LOCATION);
610 scrollView.RemoveEffect(effect);
613 effect.SetPageTranslateAlphaFunction(AlphaFunctions::Linear);
614 effect.SetPageTranslateAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
615 effect.SetPageTranslateAlphaFunctionIn(AlphaFunctions::Linear);
616 effect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::Linear);
617 effect.SetGlobalPageRotation(Math::PI, Vector3::YAXIS);
618 effect.SetAngledOriginPageRotation(Vector3(Math::PI, Math::PI, 0.0f));
619 effect.SetGlobalPageRotation(Math::PI, Vector3::YAXIS, Math::PI, Vector3::YAXIS);
620 effect.SetGlobalPageRotationIn(Math::PI, Vector3::YAXIS);
621 effect.SetGlobalPageRotationOut(Math::PI, Vector3::YAXIS);
622 effect.SetGlobalPageRotationOrigin(Vector3::ZERO);
623 effect.SetGlobalPageRotationOrigin(Vector3::ZERO, Vector3::ZERO);
624 effect.SetGlobalPageRotationOriginIn(Vector3::ZERO);
625 effect.SetGlobalPageRotationOriginOut(Vector3::ZERO);
626 effect.SetSwingAngle(Math::PI, Vector3::YAXIS);
627 effect.SetSwingAngle(Math::PI, Vector3::YAXIS, Math::PI, Vector3::YAXIS);
628 effect.SetSwingAngleIn(Math::PI, Vector3::YAXIS);
629 effect.SetSwingAngleOut(Math::PI, Vector3::YAXIS);
630 effect.SetSwingAngleAlphaFunction(AlphaFunctions::Linear);
631 effect.SetSwingAngleAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
632 effect.SetSwingAngleAlphaFunctionIn(AlphaFunctions::Linear);
633 effect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::Linear);
634 effect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
635 effect.SetSwingAnchorIn(AnchorPoint::CENTER);
636 effect.SetSwingAnchorOut(AnchorPoint::CENTER);
637 effect.SetSwingAnchorAlphaFunction(AlphaFunctions::Linear);
638 effect.SetSwingAnchorAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
639 effect.SetSwingAnchorAlphaFunctionIn(AlphaFunctions::Linear);
640 effect.SetSwingAnchorAlphaFunctionOut(AlphaFunctions::Linear);
641 effect.SetOpacityThreshold(0.5f);
642 effect.SetOpacityThreshold(0.5f, 0.5f);
643 effect.SetOpacityThresholdIn(0.5f);
644 effect.SetOpacityThresholdOut(0.5f);
645 effect.SetOpacityAlphaFunction(AlphaFunctions::Linear);
646 effect.SetOpacityAlphaFunction(AlphaFunctions::Linear, AlphaFunctions::Linear);
647 effect.SetOpacityAlphaFunctionIn(AlphaFunctions::Linear);
648 effect.SetOpacityAlphaFunctionOut(AlphaFunctions::Linear);