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.
19 #include <float.h> // for FLT_MAX
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
26 using namespace Toolkit;
30 const unsigned int TOTAL_ITEM_NUMBER = 200;
32 Vector3 DepthLayoutItemSizeFunction(unsigned int numberOfColumns, float layoutWidth)
34 float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * 0.8f;
35 return Vector3(width, width, width);
38 float DepthLayoutBottomMarginFunction(float layoutHeight)
40 return layoutHeight * 0.25f;
43 float DepthLayoutColumnPositionFunction(unsigned int numberOfColumns, unsigned int columnNumber, const Vector3& itemSize, float layoutWidth)
45 float availableSpace = layoutWidth - itemSize.width * numberOfColumns;
46 float leftMargin = availableSpace / numberOfColumns * 0.5f;
47 float columnPosition = leftMargin + itemSize.width * 0.5f + columnNumber * (itemSize.width + availableSpace / numberOfColumns);
48 return columnPosition - layoutWidth * 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);
93 void depth_layout_startup(void)
97 void depth_layout_cleanup(void)
101 int UtcDaliDepthLayoutNew(void)
103 ToolkitTestApplication application;
105 // Create a depth layout
106 DepthLayoutPtr depthLayout = DepthLayout::New();
108 DALI_TEST_CHECK(depthLayout);
112 int UtcDaliDepthLayoutSetAndGetNumberOfColumns(void)
114 ToolkitTestApplication application;
116 // Create a depth layout
117 DepthLayoutPtr depthLayout = DepthLayout::New();
119 // Set the number of columns
120 depthLayout->SetNumberOfColumns(5);
122 // Check whether we get the correct number of columns
123 DALI_TEST_CHECK(depthLayout->GetNumberOfColumns() == 5);
127 int UtcDaliDepthLayoutSetAndGetNumberOfRows(void)
129 ToolkitTestApplication application;
131 // Create a depth layout
132 DepthLayoutPtr depthLayout = DepthLayout::New();
134 // Set the number of rows
135 depthLayout->SetNumberOfRows(15);
137 // Check whether we get the correct number of rows
138 DALI_TEST_CHECK(depthLayout->GetNumberOfRows() == 15);
142 int UtcDaliDepthLayoutSetAndGetRowSpacing(void)
144 ToolkitTestApplication application;
146 // Create a depth layout
147 DepthLayoutPtr depthLayout = DepthLayout::New();
149 // Set the row spacing
150 depthLayout->SetRowSpacing(30.0f);
152 // Check whether we get the correct row spacing
153 DALI_TEST_EQUALS(depthLayout->GetRowSpacing(), 30.0f, TEST_LOCATION );
157 int UtcDaliDepthLayoutSetAndGetTiltAngle(void)
159 ToolkitTestApplication application;
161 // Create a depth layout
162 DepthLayoutPtr depthLayout = DepthLayout::New();
164 // Set the tilt angle
165 depthLayout->SetTiltAngle(Degree(25.0f));
167 // Check whether we get the correct tilt angle
168 DALI_TEST_EQUALS(float(depthLayout->GetTiltAngle()), 25.0f, 0.001f, TEST_LOCATION );
172 int UtcDaliDepthLayoutSetAndGetItemSizeFunction(void)
174 ToolkitTestApplication application;
176 // Create a depth layout
177 DepthLayoutPtr depthLayout = DepthLayout::New();
179 // Set the item size function
180 depthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunction);
182 // Check whether we get the correct item size function
183 DALI_TEST_CHECK(depthLayout->GetItemSizeFunction() == DepthLayoutItemSizeFunction);
187 int UtcDaliDepthLayoutSetAndGetBottomMarginFunction(void)
189 ToolkitTestApplication application;
191 // Create a depth layout
192 DepthLayoutPtr depthLayout = DepthLayout::New();
194 // Set the bottom margin function
195 depthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunction);
197 // Check whether we get the correct bottom margin function
198 DALI_TEST_CHECK(depthLayout->GetBottomMarginFunction() == DepthLayoutBottomMarginFunction);
202 int UtcDaliDepthLayoutSetAndGetItemTiltAngle(void)
204 ToolkitTestApplication application;
206 // Create a depth layout
207 DepthLayoutPtr depthLayout = DepthLayout::New();
209 // Set the item's tilt angle
210 depthLayout->SetItemTiltAngle(Degree(5.0f));
212 // Check whether we get the correct item's tilt angle
213 DALI_TEST_EQUALS(float(depthLayout->GetItemTiltAngle()), 5.0f, 0.001f, TEST_LOCATION );
217 int UtcDaliDepthLayoutSetAndGetColumnPositionFunction(void)
219 ToolkitTestApplication application;
221 // Create a depth layout
222 DepthLayoutPtr depthLayout = DepthLayout::New();
224 // Set the column position function
225 depthLayout->SetColumnPositionFunction(DepthLayoutColumnPositionFunction);
227 // Check whether we get the correct column position function
228 DALI_TEST_CHECK(depthLayout->GetColumnPositionFunction() == DepthLayoutColumnPositionFunction);
232 int UtcDaliDepthLayoutSetAndGetScrollSpeedFactor(void)
234 ToolkitTestApplication application;
236 // Create a depth layout
237 DepthLayoutPtr depthLayout = DepthLayout::New();
239 // Set the scroll speed factor
240 depthLayout->SetScrollSpeedFactor(0.05f);
242 // Check whether we get the correct scroll speed factor
243 DALI_TEST_EQUALS(depthLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
247 int UtcDaliDepthLayoutSetAndGetMaximumSwipeSpeed(void)
249 ToolkitTestApplication application;
251 // Create a depth layout
252 DepthLayoutPtr depthLayout = DepthLayout::New();
254 // Set the maximum swipe speed
255 depthLayout->SetMaximumSwipeSpeed(50.0f);
257 // Check whether we get the correct maximum swipe speed
258 DALI_TEST_EQUALS(depthLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
262 int UtcDaliDepthLayoutSetAndGetItemFlickAnimationDuration(void)
264 ToolkitTestApplication application;
266 // Create a depth layout
267 DepthLayoutPtr depthLayout = DepthLayout::New();
269 // Set the flick animaiton duration
270 depthLayout->SetItemFlickAnimationDuration(0.35f);
272 // Check whether we get the correct flick animaiton duration
273 DALI_TEST_EQUALS( depthLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
277 int UtcDaliDepthLayoutConstraintLeft(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 DepthLayoutPtr navigationLayout = DepthLayout::New();
286 navigationLayout->SetNumberOfColumns(6);
288 view.SetName("view actor");
289 view.AddLayout(*navigationLayout);
292 Stage::GetCurrent().Add(view);
293 navigationLayout->SetOrientation(ControlOrientation::Left);
294 view.ActivateLayout(0, vec, 0.0f);
296 application.SendNotification();
297 application.Render(0);
300 for(int i = 0; i < 10; ++i)
302 application.Render(16); // 60hz frames
305 // Confirm: we have actors in the view and they are positioned some distance from the origin.
306 int nonZeroCount = 0;
307 int elementsFound = 0;
308 for(unsigned int i = 0; i < 10; i++)
310 Actor testActor = view.GetItem(i);
314 Vector3 pos = testActor.GetCurrentPosition();
316 if (pos.LengthSquared() > 0.0f)
323 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
324 Stage::GetCurrent().Remove(view);
328 int UtcDaliDepthLayoutConstraintRight(void)
330 ToolkitTestApplication application;
332 // Create the ItemView actor
333 TestItemFactory factory;
334 ItemView view = ItemView::New(factory);
335 Vector3 vec(480.0f, 800.0f, 0.0f);
336 DepthLayoutPtr navigationLayout = DepthLayout::New();
337 navigationLayout->SetNumberOfColumns(6);
339 view.SetName("view actor");
340 view.AddLayout(*navigationLayout);
343 Stage::GetCurrent().Add(view);
344 navigationLayout->SetOrientation(ControlOrientation::Right);
345 view.ActivateLayout(0, vec, 0.0f);
347 application.SendNotification();
348 application.Render(0);
351 for(int i = 0; i < 10; ++i)
353 application.Render(16); // 60hz frames
356 // Confirm: we have actors in the view and they are positioned some distance from the origin.
357 int nonZeroCount = 0;
358 int elementsFound = 0;
359 for(unsigned int i = 0; i < 10; i++)
361 Actor testActor = view.GetItem(i);
365 Vector3 pos = testActor.GetCurrentPosition();
367 if (pos.LengthSquared() > 0.0f)
374 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
375 Stage::GetCurrent().Remove(view);
379 int UtcDaliDepthLayoutConstraintUp(void)
381 ToolkitTestApplication application;
383 // Create the ItemView actor
384 TestItemFactory factory;
385 ItemView view = ItemView::New(factory);
386 Vector3 vec(480.0f, 800.0f, 0.0f);
387 DepthLayoutPtr navigationLayout = DepthLayout::New();
388 navigationLayout->SetNumberOfColumns(6);
390 view.SetName("view actor");
391 view.AddLayout(*navigationLayout);
394 Stage::GetCurrent().Add(view);
395 navigationLayout->SetOrientation(ControlOrientation::Up);
396 view.ActivateLayout(0, vec, 0.0f);
398 application.SendNotification();
399 application.Render(0);
402 for(int i = 0; i < 10; ++i)
404 application.Render(16); // 60hz frames
407 // Confirm: we have actors in the view and they are positioned some distance from the origin.
408 int nonZeroCount = 0;
409 int elementsFound = 0;
410 for(unsigned int i = 0; i < 10; i++)
412 Actor testActor = view.GetItem(i);
416 Vector3 pos = testActor.GetCurrentPosition();
418 if (pos.LengthSquared() > 0.0f)
425 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
426 Stage::GetCurrent().Remove(view);
430 int UtcDaliDepthLayoutConstraintDown(void)
432 ToolkitTestApplication application;
434 // Create the ItemView actor
435 TestItemFactory factory;
436 ItemView view = ItemView::New(factory);
437 Vector3 vec(480.0f, 800.0f, 0.0f);
438 DepthLayoutPtr navigationLayout = DepthLayout::New();
439 navigationLayout->SetNumberOfColumns(6);
441 view.SetName("view actor");
442 view.AddLayout(*navigationLayout);
445 Stage::GetCurrent().Add(view);
446 navigationLayout->SetOrientation(ControlOrientation::Down);
447 view.ActivateLayout(0, vec, 0.0f);
449 application.SendNotification();
450 application.Render(0);
453 for(int i = 0; i < 10; ++i)
455 application.Render(16); // 60hz frames
458 // Confirm: we have actors in the view and they are positioned some distance from the origin.
459 int nonZeroCount = 0;
460 int elementsFound = 0;
461 for(unsigned int i = 0; i < 10; i++)
463 Actor testActor = view.GetItem(i);
467 Vector3 pos = testActor.GetCurrentPosition();
469 if (pos.LengthSquared() > 0.0f)
476 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
477 Stage::GetCurrent().Remove(view);
481 int UtcDaliDepthLayoutGetScrollToPosition(void)
483 ToolkitTestApplication application;
485 // Create the ItemView actor
486 TestItemFactory factory;
487 ItemView view = ItemView::New(factory);
488 Vector3 vec(480.0f, 800.0f, 0.0f);
489 DepthLayoutPtr layout = DepthLayout::New();
491 view.SetName("view actor");
492 view.AddLayout(*layout);
495 Stage::GetCurrent().Add(view);
496 layout->SetOrientation(ControlOrientation::Up);
497 view.ActivateLayout(0, vec, 0.0f);
499 application.SendNotification();
500 application.Render(0);
503 for(int i = 0; i < 10; ++i)
505 application.Render(16); // 60hz frames
508 // Confirm: we have actors in the view.
509 std::vector<unsigned int> indices;
510 for(unsigned int i = 0; i < 10; i++)
512 Actor testActor = view.GetItem(i);
515 indices.push_back(i);
521 if (!indices.empty())
523 const unsigned int firstTargetIndex = indices[indices.size()-1];
524 // scroll to last item
525 view.ScrollToItem(firstTargetIndex, 0.00f);
526 application.Render(16); // 60hz frames
528 std::size_t moveCount = 0;
529 for(std::size_t i = 0; i < indices.size(); i++)
531 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
532 view.ScrollToItem(indices[i], 0.0f);
534 application.Render(16); // 60hz frame
536 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
538 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
544 DALI_TEST_CHECK((moveCount == indices.size()));
549 tet_result(TET_FAIL);
552 Stage::GetCurrent().Remove(view);
556 int UtcDaliDepthLayoutScrollDirection(void)
558 ToolkitTestApplication application;
560 // Create the ItemView actor
561 TestItemFactory factory;
562 ItemView view = ItemView::New(factory);
563 Vector3 vec(480.0f, 800.0f, 0.0f);
564 DepthLayoutPtr navigationLayout = DepthLayout::New();
566 view.SetName("view actor");
567 view.AddLayout(*navigationLayout);
570 Stage::GetCurrent().Add(view);
571 navigationLayout->SetOrientation(ControlOrientation::Left);
572 view.ActivateLayout(0, vec, 0.0f);
574 application.SendNotification();
575 application.Render(0);
577 ItemLayoutPtr layout = navigationLayout;
580 for(int i = 0; i < 10; ++i)
582 application.Render(16); // 60hz frames
585 navigationLayout->SetOrientation(ControlOrientation::Up);
586 view.ActivateLayout(0, vec, 0.0f);
587 application.SendNotification();
588 application.Render();
590 Degree deg = layout->GetScrollDirection();
591 DALI_TEST_CHECK(deg == 180.0f);
593 navigationLayout->SetOrientation(ControlOrientation::Down);
594 view.ActivateLayout(0, vec, 0.0f);
595 application.SendNotification();
596 application.Render();
598 deg = layout->GetScrollDirection();
599 DALI_TEST_CHECK((deg == 0.0f));
601 layout->SetOrientation(ControlOrientation::Left);
602 view.ActivateLayout(0, vec, 0.0f);
603 application.SendNotification();
604 application.Render();
606 deg = layout->GetScrollDirection();
607 DALI_TEST_CHECK(deg == 270.0f);
609 navigationLayout->SetOrientation(ControlOrientation::Right);
610 view.ActivateLayout(0, vec, 0.0f);
611 application.SendNotification();
612 application.Render();
614 deg = layout->GetScrollDirection();
615 DALI_TEST_CHECK(deg == 90.0f);
617 Stage::GetCurrent().Remove(view);