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/dali.h>
27 #include <dali-toolkit/dali-toolkit.h>
30 using namespace Toolkit;
32 void utc_dali_toolkit_item_view_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_item_view_cleanup(void)
39 test_return_value = TET_PASS;
44 const unsigned int TOTAL_ITEM_NUMBER = 100;
45 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
47 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
51 gObjectCreatedCallBackCalled = true;
55 // Implementation of ItemFactory for providing actors to ItemView
56 class TestItemFactory : public ItemFactory
62 * @param application class, stored as reference
68 public: // From ItemFactory
71 * Query the number of items available from the factory.
72 * The maximum available item has an ID of GetNumberOfItems() - 1.
74 virtual unsigned int GetNumberOfItems()
76 return TOTAL_ITEM_NUMBER;
80 * Create an Actor to represent a visible item.
82 * @return the created actor.
84 virtual Actor NewItem(unsigned int itemId)
86 // Create an image actor for this item
87 Image image = Image::New( TEST_IMAGE_FILE_NAME );
88 Actor actor = ImageActor::New(image);
97 int UtcDaliItemViewNew(void)
99 ToolkitTestApplication application;
101 // Create the ItemView actor
102 TestItemFactory factory;
103 ItemView view = ItemView::New(factory);
105 DALI_TEST_CHECK(view);
107 //Additional check to ensure object is created by checking if it's registered
108 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
109 DALI_TEST_CHECK( registry );
111 gObjectCreatedCallBackCalled = false;
112 registry.ObjectCreatedSignal().Connect(&TestCallback);
114 TestItemFactory factory;
115 ItemView view = ItemView::New(factory);
117 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
121 int UtcDaliItemViewDownCast(void)
123 ToolkitTestApplication application;
125 // Create the ItemView actor
126 TestItemFactory factory;
127 const ItemView itemViewConst = ItemView::New(factory);
128 ItemView itemView(itemViewConst);
130 BaseHandle handle(itemView);
132 ItemView newItemView = ItemView::DownCast( handle );
133 DALI_TEST_CHECK( itemView );
134 DALI_TEST_CHECK( newItemView == itemView );
138 int UtcDaliItemViewAddAndGetLayout(void)
140 ToolkitTestApplication application;
142 // Create the ItemView actor
143 TestItemFactory factory;
144 ItemView view = ItemView::New(factory);
146 // Create a grid layout and add it to ItemView
147 GridLayoutPtr gridLayout = GridLayout::New();
148 view.AddLayout(*gridLayout);
150 // As we have added one layout, check the number of layout is now 1
151 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
154 // Check we are getting the correct layout from ItemView
155 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
159 int UtcDaliItemViewAddAndRemoveLayout(void)
161 ToolkitTestApplication application;
163 // Create the ItemView actor
164 TestItemFactory factory;
165 ItemView view = ItemView::New(factory);
167 // Create a grid layout and add it to ItemView
168 GridLayoutPtr gridLayout = GridLayout::New();
169 view.AddLayout(*gridLayout);
171 // As we have added one layout, check the number of layout is now 1
172 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
174 // Check we are getting the correct layout from ItemView
175 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
177 // Remove the grid layout
178 view.RemoveLayout(0);
180 // As we have removed the grid layout, check the number of layout is now 0
181 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
186 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
188 ToolkitTestApplication application;
190 // Create the ItemView actor
191 TestItemFactory factory;
192 ItemView view = ItemView::New(factory);
194 // Create a grid layout and add it to ItemView
195 GridLayoutPtr gridLayout = GridLayout::New();
196 view.AddLayout(*gridLayout);
198 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
200 // Check there is no active layout at the moment
201 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
203 // Activate the grid layout
204 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
205 view.ActivateLayout(0, stageSize, 0.5f);
207 // Check the current active layout is the grid layout
208 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
213 int UtcDaliItemViewDeactivateCurrentLayout(void)
215 ToolkitTestApplication application;
217 // Create the ItemView actor
218 TestItemFactory factory;
219 ItemView view = ItemView::New(factory);
221 // Create a grid layout and add it to ItemView
222 GridLayoutPtr gridLayout = GridLayout::New();
223 view.AddLayout(*gridLayout);
225 // Check there is no active layout at the moment
226 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
228 // Activate the grid layout
229 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
230 view.ActivateLayout(0, stageSize, 0.5f);
232 // Check the current active layout is the grid layout
233 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
235 // Deactivate the current layout
236 view.DeactivateCurrentLayout();
238 // Check there is no active layout at the moment
239 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
243 int UtcDaliItemViewGetItemAndGetItemId(void)
245 ToolkitTestApplication application;
247 // Create the ItemView actor
248 TestItemFactory factory;
249 ItemView view = ItemView::New(factory);
251 // Create a grid layout and add it to ItemView
252 GridLayoutPtr gridLayout = GridLayout::New();
253 view.AddLayout(*gridLayout);
255 // Activate the grid layout so that the items will be created and added to ItemView
256 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
257 view.ActivateLayout(0, stageSize, 0.5f);
259 // Get the item given the item ID
260 Actor itemActor = view.GetItem(2);
262 // Check we are getting the correct Item ID given the specified actor
263 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
267 int UtcDaliItemViewRemoveItem(void)
269 ToolkitTestApplication application;
271 // Create the ItemView actor
272 TestItemFactory factory;
273 ItemView view = ItemView::New(factory);
275 // Create a grid layout and add it to ItemView
276 GridLayoutPtr gridLayout = GridLayout::New();
277 view.AddLayout(*gridLayout);
279 // Activate the grid layout so that the items will be created and added to ItemView
280 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
281 view.ActivateLayout(0, stageSize, 0.5f);
283 // Get the item given the item ID 2 and 3
284 Actor oldItemActorID2 = view.GetItem(2);
285 Actor oldItemActorID3 = view.GetItem(3);
287 // Remove the item with ID 2
288 view.RemoveItem(2, 0.0f);
290 // Get the new item given the item ID 2
291 Actor newItemActorID2 = view.GetItem(2);
293 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
294 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
295 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
296 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
300 int UtcDaliItemViewGetCurrentLayoutPosition(void)
302 ToolkitTestApplication application;
304 // Create the ItemView actor
305 TestItemFactory factory;
306 ItemView view = ItemView::New(factory);
308 // Create a grid layout and add it to ItemView
309 GridLayoutPtr gridLayout = GridLayout::New();
310 view.AddLayout(*gridLayout);
312 // Activate the grid layout so that the items will be created and added to ItemView
313 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
314 view.ActivateLayout(0, stageSize, 0.0f);
316 // Check the current layout position for the 10th items is 9.0f
317 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
321 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
323 ToolkitTestApplication application;
325 // Create the ItemView actor
326 TestItemFactory factory;
327 ItemView view = ItemView::New(factory);
329 // Set the minimum swipe speed to be 1.5f
330 view.SetMinimumSwipeSpeed(1.5f);
332 // Check the minimum swipe speed is 1.5f
333 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
337 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
339 ToolkitTestApplication application;
341 // Create the ItemView actor
342 TestItemFactory factory;
343 ItemView view = ItemView::New(factory);
345 // Set the minimum swipe distance to be 2.5f
346 view.SetMinimumSwipeDistance(2.5f);
348 // Check the minimum swipe distance is 2.5f
349 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
353 int UtcDaliItemViewSetAndGetAnchoring(void)
355 ToolkitTestApplication application;
357 // Create the ItemView actor
358 TestItemFactory factory;
359 ItemView view = ItemView::New(factory);
361 // Disable the anchor animation
362 view.SetAnchoring(false);
364 // Check the anchor animation is disabled
365 DALI_TEST_CHECK(view.GetAnchoring() == false);
369 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
371 ToolkitTestApplication application;
373 // Create the ItemView actor
374 TestItemFactory factory;
375 ItemView view = ItemView::New(factory);
377 // Set the duration of anchor animation to be 1.5f
378 view.SetAnchoringDuration(1.5f);
380 // Check the duration of anchor animation is 1.5f
381 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
385 int UtcDaliItemViewSetAndGetRefreshInterval(void)
387 ToolkitTestApplication application;
389 // Create the ItemView actor
390 TestItemFactory factory;
391 ItemView view = ItemView::New(factory);
393 // Set the interval between refreshes to be 20
394 view.SetRefreshInterval(20);
396 // Check the interval between refreshes is 20
397 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
401 int UtcDaliItemViewScrollToItem(void)
403 ToolkitTestApplication application;
405 // Create the ItemView actor
406 TestItemFactory factory;
407 ItemView view = ItemView::New(factory);
408 Vector3 vec(480.0f, 800.0f, 0.0f);
409 GridLayoutPtr layout = GridLayout::New();
411 view.SetName("view actor");
412 view.AddLayout(*layout);
415 Stage::GetCurrent().Add(view);
416 layout->SetOrientation(ControlOrientation::Up);
417 view.ActivateLayout(0, vec, 0.0f);
419 application.SendNotification();
420 application.Render(0);
423 for(int i = 0; i < 10; ++i)
425 application.Render(16); // 60hz frames
428 // Confirm: we have actors in the view.
429 std::vector<unsigned int> indices;
430 for(unsigned int i = 0; i < 10; i++)
432 Actor testActor = view.GetItem(i);
435 indices.push_back(i);
441 if (!indices.empty())
443 const unsigned int firstTargetIndex = indices[indices.size()-1];
444 // scroll to last item
445 view.ScrollToItem(firstTargetIndex, 0.00f);
446 for(int i = 0; i < 10; ++i)
448 application.Render(16); // 60hz frames
451 std::size_t moveCount = 0;
452 for(std::size_t i = 0; i < indices.size(); i++)
454 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
455 view.ScrollToItem(indices[i], 0.0f);
456 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
458 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
464 DALI_TEST_CHECK((moveCount == indices.size()));
469 tet_result(TET_FAIL);
472 Stage::GetCurrent().Remove(view);
476 int UtcDaliItemViewSetAndGetMouseWheelScrollDistanceStep(void)
478 ToolkitTestApplication application;
480 // Create the ItemView actor
481 TestItemFactory factory;
482 ItemView view = ItemView::New(factory);
484 // Set the scroll distance step for the mouse wheel event to be 100.0f
485 view.SetMouseWheelScrollDistanceStep(100.0f);
487 // Check the scroll distance step is 100.0f
488 DALI_TEST_EQUALS(view.GetMouseWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );