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.
20 #include <float.h> // for FLT_MAX
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
25 using namespace Toolkit;
29 const unsigned int TOTAL_ITEM_NUMBER = 200;
32 // Implementation of ItemFactory for providing actors to ItemView
33 class TestItemFactory : public ItemFactory
39 * @param application class, stored as reference
45 public: // From ItemFactory
48 * Query the number of items available from the factory.
49 * The maximum available item has an ID of GetNumberOfItems() - 1.
51 virtual unsigned int GetNumberOfItems()
53 return TOTAL_ITEM_NUMBER;
57 * Create an Actor to represent a visible item.
59 * @return the created actor.
61 virtual Actor NewItem(unsigned int itemId)
63 // Create an test actor for this item
64 ImageActor actor = CreateSolidColorActor(Color::RED);
65 actor.SetSize(64.0f, 64.0f);
73 // Positive test case for a method
74 int UtcDaliNavigationLayoutNew(void)
76 ToolkitTestApplication application;
78 // Create a navigation layout
79 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
80 navigationLayout->SetNumberOfColumns(6);
81 DALI_TEST_CHECK(navigationLayout);
85 int UtcDaliNavigationLayoutColumns(void)
87 ToolkitTestApplication application;
88 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
90 navigationLayout->SetNumberOfColumns(6);
91 // Check whether we get the correct number of columns
92 DALI_TEST_CHECK(navigationLayout->GetNumberOfColumns() == 6);
96 int UtcDaliNavigationLayoutSetGetOrientation(void)
98 ToolkitTestApplication application;
99 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
101 navigationLayout->SetNumberOfColumns(6);
102 navigationLayout->SetOrientation(ControlOrientation::Right);
103 DALI_TEST_CHECK(navigationLayout->GetOrientation() == ControlOrientation::Right);
107 int UtcDaliNavigationLayoutTestConstraintLeft(void)
109 ToolkitTestApplication application;
111 // Create the ItemView actor
112 TestItemFactory factory;
113 ItemView view = ItemView::New(factory);
114 Vector3 vec(480.0f, 800.0f, 0.0f);
115 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
116 navigationLayout->SetNumberOfColumns(6);
118 view.SetName("view actor");
119 view.AddLayout(*navigationLayout);
122 Stage::GetCurrent().Add(view);
123 navigationLayout->SetOrientation(ControlOrientation::Left);
124 view.ActivateLayout(0, vec, 0.0f);
126 application.SendNotification();
127 application.Render(0);
130 for(int i = 0; i < 10; ++i)
132 application.Render(16); // 60hz frames
135 // Confirm: we have actors in the view and all of them is positioned at X = 0
136 // and the series is monotonely decreasing.
137 int nonZeroXCount = 0;
138 int elementsFound = 0;
139 int wrongDirectionCount = 0;
140 float prevY = FLT_MAX;
141 for(unsigned int i = 0; i < 10; i++)
143 Actor testActor = view.GetItem(i);
147 Vector3 pos = testActor.GetCurrentPosition();
156 wrongDirectionCount++;
163 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroXCount == 0) && (wrongDirectionCount == 0));
164 Stage::GetCurrent().Remove(view);
168 int UtcDaliNavigationLayoutTestConstraintRight(void)
170 ToolkitTestApplication application;
172 // Create the ItemView actor
173 TestItemFactory factory;
174 ItemView view = ItemView::New(factory);
175 Vector3 vec(480.0f, 800.0f, 0.0f);
176 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
177 navigationLayout->SetNumberOfColumns(6);
179 view.SetName("view actor");
180 view.AddLayout(*navigationLayout);
183 Stage::GetCurrent().Add(view);
184 navigationLayout->SetOrientation(ControlOrientation::Right);
185 view.ActivateLayout(0, vec, 0.0f);
187 application.SendNotification();
188 application.Render(0);
191 for(int i = 0; i < 10; ++i)
193 application.Render(16); // 60hz frames
196 // Confirm: we have actors in the view and all of them is positioned at X = 0
197 // and the series is monotonely increasing.
198 int nonZeroXCount = 0;
199 int elementsFound = 0;
200 int wrongDirectionCount = 0;
201 float prevY = -FLT_MAX;
202 for(unsigned int i = 0; i < 10; i++)
204 Actor testActor = view.GetItem(i);
208 Vector3 pos = testActor.GetCurrentPosition();
217 wrongDirectionCount++;
224 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroXCount == 0) && (wrongDirectionCount == 0));
225 Stage::GetCurrent().Remove(view);
229 int UtcDaliNavigationLayoutTestConstraintUp(void)
231 ToolkitTestApplication application;
233 // Create the ItemView actor
234 TestItemFactory factory;
235 ItemView view = ItemView::New(factory);
236 Vector3 vec(480.0f, 800.0f, 0.0f);
237 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
238 navigationLayout->SetNumberOfColumns(6);
240 view.SetName("view actor");
241 view.AddLayout(*navigationLayout);
244 Stage::GetCurrent().Add(view);
245 navigationLayout->SetOrientation(ControlOrientation::Up);
246 view.ActivateLayout(0, vec, 0.0f);
248 application.SendNotification();
249 application.Render(0);
252 for(int i = 0; i < 10; ++i)
254 application.Render(16); // 60hz frames
257 // Confirm: we have actors in the view and all of them is positioned at X = 0
258 // and the series is monotonely decreasing.
259 int nonZeroYCount = 0;
260 int elementsFound = 0;
261 int wrongDirectionCount = 0;
262 float prevX = -FLT_MAX;
263 for(unsigned int i = 0; i < 10; i++)
265 Actor testActor = view.GetItem(i);
269 Vector3 pos = testActor.GetCurrentPosition();
278 wrongDirectionCount++;
285 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroYCount == 0) && (wrongDirectionCount == 0));
286 Stage::GetCurrent().Remove(view);
290 int UtcDaliNavigationLayoutTestConstraintDown(void)
292 ToolkitTestApplication application;
294 // Create the ItemView actor
295 TestItemFactory factory;
296 ItemView view = ItemView::New(factory);
297 Vector3 vec(480.0f, 800.0f, 0.0f);
298 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
299 navigationLayout->SetNumberOfColumns(6);
301 view.SetName("view actor");
302 view.AddLayout(*navigationLayout);
305 Stage::GetCurrent().Add(view);
306 navigationLayout->SetOrientation(ControlOrientation::Down);
307 view.ActivateLayout(0, vec, 0.0f);
309 application.SendNotification();
310 application.Render(0);
313 for(int i = 0; i < 10; ++i)
315 application.Render(16); // 60hz frames
318 // Confirm: we have actors in the view and all of them is positioned at X = 0
319 // and the series is monotonely decreasing.
320 int nonZeroYCount = 0;
321 int elementsFound = 0;
322 int wrongDirectionCount = 0;
323 float prevX = FLT_MAX;
324 for(unsigned int i = 0; i < 10; i++)
326 Actor testActor = view.GetItem(i);
330 Vector3 pos = testActor.GetCurrentPosition();
339 wrongDirectionCount++;
346 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroYCount == 0) && (wrongDirectionCount == 0));
347 Stage::GetCurrent().Remove(view);
352 int UtcDaliNavigationLayoutScrollDirection(void)
354 ToolkitTestApplication application;
356 // Create the ItemView actor
357 TestItemFactory factory;
358 ItemView view = ItemView::New(factory);
359 Vector3 vec(480.0f, 800.0f, 0.0f);
360 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
361 navigationLayout->SetNumberOfColumns(6);
363 view.SetName("view actor");
364 view.AddLayout(*navigationLayout);
367 Stage::GetCurrent().Add(view);
368 navigationLayout->SetOrientation(ControlOrientation::Left);
369 view.ActivateLayout(0, vec, 0.0f);
371 application.SendNotification();
372 application.Render(0);
374 ItemLayoutPtr layout = navigationLayout;
377 for(int i = 0; i < 10; ++i)
379 application.Render(16); // 60hz frames
382 navigationLayout->SetOrientation(ControlOrientation::Up);
383 view.ActivateLayout(0, vec, 0.0f);
384 application.SendNotification();
385 application.Render();
387 Degree deg = layout->GetScrollDirection();
388 DALI_TEST_CHECK(deg == (180.0f - 45.0f));
390 navigationLayout->SetOrientation(ControlOrientation::Down);
391 view.ActivateLayout(0, vec, 0.0f);
392 application.SendNotification();
393 application.Render();
395 deg = layout->GetScrollDirection();
396 DALI_TEST_CHECK((deg == -45.0f));
398 layout->SetOrientation(ControlOrientation::Left);
399 view.ActivateLayout(0, vec, 0.0f);
400 application.SendNotification();
401 application.Render();
403 deg = layout->GetScrollDirection();
404 DALI_TEST_CHECK(deg == (270.0f - 45.0f));
406 navigationLayout->SetOrientation(ControlOrientation::Right);
407 view.ActivateLayout(0, vec, 0.0f);
408 application.SendNotification();
409 application.Render();
411 deg = layout->GetScrollDirection();
412 DALI_TEST_CHECK(deg == (90.0f - 45.0f));
414 Stage::GetCurrent().Remove(view);
418 int UtcDaliNavigationLayoutSetGetColumnSpacing(void)
420 ToolkitTestApplication application;
421 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
422 const float testValue = 11.0f;
424 navigationLayout->SetNumberOfColumns(6);
425 navigationLayout->SetColumnSpacing(testValue);
426 DALI_TEST_CHECK(navigationLayout->GetColumnSpacing() == testValue);
430 int UtcDaliNavigationLayoutSetGetTopMargin(void)
432 ToolkitTestApplication application;
433 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
434 const float testValue = 11.0f;
436 navigationLayout->SetNumberOfColumns(6);
437 navigationLayout->SetTopMargin(testValue);
438 DALI_TEST_CHECK(navigationLayout->GetTopMargin() == testValue);
442 int UtcDaliNavigationLayoutSetGetBottomMargin(void)
444 ToolkitTestApplication application;
445 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
446 const float testValue = 12.0f;
448 navigationLayout->SetNumberOfColumns(6);
449 navigationLayout->SetBottomMargin(testValue);
450 DALI_TEST_CHECK(navigationLayout->GetBottomMargin() == testValue);
454 int UtcDaliNavigationLayoutSetGetScrollSpeedFactor(void)
456 ToolkitTestApplication application;
457 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
458 const float testValue = 15.0f;
460 navigationLayout->SetNumberOfColumns(6);
461 navigationLayout->SetScrollSpeedFactor(testValue);
462 DALI_TEST_CHECK(navigationLayout->GetScrollSpeedFactor() == testValue);
466 int UtcDaliNavigationLayoutSetGetMaximumSwipeSpeed(void)
468 ToolkitTestApplication application;
469 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
470 const float testValue = 10.0f;
472 navigationLayout->SetNumberOfColumns(6);
473 navigationLayout->SetMaximumSwipeSpeed(testValue);
474 DALI_TEST_CHECK(navigationLayout->GetMaximumSwipeSpeed() == testValue);
478 int UtcDaliNavigationLayoutSetAndGetItemFlickAnimationDuration(void)
480 ToolkitTestApplication application;
482 // Create a navigation layout
483 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
485 // Set the flick animaiton duration
486 navigationLayout->SetItemFlickAnimationDuration(0.35f);
488 // Check whether we get the correct flick animaiton duration
489 DALI_TEST_EQUALS( navigationLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
493 int UtcDaliNavigationLayoutGetScrollToPosition(void)
495 ToolkitTestApplication application;
497 // Create the ItemView actor
498 TestItemFactory factory;
499 ItemView view = ItemView::New(factory);
500 Vector3 vec(480.0f, 800.0f, 0.0f);
501 NavigationLayoutPtr layout = NavigationLayout::New();
503 view.SetName("view actor");
504 view.AddLayout(*layout);
507 Stage::GetCurrent().Add(view);
508 layout->SetOrientation(ControlOrientation::Up);
509 view.ActivateLayout(0, vec, 0.0f);
511 application.SendNotification();
512 application.Render(0);
515 for(int i = 0; i < 10; ++i)
517 application.Render(16); // 60hz frames
520 // Confirm: we have actors in the view.
521 std::vector<unsigned int> indices;
522 for(unsigned int i = 0; i < 10; i++)
524 Actor testActor = view.GetItem(i);
527 indices.push_back(i);
533 if (!indices.empty())
535 const unsigned int firstTargetIndex = indices[indices.size()-1];
536 // scroll to last item
537 view.ScrollToItem(firstTargetIndex, 0.00f);
538 application.Render(16); // 60hz frames
540 std::size_t moveCount = 0;
541 for(std::size_t i = 0; i < indices.size(); i++)
543 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
544 view.ScrollToItem(indices[i], 0.0f);
546 application.Render(16); // 60hz frame
548 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
550 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
556 DALI_TEST_CHECK((moveCount == indices.size()));
561 tet_result(TET_FAIL);
564 Stage::GetCurrent().Remove(view);