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 = Image::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);
153 // Check we are getting the correct layout from ItemView
154 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
158 int UtcDaliItemViewAddAndRemoveLayout(void)
160 ToolkitTestApplication application;
162 // Create the ItemView actor
163 TestItemFactory factory;
164 ItemView view = ItemView::New(factory);
166 // Create a grid layout and add it to ItemView
167 GridLayoutPtr gridLayout = GridLayout::New();
168 view.AddLayout(*gridLayout);
170 // As we have added one layout, check the number of layout is now 1
171 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
173 // Check we are getting the correct layout from ItemView
174 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
176 // Remove the grid layout
177 view.RemoveLayout(0);
179 // As we have removed the grid layout, check the number of layout is now 0
180 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
185 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
187 ToolkitTestApplication application;
189 // Create the ItemView actor
190 TestItemFactory factory;
191 ItemView view = ItemView::New(factory);
193 // Create a grid layout and add it to ItemView
194 GridLayoutPtr gridLayout = GridLayout::New();
195 view.AddLayout(*gridLayout);
197 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
199 // Check there is no active layout at the moment
200 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
202 // Activate the grid layout
203 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
204 view.ActivateLayout(0, stageSize, 0.5f);
206 // Check the current active layout is the grid layout
207 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
212 int UtcDaliItemViewDeactivateCurrentLayout(void)
214 ToolkitTestApplication application;
216 // Create the ItemView actor
217 TestItemFactory factory;
218 ItemView view = ItemView::New(factory);
220 // Create a grid layout and add it to ItemView
221 GridLayoutPtr gridLayout = GridLayout::New();
222 view.AddLayout(*gridLayout);
224 // Check there is no active layout at the moment
225 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
227 // Activate the grid layout
228 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
229 view.ActivateLayout(0, stageSize, 0.5f);
231 // Check the current active layout is the grid layout
232 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
234 // Deactivate the current layout
235 view.DeactivateCurrentLayout();
237 // Check there is no active layout at the moment
238 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
242 int UtcDaliItemViewGetItemAndGetItemId(void)
244 ToolkitTestApplication application;
246 // Create the ItemView actor
247 TestItemFactory factory;
248 ItemView view = ItemView::New(factory);
250 // Create a grid layout and add it to ItemView
251 GridLayoutPtr gridLayout = GridLayout::New();
252 view.AddLayout(*gridLayout);
254 // Activate the grid layout so that the items will be created and added to ItemView
255 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
256 view.ActivateLayout(0, stageSize, 0.5f);
258 // Get the item given the item ID
259 Actor itemActor = view.GetItem(2);
261 // Check we are getting the correct Item ID given the specified actor
262 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
266 int UtcDaliItemViewRemoveItem(void)
268 ToolkitTestApplication application;
270 // Create the ItemView actor
271 TestItemFactory factory;
272 ItemView view = ItemView::New(factory);
274 // Create a grid layout and add it to ItemView
275 GridLayoutPtr gridLayout = GridLayout::New();
276 view.AddLayout(*gridLayout);
278 // Activate the grid layout so that the items will be created and added to ItemView
279 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
280 view.ActivateLayout(0, stageSize, 0.5f);
282 // Get the item given the item ID 2 and 3
283 Actor oldItemActorID2 = view.GetItem(2);
284 Actor oldItemActorID3 = view.GetItem(3);
286 // Remove the item with ID 2
287 view.RemoveItem(2, 0.0f);
289 // Get the new item given the item ID 2
290 Actor newItemActorID2 = view.GetItem(2);
292 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
293 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
294 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
295 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
299 int UtcDaliItemViewGetCurrentLayoutPosition(void)
301 ToolkitTestApplication application;
303 // Create the ItemView actor
304 TestItemFactory factory;
305 ItemView view = ItemView::New(factory);
307 // Create a grid layout and add it to ItemView
308 GridLayoutPtr gridLayout = GridLayout::New();
309 view.AddLayout(*gridLayout);
311 // Activate the grid layout so that the items will be created and added to ItemView
312 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
313 view.ActivateLayout(0, stageSize, 0.0f);
315 // Check the current layout position for the 10th items is 9.0f
316 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
320 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
322 ToolkitTestApplication application;
324 // Create the ItemView actor
325 TestItemFactory factory;
326 ItemView view = ItemView::New(factory);
328 // Set the minimum swipe speed to be 1.5f
329 view.SetMinimumSwipeSpeed(1.5f);
331 // Check the minimum swipe speed is 1.5f
332 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
336 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
338 ToolkitTestApplication application;
340 // Create the ItemView actor
341 TestItemFactory factory;
342 ItemView view = ItemView::New(factory);
344 // Set the minimum swipe distance to be 2.5f
345 view.SetMinimumSwipeDistance(2.5f);
347 // Check the minimum swipe distance is 2.5f
348 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
352 int UtcDaliItemViewSetAndGetAnchoring(void)
354 ToolkitTestApplication application;
356 // Create the ItemView actor
357 TestItemFactory factory;
358 ItemView view = ItemView::New(factory);
360 // Disable the anchor animation
361 view.SetAnchoring(false);
363 // Check the anchor animation is disabled
364 DALI_TEST_CHECK(view.GetAnchoring() == false);
368 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
370 ToolkitTestApplication application;
372 // Create the ItemView actor
373 TestItemFactory factory;
374 ItemView view = ItemView::New(factory);
376 // Set the duration of anchor animation to be 1.5f
377 view.SetAnchoringDuration(1.5f);
379 // Check the duration of anchor animation is 1.5f
380 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
384 int UtcDaliItemViewSetAndGetRefreshInterval(void)
386 ToolkitTestApplication application;
388 // Create the ItemView actor
389 TestItemFactory factory;
390 ItemView view = ItemView::New(factory);
392 // Set the interval between refreshes to be 20
393 view.SetRefreshInterval(20);
395 // Check the interval between refreshes is 20
396 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
400 int UtcDaliItemViewScrollToItem(void)
402 ToolkitTestApplication application;
404 // Create the ItemView actor
405 TestItemFactory factory;
406 ItemView view = ItemView::New(factory);
407 Vector3 vec(480.0f, 800.0f, 0.0f);
408 GridLayoutPtr layout = GridLayout::New();
410 view.SetName("view actor");
411 view.AddLayout(*layout);
414 Stage::GetCurrent().Add(view);
415 layout->SetOrientation(ControlOrientation::Up);
416 view.ActivateLayout(0, vec, 0.0f);
418 application.SendNotification();
419 application.Render(0);
422 for(int i = 0; i < 10; ++i)
424 application.Render(16); // 60hz frames
427 // Confirm: we have actors in the view.
428 std::vector<unsigned int> indices;
429 for(unsigned int i = 0; i < 10; i++)
431 Actor testActor = view.GetItem(i);
434 indices.push_back(i);
440 if (!indices.empty())
442 const unsigned int firstTargetIndex = indices[indices.size()-1];
443 // scroll to last item
444 view.ScrollToItem(firstTargetIndex, 0.00f);
445 for(int i = 0; i < 10; ++i)
447 application.Render(16); // 60hz frames
450 std::size_t moveCount = 0;
451 for(std::size_t i = 0; i < indices.size(); i++)
453 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
454 view.ScrollToItem(indices[i], 0.0f);
455 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
457 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
463 DALI_TEST_CHECK((moveCount == indices.size()));
468 tet_result(TET_FAIL);
471 Stage::GetCurrent().Remove(view);
475 int UtcDaliItemViewSetAndGetMouseWheelScrollDistanceStep(void)
477 ToolkitTestApplication application;
479 // Create the ItemView actor
480 TestItemFactory factory;
481 ItemView view = ItemView::New(factory);
483 // Set the scroll distance step for the mouse wheel event to be 100.0f
484 view.SetMouseWheelScrollDistanceStep(100.0f);
486 // Check the scroll distance step is 100.0f
487 DALI_TEST_EQUALS(view.GetMouseWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );