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>
31 using namespace Toolkit;
33 void utc_dali_toolkit_item_view_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_item_view_cleanup(void)
40 test_return_value = TET_PASS;
46 const unsigned int TOTAL_ITEM_NUMBER = 100;
47 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
49 const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
51 static bool gObjectCreatedCallBackCalled;
52 static bool gOnLayoutActivatedCalled; ///< Whether the LayoutActivated signal was invoked.
53 static bool gOnScrollUpdateCalled;
55 static void TestCallback(BaseHandle handle)
57 gObjectCreatedCallBackCalled = true;
60 static void OnLayoutActivated()
62 gOnLayoutActivatedCalled = true;
65 static void OnScrollUpdate( const Vector2& position )
67 gOnScrollUpdateCalled = true;
70 // Generate a PanGestureEvent to send to Core
71 Integration::PanGestureEvent GeneratePan(
73 const Vector2& previousPosition,
74 const Vector2& currentPosition,
75 unsigned long timeDelta,
76 unsigned int numberOfTouches = 1)
78 Integration::PanGestureEvent pan(state);
80 pan.previousPosition = previousPosition;
81 pan.currentPosition = currentPosition;
82 pan.timeDelta = timeDelta;
83 pan.numberOfTouches = numberOfTouches;
89 * Helper to generate PanGestureEvent
91 * @param[in] application Application instance
92 * @param[in] state The Gesture State
93 * @param[in] pos The current position of touch.
95 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
99 if( (state == Gesture::Started) ||
100 (state == Gesture::Possible) )
106 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
113 * Simulate time passed by.
115 * @note this will always process at least 1 frame (1/60 sec)
117 * @param application Test application instance
118 * @param duration Time to pass in milliseconds.
119 * @return The actual time passed in milliseconds
121 int Wait(ToolkitTestApplication& application, int duration = 0)
125 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
127 application.SendNotification();
128 application.Render(RENDER_FRAME_INTERVAL);
129 time += RENDER_FRAME_INTERVAL;
135 // Implementation of ItemFactory for providing actors to ItemView
136 class TestItemFactory : public ItemFactory
142 * @param application class, stored as reference
148 public: // From ItemFactory
151 * Query the number of items available from the factory.
152 * The maximum available item has an ID of GetNumberOfItems() - 1.
154 virtual unsigned int GetNumberOfItems()
156 return TOTAL_ITEM_NUMBER;
160 * Create an Actor to represent a visible item.
162 * @return the created actor.
164 virtual Actor NewItem(unsigned int itemId)
166 // Create a renderable actor for this item
167 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
168 Actor actor = CreateRenderableActor(image);
177 int UtcDaliItemViewNew(void)
179 ToolkitTestApplication application;
181 // Create the ItemView actor
182 TestItemFactory factory;
183 ItemView view = ItemView::New(factory);
185 DALI_TEST_CHECK(view);
187 //Additional check to ensure object is created by checking if it's registered
188 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
189 DALI_TEST_CHECK( registry );
191 gObjectCreatedCallBackCalled = false;
192 registry.ObjectCreatedSignal().Connect(&TestCallback);
194 TestItemFactory factory;
195 ItemView view = ItemView::New(factory);
197 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
201 int UtcDaliItemViewDownCast(void)
203 ToolkitTestApplication application;
205 // Create the ItemView actor
206 TestItemFactory factory;
207 const ItemView itemViewConst = ItemView::New(factory);
208 ItemView itemView(itemViewConst);
210 BaseHandle handle(itemView);
212 ItemView newItemView = ItemView::DownCast( handle );
213 DALI_TEST_CHECK( itemView );
214 DALI_TEST_CHECK( newItemView == itemView );
218 int UtcDaliItemViewAddAndGetLayout(void)
220 ToolkitTestApplication application;
222 // Create the ItemView actor
223 TestItemFactory factory;
224 ItemView view = ItemView::New(factory);
226 // Create a grid layout and add it to ItemView
227 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
228 view.AddLayout(*gridLayout);
230 // As we have added one layout, check the number of layout is now 1
231 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
233 // Create a depth layout and add it to ItemView
234 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
235 view.AddLayout(*depthLayout);
237 // As we have added another layout, check the number of layout is now 2
238 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
240 // Create a spiral layout and add it to ItemView
241 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
242 view.AddLayout(*spiralLayout);
244 // As we have added another layout, check the number of layout is now 3
245 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
247 // Check we are getting the correct layout from ItemView
248 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
249 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
250 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
254 int UtcDaliItemViewAddAndRemoveLayout(void)
256 ToolkitTestApplication application;
258 // Create the ItemView actor
259 TestItemFactory factory;
260 ItemView view = ItemView::New(factory);
262 // Create a grid layout and add it to ItemView
263 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
264 view.AddLayout(*gridLayout);
266 // As we have added one layout, check the number of layout is now 1
267 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
269 // Create a depth layout and add it to ItemView
270 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
271 view.AddLayout(*depthLayout);
273 // As we have added another layout, check the number of layout is now 2
274 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
276 // Check we are getting the correct layout from ItemView
277 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
278 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
280 // Remove the grid layout
281 view.RemoveLayout(0);
283 // As we have removed the grid layout, check the number of layout is now 1
284 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
286 // Check we are getting the correct layout from ItemView
287 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
289 // Remove the depth layout
290 view.RemoveLayout(0);
292 // As we also removed the depth layout, check the number of layout is now 0
293 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
297 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
299 ToolkitTestApplication application;
301 // Create the ItemView actor
302 TestItemFactory factory;
303 ItemView view = ItemView::New(factory);
305 // Create a grid layout and add it to ItemView
306 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
307 view.AddLayout(*gridLayout);
309 // Create a depth layout and add it to ItemView
310 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
311 view.AddLayout(*depthLayout);
313 // Create a spiral layout and add it to ItemView
314 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
315 view.AddLayout(*spiralLayout);
317 // As we have added three layouts, check the number of layout is now 3
318 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
320 // Check there is no active layout at the moment
321 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
323 // Activate the depth layout
324 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
325 view.ActivateLayout(1, stageSize, 0.5f);
327 // Check the current active layout is the depth layout
328 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
330 // Activate the grid layout
331 view.ActivateLayout(0, stageSize, 0.5f);
333 // Check the current active layout is the grid layout
334 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
336 // Activate the spiral layout
337 view.ActivateLayout(2, stageSize, 0.5f);
339 // Check the current active layout is the spiral layout
340 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
344 int UtcDaliItemViewDeactivateCurrentLayout(void)
346 ToolkitTestApplication application;
348 // Create the ItemView actor
349 TestItemFactory factory;
350 ItemView view = ItemView::New(factory);
352 // Create a grid layout and add it to ItemView
353 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
354 gridLayout->SetOrientation(ControlOrientation::Down);
355 view.AddLayout(*gridLayout);
357 // Check there is no active layout at the moment
358 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
360 // Activate the grid layout
361 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
362 view.ActivateLayout(0, stageSize, 0.5f);
364 // Check the current active layout is the grid layout
365 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
367 // Deactivate the current layout
368 view.DeactivateCurrentLayout();
370 // Check there is no active layout at the moment
371 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
375 int UtcDaliItemViewGetItemAndGetItemId(void)
377 ToolkitTestApplication application;
379 // Create the ItemView actor
380 TestItemFactory factory;
381 ItemView view = ItemView::New(factory);
383 // Create a grid layout and add it to ItemView
384 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
385 gridLayout->SetOrientation(ControlOrientation::Left);
386 view.AddLayout(*gridLayout);
388 // Activate the grid layout so that the items will be created and added to ItemView
389 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
390 view.ActivateLayout(0, stageSize, 0.5f);
392 // Get the item given the item ID
393 Actor itemActor = view.GetItem(2);
395 // Check we are getting the correct Item ID given the specified actor
396 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
400 int UtcDaliItemViewRemoveItem(void)
402 ToolkitTestApplication application;
404 // Create the ItemView actor
405 TestItemFactory factory;
406 ItemView view = ItemView::New(factory);
408 // Create a grid layout and add it to ItemView
409 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
410 gridLayout->SetOrientation(ControlOrientation::Right);
411 view.AddLayout(*gridLayout);
413 // Activate the grid layout so that the items will be created and added to ItemView
414 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
415 view.ActivateLayout(0, stageSize, 0.5f);
417 // Get the item given the item ID 2 and 3
418 Actor oldItemActorID2 = view.GetItem(2);
419 Actor oldItemActorID3 = view.GetItem(3);
421 // Remove the item with ID 2
422 view.RemoveItem(2, 0.0f);
424 // Get the new item given the item ID 2
425 Actor newItemActorID2 = view.GetItem(2);
427 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
428 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
429 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
430 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
434 int UtcDaliItemViewGetCurrentLayoutPosition(void)
436 ToolkitTestApplication application;
438 // Create the ItemView actor
439 TestItemFactory factory;
440 ItemView view = ItemView::New(factory);
442 // Create a depth layout and add it to ItemView
443 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
444 depthLayout->SetOrientation(ControlOrientation::Up);
445 view.AddLayout(*depthLayout);
447 // Activate the grid layout so that the items will be created and added to ItemView
448 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
449 view.ActivateLayout(0, stageSize, 0.0f);
451 // Check the current layout position for the 10th items is 9.0f
452 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
456 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
458 ToolkitTestApplication application;
460 // Create the ItemView actor
461 TestItemFactory factory;
462 ItemView view = ItemView::New(factory);
464 // Set the minimum swipe speed to be 1.5f
465 view.SetMinimumSwipeSpeed(1.5f);
467 // Check the minimum swipe speed is 1.5f
468 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
472 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
474 ToolkitTestApplication application;
476 // Create the ItemView actor
477 TestItemFactory factory;
478 ItemView view = ItemView::New(factory);
480 // Set the minimum swipe distance to be 2.5f
481 view.SetMinimumSwipeDistance(2.5f);
483 // Check the minimum swipe distance is 2.5f
484 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
488 int UtcDaliItemViewSetAndGetAnchoring(void)
490 ToolkitTestApplication application;
492 // Create the ItemView actor
493 TestItemFactory factory;
494 ItemView view = ItemView::New(factory);
496 // Disable the anchor animation
497 view.SetAnchoring(false);
499 // Check the anchor animation is disabled
500 DALI_TEST_CHECK(view.GetAnchoring() == false);
504 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
506 ToolkitTestApplication application;
508 // Create the ItemView actor
509 TestItemFactory factory;
510 ItemView view = ItemView::New(factory);
512 // Set the duration of anchor animation to be 1.5f
513 view.SetAnchoringDuration(1.5f);
515 // Check the duration of anchor animation is 1.5f
516 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
520 int UtcDaliItemViewSetAndGetRefreshInterval(void)
522 ToolkitTestApplication application;
524 // Create the ItemView actor
525 TestItemFactory factory;
526 ItemView view = ItemView::New(factory);
528 // Set the interval between refreshes to be 20
529 view.SetRefreshInterval(20);
533 // Check the interval between refreshes is 20
534 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
538 int UtcDaliItemViewScrollToItem(void)
540 ToolkitTestApplication application;
542 // Create the ItemView actor
543 TestItemFactory factory;
544 ItemView view = ItemView::New(factory);
545 Vector3 vec(480.0f, 800.0f, 0.0f);
546 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
548 view.SetName("view actor");
549 view.AddLayout(*layout);
552 Stage::GetCurrent().Add(view);
553 layout->SetOrientation(ControlOrientation::Down);
554 view.ActivateLayout(0, vec, 0.0f);
556 application.SendNotification();
557 application.Render(0);
560 for(int i = 0; i < 10; ++i)
562 application.Render(16); // 60hz frames
565 // Confirm: we have actors in the view.
566 std::vector<unsigned int> indices;
567 for(unsigned int i = 0; i < 10; i++)
569 Actor testActor = view.GetItem(i);
572 indices.push_back(i);
578 if (!indices.empty())
580 const unsigned int firstTargetIndex = indices[indices.size()-1];
581 // scroll to last item
582 view.ScrollToItem(firstTargetIndex, 0.00f);
583 for(int i = 0; i < 10; ++i)
585 application.Render(16); // 60hz frames
588 std::size_t moveCount = 0;
589 for(std::size_t i = 0; i < indices.size(); i++)
591 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
592 view.ScrollToItem(indices[i], 0.0f);
593 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
595 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
601 DALI_TEST_CHECK((moveCount == indices.size()));
606 tet_result(TET_FAIL);
609 Stage::GetCurrent().Remove(view);
613 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
615 ToolkitTestApplication application;
617 // Create the ItemView actor
618 TestItemFactory factory;
619 ItemView view = ItemView::New(factory);
621 // Set the scroll distance step for the wheel event to be 100.0f
622 view.SetWheelScrollDistanceStep(100.0f);
624 // Check the scroll distance step is 100.0f
625 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
629 int UtcDaliItemViewInsertItemP(void)
631 ToolkitTestApplication application;
633 // Create the ItemView actor
634 TestItemFactory factory;
635 ItemView view = ItemView::New(factory);
637 // Create a depth layout and add it to ItemView
638 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
639 depthLayout->SetOrientation(ControlOrientation::Left);
640 view.AddLayout(*depthLayout);
642 // Activate the grid layout so that the items will be created and added to ItemView
643 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
644 view.ActivateLayout(0, stageSize, 0.5f);
646 // Get the item given the item ID
647 Actor itemActor = view.GetItem(2);
649 ItemId id = view.GetItemId( itemActor );
651 // Check we are getting the correct Item ID given the specified actor
652 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
654 Actor newActor = Actor::New();
656 view.InsertItem(Item(id, newActor), 0.5f);
658 DALI_TEST_CHECK(view.GetItem(2) == newActor);
662 int UtcDaliItemViewInsertItemsP(void)
664 ToolkitTestApplication application;
666 // Create the ItemView actor
667 TestItemFactory factory;
668 ItemView view = ItemView::New(factory);
670 // Create a depth layout and add it to ItemView
671 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
672 depthLayout->SetOrientation(ControlOrientation::Right);
673 view.AddLayout(*depthLayout);
675 // Activate the grid layout so that the items will be created and added to ItemView
676 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
677 view.ActivateLayout(0, stageSize, 0.5f);
679 unsigned int itemCount = view.GetChildCount();
681 ItemContainer insertList;
683 for( unsigned int i = 0u; i < 10; ++i )
685 Actor child = view.GetChildAt( i );
686 Actor newActor = Actor::New();
687 newActor.SetName("Inserted");
688 insertList.push_back( Item( view.GetItemId(child), newActor ) );
691 if( !insertList.empty() )
693 view.InsertItems( insertList, 0.5f );
696 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
698 ItemIdContainer removeList;
700 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
702 Actor child = view.GetChildAt( i );
704 if( child.GetName() == "Inserted" )
706 removeList.push_back( view.GetItemId(child) );
710 if( ! removeList.empty() )
712 view.RemoveItems( removeList, 0.5f );
715 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
719 int UtcDaliItemViewReplaceItemP(void)
721 ToolkitTestApplication application;
723 // Create the ItemView actor
724 TestItemFactory factory;
725 ItemView view = ItemView::New(factory);
727 // Create a spiral layout and add it to ItemView
728 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
729 view.AddLayout(*spiralLayout);
731 // Activate the grid layout so that the items will be created and added to ItemView
732 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
733 view.ActivateLayout(0, stageSize, 0.5f);
735 Actor newActor = Actor::New();
737 view.ReplaceItem( Item( 0, newActor ), 0.5f );
739 DALI_TEST_CHECK(view.GetItem(0) == newActor);
743 int UtcDaliItemViewReplaceItemsP(void)
745 ToolkitTestApplication application;
747 // Create the ItemView actor
748 TestItemFactory factory;
749 ItemView view = ItemView::New(factory);
751 // Create a spiral layout and add it to ItemView
752 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
753 spiralLayout->SetOrientation( ControlOrientation::Down );
754 view.AddLayout(*spiralLayout);
756 // Activate the grid layout so that the items will be created and added to ItemView
757 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
758 view.ActivateLayout(0, stageSize, 0.5f);
760 ItemContainer replaceList;
762 for( unsigned int i = 0u; i < 10; ++i )
764 Actor child = view.GetItem( i );
765 Actor newActor = Actor::New();
766 newActor.SetName("Replaced");
768 replaceList.push_back( Item( i, newActor ) );
771 if( !replaceList.empty() )
773 view.ReplaceItems( replaceList, 0.5f );
776 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
777 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
781 int UtcDaliItemViewGetItemsRangeP(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 spiralLayout->SetOrientation( ControlOrientation::Left );
792 view.AddLayout(*spiralLayout);
794 // Activate the grid layout so that the items will be created and added to ItemView
795 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
796 view.ActivateLayout(0, stageSize, 0.5f);
798 ItemRange itemRange(0, 0);
800 view.GetItemsRange(itemRange);
802 DALI_TEST_CHECK(itemRange.Within(0));
806 int UtcDaliItemViewSetItemsAnchorPointP(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::Right );
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 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
825 view.SetItemsAnchorPoint(anchorPoint);
827 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
828 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
832 int UtcDaliItemViewSetItemsParentOriginP(void)
834 ToolkitTestApplication application;
836 // Create the ItemView actor
837 TestItemFactory factory;
838 ItemView view = ItemView::New(factory);
840 // Create a grid layout and add it to ItemView
841 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
842 view.AddLayout(*gridLayout);
844 // Activate the grid layout so that the items will be created and added to ItemView
845 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
846 view.ActivateLayout(0, stageSize, 0.5f);
848 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
850 view.SetItemsParentOrigin(parentOrigin);
852 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
853 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
857 int UtcDaliItemFactoryGetExtention(void)
859 ToolkitTestApplication application;
860 TestItemFactory factory;
861 DALI_TEST_CHECK( factory.GetExtension() == NULL );
865 int UtcDaliItemViewLayoutActivatedSignalP(void)
867 ToolkitTestApplication application;
869 // Create the ItemView actor
870 TestItemFactory factory;
871 ItemView view = ItemView::New(factory);
873 // Create a grid layout and add it to ItemView
874 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
875 view.AddLayout(*gridLayout);
877 Stage::GetCurrent().Add( view );
879 // Connect the layout activated signal
880 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
882 gOnLayoutActivatedCalled = false;
885 application.SendNotification();
886 application.Render();
888 // Activate the grid layout so that the items will be created and added to ItemView
889 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
890 view.ActivateLayout(0, stageSize, 0.1f);
892 // Wait for 0.1 second
893 Wait(application, 100);
895 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
900 int UtcDaliItemViewSetGetProperty(void)
902 ToolkitTestApplication application;
904 // Create the ItemView actor
905 TestItemFactory factory;
906 ItemView view = ItemView::New(factory);
907 DALI_TEST_CHECK(view);
909 // Event side properties
911 // Test "minimumSwipeSpeed" property
912 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
913 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
914 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
915 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
917 // Test "minimumSwipeDistance" property
918 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
919 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
920 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
921 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
923 // Test "wheelScrollDistanceStep" property
924 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
925 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
926 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
927 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
929 // Test "snapToItemEnabled" property
930 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
931 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
932 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
933 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
935 // Test "refreshInterval" property
936 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
937 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
938 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
939 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
941 // Test "overshootEnabled" property
942 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
943 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
944 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
945 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
947 // Animatable properties
949 // Test "layoutPosition" property
950 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
951 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
953 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
955 // Test "scrollSpeed" property
956 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
957 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
959 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
961 // Test "overshoot" property
962 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
963 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
965 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
967 // Test "scrollDirection" property
968 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
969 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
971 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
973 // Test "layoutOrientation" property
974 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
975 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
977 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
979 // Test "scrollContentSize" property
980 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
981 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
983 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
989 int UtcDaliItemViewOvershootVertical(void)
991 ToolkitTestApplication application;
992 Dali::Stage stage = Dali::Stage::GetCurrent();
994 // Create the ItemView actor
995 TestItemFactory factory;
996 ItemView view = ItemView::New(factory);
998 // Create a grid layout and add it to ItemView
999 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1000 view.AddLayout(*gridLayout);
1003 // Activate the grid layout so that the items will be created and added to ItemView
1004 Vector3 stageSize(stage.GetSize());
1005 view.ActivateLayout(0, stageSize, 0.5f);
1007 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1008 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1010 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1014 // Do a pan starting from 100,100 and moving down
1015 Vector2 pos(100.0f, 100.0f);
1016 SendPan(application, Gesture::Possible, pos);
1017 SendPan(application, Gesture::Started, pos);
1019 Wait(application, 100);
1021 for(int i = 0;i<200;i++)
1023 SendPan(application, Gesture::Continuing, pos);
1028 SendPan(application, Gesture::Finished, pos);
1029 Wait(application, 100);
1031 // Do a pan starting from 100,100 and moving up
1032 pos = Vector2(100.0f, 300.0f);
1033 SendPan(application, Gesture::Possible, pos);
1034 SendPan(application, Gesture::Started, pos);
1036 Wait(application, 100);
1038 for(int i = 0;i<200;i++)
1040 SendPan(application, Gesture::Continuing, pos);
1045 SendPan(application, Gesture::Finished, pos);
1046 Wait(application, 100);
1050 int UtcDaliItemViewOvershootHorizontal(void)
1052 ToolkitTestApplication application;
1053 Dali::Stage stage = Dali::Stage::GetCurrent();
1055 // Create the ItemView actor
1056 TestItemFactory factory;
1057 ItemView view = ItemView::New(factory);
1059 // Create a grid layout and add it to ItemView
1060 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1061 view.AddLayout(*gridLayout);
1064 // Activate the grid layout so that the items will be created and added to ItemView
1065 Vector3 stageSize(stage.GetSize());
1066 view.ActivateLayout(0, stageSize, 0.5f);
1068 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1069 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1071 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1075 // Do a pan starting from 100,100 and moving left
1076 Vector2 pos(100.0f, 100.0f);
1077 SendPan(application, Gesture::Possible, pos);
1078 SendPan(application, Gesture::Started, pos);
1080 Wait(application, 100);
1082 for(int i = 0;i<200;i++)
1084 SendPan(application, Gesture::Continuing, pos);
1089 SendPan(application, Gesture::Finished, pos);
1090 Wait(application, 100);
1092 // Do a pan starting from 100,100 and moving right
1093 pos = Vector2(100.0f, 100.0f);
1094 SendPan(application, Gesture::Possible, pos);
1095 SendPan(application, Gesture::Started, pos);
1097 Wait(application, 100);
1099 for(int i = 0;i<200;i++)
1101 SendPan(application, Gesture::Continuing, pos);
1106 SendPan(application, Gesture::Finished, pos);
1107 Wait(application, 100);
1112 int UtcDaliItemEnableDisableRefresh(void)
1114 ToolkitTestApplication application;
1115 Dali::Stage stage = Dali::Stage::GetCurrent();
1117 // Create the ItemView actor
1118 TestItemFactory factory;
1119 ItemView view = ItemView::New(factory);
1121 // Create a grid layout and add it to ItemView
1122 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1123 view.AddLayout(*gridLayout);
1126 // Activate the grid layout so that the items will be created and added to ItemView
1127 Vector3 stageSize(stage.GetSize());
1128 view.ActivateLayout(0, stageSize, 0.5f);
1130 //Connect to signal scroll updated
1131 view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1133 Property::Map attributes;
1134 view.DoAction("enableRefresh", attributes );
1135 gOnScrollUpdateCalled = true;
1136 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1137 application.SendNotification();
1138 application.Render(1000);
1139 DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1142 view.DoAction("disableRefresh", attributes );
1143 gOnScrollUpdateCalled = false;
1144 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1145 application.SendNotification();
1146 application.Render(1000);
1148 DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );