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>
26 using namespace Toolkit;
28 void spiral_layout_startup(void)
30 test_return_value = TET_UNDEF;
33 void spiral_layout_cleanup(void)
35 test_return_value = TET_PASS;
40 const unsigned int TOTAL_ITEM_NUMBER = 200;
42 Vector3 SpiralLayoutItemSizeFunction(const Vector3& layoutSize)
44 float width = layoutSize.width * 0.2f;
45 return Vector3(width, width, width);
48 float SpiralLayoutSpiralRadiusFunction(const Vector3& layoutSize)
50 return layoutSize.width * 0.5f;
54 // Implementation of ItemFactory for providing actors to ItemView
55 class TestItemFactory : public ItemFactory
61 * @param application class, stored as reference
67 public: // From ItemFactory
70 * Query the number of items available from the factory.
71 * The maximum available item has an ID of GetNumberOfItems() - 1.
73 virtual unsigned int GetNumberOfItems()
75 return TOTAL_ITEM_NUMBER;
79 * Create an Actor to represent a visible item.
81 * @return the created actor.
83 virtual Actor NewItem(unsigned int itemId)
85 // Create an test actor for this item
86 ImageActor actor = CreateSolidColorActor(Color::RED);
87 actor.SetSize(64.0f, 64.0f);
96 int UtcDaliSpiralLayoutNew(void)
98 ToolkitTestApplication application;
100 // Create a spiral layout
101 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
103 DALI_TEST_CHECK(spiralLayout);
107 int UtcDaliSpiralSetAndGetItemSizeFunction(void)
109 ToolkitTestApplication application;
111 // Create a spiral layout
112 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
114 // Set the item size function
115 spiralLayout->SetItemSizeFunction(SpiralLayoutItemSizeFunction);
117 // Check whether we get the correct item size function
118 DALI_TEST_CHECK(spiralLayout->GetItemSizeFunction() == SpiralLayoutItemSizeFunction);
122 int UtcDaliSpiralSetAndGetItemSpacing(void)
124 ToolkitTestApplication application;
126 // Create a spiral layout
127 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
129 // Set the item spacing
130 spiralLayout->SetItemSpacing(Radian(0.6f));
132 // Check whether we get the correct item spacing
133 DALI_TEST_EQUALS(spiralLayout->GetItemSpacing(), 0.6f, TEST_LOCATION );
137 int UtcDaliSpiralSetAndGetRevolutionDistance(void)
139 ToolkitTestApplication application;
141 // Create a spiral layout
142 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
144 // Set the revolution distance
145 spiralLayout->SetRevolutionDistance(150.0f);
147 // Check whether we get the correct revolution distance
148 DALI_TEST_EQUALS(spiralLayout->GetRevolutionDistance(), 150.0f, TEST_LOCATION );
152 int UtcDaliSpiralSetAndGetSpiralRadiusFunction(void)
154 ToolkitTestApplication application;
156 // Create a spiral layout
157 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
159 // Set the spiral radius function
160 spiralLayout->SetSpiralRadiusFunction(SpiralLayoutSpiralRadiusFunction);
162 // Check whether we get the correct spiral radius function
163 DALI_TEST_CHECK(spiralLayout->GetSpiralRadiusFunction() == SpiralLayoutSpiralRadiusFunction);
167 int UtcDaliSpiralSetAndGetTopItemAlignment(void)
169 ToolkitTestApplication application;
171 // Create a spiral layout
172 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
174 // Set the alignment of the top item
175 spiralLayout->SetTopItemAlignment(-0.25f);
177 // Check whether we get the correct alignment of the top item
178 DALI_TEST_EQUALS(spiralLayout->GetTopItemAlignment(), -0.25f, TEST_LOCATION );
182 int UtcDaliSpiralSetAndGetScrollSpeedFactor(void)
184 ToolkitTestApplication application;
186 // Create a spiral layout
187 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
189 // Set the scroll speed factor
190 spiralLayout->SetScrollSpeedFactor(0.05f);
192 // Check whether we get the correct scroll speed factor
193 DALI_TEST_EQUALS(spiralLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
197 int UtcDaliSpiralSetAndGetMaximumSwipeSpeed(void)
199 ToolkitTestApplication application;
201 // Create a spiral layout
202 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
204 // Set the maximum swipe speed
205 spiralLayout->SetMaximumSwipeSpeed(50.0f);
207 // Check whether we get the correct maximum swipe speed
208 DALI_TEST_EQUALS(spiralLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
212 int UtcDaliSpiralLayoutSetAndGetItemFlickAnimationDuration(void)
214 ToolkitTestApplication application;
216 // Create a spiral layout
217 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
219 // Set the flick animaiton duration
220 spiralLayout->SetItemFlickAnimationDuration(0.35f);
222 // Check whether we get the correct flick animaiton duration
223 DALI_TEST_EQUALS( spiralLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
227 int UtcDaliSpiralLayoutConstraintLeft(void)
229 ToolkitTestApplication application;
231 // Create the ItemView actor
232 TestItemFactory factory;
233 ItemView view = ItemView::New(factory);
234 Vector3 vec(480.0f, 800.0f, 0.0f);
235 SpiralLayoutPtr layout = SpiralLayout::New();
237 view.SetName("view actor");
238 view.AddLayout(*layout);
241 Stage::GetCurrent().Add(view);
242 layout->SetOrientation(ControlOrientation::Left);
243 view.ActivateLayout(0, vec, 0.0f);
245 application.SendNotification();
246 application.Render(0);
249 for(int i = 0; i < 10; ++i)
251 application.Render(16); // 60hz frames
254 // Confirm: we have actors in the view and they are positioned some distance from the origin.
255 int nonZeroCount = 0;
256 int elementsFound = 0;
257 for(unsigned int i = 0; i < 10; i++)
259 Actor testActor = view.GetItem(i);
263 Vector3 pos = testActor.GetCurrentPosition();
265 if (pos.LengthSquared() > 0.0f)
272 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
273 Stage::GetCurrent().Remove(view);
277 int UtcDaliSpiralLayoutConstraintRight(void)
279 ToolkitTestApplication application;
281 // Create the ItemView actor
282 TestItemFactory factory;
283 ItemView view = ItemView::New(factory);
284 Vector3 vec(480.0f, 800.0f, 0.0f);
285 SpiralLayoutPtr layout = SpiralLayout::New();
287 view.SetName("view actor");
288 view.AddLayout(*layout);
291 Stage::GetCurrent().Add(view);
292 layout->SetOrientation(ControlOrientation::Right);
293 view.ActivateLayout(0, vec, 0.0f);
295 application.SendNotification();
296 application.Render(0);
299 for(int i = 0; i < 10; ++i)
301 application.Render(16); // 60hz frames
304 // Confirm: we have actors in the view and they are positioned some distance from the origin.
305 int nonZeroCount = 0;
306 int elementsFound = 0;
307 for(unsigned int i = 0; i < 10; i++)
309 Actor testActor = view.GetItem(i);
313 Vector3 pos = testActor.GetCurrentPosition();
315 if (pos.LengthSquared() > 0.0f)
322 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
323 Stage::GetCurrent().Remove(view);
327 int UtcDaliSpiralLayoutConstraintUp(void)
329 ToolkitTestApplication application;
331 // Create the ItemView actor
332 TestItemFactory factory;
333 ItemView view = ItemView::New(factory);
334 Vector3 vec(480.0f, 800.0f, 0.0f);
335 SpiralLayoutPtr layout = SpiralLayout::New();
337 view.SetName("view actor");
338 view.AddLayout(*layout);
341 Stage::GetCurrent().Add(view);
342 layout->SetOrientation(ControlOrientation::Up);
343 view.ActivateLayout(0, vec, 0.0f);
345 application.SendNotification();
346 application.Render(0);
349 for(int i = 0; i < 10; ++i)
351 application.Render(16); // 60hz frames
354 // Confirm: we have actors in the view and they are positioned some distance from the origin.
355 int nonZeroCount = 0;
356 int elementsFound = 0;
357 for(unsigned int i = 0; i < 10; i++)
359 Actor testActor = view.GetItem(i);
363 Vector3 pos = testActor.GetCurrentPosition();
365 if (pos.LengthSquared() > 0.0f)
372 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
374 layout->GetClosestOnScreenLayoutPosition(0, 0.0f, vec);
375 int nextItem = layout->GetNextFocusItemID(0, 10, Dali::Toolkit::Control::Right, false);
376 DALI_TEST_CHECK(nextItem == 1);
378 Stage::GetCurrent().Remove(view);
382 int UtcDaliSpiralLayoutConstraintDown(void)
384 ToolkitTestApplication application;
386 // Create the ItemView actor
387 TestItemFactory factory;
388 ItemView view = ItemView::New(factory);
389 Vector3 vec(480.0f, 800.0f, 0.0f);
390 SpiralLayoutPtr layout = SpiralLayout::New();
392 view.SetName("view actor");
393 view.AddLayout(*layout);
396 Stage::GetCurrent().Add(view);
397 layout->SetOrientation(ControlOrientation::Down);
398 view.ActivateLayout(0, vec, 0.0f);
400 application.SendNotification();
401 application.Render(0);
404 for(int i = 0; i < 10; ++i)
406 application.Render(16); // 60hz frames
409 // Confirm: we have actors in the view and they are positioned some distance from the origin.
410 int nonZeroCount = 0;
411 int elementsFound = 0;
412 for(unsigned int i = 0; i < 10; i++)
414 Actor testActor = view.GetItem(i);
418 Vector3 pos = testActor.GetCurrentPosition();
420 if (pos.LengthSquared() > 0.0f)
427 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
428 Stage::GetCurrent().Remove(view);
432 int UtcDaliSpiralLayoutScrollDirection(void)
434 ToolkitTestApplication application;
436 // Create the ItemView actor
437 TestItemFactory factory;
438 ItemView view = ItemView::New(factory);
439 Vector3 vec(480.0f, 800.0f, 0.0f);
440 SpiralLayoutPtr navigationLayout = SpiralLayout::New();
442 view.SetName("view actor");
443 view.AddLayout(*navigationLayout);
446 Stage::GetCurrent().Add(view);
447 navigationLayout->SetOrientation(ControlOrientation::Left);
448 view.ActivateLayout(0, vec, 0.0f);
450 application.SendNotification();
451 application.Render(0);
453 ItemLayoutPtr layout = navigationLayout;
456 for(int i = 0; i < 10; ++i)
458 application.Render(16); // 60hz frames
461 navigationLayout->SetOrientation(ControlOrientation::Up);
462 view.ActivateLayout(0, vec, 0.0f);
463 application.SendNotification();
464 application.Render();
466 Degree deg = layout->GetScrollDirection();
467 DALI_TEST_CHECK(deg == -45.0f);
469 navigationLayout->SetOrientation(ControlOrientation::Down);
470 view.ActivateLayout(0, vec, 0.0f);
471 application.SendNotification();
472 application.Render();
474 deg = layout->GetScrollDirection();
475 DALI_TEST_CHECK((deg == 180.0f - 45.0f));
477 layout->SetOrientation(ControlOrientation::Left);
478 view.ActivateLayout(0, vec, 0.0f);
479 application.SendNotification();
480 application.Render();
482 deg = layout->GetScrollDirection();
483 DALI_TEST_CHECK(deg == 45.0f);
485 navigationLayout->SetOrientation(ControlOrientation::Right);
486 view.ActivateLayout(0, vec, 0.0f);
487 application.SendNotification();
488 application.Render();
490 deg = layout->GetScrollDirection();
491 DALI_TEST_CHECK(deg == (270.0f - 45.0f));
493 Stage::GetCurrent().Remove(view);
497 int UtcDaliSpiralLayoutGetScrollToPosition(void)
499 ToolkitTestApplication application;
501 // Create the ItemView actor
502 TestItemFactory factory;
503 ItemView view = ItemView::New(factory);
504 Vector3 vec(480.0f, 800.0f, 0.0f);
505 SpiralLayoutPtr layout = SpiralLayout::New();
507 view.SetName("view actor");
508 view.AddLayout(*layout);
511 Stage::GetCurrent().Add(view);
512 layout->SetOrientation(ControlOrientation::Up);
513 view.ActivateLayout(0, vec, 0.0f);
515 application.SendNotification();
516 application.Render(0);
519 for(int i = 0; i < 10; ++i)
521 application.Render(16); // 60hz frames
524 // Confirm: we have actors in the view.
525 std::vector<unsigned int> indices;
526 for(unsigned int i = 0; i < 10; i++)
528 Actor testActor = view.GetItem(i);
531 indices.push_back(i);
537 if (!indices.empty())
539 const unsigned int firstTargetIndex = indices[indices.size()-1];
540 // scroll to last item
541 view.ScrollToItem(firstTargetIndex, 0.00f);
542 application.Render(16); // 60hz frames
544 std::size_t moveCount = 0;
545 for(std::size_t i = 0; i < indices.size(); i++)
547 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
548 view.ScrollToItem(indices[i], 0.0f);
550 application.Render(16); // 60hz frame
552 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
554 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
560 DALI_TEST_CHECK((moveCount == indices.size()));
565 tet_result(TET_FAIL);
568 Stage::GetCurrent().Remove(view);