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.
19 #include <float.h> // for FLT_MAX
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Toolkit;
28 const unsigned int TOTAL_ITEM_NUMBER = 200;
31 // Implementation of ItemFactory for providing actors to ItemView
32 class TestItemFactory : public ItemFactory
38 * @param application class, stored as reference
44 public: // From ItemFactory
47 * Query the number of items available from the factory.
48 * The maximum available item has an ID of GetNumberOfItems() - 1.
50 virtual unsigned int GetNumberOfItems()
52 return TOTAL_ITEM_NUMBER;
56 * Create an Actor to represent a visible item.
58 * @return the created actor.
60 virtual Actor NewItem(unsigned int itemId)
62 // Create an test actor for this item
63 ImageActor actor = CreateSolidColorActor(Color::RED);
64 actor.SetSize(64.0f, 64.0f);
72 // Positive test case for a method
73 int UtcDaliNavigationLayoutNew(void)
75 ToolkitTestApplication application;
77 // Create a navigation layout
78 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
79 navigationLayout->SetNumberOfColumns(6);
80 DALI_TEST_CHECK(navigationLayout);
84 int UtcDaliNavigationLayoutColumns(void)
86 ToolkitTestApplication application;
87 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
89 navigationLayout->SetNumberOfColumns(6);
90 // Check whether we get the correct number of columns
91 DALI_TEST_CHECK(navigationLayout->GetNumberOfColumns() == 6);
95 int UtcDaliNavigationLayoutSetGetOrientation(void)
97 ToolkitTestApplication application;
98 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
100 navigationLayout->SetNumberOfColumns(6);
101 navigationLayout->SetOrientation(ControlOrientation::Right);
102 DALI_TEST_CHECK(navigationLayout->GetOrientation() == ControlOrientation::Right);
106 int UtcDaliNavigationLayoutTestConstraintLeft(void)
108 ToolkitTestApplication application;
110 // Create the ItemView actor
111 TestItemFactory factory;
112 ItemView view = ItemView::New(factory);
113 Vector3 vec(480.0f, 800.0f, 0.0f);
114 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
115 navigationLayout->SetNumberOfColumns(6);
117 view.SetName("view actor");
118 view.AddLayout(*navigationLayout);
121 Stage::GetCurrent().Add(view);
122 navigationLayout->SetOrientation(ControlOrientation::Left);
123 view.ActivateLayout(0, vec, 0.0f);
125 application.SendNotification();
126 application.Render(0);
129 for(int i = 0; i < 10; ++i)
131 application.Render(16); // 60hz frames
134 // Confirm: we have actors in the view and all of them is positioned at X = 0
135 // and the series is monotonely decreasing.
136 int nonZeroXCount = 0;
137 int elementsFound = 0;
138 int wrongDirectionCount = 0;
139 float prevY = FLT_MAX;
140 for(unsigned int i = 0; i < 10; i++)
142 Actor testActor = view.GetItem(i);
146 Vector3 pos = testActor.GetCurrentPosition();
155 wrongDirectionCount++;
162 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroXCount == 0) && (wrongDirectionCount == 0));
163 Stage::GetCurrent().Remove(view);
167 int UtcDaliNavigationLayoutTestConstraintRight(void)
169 ToolkitTestApplication application;
171 // Create the ItemView actor
172 TestItemFactory factory;
173 ItemView view = ItemView::New(factory);
174 Vector3 vec(480.0f, 800.0f, 0.0f);
175 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
176 navigationLayout->SetNumberOfColumns(6);
178 view.SetName("view actor");
179 view.AddLayout(*navigationLayout);
182 Stage::GetCurrent().Add(view);
183 navigationLayout->SetOrientation(ControlOrientation::Right);
184 view.ActivateLayout(0, vec, 0.0f);
186 application.SendNotification();
187 application.Render(0);
190 for(int i = 0; i < 10; ++i)
192 application.Render(16); // 60hz frames
195 // Confirm: we have actors in the view and all of them is positioned at X = 0
196 // and the series is monotonely increasing.
197 int nonZeroXCount = 0;
198 int elementsFound = 0;
199 int wrongDirectionCount = 0;
200 float prevY = -FLT_MAX;
201 for(unsigned int i = 0; i < 10; i++)
203 Actor testActor = view.GetItem(i);
207 Vector3 pos = testActor.GetCurrentPosition();
216 wrongDirectionCount++;
223 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroXCount == 0) && (wrongDirectionCount == 0));
224 Stage::GetCurrent().Remove(view);
228 int UtcDaliNavigationLayoutTestConstraintUp(void)
230 ToolkitTestApplication application;
232 // Create the ItemView actor
233 TestItemFactory factory;
234 ItemView view = ItemView::New(factory);
235 Vector3 vec(480.0f, 800.0f, 0.0f);
236 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
237 navigationLayout->SetNumberOfColumns(6);
239 view.SetName("view actor");
240 view.AddLayout(*navigationLayout);
243 Stage::GetCurrent().Add(view);
244 navigationLayout->SetOrientation(ControlOrientation::Up);
245 view.ActivateLayout(0, vec, 0.0f);
247 application.SendNotification();
248 application.Render(0);
251 for(int i = 0; i < 10; ++i)
253 application.Render(16); // 60hz frames
256 // Confirm: we have actors in the view and all of them is positioned at X = 0
257 // and the series is monotonely decreasing.
258 int nonZeroYCount = 0;
259 int elementsFound = 0;
260 int wrongDirectionCount = 0;
261 float prevX = -FLT_MAX;
262 for(unsigned int i = 0; i < 10; i++)
264 Actor testActor = view.GetItem(i);
268 Vector3 pos = testActor.GetCurrentPosition();
277 wrongDirectionCount++;
284 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroYCount == 0) && (wrongDirectionCount == 0));
285 Stage::GetCurrent().Remove(view);
289 int UtcDaliNavigationLayoutTestConstraintDown(void)
291 ToolkitTestApplication application;
293 // Create the ItemView actor
294 TestItemFactory factory;
295 ItemView view = ItemView::New(factory);
296 Vector3 vec(480.0f, 800.0f, 0.0f);
297 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
298 navigationLayout->SetNumberOfColumns(6);
300 view.SetName("view actor");
301 view.AddLayout(*navigationLayout);
304 Stage::GetCurrent().Add(view);
305 navigationLayout->SetOrientation(ControlOrientation::Down);
306 view.ActivateLayout(0, vec, 0.0f);
308 application.SendNotification();
309 application.Render(0);
312 for(int i = 0; i < 10; ++i)
314 application.Render(16); // 60hz frames
317 // Confirm: we have actors in the view and all of them is positioned at X = 0
318 // and the series is monotonely decreasing.
319 int nonZeroYCount = 0;
320 int elementsFound = 0;
321 int wrongDirectionCount = 0;
322 float prevX = FLT_MAX;
323 for(unsigned int i = 0; i < 10; i++)
325 Actor testActor = view.GetItem(i);
329 Vector3 pos = testActor.GetCurrentPosition();
338 wrongDirectionCount++;
345 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroYCount == 0) && (wrongDirectionCount == 0));
346 Stage::GetCurrent().Remove(view);
351 int UtcDaliNavigationLayoutScrollDirection(void)
353 ToolkitTestApplication application;
355 // Create the ItemView actor
356 TestItemFactory factory;
357 ItemView view = ItemView::New(factory);
358 Vector3 vec(480.0f, 800.0f, 0.0f);
359 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
360 navigationLayout->SetNumberOfColumns(6);
362 view.SetName("view actor");
363 view.AddLayout(*navigationLayout);
366 Stage::GetCurrent().Add(view);
367 navigationLayout->SetOrientation(ControlOrientation::Left);
368 view.ActivateLayout(0, vec, 0.0f);
370 application.SendNotification();
371 application.Render(0);
373 ItemLayoutPtr layout = navigationLayout;
376 for(int i = 0; i < 10; ++i)
378 application.Render(16); // 60hz frames
381 navigationLayout->SetOrientation(ControlOrientation::Up);
382 view.ActivateLayout(0, vec, 0.0f);
383 application.SendNotification();
384 application.Render();
386 Degree deg = layout->GetScrollDirection();
387 DALI_TEST_CHECK(deg == (180.0f - 45.0f));
389 navigationLayout->SetOrientation(ControlOrientation::Down);
390 view.ActivateLayout(0, vec, 0.0f);
391 application.SendNotification();
392 application.Render();
394 deg = layout->GetScrollDirection();
395 DALI_TEST_CHECK((deg == -45.0f));
397 layout->SetOrientation(ControlOrientation::Left);
398 view.ActivateLayout(0, vec, 0.0f);
399 application.SendNotification();
400 application.Render();
402 deg = layout->GetScrollDirection();
403 DALI_TEST_CHECK(deg == (270.0f - 45.0f));
405 navigationLayout->SetOrientation(ControlOrientation::Right);
406 view.ActivateLayout(0, vec, 0.0f);
407 application.SendNotification();
408 application.Render();
410 deg = layout->GetScrollDirection();
411 DALI_TEST_CHECK(deg == (90.0f - 45.0f));
413 Stage::GetCurrent().Remove(view);
417 int UtcDaliNavigationLayoutSetGetColumnSpacing(void)
419 ToolkitTestApplication application;
420 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
421 const float testValue = 11.0f;
423 navigationLayout->SetNumberOfColumns(6);
424 navigationLayout->SetColumnSpacing(testValue);
425 DALI_TEST_CHECK(navigationLayout->GetColumnSpacing() == testValue);
429 int UtcDaliNavigationLayoutSetGetTopMargin(void)
431 ToolkitTestApplication application;
432 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
433 const float testValue = 11.0f;
435 navigationLayout->SetNumberOfColumns(6);
436 navigationLayout->SetTopMargin(testValue);
437 DALI_TEST_CHECK(navigationLayout->GetTopMargin() == testValue);
441 int UtcDaliNavigationLayoutSetGetBottomMargin(void)
443 ToolkitTestApplication application;
444 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
445 const float testValue = 12.0f;
447 navigationLayout->SetNumberOfColumns(6);
448 navigationLayout->SetBottomMargin(testValue);
449 DALI_TEST_CHECK(navigationLayout->GetBottomMargin() == testValue);
453 int UtcDaliNavigationLayoutSetGetScrollSpeedFactor(void)
455 ToolkitTestApplication application;
456 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
457 const float testValue = 15.0f;
459 navigationLayout->SetNumberOfColumns(6);
460 navigationLayout->SetScrollSpeedFactor(testValue);
461 DALI_TEST_CHECK(navigationLayout->GetScrollSpeedFactor() == testValue);
465 int UtcDaliNavigationLayoutSetGetMaximumSwipeSpeed(void)
467 ToolkitTestApplication application;
468 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
469 const float testValue = 10.0f;
471 navigationLayout->SetNumberOfColumns(6);
472 navigationLayout->SetMaximumSwipeSpeed(testValue);
473 DALI_TEST_CHECK(navigationLayout->GetMaximumSwipeSpeed() == testValue);
477 int UtcDaliNavigationLayoutSetAndGetItemFlickAnimationDuration(void)
479 ToolkitTestApplication application;
481 // Create a navigation layout
482 NavigationLayoutPtr navigationLayout = NavigationLayout::New();
484 // Set the flick animaiton duration
485 navigationLayout->SetItemFlickAnimationDuration(0.35f);
487 // Check whether we get the correct flick animaiton duration
488 DALI_TEST_EQUALS( navigationLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
492 int UtcDaliNavigationLayoutGetScrollToPosition(void)
494 ToolkitTestApplication application;
496 // Create the ItemView actor
497 TestItemFactory factory;
498 ItemView view = ItemView::New(factory);
499 Vector3 vec(480.0f, 800.0f, 0.0f);
500 NavigationLayoutPtr layout = NavigationLayout::New();
502 view.SetName("view actor");
503 view.AddLayout(*layout);
506 Stage::GetCurrent().Add(view);
507 layout->SetOrientation(ControlOrientation::Up);
508 view.ActivateLayout(0, vec, 0.0f);
510 application.SendNotification();
511 application.Render(0);
514 for(int i = 0; i < 10; ++i)
516 application.Render(16); // 60hz frames
519 // Confirm: we have actors in the view.
520 std::vector<unsigned int> indices;
521 for(unsigned int i = 0; i < 10; i++)
523 Actor testActor = view.GetItem(i);
526 indices.push_back(i);
532 if (!indices.empty())
534 const unsigned int firstTargetIndex = indices[indices.size()-1];
535 // scroll to last item
536 view.ScrollToItem(firstTargetIndex, 0.00f);
537 application.Render(16); // 60hz frames
539 std::size_t moveCount = 0;
540 for(std::size_t i = 0; i < indices.size(); i++)
542 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
543 view.ScrollToItem(indices[i], 0.0f);
545 application.Render(16); // 60hz frame
547 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
549 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
555 DALI_TEST_CHECK((moveCount == indices.size()));
560 tet_result(TET_FAIL);
563 Stage::GetCurrent().Remove(view);