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>
25 using namespace Toolkit;
27 void spiral_layout_startup(void)
29 test_return_value = TET_UNDEF;
32 void spiral_layout_cleanup(void)
34 test_return_value = TET_PASS;
39 const unsigned int TOTAL_ITEM_NUMBER = 200;
41 Vector3 SpiralLayoutItemSizeFunction(const Vector3& layoutSize)
43 float width = layoutSize.width * 0.2f;
44 return Vector3(width, width, width);
47 float SpiralLayoutSpiralRadiusFunction(const Vector3& layoutSize)
49 return layoutSize.width * 0.5f;
53 // Implementation of ItemFactory for providing actors to ItemView
54 class TestItemFactory : public ItemFactory
60 * @param application class, stored as reference
66 public: // From ItemFactory
69 * Query the number of items available from the factory.
70 * The maximum available item has an ID of GetNumberOfItems() - 1.
72 virtual unsigned int GetNumberOfItems()
74 return TOTAL_ITEM_NUMBER;
78 * Create an Actor to represent a visible item.
80 * @return the created actor.
82 virtual Actor NewItem(unsigned int itemId)
84 // Create an test actor for this item
85 ImageActor actor = CreateSolidColorActor(Color::RED);
86 actor.SetSize(64.0f, 64.0f);
95 int UtcDaliSpiralLayoutNew(void)
97 ToolkitTestApplication application;
99 // Create a spiral layout
100 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
102 DALI_TEST_CHECK(spiralLayout);
106 int UtcDaliSpiralSetAndGetItemSizeFunction(void)
108 ToolkitTestApplication application;
110 // Create a spiral layout
111 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
113 // Set the item size function
114 spiralLayout->SetItemSizeFunction(SpiralLayoutItemSizeFunction);
116 // Check whether we get the correct item size function
117 DALI_TEST_CHECK(spiralLayout->GetItemSizeFunction() == SpiralLayoutItemSizeFunction);
121 int UtcDaliSpiralSetAndGetItemSpacing(void)
123 ToolkitTestApplication application;
125 // Create a spiral layout
126 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
128 // Set the item spacing
129 spiralLayout->SetItemSpacing(Radian(0.6f));
131 // Check whether we get the correct item spacing
132 DALI_TEST_EQUALS(spiralLayout->GetItemSpacing(), 0.6f, TEST_LOCATION );
136 int UtcDaliSpiralSetAndGetRevolutionDistance(void)
138 ToolkitTestApplication application;
140 // Create a spiral layout
141 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
143 // Set the revolution distance
144 spiralLayout->SetRevolutionDistance(150.0f);
146 // Check whether we get the correct revolution distance
147 DALI_TEST_EQUALS(spiralLayout->GetRevolutionDistance(), 150.0f, TEST_LOCATION );
151 int UtcDaliSpiralSetAndGetSpiralRadiusFunction(void)
153 ToolkitTestApplication application;
155 // Create a spiral layout
156 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
158 // Set the spiral radius function
159 spiralLayout->SetSpiralRadiusFunction(SpiralLayoutSpiralRadiusFunction);
161 // Check whether we get the correct spiral radius function
162 DALI_TEST_CHECK(spiralLayout->GetSpiralRadiusFunction() == SpiralLayoutSpiralRadiusFunction);
166 int UtcDaliSpiralSetAndGetTopItemAlignment(void)
168 ToolkitTestApplication application;
170 // Create a spiral layout
171 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
173 // Set the alignment of the top item
174 spiralLayout->SetTopItemAlignment(-0.25f);
176 // Check whether we get the correct alignment of the top item
177 DALI_TEST_EQUALS(spiralLayout->GetTopItemAlignment(), -0.25f, TEST_LOCATION );
181 int UtcDaliSpiralSetAndGetScrollSpeedFactor(void)
183 ToolkitTestApplication application;
185 // Create a spiral layout
186 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
188 // Set the scroll speed factor
189 spiralLayout->SetScrollSpeedFactor(0.05f);
191 // Check whether we get the correct scroll speed factor
192 DALI_TEST_EQUALS(spiralLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
196 int UtcDaliSpiralSetAndGetMaximumSwipeSpeed(void)
198 ToolkitTestApplication application;
200 // Create a spiral layout
201 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
203 // Set the maximum swipe speed
204 spiralLayout->SetMaximumSwipeSpeed(50.0f);
206 // Check whether we get the correct maximum swipe speed
207 DALI_TEST_EQUALS(spiralLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
211 int UtcDaliSpiralLayoutSetAndGetItemFlickAnimationDuration(void)
213 ToolkitTestApplication application;
215 // Create a spiral layout
216 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
218 // Set the flick animaiton duration
219 spiralLayout->SetItemFlickAnimationDuration(0.35f);
221 // Check whether we get the correct flick animaiton duration
222 DALI_TEST_EQUALS( spiralLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
226 int UtcDaliSpiralLayoutConstraintLeft(void)
228 ToolkitTestApplication application;
230 // Create the ItemView actor
231 TestItemFactory factory;
232 ItemView view = ItemView::New(factory);
233 Vector3 vec(480.0f, 800.0f, 0.0f);
234 SpiralLayoutPtr layout = SpiralLayout::New();
236 view.SetName("view actor");
237 view.AddLayout(*layout);
240 Stage::GetCurrent().Add(view);
241 layout->SetOrientation(ControlOrientation::Left);
242 view.ActivateLayout(0, vec, 0.0f);
244 application.SendNotification();
245 application.Render(0);
248 for(int i = 0; i < 10; ++i)
250 application.Render(16); // 60hz frames
253 // Confirm: we have actors in the view and they are positioned some distance from the origin.
254 int nonZeroCount = 0;
255 int elementsFound = 0;
256 for(unsigned int i = 0; i < 10; i++)
258 Actor testActor = view.GetItem(i);
262 Vector3 pos = testActor.GetCurrentPosition();
264 if (pos.LengthSquared() > 0.0f)
271 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
272 Stage::GetCurrent().Remove(view);
276 int UtcDaliSpiralLayoutConstraintRight(void)
278 ToolkitTestApplication application;
280 // Create the ItemView actor
281 TestItemFactory factory;
282 ItemView view = ItemView::New(factory);
283 Vector3 vec(480.0f, 800.0f, 0.0f);
284 SpiralLayoutPtr layout = SpiralLayout::New();
286 view.SetName("view actor");
287 view.AddLayout(*layout);
290 Stage::GetCurrent().Add(view);
291 layout->SetOrientation(ControlOrientation::Right);
292 view.ActivateLayout(0, vec, 0.0f);
294 application.SendNotification();
295 application.Render(0);
298 for(int i = 0; i < 10; ++i)
300 application.Render(16); // 60hz frames
303 // Confirm: we have actors in the view and they are positioned some distance from the origin.
304 int nonZeroCount = 0;
305 int elementsFound = 0;
306 for(unsigned int i = 0; i < 10; i++)
308 Actor testActor = view.GetItem(i);
312 Vector3 pos = testActor.GetCurrentPosition();
314 if (pos.LengthSquared() > 0.0f)
321 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
322 Stage::GetCurrent().Remove(view);
326 int UtcDaliSpiralLayoutConstraintUp(void)
328 ToolkitTestApplication application;
330 // Create the ItemView actor
331 TestItemFactory factory;
332 ItemView view = ItemView::New(factory);
333 Vector3 vec(480.0f, 800.0f, 0.0f);
334 SpiralLayoutPtr layout = SpiralLayout::New();
336 view.SetName("view actor");
337 view.AddLayout(*layout);
340 Stage::GetCurrent().Add(view);
341 layout->SetOrientation(ControlOrientation::Up);
342 view.ActivateLayout(0, vec, 0.0f);
344 application.SendNotification();
345 application.Render(0);
348 for(int i = 0; i < 10; ++i)
350 application.Render(16); // 60hz frames
353 // Confirm: we have actors in the view and they are positioned some distance from the origin.
354 int nonZeroCount = 0;
355 int elementsFound = 0;
356 for(unsigned int i = 0; i < 10; i++)
358 Actor testActor = view.GetItem(i);
362 Vector3 pos = testActor.GetCurrentPosition();
364 if (pos.LengthSquared() > 0.0f)
371 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
373 layout->GetClosestOnScreenLayoutPosition(0, 0.0f, vec);
374 int nextItem = layout->GetNextFocusItemID(0, 10, Dali::Toolkit::Control::Right, false);
375 DALI_TEST_CHECK(nextItem == 1);
377 Stage::GetCurrent().Remove(view);
381 int UtcDaliSpiralLayoutConstraintDown(void)
383 ToolkitTestApplication application;
385 // Create the ItemView actor
386 TestItemFactory factory;
387 ItemView view = ItemView::New(factory);
388 Vector3 vec(480.0f, 800.0f, 0.0f);
389 SpiralLayoutPtr layout = SpiralLayout::New();
391 view.SetName("view actor");
392 view.AddLayout(*layout);
395 Stage::GetCurrent().Add(view);
396 layout->SetOrientation(ControlOrientation::Down);
397 view.ActivateLayout(0, vec, 0.0f);
399 application.SendNotification();
400 application.Render(0);
403 for(int i = 0; i < 10; ++i)
405 application.Render(16); // 60hz frames
408 // Confirm: we have actors in the view and they are positioned some distance from the origin.
409 int nonZeroCount = 0;
410 int elementsFound = 0;
411 for(unsigned int i = 0; i < 10; i++)
413 Actor testActor = view.GetItem(i);
417 Vector3 pos = testActor.GetCurrentPosition();
419 if (pos.LengthSquared() > 0.0f)
426 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
427 Stage::GetCurrent().Remove(view);
431 int UtcDaliSpiralLayoutScrollDirection(void)
433 ToolkitTestApplication application;
435 // Create the ItemView actor
436 TestItemFactory factory;
437 ItemView view = ItemView::New(factory);
438 Vector3 vec(480.0f, 800.0f, 0.0f);
439 SpiralLayoutPtr navigationLayout = SpiralLayout::New();
441 view.SetName("view actor");
442 view.AddLayout(*navigationLayout);
445 Stage::GetCurrent().Add(view);
446 navigationLayout->SetOrientation(ControlOrientation::Left);
447 view.ActivateLayout(0, vec, 0.0f);
449 application.SendNotification();
450 application.Render(0);
452 ItemLayoutPtr layout = navigationLayout;
455 for(int i = 0; i < 10; ++i)
457 application.Render(16); // 60hz frames
460 navigationLayout->SetOrientation(ControlOrientation::Up);
461 view.ActivateLayout(0, vec, 0.0f);
462 application.SendNotification();
463 application.Render();
465 Degree deg = layout->GetScrollDirection();
466 DALI_TEST_CHECK(deg == -45.0f);
468 navigationLayout->SetOrientation(ControlOrientation::Down);
469 view.ActivateLayout(0, vec, 0.0f);
470 application.SendNotification();
471 application.Render();
473 deg = layout->GetScrollDirection();
474 DALI_TEST_CHECK((deg == 180.0f - 45.0f));
476 layout->SetOrientation(ControlOrientation::Left);
477 view.ActivateLayout(0, vec, 0.0f);
478 application.SendNotification();
479 application.Render();
481 deg = layout->GetScrollDirection();
482 DALI_TEST_CHECK(deg == 45.0f);
484 navigationLayout->SetOrientation(ControlOrientation::Right);
485 view.ActivateLayout(0, vec, 0.0f);
486 application.SendNotification();
487 application.Render();
489 deg = layout->GetScrollDirection();
490 DALI_TEST_CHECK(deg == (270.0f - 45.0f));
492 Stage::GetCurrent().Remove(view);
496 int UtcDaliSpiralLayoutGetScrollToPosition(void)
498 ToolkitTestApplication application;
500 // Create the ItemView actor
501 TestItemFactory factory;
502 ItemView view = ItemView::New(factory);
503 Vector3 vec(480.0f, 800.0f, 0.0f);
504 SpiralLayoutPtr layout = SpiralLayout::New();
506 view.SetName("view actor");
507 view.AddLayout(*layout);
510 Stage::GetCurrent().Add(view);
511 layout->SetOrientation(ControlOrientation::Up);
512 view.ActivateLayout(0, vec, 0.0f);
514 application.SendNotification();
515 application.Render(0);
518 for(int i = 0; i < 10; ++i)
520 application.Render(16); // 60hz frames
523 // Confirm: we have actors in the view.
524 std::vector<unsigned int> indices;
525 for(unsigned int i = 0; i < 10; i++)
527 Actor testActor = view.GetItem(i);
530 indices.push_back(i);
536 if (!indices.empty())
538 const unsigned int firstTargetIndex = indices[indices.size()-1];
539 // scroll to last item
540 view.ScrollToItem(firstTargetIndex, 0.00f);
541 application.Render(16); // 60hz frames
543 std::size_t moveCount = 0;
544 for(std::size_t i = 0; i < indices.size(); i++)
546 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
547 view.ScrollToItem(indices[i], 0.0f);
549 application.Render(16); // 60hz frame
551 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
553 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
559 DALI_TEST_CHECK((moveCount == indices.size()));
564 tet_result(TET_FAIL);
567 Stage::GetCurrent().Remove(view);