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>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
31 void utc_dali_toolkit_item_view_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_item_view_cleanup(void)
38 test_return_value = TET_PASS;
43 const unsigned int TOTAL_ITEM_NUMBER = 100;
44 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
46 static bool gObjectCreatedCallBackCalled;
48 static void TestCallback(BaseHandle handle)
50 gObjectCreatedCallBackCalled = true;
54 // Implementation of ItemFactory for providing actors to ItemView
55 class TestItemFactory : public ItemFactory
61 * @param application class, stored as reference
67 public: // From ItemFactory
70 * Query the number of items available from the factory.
71 * The maximum available item has an ID of GetNumberOfItems() - 1.
73 virtual unsigned int GetNumberOfItems()
75 return TOTAL_ITEM_NUMBER;
79 * Create an Actor to represent a visible item.
81 * @return the created actor.
83 virtual Actor NewItem(unsigned int itemId)
85 // Create an image actor for this item
86 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
87 Actor actor = ImageActor::New(image);
96 int UtcDaliItemViewNew(void)
98 ToolkitTestApplication application;
100 // Create the ItemView actor
101 TestItemFactory factory;
102 ItemView view = ItemView::New(factory);
104 DALI_TEST_CHECK(view);
106 //Additional check to ensure object is created by checking if it's registered
107 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
108 DALI_TEST_CHECK( registry );
110 gObjectCreatedCallBackCalled = false;
111 registry.ObjectCreatedSignal().Connect(&TestCallback);
113 TestItemFactory factory;
114 ItemView view = ItemView::New(factory);
116 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
120 int UtcDaliItemViewDownCast(void)
122 ToolkitTestApplication application;
124 // Create the ItemView actor
125 TestItemFactory factory;
126 const ItemView itemViewConst = ItemView::New(factory);
127 ItemView itemView(itemViewConst);
129 BaseHandle handle(itemView);
131 ItemView newItemView = ItemView::DownCast( handle );
132 DALI_TEST_CHECK( itemView );
133 DALI_TEST_CHECK( newItemView == itemView );
137 int UtcDaliItemViewAddAndGetLayout(void)
139 ToolkitTestApplication application;
141 // Create the ItemView actor
142 TestItemFactory factory;
143 ItemView view = ItemView::New(factory);
145 // Create a grid layout and add it to ItemView
146 GridLayoutPtr gridLayout = GridLayout::New();
147 view.AddLayout(*gridLayout);
149 // As we have added one layout, check the number of layout is now 1
150 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
152 // Create a depth layout and add it to ItemView
153 DepthLayoutPtr depthLayout = DepthLayout::New();
154 view.AddLayout(*depthLayout);
156 // As we have added another layout, check the number of layout is now 2
157 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
159 // Create a spiral layout and add it to ItemView
160 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
161 view.AddLayout(*spiralLayout);
163 // As we have added another layout, check the number of layout is now 3
164 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
166 // Check we are getting the correct layout from ItemView
167 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
168 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
169 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
173 int UtcDaliItemViewAddAndRemoveLayout(void)
175 ToolkitTestApplication application;
177 // Create the ItemView actor
178 TestItemFactory factory;
179 ItemView view = ItemView::New(factory);
181 // Create a grid layout and add it to ItemView
182 GridLayoutPtr gridLayout = GridLayout::New();
183 view.AddLayout(*gridLayout);
185 // As we have added one layout, check the number of layout is now 1
186 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
188 // Create a depth layout and add it to ItemView
189 DepthLayoutPtr depthLayout = DepthLayout::New();
190 view.AddLayout(*depthLayout);
192 // As we have added another layout, check the number of layout is now 2
193 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
195 // Check we are getting the correct layout from ItemView
196 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
197 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
199 // Remove the grid layout
200 view.RemoveLayout(0);
202 // As we have removed the grid layout, check the number of layout is now 1
203 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
205 // Check we are getting the correct layout from ItemView
206 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
208 // Remove the depth layout
209 view.RemoveLayout(0);
211 // As we also removed the depth layout, check the number of layout is now 0
212 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
216 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
218 ToolkitTestApplication application;
220 // Create the ItemView actor
221 TestItemFactory factory;
222 ItemView view = ItemView::New(factory);
224 // Create a grid layout and add it to ItemView
225 GridLayoutPtr gridLayout = GridLayout::New();
226 view.AddLayout(*gridLayout);
228 // Create a depth layout and add it to ItemView
229 DepthLayoutPtr depthLayout = DepthLayout::New();
230 view.AddLayout(*depthLayout);
232 // Create a spiral layout and add it to ItemView
233 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
234 view.AddLayout(*spiralLayout);
236 // As we have added three layouts, check the number of layout is now 3
237 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
239 // Check there is no active layout at the moment
240 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
242 // Activate the depth layout
243 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
244 view.ActivateLayout(1, stageSize, 0.5f);
246 // Check the current active layout is the depth layout
247 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
249 // Activate the grid layout
250 view.ActivateLayout(0, stageSize, 0.5f);
252 // Check the current active layout is the grid layout
253 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
255 // Activate the spiral layout
256 view.ActivateLayout(2, stageSize, 0.5f);
258 // Check the current active layout is the spiral layout
259 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
263 int UtcDaliItemViewDeactivateCurrentLayout(void)
265 ToolkitTestApplication application;
267 // Create the ItemView actor
268 TestItemFactory factory;
269 ItemView view = ItemView::New(factory);
271 // Create a grid layout and add it to ItemView
272 GridLayoutPtr gridLayout = GridLayout::New();
273 view.AddLayout(*gridLayout);
275 // Check there is no active layout at the moment
276 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
278 // Activate the grid layout
279 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
280 view.ActivateLayout(0, stageSize, 0.5f);
282 // Check the current active layout is the grid layout
283 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
285 // Deactivate the current layout
286 view.DeactivateCurrentLayout();
288 // Check there is no active layout at the moment
289 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
293 int UtcDaliItemViewGetItemAndGetItemId(void)
295 ToolkitTestApplication application;
297 // Create the ItemView actor
298 TestItemFactory factory;
299 ItemView view = ItemView::New(factory);
301 // Create a grid layout and add it to ItemView
302 GridLayoutPtr gridLayout = GridLayout::New();
303 view.AddLayout(*gridLayout);
305 // Activate the grid layout so that the items will be created and added to ItemView
306 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
307 view.ActivateLayout(0, stageSize, 0.5f);
309 // Get the item given the item ID
310 Actor itemActor = view.GetItem(2);
312 // Check we are getting the correct Item ID given the specified actor
313 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
317 int UtcDaliItemViewRemoveItem(void)
319 ToolkitTestApplication application;
321 // Create the ItemView actor
322 TestItemFactory factory;
323 ItemView view = ItemView::New(factory);
325 // Create a grid layout and add it to ItemView
326 GridLayoutPtr gridLayout = GridLayout::New();
327 view.AddLayout(*gridLayout);
329 // Activate the grid layout so that the items will be created and added to ItemView
330 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
331 view.ActivateLayout(0, stageSize, 0.5f);
333 // Get the item given the item ID 2 and 3
334 Actor oldItemActorID2 = view.GetItem(2);
335 Actor oldItemActorID3 = view.GetItem(3);
337 // Remove the item with ID 2
338 view.RemoveItem(2, 0.0f);
340 // Get the new item given the item ID 2
341 Actor newItemActorID2 = view.GetItem(2);
343 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
344 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
345 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
346 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
350 int UtcDaliItemViewGetCurrentLayoutPosition(void)
352 ToolkitTestApplication application;
354 // Create the ItemView actor
355 TestItemFactory factory;
356 ItemView view = ItemView::New(factory);
358 // Create a grid layout and add it to ItemView
359 GridLayoutPtr gridLayout = GridLayout::New();
360 view.AddLayout(*gridLayout);
362 // Activate the grid layout so that the items will be created and added to ItemView
363 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
364 view.ActivateLayout(0, stageSize, 0.0f);
366 // Check the current layout position for the 10th items is 9.0f
367 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
371 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
373 ToolkitTestApplication application;
375 // Create the ItemView actor
376 TestItemFactory factory;
377 ItemView view = ItemView::New(factory);
379 // Set the minimum swipe speed to be 1.5f
380 view.SetMinimumSwipeSpeed(1.5f);
382 // Check the minimum swipe speed is 1.5f
383 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
387 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
389 ToolkitTestApplication application;
391 // Create the ItemView actor
392 TestItemFactory factory;
393 ItemView view = ItemView::New(factory);
395 // Set the minimum swipe distance to be 2.5f
396 view.SetMinimumSwipeDistance(2.5f);
398 // Check the minimum swipe distance is 2.5f
399 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
403 int UtcDaliItemViewSetAndGetAnchoring(void)
405 ToolkitTestApplication application;
407 // Create the ItemView actor
408 TestItemFactory factory;
409 ItemView view = ItemView::New(factory);
411 // Disable the anchor animation
412 view.SetAnchoring(false);
414 // Check the anchor animation is disabled
415 DALI_TEST_CHECK(view.GetAnchoring() == false);
419 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
421 ToolkitTestApplication application;
423 // Create the ItemView actor
424 TestItemFactory factory;
425 ItemView view = ItemView::New(factory);
427 // Set the duration of anchor animation to be 1.5f
428 view.SetAnchoringDuration(1.5f);
430 // Check the duration of anchor animation is 1.5f
431 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
435 int UtcDaliItemViewSetAndGetRefreshInterval(void)
437 ToolkitTestApplication application;
439 // Create the ItemView actor
440 TestItemFactory factory;
441 ItemView view = ItemView::New(factory);
443 // Set the interval between refreshes to be 20
444 view.SetRefreshInterval(20);
446 // Check the interval between refreshes is 20
447 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
451 int UtcDaliItemViewScrollToItem(void)
453 ToolkitTestApplication application;
455 // Create the ItemView actor
456 TestItemFactory factory;
457 ItemView view = ItemView::New(factory);
458 Vector3 vec(480.0f, 800.0f, 0.0f);
459 GridLayoutPtr layout = GridLayout::New();
461 view.SetName("view actor");
462 view.AddLayout(*layout);
465 Stage::GetCurrent().Add(view);
466 layout->SetOrientation(ControlOrientation::Up);
467 view.ActivateLayout(0, vec, 0.0f);
469 application.SendNotification();
470 application.Render(0);
473 for(int i = 0; i < 10; ++i)
475 application.Render(16); // 60hz frames
478 // Confirm: we have actors in the view.
479 std::vector<unsigned int> indices;
480 for(unsigned int i = 0; i < 10; i++)
482 Actor testActor = view.GetItem(i);
485 indices.push_back(i);
491 if (!indices.empty())
493 const unsigned int firstTargetIndex = indices[indices.size()-1];
494 // scroll to last item
495 view.ScrollToItem(firstTargetIndex, 0.00f);
496 for(int i = 0; i < 10; ++i)
498 application.Render(16); // 60hz frames
501 std::size_t moveCount = 0;
502 for(std::size_t i = 0; i < indices.size(); i++)
504 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
505 view.ScrollToItem(indices[i], 0.0f);
506 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
508 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
514 DALI_TEST_CHECK((moveCount == indices.size()));
519 tet_result(TET_FAIL);
522 Stage::GetCurrent().Remove(view);
526 int UtcDaliItemViewSetAndGetMouseWheelScrollDistanceStep(void)
528 ToolkitTestApplication application;
530 // Create the ItemView actor
531 TestItemFactory factory;
532 ItemView view = ItemView::New(factory);
534 // Set the scroll distance step for the mouse wheel event to be 100.0f
535 view.SetMouseWheelScrollDistanceStep(100.0f);
537 // Check the scroll distance step is 100.0f
538 DALI_TEST_EQUALS(view.GetMouseWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );