2 * Copyright (c) 2020 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 return ImageView::New( TEST_IMAGE_FILE_NAME );
145 int UtcDaliItemViewNew(void)
147 ToolkitTestApplication application;
149 // Create the ItemView actor
150 TestItemFactory factory;
151 ItemView view = ItemView::New(factory);
153 DALI_TEST_CHECK(view);
155 //Additional check to ensure object is created by checking if it's registered
156 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
157 DALI_TEST_CHECK( registry );
159 gObjectCreatedCallBackCalled = false;
160 registry.ObjectCreatedSignal().Connect(&TestCallback);
162 TestItemFactory factory;
163 ItemView view = ItemView::New(factory);
165 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
169 int UtcDaliItemViewDownCast(void)
171 ToolkitTestApplication application;
173 // Create the ItemView actor
174 TestItemFactory factory;
175 const ItemView itemViewConst = ItemView::New(factory);
176 ItemView itemView(itemViewConst);
178 BaseHandle handle(itemView);
180 ItemView newItemView = ItemView::DownCast( handle );
181 DALI_TEST_CHECK( itemView );
182 DALI_TEST_CHECK( newItemView == itemView );
186 int UtcDaliItemViewAddAndGetLayout(void)
188 ToolkitTestApplication application;
190 // Create the ItemView actor
191 TestItemFactory factory;
192 ItemView view = ItemView::New(factory);
194 // Create a grid layout and add it to ItemView
195 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
196 view.AddLayout(*gridLayout);
198 // As we have added one layout, check the number of layout is now 1
199 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
201 // Create a depth layout and add it to ItemView
202 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
203 view.AddLayout(*depthLayout);
205 // As we have added another layout, check the number of layout is now 2
206 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
208 // Create a spiral layout and add it to ItemView
209 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
210 view.AddLayout(*spiralLayout);
212 // As we have added another layout, check the number of layout is now 3
213 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
215 // Check we are getting the correct layout from ItemView
216 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
217 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
218 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
222 int UtcDaliItemViewAddAndRemoveLayout(void)
224 ToolkitTestApplication application;
226 // Create the ItemView actor
227 TestItemFactory factory;
228 ItemView view = ItemView::New(factory);
230 // Create a grid layout and add it to ItemView
231 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
232 view.AddLayout(*gridLayout);
234 // As we have added one layout, check the number of layout is now 1
235 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
237 // Create a depth layout and add it to ItemView
238 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
239 view.AddLayout(*depthLayout);
241 // As we have added another layout, check the number of layout is now 2
242 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
244 // Check we are getting the correct layout from ItemView
245 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
246 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
248 // Remove the grid layout
249 view.RemoveLayout(0);
251 // As we have removed the grid layout, check the number of layout is now 1
252 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
254 // Check we are getting the correct layout from ItemView
255 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
257 // Remove the depth layout
258 view.RemoveLayout(0);
260 // As we also removed the depth layout, check the number of layout is now 0
261 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
265 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
267 ToolkitTestApplication application;
269 // Create the ItemView actor
270 TestItemFactory factory;
271 ItemView view = ItemView::New(factory);
273 // Create a grid layout and add it to ItemView
274 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
275 view.AddLayout(*gridLayout);
277 // Create a depth layout and add it to ItemView
278 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
279 view.AddLayout(*depthLayout);
281 // Create a spiral layout and add it to ItemView
282 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
283 view.AddLayout(*spiralLayout);
285 // As we have added three layouts, check the number of layout is now 3
286 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
288 // Check there is no active layout at the moment
289 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
291 // Activate the depth layout
292 Vector3 stageSize(application.GetScene().GetSize());
293 view.ActivateLayout(1, stageSize, 0.5f);
295 // Check the current active layout is the depth layout
296 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
298 // Activate the grid layout
299 view.ActivateLayout(0, stageSize, 0.5f);
301 // Check the current active layout is the grid layout
302 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
304 // Activate the spiral layout
305 view.ActivateLayout(2, stageSize, 0.5f);
307 // Check the current active layout is the spiral layout
308 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
312 int UtcDaliItemViewDeactivateCurrentLayout(void)
314 ToolkitTestApplication application;
316 // Create the ItemView actor
317 TestItemFactory factory;
318 ItemView view = ItemView::New(factory);
320 // Create a grid layout and add it to ItemView
321 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
322 gridLayout->SetOrientation(ControlOrientation::Down);
323 view.AddLayout(*gridLayout);
325 // Check there is no active layout at the moment
326 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
328 // Activate the grid layout
329 Vector3 stageSize(application.GetScene().GetSize());
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 // Deactivate the current layout
336 view.DeactivateCurrentLayout();
338 // Check there is no active layout at the moment
339 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
343 int UtcDaliItemViewGetItemAndGetItemId(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::Left);
354 view.AddLayout(*gridLayout);
356 // Activate the grid layout so that the items will be created and added to ItemView
357 Vector3 stageSize(application.GetScene().GetSize());
358 view.ActivateLayout(0, stageSize, 0.5f);
360 // Get the item given the item ID
361 Actor itemActor = view.GetItem(2);
363 // Check we are getting the correct Item ID given the specified actor
364 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
368 int UtcDaliItemViewRemoveItem(void)
370 ToolkitTestApplication application;
372 // Create the ItemView actor
373 TestItemFactory factory;
374 ItemView view = ItemView::New(factory);
376 // Create a grid layout and add it to ItemView
377 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
378 gridLayout->SetOrientation(ControlOrientation::Right);
379 view.AddLayout(*gridLayout);
381 // Activate the grid layout so that the items will be created and added to ItemView
382 Vector3 stageSize(application.GetScene().GetSize());
383 view.ActivateLayout(0, stageSize, 0.5f);
385 // Get the item given the item ID 2 and 3
386 Actor oldItemActorID2 = view.GetItem(2);
387 Actor oldItemActorID3 = view.GetItem(3);
389 // Remove the item with ID 2
390 view.RemoveItem(2, 0.0f);
392 // Get the new item given the item ID 2 and 3
393 Actor newItemActorID2 = view.GetItem(2);
394 Actor newItemActorID3 = view.GetItem(3);
396 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
397 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
398 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
399 DALI_TEST_CHECK(newItemActorID2 == oldItemActorID3);
401 // scroll to the end of item view
402 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
404 application.SendNotification();
405 application.Render(0);
407 // Refresh the item view
410 Actor itemActorID390 = view.GetItem(390);
411 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
413 // Remove the item with ID 2 (which is now before the current item range)
414 view.RemoveItem(2, 0.0f);
416 // Check the original item with item ID 2 was deleted and now item ID 389 represents the original item with ID 390
417 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 389);
418 DALI_TEST_CHECK(view.GetItem(389) == itemActorID390);
423 int UtcDaliItemViewGetCurrentLayoutPosition(void)
425 ToolkitTestApplication application;
427 // Create the ItemView actor
428 TestItemFactory factory;
429 ItemView view = ItemView::New(factory);
431 // Create a depth layout and add it to ItemView
432 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
433 depthLayout->SetOrientation(ControlOrientation::Up);
434 view.AddLayout(*depthLayout);
436 // Activate the grid layout so that the items will be created and added to ItemView
437 Vector3 stageSize(application.GetScene().GetSize());
438 view.ActivateLayout(0, stageSize, 0.0f);
440 // Check the current layout position for the 10th items is 9.0f
441 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
445 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
447 ToolkitTestApplication application;
449 // Create the ItemView actor
450 TestItemFactory factory;
451 ItemView view = ItemView::New(factory);
453 // Set the minimum swipe speed to be 1.5f
454 view.SetMinimumSwipeSpeed(1.5f);
456 // Check the minimum swipe speed is 1.5f
457 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
461 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
463 ToolkitTestApplication application;
465 // Create the ItemView actor
466 TestItemFactory factory;
467 ItemView view = ItemView::New(factory);
469 // Set the minimum swipe distance to be 2.5f
470 view.SetMinimumSwipeDistance(2.5f);
472 // Check the minimum swipe distance is 2.5f
473 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
477 int UtcDaliItemViewSetAndGetAnchoring(void)
479 ToolkitTestApplication application;
481 // Create the ItemView actor
482 TestItemFactory factory;
483 ItemView view = ItemView::New(factory);
485 // Disable the anchor animation
486 view.SetAnchoring(false);
488 // Check the anchor animation is disabled
489 DALI_TEST_CHECK(view.GetAnchoring() == false);
493 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
495 ToolkitTestApplication application;
497 // Create the ItemView actor
498 TestItemFactory factory;
499 ItemView view = ItemView::New(factory);
501 // Set the duration of anchor animation to be 1.5f
502 view.SetAnchoringDuration(1.5f);
504 // Check the duration of anchor animation is 1.5f
505 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
509 int UtcDaliItemViewSetAndGetRefreshInterval(void)
511 ToolkitTestApplication application;
513 // Create the ItemView actor
514 TestItemFactory factory;
515 ItemView view = ItemView::New(factory);
517 // Set the interval between refreshes to be 20
518 view.SetRefreshInterval(20);
522 // Check the interval between refreshes is 20
523 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
527 int UtcDaliItemViewScrollToItem(void)
529 ToolkitTestApplication application;
531 // Create the ItemView actor
532 TestItemFactory factory;
533 ItemView view = ItemView::New(factory);
534 Vector3 vec(480.0f, 800.0f, 0.0f);
535 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
537 view.SetProperty( Dali::Actor::Property::NAME,"view actor");
538 view.AddLayout(*layout);
539 view.SetProperty( Actor::Property::SIZE, vec );
541 application.GetScene().Add(view);
542 layout->SetOrientation(ControlOrientation::Down);
543 view.ActivateLayout(0, vec, 0.0f);
545 application.SendNotification();
546 application.Render(0);
549 for(int i = 0; i < 10; ++i)
551 application.Render(16); // 60hz frames
554 // Confirm: we have actors in the view.
555 std::vector<unsigned int> indices;
556 for(unsigned int i = 0; i < 10; i++)
558 Actor testActor = view.GetItem(i);
561 indices.push_back(i);
567 if (!indices.empty())
569 const unsigned int firstTargetIndex = indices[indices.size()-1];
570 // scroll to last item
571 view.ScrollToItem(firstTargetIndex, 0.00f);
572 for(int i = 0; i < 10; ++i)
574 application.Render(16); // 60hz frames
577 std::size_t moveCount = 0;
578 for(std::size_t i = 0; i < indices.size(); i++)
580 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
581 view.ScrollToItem(indices[i], 0.0f);
582 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
584 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
590 DALI_TEST_CHECK((moveCount == indices.size()));
595 tet_result(TET_FAIL);
598 application.GetScene().Remove(view);
602 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
604 ToolkitTestApplication application;
606 // Create the ItemView actor
607 TestItemFactory factory;
608 ItemView view = ItemView::New(factory);
610 // Set the scroll distance step for the wheel event to be 100.0f
611 view.SetWheelScrollDistanceStep(100.0f);
613 // Check the scroll distance step is 100.0f
614 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
618 int UtcDaliItemViewInsertItemP(void)
620 ToolkitTestApplication application;
622 // Create the ItemView actor
623 TestItemFactory factory;
624 ItemView view = ItemView::New(factory);
626 // Create a grid layout and add it to ItemView
627 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID);
628 gridLayout->SetOrientation(ControlOrientation::Left);
629 view.AddLayout(*gridLayout);
631 // Activate the grid layout so that the items will be created and added to ItemView
632 Vector3 stageSize(application.GetScene().GetSize());
633 view.ActivateLayout(0, stageSize, 0.0f);
635 // Get the specified item where new item to be inserted before that
636 Actor itemActor = view.GetItem(2);
638 ItemId id = view.GetItemId( itemActor );
640 // Check we are getting the correct Item ID given the specified actor
641 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
643 Actor newActor = Actor::New();
645 view.InsertItem(Item(id, newActor), 0.0f);
647 DALI_TEST_CHECK(view.GetItem(2) == newActor);
649 DALI_TEST_CHECK(view.GetItemId(itemActor) == 3);
650 DALI_TEST_CHECK(view.GetItem(3) == itemActor);
652 // scroll to the end of item view
653 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
655 application.SendNotification();
656 application.Render(0);
658 // Refresh the item view
661 Actor itemActorID390 = view.GetItem(390);
662 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
664 // Insert the item with ID 2 (which is now before the current item range)
665 Actor anotherNewActor = Actor::New();
666 view.InsertItem(Item(id, anotherNewActor), 0.0f);
668 // Check that item ID 391 now represents the original item with ID 390
669 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 391);
670 DALI_TEST_CHECK(view.GetItem(391) == itemActorID390);
675 int UtcDaliItemViewInsertItemsP(void)
677 ToolkitTestApplication application;
679 // Create the ItemView actor
680 TestItemFactory factory;
681 ItemView view = ItemView::New(factory);
683 // Create a depth layout and add it to ItemView
684 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
685 depthLayout->SetOrientation(ControlOrientation::Right);
686 view.AddLayout(*depthLayout);
688 // Activate the grid layout so that the items will be created and added to ItemView
689 Vector3 stageSize(application.GetScene().GetSize());
690 view.ActivateLayout(0, stageSize, 0.5f);
692 unsigned int itemCount = view.GetChildCount();
694 // Get the specified item where new items to be inserted before that
695 Actor itemActor = view.GetItem(1);
697 // Check we are getting the correct Item ID given the specified item
698 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
700 ItemContainer insertList;
702 for( unsigned int i = 1u; i < 11; ++i )
704 Actor child = view.GetChildAt( i );
705 Actor newActor = Actor::New();
706 newActor.SetProperty( Dali::Actor::Property::NAME,"Inserted");
707 insertList.push_back( Item( view.GetItemId(child), newActor ) );
710 if( !insertList.empty() )
712 view.InsertItems( insertList, 0.5f );
715 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
717 // Check that new items are inserted in the correct positions
718 DALI_TEST_CHECK(view.GetItemId(itemActor) == 11);
719 DALI_TEST_CHECK(view.GetItem(11) == itemActor);
721 ItemIdContainer removeList;
723 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
725 Actor child = view.GetChildAt( i );
727 if( child.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Inserted" )
729 removeList.push_back( view.GetItemId(child) );
733 if( ! removeList.empty() )
735 view.RemoveItems( removeList, 0.5f );
738 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
740 // Check that new items are removed correctly so that we are getting the correct Item ID given the specified item
741 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
742 DALI_TEST_CHECK(view.GetItem(1) == itemActor);
747 int UtcDaliItemViewReplaceItemP(void)
749 ToolkitTestApplication application;
751 // Create the ItemView actor
752 TestItemFactory factory;
753 ItemView view = ItemView::New(factory);
755 // Create a spiral layout and add it to ItemView
756 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
757 view.AddLayout(*spiralLayout);
759 // Activate the grid layout so that the items will be created and added to ItemView
760 Vector3 stageSize(application.GetScene().GetSize());
761 view.ActivateLayout(0, stageSize, 0.5f);
763 Actor newActor = Actor::New();
765 view.ReplaceItem( Item( 5, newActor ), 0.5f );
767 DALI_TEST_CHECK(view.GetItem(5) == newActor);
772 int UtcDaliItemViewReplaceItemsP(void)
774 ToolkitTestApplication application;
776 // Create the ItemView actor
777 TestItemFactory factory;
778 ItemView view = ItemView::New(factory);
780 // Create a spiral layout and add it to ItemView
781 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
782 spiralLayout->SetOrientation( ControlOrientation::Down );
783 view.AddLayout(*spiralLayout);
785 // Activate the grid layout so that the items will be created and added to ItemView
786 Vector3 stageSize(application.GetScene().GetSize());
787 view.ActivateLayout(0, stageSize, 0.5f);
789 ItemContainer replaceList;
791 for( unsigned int i = 0u; i < 10; ++i )
793 Actor child = view.GetItem( i );
794 Actor newActor = Actor::New();
795 newActor.SetProperty( Dali::Actor::Property::NAME,"Replaced");
797 replaceList.push_back( Item( i, newActor ) );
800 if( !replaceList.empty() )
802 view.ReplaceItems( replaceList, 0.5f );
805 DALI_TEST_CHECK(view.GetItem(0).GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Replaced");
806 DALI_TEST_CHECK(view.GetItem(8).GetProperty< std::string >( Dali::Actor::Property::NAME ) == "Replaced");
810 int UtcDaliItemViewGetItemsRangeP(void)
812 ToolkitTestApplication application;
814 // Create the ItemView actor
815 TestItemFactory factory;
816 ItemView view = ItemView::New(factory);
818 // Create a spiral layout and add it to ItemView
819 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
820 spiralLayout->SetOrientation( ControlOrientation::Left );
821 view.AddLayout(*spiralLayout);
823 // Activate the grid layout so that the items will be created and added to ItemView
824 Vector3 stageSize(application.GetScene().GetSize());
825 view.ActivateLayout(0, stageSize, 0.5f);
827 ItemRange itemRange(0, 0);
829 view.GetItemsRange(itemRange);
831 DALI_TEST_CHECK(itemRange.Within(0));
835 int UtcDaliItemViewSetItemsAnchorPointP(void)
837 ToolkitTestApplication application;
839 // Create the ItemView actor
840 TestItemFactory factory;
841 ItemView view = ItemView::New(factory);
843 // Create a spiral layout and add it to ItemView
844 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
845 spiralLayout->SetOrientation( ControlOrientation::Right );
846 view.AddLayout(*spiralLayout);
848 // Activate the grid layout so that the items will be created and added to ItemView
849 Vector3 stageSize(application.GetScene().GetSize());
850 view.ActivateLayout(0, stageSize, 0.5f);
852 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
854 view.SetItemsAnchorPoint(anchorPoint);
856 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
857 DALI_TEST_CHECK(view.GetItem(0).GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) == anchorPoint);
861 int UtcDaliItemViewSetItemsParentOriginP(void)
863 ToolkitTestApplication application;
865 // Create the ItemView actor
866 TestItemFactory factory;
867 ItemView view = ItemView::New(factory);
869 // Create a grid layout and add it to ItemView
870 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
871 view.AddLayout(*gridLayout);
873 // Activate the grid layout so that the items will be created and added to ItemView
874 Vector3 stageSize(application.GetScene().GetSize());
875 view.ActivateLayout(0, stageSize, 0.5f);
877 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
879 view.SetItemsParentOrigin(parentOrigin);
881 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
882 DALI_TEST_CHECK(view.GetItem(0).GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ) == parentOrigin);
886 int UtcDaliItemFactoryGetExtention(void)
888 ToolkitTestApplication application;
889 TestItemFactory factory;
890 DALI_TEST_CHECK( factory.GetExtension() == NULL );
894 int UtcDaliItemViewLayoutActivatedSignalP(void)
896 ToolkitTestApplication application;
898 // Create the ItemView actor
899 TestItemFactory factory;
900 ItemView view = ItemView::New(factory);
902 // Create a grid layout and add it to ItemView
903 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
904 view.AddLayout(*gridLayout);
906 application.GetScene().Add( view );
908 // Connect the layout activated signal
909 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
911 gOnLayoutActivatedCalled = false;
914 application.SendNotification();
915 application.Render();
917 // Activate the grid layout so that the items will be created and added to ItemView
918 Vector3 stageSize(application.GetScene().GetSize());
919 view.ActivateLayout(0, stageSize, 0.1f);
921 // Wait for 0.1 second
922 Wait(application, 100);
924 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
929 int UtcDaliItemViewSetGetProperty(void)
931 ToolkitTestApplication application;
933 // Create the ItemView actor
934 TestItemFactory factory;
935 ItemView view = ItemView::New(factory);
936 DALI_TEST_CHECK(view);
938 // Event side properties
940 // Test "minimumSwipeSpeed" property
941 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
942 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
943 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
944 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
946 // Test "minimumSwipeDistance" property
947 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
948 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
949 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
950 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
952 // Test "wheelScrollDistanceStep" property
953 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
954 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
955 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
956 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
958 // Test "snapToItemEnabled" property
959 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
960 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
961 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
962 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
964 // Test "refreshInterval" property
965 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
966 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
967 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
968 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
970 // Test "layout" property
971 DALI_TEST_CHECK( view.GetPropertyIndex("layout") == ItemView::Property::LAYOUT );
972 Property::Map gridLayoutProperty;
973 gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
974 gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
975 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
976 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
978 Property::Map depthLayoutProperty;
979 depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
980 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
981 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
983 Property::Map spiralLayoutPrperty;
984 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
985 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
986 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
988 Property::Map listLayoutPrperty;
989 listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
990 listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
993 Property::Array layoutArray;
994 layoutArray.PushBack(gridLayoutProperty);
995 layoutArray.PushBack(depthLayoutProperty);
996 layoutArray.PushBack(spiralLayoutPrperty);
997 layoutArray.PushBack(listLayoutPrperty);
999 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1001 Property::Array getLayoutArray;
1002 DALI_TEST_CHECK( view.GetProperty( ItemView::Property::LAYOUT ).Get( getLayoutArray ) );
1004 //Check that the result is the same as
1005 DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
1006 Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
1008 for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
1010 KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
1011 if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
1013 int layoutType = propertyPair.second.Get<int>();
1014 DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
1016 else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
1018 Vector3 size = propertyPair.second.Get<Vector3>();
1019 DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
1021 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
1023 float spacing = propertyPair.second.Get<float>();
1024 DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
1026 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1028 int number = propertyPair.second.Get<int>();
1029 DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1032 view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1035 // Test "overshootEnabled" property
1036 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
1037 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1038 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1039 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1041 // Test "overshootSize" property
1042 DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE );
1043 Vector2 overshootSize = Vector2(100.0f,100.0f);
1044 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
1045 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
1047 // Animatable properties
1049 // Test "layoutPosition" property
1050 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
1051 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1053 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1055 // Test "scrollSpeed" property
1056 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
1057 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1059 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1061 // Test "overshoot" property
1062 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
1063 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1065 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1067 // Test "scrollDirection" property
1068 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
1069 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1071 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1073 // Test "layoutOrientation" property
1074 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
1075 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1077 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1079 // Test "scrollContentSize" property
1080 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
1081 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1083 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1089 int UtcDaliItemViewOvershootVertical(void)
1091 ToolkitTestApplication application;
1092 Dali::Integration::Scene stage = application.GetScene();
1094 // Create the ItemView actor
1095 TestItemFactory factory;
1096 ItemView view = ItemView::New(factory);
1098 // Create a grid layout and add it to ItemView
1099 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1100 view.AddLayout(*gridLayout);
1103 // Activate the grid layout so that the items will be created and added to ItemView
1104 Vector3 stageSize(stage.GetSize());
1105 view.ActivateLayout(0, stageSize, 0.5f);
1107 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1108 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1110 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1114 // Do a pan starting from 100,100 and moving down
1115 Vector2 pos(100.0f, 100.0f);
1117 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1118 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1121 Wait(application, 100);
1123 for(int i = 0;i<200;i++)
1125 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1130 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1132 Wait(application, 100);
1134 // Do a pan starting from 100,100 and moving up
1135 pos = Vector2(100.0f, 300.0f);
1137 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1138 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1141 Wait(application, 100);
1143 for(int i = 0;i<200;i++)
1145 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1150 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1151 Wait(application, 100);
1155 int UtcDaliItemViewOvershootHorizontal(void)
1157 ToolkitTestApplication application;
1158 Dali::Integration::Scene stage = application.GetScene();
1160 // Create the ItemView actor
1161 TestItemFactory factory;
1162 ItemView view = ItemView::New(factory);
1164 // Create a grid layout and add it to ItemView
1165 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1166 view.AddLayout(*gridLayout);
1169 // Activate the grid layout so that the items will be created and added to ItemView
1170 Vector3 stageSize(stage.GetSize());
1171 view.ActivateLayout(0, stageSize, 0.5f);
1173 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1174 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1176 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1180 // Do a pan starting from 100,100 and moving left
1181 Vector2 pos(100.0f, 100.0f);
1182 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ));
1183 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ));
1185 Wait(application, 100);
1187 for(int i = 0;i<200;i++)
1189 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1194 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1195 Wait(application, 100);
1197 // Do a pan starting from 100,100 and moving right
1198 pos = Vector2(100.0f, 100.0f);
1199 application.ProcessEvent( GenerateSingleTouch(PointState::DOWN, pos, 100 ) );
1200 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1202 Wait(application, 100);
1204 for(int i = 0;i<200;i++)
1206 application.ProcessEvent( GenerateSingleTouch(PointState::MOTION, pos, 100 ) );
1211 application.ProcessEvent( GenerateSingleTouch(PointState::UP, pos, 100 ) );
1212 Wait(application, 100);
1217 int UtcDaliItemEnableDisableRefresh(void)
1219 ToolkitTestApplication application;
1220 Dali::Integration::Scene stage = application.GetScene();
1222 // Create the ItemView actor
1223 TestItemFactory factory;
1224 ItemView view = ItemView::New(factory);
1226 // Create a grid layout and add it to ItemView
1227 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1228 view.AddLayout(*gridLayout);
1231 // Activate the grid layout so that the items will be created and added to ItemView
1232 Vector3 stageSize(stage.GetSize());
1233 view.ActivateLayout(0, stageSize, 0.5f);
1235 //Connect to signal scroll updated
1236 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1238 Property::Map attributes;
1239 view.DoAction("enableRefresh", attributes );
1240 gOnScrollUpdateCalled = true;
1241 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1242 application.SendNotification();
1243 application.Render(1000);
1244 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1247 view.DoAction("disableRefresh", attributes );
1248 gOnScrollUpdateCalled = false;
1249 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1250 application.SendNotification();
1251 application.Render(1000);
1253 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );