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 = 400;
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 and 3
427 Actor newItemActorID2 = view.GetItem(2);
428 Actor newItemActorID3 = view.GetItem(3);
430 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
431 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
432 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
433 DALI_TEST_CHECK(newItemActorID2 == oldItemActorID3);
435 // scroll to the end of item view
436 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
438 application.SendNotification();
439 application.Render(0);
441 // Refresh the item view
444 Actor itemActorID390 = view.GetItem(390);
445 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
447 // Remove the item with ID 2 (which is now before the current item range)
448 view.RemoveItem(2, 0.0f);
450 // Check the original item with item ID 2 was deleted and now item ID 389 represents the original item with ID 390
451 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 389);
452 DALI_TEST_CHECK(view.GetItem(389) == itemActorID390);
457 int UtcDaliItemViewGetCurrentLayoutPosition(void)
459 ToolkitTestApplication application;
461 // Create the ItemView actor
462 TestItemFactory factory;
463 ItemView view = ItemView::New(factory);
465 // Create a depth layout and add it to ItemView
466 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
467 depthLayout->SetOrientation(ControlOrientation::Up);
468 view.AddLayout(*depthLayout);
470 // Activate the grid layout so that the items will be created and added to ItemView
471 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
472 view.ActivateLayout(0, stageSize, 0.0f);
474 // Check the current layout position for the 10th items is 9.0f
475 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
479 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
481 ToolkitTestApplication application;
483 // Create the ItemView actor
484 TestItemFactory factory;
485 ItemView view = ItemView::New(factory);
487 // Set the minimum swipe speed to be 1.5f
488 view.SetMinimumSwipeSpeed(1.5f);
490 // Check the minimum swipe speed is 1.5f
491 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
495 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
497 ToolkitTestApplication application;
499 // Create the ItemView actor
500 TestItemFactory factory;
501 ItemView view = ItemView::New(factory);
503 // Set the minimum swipe distance to be 2.5f
504 view.SetMinimumSwipeDistance(2.5f);
506 // Check the minimum swipe distance is 2.5f
507 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
511 int UtcDaliItemViewSetAndGetAnchoring(void)
513 ToolkitTestApplication application;
515 // Create the ItemView actor
516 TestItemFactory factory;
517 ItemView view = ItemView::New(factory);
519 // Disable the anchor animation
520 view.SetAnchoring(false);
522 // Check the anchor animation is disabled
523 DALI_TEST_CHECK(view.GetAnchoring() == false);
527 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
529 ToolkitTestApplication application;
531 // Create the ItemView actor
532 TestItemFactory factory;
533 ItemView view = ItemView::New(factory);
535 // Set the duration of anchor animation to be 1.5f
536 view.SetAnchoringDuration(1.5f);
538 // Check the duration of anchor animation is 1.5f
539 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
543 int UtcDaliItemViewSetAndGetRefreshInterval(void)
545 ToolkitTestApplication application;
547 // Create the ItemView actor
548 TestItemFactory factory;
549 ItemView view = ItemView::New(factory);
551 // Set the interval between refreshes to be 20
552 view.SetRefreshInterval(20);
556 // Check the interval between refreshes is 20
557 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
561 int UtcDaliItemViewScrollToItem(void)
563 ToolkitTestApplication application;
565 // Create the ItemView actor
566 TestItemFactory factory;
567 ItemView view = ItemView::New(factory);
568 Vector3 vec(480.0f, 800.0f, 0.0f);
569 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
571 view.SetName("view actor");
572 view.AddLayout(*layout);
575 Stage::GetCurrent().Add(view);
576 layout->SetOrientation(ControlOrientation::Down);
577 view.ActivateLayout(0, vec, 0.0f);
579 application.SendNotification();
580 application.Render(0);
583 for(int i = 0; i < 10; ++i)
585 application.Render(16); // 60hz frames
588 // Confirm: we have actors in the view.
589 std::vector<unsigned int> indices;
590 for(unsigned int i = 0; i < 10; i++)
592 Actor testActor = view.GetItem(i);
595 indices.push_back(i);
601 if (!indices.empty())
603 const unsigned int firstTargetIndex = indices[indices.size()-1];
604 // scroll to last item
605 view.ScrollToItem(firstTargetIndex, 0.00f);
606 for(int i = 0; i < 10; ++i)
608 application.Render(16); // 60hz frames
611 std::size_t moveCount = 0;
612 for(std::size_t i = 0; i < indices.size(); i++)
614 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
615 view.ScrollToItem(indices[i], 0.0f);
616 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
618 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
624 DALI_TEST_CHECK((moveCount == indices.size()));
629 tet_result(TET_FAIL);
632 Stage::GetCurrent().Remove(view);
636 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
638 ToolkitTestApplication application;
640 // Create the ItemView actor
641 TestItemFactory factory;
642 ItemView view = ItemView::New(factory);
644 // Set the scroll distance step for the wheel event to be 100.0f
645 view.SetWheelScrollDistanceStep(100.0f);
647 // Check the scroll distance step is 100.0f
648 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
652 int UtcDaliItemViewInsertItemP(void)
654 ToolkitTestApplication application;
656 // Create the ItemView actor
657 TestItemFactory factory;
658 ItemView view = ItemView::New(factory);
660 // Create a grid layout and add it to ItemView
661 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID);
662 gridLayout->SetOrientation(ControlOrientation::Left);
663 view.AddLayout(*gridLayout);
665 // Activate the grid layout so that the items will be created and added to ItemView
666 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
667 view.ActivateLayout(0, stageSize, 0.0f);
669 // Get the specified item where new item to be inserted before that
670 Actor itemActor = view.GetItem(2);
672 ItemId id = view.GetItemId( itemActor );
674 // Check we are getting the correct Item ID given the specified actor
675 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
677 Actor newActor = Actor::New();
679 view.InsertItem(Item(id, newActor), 0.0f);
681 DALI_TEST_CHECK(view.GetItem(2) == newActor);
683 DALI_TEST_CHECK(view.GetItemId(itemActor) == 3);
684 DALI_TEST_CHECK(view.GetItem(3) == itemActor);
686 // scroll to the end of item view
687 view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
689 application.SendNotification();
690 application.Render(0);
692 // Refresh the item view
695 Actor itemActorID390 = view.GetItem(390);
696 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
698 // Insert the item with ID 2 (which is now before the current item range)
699 Actor anotherNewActor = Actor::New();
700 view.InsertItem(Item(id, anotherNewActor), 0.0f);
702 // Check that item ID 391 now represents the original item with ID 390
703 DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 391);
704 DALI_TEST_CHECK(view.GetItem(391) == itemActorID390);
709 int UtcDaliItemViewInsertItemsP(void)
711 ToolkitTestApplication application;
713 // Create the ItemView actor
714 TestItemFactory factory;
715 ItemView view = ItemView::New(factory);
717 // Create a depth layout and add it to ItemView
718 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
719 depthLayout->SetOrientation(ControlOrientation::Right);
720 view.AddLayout(*depthLayout);
722 // Activate the grid layout so that the items will be created and added to ItemView
723 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
724 view.ActivateLayout(0, stageSize, 0.5f);
726 unsigned int itemCount = view.GetChildCount();
728 // Get the specified item where new items to be inserted before that
729 Actor itemActor = view.GetItem(1);
731 // Check we are getting the correct Item ID given the specified item
732 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
734 ItemContainer insertList;
736 for( unsigned int i = 1u; i < 11; ++i )
738 Actor child = view.GetChildAt( i );
739 Actor newActor = Actor::New();
740 newActor.SetName("Inserted");
741 insertList.push_back( Item( view.GetItemId(child), newActor ) );
744 if( !insertList.empty() )
746 view.InsertItems( insertList, 0.5f );
749 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
751 // Check that new items are inserted in the correct positions
752 DALI_TEST_CHECK(view.GetItemId(itemActor) == 11);
753 DALI_TEST_CHECK(view.GetItem(11) == itemActor);
755 ItemIdContainer removeList;
757 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
759 Actor child = view.GetChildAt( i );
761 if( child.GetName() == "Inserted" )
763 removeList.push_back( view.GetItemId(child) );
767 if( ! removeList.empty() )
769 view.RemoveItems( removeList, 0.5f );
772 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
774 // Check that new items are removed correctly so that we are getting the correct Item ID given the specified item
775 DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
776 DALI_TEST_CHECK(view.GetItem(1) == itemActor);
781 int UtcDaliItemViewReplaceItemP(void)
783 ToolkitTestApplication application;
785 // Create the ItemView actor
786 TestItemFactory factory;
787 ItemView view = ItemView::New(factory);
789 // Create a spiral layout and add it to ItemView
790 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
791 view.AddLayout(*spiralLayout);
793 // Activate the grid layout so that the items will be created and added to ItemView
794 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
795 view.ActivateLayout(0, stageSize, 0.5f);
797 Actor newActor = Actor::New();
799 view.ReplaceItem( Item( 5, newActor ), 0.5f );
801 DALI_TEST_CHECK(view.GetItem(5) == newActor);
806 int UtcDaliItemViewReplaceItemsP(void)
808 ToolkitTestApplication application;
810 // Create the ItemView actor
811 TestItemFactory factory;
812 ItemView view = ItemView::New(factory);
814 // Create a spiral layout and add it to ItemView
815 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
816 spiralLayout->SetOrientation( ControlOrientation::Down );
817 view.AddLayout(*spiralLayout);
819 // Activate the grid layout so that the items will be created and added to ItemView
820 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
821 view.ActivateLayout(0, stageSize, 0.5f);
823 ItemContainer replaceList;
825 for( unsigned int i = 0u; i < 10; ++i )
827 Actor child = view.GetItem( i );
828 Actor newActor = Actor::New();
829 newActor.SetName("Replaced");
831 replaceList.push_back( Item( i, newActor ) );
834 if( !replaceList.empty() )
836 view.ReplaceItems( replaceList, 0.5f );
839 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
840 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
844 int UtcDaliItemViewGetItemsRangeP(void)
846 ToolkitTestApplication application;
848 // Create the ItemView actor
849 TestItemFactory factory;
850 ItemView view = ItemView::New(factory);
852 // Create a spiral layout and add it to ItemView
853 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
854 spiralLayout->SetOrientation( ControlOrientation::Left );
855 view.AddLayout(*spiralLayout);
857 // Activate the grid layout so that the items will be created and added to ItemView
858 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
859 view.ActivateLayout(0, stageSize, 0.5f);
861 ItemRange itemRange(0, 0);
863 view.GetItemsRange(itemRange);
865 DALI_TEST_CHECK(itemRange.Within(0));
869 int UtcDaliItemViewSetItemsAnchorPointP(void)
871 ToolkitTestApplication application;
873 // Create the ItemView actor
874 TestItemFactory factory;
875 ItemView view = ItemView::New(factory);
877 // Create a spiral layout and add it to ItemView
878 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
879 spiralLayout->SetOrientation( ControlOrientation::Right );
880 view.AddLayout(*spiralLayout);
882 // Activate the grid layout so that the items will be created and added to ItemView
883 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
884 view.ActivateLayout(0, stageSize, 0.5f);
886 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
888 view.SetItemsAnchorPoint(anchorPoint);
890 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
891 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
895 int UtcDaliItemViewSetItemsParentOriginP(void)
897 ToolkitTestApplication application;
899 // Create the ItemView actor
900 TestItemFactory factory;
901 ItemView view = ItemView::New(factory);
903 // Create a grid layout and add it to ItemView
904 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
905 view.AddLayout(*gridLayout);
907 // Activate the grid layout so that the items will be created and added to ItemView
908 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
909 view.ActivateLayout(0, stageSize, 0.5f);
911 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
913 view.SetItemsParentOrigin(parentOrigin);
915 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
916 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
920 int UtcDaliItemFactoryGetExtention(void)
922 ToolkitTestApplication application;
923 TestItemFactory factory;
924 DALI_TEST_CHECK( factory.GetExtension() == NULL );
928 int UtcDaliItemViewLayoutActivatedSignalP(void)
930 ToolkitTestApplication application;
932 // Create the ItemView actor
933 TestItemFactory factory;
934 ItemView view = ItemView::New(factory);
936 // Create a grid layout and add it to ItemView
937 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
938 view.AddLayout(*gridLayout);
940 Stage::GetCurrent().Add( view );
942 // Connect the layout activated signal
943 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
945 gOnLayoutActivatedCalled = false;
948 application.SendNotification();
949 application.Render();
951 // Activate the grid layout so that the items will be created and added to ItemView
952 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
953 view.ActivateLayout(0, stageSize, 0.1f);
955 // Wait for 0.1 second
956 Wait(application, 100);
958 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
963 int UtcDaliItemViewSetGetProperty(void)
965 ToolkitTestApplication application;
967 // Create the ItemView actor
968 TestItemFactory factory;
969 ItemView view = ItemView::New(factory);
970 DALI_TEST_CHECK(view);
972 // Event side properties
974 // Test "minimumSwipeSpeed" property
975 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
976 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
977 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
978 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
980 // Test "minimumSwipeDistance" property
981 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
982 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
983 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
984 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
986 // Test "wheelScrollDistanceStep" property
987 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
988 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
989 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
990 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
992 // Test "snapToItemEnabled" property
993 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
994 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
995 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
996 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
998 // Test "refreshInterval" property
999 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
1000 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
1001 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
1002 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
1004 // Test "layout" property
1005 DALI_TEST_CHECK( view.GetPropertyIndex("layout") == DevelItemView::Property::LAYOUT );
1006 Property::Map gridLayoutProperty;
1007 gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
1008 gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
1009 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
1010 gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
1012 Property::Map depthLayoutProperty;
1013 depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
1014 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
1015 depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
1017 Property::Map spiralLayoutPrperty;
1018 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
1019 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
1020 spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
1022 Property::Map listLayoutPrperty;
1023 listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
1024 listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
1027 Property::Array layoutArray;
1028 layoutArray.PushBack(gridLayoutProperty);
1029 layoutArray.PushBack(depthLayoutProperty);
1030 layoutArray.PushBack(spiralLayoutPrperty);
1031 layoutArray.PushBack(listLayoutPrperty);
1033 view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
1035 Property::Array getLayoutArray;
1036 DALI_TEST_CHECK( view.GetProperty(DevelItemView::Property::LAYOUT ).Get( getLayoutArray ) );
1038 //Check that the result is the same as
1039 DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
1040 Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
1042 for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
1044 KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
1045 if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
1047 int layoutType = propertyPair.second.Get<int>();
1048 DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
1050 else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
1052 Vector3 size = propertyPair.second.Get<Vector3>();
1053 DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
1055 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
1057 float spacing = propertyPair.second.Get<float>();
1058 DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
1060 else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1062 int number = propertyPair.second.Get<int>();
1063 DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1066 view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
1069 // Test "overshootEnabled" property
1070 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
1071 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1072 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1073 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1075 // Test "overshootSize" property
1076 DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE );
1077 Vector2 overshootSize = Vector2(100.0f,100.0f);
1078 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
1079 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
1081 // Animatable properties
1083 // Test "layoutPosition" property
1084 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
1085 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1087 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1089 // Test "scrollSpeed" property
1090 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
1091 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1093 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1095 // Test "overshoot" property
1096 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
1097 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1099 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1101 // Test "scrollDirection" property
1102 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
1103 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1105 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1107 // Test "layoutOrientation" property
1108 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
1109 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1111 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1113 // Test "scrollContentSize" property
1114 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
1115 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1117 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1123 int UtcDaliItemViewOvershootVertical(void)
1125 ToolkitTestApplication application;
1126 Dali::Stage stage = Dali::Stage::GetCurrent();
1128 // Create the ItemView actor
1129 TestItemFactory factory;
1130 ItemView view = ItemView::New(factory);
1132 // Create a grid layout and add it to ItemView
1133 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1134 view.AddLayout(*gridLayout);
1137 // Activate the grid layout so that the items will be created and added to ItemView
1138 Vector3 stageSize(stage.GetSize());
1139 view.ActivateLayout(0, stageSize, 0.5f);
1141 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1142 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1144 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1148 // Do a pan starting from 100,100 and moving down
1149 Vector2 pos(100.0f, 100.0f);
1150 SendPan(application, Gesture::Possible, pos);
1151 SendPan(application, Gesture::Started, pos);
1153 Wait(application, 100);
1155 for(int i = 0;i<200;i++)
1157 SendPan(application, Gesture::Continuing, pos);
1162 SendPan(application, Gesture::Finished, pos);
1163 Wait(application, 100);
1165 // Do a pan starting from 100,100 and moving up
1166 pos = Vector2(100.0f, 300.0f);
1167 SendPan(application, Gesture::Possible, pos);
1168 SendPan(application, Gesture::Started, pos);
1170 Wait(application, 100);
1172 for(int i = 0;i<200;i++)
1174 SendPan(application, Gesture::Continuing, pos);
1179 SendPan(application, Gesture::Finished, pos);
1180 Wait(application, 100);
1184 int UtcDaliItemViewOvershootHorizontal(void)
1186 ToolkitTestApplication application;
1187 Dali::Stage stage = Dali::Stage::GetCurrent();
1189 // Create the ItemView actor
1190 TestItemFactory factory;
1191 ItemView view = ItemView::New(factory);
1193 // Create a grid layout and add it to ItemView
1194 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1195 view.AddLayout(*gridLayout);
1198 // Activate the grid layout so that the items will be created and added to ItemView
1199 Vector3 stageSize(stage.GetSize());
1200 view.ActivateLayout(0, stageSize, 0.5f);
1202 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1203 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1205 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1209 // Do a pan starting from 100,100 and moving left
1210 Vector2 pos(100.0f, 100.0f);
1211 SendPan(application, Gesture::Possible, pos);
1212 SendPan(application, Gesture::Started, pos);
1214 Wait(application, 100);
1216 for(int i = 0;i<200;i++)
1218 SendPan(application, Gesture::Continuing, pos);
1223 SendPan(application, Gesture::Finished, pos);
1224 Wait(application, 100);
1226 // Do a pan starting from 100,100 and moving right
1227 pos = Vector2(100.0f, 100.0f);
1228 SendPan(application, Gesture::Possible, pos);
1229 SendPan(application, Gesture::Started, pos);
1231 Wait(application, 100);
1233 for(int i = 0;i<200;i++)
1235 SendPan(application, Gesture::Continuing, pos);
1240 SendPan(application, Gesture::Finished, pos);
1241 Wait(application, 100);
1246 int UtcDaliItemEnableDisableRefresh(void)
1248 ToolkitTestApplication application;
1249 Dali::Stage stage = Dali::Stage::GetCurrent();
1251 // Create the ItemView actor
1252 TestItemFactory factory;
1253 ItemView view = ItemView::New(factory);
1255 // Create a grid layout and add it to ItemView
1256 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1257 view.AddLayout(*gridLayout);
1260 // Activate the grid layout so that the items will be created and added to ItemView
1261 Vector3 stageSize(stage.GetSize());
1262 view.ActivateLayout(0, stageSize, 0.5f);
1264 //Connect to signal scroll updated
1265 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1267 Property::Map attributes;
1268 view.DoAction("enableRefresh", attributes );
1269 gOnScrollUpdateCalled = true;
1270 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1271 application.SendNotification();
1272 application.Render(1000);
1273 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1276 view.DoAction("disableRefresh", attributes );
1277 gOnScrollUpdateCalled = false;
1278 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1279 application.SendNotification();
1280 application.Render(1000);
1282 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );