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
22 // Need to override adaptor classes for toolkit test harness, so include
23 // test harness headers before dali headers.
24 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/dali-toolkit.h>
30 using namespace Toolkit;
32 void utc_dali_toolkit_grid_layout_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_grid_layout_cleanup(void)
39 test_return_value = TET_PASS;
46 const unsigned int TOTAL_ITEM_NUMBER = 200;
48 Vector3 GridLayoutItemSizeFunction(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)
50 float width = (layoutWidth - sideMargin * 2.0f - columnSpacing * static_cast<float>(numberOfColumns - 1)) / static_cast<float>(numberOfColumns);
52 return Vector3(width, width, width);
56 // Implementation of ItemFactory for providing actors to ItemView
57 class TestItemFactory : public ItemFactory
63 * @param application class, stored as reference
69 public: // From ItemFactory
72 * Query the number of items available from the factory.
73 * The maximum available item has an ID of GetNumberOfItems() - 1.
75 virtual unsigned int GetNumberOfItems()
77 return TOTAL_ITEM_NUMBER;
81 * Create an Actor to represent a visible item.
83 * @return the created actor.
85 virtual Actor NewItem(unsigned int itemId)
87 // Create an test actor for this item
88 ImageActor actor = CreateSolidColorActor(Color::RED);
89 actor.SetSize(64.0f, 64.0f);
98 int UtcDaliGridLayoutNew(void)
100 ToolkitTestApplication application;
102 // Create a grid layout
103 GridLayoutPtr gridLayout = GridLayout::New();
105 DALI_TEST_CHECK(gridLayout);
109 int UtcDaliGridLayoutSetAndGetNumberOfColumns(void)
111 ToolkitTestApplication application;
113 // Create a grid layout
114 GridLayoutPtr gridLayout = GridLayout::New();
116 // Set the number of columns
117 gridLayout->SetNumberOfColumns(6);
119 // Check whether we get the correct number of columns
120 DALI_TEST_CHECK(gridLayout->GetNumberOfColumns() == 6);
124 int UtcDaliGridLayoutSetAndGetRowSpacing(void)
126 ToolkitTestApplication application;
128 // Create a grid layout
129 GridLayoutPtr gridLayout = GridLayout::New();
131 // Set the row spacing
132 gridLayout->SetRowSpacing(10.0f);
134 // Check whether we get the correct row spacing
135 DALI_TEST_EQUALS(gridLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
139 int UtcDaliGridLayoutSetAndGetColumnSpacing(void)
141 ToolkitTestApplication application;
143 // Create a grid layout
144 GridLayoutPtr gridLayout = GridLayout::New();
146 // Set the column spacing
147 gridLayout->SetColumnSpacing(10.0f);
149 // Check whether we get the correct column spacing
150 DALI_TEST_EQUALS(gridLayout->GetColumnSpacing(), 10.0f, TEST_LOCATION );
154 int UtcDaliGridLayoutSetAndGetTopMargin(void)
156 ToolkitTestApplication application;
158 // Create a grid layout
159 GridLayoutPtr gridLayout = GridLayout::New();
161 // Set the top margin
162 gridLayout->SetTopMargin(30.0f);
164 // Check whether we get the correct top margin
165 DALI_TEST_EQUALS(gridLayout->GetTopMargin(), 30.0f, TEST_LOCATION );
169 int UtcDaliGridLayoutSetAndGetBottomMargin(void)
171 ToolkitTestApplication application;
173 // Create a grid layout
174 GridLayoutPtr gridLayout = GridLayout::New();
176 // Set the bottom margin
177 gridLayout->SetBottomMargin(30.0f);
179 // Check whether we get the correct bottom margin
180 DALI_TEST_EQUALS(gridLayout->GetBottomMargin(), 30.0f, TEST_LOCATION );
184 int UtcDaliGridLayoutSetAndGetSideMargin(void)
186 ToolkitTestApplication application;
188 // Create a grid layout
189 GridLayoutPtr gridLayout = GridLayout::New();
191 // Set the side margin
192 gridLayout->SetSideMargin(10.0f);
194 // Check whether we get the correct side margin
195 DALI_TEST_EQUALS(gridLayout->GetSideMargin(), 10.0f, TEST_LOCATION );
199 int UtcDaliGridLayoutSetAndGetZGap(void)
201 ToolkitTestApplication application;
203 // Create a grid layout
204 GridLayoutPtr gridLayout = GridLayout::New();
206 // Set the gap of items in the Z axis in different columns
207 gridLayout->SetZGap(5.0f);
209 // Check whether we get the correct Z gap
210 DALI_TEST_EQUALS(gridLayout->GetZGap(), 5.0f, TEST_LOCATION );
214 int UtcDaliGridLayoutSetAndGetItemSizeFunction(void)
216 ToolkitTestApplication application;
218 // Create a grid layout
219 GridLayoutPtr gridLayout = GridLayout::New();
221 // Set the item size function
222 gridLayout->SetItemSizeFunction(GridLayoutItemSizeFunction);
224 // Check whether we get the correct item size function
225 DALI_TEST_CHECK(gridLayout->GetItemSizeFunction() == GridLayoutItemSizeFunction);
229 int UtcDaliGridLayoutSetAndGetScrollSpeedFactor(void)
231 ToolkitTestApplication application;
233 // Create a grid layout
234 GridLayoutPtr gridLayout = GridLayout::New();
236 // Set the scroll speed factor
237 gridLayout->SetScrollSpeedFactor(0.05f);
239 // Check whether we get the correct scroll speed factor
240 DALI_TEST_EQUALS(gridLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
244 int UtcDaliGridLayoutSetAndGetMaximumSwipeSpeed(void)
246 ToolkitTestApplication application;
248 // Create a grid layout
249 GridLayoutPtr gridLayout = GridLayout::New();
251 // Set the maximum swipe speed
252 gridLayout->SetMaximumSwipeSpeed(50.0f);
254 // Check whether we get the correct maximum swipe speed
255 DALI_TEST_EQUALS(gridLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
259 int UtcDaliGridLayoutSetAndGetItemFlickAnimationDuration(void)
261 ToolkitTestApplication application;
263 // Create a grid layout
264 GridLayoutPtr gridLayout = GridLayout::New();
266 // Set the flick animaiton duration
267 gridLayout->SetItemFlickAnimationDuration(0.35f);
269 // Check whether we get the correct flick animaiton duration
270 DALI_TEST_EQUALS( gridLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
274 int UtcDaliGridLayoutConstraintLeft(void)
276 ToolkitTestApplication application;
278 // Create the ItemView actor
279 TestItemFactory factory;
280 ItemView view = ItemView::New(factory);
281 Vector3 vec(480.0f, 800.0f, 0.0f);
282 GridLayoutPtr gridLayout = GridLayout::New();
283 gridLayout->SetNumberOfColumns(6);
285 view.SetName("view actor");
286 view.AddLayout(*gridLayout);
289 Stage::GetCurrent().Add(view);
290 gridLayout->SetOrientation(ControlOrientation::Left);
291 view.ActivateLayout(0, vec, 0.0f);
293 application.SendNotification();
294 application.Render(0);
297 for(int i = 0; i < 10; ++i)
299 application.Render(16); // 60hz frames
302 // Confirm: we have actors in the view and they are positioned some distance from the origin.
303 int nonZeroCount = 0;
304 int elementsFound = 0;
305 for(unsigned int i = 0; i < 10; i++)
307 Actor testActor = view.GetItem(i);
311 Vector3 pos = testActor.GetCurrentPosition();
313 if (pos.LengthSquared() > 0.0f)
320 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
321 Stage::GetCurrent().Remove(view);
325 int UtcDaliGridLayoutConstraintRight(void)
327 ToolkitTestApplication application;
329 // Create the ItemView actor
330 TestItemFactory factory;
331 ItemView view = ItemView::New(factory);
332 Vector3 vec(480.0f, 800.0f, 0.0f);
333 GridLayoutPtr gridLayout = GridLayout::New();
334 gridLayout->SetNumberOfColumns(6);
336 view.SetName("view actor");
337 view.AddLayout(*gridLayout);
340 Stage::GetCurrent().Add(view);
341 gridLayout->SetOrientation(ControlOrientation::Right);
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));
372 Stage::GetCurrent().Remove(view);
376 int UtcDaliGridLayoutConstraintUp(void)
378 ToolkitTestApplication application;
380 // Create the ItemView actor
381 TestItemFactory factory;
382 ItemView view = ItemView::New(factory);
383 Vector3 vec(480.0f, 800.0f, 0.0f);
384 GridLayoutPtr gridLayout = GridLayout::New();
385 gridLayout->SetNumberOfColumns(6);
387 view.SetName("view actor");
388 view.AddLayout(*gridLayout);
391 Stage::GetCurrent().Add(view);
392 gridLayout->SetOrientation(ControlOrientation::Up);
393 view.ActivateLayout(0, vec, 0.0f);
395 application.SendNotification();
396 application.Render(0);
399 for(int i = 0; i < 10; ++i)
401 application.Render(16); // 60hz frames
404 // Confirm: we have actors in the view and they are positioned some distance from the origin.
405 int nonZeroCount = 0;
406 int elementsFound = 0;
407 for(unsigned int i = 0; i < 10; i++)
409 Actor testActor = view.GetItem(i);
413 Vector3 pos = testActor.GetCurrentPosition();
415 if (pos.LengthSquared() > 0.0f)
422 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
424 ItemLayoutPtr layout = gridLayout;
425 layout->GetClosestOnScreenLayoutPosition(0, 0.0f, vec);
426 int nextItem = layout->GetNextFocusItemID(0, 10, Dali::Toolkit::Control::Right, false);
427 DALI_TEST_CHECK(nextItem == 1);
429 Stage::GetCurrent().Remove(view);
433 int UtcDaliGridLayoutConstraintDown(void)
435 ToolkitTestApplication application;
437 // Create the ItemView actor
438 TestItemFactory factory;
439 ItemView view = ItemView::New(factory);
440 Vector3 vec(480.0f, 800.0f, 0.0f);
441 GridLayoutPtr gridLayout = GridLayout::New();
442 gridLayout->SetNumberOfColumns(6);
444 view.SetName("view actor");
445 view.AddLayout(*gridLayout);
448 Stage::GetCurrent().Add(view);
449 gridLayout->SetOrientation(ControlOrientation::Down);
450 view.ActivateLayout(0, vec, 0.0f);
452 application.SendNotification();
453 application.Render(0);
456 for(int i = 0; i < 10; ++i)
458 application.Render(16); // 60hz frames
461 // Confirm: we have actors in the view and they are positioned some distance from the origin.
462 int nonZeroCount = 0;
463 int elementsFound = 0;
464 for(unsigned int i = 0; i < 10; i++)
466 Actor testActor = view.GetItem(i);
470 Vector3 pos = testActor.GetCurrentPosition();
472 if (pos.LengthSquared() > 0.0f)
479 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
480 Stage::GetCurrent().Remove(view);
484 int UtcDaliGridLayoutScrollDirection(void)
486 ToolkitTestApplication application;
488 // Create the ItemView actor
489 TestItemFactory factory;
490 ItemView view = ItemView::New(factory);
491 Vector3 vec(480.0f, 800.0f, 0.0f);
492 GridLayoutPtr gridLayout = GridLayout::New();
493 gridLayout->SetNumberOfColumns(6);
495 view.SetName("view actor");
496 view.AddLayout(*gridLayout);
499 Stage::GetCurrent().Add(view);
500 gridLayout->SetOrientation(ControlOrientation::Left);
501 view.ActivateLayout(0, vec, 0.0f);
503 application.SendNotification();
504 application.Render(0);
506 ItemLayoutPtr layout = gridLayout;
509 for(int i = 0; i < 10; ++i)
511 application.Render(16); // 60hz frames
514 gridLayout->SetOrientation(ControlOrientation::Up);
515 view.ActivateLayout(0, vec, 0.0f);
516 application.SendNotification();
517 application.Render();
519 Degree deg = layout->GetScrollDirection();
520 DALI_TEST_CHECK(deg == 0.0f);
522 gridLayout->SetOrientation(ControlOrientation::Down);
523 view.ActivateLayout(0, vec, 0.0f);
524 application.SendNotification();
525 application.Render();
527 deg = layout->GetScrollDirection();
528 DALI_TEST_CHECK((deg == 180.0f));
530 layout->SetOrientation(ControlOrientation::Left);
531 view.ActivateLayout(0, vec, 0.0f);
532 application.SendNotification();
533 application.Render();
535 deg = layout->GetScrollDirection();
536 DALI_TEST_CHECK(deg == 90.f);
538 gridLayout->SetOrientation(ControlOrientation::Right);
539 view.ActivateLayout(0, vec, 0.0f);
540 application.SendNotification();
541 application.Render();
543 deg = layout->GetScrollDirection();
544 DALI_TEST_CHECK(deg == 270.0f);
546 Stage::GetCurrent().Remove(view);