2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <float.h> // for FLT_MAX
22 // Need to override adaptor classes for toolkit test harness, so include
23 // test harness headers before dali headers.
24 #include <dali-toolkit-test-suite-utils.h>
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>
28 #include <dali-toolkit/devel-api/controls/scrollable/item-view/default-item-layout-property.h>
29 #include <dali-toolkit/devel-api/controls/scrollable/item-view/item-view-devel.h>
33 using namespace Toolkit;
35 void utc_dali_toolkit_item_view_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_toolkit_item_view_cleanup(void)
42 test_return_value = TET_PASS;
48 const unsigned int TOTAL_ITEM_NUMBER = 100;
49 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
51 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
53 static bool gObjectCreatedCallBackCalled;
54 static bool gOnLayoutActivatedCalled; ///< Whether the LayoutActivated signal was invoked.
55 static bool gOnScrollUpdateCalled;
57 static void TestCallback(BaseHandle handle)
59 gObjectCreatedCallBackCalled = true;
62 static void OnLayoutActivated()
64 gOnLayoutActivatedCalled = true;
67 static void OnScrollUpdate( const Vector2& position )
69 gOnScrollUpdateCalled = true;
72 // Generate a PanGestureEvent to send to Core
73 Integration::PanGestureEvent GeneratePan(
75 const Vector2& previousPosition,
76 const Vector2& currentPosition,
77 unsigned long timeDelta,
78 unsigned int numberOfTouches = 1)
80 Integration::PanGestureEvent pan(state);
82 pan.previousPosition = previousPosition;
83 pan.currentPosition = currentPosition;
84 pan.timeDelta = timeDelta;
85 pan.numberOfTouches = numberOfTouches;
91 * Helper to generate PanGestureEvent
93 * @param[in] application Application instance
94 * @param[in] state The Gesture State
95 * @param[in] pos The current position of touch.
97 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
101 if( (state == Gesture::Started) ||
102 (state == Gesture::Possible) )
108 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
115 * Simulate time passed by.
117 * @note this will always process at least 1 frame (1/60 sec)
119 * @param application Test application instance
120 * @param duration Time to pass in milliseconds.
121 * @return The actual time passed in milliseconds
123 int Wait(ToolkitTestApplication& application, int duration = 0)
127 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
129 application.SendNotification();
130 application.Render(RENDER_FRAME_INTERVAL);
131 time += RENDER_FRAME_INTERVAL;
137 // Implementation of ItemFactory for providing actors to ItemView
138 class TestItemFactory : public ItemFactory
144 * @param application class, stored as reference
150 public: // From ItemFactory
153 * Query the number of items available from the factory.
154 * The maximum available item has an ID of GetNumberOfItems() - 1.
156 virtual unsigned int GetNumberOfItems()
158 return TOTAL_ITEM_NUMBER;
162 * Create an Actor to represent a visible item.
164 * @return the created actor.
166 virtual Actor NewItem(unsigned int itemId)
168 // Create a renderable actor for this item
169 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
170 Actor actor = CreateRenderableActor(image);
179 int UtcDaliItemViewNew(void)
181 ToolkitTestApplication application;
183 // Create the ItemView actor
184 TestItemFactory factory;
185 ItemView view = ItemView::New(factory);
187 DALI_TEST_CHECK(view);
189 //Additional check to ensure object is created by checking if it's registered
190 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
191 DALI_TEST_CHECK( registry );
193 gObjectCreatedCallBackCalled = false;
194 registry.ObjectCreatedSignal().Connect(&TestCallback);
196 TestItemFactory factory;
197 ItemView view = ItemView::New(factory);
199 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
203 int UtcDaliItemViewDownCast(void)
205 ToolkitTestApplication application;
207 // Create the ItemView actor
208 TestItemFactory factory;
209 const ItemView itemViewConst = ItemView::New(factory);
210 ItemView itemView(itemViewConst);
212 BaseHandle handle(itemView);
214 ItemView newItemView = ItemView::DownCast( handle );
215 DALI_TEST_CHECK( itemView );
216 DALI_TEST_CHECK( newItemView == itemView );
220 int UtcDaliItemViewAddAndGetLayout(void)
222 ToolkitTestApplication application;
224 // Create the ItemView actor
225 TestItemFactory factory;
226 ItemView view = ItemView::New(factory);
228 // Create a grid layout and add it to ItemView
229 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
230 view.AddLayout(*gridLayout);
232 // As we have added one layout, check the number of layout is now 1
233 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
235 // Create a depth layout and add it to ItemView
236 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
237 view.AddLayout(*depthLayout);
239 // As we have added another layout, check the number of layout is now 2
240 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
242 // Create a spiral layout and add it to ItemView
243 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
244 view.AddLayout(*spiralLayout);
246 // As we have added another layout, check the number of layout is now 3
247 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
249 // Check we are getting the correct layout from ItemView
250 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
251 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
252 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
256 int UtcDaliItemViewAddAndRemoveLayout(void)
258 ToolkitTestApplication application;
260 // Create the ItemView actor
261 TestItemFactory factory;
262 ItemView view = ItemView::New(factory);
264 // Create a grid layout and add it to ItemView
265 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
266 view.AddLayout(*gridLayout);
268 // As we have added one layout, check the number of layout is now 1
269 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
271 // Create a depth layout and add it to ItemView
272 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
273 view.AddLayout(*depthLayout);
275 // As we have added another layout, check the number of layout is now 2
276 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
278 // Check we are getting the correct layout from ItemView
279 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
280 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
282 // Remove the grid layout
283 view.RemoveLayout(0);
285 // As we have removed the grid layout, check the number of layout is now 1
286 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
288 // Check we are getting the correct layout from ItemView
289 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
291 // Remove the depth layout
292 view.RemoveLayout(0);
294 // As we also removed the depth layout, check the number of layout is now 0
295 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
299 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
301 ToolkitTestApplication application;
303 // Create the ItemView actor
304 TestItemFactory factory;
305 ItemView view = ItemView::New(factory);
307 // Create a grid layout and add it to ItemView
308 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
309 view.AddLayout(*gridLayout);
311 // Create a depth layout and add it to ItemView
312 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
313 view.AddLayout(*depthLayout);
315 // Create a spiral layout and add it to ItemView
316 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
317 view.AddLayout(*spiralLayout);
319 // As we have added three layouts, check the number of layout is now 3
320 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
322 // Check there is no active layout at the moment
323 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
325 // Activate the depth layout
326 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
327 view.ActivateLayout(1, stageSize, 0.5f);
329 // Check the current active layout is the depth layout
330 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
332 // Activate the grid layout
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 // Activate the spiral layout
339 view.ActivateLayout(2, stageSize, 0.5f);
341 // Check the current active layout is the spiral layout
342 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
346 int UtcDaliItemViewDeactivateCurrentLayout(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::Down);
357 view.AddLayout(*gridLayout);
359 // Check there is no active layout at the moment
360 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
362 // Activate the grid layout
363 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
364 view.ActivateLayout(0, stageSize, 0.5f);
366 // Check the current active layout is the grid layout
367 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
369 // Deactivate the current layout
370 view.DeactivateCurrentLayout();
372 // Check there is no active layout at the moment
373 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
377 int UtcDaliItemViewGetItemAndGetItemId(void)
379 ToolkitTestApplication application;
381 // Create the ItemView actor
382 TestItemFactory factory;
383 ItemView view = ItemView::New(factory);
385 // Create a grid layout and add it to ItemView
386 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
387 gridLayout->SetOrientation(ControlOrientation::Left);
388 view.AddLayout(*gridLayout);
390 // Activate the grid layout so that the items will be created and added to ItemView
391 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
392 view.ActivateLayout(0, stageSize, 0.5f);
394 // Get the item given the item ID
395 Actor itemActor = view.GetItem(2);
397 // Check we are getting the correct Item ID given the specified actor
398 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
402 int UtcDaliItemViewRemoveItem(void)
404 ToolkitTestApplication application;
406 // Create the ItemView actor
407 TestItemFactory factory;
408 ItemView view = ItemView::New(factory);
410 // Create a grid layout and add it to ItemView
411 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
412 gridLayout->SetOrientation(ControlOrientation::Right);
413 view.AddLayout(*gridLayout);
415 // Activate the grid layout so that the items will be created and added to ItemView
416 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
417 view.ActivateLayout(0, stageSize, 0.5f);
419 // Get the item given the item ID 2 and 3
420 Actor oldItemActorID2 = view.GetItem(2);
421 Actor oldItemActorID3 = view.GetItem(3);
423 // Remove the item with ID 2
424 view.RemoveItem(2, 0.0f);
426 // Get the new item given the item ID 2
427 Actor newItemActorID2 = view.GetItem(2);
429 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
430 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
431 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
432 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
436 int UtcDaliItemViewGetCurrentLayoutPosition(void)
438 ToolkitTestApplication application;
440 // Create the ItemView actor
441 TestItemFactory factory;
442 ItemView view = ItemView::New(factory);
444 // Create a depth layout and add it to ItemView
445 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
446 depthLayout->SetOrientation(ControlOrientation::Up);
447 view.AddLayout(*depthLayout);
449 // Activate the grid layout so that the items will be created and added to ItemView
450 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
451 view.ActivateLayout(0, stageSize, 0.0f);
453 // Check the current layout position for the 10th items is 9.0f
454 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
458 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
460 ToolkitTestApplication application;
462 // Create the ItemView actor
463 TestItemFactory factory;
464 ItemView view = ItemView::New(factory);
466 // Set the minimum swipe speed to be 1.5f
467 view.SetMinimumSwipeSpeed(1.5f);
469 // Check the minimum swipe speed is 1.5f
470 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
474 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
476 ToolkitTestApplication application;
478 // Create the ItemView actor
479 TestItemFactory factory;
480 ItemView view = ItemView::New(factory);
482 // Set the minimum swipe distance to be 2.5f
483 view.SetMinimumSwipeDistance(2.5f);
485 // Check the minimum swipe distance is 2.5f
486 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
490 int UtcDaliItemViewSetAndGetAnchoring(void)
492 ToolkitTestApplication application;
494 // Create the ItemView actor
495 TestItemFactory factory;
496 ItemView view = ItemView::New(factory);
498 // Disable the anchor animation
499 view.SetAnchoring(false);
501 // Check the anchor animation is disabled
502 DALI_TEST_CHECK(view.GetAnchoring() == false);
506 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
508 ToolkitTestApplication application;
510 // Create the ItemView actor
511 TestItemFactory factory;
512 ItemView view = ItemView::New(factory);
514 // Set the duration of anchor animation to be 1.5f
515 view.SetAnchoringDuration(1.5f);
517 // Check the duration of anchor animation is 1.5f
518 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
522 int UtcDaliItemViewSetAndGetRefreshInterval(void)
524 ToolkitTestApplication application;
526 // Create the ItemView actor
527 TestItemFactory factory;
528 ItemView view = ItemView::New(factory);
530 // Set the interval between refreshes to be 20
531 view.SetRefreshInterval(20);
535 // Check the interval between refreshes is 20
536 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
540 int UtcDaliItemViewScrollToItem(void)
542 ToolkitTestApplication application;
544 // Create the ItemView actor
545 TestItemFactory factory;
546 ItemView view = ItemView::New(factory);
547 Vector3 vec(480.0f, 800.0f, 0.0f);
548 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
550 view.SetName("view actor");
551 view.AddLayout(*layout);
554 Stage::GetCurrent().Add(view);
555 layout->SetOrientation(ControlOrientation::Down);
556 view.ActivateLayout(0, vec, 0.0f);
558 application.SendNotification();
559 application.Render(0);
562 for(int i = 0; i < 10; ++i)
564 application.Render(16); // 60hz frames
567 // Confirm: we have actors in the view.
568 std::vector<unsigned int> indices;
569 for(unsigned int i = 0; i < 10; i++)
571 Actor testActor = view.GetItem(i);
574 indices.push_back(i);
580 if (!indices.empty())
582 const unsigned int firstTargetIndex = indices[indices.size()-1];
583 // scroll to last item
584 view.ScrollToItem(firstTargetIndex, 0.00f);
585 for(int i = 0; i < 10; ++i)
587 application.Render(16); // 60hz frames
590 std::size_t moveCount = 0;
591 for(std::size_t i = 0; i < indices.size(); i++)
593 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
594 view.ScrollToItem(indices[i], 0.0f);
595 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
597 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
603 DALI_TEST_CHECK((moveCount == indices.size()));
608 tet_result(TET_FAIL);
611 Stage::GetCurrent().Remove(view);
615 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
617 ToolkitTestApplication application;
619 // Create the ItemView actor
620 TestItemFactory factory;
621 ItemView view = ItemView::New(factory);
623 // Set the scroll distance step for the wheel event to be 100.0f
624 view.SetWheelScrollDistanceStep(100.0f);
626 // Check the scroll distance step is 100.0f
627 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
631 int UtcDaliItemViewInsertItemP(void)
633 ToolkitTestApplication application;
635 // Create the ItemView actor
636 TestItemFactory factory;
637 ItemView view = ItemView::New(factory);
639 // Create a depth layout and add it to ItemView
640 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
641 depthLayout->SetOrientation(ControlOrientation::Left);
642 view.AddLayout(*depthLayout);
644 // Activate the grid layout so that the items will be created and added to ItemView
645 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
646 view.ActivateLayout(0, stageSize, 0.5f);
648 // Get the item given the item ID
649 Actor itemActor = view.GetItem(2);
651 ItemId id = view.GetItemId( itemActor );
653 // Check we are getting the correct Item ID given the specified actor
654 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
656 Actor newActor = Actor::New();
658 view.InsertItem(Item(id, newActor), 0.5f);
660 DALI_TEST_CHECK(view.GetItem(2) == newActor);
664 int UtcDaliItemViewInsertItemsP(void)
666 ToolkitTestApplication application;
668 // Create the ItemView actor
669 TestItemFactory factory;
670 ItemView view = ItemView::New(factory);
672 // Create a depth layout and add it to ItemView
673 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
674 depthLayout->SetOrientation(ControlOrientation::Right);
675 view.AddLayout(*depthLayout);
677 // Activate the grid layout so that the items will be created and added to ItemView
678 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
679 view.ActivateLayout(0, stageSize, 0.5f);
681 unsigned int itemCount = view.GetChildCount();
683 ItemContainer insertList;
685 for( unsigned int i = 0u; i < 10; ++i )
687 Actor child = view.GetChildAt( i );
688 Actor newActor = Actor::New();
689 newActor.SetName("Inserted");
690 insertList.push_back( Item( view.GetItemId(child), newActor ) );
693 if( !insertList.empty() )
695 view.InsertItems( insertList, 0.5f );
698 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
700 ItemIdContainer removeList;
702 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
704 Actor child = view.GetChildAt( i );
706 if( child.GetName() == "Inserted" )
708 removeList.push_back( view.GetItemId(child) );
712 if( ! removeList.empty() )
714 view.RemoveItems( removeList, 0.5f );
717 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
721 int UtcDaliItemViewReplaceItemP(void)
723 ToolkitTestApplication application;
725 // Create the ItemView actor
726 TestItemFactory factory;
727 ItemView view = ItemView::New(factory);
729 // Create a spiral layout and add it to ItemView
730 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
731 view.AddLayout(*spiralLayout);
733 // Activate the grid layout so that the items will be created and added to ItemView
734 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
735 view.ActivateLayout(0, stageSize, 0.5f);
737 Actor newActor = Actor::New();
739 view.ReplaceItem( Item( 0, newActor ), 0.5f );
741 DALI_TEST_CHECK(view.GetItem(0) == newActor);
745 int UtcDaliItemViewReplaceItemsP(void)
747 ToolkitTestApplication application;
749 // Create the ItemView actor
750 TestItemFactory factory;
751 ItemView view = ItemView::New(factory);
753 // Create a spiral layout and add it to ItemView
754 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
755 spiralLayout->SetOrientation( ControlOrientation::Down );
756 view.AddLayout(*spiralLayout);
758 // Activate the grid layout so that the items will be created and added to ItemView
759 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
760 view.ActivateLayout(0, stageSize, 0.5f);
762 ItemContainer replaceList;
764 for( unsigned int i = 0u; i < 10; ++i )
766 Actor child = view.GetItem( i );
767 Actor newActor = Actor::New();
768 newActor.SetName("Replaced");
770 replaceList.push_back( Item( i, newActor ) );
773 if( !replaceList.empty() )
775 view.ReplaceItems( replaceList, 0.5f );
778 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
779 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
783 int UtcDaliItemViewGetItemsRangeP(void)
785 ToolkitTestApplication application;
787 // Create the ItemView actor
788 TestItemFactory factory;
789 ItemView view = ItemView::New(factory);
791 // Create a spiral layout and add it to ItemView
792 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
793 spiralLayout->SetOrientation( ControlOrientation::Left );
794 view.AddLayout(*spiralLayout);
796 // Activate the grid layout so that the items will be created and added to ItemView
797 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
798 view.ActivateLayout(0, stageSize, 0.5f);
800 ItemRange itemRange(0, 0);
802 view.GetItemsRange(itemRange);
804 DALI_TEST_CHECK(itemRange.Within(0));
808 int UtcDaliItemViewSetItemsAnchorPointP(void)
810 ToolkitTestApplication application;
812 // Create the ItemView actor
813 TestItemFactory factory;
814 ItemView view = ItemView::New(factory);
816 // Create a spiral layout and add it to ItemView
817 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
818 spiralLayout->SetOrientation( ControlOrientation::Right );
819 view.AddLayout(*spiralLayout);
821 // Activate the grid layout so that the items will be created and added to ItemView
822 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
823 view.ActivateLayout(0, stageSize, 0.5f);
825 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
827 view.SetItemsAnchorPoint(anchorPoint);
829 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
830 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
834 int UtcDaliItemViewSetItemsParentOriginP(void)
836 ToolkitTestApplication application;
838 // Create the ItemView actor
839 TestItemFactory factory;
840 ItemView view = ItemView::New(factory);
842 // Create a grid layout and add it to ItemView
843 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
844 view.AddLayout(*gridLayout);
846 // Activate the grid layout so that the items will be created and added to ItemView
847 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
848 view.ActivateLayout(0, stageSize, 0.5f);
850 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
852 view.SetItemsParentOrigin(parentOrigin);
854 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
855 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
859 int UtcDaliItemFactoryGetExtention(void)
861 ToolkitTestApplication application;
862 TestItemFactory factory;
863 DALI_TEST_CHECK( factory.GetExtension() == NULL );
867 int UtcDaliItemViewLayoutActivatedSignalP(void)
869 ToolkitTestApplication application;
871 // Create the ItemView actor
872 TestItemFactory factory;
873 ItemView view = ItemView::New(factory);
875 // Create a grid layout and add it to ItemView
876 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
877 view.AddLayout(*gridLayout);
879 Stage::GetCurrent().Add( view );
881 // Connect the layout activated signal
882 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
884 gOnLayoutActivatedCalled = false;
887 application.SendNotification();
888 application.Render();
890 // Activate the grid layout so that the items will be created and added to ItemView
891 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
892 view.ActivateLayout(0, stageSize, 0.1f);
894 // Wait for 0.1 second
895 Wait(application, 100);
897 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
902 int UtcDaliItemViewSetGetProperty(void)
904 ToolkitTestApplication application;
906 // Create the ItemView actor
907 TestItemFactory factory;
908 ItemView view = ItemView::New(factory);
909 DALI_TEST_CHECK(view);
911 // Event side properties
913 // Test "minimumSwipeSpeed" property
914 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
915 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
916 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
917 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
919 // Test "minimumSwipeDistance" property
920 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
921 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
922 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
923 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
925 // Test "wheelScrollDistanceStep" property
926 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
927 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
928 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
929 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
931 // Test "snapToItemEnabled" property
932 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
933 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
934 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
935 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
937 // Test "refreshInterval" property
938 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
939 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
940 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
941 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
943 // Test "layout" property
944 DALI_TEST_CHECK( view.GetPropertyIndex("layout") == DevelItemView::Property::LAYOUT );
945 Property::Map gridLayoutProperty;
946 gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
947 gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
948 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
949 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
951 Property::Map depthLayoutProperty;
952 depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
953 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
954 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
956 Property::Map spiralLayoutPrperty;
957 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
958 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
959 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
961 Property::Map listLayoutPrperty;
962 listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
963 listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
966 Property::Array layoutArray;
967 layoutArray.PushBack(gridLayoutProperty);
968 layoutArray.PushBack(depthLayoutProperty);
969 layoutArray.PushBack(spiralLayoutPrperty);
970 layoutArray.PushBack(listLayoutPrperty);
972 view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
974 Property::Array getLayoutArray;
975 DALI_TEST_CHECK( view.GetProperty(DevelItemView::Property::LAYOUT ).Get( getLayoutArray ) );
977 //Check that the result is the same as
978 DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
979 Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
981 for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
983 KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
984 if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
986 int layoutType = propertyPair.second.Get<int>();
987 DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
989 else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
991 Vector3 size = propertyPair.second.Get<Vector3>();
992 DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
994 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
996 float spacing = propertyPair.second.Get<float>();
997 DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
999 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1001 int number = propertyPair.second.Get<int>();
1002 DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1005 view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
1008 // Test "overshootEnabled" property
1009 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
1010 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1011 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1012 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1014 // Animatable properties
1016 // Test "layoutPosition" property
1017 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
1018 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1020 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1022 // Test "scrollSpeed" property
1023 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
1024 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1026 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1028 // Test "overshoot" property
1029 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
1030 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1032 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1034 // Test "scrollDirection" property
1035 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
1036 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1038 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1040 // Test "layoutOrientation" property
1041 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
1042 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1044 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1046 // Test "scrollContentSize" property
1047 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
1048 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1050 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1056 int UtcDaliItemViewOvershootVertical(void)
1058 ToolkitTestApplication application;
1059 Dali::Stage stage = Dali::Stage::GetCurrent();
1061 // Create the ItemView actor
1062 TestItemFactory factory;
1063 ItemView view = ItemView::New(factory);
1065 // Create a grid layout and add it to ItemView
1066 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1067 view.AddLayout(*gridLayout);
1070 // Activate the grid layout so that the items will be created and added to ItemView
1071 Vector3 stageSize(stage.GetSize());
1072 view.ActivateLayout(0, stageSize, 0.5f);
1074 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1075 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1077 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1081 // Do a pan starting from 100,100 and moving down
1082 Vector2 pos(100.0f, 100.0f);
1083 SendPan(application, Gesture::Possible, pos);
1084 SendPan(application, Gesture::Started, pos);
1086 Wait(application, 100);
1088 for(int i = 0;i<200;i++)
1090 SendPan(application, Gesture::Continuing, pos);
1095 SendPan(application, Gesture::Finished, pos);
1096 Wait(application, 100);
1098 // Do a pan starting from 100,100 and moving up
1099 pos = Vector2(100.0f, 300.0f);
1100 SendPan(application, Gesture::Possible, pos);
1101 SendPan(application, Gesture::Started, pos);
1103 Wait(application, 100);
1105 for(int i = 0;i<200;i++)
1107 SendPan(application, Gesture::Continuing, pos);
1112 SendPan(application, Gesture::Finished, pos);
1113 Wait(application, 100);
1117 int UtcDaliItemViewOvershootHorizontal(void)
1119 ToolkitTestApplication application;
1120 Dali::Stage stage = Dali::Stage::GetCurrent();
1122 // Create the ItemView actor
1123 TestItemFactory factory;
1124 ItemView view = ItemView::New(factory);
1126 // Create a grid layout and add it to ItemView
1127 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1128 view.AddLayout(*gridLayout);
1131 // Activate the grid layout so that the items will be created and added to ItemView
1132 Vector3 stageSize(stage.GetSize());
1133 view.ActivateLayout(0, stageSize, 0.5f);
1135 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1136 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1138 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1142 // Do a pan starting from 100,100 and moving left
1143 Vector2 pos(100.0f, 100.0f);
1144 SendPan(application, Gesture::Possible, pos);
1145 SendPan(application, Gesture::Started, pos);
1147 Wait(application, 100);
1149 for(int i = 0;i<200;i++)
1151 SendPan(application, Gesture::Continuing, pos);
1156 SendPan(application, Gesture::Finished, pos);
1157 Wait(application, 100);
1159 // Do a pan starting from 100,100 and moving right
1160 pos = Vector2(100.0f, 100.0f);
1161 SendPan(application, Gesture::Possible, pos);
1162 SendPan(application, Gesture::Started, pos);
1164 Wait(application, 100);
1166 for(int i = 0;i<200;i++)
1168 SendPan(application, Gesture::Continuing, pos);
1173 SendPan(application, Gesture::Finished, pos);
1174 Wait(application, 100);
1179 int UtcDaliItemEnableDisableRefresh(void)
1181 ToolkitTestApplication application;
1182 Dali::Stage stage = Dali::Stage::GetCurrent();
1184 // Create the ItemView actor
1185 TestItemFactory factory;
1186 ItemView view = ItemView::New(factory);
1188 // Create a grid layout and add it to ItemView
1189 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1190 view.AddLayout(*gridLayout);
1193 // Activate the grid layout so that the items will be created and added to ItemView
1194 Vector3 stageSize(stage.GetSize());
1195 view.ActivateLayout(0, stageSize, 0.5f);
1197 //Connect to signal scroll updated
1198 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1200 Property::Map attributes;
1201 view.DoAction("enableRefresh", attributes );
1202 gOnScrollUpdateCalled = true;
1203 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1204 application.SendNotification();
1205 application.Render(1000);
1206 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1209 view.DoAction("disableRefresh", attributes );
1210 gOnScrollUpdateCalled = false;
1211 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1212 application.SendNotification();
1213 application.Render(1000);
1215 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );