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 <float.h> // for FLT_MAX
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
33 const unsigned int TOTAL_ITEM_NUMBER = 200;
35 Vector3 SpiralLayoutItemSizeFunction(const Vector3& layoutSize)
37 float width = layoutSize.width * 0.2f;
38 return Vector3(width, width, width);
41 float SpiralLayoutSpiralRadiusFunction(const Vector3& layoutSize)
43 return layoutSize.width * 0.5f;
47 static void Startup();
48 static void Cleanup();
50 // Implementation of ItemFactory for providing actors to ItemView
51 class TestItemFactory : public ItemFactory
57 * @param application class, stored as reference
63 public: // From ItemFactory
66 * Query the number of items available from the factory.
67 * The maximum available item has an ID of GetNumberOfItems() - 1.
69 virtual unsigned int GetNumberOfItems()
71 return TOTAL_ITEM_NUMBER;
75 * Create an Actor to represent a visible item.
77 * @return the created actor.
79 virtual Actor NewItem(unsigned int itemId)
81 // Create an test actor for this item
82 ImageActor actor = CreateSolidColorActor(Color::RED);
83 actor.SetSize(64.0f, 64.0f);
90 void (*tet_startup)() = Startup;
91 void (*tet_cleanup)() = Cleanup;
94 static void UtcDaliSpiralLayoutNew();
95 static void UtcDaliSpiralSetAndGetItemSizeFunction();
96 static void UtcDaliSpiralSetAndGetItemSpacing();
97 static void UtcDaliSpiralSetAndGetRevolutionDistance();
98 static void UtcDaliSpiralSetAndGetSpiralRadiusFunction();
99 static void UtcDaliSpiralSetAndGetTopItemAlignment();
100 static void UtcDaliSpiralSetAndGetScrollSpeedFactor();
101 static void UtcDaliSpiralSetAndGetMaximumSwipeSpeed();
102 static void UtcDaliSpiralLayoutSetAndGetItemFlickAnimationDuration();
103 static void UtcDaliSpiralLayoutConstraintLeft();
104 static void UtcDaliSpiralLayoutConstraintRight();
105 static void UtcDaliSpiralLayoutConstraintUp();
106 static void UtcDaliSpiralLayoutConstraintDown();
107 static void UtcDaliSpiralLayoutGetScrollToPosition();
108 static void UtcDaliSpiralLayoutScrollDirection();
111 POSITIVE_TC_IDX = 0x01,
115 // Add test functionality for all APIs in the class (Positive and Negative)
117 struct tet_testlist tet_testlist[] = {
118 { UtcDaliSpiralLayoutScrollDirection, POSITIVE_TC_IDX },
119 { UtcDaliSpiralLayoutNew, POSITIVE_TC_IDX },
120 { UtcDaliSpiralSetAndGetItemSizeFunction, POSITIVE_TC_IDX },
121 { UtcDaliSpiralSetAndGetItemSpacing, POSITIVE_TC_IDX },
122 { UtcDaliSpiralSetAndGetRevolutionDistance, POSITIVE_TC_IDX },
123 { UtcDaliSpiralSetAndGetSpiralRadiusFunction, POSITIVE_TC_IDX },
124 { UtcDaliSpiralSetAndGetTopItemAlignment, POSITIVE_TC_IDX },
125 { UtcDaliSpiralSetAndGetScrollSpeedFactor, POSITIVE_TC_IDX },
126 { UtcDaliSpiralSetAndGetMaximumSwipeSpeed, POSITIVE_TC_IDX },
127 { UtcDaliSpiralLayoutSetAndGetItemFlickAnimationDuration, POSITIVE_TC_IDX },
128 { UtcDaliSpiralLayoutConstraintLeft, POSITIVE_TC_IDX },
129 { UtcDaliSpiralLayoutConstraintRight, POSITIVE_TC_IDX },
130 { UtcDaliSpiralLayoutConstraintUp, POSITIVE_TC_IDX },
131 { UtcDaliSpiralLayoutConstraintDown, POSITIVE_TC_IDX },
132 { UtcDaliSpiralLayoutGetScrollToPosition, POSITIVE_TC_IDX },
137 // Called only once before first test is run.
138 static void Startup()
142 // Called only once after last test is run
143 static void Cleanup()
147 static void UtcDaliSpiralLayoutNew()
149 ToolkitTestApplication application;
151 // Create a spiral layout
152 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
154 DALI_TEST_CHECK(spiralLayout);
157 static void UtcDaliSpiralSetAndGetItemSizeFunction()
159 ToolkitTestApplication application;
161 // Create a spiral layout
162 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
164 // Set the item size function
165 spiralLayout->SetItemSizeFunction(SpiralLayoutItemSizeFunction);
167 // Check whether we get the correct item size function
168 DALI_TEST_CHECK(spiralLayout->GetItemSizeFunction() == SpiralLayoutItemSizeFunction);
171 static void UtcDaliSpiralSetAndGetItemSpacing()
173 ToolkitTestApplication application;
175 // Create a spiral layout
176 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
178 // Set the item spacing
179 spiralLayout->SetItemSpacing(Radian(0.6f));
181 // Check whether we get the correct item spacing
182 DALI_TEST_EQUALS(spiralLayout->GetItemSpacing(), 0.6f, TEST_LOCATION );
185 static void UtcDaliSpiralSetAndGetRevolutionDistance()
187 ToolkitTestApplication application;
189 // Create a spiral layout
190 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
192 // Set the revolution distance
193 spiralLayout->SetRevolutionDistance(150.0f);
195 // Check whether we get the correct revolution distance
196 DALI_TEST_EQUALS(spiralLayout->GetRevolutionDistance(), 150.0f, TEST_LOCATION );
199 static void UtcDaliSpiralSetAndGetSpiralRadiusFunction()
201 ToolkitTestApplication application;
203 // Create a spiral layout
204 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
206 // Set the spiral radius function
207 spiralLayout->SetSpiralRadiusFunction(SpiralLayoutSpiralRadiusFunction);
209 // Check whether we get the correct spiral radius function
210 DALI_TEST_CHECK(spiralLayout->GetSpiralRadiusFunction() == SpiralLayoutSpiralRadiusFunction);
213 static void UtcDaliSpiralSetAndGetTopItemAlignment()
215 ToolkitTestApplication application;
217 // Create a spiral layout
218 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
220 // Set the alignment of the top item
221 spiralLayout->SetTopItemAlignment(-0.25f);
223 // Check whether we get the correct alignment of the top item
224 DALI_TEST_EQUALS(spiralLayout->GetTopItemAlignment(), -0.25f, TEST_LOCATION );
227 static void UtcDaliSpiralSetAndGetScrollSpeedFactor()
229 ToolkitTestApplication application;
231 // Create a spiral layout
232 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
234 // Set the scroll speed factor
235 spiralLayout->SetScrollSpeedFactor(0.05f);
237 // Check whether we get the correct scroll speed factor
238 DALI_TEST_EQUALS(spiralLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
241 static void UtcDaliSpiralSetAndGetMaximumSwipeSpeed()
243 ToolkitTestApplication application;
245 // Create a spiral layout
246 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
248 // Set the maximum swipe speed
249 spiralLayout->SetMaximumSwipeSpeed(50.0f);
251 // Check whether we get the correct maximum swipe speed
252 DALI_TEST_EQUALS(spiralLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
255 static void UtcDaliSpiralLayoutSetAndGetItemFlickAnimationDuration()
257 ToolkitTestApplication application;
259 // Create a spiral layout
260 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
262 // Set the flick animaiton duration
263 spiralLayout->SetItemFlickAnimationDuration(0.35f);
265 // Check whether we get the correct flick animaiton duration
266 DALI_TEST_EQUALS( spiralLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
269 static void UtcDaliSpiralLayoutConstraintLeft()
271 ToolkitTestApplication application;
273 // Create the ItemView actor
274 TestItemFactory factory;
275 ItemView view = ItemView::New(factory);
276 Vector3 vec(480.0f, 800.0f, 0.0f);
277 SpiralLayoutPtr layout = SpiralLayout::New();
279 view.SetName("view actor");
280 view.AddLayout(*layout);
283 Stage::GetCurrent().Add(view);
284 layout->SetOrientation(ControlOrientation::Left);
285 view.ActivateLayout(0, vec, 0.0f);
287 application.SendNotification();
288 application.Render(0);
291 for(int i = 0; i < 10; ++i)
293 application.Render(16); // 60hz frames
296 // Confirm: we have actors in the view and they are positioned some distance from the origin.
297 int nonZeroCount = 0;
298 int elementsFound = 0;
299 for(unsigned int i = 0; i < 10; i++)
301 Actor testActor = view.GetItem(i);
305 Vector3 pos = testActor.GetCurrentPosition();
307 if (pos.LengthSquared() > 0.0f)
314 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
315 Stage::GetCurrent().Remove(view);
318 static void UtcDaliSpiralLayoutConstraintRight()
320 ToolkitTestApplication application;
322 // Create the ItemView actor
323 TestItemFactory factory;
324 ItemView view = ItemView::New(factory);
325 Vector3 vec(480.0f, 800.0f, 0.0f);
326 SpiralLayoutPtr layout = SpiralLayout::New();
328 view.SetName("view actor");
329 view.AddLayout(*layout);
332 Stage::GetCurrent().Add(view);
333 layout->SetOrientation(ControlOrientation::Right);
334 view.ActivateLayout(0, vec, 0.0f);
336 application.SendNotification();
337 application.Render(0);
340 for(int i = 0; i < 10; ++i)
342 application.Render(16); // 60hz frames
345 // Confirm: we have actors in the view and they are positioned some distance from the origin.
346 int nonZeroCount = 0;
347 int elementsFound = 0;
348 for(unsigned int i = 0; i < 10; i++)
350 Actor testActor = view.GetItem(i);
354 Vector3 pos = testActor.GetCurrentPosition();
356 if (pos.LengthSquared() > 0.0f)
363 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
364 Stage::GetCurrent().Remove(view);
367 static void UtcDaliSpiralLayoutConstraintUp()
369 ToolkitTestApplication application;
371 // Create the ItemView actor
372 TestItemFactory factory;
373 ItemView view = ItemView::New(factory);
374 Vector3 vec(480.0f, 800.0f, 0.0f);
375 SpiralLayoutPtr layout = SpiralLayout::New();
377 view.SetName("view actor");
378 view.AddLayout(*layout);
381 Stage::GetCurrent().Add(view);
382 layout->SetOrientation(ControlOrientation::Up);
383 view.ActivateLayout(0, vec, 0.0f);
385 application.SendNotification();
386 application.Render(0);
389 for(int i = 0; i < 10; ++i)
391 application.Render(16); // 60hz frames
394 // Confirm: we have actors in the view and they are positioned some distance from the origin.
395 int nonZeroCount = 0;
396 int elementsFound = 0;
397 for(unsigned int i = 0; i < 10; i++)
399 Actor testActor = view.GetItem(i);
403 Vector3 pos = testActor.GetCurrentPosition();
405 if (pos.LengthSquared() > 0.0f)
412 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
414 layout->GetClosestOnScreenLayoutPosition(0, 0.0f, vec);
415 int nextItem = layout->GetNextFocusItemID(0, 10, Dali::Toolkit::Control::Right, false);
416 DALI_TEST_CHECK(nextItem == 1);
418 Stage::GetCurrent().Remove(view);
421 static void UtcDaliSpiralLayoutConstraintDown()
423 ToolkitTestApplication application;
425 // Create the ItemView actor
426 TestItemFactory factory;
427 ItemView view = ItemView::New(factory);
428 Vector3 vec(480.0f, 800.0f, 0.0f);
429 SpiralLayoutPtr layout = SpiralLayout::New();
431 view.SetName("view actor");
432 view.AddLayout(*layout);
435 Stage::GetCurrent().Add(view);
436 layout->SetOrientation(ControlOrientation::Down);
437 view.ActivateLayout(0, vec, 0.0f);
439 application.SendNotification();
440 application.Render(0);
443 for(int i = 0; i < 10; ++i)
445 application.Render(16); // 60hz frames
448 // Confirm: we have actors in the view and they are positioned some distance from the origin.
449 int nonZeroCount = 0;
450 int elementsFound = 0;
451 for(unsigned int i = 0; i < 10; i++)
453 Actor testActor = view.GetItem(i);
457 Vector3 pos = testActor.GetCurrentPosition();
459 if (pos.LengthSquared() > 0.0f)
466 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
467 Stage::GetCurrent().Remove(view);
470 static void UtcDaliSpiralLayoutScrollDirection()
472 ToolkitTestApplication application;
474 // Create the ItemView actor
475 TestItemFactory factory;
476 ItemView view = ItemView::New(factory);
477 Vector3 vec(480.0f, 800.0f, 0.0f);
478 SpiralLayoutPtr navigationLayout = SpiralLayout::New();
480 view.SetName("view actor");
481 view.AddLayout(*navigationLayout);
484 Stage::GetCurrent().Add(view);
485 navigationLayout->SetOrientation(ControlOrientation::Left);
486 view.ActivateLayout(0, vec, 0.0f);
488 application.SendNotification();
489 application.Render(0);
491 ItemLayoutPtr layout = navigationLayout;
494 for(int i = 0; i < 10; ++i)
496 application.Render(16); // 60hz frames
499 navigationLayout->SetOrientation(ControlOrientation::Up);
500 view.ActivateLayout(0, vec, 0.0f);
501 application.SendNotification();
502 application.Render();
504 Degree deg = layout->GetScrollDirection();
505 DALI_TEST_CHECK(deg == -45.0f);
507 navigationLayout->SetOrientation(ControlOrientation::Down);
508 view.ActivateLayout(0, vec, 0.0f);
509 application.SendNotification();
510 application.Render();
512 deg = layout->GetScrollDirection();
513 DALI_TEST_CHECK((deg == 180.0f - 45.0f));
515 layout->SetOrientation(ControlOrientation::Left);
516 view.ActivateLayout(0, vec, 0.0f);
517 application.SendNotification();
518 application.Render();
520 deg = layout->GetScrollDirection();
521 DALI_TEST_CHECK(deg == 45.0f);
523 navigationLayout->SetOrientation(ControlOrientation::Right);
524 view.ActivateLayout(0, vec, 0.0f);
525 application.SendNotification();
526 application.Render();
528 deg = layout->GetScrollDirection();
529 DALI_TEST_CHECK(deg == (270.0f - 45.0f));
531 Stage::GetCurrent().Remove(view);
534 static void UtcDaliSpiralLayoutGetScrollToPosition()
536 ToolkitTestApplication application;
538 // Create the ItemView actor
539 TestItemFactory factory;
540 ItemView view = ItemView::New(factory);
541 Vector3 vec(480.0f, 800.0f, 0.0f);
542 SpiralLayoutPtr layout = SpiralLayout::New();
544 view.SetName("view actor");
545 view.AddLayout(*layout);
548 Stage::GetCurrent().Add(view);
549 layout->SetOrientation(ControlOrientation::Up);
550 view.ActivateLayout(0, vec, 0.0f);
552 application.SendNotification();
553 application.Render(0);
556 for(int i = 0; i < 10; ++i)
558 application.Render(16); // 60hz frames
561 // Confirm: we have actors in the view.
562 std::vector<unsigned int> indices;
563 for(unsigned int i = 0; i < 10; i++)
565 Actor testActor = view.GetItem(i);
568 indices.push_back(i);
574 if (!indices.empty())
576 const unsigned int firstTargetIndex = indices[indices.size()-1];
577 // scroll to last item
578 view.ScrollToItem(firstTargetIndex, 0.00f);
579 application.Render(16); // 60hz frames
581 std::size_t moveCount = 0;
582 for(std::size_t i = 0; i < indices.size(); i++)
584 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
585 view.ScrollToItem(indices[i], 0.0f);
587 application.Render(16); // 60hz frame
589 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
591 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
597 DALI_TEST_CHECK((moveCount == indices.size()));
602 tet_result(TET_FAIL);
605 Stage::GetCurrent().Remove(view);