2 * Copyright (c) 2017 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>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/pan-gesture-event.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;
45 const unsigned int TOTAL_ITEM_NUMBER = 400;
46 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
48 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
50 static bool gObjectCreatedCallBackCalled;
51 static bool gOnLayoutActivatedCalled; ///< Whether the LayoutActivated signal was invoked.
52 static bool gOnScrollUpdateCalled;
54 static void TestCallback(BaseHandle handle)
56 gObjectCreatedCallBackCalled = true;
59 static void OnLayoutActivated()
61 gOnLayoutActivatedCalled = true;
64 static void OnScrollUpdate( const Vector2& position )
66 gOnScrollUpdateCalled = true;
69 // Generate a PanGestureEvent to send to Core
70 Integration::PanGestureEvent GeneratePan(
72 const Vector2& previousPosition,
73 const Vector2& currentPosition,
74 unsigned long timeDelta,
75 unsigned int numberOfTouches = 1)
77 Integration::PanGestureEvent pan(state);
79 pan.previousPosition = previousPosition;
80 pan.currentPosition = currentPosition;
81 pan.timeDelta = timeDelta;
82 pan.numberOfTouches = numberOfTouches;
88 * Helper to generate PanGestureEvent
90 * @param[in] application Application instance
91 * @param[in] state The Gesture State
92 * @param[in] pos The current position of touch.
94 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
98 if( (state == Gesture::Started) ||
99 (state == Gesture::Possible) )
105 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
112 * Simulate time passed by.
114 * @note this will always process at least 1 frame (1/60 sec)
116 * @param application Test application instance
117 * @param duration Time to pass in milliseconds.
118 * @return The actual time passed in milliseconds
120 int Wait(ToolkitTestApplication& application, int duration = 0)
124 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
126 application.SendNotification();
127 application.Render(RENDER_FRAME_INTERVAL);
128 time += RENDER_FRAME_INTERVAL;
134 // Implementation of ItemFactory for providing actors to ItemView
135 class TestItemFactory : public ItemFactory
141 * @param application class, stored as reference
147 public: // From ItemFactory
150 * Query the number of items available from the factory.
151 * The maximum available item has an ID of GetNumberOfItems() - 1.
153 virtual unsigned int GetNumberOfItems()
155 return TOTAL_ITEM_NUMBER;
159 * Create an Actor to represent a visible item.
161 * @return the created actor.
163 virtual Actor NewItem(unsigned int itemId)
165 // Create a renderable actor for this item
166 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
167 Actor actor = CreateRenderableActor(image);
176 int UtcDaliItemViewNew(void)
178 ToolkitTestApplication application;
180 // Create the ItemView actor
181 TestItemFactory factory;
182 ItemView view = ItemView::New(factory);
184 DALI_TEST_CHECK(view);
186 //Additional check to ensure object is created by checking if it's registered
187 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
188 DALI_TEST_CHECK( registry );
190 gObjectCreatedCallBackCalled = false;
191 registry.ObjectCreatedSignal().Connect(&TestCallback);
193 TestItemFactory factory;
194 ItemView view = ItemView::New(factory);
196 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
200 int UtcDaliItemViewDownCast(void)
202 ToolkitTestApplication application;
204 // Create the ItemView actor
205 TestItemFactory factory;
206 const ItemView itemViewConst = ItemView::New(factory);
207 ItemView itemView(itemViewConst);
209 BaseHandle handle(itemView);
211 ItemView newItemView = ItemView::DownCast( handle );
212 DALI_TEST_CHECK( itemView );
213 DALI_TEST_CHECK( newItemView == itemView );
217 int UtcDaliItemViewAddAndGetLayout(void)
219 ToolkitTestApplication application;
221 // Create the ItemView actor
222 TestItemFactory factory;
223 ItemView view = ItemView::New(factory);
225 // Create a grid layout and add it to ItemView
226 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
227 view.AddLayout(*gridLayout);
229 // As we have added one layout, check the number of layout is now 1
230 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
232 // Create a depth layout and add it to ItemView
233 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
234 view.AddLayout(*depthLayout);
236 // As we have added another layout, check the number of layout is now 2
237 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
239 // Create a spiral layout and add it to ItemView
240 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
241 view.AddLayout(*spiralLayout);
243 // As we have added another layout, check the number of layout is now 3
244 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
246 // Check we are getting the correct layout from ItemView
247 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
248 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
249 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
253 int UtcDaliItemViewAddAndRemoveLayout(void)
255 ToolkitTestApplication application;
257 // Create the ItemView actor
258 TestItemFactory factory;
259 ItemView view = ItemView::New(factory);
261 // Create a grid layout and add it to ItemView
262 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
263 view.AddLayout(*gridLayout);
265 // As we have added one layout, check the number of layout is now 1
266 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
268 // Create a depth layout and add it to ItemView
269 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
270 view.AddLayout(*depthLayout);
272 // As we have added another layout, check the number of layout is now 2
273 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
275 // Check we are getting the correct layout from ItemView
276 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
277 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
279 // Remove the grid layout
280 view.RemoveLayout(0);
282 // As we have removed the grid layout, check the number of layout is now 1
283 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
285 // Check we are getting the correct layout from ItemView
286 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
288 // Remove the depth layout
289 view.RemoveLayout(0);
291 // As we also removed the depth layout, check the number of layout is now 0
292 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
296 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
298 ToolkitTestApplication application;
300 // Create the ItemView actor
301 TestItemFactory factory;
302 ItemView view = ItemView::New(factory);
304 // Create a grid layout and add it to ItemView
305 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
306 view.AddLayout(*gridLayout);
308 // Create a depth layout and add it to ItemView
309 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
310 view.AddLayout(*depthLayout);
312 // Create a spiral layout and add it to ItemView
313 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
314 view.AddLayout(*spiralLayout);
316 // As we have added three layouts, check the number of layout is now 3
317 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
319 // Check there is no active layout at the moment
320 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
322 // Activate the depth layout
323 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
324 view.ActivateLayout(1, stageSize, 0.5f);
326 // Check the current active layout is the depth layout
327 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
329 // Activate the grid layout
330 view.ActivateLayout(0, stageSize, 0.5f);
332 // Check the current active layout is the grid layout
333 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
335 // Activate the spiral layout
336 view.ActivateLayout(2, stageSize, 0.5f);
338 // Check the current active layout is the spiral layout
339 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
343 int UtcDaliItemViewDeactivateCurrentLayout(void)
345 ToolkitTestApplication application;
347 // Create the ItemView actor
348 TestItemFactory factory;
349 ItemView view = ItemView::New(factory);
351 // Create a grid layout and add it to ItemView
352 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
353 gridLayout->SetOrientation(ControlOrientation::Down);
354 view.AddLayout(*gridLayout);
356 // Check there is no active layout at the moment
357 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
359 // Activate the grid layout
360 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
361 view.ActivateLayout(0, stageSize, 0.5f);
363 // Check the current active layout is the grid layout
364 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
366 // Deactivate the current layout
367 view.DeactivateCurrentLayout();
369 // Check there is no active layout at the moment
370 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
374 int UtcDaliItemViewGetItemAndGetItemId(void)
376 ToolkitTestApplication application;
378 // Create the ItemView actor
379 TestItemFactory factory;
380 ItemView view = ItemView::New(factory);
382 // Create a grid layout and add it to ItemView
383 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
384 gridLayout->SetOrientation(ControlOrientation::Left);
385 view.AddLayout(*gridLayout);
387 // Activate the grid layout so that the items will be created and added to ItemView
388 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
389 view.ActivateLayout(0, stageSize, 0.5f);
391 // Get the item given the item ID
392 Actor itemActor = view.GetItem(2);
394 // Check we are getting the correct Item ID given the specified actor
395 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
399 int UtcDaliItemViewRemoveItem(void)
401 ToolkitTestApplication application;
403 // Create the ItemView actor
404 TestItemFactory factory;
405 ItemView view = ItemView::New(factory);
407 // Create a grid layout and add it to ItemView
408 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
409 gridLayout->SetOrientation(ControlOrientation::Right);
410 view.AddLayout(*gridLayout);
412 // Activate the grid layout so that the items will be created and added to ItemView
413 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
414 view.ActivateLayout(0, stageSize, 0.5f);
416 // Get the item given the item ID 2 and 3
417 Actor oldItemActorID2 = view.GetItem(2);
418 Actor oldItemActorID3 = view.GetItem(3);
420 // Remove the item with ID 2
421 view.RemoveItem(2, 0.0f);
423 // Get the new item given the item ID 2 and 3
424 Actor newItemActorID2 = view.GetItem(2);
425 Actor newItemActorID3 = view.GetItem(3);
427 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
428 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
429 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
430 DALI_TEST_CHECK(newItemActorID2 == oldItemActorID3);
432 // scroll to the end of item view
433 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
435 application.SendNotification();
436 application.Render(0);
438 // Refresh the item view
441 Actor itemActorID390 = view.GetItem(390);
442 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
444 // Remove the item with ID 2 (which is now before the current item range)
445 view.RemoveItem(2, 0.0f);
447 // Check the original item with item ID 2 was deleted and now item ID 389 represents the original item with ID 390
448 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 389);
449 DALI_TEST_CHECK(view.GetItem(389) == itemActorID390);
454 int UtcDaliItemViewGetCurrentLayoutPosition(void)
456 ToolkitTestApplication application;
458 // Create the ItemView actor
459 TestItemFactory factory;
460 ItemView view = ItemView::New(factory);
462 // Create a depth layout and add it to ItemView
463 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
464 depthLayout->SetOrientation(ControlOrientation::Up);
465 view.AddLayout(*depthLayout);
467 // Activate the grid layout so that the items will be created and added to ItemView
468 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
469 view.ActivateLayout(0, stageSize, 0.0f);
471 // Check the current layout position for the 10th items is 9.0f
472 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
476 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
478 ToolkitTestApplication application;
480 // Create the ItemView actor
481 TestItemFactory factory;
482 ItemView view = ItemView::New(factory);
484 // Set the minimum swipe speed to be 1.5f
485 view.SetMinimumSwipeSpeed(1.5f);
487 // Check the minimum swipe speed is 1.5f
488 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
492 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
494 ToolkitTestApplication application;
496 // Create the ItemView actor
497 TestItemFactory factory;
498 ItemView view = ItemView::New(factory);
500 // Set the minimum swipe distance to be 2.5f
501 view.SetMinimumSwipeDistance(2.5f);
503 // Check the minimum swipe distance is 2.5f
504 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
508 int UtcDaliItemViewSetAndGetAnchoring(void)
510 ToolkitTestApplication application;
512 // Create the ItemView actor
513 TestItemFactory factory;
514 ItemView view = ItemView::New(factory);
516 // Disable the anchor animation
517 view.SetAnchoring(false);
519 // Check the anchor animation is disabled
520 DALI_TEST_CHECK(view.GetAnchoring() == false);
524 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
526 ToolkitTestApplication application;
528 // Create the ItemView actor
529 TestItemFactory factory;
530 ItemView view = ItemView::New(factory);
532 // Set the duration of anchor animation to be 1.5f
533 view.SetAnchoringDuration(1.5f);
535 // Check the duration of anchor animation is 1.5f
536 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
540 int UtcDaliItemViewSetAndGetRefreshInterval(void)
542 ToolkitTestApplication application;
544 // Create the ItemView actor
545 TestItemFactory factory;
546 ItemView view = ItemView::New(factory);
548 // Set the interval between refreshes to be 20
549 view.SetRefreshInterval(20);
553 // Check the interval between refreshes is 20
554 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
558 int UtcDaliItemViewScrollToItem(void)
560 ToolkitTestApplication application;
562 // Create the ItemView actor
563 TestItemFactory factory;
564 ItemView view = ItemView::New(factory);
565 Vector3 vec(480.0f, 800.0f, 0.0f);
566 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
568 view.SetName("view actor");
569 view.AddLayout(*layout);
572 Stage::GetCurrent().Add(view);
573 layout->SetOrientation(ControlOrientation::Down);
574 view.ActivateLayout(0, vec, 0.0f);
576 application.SendNotification();
577 application.Render(0);
580 for(int i = 0; i < 10; ++i)
582 application.Render(16); // 60hz frames
585 // Confirm: we have actors in the view.
586 std::vector<unsigned int> indices;
587 for(unsigned int i = 0; i < 10; i++)
589 Actor testActor = view.GetItem(i);
592 indices.push_back(i);
598 if (!indices.empty())
600 const unsigned int firstTargetIndex = indices[indices.size()-1];
601 // scroll to last item
602 view.ScrollToItem(firstTargetIndex, 0.00f);
603 for(int i = 0; i < 10; ++i)
605 application.Render(16); // 60hz frames
608 std::size_t moveCount = 0;
609 for(std::size_t i = 0; i < indices.size(); i++)
611 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
612 view.ScrollToItem(indices[i], 0.0f);
613 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
615 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
621 DALI_TEST_CHECK((moveCount == indices.size()));
626 tet_result(TET_FAIL);
629 Stage::GetCurrent().Remove(view);
633 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
635 ToolkitTestApplication application;
637 // Create the ItemView actor
638 TestItemFactory factory;
639 ItemView view = ItemView::New(factory);
641 // Set the scroll distance step for the wheel event to be 100.0f
642 view.SetWheelScrollDistanceStep(100.0f);
644 // Check the scroll distance step is 100.0f
645 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
649 int UtcDaliItemViewInsertItemP(void)
651 ToolkitTestApplication application;
653 // Create the ItemView actor
654 TestItemFactory factory;
655 ItemView view = ItemView::New(factory);
657 // Create a grid layout and add it to ItemView
658 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID);
659 gridLayout->SetOrientation(ControlOrientation::Left);
660 view.AddLayout(*gridLayout);
662 // Activate the grid layout so that the items will be created and added to ItemView
663 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
664 view.ActivateLayout(0, stageSize, 0.0f);
666 // Get the specified item where new item to be inserted before that
667 Actor itemActor = view.GetItem(2);
669 ItemId id = view.GetItemId( itemActor );
671 // Check we are getting the correct Item ID given the specified actor
672 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
674 Actor newActor = Actor::New();
676 view.InsertItem(Item(id, newActor), 0.0f);
678 DALI_TEST_CHECK(view.GetItem(2) == newActor);
680 DALI_TEST_CHECK(view.GetItemId(itemActor) == 3);
681 DALI_TEST_CHECK(view.GetItem(3) == itemActor);
683 // scroll to the end of item view
684 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
686 application.SendNotification();
687 application.Render(0);
689 // Refresh the item view
692 Actor itemActorID390 = view.GetItem(390);
693 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
695 // Insert the item with ID 2 (which is now before the current item range)
696 Actor anotherNewActor = Actor::New();
697 view.InsertItem(Item(id, anotherNewActor), 0.0f);
699 // Check that item ID 391 now represents the original item with ID 390
700 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 391);
701 DALI_TEST_CHECK(view.GetItem(391) == itemActorID390);
706 int UtcDaliItemViewInsertItemsP(void)
708 ToolkitTestApplication application;
710 // Create the ItemView actor
711 TestItemFactory factory;
712 ItemView view = ItemView::New(factory);
714 // Create a depth layout and add it to ItemView
715 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
716 depthLayout->SetOrientation(ControlOrientation::Right);
717 view.AddLayout(*depthLayout);
719 // Activate the grid layout so that the items will be created and added to ItemView
720 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
721 view.ActivateLayout(0, stageSize, 0.5f);
723 unsigned int itemCount = view.GetChildCount();
725 // Get the specified item where new items to be inserted before that
726 Actor itemActor = view.GetItem(1);
728 // Check we are getting the correct Item ID given the specified item
729 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
731 ItemContainer insertList;
733 for( unsigned int i = 1u; i < 11; ++i )
735 Actor child = view.GetChildAt( i );
736 Actor newActor = Actor::New();
737 newActor.SetName("Inserted");
738 insertList.push_back( Item( view.GetItemId(child), newActor ) );
741 if( !insertList.empty() )
743 view.InsertItems( insertList, 0.5f );
746 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
748 // Check that new items are inserted in the correct positions
749 DALI_TEST_CHECK(view.GetItemId(itemActor) == 11);
750 DALI_TEST_CHECK(view.GetItem(11) == itemActor);
752 ItemIdContainer removeList;
754 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
756 Actor child = view.GetChildAt( i );
758 if( child.GetName() == "Inserted" )
760 removeList.push_back( view.GetItemId(child) );
764 if( ! removeList.empty() )
766 view.RemoveItems( removeList, 0.5f );
769 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
771 // Check that new items are removed correctly so that we are getting the correct Item ID given the specified item
772 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
773 DALI_TEST_CHECK(view.GetItem(1) == itemActor);
778 int UtcDaliItemViewReplaceItemP(void)
780 ToolkitTestApplication application;
782 // Create the ItemView actor
783 TestItemFactory factory;
784 ItemView view = ItemView::New(factory);
786 // Create a spiral layout and add it to ItemView
787 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
788 view.AddLayout(*spiralLayout);
790 // Activate the grid layout so that the items will be created and added to ItemView
791 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
792 view.ActivateLayout(0, stageSize, 0.5f);
794 Actor newActor = Actor::New();
796 view.ReplaceItem( Item( 5, newActor ), 0.5f );
798 DALI_TEST_CHECK(view.GetItem(5) == newActor);
803 int UtcDaliItemViewReplaceItemsP(void)
805 ToolkitTestApplication application;
807 // Create the ItemView actor
808 TestItemFactory factory;
809 ItemView view = ItemView::New(factory);
811 // Create a spiral layout and add it to ItemView
812 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
813 spiralLayout->SetOrientation( ControlOrientation::Down );
814 view.AddLayout(*spiralLayout);
816 // Activate the grid layout so that the items will be created and added to ItemView
817 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
818 view.ActivateLayout(0, stageSize, 0.5f);
820 ItemContainer replaceList;
822 for( unsigned int i = 0u; i < 10; ++i )
824 Actor child = view.GetItem( i );
825 Actor newActor = Actor::New();
826 newActor.SetName("Replaced");
828 replaceList.push_back( Item( i, newActor ) );
831 if( !replaceList.empty() )
833 view.ReplaceItems( replaceList, 0.5f );
836 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
837 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
841 int UtcDaliItemViewGetItemsRangeP(void)
843 ToolkitTestApplication application;
845 // Create the ItemView actor
846 TestItemFactory factory;
847 ItemView view = ItemView::New(factory);
849 // Create a spiral layout and add it to ItemView
850 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
851 spiralLayout->SetOrientation( ControlOrientation::Left );
852 view.AddLayout(*spiralLayout);
854 // Activate the grid layout so that the items will be created and added to ItemView
855 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
856 view.ActivateLayout(0, stageSize, 0.5f);
858 ItemRange itemRange(0, 0);
860 view.GetItemsRange(itemRange);
862 DALI_TEST_CHECK(itemRange.Within(0));
866 int UtcDaliItemViewSetItemsAnchorPointP(void)
868 ToolkitTestApplication application;
870 // Create the ItemView actor
871 TestItemFactory factory;
872 ItemView view = ItemView::New(factory);
874 // Create a spiral layout and add it to ItemView
875 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
876 spiralLayout->SetOrientation( ControlOrientation::Right );
877 view.AddLayout(*spiralLayout);
879 // Activate the grid layout so that the items will be created and added to ItemView
880 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
881 view.ActivateLayout(0, stageSize, 0.5f);
883 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
885 view.SetItemsAnchorPoint(anchorPoint);
887 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
888 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
892 int UtcDaliItemViewSetItemsParentOriginP(void)
894 ToolkitTestApplication application;
896 // Create the ItemView actor
897 TestItemFactory factory;
898 ItemView view = ItemView::New(factory);
900 // Create a grid layout and add it to ItemView
901 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
902 view.AddLayout(*gridLayout);
904 // Activate the grid layout so that the items will be created and added to ItemView
905 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
906 view.ActivateLayout(0, stageSize, 0.5f);
908 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
910 view.SetItemsParentOrigin(parentOrigin);
912 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
913 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
917 int UtcDaliItemFactoryGetExtention(void)
919 ToolkitTestApplication application;
920 TestItemFactory factory;
921 DALI_TEST_CHECK( factory.GetExtension() == NULL );
925 int UtcDaliItemViewLayoutActivatedSignalP(void)
927 ToolkitTestApplication application;
929 // Create the ItemView actor
930 TestItemFactory factory;
931 ItemView view = ItemView::New(factory);
933 // Create a grid layout and add it to ItemView
934 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
935 view.AddLayout(*gridLayout);
937 Stage::GetCurrent().Add( view );
939 // Connect the layout activated signal
940 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
942 gOnLayoutActivatedCalled = false;
945 application.SendNotification();
946 application.Render();
948 // Activate the grid layout so that the items will be created and added to ItemView
949 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
950 view.ActivateLayout(0, stageSize, 0.1f);
952 // Wait for 0.1 second
953 Wait(application, 100);
955 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
960 int UtcDaliItemViewSetGetProperty(void)
962 ToolkitTestApplication application;
964 // Create the ItemView actor
965 TestItemFactory factory;
966 ItemView view = ItemView::New(factory);
967 DALI_TEST_CHECK(view);
969 // Event side properties
971 // Test "minimumSwipeSpeed" property
972 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
973 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
974 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
975 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
977 // Test "minimumSwipeDistance" property
978 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
979 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
980 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
981 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
983 // Test "wheelScrollDistanceStep" property
984 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
985 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
986 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
987 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
989 // Test "snapToItemEnabled" property
990 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
991 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
992 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
993 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
995 // Test "refreshInterval" property
996 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
997 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
998 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
999 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
1001 // Test "layout" property
1002 DALI_TEST_CHECK( view.GetPropertyIndex("layout") == ItemView::Property::LAYOUT );
1003 Property::Map gridLayoutProperty;
1004 gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
1005 gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
1006 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
1007 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
1009 Property::Map depthLayoutProperty;
1010 depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
1011 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
1012 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
1014 Property::Map spiralLayoutPrperty;
1015 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
1016 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
1017 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
1019 Property::Map listLayoutPrperty;
1020 listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
1021 listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
1024 Property::Array layoutArray;
1025 layoutArray.PushBack(gridLayoutProperty);
1026 layoutArray.PushBack(depthLayoutProperty);
1027 layoutArray.PushBack(spiralLayoutPrperty);
1028 layoutArray.PushBack(listLayoutPrperty);
1030 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1032 Property::Array getLayoutArray;
1033 DALI_TEST_CHECK( view.GetProperty( ItemView::Property::LAYOUT ).Get( getLayoutArray ) );
1035 //Check that the result is the same as
1036 DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
1037 Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
1039 for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
1041 KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
1042 if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
1044 int layoutType = propertyPair.second.Get<int>();
1045 DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
1047 else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
1049 Vector3 size = propertyPair.second.Get<Vector3>();
1050 DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
1052 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
1054 float spacing = propertyPair.second.Get<float>();
1055 DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
1057 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1059 int number = propertyPair.second.Get<int>();
1060 DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1063 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1066 // Test "overshootEnabled" property
1067 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
1068 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1069 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1070 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1072 // Test "overshootSize" property
1073 DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE );
1074 Vector2 overshootSize = Vector2(100.0f,100.0f);
1075 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
1076 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
1078 // Animatable properties
1080 // Test "layoutPosition" property
1081 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
1082 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1084 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1086 // Test "scrollSpeed" property
1087 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
1088 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1090 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1092 // Test "overshoot" property
1093 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
1094 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1096 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1098 // Test "scrollDirection" property
1099 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
1100 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1102 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1104 // Test "layoutOrientation" property
1105 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
1106 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1108 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1110 // Test "scrollContentSize" property
1111 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
1112 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1114 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1120 int UtcDaliItemViewOvershootVertical(void)
1122 ToolkitTestApplication application;
1123 Dali::Stage stage = Dali::Stage::GetCurrent();
1125 // Create the ItemView actor
1126 TestItemFactory factory;
1127 ItemView view = ItemView::New(factory);
1129 // Create a grid layout and add it to ItemView
1130 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1131 view.AddLayout(*gridLayout);
1134 // Activate the grid layout so that the items will be created and added to ItemView
1135 Vector3 stageSize(stage.GetSize());
1136 view.ActivateLayout(0, stageSize, 0.5f);
1138 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1139 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1141 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1145 // Do a pan starting from 100,100 and moving down
1146 Vector2 pos(100.0f, 100.0f);
1147 SendPan(application, Gesture::Possible, pos);
1148 SendPan(application, Gesture::Started, pos);
1150 Wait(application, 100);
1152 for(int i = 0;i<200;i++)
1154 SendPan(application, Gesture::Continuing, pos);
1159 SendPan(application, Gesture::Finished, pos);
1160 Wait(application, 100);
1162 // Do a pan starting from 100,100 and moving up
1163 pos = Vector2(100.0f, 300.0f);
1164 SendPan(application, Gesture::Possible, pos);
1165 SendPan(application, Gesture::Started, pos);
1167 Wait(application, 100);
1169 for(int i = 0;i<200;i++)
1171 SendPan(application, Gesture::Continuing, pos);
1176 SendPan(application, Gesture::Finished, pos);
1177 Wait(application, 100);
1181 int UtcDaliItemViewOvershootHorizontal(void)
1183 ToolkitTestApplication application;
1184 Dali::Stage stage = Dali::Stage::GetCurrent();
1186 // Create the ItemView actor
1187 TestItemFactory factory;
1188 ItemView view = ItemView::New(factory);
1190 // Create a grid layout and add it to ItemView
1191 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1192 view.AddLayout(*gridLayout);
1195 // Activate the grid layout so that the items will be created and added to ItemView
1196 Vector3 stageSize(stage.GetSize());
1197 view.ActivateLayout(0, stageSize, 0.5f);
1199 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1200 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1202 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1206 // Do a pan starting from 100,100 and moving left
1207 Vector2 pos(100.0f, 100.0f);
1208 SendPan(application, Gesture::Possible, pos);
1209 SendPan(application, Gesture::Started, pos);
1211 Wait(application, 100);
1213 for(int i = 0;i<200;i++)
1215 SendPan(application, Gesture::Continuing, pos);
1220 SendPan(application, Gesture::Finished, pos);
1221 Wait(application, 100);
1223 // Do a pan starting from 100,100 and moving right
1224 pos = Vector2(100.0f, 100.0f);
1225 SendPan(application, Gesture::Possible, pos);
1226 SendPan(application, Gesture::Started, pos);
1228 Wait(application, 100);
1230 for(int i = 0;i<200;i++)
1232 SendPan(application, Gesture::Continuing, pos);
1237 SendPan(application, Gesture::Finished, pos);
1238 Wait(application, 100);
1243 int UtcDaliItemEnableDisableRefresh(void)
1245 ToolkitTestApplication application;
1246 Dali::Stage stage = Dali::Stage::GetCurrent();
1248 // Create the ItemView actor
1249 TestItemFactory factory;
1250 ItemView view = ItemView::New(factory);
1252 // Create a grid layout and add it to ItemView
1253 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1254 view.AddLayout(*gridLayout);
1257 // Activate the grid layout so that the items will be created and added to ItemView
1258 Vector3 stageSize(stage.GetSize());
1259 view.ActivateLayout(0, stageSize, 0.5f);
1261 //Connect to signal scroll updated
1262 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1264 Property::Map attributes;
1265 view.DoAction("enableRefresh", attributes );
1266 gOnScrollUpdateCalled = true;
1267 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1268 application.SendNotification();
1269 application.Render(1000);
1270 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1273 view.DoAction("disableRefresh", attributes );
1274 gOnScrollUpdateCalled = false;
1275 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1276 application.SendNotification();
1277 application.Render(1000);
1279 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );