2 * Copyright (c) 2019 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>
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 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
71 Integration::TouchEvent touchEvent;
72 Integration::Point point;
73 point.SetState( state );
75 point.SetScreenPosition( screenPosition );
76 point.SetDeviceClass( Device::Class::TOUCH );
77 point.SetDeviceSubclass( Device::Subclass::NONE );
78 touchEvent.points.push_back( point );
79 touchEvent.time = time;
84 * Simulate time passed by.
86 * @note this will always process at least 1 frame (1/60 sec)
88 * @param application Test application instance
89 * @param duration Time to pass in milliseconds.
90 * @return The actual time passed in milliseconds
92 int Wait(ToolkitTestApplication& application, int duration = 0)
96 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
98 application.SendNotification();
99 application.Render(RENDER_FRAME_INTERVAL);
100 time += RENDER_FRAME_INTERVAL;
106 // Implementation of ItemFactory for providing actors to ItemView
107 class TestItemFactory : public ItemFactory
113 * @param application class, stored as reference
119 public: // From ItemFactory
122 * Query the number of items available from the factory.
123 * The maximum available item has an ID of GetNumberOfItems() - 1.
125 virtual unsigned int GetNumberOfItems()
127 return TOTAL_ITEM_NUMBER;
131 * Create an Actor to represent a visible item.
133 * @return the created actor.
135 virtual Actor NewItem(unsigned int itemId)
137 // Create a renderable actor for this item
138 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
139 Actor actor = CreateRenderableActor(image);
148 int UtcDaliItemViewNew(void)
150 ToolkitTestApplication application;
152 // Create the ItemView actor
153 TestItemFactory factory;
154 ItemView view = ItemView::New(factory);
156 DALI_TEST_CHECK(view);
158 //Additional check to ensure object is created by checking if it's registered
159 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
160 DALI_TEST_CHECK( registry );
162 gObjectCreatedCallBackCalled = false;
163 registry.ObjectCreatedSignal().Connect(&TestCallback);
165 TestItemFactory factory;
166 ItemView view = ItemView::New(factory);
168 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
172 int UtcDaliItemViewDownCast(void)
174 ToolkitTestApplication application;
176 // Create the ItemView actor
177 TestItemFactory factory;
178 const ItemView itemViewConst = ItemView::New(factory);
179 ItemView itemView(itemViewConst);
181 BaseHandle handle(itemView);
183 ItemView newItemView = ItemView::DownCast( handle );
184 DALI_TEST_CHECK( itemView );
185 DALI_TEST_CHECK( newItemView == itemView );
189 int UtcDaliItemViewAddAndGetLayout(void)
191 ToolkitTestApplication application;
193 // Create the ItemView actor
194 TestItemFactory factory;
195 ItemView view = ItemView::New(factory);
197 // Create a grid layout and add it to ItemView
198 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
199 view.AddLayout(*gridLayout);
201 // As we have added one layout, check the number of layout is now 1
202 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
204 // Create a depth layout and add it to ItemView
205 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
206 view.AddLayout(*depthLayout);
208 // As we have added another layout, check the number of layout is now 2
209 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
211 // Create a spiral layout and add it to ItemView
212 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
213 view.AddLayout(*spiralLayout);
215 // As we have added another layout, check the number of layout is now 3
216 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
218 // Check we are getting the correct layout from ItemView
219 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
220 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
221 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
225 int UtcDaliItemViewAddAndRemoveLayout(void)
227 ToolkitTestApplication application;
229 // Create the ItemView actor
230 TestItemFactory factory;
231 ItemView view = ItemView::New(factory);
233 // Create a grid layout and add it to ItemView
234 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
235 view.AddLayout(*gridLayout);
237 // As we have added one layout, check the number of layout is now 1
238 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
240 // Create a depth layout and add it to ItemView
241 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
242 view.AddLayout(*depthLayout);
244 // As we have added another layout, check the number of layout is now 2
245 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
247 // Check we are getting the correct layout from ItemView
248 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
249 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
251 // Remove the grid layout
252 view.RemoveLayout(0);
254 // As we have removed the grid layout, check the number of layout is now 1
255 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
257 // Check we are getting the correct layout from ItemView
258 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
260 // Remove the depth layout
261 view.RemoveLayout(0);
263 // As we also removed the depth layout, check the number of layout is now 0
264 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
268 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
270 ToolkitTestApplication application;
272 // Create the ItemView actor
273 TestItemFactory factory;
274 ItemView view = ItemView::New(factory);
276 // Create a grid layout and add it to ItemView
277 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
278 view.AddLayout(*gridLayout);
280 // Create a depth layout and add it to ItemView
281 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
282 view.AddLayout(*depthLayout);
284 // Create a spiral layout and add it to ItemView
285 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
286 view.AddLayout(*spiralLayout);
288 // As we have added three layouts, check the number of layout is now 3
289 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
291 // Check there is no active layout at the moment
292 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
294 // Activate the depth layout
295 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
296 view.ActivateLayout(1, stageSize, 0.5f);
298 // Check the current active layout is the depth layout
299 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
301 // Activate the grid layout
302 view.ActivateLayout(0, stageSize, 0.5f);
304 // Check the current active layout is the grid layout
305 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
307 // Activate the spiral layout
308 view.ActivateLayout(2, stageSize, 0.5f);
310 // Check the current active layout is the spiral layout
311 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
315 int UtcDaliItemViewDeactivateCurrentLayout(void)
317 ToolkitTestApplication application;
319 // Create the ItemView actor
320 TestItemFactory factory;
321 ItemView view = ItemView::New(factory);
323 // Create a grid layout and add it to ItemView
324 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
325 gridLayout->SetOrientation(ControlOrientation::Down);
326 view.AddLayout(*gridLayout);
328 // Check there is no active layout at the moment
329 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
331 // Activate the grid layout
332 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
333 view.ActivateLayout(0, stageSize, 0.5f);
335 // Check the current active layout is the grid layout
336 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
338 // Deactivate the current layout
339 view.DeactivateCurrentLayout();
341 // Check there is no active layout at the moment
342 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
346 int UtcDaliItemViewGetItemAndGetItemId(void)
348 ToolkitTestApplication application;
350 // Create the ItemView actor
351 TestItemFactory factory;
352 ItemView view = ItemView::New(factory);
354 // Create a grid layout and add it to ItemView
355 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
356 gridLayout->SetOrientation(ControlOrientation::Left);
357 view.AddLayout(*gridLayout);
359 // Activate the grid layout so that the items will be created and added to ItemView
360 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
361 view.ActivateLayout(0, stageSize, 0.5f);
363 // Get the item given the item ID
364 Actor itemActor = view.GetItem(2);
366 // Check we are getting the correct Item ID given the specified actor
367 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
371 int UtcDaliItemViewRemoveItem(void)
373 ToolkitTestApplication application;
375 // Create the ItemView actor
376 TestItemFactory factory;
377 ItemView view = ItemView::New(factory);
379 // Create a grid layout and add it to ItemView
380 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
381 gridLayout->SetOrientation(ControlOrientation::Right);
382 view.AddLayout(*gridLayout);
384 // Activate the grid layout so that the items will be created and added to ItemView
385 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
386 view.ActivateLayout(0, stageSize, 0.5f);
388 // Get the item given the item ID 2 and 3
389 Actor oldItemActorID2 = view.GetItem(2);
390 Actor oldItemActorID3 = view.GetItem(3);
392 // Remove the item with ID 2
393 view.RemoveItem(2, 0.0f);
395 // Get the new item given the item ID 2 and 3
396 Actor newItemActorID2 = view.GetItem(2);
397 Actor newItemActorID3 = view.GetItem(3);
399 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
400 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
401 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
402 DALI_TEST_CHECK(newItemActorID2 == oldItemActorID3);
404 // scroll to the end of item view
405 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
407 application.SendNotification();
408 application.Render(0);
410 // Refresh the item view
413 Actor itemActorID390 = view.GetItem(390);
414 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
416 // Remove the item with ID 2 (which is now before the current item range)
417 view.RemoveItem(2, 0.0f);
419 // Check the original item with item ID 2 was deleted and now item ID 389 represents the original item with ID 390
420 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 389);
421 DALI_TEST_CHECK(view.GetItem(389) == itemActorID390);
426 int UtcDaliItemViewGetCurrentLayoutPosition(void)
428 ToolkitTestApplication application;
430 // Create the ItemView actor
431 TestItemFactory factory;
432 ItemView view = ItemView::New(factory);
434 // Create a depth layout and add it to ItemView
435 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
436 depthLayout->SetOrientation(ControlOrientation::Up);
437 view.AddLayout(*depthLayout);
439 // Activate the grid layout so that the items will be created and added to ItemView
440 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
441 view.ActivateLayout(0, stageSize, 0.0f);
443 // Check the current layout position for the 10th items is 9.0f
444 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
448 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
450 ToolkitTestApplication application;
452 // Create the ItemView actor
453 TestItemFactory factory;
454 ItemView view = ItemView::New(factory);
456 // Set the minimum swipe speed to be 1.5f
457 view.SetMinimumSwipeSpeed(1.5f);
459 // Check the minimum swipe speed is 1.5f
460 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
464 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
466 ToolkitTestApplication application;
468 // Create the ItemView actor
469 TestItemFactory factory;
470 ItemView view = ItemView::New(factory);
472 // Set the minimum swipe distance to be 2.5f
473 view.SetMinimumSwipeDistance(2.5f);
475 // Check the minimum swipe distance is 2.5f
476 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
480 int UtcDaliItemViewSetAndGetAnchoring(void)
482 ToolkitTestApplication application;
484 // Create the ItemView actor
485 TestItemFactory factory;
486 ItemView view = ItemView::New(factory);
488 // Disable the anchor animation
489 view.SetAnchoring(false);
491 // Check the anchor animation is disabled
492 DALI_TEST_CHECK(view.GetAnchoring() == false);
496 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
498 ToolkitTestApplication application;
500 // Create the ItemView actor
501 TestItemFactory factory;
502 ItemView view = ItemView::New(factory);
504 // Set the duration of anchor animation to be 1.5f
505 view.SetAnchoringDuration(1.5f);
507 // Check the duration of anchor animation is 1.5f
508 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
512 int UtcDaliItemViewSetAndGetRefreshInterval(void)
514 ToolkitTestApplication application;
516 // Create the ItemView actor
517 TestItemFactory factory;
518 ItemView view = ItemView::New(factory);
520 // Set the interval between refreshes to be 20
521 view.SetRefreshInterval(20);
525 // Check the interval between refreshes is 20
526 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
530 int UtcDaliItemViewScrollToItem(void)
532 ToolkitTestApplication application;
534 // Create the ItemView actor
535 TestItemFactory factory;
536 ItemView view = ItemView::New(factory);
537 Vector3 vec(480.0f, 800.0f, 0.0f);
538 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
540 view.SetProperty( Dali::Actor::Property::NAME,"view actor");
541 view.AddLayout(*layout);
542 view.SetProperty( Actor::Property::SIZE, vec );
544 Stage::GetCurrent().Add(view);
545 layout->SetOrientation(ControlOrientation::Down);
546 view.ActivateLayout(0, vec, 0.0f);
548 application.SendNotification();
549 application.Render(0);
552 for(int i = 0; i < 10; ++i)
554 application.Render(16); // 60hz frames
557 // Confirm: we have actors in the view.
558 std::vector<unsigned int> indices;
559 for(unsigned int i = 0; i < 10; i++)
561 Actor testActor = view.GetItem(i);
564 indices.push_back(i);
570 if (!indices.empty())
572 const unsigned int firstTargetIndex = indices[indices.size()-1];
573 // scroll to last item
574 view.ScrollToItem(firstTargetIndex, 0.00f);
575 for(int i = 0; i < 10; ++i)
577 application.Render(16); // 60hz frames
580 std::size_t moveCount = 0;
581 for(std::size_t i = 0; i < indices.size(); i++)
583 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
584 view.ScrollToItem(indices[i], 0.0f);
585 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
587 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
593 DALI_TEST_CHECK((moveCount == indices.size()));
598 tet_result(TET_FAIL);
601 Stage::GetCurrent().Remove(view);
605 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
607 ToolkitTestApplication application;
609 // Create the ItemView actor
610 TestItemFactory factory;
611 ItemView view = ItemView::New(factory);
613 // Set the scroll distance step for the wheel event to be 100.0f
614 view.SetWheelScrollDistanceStep(100.0f);
616 // Check the scroll distance step is 100.0f
617 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
621 int UtcDaliItemViewInsertItemP(void)
623 ToolkitTestApplication application;
625 // Create the ItemView actor
626 TestItemFactory factory;
627 ItemView view = ItemView::New(factory);
629 // Create a grid layout and add it to ItemView
630 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID);
631 gridLayout->SetOrientation(ControlOrientation::Left);
632 view.AddLayout(*gridLayout);
634 // Activate the grid layout so that the items will be created and added to ItemView
635 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
636 view.ActivateLayout(0, stageSize, 0.0f);
638 // Get the specified item where new item to be inserted before that
639 Actor itemActor = view.GetItem(2);
641 ItemId id = view.GetItemId( itemActor );
643 // Check we are getting the correct Item ID given the specified actor
644 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
646 Actor newActor = Actor::New();
648 view.InsertItem(Item(id, newActor), 0.0f);
650 DALI_TEST_CHECK(view.GetItem(2) == newActor);
652 DALI_TEST_CHECK(view.GetItemId(itemActor) == 3);
653 DALI_TEST_CHECK(view.GetItem(3) == itemActor);
655 // scroll to the end of item view
656 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
658 application.SendNotification();
659 application.Render(0);
661 // Refresh the item view
664 Actor itemActorID390 = view.GetItem(390);
665 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
667 // Insert the item with ID 2 (which is now before the current item range)
668 Actor anotherNewActor = Actor::New();
669 view.InsertItem(Item(id, anotherNewActor), 0.0f);
671 // Check that item ID 391 now represents the original item with ID 390
672 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 391);
673 DALI_TEST_CHECK(view.GetItem(391) == itemActorID390);
678 int UtcDaliItemViewInsertItemsP(void)
680 ToolkitTestApplication application;
682 // Create the ItemView actor
683 TestItemFactory factory;
684 ItemView view = ItemView::New(factory);
686 // Create a depth layout and add it to ItemView
687 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
688 depthLayout->SetOrientation(ControlOrientation::Right);
689 view.AddLayout(*depthLayout);
691 // Activate the grid layout so that the items will be created and added to ItemView
692 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
693 view.ActivateLayout(0, stageSize, 0.5f);
695 unsigned int itemCount = view.GetChildCount();
697 // Get the specified item where new items to be inserted before that
698 Actor itemActor = view.GetItem(1);
700 // Check we are getting the correct Item ID given the specified item
701 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
703 ItemContainer insertList;
705 for( unsigned int i = 1u; i < 11; ++i )
707 Actor child = view.GetChildAt( i );
708 Actor newActor = Actor::New();
709 newActor.SetProperty( Dali::Actor::Property::NAME,"Inserted");
710 insertList.push_back( Item( view.GetItemId(child), newActor ) );
713 if( !insertList.empty() )
715 view.InsertItems( insertList, 0.5f );
718 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
720 // Check that new items are inserted in the correct positions
721 DALI_TEST_CHECK(view.GetItemId(itemActor) == 11);
722 DALI_TEST_CHECK(view.GetItem(11) == itemActor);
724 ItemIdContainer removeList;
726 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
728 Actor child = view.GetChildAt( i );
730 if( child.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Inserted" )
732 removeList.push_back( view.GetItemId(child) );
736 if( ! removeList.empty() )
738 view.RemoveItems( removeList, 0.5f );
741 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
743 // Check that new items are removed correctly so that we are getting the correct Item ID given the specified item
744 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
745 DALI_TEST_CHECK(view.GetItem(1) == itemActor);
750 int UtcDaliItemViewReplaceItemP(void)
752 ToolkitTestApplication application;
754 // Create the ItemView actor
755 TestItemFactory factory;
756 ItemView view = ItemView::New(factory);
758 // Create a spiral layout and add it to ItemView
759 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
760 view.AddLayout(*spiralLayout);
762 // Activate the grid layout so that the items will be created and added to ItemView
763 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
764 view.ActivateLayout(0, stageSize, 0.5f);
766 Actor newActor = Actor::New();
768 view.ReplaceItem( Item( 5, newActor ), 0.5f );
770 DALI_TEST_CHECK(view.GetItem(5) == newActor);
775 int UtcDaliItemViewReplaceItemsP(void)
777 ToolkitTestApplication application;
779 // Create the ItemView actor
780 TestItemFactory factory;
781 ItemView view = ItemView::New(factory);
783 // Create a spiral layout and add it to ItemView
784 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
785 spiralLayout->SetOrientation( ControlOrientation::Down );
786 view.AddLayout(*spiralLayout);
788 // Activate the grid layout so that the items will be created and added to ItemView
789 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
790 view.ActivateLayout(0, stageSize, 0.5f);
792 ItemContainer replaceList;
794 for( unsigned int i = 0u; i < 10; ++i )
796 Actor child = view.GetItem( i );
797 Actor newActor = Actor::New();
798 newActor.SetProperty( Dali::Actor::Property::NAME,"Replaced");
800 replaceList.push_back( Item( i, newActor ) );
803 if( !replaceList.empty() )
805 view.ReplaceItems( replaceList, 0.5f );
808 DALI_TEST_CHECK(view.GetItem(0).GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Replaced");
809 DALI_TEST_CHECK(view.GetItem(8).GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Replaced");
813 int UtcDaliItemViewGetItemsRangeP(void)
815 ToolkitTestApplication application;
817 // Create the ItemView actor
818 TestItemFactory factory;
819 ItemView view = ItemView::New(factory);
821 // Create a spiral layout and add it to ItemView
822 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
823 spiralLayout->SetOrientation( ControlOrientation::Left );
824 view.AddLayout(*spiralLayout);
826 // Activate the grid layout so that the items will be created and added to ItemView
827 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
828 view.ActivateLayout(0, stageSize, 0.5f);
830 ItemRange itemRange(0, 0);
832 view.GetItemsRange(itemRange);
834 DALI_TEST_CHECK(itemRange.Within(0));
838 int UtcDaliItemViewSetItemsAnchorPointP(void)
840 ToolkitTestApplication application;
842 // Create the ItemView actor
843 TestItemFactory factory;
844 ItemView view = ItemView::New(factory);
846 // Create a spiral layout and add it to ItemView
847 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
848 spiralLayout->SetOrientation( ControlOrientation::Right );
849 view.AddLayout(*spiralLayout);
851 // Activate the grid layout so that the items will be created and added to ItemView
852 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
853 view.ActivateLayout(0, stageSize, 0.5f);
855 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
857 view.SetItemsAnchorPoint(anchorPoint);
859 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
860 DALI_TEST_CHECK(view.GetItem(0).GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) == anchorPoint);
864 int UtcDaliItemViewSetItemsParentOriginP(void)
866 ToolkitTestApplication application;
868 // Create the ItemView actor
869 TestItemFactory factory;
870 ItemView view = ItemView::New(factory);
872 // Create a grid layout and add it to ItemView
873 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
874 view.AddLayout(*gridLayout);
876 // Activate the grid layout so that the items will be created and added to ItemView
877 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
878 view.ActivateLayout(0, stageSize, 0.5f);
880 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
882 view.SetItemsParentOrigin(parentOrigin);
884 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
885 DALI_TEST_CHECK(view.GetItem(0).GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ) == parentOrigin);
889 int UtcDaliItemFactoryGetExtention(void)
891 ToolkitTestApplication application;
892 TestItemFactory factory;
893 DALI_TEST_CHECK( factory.GetExtension() == NULL );
897 int UtcDaliItemViewLayoutActivatedSignalP(void)
899 ToolkitTestApplication application;
901 // Create the ItemView actor
902 TestItemFactory factory;
903 ItemView view = ItemView::New(factory);
905 // Create a grid layout and add it to ItemView
906 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
907 view.AddLayout(*gridLayout);
909 Stage::GetCurrent().Add( view );
911 // Connect the layout activated signal
912 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
914 gOnLayoutActivatedCalled = false;
917 application.SendNotification();
918 application.Render();
920 // Activate the grid layout so that the items will be created and added to ItemView
921 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
922 view.ActivateLayout(0, stageSize, 0.1f);
924 // Wait for 0.1 second
925 Wait(application, 100);
927 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
932 int UtcDaliItemViewSetGetProperty(void)
934 ToolkitTestApplication application;
936 // Create the ItemView actor
937 TestItemFactory factory;
938 ItemView view = ItemView::New(factory);
939 DALI_TEST_CHECK(view);
941 // Event side properties
943 // Test "minimumSwipeSpeed" property
944 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
945 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
946 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
947 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
949 // Test "minimumSwipeDistance" property
950 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
951 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
952 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
953 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
955 // Test "wheelScrollDistanceStep" property
956 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
957 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
958 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
959 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
961 // Test "snapToItemEnabled" property
962 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
963 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
964 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
965 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
967 // Test "refreshInterval" property
968 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
969 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
970 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
971 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
973 // Test "layout" property
974 DALI_TEST_CHECK( view.GetPropertyIndex("layout") == ItemView::Property::LAYOUT );
975 Property::Map gridLayoutProperty;
976 gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
977 gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
978 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
979 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
981 Property::Map depthLayoutProperty;
982 depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
983 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
984 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
986 Property::Map spiralLayoutPrperty;
987 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
988 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
989 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
991 Property::Map listLayoutPrperty;
992 listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
993 listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
996 Property::Array layoutArray;
997 layoutArray.PushBack(gridLayoutProperty);
998 layoutArray.PushBack(depthLayoutProperty);
999 layoutArray.PushBack(spiralLayoutPrperty);
1000 layoutArray.PushBack(listLayoutPrperty);
1002 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1004 Property::Array getLayoutArray;
1005 DALI_TEST_CHECK( view.GetProperty( ItemView::Property::LAYOUT ).Get( getLayoutArray ) );
1007 //Check that the result is the same as
1008 DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
1009 Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
1011 for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
1013 KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
1014 if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
1016 int layoutType = propertyPair.second.Get<int>();
1017 DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
1019 else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
1021 Vector3 size = propertyPair.second.Get<Vector3>();
1022 DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
1024 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
1026 float spacing = propertyPair.second.Get<float>();
1027 DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
1029 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1031 int number = propertyPair.second.Get<int>();
1032 DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1035 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1038 // Test "overshootEnabled" property
1039 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
1040 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1041 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1042 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1044 // Test "overshootSize" property
1045 DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE );
1046 Vector2 overshootSize = Vector2(100.0f,100.0f);
1047 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
1048 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
1050 // Animatable properties
1052 // Test "layoutPosition" property
1053 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
1054 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1056 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1058 // Test "scrollSpeed" property
1059 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
1060 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1062 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1064 // Test "overshoot" property
1065 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
1066 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1068 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1070 // Test "scrollDirection" property
1071 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
1072 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1074 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1076 // Test "layoutOrientation" property
1077 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
1078 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1080 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1082 // Test "scrollContentSize" property
1083 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
1084 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1086 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1092 int UtcDaliItemViewOvershootVertical(void)
1094 ToolkitTestApplication application;
1095 Dali::Stage stage = Dali::Stage::GetCurrent();
1097 // Create the ItemView actor
1098 TestItemFactory factory;
1099 ItemView view = ItemView::New(factory);
1101 // Create a grid layout and add it to ItemView
1102 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1103 view.AddLayout(*gridLayout);
1106 // Activate the grid layout so that the items will be created and added to ItemView
1107 Vector3 stageSize(stage.GetSize());
1108 view.ActivateLayout(0, stageSize, 0.5f);
1110 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1111 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1113 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1117 // Do a pan starting from 100,100 and moving down
1118 Vector2 pos(100.0f, 100.0f);
1120 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1121 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1124 Wait(application, 100);
1126 for(int i = 0;i<200;i++)
1128 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1133 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1135 Wait(application, 100);
1137 // Do a pan starting from 100,100 and moving up
1138 pos = Vector2(100.0f, 300.0f);
1140 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1141 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1144 Wait(application, 100);
1146 for(int i = 0;i<200;i++)
1148 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1153 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1154 Wait(application, 100);
1158 int UtcDaliItemViewOvershootHorizontal(void)
1160 ToolkitTestApplication application;
1161 Dali::Stage stage = Dali::Stage::GetCurrent();
1163 // Create the ItemView actor
1164 TestItemFactory factory;
1165 ItemView view = ItemView::New(factory);
1167 // Create a grid layout and add it to ItemView
1168 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1169 view.AddLayout(*gridLayout);
1172 // Activate the grid layout so that the items will be created and added to ItemView
1173 Vector3 stageSize(stage.GetSize());
1174 view.ActivateLayout(0, stageSize, 0.5f);
1176 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1177 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1179 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1183 // Do a pan starting from 100,100 and moving left
1184 Vector2 pos(100.0f, 100.0f);
1185 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ));
1186 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ));
1188 Wait(application, 100);
1190 for(int i = 0;i<200;i++)
1192 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1197 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1198 Wait(application, 100);
1200 // Do a pan starting from 100,100 and moving right
1201 pos = Vector2(100.0f, 100.0f);
1202 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1203 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1205 Wait(application, 100);
1207 for(int i = 0;i<200;i++)
1209 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1214 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1215 Wait(application, 100);
1220 int UtcDaliItemEnableDisableRefresh(void)
1222 ToolkitTestApplication application;
1223 Dali::Stage stage = Dali::Stage::GetCurrent();
1225 // Create the ItemView actor
1226 TestItemFactory factory;
1227 ItemView view = ItemView::New(factory);
1229 // Create a grid layout and add it to ItemView
1230 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1231 view.AddLayout(*gridLayout);
1234 // Activate the grid layout so that the items will be created and added to ItemView
1235 Vector3 stageSize(stage.GetSize());
1236 view.ActivateLayout(0, stageSize, 0.5f);
1238 //Connect to signal scroll updated
1239 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1241 Property::Map attributes;
1242 view.DoAction("enableRefresh", attributes );
1243 gOnScrollUpdateCalled = true;
1244 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1245 application.SendNotification();
1246 application.Render(1000);
1247 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1250 view.DoAction("disableRefresh", attributes );
1251 gOnScrollUpdateCalled = false;
1252 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1253 application.SendNotification();
1254 application.Render(1000);
1256 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );