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 view.AddLayout(*gridLayout);
350 // Check there is no active layout at the moment
351 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
353 // Activate the grid layout
354 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
355 view.ActivateLayout(0, stageSize, 0.5f);
357 // Check the current active layout is the grid layout
358 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
360 // Deactivate the current layout
361 view.DeactivateCurrentLayout();
363 // Check there is no active layout at the moment
364 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
368 int UtcDaliItemViewGetItemAndGetItemId(void)
370 ToolkitTestApplication application;
372 // Create the ItemView actor
373 TestItemFactory factory;
374 ItemView view = ItemView::New(factory);
376 // Create a grid layout and add it to ItemView
377 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
378 view.AddLayout(*gridLayout);
380 // Activate the grid layout so that the items will be created and added to ItemView
381 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
382 view.ActivateLayout(0, stageSize, 0.5f);
384 // Get the item given the item ID
385 Actor itemActor = view.GetItem(2);
387 // Check we are getting the correct Item ID given the specified actor
388 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
392 int UtcDaliItemViewRemoveItem(void)
394 ToolkitTestApplication application;
396 // Create the ItemView actor
397 TestItemFactory factory;
398 ItemView view = ItemView::New(factory);
400 // Create a grid layout and add it to ItemView
401 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
402 view.AddLayout(*gridLayout);
404 // Activate the grid layout so that the items will be created and added to ItemView
405 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
406 view.ActivateLayout(0, stageSize, 0.5f);
408 // Get the item given the item ID 2 and 3
409 Actor oldItemActorID2 = view.GetItem(2);
410 Actor oldItemActorID3 = view.GetItem(3);
412 // Remove the item with ID 2
413 view.RemoveItem(2, 0.0f);
415 // Get the new item given the item ID 2
416 Actor newItemActorID2 = view.GetItem(2);
418 // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
419 DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
420 DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
421 DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
425 int UtcDaliItemViewGetCurrentLayoutPosition(void)
427 ToolkitTestApplication application;
429 // Create the ItemView actor
430 TestItemFactory factory;
431 ItemView view = ItemView::New(factory);
433 // Create a grid layout and add it to ItemView
434 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
435 view.AddLayout(*gridLayout);
437 // Activate the grid layout so that the items will be created and added to ItemView
438 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
439 view.ActivateLayout(0, stageSize, 0.0f);
441 // Check the current layout position for the 10th items is 9.0f
442 DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
446 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
448 ToolkitTestApplication application;
450 // Create the ItemView actor
451 TestItemFactory factory;
452 ItemView view = ItemView::New(factory);
454 // Set the minimum swipe speed to be 1.5f
455 view.SetMinimumSwipeSpeed(1.5f);
457 // Check the minimum swipe speed is 1.5f
458 DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
462 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
464 ToolkitTestApplication application;
466 // Create the ItemView actor
467 TestItemFactory factory;
468 ItemView view = ItemView::New(factory);
470 // Set the minimum swipe distance to be 2.5f
471 view.SetMinimumSwipeDistance(2.5f);
473 // Check the minimum swipe distance is 2.5f
474 DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
478 int UtcDaliItemViewSetAndGetAnchoring(void)
480 ToolkitTestApplication application;
482 // Create the ItemView actor
483 TestItemFactory factory;
484 ItemView view = ItemView::New(factory);
486 // Disable the anchor animation
487 view.SetAnchoring(false);
489 // Check the anchor animation is disabled
490 DALI_TEST_CHECK(view.GetAnchoring() == false);
494 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
496 ToolkitTestApplication application;
498 // Create the ItemView actor
499 TestItemFactory factory;
500 ItemView view = ItemView::New(factory);
502 // Set the duration of anchor animation to be 1.5f
503 view.SetAnchoringDuration(1.5f);
505 // Check the duration of anchor animation is 1.5f
506 DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
510 int UtcDaliItemViewSetAndGetRefreshInterval(void)
512 ToolkitTestApplication application;
514 // Create the ItemView actor
515 TestItemFactory factory;
516 ItemView view = ItemView::New(factory);
518 // Set the interval between refreshes to be 20
519 view.SetRefreshInterval(20);
523 // Check the interval between refreshes is 20
524 DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
528 int UtcDaliItemViewScrollToItem(void)
530 ToolkitTestApplication application;
532 // Create the ItemView actor
533 TestItemFactory factory;
534 ItemView view = ItemView::New(factory);
535 Vector3 vec(480.0f, 800.0f, 0.0f);
536 ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::GRID );
538 view.SetName("view actor");
539 view.AddLayout(*layout);
542 Stage::GetCurrent().Add(view);
543 layout->SetOrientation(ControlOrientation::Up);
544 view.ActivateLayout(0, vec, 0.0f);
546 application.SendNotification();
547 application.Render(0);
550 for(int i = 0; i < 10; ++i)
552 application.Render(16); // 60hz frames
555 // Confirm: we have actors in the view.
556 std::vector<unsigned int> indices;
557 for(unsigned int i = 0; i < 10; i++)
559 Actor testActor = view.GetItem(i);
562 indices.push_back(i);
568 if (!indices.empty())
570 const unsigned int firstTargetIndex = indices[indices.size()-1];
571 // scroll to last item
572 view.ScrollToItem(firstTargetIndex, 0.00f);
573 for(int i = 0; i < 10; ++i)
575 application.Render(16); // 60hz frames
578 std::size_t moveCount = 0;
579 for(std::size_t i = 0; i < indices.size(); i++)
581 float layoutPosBefore = view.GetCurrentLayoutPosition(i);
582 view.ScrollToItem(indices[i], 0.0f);
583 float layoutPosAfter = view.GetCurrentLayoutPosition(i);
585 if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
591 DALI_TEST_CHECK((moveCount == indices.size()));
596 tet_result(TET_FAIL);
599 Stage::GetCurrent().Remove(view);
603 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
605 ToolkitTestApplication application;
607 // Create the ItemView actor
608 TestItemFactory factory;
609 ItemView view = ItemView::New(factory);
611 // Set the scroll distance step for the wheel event to be 100.0f
612 view.SetWheelScrollDistanceStep(100.0f);
614 // Check the scroll distance step is 100.0f
615 DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
619 int UtcDaliItemViewInsertItemP(void)
621 ToolkitTestApplication application;
623 // Create the ItemView actor
624 TestItemFactory factory;
625 ItemView view = ItemView::New(factory);
627 // Create a grid layout and add it to ItemView
628 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
629 view.AddLayout(*gridLayout);
631 // Activate the grid layout so that the items will be created and added to ItemView
632 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
633 view.ActivateLayout(0, stageSize, 0.5f);
635 // Get the item given the item ID
636 Actor itemActor = view.GetItem(2);
638 ItemId id = view.GetItemId( itemActor );
640 // Check we are getting the correct Item ID given the specified actor
641 DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
643 Actor newActor = Actor::New();
645 view.InsertItem(Item(id, newActor), 0.5f);
647 DALI_TEST_CHECK(view.GetItem(2) == newActor);
651 int UtcDaliItemViewInsertItemsP(void)
653 ToolkitTestApplication application;
655 // Create the ItemView actor
656 TestItemFactory factory;
657 ItemView view = ItemView::New(factory);
659 // Create a grid layout and add it to ItemView
660 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
661 view.AddLayout(*gridLayout);
663 // Activate the grid layout so that the items will be created and added to ItemView
664 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
665 view.ActivateLayout(0, stageSize, 0.5f);
667 unsigned int itemCount = view.GetChildCount();
669 ItemContainer insertList;
671 for( unsigned int i = 0u; i < 10; ++i )
673 Actor child = view.GetChildAt( i );
674 Actor newActor = Actor::New();
675 newActor.SetName("Inserted");
676 insertList.push_back( Item( view.GetItemId(child), newActor ) );
679 if( !insertList.empty() )
681 view.InsertItems( insertList, 0.5f );
684 DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
686 ItemIdContainer removeList;
688 for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
690 Actor child = view.GetChildAt( i );
692 if( child.GetName() == "Inserted" )
694 removeList.push_back( view.GetItemId(child) );
698 if( ! removeList.empty() )
700 view.RemoveItems( removeList, 0.5f );
703 DALI_TEST_CHECK(view.GetChildCount() == itemCount);
707 int UtcDaliItemViewReplaceItemP(void)
709 ToolkitTestApplication application;
711 // Create the ItemView actor
712 TestItemFactory factory;
713 ItemView view = ItemView::New(factory);
715 // Create a grid layout and add it to ItemView
716 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
717 view.AddLayout(*gridLayout);
719 // Activate the grid layout so that the items will be created and added to ItemView
720 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
721 view.ActivateLayout(0, stageSize, 0.5f);
723 Actor newActor = Actor::New();
725 view.ReplaceItem( Item( 0, newActor ), 0.5f );
727 DALI_TEST_CHECK(view.GetItem(0) == newActor);
731 int UtcDaliItemViewReplaceItemsP(void)
733 ToolkitTestApplication application;
735 // Create the ItemView actor
736 TestItemFactory factory;
737 ItemView view = ItemView::New(factory);
739 // Create a grid layout and add it to ItemView
740 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
741 view.AddLayout(*gridLayout);
743 // Activate the grid layout so that the items will be created and added to ItemView
744 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
745 view.ActivateLayout(0, stageSize, 0.5f);
747 ItemContainer replaceList;
749 for( unsigned int i = 0u; i < 10; ++i )
751 Actor child = view.GetItem( i );
752 Actor newActor = Actor::New();
753 newActor.SetName("Replaced");
755 replaceList.push_back( Item( i, newActor ) );
758 if( !replaceList.empty() )
760 view.ReplaceItems( replaceList, 0.5f );
763 DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
764 DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
768 int UtcDaliItemViewGetItemsRangeP(void)
770 ToolkitTestApplication application;
772 // Create the ItemView actor
773 TestItemFactory factory;
774 ItemView view = ItemView::New(factory);
776 // Create a grid layout and add it to ItemView
777 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
778 view.AddLayout(*gridLayout);
780 // Activate the grid layout so that the items will be created and added to ItemView
781 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
782 view.ActivateLayout(0, stageSize, 0.5f);
784 ItemRange itemRange(0, 0);
786 view.GetItemsRange(itemRange);
788 DALI_TEST_CHECK(itemRange.Within(0));
792 int UtcDaliItemViewSetItemsAnchorPointP(void)
794 ToolkitTestApplication application;
796 // Create the ItemView actor
797 TestItemFactory factory;
798 ItemView view = ItemView::New(factory);
800 // Create a grid layout and add it to ItemView
801 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
802 view.AddLayout(*gridLayout);
804 // Activate the grid layout so that the items will be created and added to ItemView
805 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
806 view.ActivateLayout(0, stageSize, 0.5f);
808 Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
810 view.SetItemsAnchorPoint(anchorPoint);
812 DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
813 DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
817 int UtcDaliItemViewSetItemsParentOriginP(void)
819 ToolkitTestApplication application;
821 // Create the ItemView actor
822 TestItemFactory factory;
823 ItemView view = ItemView::New(factory);
825 // Create a grid layout and add it to ItemView
826 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
827 view.AddLayout(*gridLayout);
829 // Activate the grid layout so that the items will be created and added to ItemView
830 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
831 view.ActivateLayout(0, stageSize, 0.5f);
833 Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
835 view.SetItemsParentOrigin(parentOrigin);
837 DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
838 DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
842 int UtcDaliItemFactoryGetExtention(void)
844 ToolkitTestApplication application;
845 TestItemFactory factory;
846 DALI_TEST_CHECK( factory.GetExtension() == NULL );
850 int UtcDaliItemViewLayoutActivatedSignalP(void)
852 ToolkitTestApplication application;
854 // Create the ItemView actor
855 TestItemFactory factory;
856 ItemView view = ItemView::New(factory);
858 // Create a grid layout and add it to ItemView
859 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
860 view.AddLayout(*gridLayout);
862 Stage::GetCurrent().Add( view );
864 // Connect the layout activated signal
865 view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
867 gOnLayoutActivatedCalled = false;
870 application.SendNotification();
871 application.Render();
873 // Activate the grid layout so that the items will be created and added to ItemView
874 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
875 view.ActivateLayout(0, stageSize, 0.1f);
877 // Wait for 0.1 second
878 Wait(application, 100);
880 DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
885 int UtcDaliItemViewSetGetProperty(void)
887 ToolkitTestApplication application;
889 // Create the ItemView actor
890 TestItemFactory factory;
891 ItemView view = ItemView::New(factory);
892 DALI_TEST_CHECK(view);
894 // Event side properties
896 // Test "minimumSwipeSpeed" property
897 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED );
898 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
899 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
900 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
902 // Test "minimumSwipeDistance" property
903 DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE );
904 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
905 view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
906 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
908 // Test "wheelScrollDistanceStep" property
909 DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP );
910 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
911 view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
912 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
914 // Test "snapToItemEnabled" property
915 DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED );
916 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
917 view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
918 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
920 // Test "refreshInterval" property
921 DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL );
922 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
923 view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
924 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
926 // Test "overshootEnabled" property
927 DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED );
928 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
929 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
930 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
932 // Animatable properties
934 // Test "layoutPosition" property
935 DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION );
936 view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
938 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
940 // Test "scrollSpeed" property
941 DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED );
942 view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
944 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
946 // Test "overshoot" property
947 DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT );
948 view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
950 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
952 // Test "scrollDirection" property
953 DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION );
954 view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
956 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
958 // Test "layoutOrientation" property
959 DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION );
960 view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
962 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
964 // Test "scrollContentSize" property
965 DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE );
966 view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
968 DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
974 int UtcDaliItemViewOvershootVertical(void)
976 ToolkitTestApplication application;
977 Dali::Stage stage = Dali::Stage::GetCurrent();
979 // Create the ItemView actor
980 TestItemFactory factory;
981 ItemView view = ItemView::New(factory);
983 // Create a grid layout and add it to ItemView
984 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
985 view.AddLayout(*gridLayout);
988 // Activate the grid layout so that the items will be created and added to ItemView
989 Vector3 stageSize(stage.GetSize());
990 view.ActivateLayout(0, stageSize, 0.5f);
992 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
993 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
995 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
999 // Do a pan starting from 100,100 and moving down
1000 Vector2 pos(100.0f, 100.0f);
1001 SendPan(application, Gesture::Possible, pos);
1002 SendPan(application, Gesture::Started, pos);
1004 Wait(application, 100);
1006 for(int i = 0;i<200;i++)
1008 SendPan(application, Gesture::Continuing, pos);
1013 SendPan(application, Gesture::Finished, pos);
1014 Wait(application, 100);
1016 // Do a pan starting from 100,100 and moving up
1017 pos = Vector2(100.0f, 300.0f);
1018 SendPan(application, Gesture::Possible, pos);
1019 SendPan(application, Gesture::Started, pos);
1021 Wait(application, 100);
1023 for(int i = 0;i<200;i++)
1025 SendPan(application, Gesture::Continuing, pos);
1030 SendPan(application, Gesture::Finished, pos);
1031 Wait(application, 100);
1035 int UtcDaliItemViewOvershootHorizontal(void)
1037 ToolkitTestApplication application;
1038 Dali::Stage stage = Dali::Stage::GetCurrent();
1040 // Create the ItemView actor
1041 TestItemFactory factory;
1042 ItemView view = ItemView::New(factory);
1044 // Create a grid layout and add it to ItemView
1045 ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1046 view.AddLayout(*gridLayout);
1049 // Activate the grid layout so that the items will be created and added to ItemView
1050 Vector3 stageSize(stage.GetSize());
1051 view.ActivateLayout(0, stageSize, 0.5f);
1053 view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1054 DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1056 view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1060 // Do a pan starting from 100,100 and moving left
1061 Vector2 pos(100.0f, 100.0f);
1062 SendPan(application, Gesture::Possible, pos);
1063 SendPan(application, Gesture::Started, pos);
1065 Wait(application, 100);
1067 for(int i = 0;i<200;i++)
1069 SendPan(application, Gesture::Continuing, pos);
1074 SendPan(application, Gesture::Finished, pos);
1075 Wait(application, 100);
1077 // Do a pan starting from 100,100 and moving right
1078 pos = Vector2(100.0f, 100.0f);
1079 SendPan(application, Gesture::Possible, pos);
1080 SendPan(application, Gesture::Started, pos);
1082 Wait(application, 100);
1084 for(int i = 0;i<200;i++)
1086 SendPan(application, Gesture::Continuing, pos);
1091 SendPan(application, Gesture::Finished, pos);
1092 Wait(application, 100);