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-toolkit/dali-toolkit.h>
25 using namespace Toolkit;
29 const unsigned int TOTAL_ITEM_NUMBER = 200;
31 Vector3 DepthLayoutItemSizeFunction(unsigned int numberOfColumns, float layoutWidth)
33 float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * 0.8f;
34 return Vector3(width, width, width);
37 float DepthLayoutBottomMarginFunction(float layoutHeight)
39 return layoutHeight * 0.25f;
42 float DepthLayoutColumnPositionFunction(unsigned int numberOfColumns, unsigned int columnNumber, const Vector3& itemSize, float layoutWidth)
44 float availableSpace = layoutWidth - itemSize.width * numberOfColumns;
45 float leftMargin = availableSpace / numberOfColumns * 0.5f;
46 float columnPosition = leftMargin + itemSize.width * 0.5f + columnNumber * (itemSize.width + availableSpace / numberOfColumns);
47 return columnPosition - layoutWidth * 0.5f;
52 // Implementation of ItemFactory for providing actors to ItemView
53 class TestItemFactory : public ItemFactory
59 * @param application class, stored as reference
65 public: // From ItemFactory
68 * Query the number of items available from the factory.
69 * The maximum available item has an ID of GetNumberOfItems() - 1.
71 virtual unsigned int GetNumberOfItems()
73 return TOTAL_ITEM_NUMBER;
77 * Create an Actor to represent a visible item.
79 * @return the created actor.
81 virtual Actor NewItem(unsigned int itemId)
83 // Create an test actor for this item
84 ImageActor actor = CreateSolidColorActor(Color::RED);
85 actor.SetSize(64.0f, 64.0f);
92 void depth_layout_startup(void)
96 void depth_layout_cleanup(void)
100 int UtcDaliDepthLayoutNew(void)
102 ToolkitTestApplication application;
104 // Create a depth layout
105 DepthLayoutPtr depthLayout = DepthLayout::New();
107 DALI_TEST_CHECK(depthLayout);
111 int UtcDaliDepthLayoutSetAndGetNumberOfColumns(void)
113 ToolkitTestApplication application;
115 // Create a depth layout
116 DepthLayoutPtr depthLayout = DepthLayout::New();
118 // Set the number of columns
119 depthLayout->SetNumberOfColumns(5);
121 // Check whether we get the correct number of columns
122 DALI_TEST_CHECK(depthLayout->GetNumberOfColumns() == 5);
126 int UtcDaliDepthLayoutSetAndGetNumberOfRows(void)
128 ToolkitTestApplication application;
130 // Create a depth layout
131 DepthLayoutPtr depthLayout = DepthLayout::New();
133 // Set the number of rows
134 depthLayout->SetNumberOfRows(15);
136 // Check whether we get the correct number of rows
137 DALI_TEST_CHECK(depthLayout->GetNumberOfRows() == 15);
141 int UtcDaliDepthLayoutSetAndGetRowSpacing(void)
143 ToolkitTestApplication application;
145 // Create a depth layout
146 DepthLayoutPtr depthLayout = DepthLayout::New();
148 // Set the row spacing
149 depthLayout->SetRowSpacing(30.0f);
151 // Check whether we get the correct row spacing
152 DALI_TEST_EQUALS(depthLayout->GetRowSpacing(), 30.0f, TEST_LOCATION );
156 int UtcDaliDepthLayoutSetAndGetTiltAngle(void)
158 ToolkitTestApplication application;
160 // Create a depth layout
161 DepthLayoutPtr depthLayout = DepthLayout::New();
163 // Set the tilt angle
164 depthLayout->SetTiltAngle(Degree(25.0f));
166 // Check whether we get the correct tilt angle
167 DALI_TEST_EQUALS(depthLayout->GetTiltAngle(), Degree(25.0f), 0.001f, TEST_LOCATION );
171 int UtcDaliDepthLayoutSetAndGetItemSizeFunction(void)
173 ToolkitTestApplication application;
175 // Create a depth layout
176 DepthLayoutPtr depthLayout = DepthLayout::New();
178 // Set the item size function
179 depthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunction);
181 // Check whether we get the correct item size function
182 DALI_TEST_CHECK(depthLayout->GetItemSizeFunction() == DepthLayoutItemSizeFunction);
186 int UtcDaliDepthLayoutSetAndGetBottomMarginFunction(void)
188 ToolkitTestApplication application;
190 // Create a depth layout
191 DepthLayoutPtr depthLayout = DepthLayout::New();
193 // Set the bottom margin function
194 depthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunction);
196 // Check whether we get the correct bottom margin function
197 DALI_TEST_CHECK(depthLayout->GetBottomMarginFunction() == DepthLayoutBottomMarginFunction);
201 int UtcDaliDepthLayoutSetAndGetItemTiltAngle(void)
203 ToolkitTestApplication application;
205 // Create a depth layout
206 DepthLayoutPtr depthLayout = DepthLayout::New();
208 // Set the item's tilt angle
209 depthLayout->SetItemTiltAngle(Degree(5.0f));
211 // Check whether we get the correct item's tilt angle
212 DALI_TEST_EQUALS(depthLayout->GetItemTiltAngle(), Degree(5.0f), 0.001f, TEST_LOCATION );
216 int UtcDaliDepthLayoutSetAndGetColumnPositionFunction(void)
218 ToolkitTestApplication application;
220 // Create a depth layout
221 DepthLayoutPtr depthLayout = DepthLayout::New();
223 // Set the column position function
224 depthLayout->SetColumnPositionFunction(DepthLayoutColumnPositionFunction);
226 // Check whether we get the correct column position function
227 DALI_TEST_CHECK(depthLayout->GetColumnPositionFunction() == DepthLayoutColumnPositionFunction);
231 int UtcDaliDepthLayoutSetAndGetScrollSpeedFactor(void)
233 ToolkitTestApplication application;
235 // Create a depth layout
236 DepthLayoutPtr depthLayout = DepthLayout::New();
238 // Set the scroll speed factor
239 depthLayout->SetScrollSpeedFactor(0.05f);
241 // Check whether we get the correct scroll speed factor
242 DALI_TEST_EQUALS(depthLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
246 int UtcDaliDepthLayoutSetAndGetMaximumSwipeSpeed(void)
248 ToolkitTestApplication application;
250 // Create a depth layout
251 DepthLayoutPtr depthLayout = DepthLayout::New();
253 // Set the maximum swipe speed
254 depthLayout->SetMaximumSwipeSpeed(50.0f);
256 // Check whether we get the correct maximum swipe speed
257 DALI_TEST_EQUALS(depthLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
261 int UtcDaliDepthLayoutSetAndGetItemFlickAnimationDuration(void)
263 ToolkitTestApplication application;
265 // Create a depth layout
266 DepthLayoutPtr depthLayout = DepthLayout::New();
268 // Set the flick animaiton duration
269 depthLayout->SetItemFlickAnimationDuration(0.35f);
271 // Check whether we get the correct flick animaiton duration
272 DALI_TEST_EQUALS( depthLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
276 int UtcDaliDepthLayoutConstraintLeft(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 DepthLayoutPtr navigationLayout = DepthLayout::New();
285 navigationLayout->SetNumberOfColumns(6);
287 view.SetName("view actor");
288 view.AddLayout(*navigationLayout);
291 Stage::GetCurrent().Add(view);
292 navigationLayout->SetOrientation(ControlOrientation::Left);
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 UtcDaliDepthLayoutConstraintRight(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 DepthLayoutPtr navigationLayout = DepthLayout::New();
336 navigationLayout->SetNumberOfColumns(6);
338 view.SetName("view actor");
339 view.AddLayout(*navigationLayout);
342 Stage::GetCurrent().Add(view);
343 navigationLayout->SetOrientation(ControlOrientation::Right);
344 view.ActivateLayout(0, vec, 0.0f);
346 application.SendNotification();
347 application.Render(0);
350 for(int i = 0; i < 10; ++i)
352 application.Render(16); // 60hz frames
355 // Confirm: we have actors in the view and they are positioned some distance from the origin.
356 int nonZeroCount = 0;
357 int elementsFound = 0;
358 for(unsigned int i = 0; i < 10; i++)
360 Actor testActor = view.GetItem(i);
364 Vector3 pos = testActor.GetCurrentPosition();
366 if (pos.LengthSquared() > 0.0f)
373 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
374 Stage::GetCurrent().Remove(view);
378 int UtcDaliDepthLayoutConstraintUp(void)
380 ToolkitTestApplication application;
382 // Create the ItemView actor
383 TestItemFactory factory;
384 ItemView view = ItemView::New(factory);
385 Vector3 vec(480.0f, 800.0f, 0.0f);
386 DepthLayoutPtr navigationLayout = DepthLayout::New();
387 navigationLayout->SetNumberOfColumns(6);
389 view.SetName("view actor");
390 view.AddLayout(*navigationLayout);
393 Stage::GetCurrent().Add(view);
394 navigationLayout->SetOrientation(ControlOrientation::Up);
395 view.ActivateLayout(0, vec, 0.0f);
397 application.SendNotification();
398 application.Render(0);
401 for(int i = 0; i < 10; ++i)
403 application.Render(16); // 60hz frames
406 // Confirm: we have actors in the view and they are positioned some distance from the origin.
407 int nonZeroCount = 0;
408 int elementsFound = 0;
409 for(unsigned int i = 0; i < 10; i++)
411 Actor testActor = view.GetItem(i);
415 Vector3 pos = testActor.GetCurrentPosition();
417 if (pos.LengthSquared() > 0.0f)
424 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
425 Stage::GetCurrent().Remove(view);
429 int UtcDaliDepthLayoutConstraintDown(void)
431 ToolkitTestApplication application;
433 // Create the ItemView actor
434 TestItemFactory factory;
435 ItemView view = ItemView::New(factory);
436 Vector3 vec(480.0f, 800.0f, 0.0f);
437 DepthLayoutPtr navigationLayout = DepthLayout::New();
438 navigationLayout->SetNumberOfColumns(6);
440 view.SetName("view actor");
441 view.AddLayout(*navigationLayout);
444 Stage::GetCurrent().Add(view);
445 navigationLayout->SetOrientation(ControlOrientation::Down);
446 view.ActivateLayout(0, vec, 0.0f);
448 application.SendNotification();
449 application.Render(0);
452 for(int i = 0; i < 10; ++i)
454 application.Render(16); // 60hz frames
457 // Confirm: we have actors in the view and they are positioned some distance from the origin.
458 int nonZeroCount = 0;
459 int elementsFound = 0;
460 for(unsigned int i = 0; i < 10; i++)
462 Actor testActor = view.GetItem(i);
466 Vector3 pos = testActor.GetCurrentPosition();
468 if (pos.LengthSquared() > 0.0f)
475 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
476 Stage::GetCurrent().Remove(view);
480 int UtcDaliDepthLayoutGetScrollToPosition(void)
482 ToolkitTestApplication application;
484 // Create the ItemView actor
485 TestItemFactory factory;
486 ItemView view = ItemView::New(factory);
487 Vector3 vec(480.0f, 800.0f, 0.0f);
488 DepthLayoutPtr layout = DepthLayout::New();
490 view.SetName("view actor");
491 view.AddLayout(*layout);
494 Stage::GetCurrent().Add(view);
495 layout->SetOrientation(ControlOrientation::Up);
496 view.ActivateLayout(0, vec, 0.0f);
498 application.SendNotification();
499 application.Render(0);
502 for(int i = 0; i < 10; ++i)
504 application.Render(16); // 60hz frames
507 // Confirm: we have actors in the view.
508 std::vector<unsigned int> indices;
509 for(unsigned int i = 0; i < 10; i++)
511 Actor testActor = view.GetItem(i);
514 indices.push_back(i);
520 if (!indices.empty())
522 const unsigned int firstTargetIndex = indices[indices.size()-1];
523 // scroll to last item
524 view.ScrollToItem(firstTargetIndex, 0.00f);
525 application.Render(16); // 60hz frames
527 std::size_t moveCount = 0;
528 for(std::size_t i = 0; i < indices.size(); i++)
530 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
531 view.ScrollToItem(indices[i], 0.0f);
533 application.Render(16); // 60hz frame
535 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
537 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
543 DALI_TEST_CHECK((moveCount == indices.size()));
548 tet_result(TET_FAIL);
551 Stage::GetCurrent().Remove(view);
555 int UtcDaliDepthLayoutScrollDirection(void)
557 ToolkitTestApplication application;
559 // Create the ItemView actor
560 TestItemFactory factory;
561 ItemView view = ItemView::New(factory);
562 Vector3 vec(480.0f, 800.0f, 0.0f);
563 DepthLayoutPtr navigationLayout = DepthLayout::New();
565 view.SetName("view actor");
566 view.AddLayout(*navigationLayout);
569 Stage::GetCurrent().Add(view);
570 navigationLayout->SetOrientation(ControlOrientation::Left);
571 view.ActivateLayout(0, vec, 0.0f);
573 application.SendNotification();
574 application.Render(0);
576 ItemLayoutPtr layout = navigationLayout;
579 for(int i = 0; i < 10; ++i)
581 application.Render(16); // 60hz frames
584 navigationLayout->SetOrientation(ControlOrientation::Up);
585 view.ActivateLayout(0, vec, 0.0f);
586 application.SendNotification();
587 application.Render();
589 Degree deg = layout->GetScrollDirection();
590 DALI_TEST_CHECK(deg.degree == 180.0f);
592 navigationLayout->SetOrientation(ControlOrientation::Down);
593 view.ActivateLayout(0, vec, 0.0f);
594 application.SendNotification();
595 application.Render();
597 deg = layout->GetScrollDirection();
598 DALI_TEST_CHECK((deg.degree == 0.0f));
600 layout->SetOrientation(ControlOrientation::Left);
601 view.ActivateLayout(0, vec, 0.0f);
602 application.SendNotification();
603 application.Render();
605 deg = layout->GetScrollDirection();
606 DALI_TEST_CHECK(deg.degree == 270.0f);
608 navigationLayout->SetOrientation(ControlOrientation::Right);
609 view.ActivateLayout(0, vec, 0.0f);
610 application.SendNotification();
611 application.Render();
613 deg = layout->GetScrollDirection();
614 DALI_TEST_CHECK(deg.degree == 90.0f);
616 Stage::GetCurrent().Remove(view);