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.
54 static void TestCallback(BaseHandle handle)
56 gObjectCreatedCallBackCalled = true;
59 static void OnLayoutActivated()
61 gOnLayoutActivatedCalled = true;
64 // Generate a PanGestureEvent to send to Core
65 Integration::PanGestureEvent GeneratePan(
67 const Vector2& previousPosition,
68 const Vector2& currentPosition,
69 unsigned long timeDelta,
70 unsigned int numberOfTouches = 1)
72 Integration::PanGestureEvent pan(state);
74 pan.previousPosition = previousPosition;
75 pan.currentPosition = currentPosition;
76 pan.timeDelta = timeDelta;
77 pan.numberOfTouches = numberOfTouches;
83 * Helper to generate PanGestureEvent
85 * @param[in] application Application instance
86 * @param[in] state The Gesture State
87 * @param[in] pos The current position of touch.
89 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
93 if( (state == Gesture::Started) ||
94 (state == Gesture::Possible) )
100 application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
107 * Simulate time passed by.
109 * @note this will always process at least 1 frame (1/60 sec)
111 * @param application Test application instance
112 * @param duration Time to pass in milliseconds.
113 * @return The actual time passed in milliseconds
115 int Wait(ToolkitTestApplication& application, int duration = 0)
119 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
121 application.SendNotification();
122 application.Render(RENDER_FRAME_INTERVAL);
123 time += RENDER_FRAME_INTERVAL;
129 // Implementation of ItemFactory for providing actors to ItemView
130 class TestItemFactory : public ItemFactory
136 * @param application class, stored as reference
142 public: // From ItemFactory
145 * Query the number of items available from the factory.
146 * The maximum available item has an ID of GetNumberOfItems() - 1.
148 virtual unsigned int GetNumberOfItems()
150 return TOTAL_ITEM_NUMBER;
154 * Create an Actor to represent a visible item.
156 * @return the created actor.
158 virtual Actor NewItem(unsigned int itemId)
160 // Create a renderable actor for this item
161 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
162 Actor actor = CreateRenderableActor(image);
171 int UtcDaliItemViewNew(void)
173 ToolkitTestApplication application;
175 // Create the ItemView actor
176 TestItemFactory factory;
177 ItemView view = ItemView::New(factory);
179 DALI_TEST_CHECK(view);
181 //Additional check to ensure object is created by checking if it's registered
182 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
183 DALI_TEST_CHECK( registry );
185 gObjectCreatedCallBackCalled = false;
186 registry.ObjectCreatedSignal().Connect(&TestCallback);
188 TestItemFactory factory;
189 ItemView view = ItemView::New(factory);
191 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
195 int UtcDaliItemViewDownCast(void)
197 ToolkitTestApplication application;
199 // Create the ItemView actor
200 TestItemFactory factory;
201 const ItemView itemViewConst = ItemView::New(factory);
202 ItemView itemView(itemViewConst);
204 BaseHandle handle(itemView);
206 ItemView newItemView = ItemView::DownCast( handle );
207 DALI_TEST_CHECK( itemView );
208 DALI_TEST_CHECK( newItemView == itemView );
212 int UtcDaliItemViewAddAndGetLayout(void)
214 ToolkitTestApplication application;
216 // Create the ItemView actor
217 TestItemFactory factory;
218 ItemView view = ItemView::New(factory);
220 // Create a grid layout and add it to ItemView
221 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
222 view.AddLayout(*gridLayout);
224 // As we have added one layout, check the number of layout is now 1
225 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
227 // Create a depth layout and add it to ItemView
228 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
229 view.AddLayout(*depthLayout);
231 // As we have added another layout, check the number of layout is now 2
232 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
234 // Create a spiral layout and add it to ItemView
235 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
236 view.AddLayout(*spiralLayout);
238 // As we have added another layout, check the number of layout is now 3
239 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
241 // Check we are getting the correct layout from ItemView
242 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
243 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
244 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
248 int UtcDaliItemViewAddAndRemoveLayout(void)
250 ToolkitTestApplication application;
252 // Create the ItemView actor
253 TestItemFactory factory;
254 ItemView view = ItemView::New(factory);
256 // Create a grid layout and add it to ItemView
257 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
258 view.AddLayout(*gridLayout);
260 // As we have added one layout, check the number of layout is now 1
261 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
263 // Create a depth layout and add it to ItemView
264 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
265 view.AddLayout(*depthLayout);
267 // As we have added another layout, check the number of layout is now 2
268 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
270 // Check we are getting the correct layout from ItemView
271 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
272 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
274 // Remove the grid layout
275 view.RemoveLayout(0);
277 // As we have removed the grid layout, check the number of layout is now 1
278 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
280 // Check we are getting the correct layout from ItemView
281 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
283 // Remove the depth layout
284 view.RemoveLayout(0);
286 // As we also removed the depth layout, check the number of layout is now 0
287 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
291 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
293 ToolkitTestApplication application;
295 // Create the ItemView actor
296 TestItemFactory factory;
297 ItemView view = ItemView::New(factory);
299 // Create a grid layout and add it to ItemView
300 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
301 view.AddLayout(*gridLayout);
303 // Create a depth layout and add it to ItemView
304 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
305 view.AddLayout(*depthLayout);
307 // Create a spiral layout and add it to ItemView
308 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
309 view.AddLayout(*spiralLayout);
311 // As we have added three layouts, check the number of layout is now 3
312 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
314 // Check there is no active layout at the moment
315 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
317 // Activate the depth layout
318 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
319 view.ActivateLayout(1, stageSize, 0.5f);
321 // Check the current active layout is the depth layout
322 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
324 // Activate the grid layout
325 view.ActivateLayout(0, stageSize, 0.5f);
327 // Check the current active layout is the grid layout
328 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
330 // Activate the spiral layout
331 view.ActivateLayout(2, stageSize, 0.5f);
333 // Check the current active layout is the spiral layout
334 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
338 int UtcDaliItemViewDeactivateCurrentLayout(void)
340 ToolkitTestApplication application;
342 // Create the ItemView actor
343 TestItemFactory factory;
344 ItemView view = ItemView::New(factory);
346 // Create a grid layout and add it to ItemView
347 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
348 gridLayout->SetOrientation(ControlOrientation::Down);
349 view.AddLayout(*gridLayout);
351 // Check there is no active layout at the moment
352 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
354 // Activate the grid layout
355 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
356 view.ActivateLayout(0, stageSize, 0.5f);
358 // Check the current active layout is the grid layout
359 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
361 // Deactivate the current layout
362 view.DeactivateCurrentLayout();
364 // Check there is no active layout at the moment
365 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
369 int UtcDaliItemViewGetItemAndGetItemId(void)
371 ToolkitTestApplication application;
373 // Create the ItemView actor
374 TestItemFactory factory;
375 ItemView view = ItemView::New(factory);
377 // Create a grid layout and add it to ItemView
378 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
379 gridLayout->SetOrientation(ControlOrientation::Left);
380 view.AddLayout(*gridLayout);
382 // Activate the grid layout so that the items will be created and added to ItemView
383 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
384 view.ActivateLayout(0, stageSize, 0.5f);
386 // Get the item given the item ID
387 Actor itemActor = view.GetItem(2);
389 // Check we are getting the correct Item ID given the specified actor
390 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
394 int UtcDaliItemViewRemoveItem(void)
396 ToolkitTestApplication application;
398 // Create the ItemView actor
399 TestItemFactory factory;
400 ItemView view = ItemView::New(factory);
402 // Create a grid layout and add it to ItemView
403 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
404 gridLayout->SetOrientation(ControlOrientation::Right);
405 view.AddLayout(*gridLayout);
407 // Activate the grid layout so that the items will be created and added to ItemView
408 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
409 view.ActivateLayout(0, stageSize, 0.5f);
411 // Get the item given the item ID 2 and 3
412 Actor oldItemActorID2 = view.GetItem(2);
413 Actor oldItemActorID3 = view.GetItem(3);
415 // Remove the item with ID 2
416 view.RemoveItem(2, 0.0f);
418 // Get the new item given the item ID 2
419 Actor newItemActorID2 = view.GetItem(2);
421 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
422 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
423 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
424 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
428 int UtcDaliItemViewGetCurrentLayoutPosition(void)
430 ToolkitTestApplication application;
432 // Create the ItemView actor
433 TestItemFactory factory;
434 ItemView view = ItemView::New(factory);
436 // Create a depth layout and add it to ItemView
437 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
438 depthLayout->SetOrientation(ControlOrientation::Up);
439 view.AddLayout(*depthLayout);
441 // Activate the grid layout so that the items will be created and added to ItemView
442 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
443 view.ActivateLayout(0, stageSize, 0.0f);
445 // Check the current layout position for the 10th items is 9.0f
446 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
450 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
452 ToolkitTestApplication application;
454 // Create the ItemView actor
455 TestItemFactory factory;
456 ItemView view = ItemView::New(factory);
458 // Set the minimum swipe speed to be 1.5f
459 view.SetMinimumSwipeSpeed(1.5f);
461 // Check the minimum swipe speed is 1.5f
462 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
466 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
468 ToolkitTestApplication application;
470 // Create the ItemView actor
471 TestItemFactory factory;
472 ItemView view = ItemView::New(factory);
474 // Set the minimum swipe distance to be 2.5f
475 view.SetMinimumSwipeDistance(2.5f);
477 // Check the minimum swipe distance is 2.5f
478 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
482 int UtcDaliItemViewSetAndGetAnchoring(void)
484 ToolkitTestApplication application;
486 // Create the ItemView actor
487 TestItemFactory factory;
488 ItemView view = ItemView::New(factory);
490 // Disable the anchor animation
491 view.SetAnchoring(false);
493 // Check the anchor animation is disabled
494 DALI_TEST_CHECK(view.GetAnchoring() == false);
498 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
500 ToolkitTestApplication application;
502 // Create the ItemView actor
503 TestItemFactory factory;
504 ItemView view = ItemView::New(factory);
506 // Set the duration of anchor animation to be 1.5f
507 view.SetAnchoringDuration(1.5f);
509 // Check the duration of anchor animation is 1.5f
510 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
514 int UtcDaliItemViewSetAndGetRefreshInterval(void)
516 ToolkitTestApplication application;
518 // Create the ItemView actor
519 TestItemFactory factory;
520 ItemView view = ItemView::New(factory);
522 // Set the interval between refreshes to be 20
523 view.SetRefreshInterval(20);
527 // Check the interval between refreshes is 20
528 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
532 int UtcDaliItemViewScrollToItem(void)
534 ToolkitTestApplication application;
536 // Create the ItemView actor
537 TestItemFactory factory;
538 ItemView view = ItemView::New(factory);
539 Vector3 vec(480.0f, 800.0f, 0.0f);
540 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
542 view.SetName("view actor");
543 view.AddLayout(*layout);
546 Stage::GetCurrent().Add(view);
547 layout->SetOrientation(ControlOrientation::Down);
548 view.ActivateLayout(0, vec, 0.0f);
550 application.SendNotification();
551 application.Render(0);
554 for(int i = 0; i < 10; ++i)
556 application.Render(16); // 60hz frames
559 // Confirm: we have actors in the view.
560 std::vector<unsigned int> indices;
561 for(unsigned int i = 0; i < 10; i++)
563 Actor testActor = view.GetItem(i);
566 indices.push_back(i);
572 if (!indices.empty())
574 const unsigned int firstTargetIndex = indices[indices.size()-1];
575 // scroll to last item
576 view.ScrollToItem(firstTargetIndex, 0.00f);
577 for(int i = 0; i < 10; ++i)
579 application.Render(16); // 60hz frames
582 std::size_t moveCount = 0;
583 for(std::size_t i = 0; i < indices.size(); i++)
585 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
586 view.ScrollToItem(indices[i], 0.0f);
587 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
589 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
595 DALI_TEST_CHECK((moveCount == indices.size()));
600 tet_result(TET_FAIL);
603 Stage::GetCurrent().Remove(view);
607 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
609 ToolkitTestApplication application;
611 // Create the ItemView actor
612 TestItemFactory factory;
613 ItemView view = ItemView::New(factory);
615 // Set the scroll distance step for the wheel event to be 100.0f
616 view.SetWheelScrollDistanceStep(100.0f);
618 // Check the scroll distance step is 100.0f
619 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
623 int UtcDaliItemViewInsertItemP(void)
625 ToolkitTestApplication application;
627 // Create the ItemView actor
628 TestItemFactory factory;
629 ItemView view = ItemView::New(factory);
631 // Create a depth layout and add it to ItemView
632 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
633 depthLayout->SetOrientation(ControlOrientation::Left);
634 view.AddLayout(*depthLayout);
636 // Activate the grid layout so that the items will be created and added to ItemView
637 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
638 view.ActivateLayout(0, stageSize, 0.5f);
640 // Get the item given the item ID
641 Actor itemActor = view.GetItem(2);
643 ItemId id = view.GetItemId( itemActor );
645 // Check we are getting the correct Item ID given the specified actor
646 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
648 Actor newActor = Actor::New();
650 view.InsertItem(Item(id, newActor), 0.5f);
652 DALI_TEST_CHECK(view.GetItem(2) == newActor);
656 int UtcDaliItemViewInsertItemsP(void)
658 ToolkitTestApplication application;
660 // Create the ItemView actor
661 TestItemFactory factory;
662 ItemView view = ItemView::New(factory);
664 // Create a depth layout and add it to ItemView
665 ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
666 depthLayout->SetOrientation(ControlOrientation::Right);
667 view.AddLayout(*depthLayout);
669 // Activate the grid layout so that the items will be created and added to ItemView
670 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
671 view.ActivateLayout(0, stageSize, 0.5f);
673 unsigned int itemCount = view.GetChildCount();
675 ItemContainer insertList;
677 for( unsigned int i = 0u; i < 10; ++i )
679 Actor child = view.GetChildAt( i );
680 Actor newActor = Actor::New();
681 newActor.SetName("Inserted");
682 insertList.push_back( Item( view.GetItemId(child), newActor ) );
685 if( !insertList.empty() )
687 view.InsertItems( insertList, 0.5f );
690 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
692 ItemIdContainer removeList;
694 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
696 Actor child = view.GetChildAt( i );
698 if( child.GetName() == "Inserted" )
700 removeList.push_back( view.GetItemId(child) );
704 if( ! removeList.empty() )
706 view.RemoveItems( removeList, 0.5f );
709 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
713 int UtcDaliItemViewReplaceItemP(void)
715 ToolkitTestApplication application;
717 // Create the ItemView actor
718 TestItemFactory factory;
719 ItemView view = ItemView::New(factory);
721 // Create a spiral layout and add it to ItemView
722 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
723 view.AddLayout(*spiralLayout);
725 // Activate the grid layout so that the items will be created and added to ItemView
726 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
727 view.ActivateLayout(0, stageSize, 0.5f);
729 Actor newActor = Actor::New();
731 view.ReplaceItem( Item( 0, newActor ), 0.5f );
733 DALI_TEST_CHECK(view.GetItem(0) == newActor);
737 int UtcDaliItemViewReplaceItemsP(void)
739 ToolkitTestApplication application;
741 // Create the ItemView actor
742 TestItemFactory factory;
743 ItemView view = ItemView::New(factory);
745 // Create a spiral layout and add it to ItemView
746 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
747 spiralLayout->SetOrientation( ControlOrientation::Down );
748 view.AddLayout(*spiralLayout);
750 // Activate the grid layout so that the items will be created and added to ItemView
751 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
752 view.ActivateLayout(0, stageSize, 0.5f);
754 ItemContainer replaceList;
756 for( unsigned int i = 0u; i < 10; ++i )
758 Actor child = view.GetItem( i );
759 Actor newActor = Actor::New();
760 newActor.SetName("Replaced");
762 replaceList.push_back( Item( i, newActor ) );
765 if( !replaceList.empty() )
767 view.ReplaceItems( replaceList, 0.5f );
770 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
771 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
775 int UtcDaliItemViewGetItemsRangeP(void)
777 ToolkitTestApplication application;
779 // Create the ItemView actor
780 TestItemFactory factory;
781 ItemView view = ItemView::New(factory);
783 // Create a spiral layout and add it to ItemView
784 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
785 spiralLayout->SetOrientation( ControlOrientation::Left );
786 view.AddLayout(*spiralLayout);
788 // Activate the grid layout so that the items will be created and added to ItemView
789 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
790 view.ActivateLayout(0, stageSize, 0.5f);
792 ItemRange itemRange(0, 0);
794 view.GetItemsRange(itemRange);
796 DALI_TEST_CHECK(itemRange.Within(0));
800 int UtcDaliItemViewSetItemsAnchorPointP(void)
802 ToolkitTestApplication application;
804 // Create the ItemView actor
805 TestItemFactory factory;
806 ItemView view = ItemView::New(factory);
808 // Create a spiral layout and add it to ItemView
809 ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
810 spiralLayout->SetOrientation( ControlOrientation::Right );
811 view.AddLayout(*spiralLayout);
813 // Activate the grid layout so that the items will be created and added to ItemView
814 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
815 view.ActivateLayout(0, stageSize, 0.5f);
817 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
819 view.SetItemsAnchorPoint(anchorPoint);
821 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
822 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
826 int UtcDaliItemViewSetItemsParentOriginP(void)
828 ToolkitTestApplication application;
830 // Create the ItemView actor
831 TestItemFactory factory;
832 ItemView view = ItemView::New(factory);
834 // Create a grid layout and add it to ItemView
835 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
836 view.AddLayout(*gridLayout);
838 // Activate the grid layout so that the items will be created and added to ItemView
839 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
840 view.ActivateLayout(0, stageSize, 0.5f);
842 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
844 view.SetItemsParentOrigin(parentOrigin);
846 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
847 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
851 int UtcDaliItemFactoryGetExtention(void)
853 ToolkitTestApplication application;
854 TestItemFactory factory;
855 DALI_TEST_CHECK( factory.GetExtension() == NULL );
859 int UtcDaliItemViewLayoutActivatedSignalP(void)
861 ToolkitTestApplication application;
863 // Create the ItemView actor
864 TestItemFactory factory;
865 ItemView view = ItemView::New(factory);
867 // Create a grid layout and add it to ItemView
868 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
869 view.AddLayout(*gridLayout);
871 Stage::GetCurrent().Add( view );
873 // Connect the layout activated signal
874 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
876 gOnLayoutActivatedCalled = false;
879 application.SendNotification();
880 application.Render();
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.1f);
886 // Wait for 0.1 second
887 Wait(application, 100);
889 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
894 int UtcDaliItemViewSetGetProperty(void)
896 ToolkitTestApplication application;
898 // Create the ItemView actor
899 TestItemFactory factory;
900 ItemView view = ItemView::New(factory);
901 DALI_TEST_CHECK(view);
903 // Event side properties
905 // Test "minimumSwipeSpeed" property
906 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
907 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
908 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
909 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
911 // Test "minimumSwipeDistance" property
912 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
913 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
914 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
915 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
917 // Test "wheelScrollDistanceStep" property
918 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
919 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
920 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
921 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
923 // Test "snapToItemEnabled" property
924 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
925 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
926 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
927 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
929 // Test "refreshInterval" property
930 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
931 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
932 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
933 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
935 // Test "overshootEnabled" property
936 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
937 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
938 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
939 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
941 // Animatable properties
943 // Test "layoutPosition" property
944 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
945 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
947 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
949 // Test "scrollSpeed" property
950 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
951 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
953 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
955 // Test "overshoot" property
956 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
957 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
959 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
961 // Test "scrollDirection" property
962 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
963 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
965 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
967 // Test "layoutOrientation" property
968 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
969 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
971 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
973 // Test "scrollContentSize" property
974 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
975 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
977 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
983 int UtcDaliItemViewOvershootVertical(void)
985 ToolkitTestApplication application;
986 Dali::Stage stage = Dali::Stage::GetCurrent();
988 // Create the ItemView actor
989 TestItemFactory factory;
990 ItemView view = ItemView::New(factory);
992 // Create a grid layout and add it to ItemView
993 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
994 view.AddLayout(*gridLayout);
997 // Activate the grid layout so that the items will be created and added to ItemView
998 Vector3 stageSize(stage.GetSize());
999 view.ActivateLayout(0, stageSize, 0.5f);
1001 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1002 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1004 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1008 // Do a pan starting from 100,100 and moving down
1009 Vector2 pos(100.0f, 100.0f);
1010 SendPan(application, Gesture::Possible, pos);
1011 SendPan(application, Gesture::Started, pos);
1013 Wait(application, 100);
1015 for(int i = 0;i<200;i++)
1017 SendPan(application, Gesture::Continuing, pos);
1022 SendPan(application, Gesture::Finished, pos);
1023 Wait(application, 100);
1025 // Do a pan starting from 100,100 and moving up
1026 pos = Vector2(100.0f, 300.0f);
1027 SendPan(application, Gesture::Possible, pos);
1028 SendPan(application, Gesture::Started, pos);
1030 Wait(application, 100);
1032 for(int i = 0;i<200;i++)
1034 SendPan(application, Gesture::Continuing, pos);
1039 SendPan(application, Gesture::Finished, pos);
1040 Wait(application, 100);
1044 int UtcDaliItemViewOvershootHorizontal(void)
1046 ToolkitTestApplication application;
1047 Dali::Stage stage = Dali::Stage::GetCurrent();
1049 // Create the ItemView actor
1050 TestItemFactory factory;
1051 ItemView view = ItemView::New(factory);
1053 // Create a grid layout and add it to ItemView
1054 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1055 view.AddLayout(*gridLayout);
1058 // Activate the grid layout so that the items will be created and added to ItemView
1059 Vector3 stageSize(stage.GetSize());
1060 view.ActivateLayout(0, stageSize, 0.5f);
1062 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1063 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1065 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1069 // Do a pan starting from 100,100 and moving left
1070 Vector2 pos(100.0f, 100.0f);
1071 SendPan(application, Gesture::Possible, pos);
1072 SendPan(application, Gesture::Started, pos);
1074 Wait(application, 100);
1076 for(int i = 0;i<200;i++)
1078 SendPan(application, Gesture::Continuing, pos);
1083 SendPan(application, Gesture::Finished, pos);
1084 Wait(application, 100);
1086 // Do a pan starting from 100,100 and moving right
1087 pos = Vector2(100.0f, 100.0f);
1088 SendPan(application, Gesture::Possible, pos);
1089 SendPan(application, Gesture::Started, pos);
1091 Wait(application, 100);
1093 for(int i = 0;i<200;i++)
1095 SendPan(application, Gesture::Continuing, pos);
1100 SendPan(application, Gesture::Finished, pos);
1101 Wait(application, 100);