2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
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>
27 using namespace Toolkit;
29 void dali_scroll_view_effect_startup(void)
31 test_return_value = TET_UNDEF;
34 void dali_scroll_view_effect_cleanup(void)
36 test_return_value = TET_PASS;
42 const int MILLISECONDS_PER_SECOND = 1000;
43 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
44 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
45 const int RENDER_DELAY_SCROLL = 1000; ///< duration to wait for any scroll to complete.
48 * Simulate time passed by.
50 * @note this will always process at least 1 frame (1/60 sec)
52 * @param application Test application instance
53 * @param duration Time to pass in milliseconds.
54 * @return The actual time passed in milliseconds
56 int Wait(ToolkitTestApplication& application, int duration = 0)
60 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
62 application.SendNotification();
63 application.Render(RENDER_FRAME_INTERVAL);
64 time += RENDER_FRAME_INTERVAL;
71 * Creates a Ruler that snaps to a specified grid size.
72 * If that grid size is 0.0 then this ruler does not
75 * @param[in] gridSize (optional) The grid size for the ruler,
76 * (Default = 0.0 i.e. no snapping)
77 * @return The ruler is returned.
79 RulerPtr CreateRuler(float gridSize = 0.0f)
81 if(gridSize <= Math::MACHINE_EPSILON_0)
83 return new DefaultRuler();
85 return new FixedRuler(gridSize);
90 static bool gOnScrollStartCalled; ///< Whether the OnScrollStart signal was invoked.
91 static bool gOnScrollUpdateCalled; ///< Whether the OnScrollUpdate signal was invoked.
92 static bool gOnScrollCompleteCalled; ///< Whether the OnScrollComplete signal was invoked.
93 static Vector3 gConstraintResult; ///< Result from constraint.
95 static ActorContainer gPages; ///< Keeps track of all the pages for applying effects.
97 static void ResetScrollCallbackResults()
99 gOnScrollStartCalled = false;
100 gOnScrollUpdateCalled = false;
101 gOnScrollCompleteCalled = false;
105 * Invoked when scrolling starts.
107 * @param[in] position The current scroll position.
109 static void OnScrollStart( const Vector3& position )
111 gOnScrollStartCalled = true;
115 * Invoked when scrolling updates (via dragging)
117 * @param[in] position The current scroll position.
119 static void OnScrollUpdate( const Vector3& position )
121 gOnScrollUpdateCalled = true;
125 * Invoked when scrolling finishes
127 * @param[in] position The current scroll position.
129 static void OnScrollComplete( const Vector3& position )
131 gOnScrollCompleteCalled = true;
135 ScrollView SetupTestScrollView(int rows, int columns, Vector2 size)
137 ScrollView scrollView = ScrollView::New();
138 scrollView.SetSize(size);
139 scrollView.SetAnchorPoint(AnchorPoint::CENTER);
140 scrollView.SetParentOrigin(ParentOrigin::CENTER);
141 scrollView.ApplyConstraint( Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
142 // Disable Refresh signal (TET environment cannot use adaptor's Timer)
143 scrollView.SetWrapMode(false);
144 scrollView.SetRefreshInterval(0);
145 scrollView.ScrollStartedSignal().Connect( &OnScrollStart );
146 scrollView.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
147 scrollView.ScrollCompletedSignal().Connect( &OnScrollComplete );
148 Stage::GetCurrent().Add( scrollView );
149 RulerPtr rulerX = CreateRuler(size.width);
150 RulerPtr rulerY = CreateRuler(size.height);
153 rulerX->SetDomain(RulerDomain(0.0f, size.width * columns));
161 rulerY->SetDomain(RulerDomain(0.0f, size.width * rows));
168 scrollView.SetRulerX( rulerX );
169 scrollView.SetRulerY( rulerY );
170 Stage::GetCurrent().Add( scrollView );
172 Actor container = Actor::New();
173 container.SetParentOrigin(ParentOrigin::CENTER);
174 container.SetAnchorPoint(AnchorPoint::CENTER);
175 container.SetSize( size );
176 scrollView.Add( container );
177 container.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
180 for(int row = 0;row<rows;row++)
182 for(int column = 0;column<columns;column++)
184 Actor page = Actor::New();
185 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
186 page.SetParentOrigin( ParentOrigin::CENTER );
187 page.SetAnchorPoint( AnchorPoint::CENTER );
188 page.SetPosition( column * size.x, row * size.y );
191 gPages.push_back(page);
195 ResetScrollCallbackResults();
202 ResetScrollCallbackResults();
205 Actor AddActorToPage(Actor page, float x, float y, float cols, float rows)
207 Stage stage = Stage::GetCurrent();
208 Vector2 stageSize = stage.GetSize();
210 const float margin = 10.0f;
211 const Vector2 actorSize((stageSize.x / cols) - margin, (stageSize.y / rows) - margin);
213 Actor actor = Actor::New();
214 actor.SetParentOrigin( ParentOrigin::CENTER );
215 actor.SetAnchorPoint( AnchorPoint::CENTER );
217 Vector3 position( margin * 0.5f + (actorSize.x + margin) * x - stageSize.width * 0.5f,
218 margin * 0.5f + (actorSize.y + margin) * y - stageSize.height * 0.5f,
220 Vector3 positionEnd( margin * 0.5f + (actorSize.x + margin) * (x + cols) - stageSize.width * 0.5f - margin,
221 margin * 0.5f + (actorSize.y + margin) * (y + rows) - stageSize.height * 0.5f - margin,
223 Vector3 size(positionEnd - position);
224 actor.SetPosition( position + size * 0.5f);
225 actor.SetSize( positionEnd - position );
230 } // unnamed namespace
233 int UtcDaliScrollViewPageCubeEffectSetup(void)
235 tet_infoline(" UtcDaliScrollViewPageCubeEffectSetup");
237 ScrollViewPageCubeEffect effect;
239 DALI_TEST_CHECK( !effect );
241 BaseHandle handle = ScrollViewPageCubeEffect::New();
243 DALI_TEST_CHECK( handle );
245 effect = ScrollViewPageCubeEffect::DownCast(handle);
247 DALI_TEST_CHECK( effect );
252 int UtcDaliScrollViewPageCarouselEffectSetup(void)
254 tet_infoline(" UtcDaliScrollViewCarouselEffectSetup");
256 ScrollViewPageCarouselEffect effect;
258 DALI_TEST_CHECK( !effect );
260 BaseHandle handle = ScrollViewPageCarouselEffect::New();
262 DALI_TEST_CHECK( handle );
264 effect = ScrollViewPageCarouselEffect::DownCast(handle);
266 DALI_TEST_CHECK( effect );
270 int UtcDaliScrollViewCarouselEffectSetup(void)
272 tet_infoline(" UtcDaliScrollViewCarouselEffectSetup");
274 ScrollViewCarouselEffect effect;
276 DALI_TEST_CHECK( !effect );
278 BaseHandle handle = ScrollViewCarouselEffect::New();
280 DALI_TEST_CHECK( handle );
282 effect = ScrollViewCarouselEffect::DownCast(handle);
284 DALI_TEST_CHECK( effect );
288 int UtcDaliScrollViewDepthEffectSetup(void)
290 tet_infoline(" UtcDaliScrollViewDepthEffectSetup");
292 ScrollViewDepthEffect effect;
294 DALI_TEST_CHECK( !effect );
296 BaseHandle handle = ScrollViewDepthEffect::New();
298 DALI_TEST_CHECK( handle );
300 effect = ScrollViewDepthEffect::DownCast(handle);
302 DALI_TEST_CHECK( effect );
307 int UtcDaliScrollViewPageCubeEffectTest(void)
309 ToolkitTestApplication application;
310 tet_infoline(" UtcDaliScrollViewPageCubeEffectTest");
312 Vector2 size = Stage::GetCurrent().GetSize();
314 ScrollView scrollView = SetupTestScrollView(1, 3, size);
315 Actor testPage = gPages[1];
316 Wait(application, 500);
318 ScrollViewPageCubeEffect effect = ScrollViewPageCubeEffect::New();
319 scrollView.ApplyEffect(effect);
321 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
323 Actor page = *pageIter;
324 page.RemoveConstraints();
325 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
326 effect.ApplyToPage(page, Vector2(Math::PI_2, 0.0f));
330 scrollView.ScrollTo(1);
331 while(!gOnScrollCompleteCalled)
335 // test that the first page has reached centre of screen
336 Vector3 pagePos = testPage.GetCurrentPosition();
337 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
342 int UtcDaliScrollViewPageCarouselEffectTest(void)
344 ToolkitTestApplication application;
345 tet_infoline(" UtcDaliScrollViewPageCarouselEffectTest");
347 Vector2 size = Stage::GetCurrent().GetSize();
349 ScrollView scrollView = SetupTestScrollView(1, 3, size);
350 Actor testPage = gPages[1];
351 Wait(application, 500);
353 ScrollViewPageCarouselEffect effect = ScrollViewPageCarouselEffect::New();
354 scrollView.ApplyEffect(effect);
356 for(ActorIter pageIter = gPages.begin(); pageIter != gPages.end(); ++pageIter)
358 Actor page = *pageIter;
359 page.RemoveConstraints();
360 page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
361 effect.ApplyToPage(page);
365 scrollView.ScrollTo(1, 0.5f, DirectionBiasNone);
366 while(!gOnScrollCompleteCalled)
370 // test that the first page has reached centre of screen
371 Vector3 pagePos = testPage.GetCurrentPosition();
372 DALI_TEST_EQUALS(pagePos, Vector3::ZERO, Math::MACHINE_EPSILON_0, TEST_LOCATION);
377 int UtcDaliScrollViewCarouselEffectTest(void)
379 ToolkitTestApplication application;
380 tet_infoline(" UtcDaliScrollViewCarouselEffectTest");
382 Vector2 size = Stage::GetCurrent().GetSize();
384 ScrollView scrollView = SetupTestScrollView(1, 3, size);
385 Actor testPage = gPages[1];
386 Wait(application, 500);
388 ScrollViewCarouselEffect effect = ScrollViewCarouselEffect::New();
389 scrollView.ApplyEffect(effect);
391 Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
393 Vector3 actorPrePosition = actor.GetCurrentPosition();
395 effect.ApplyToActor( actor, Vector2(1.2f, 1.2f) );
397 scrollView.ScrollTo(Vector3(size.x, 0.0f, 0.0f), 0.5f, DirectionBiasNone, DirectionBiasNone);
398 while(!gOnScrollCompleteCalled)
402 // test that the first page has reached centre of screen
403 Vector3 actorPostPosition = actor.GetCurrentPosition();
404 // just check the actor has moved
405 DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);
410 int UtcDaliScrollViewDepthEffectTest(void)
412 ToolkitTestApplication application;
413 tet_infoline(" UtcDaliScrollViewDepthEffectTest");
415 Vector2 size = Stage::GetCurrent().GetSize();
417 ScrollView scrollView = SetupTestScrollView(1, 3, size);
418 Actor testPage = gPages[1];
419 Wait(application, 500);
421 ScrollViewDepthEffect effect = ScrollViewDepthEffect::New();
422 scrollView.ApplyEffect(effect);
424 Actor actor = AddActorToPage(testPage, 0.5f, 0.5f, 3, 3);
426 Vector3 actorPrePosition = actor.GetCurrentPosition();
428 const Vector2 positionExtent(0.5f, 2.5f);
429 const Vector2 offsetExtent(1.0f, 1.0f);
430 const float positionScale(1.5f);
431 const float scaleExtent(0.5f);
433 effect.ApplyToActor( actor, positionExtent, offsetExtent, positionScale, scaleExtent );
435 scrollView.ScrollTo(1);
436 while(!gOnScrollCompleteCalled)
440 // test that the first page has reached centre of screen
441 Vector3 actorPostPosition = actor.GetCurrentPosition();
442 // just check the actor has moved
443 DALI_TEST_CHECK((actorPostPosition - actorPrePosition).Length() > Math::MACHINE_EPSILON_1);