Merge "Controls are LayoutGroups instead of LayoutItems" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ItemView.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <float.h>       // for FLT_MAX
21
22 // Need to override adaptor classes for toolkit test harness, so include
23 // test harness headers before dali headers.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 void utc_dali_toolkit_item_view_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_item_view_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44
45 const unsigned int TOTAL_ITEM_NUMBER = 400;
46 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
47
48 const int RENDER_FRAME_INTERVAL = 16;                     ///< Duration of each frame in ms. (at approx 60FPS)
49
50 static bool gObjectCreatedCallBackCalled;
51 static bool gOnLayoutActivatedCalled;                     ///< Whether the LayoutActivated signal was invoked.
52 static bool gOnScrollUpdateCalled;
53
54 static void TestCallback(BaseHandle handle)
55 {
56   gObjectCreatedCallBackCalled = true;
57 }
58
59 static void OnLayoutActivated()
60 {
61   gOnLayoutActivatedCalled = true;
62 }
63
64 static void OnScrollUpdate( const Vector2& position )
65 {
66   gOnScrollUpdateCalled = true;
67 }
68
69 // Generate a PanGestureEvent to send to Core
70 Integration::PanGestureEvent GeneratePan(
71     Gesture::State state,
72     const Vector2& previousPosition,
73     const Vector2& currentPosition,
74     unsigned long timeDelta,
75     unsigned int numberOfTouches = 1)
76 {
77   Integration::PanGestureEvent pan(state);
78
79   pan.previousPosition = previousPosition;
80   pan.currentPosition = currentPosition;
81   pan.timeDelta = timeDelta;
82   pan.numberOfTouches = numberOfTouches;
83
84   return pan;
85 }
86
87 /**
88  * Helper to generate PanGestureEvent
89  *
90  * @param[in] application Application instance
91  * @param[in] state The Gesture State
92  * @param[in] pos The current position of touch.
93  */
94 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
95 {
96   static Vector2 last;
97
98   if( (state == Gesture::Started) ||
99       (state == Gesture::Possible) )
100   {
101     last.x = pos.x;
102     last.y = pos.y;
103   }
104
105   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
106
107   last.x = pos.x;
108   last.y = pos.y;
109 }
110
111 /*
112  * Simulate time passed by.
113  *
114  * @note this will always process at least 1 frame (1/60 sec)
115  *
116  * @param application Test application instance
117  * @param duration Time to pass in milliseconds.
118  * @return The actual time passed in milliseconds
119  */
120 int Wait(ToolkitTestApplication& application, int duration = 0)
121 {
122   int time = 0;
123
124   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
125   {
126     application.SendNotification();
127     application.Render(RENDER_FRAME_INTERVAL);
128     time += RENDER_FRAME_INTERVAL;
129   }
130
131   return time;
132 }
133
134 // Implementation of ItemFactory for providing actors to ItemView
135 class TestItemFactory : public ItemFactory
136 {
137 public:
138
139   /**
140    * Constructor
141    * @param application class, stored as reference
142    */
143   TestItemFactory()
144   {
145   }
146
147 public: // From ItemFactory
148
149   /**
150    * Query the number of items available from the factory.
151    * The maximum available item has an ID of GetNumberOfItems() - 1.
152    */
153   virtual unsigned int GetNumberOfItems()
154   {
155     return TOTAL_ITEM_NUMBER;
156   }
157
158   /**
159    * Create an Actor to represent a visible item.
160    * @param itemId
161    * @return the created actor.
162    */
163   virtual Actor NewItem(unsigned int itemId)
164   {
165     // Create a renderable actor for this item
166     Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
167     Actor actor = CreateRenderableActor(image);
168
169     return actor;
170   }
171 };
172
173 } // namespace
174
175
176 int UtcDaliItemViewNew(void)
177 {
178   ToolkitTestApplication application;
179
180   // Create the ItemView actor
181   TestItemFactory factory;
182   ItemView view = ItemView::New(factory);
183
184   DALI_TEST_CHECK(view);
185
186   //Additional check to ensure object is created by checking if it's registered
187   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
188   DALI_TEST_CHECK( registry );
189
190   gObjectCreatedCallBackCalled = false;
191   registry.ObjectCreatedSignal().Connect(&TestCallback);
192   {
193     TestItemFactory factory;
194     ItemView view = ItemView::New(factory);
195   }
196   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
197   END_TEST;
198 }
199
200 int UtcDaliItemViewDownCast(void)
201 {
202   ToolkitTestApplication application;
203
204   // Create the ItemView actor
205   TestItemFactory factory;
206   const ItemView itemViewConst = ItemView::New(factory);
207   ItemView itemView(itemViewConst);
208
209   BaseHandle handle(itemView);
210
211   ItemView newItemView = ItemView::DownCast( handle );
212   DALI_TEST_CHECK( itemView );
213   DALI_TEST_CHECK( newItemView == itemView );
214   END_TEST;
215 }
216
217 int UtcDaliItemViewAddAndGetLayout(void)
218 {
219   ToolkitTestApplication application;
220
221   // Create the ItemView actor
222   TestItemFactory factory;
223   ItemView view = ItemView::New(factory);
224
225   // Create a grid layout and add it to ItemView
226   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
227   view.AddLayout(*gridLayout);
228
229   // As we have added one layout, check the number of layout is now 1
230   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
231
232   // Create a depth layout and add it to ItemView
233   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
234   view.AddLayout(*depthLayout);
235
236   // As we have added another layout, check the number of layout is now 2
237   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
238
239   // Create a spiral layout and add it to ItemView
240   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
241   view.AddLayout(*spiralLayout);
242
243   // As we have added another layout, check the number of layout is now 3
244   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
245
246   // Check we are getting the correct layout from ItemView
247   DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
248   DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
249   DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
250   END_TEST;
251 }
252
253 int UtcDaliItemViewAddAndRemoveLayout(void)
254 {
255   ToolkitTestApplication application;
256
257   // Create the ItemView actor
258   TestItemFactory factory;
259   ItemView view = ItemView::New(factory);
260
261   // Create a grid layout and add it to ItemView
262   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
263   view.AddLayout(*gridLayout);
264
265   // As we have added one layout, check the number of layout is now 1
266   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
267
268   // Create a depth layout and add it to ItemView
269   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
270   view.AddLayout(*depthLayout);
271
272   // As we have added another layout, check the number of layout is now 2
273   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
274
275   // Check we are getting the correct layout from ItemView
276   DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
277   DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
278
279   // Remove the grid layout
280   view.RemoveLayout(0);
281
282   // As we have removed the grid layout, check the number of layout is now 1
283   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
284
285   // Check we are getting the correct layout from ItemView
286   DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
287
288   // Remove the depth layout
289   view.RemoveLayout(0);
290
291   // As we also removed the depth layout, check the number of layout is now 0
292   DALI_TEST_CHECK(view.GetLayoutCount() == 0);
293   END_TEST;
294 }
295
296 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
297 {
298   ToolkitTestApplication application;
299
300   // Create the ItemView actor
301   TestItemFactory factory;
302   ItemView view = ItemView::New(factory);
303
304   // Create a grid layout and add it to ItemView
305   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
306   view.AddLayout(*gridLayout);
307
308   // Create a depth layout and add it to ItemView
309   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
310   view.AddLayout(*depthLayout);
311
312   // Create a spiral layout and add it to ItemView
313   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
314   view.AddLayout(*spiralLayout);
315
316   // As we have added three layouts, check the number of layout is now 3
317   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
318
319   // Check there is no active layout at the moment
320   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
321
322   // Activate the depth layout
323   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
324   view.ActivateLayout(1, stageSize, 0.5f);
325
326   // Check the current active layout is the depth layout
327   DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
328
329   // Activate the grid layout
330   view.ActivateLayout(0, stageSize, 0.5f);
331
332   // Check the current active layout is the grid layout
333   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
334
335   // Activate the spiral layout
336   view.ActivateLayout(2, stageSize, 0.5f);
337
338   // Check the current active layout is the spiral layout
339   DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
340   END_TEST;
341 }
342
343 int UtcDaliItemViewDeactivateCurrentLayout(void)
344 {
345   ToolkitTestApplication application;
346
347   // Create the ItemView actor
348   TestItemFactory factory;
349   ItemView view = ItemView::New(factory);
350
351   // Create a grid layout and add it to ItemView
352   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
353   gridLayout->SetOrientation(ControlOrientation::Down);
354   view.AddLayout(*gridLayout);
355
356   // Check there is no active layout at the moment
357   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
358
359   // Activate the grid layout
360   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
361   view.ActivateLayout(0, stageSize, 0.5f);
362
363   // Check the current active layout is the grid layout
364   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
365
366   // Deactivate the current layout
367   view.DeactivateCurrentLayout();
368
369   // Check there is no active layout at the moment
370   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
371   END_TEST;
372 }
373
374 int UtcDaliItemViewGetItemAndGetItemId(void)
375 {
376   ToolkitTestApplication application;
377
378   // Create the ItemView actor
379   TestItemFactory factory;
380   ItemView view = ItemView::New(factory);
381
382   // Create a grid layout and add it to ItemView
383   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
384   gridLayout->SetOrientation(ControlOrientation::Left);
385   view.AddLayout(*gridLayout);
386
387   // Activate the grid layout so that the items will be created and added to ItemView
388   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
389   view.ActivateLayout(0, stageSize, 0.5f);
390
391   // Get the item given the item ID
392   Actor itemActor = view.GetItem(2);
393
394   // Check we are getting the correct Item ID given the specified actor
395   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
396   END_TEST;
397 }
398
399 int UtcDaliItemViewRemoveItem(void)
400 {
401   ToolkitTestApplication application;
402
403   // Create the ItemView actor
404   TestItemFactory factory;
405   ItemView view = ItemView::New(factory);
406
407   // Create a grid layout and add it to ItemView
408   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
409   gridLayout->SetOrientation(ControlOrientation::Right);
410   view.AddLayout(*gridLayout);
411
412   // Activate the grid layout so that the items will be created and added to ItemView
413   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
414   view.ActivateLayout(0, stageSize, 0.5f);
415
416   // Get the item given the item ID 2 and 3
417   Actor oldItemActorID2 = view.GetItem(2);
418   Actor oldItemActorID3 = view.GetItem(3);
419
420   // Remove the item with ID 2
421   view.RemoveItem(2, 0.0f);
422
423   // Get the new item given the item ID 2 and 3
424   Actor newItemActorID2 = view.GetItem(2);
425   Actor newItemActorID3 = view.GetItem(3);
426
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);
431
432   // scroll to the end of item view
433   view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
434
435   application.SendNotification();
436   application.Render(0);
437
438   // Refresh the item view
439   view.Refresh();
440
441   Actor itemActorID390 = view.GetItem(390);
442   DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
443
444   // Remove the item with ID 2 (which is now before the current item range)
445   view.RemoveItem(2, 0.0f);
446
447   // Check the original item with item ID 2 was deleted and now item ID 389 represents the original item with ID 390
448   DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 389);
449   DALI_TEST_CHECK(view.GetItem(389) == itemActorID390);
450
451   END_TEST;
452 }
453
454 int UtcDaliItemViewGetCurrentLayoutPosition(void)
455 {
456   ToolkitTestApplication application;
457
458   // Create the ItemView actor
459   TestItemFactory factory;
460   ItemView view = ItemView::New(factory);
461
462   // Create a depth layout and add it to ItemView
463   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
464   depthLayout->SetOrientation(ControlOrientation::Up);
465   view.AddLayout(*depthLayout);
466
467   // Activate the grid layout so that the items will be created and added to ItemView
468   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
469   view.ActivateLayout(0, stageSize, 0.0f);
470
471   // Check the current layout position for the 10th items is 9.0f
472   DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
473   END_TEST;
474 }
475
476 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
477 {
478   ToolkitTestApplication application;
479
480   // Create the ItemView actor
481   TestItemFactory factory;
482   ItemView view = ItemView::New(factory);
483
484   // Set the minimum swipe speed to be 1.5f
485   view.SetMinimumSwipeSpeed(1.5f);
486
487   // Check the minimum swipe speed is 1.5f
488   DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
489   END_TEST;
490 }
491
492 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
493 {
494   ToolkitTestApplication application;
495
496   // Create the ItemView actor
497   TestItemFactory factory;
498   ItemView view = ItemView::New(factory);
499
500   // Set the minimum swipe distance to be 2.5f
501   view.SetMinimumSwipeDistance(2.5f);
502
503   // Check the minimum swipe distance is 2.5f
504   DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
505   END_TEST;
506 }
507
508 int UtcDaliItemViewSetAndGetAnchoring(void)
509 {
510   ToolkitTestApplication application;
511
512   // Create the ItemView actor
513   TestItemFactory factory;
514   ItemView view = ItemView::New(factory);
515
516   // Disable the anchor animation
517   view.SetAnchoring(false);
518
519   // Check the anchor animation is disabled
520   DALI_TEST_CHECK(view.GetAnchoring() == false);
521   END_TEST;
522 }
523
524 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
525 {
526   ToolkitTestApplication application;
527
528   // Create the ItemView actor
529   TestItemFactory factory;
530   ItemView view = ItemView::New(factory);
531
532   // Set the duration of anchor animation to be 1.5f
533   view.SetAnchoringDuration(1.5f);
534
535   // Check the duration of anchor animation is 1.5f
536   DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
537   END_TEST;
538 }
539
540 int UtcDaliItemViewSetAndGetRefreshInterval(void)
541 {
542   ToolkitTestApplication application;
543
544   // Create the ItemView actor
545   TestItemFactory factory;
546   ItemView view = ItemView::New(factory);
547
548   // Set the interval between refreshes to be 20
549   view.SetRefreshInterval(20);
550
551   view.Refresh();
552
553   // Check the interval between refreshes is 20
554   DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
555   END_TEST;
556 }
557
558 int UtcDaliItemViewScrollToItem(void)
559 {
560   ToolkitTestApplication application;
561
562   // Create the ItemView actor
563   TestItemFactory factory;
564   ItemView view = ItemView::New(factory);
565   Vector3 vec(480.0f, 800.0f, 0.0f);
566   ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
567
568   view.SetName("view actor");
569   view.AddLayout(*layout);
570   view.SetSize(vec);
571
572   Stage::GetCurrent().Add(view);
573   layout->SetOrientation(ControlOrientation::Down);
574   view.ActivateLayout(0, vec, 0.0f);
575
576   application.SendNotification();
577   application.Render(0);
578
579   // render 10 frames
580   for(int i = 0; i < 10; ++i)
581   {
582     application.Render(16); // 60hz frames
583   }
584
585   // Confirm: we have actors in the view.
586   std::vector<unsigned int> indices;
587   for(unsigned int i = 0; i < 10; i++)
588   {
589     Actor testActor = view.GetItem(i);
590     if (testActor)
591     {
592       indices.push_back(i);
593     }
594   }
595
596   try
597   {
598     if (!indices.empty())
599     {
600       const unsigned int firstTargetIndex = indices[indices.size()-1];
601       // scroll to last item
602       view.ScrollToItem(firstTargetIndex, 0.00f);
603       for(int i = 0; i < 10; ++i)
604       {
605         application.Render(16); // 60hz frames
606       }
607
608       std::size_t moveCount = 0;
609       for(std::size_t i = 0; i < indices.size(); i++)
610       {
611         float layoutPosBefore = view.GetCurrentLayoutPosition(i);
612         view.ScrollToItem(indices[i], 0.0f);
613         float layoutPosAfter = view.GetCurrentLayoutPosition(i);
614
615         if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
616         {
617           ++moveCount;
618         }
619       }
620
621       DALI_TEST_CHECK((moveCount == indices.size()));
622     }
623   }
624   catch(...)
625   {
626     tet_result(TET_FAIL);
627   }
628
629   Stage::GetCurrent().Remove(view);
630   END_TEST;
631 }
632
633 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
634 {
635   ToolkitTestApplication application;
636
637   // Create the ItemView actor
638   TestItemFactory factory;
639   ItemView view = ItemView::New(factory);
640
641   // Set the scroll distance step for the wheel event to be 100.0f
642   view.SetWheelScrollDistanceStep(100.0f);
643
644   // Check the scroll distance step is 100.0f
645   DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
646   END_TEST;
647 }
648
649 int UtcDaliItemViewInsertItemP(void)
650 {
651   ToolkitTestApplication application;
652
653   // Create the ItemView actor
654   TestItemFactory factory;
655   ItemView view = ItemView::New(factory);
656
657   // Create a grid layout and add it to ItemView
658   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID);
659   gridLayout->SetOrientation(ControlOrientation::Left);
660   view.AddLayout(*gridLayout);
661
662   // Activate the grid layout so that the items will be created and added to ItemView
663   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
664   view.ActivateLayout(0, stageSize, 0.0f);
665
666   // Get the specified item where new item to be inserted before that
667   Actor itemActor = view.GetItem(2);
668
669   ItemId id = view.GetItemId( itemActor );
670
671   // Check we are getting the correct Item ID given the specified actor
672   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
673
674   Actor newActor = Actor::New();
675
676   view.InsertItem(Item(id, newActor), 0.0f);
677
678   DALI_TEST_CHECK(view.GetItem(2) == newActor);
679
680   DALI_TEST_CHECK(view.GetItemId(itemActor) == 3);
681   DALI_TEST_CHECK(view.GetItem(3) == itemActor);
682
683   // scroll to the end of item view
684   view.ScrollToItem(TOTAL_ITEM_NUMBER - 1, 0.00f);
685
686   application.SendNotification();
687   application.Render(0);
688
689   // Refresh the item view
690   view.Refresh();
691
692   Actor itemActorID390 = view.GetItem(390);
693   DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 390);
694
695   // Insert the item with ID 2 (which is now before the current item range)
696   Actor anotherNewActor = Actor::New();
697   view.InsertItem(Item(id, anotherNewActor), 0.0f);
698
699   // Check that item ID 391 now represents the original item with ID 390
700   DALI_TEST_CHECK(view.GetItemId(itemActorID390) == 391);
701   DALI_TEST_CHECK(view.GetItem(391) == itemActorID390);
702
703   END_TEST;
704 }
705
706 int UtcDaliItemViewInsertItemsP(void)
707 {
708   ToolkitTestApplication application;
709
710   // Create the ItemView actor
711   TestItemFactory factory;
712   ItemView view = ItemView::New(factory);
713
714   // Create a depth layout and add it to ItemView
715   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
716   depthLayout->SetOrientation(ControlOrientation::Right);
717   view.AddLayout(*depthLayout);
718
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);
722
723   unsigned int itemCount = view.GetChildCount();
724
725   // Get the specified item where new items to be inserted before that
726   Actor itemActor = view.GetItem(1);
727
728   // Check we are getting the correct Item ID given the specified item
729   DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
730
731   ItemContainer insertList;
732
733   for( unsigned int i = 1u; i < 11; ++i )
734   {
735     Actor child = view.GetChildAt( i );
736     Actor newActor = Actor::New();
737     newActor.SetName("Inserted");
738     insertList.push_back( Item( view.GetItemId(child), newActor ) );
739   }
740
741   if( !insertList.empty() )
742   {
743     view.InsertItems( insertList, 0.5f );
744   }
745
746   DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
747
748   // Check that new items are inserted in the correct positions
749   DALI_TEST_CHECK(view.GetItemId(itemActor) == 11);
750   DALI_TEST_CHECK(view.GetItem(11) == itemActor);
751
752   ItemIdContainer removeList;
753
754   for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
755   {
756     Actor child = view.GetChildAt( i );
757
758     if( child.GetName() == "Inserted" )
759     {
760       removeList.push_back( view.GetItemId(child) );
761     }
762   }
763
764   if( ! removeList.empty() )
765   {
766     view.RemoveItems( removeList, 0.5f );
767   }
768
769   DALI_TEST_CHECK(view.GetChildCount() == itemCount);
770
771   // Check that new items are removed correctly so that we are getting the correct Item ID given the specified item
772   DALI_TEST_CHECK(view.GetItemId(itemActor) == 1);
773   DALI_TEST_CHECK(view.GetItem(1) == itemActor);
774
775   END_TEST;
776 }
777
778 int UtcDaliItemViewReplaceItemP(void)
779 {
780   ToolkitTestApplication application;
781
782   // Create the ItemView actor
783   TestItemFactory factory;
784   ItemView view = ItemView::New(factory);
785
786   // Create a spiral layout and add it to ItemView
787   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
788   view.AddLayout(*spiralLayout);
789
790   // Activate the grid layout so that the items will be created and added to ItemView
791   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
792   view.ActivateLayout(0, stageSize, 0.5f);
793
794   Actor newActor = Actor::New();
795
796   view.ReplaceItem( Item( 5, newActor ), 0.5f );
797
798   DALI_TEST_CHECK(view.GetItem(5) == newActor);
799
800   END_TEST;
801 }
802
803 int UtcDaliItemViewReplaceItemsP(void)
804 {
805   ToolkitTestApplication application;
806
807   // Create the ItemView actor
808   TestItemFactory factory;
809   ItemView view = ItemView::New(factory);
810
811   // Create a spiral layout and add it to ItemView
812   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
813   spiralLayout->SetOrientation( ControlOrientation::Down );
814   view.AddLayout(*spiralLayout);
815
816   // Activate the grid layout so that the items will be created and added to ItemView
817   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
818   view.ActivateLayout(0, stageSize, 0.5f);
819
820   ItemContainer replaceList;
821
822   for( unsigned int i = 0u; i < 10; ++i )
823   {
824     Actor child = view.GetItem( i );
825     Actor newActor = Actor::New();
826     newActor.SetName("Replaced");
827
828     replaceList.push_back( Item( i, newActor ) );
829   }
830
831   if( !replaceList.empty() )
832   {
833     view.ReplaceItems( replaceList, 0.5f );
834   }
835
836   DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
837   DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
838   END_TEST;
839 }
840
841 int UtcDaliItemViewGetItemsRangeP(void)
842 {
843   ToolkitTestApplication application;
844
845   // Create the ItemView actor
846   TestItemFactory factory;
847   ItemView view = ItemView::New(factory);
848
849   // Create a spiral layout and add it to ItemView
850   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
851   spiralLayout->SetOrientation( ControlOrientation::Left );
852   view.AddLayout(*spiralLayout);
853
854   // Activate the grid layout so that the items will be created and added to ItemView
855   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
856   view.ActivateLayout(0, stageSize, 0.5f);
857
858   ItemRange itemRange(0, 0);
859
860   view.GetItemsRange(itemRange);
861
862   DALI_TEST_CHECK(itemRange.Within(0));
863   END_TEST;
864 }
865
866 int UtcDaliItemViewSetItemsAnchorPointP(void)
867 {
868   ToolkitTestApplication application;
869
870   // Create the ItemView actor
871   TestItemFactory factory;
872   ItemView view = ItemView::New(factory);
873
874   // Create a spiral layout and add it to ItemView
875   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
876   spiralLayout->SetOrientation( ControlOrientation::Right );
877   view.AddLayout(*spiralLayout);
878
879   // Activate the grid layout so that the items will be created and added to ItemView
880   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
881   view.ActivateLayout(0, stageSize, 0.5f);
882
883   Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
884
885   view.SetItemsAnchorPoint(anchorPoint);
886
887   DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
888   DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
889   END_TEST;
890 }
891
892 int UtcDaliItemViewSetItemsParentOriginP(void)
893 {
894   ToolkitTestApplication application;
895
896   // Create the ItemView actor
897   TestItemFactory factory;
898   ItemView view = ItemView::New(factory);
899
900   // Create a grid layout and add it to ItemView
901   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
902   view.AddLayout(*gridLayout);
903
904   // Activate the grid layout so that the items will be created and added to ItemView
905   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
906   view.ActivateLayout(0, stageSize, 0.5f);
907
908   Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
909
910   view.SetItemsParentOrigin(parentOrigin);
911
912   DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
913   DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
914   END_TEST;
915 }
916
917 int UtcDaliItemFactoryGetExtention(void)
918 {
919   ToolkitTestApplication application;
920   TestItemFactory factory;
921   DALI_TEST_CHECK( factory.GetExtension() == NULL );
922   END_TEST;
923 }
924
925 int UtcDaliItemViewLayoutActivatedSignalP(void)
926 {
927   ToolkitTestApplication application;
928
929   // Create the ItemView actor
930   TestItemFactory factory;
931   ItemView view = ItemView::New(factory);
932
933   // Create a grid layout and add it to ItemView
934   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
935   view.AddLayout(*gridLayout);
936
937   Stage::GetCurrent().Add( view );
938
939   // Connect the layout activated signal
940   view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
941
942   gOnLayoutActivatedCalled = false;
943
944   // Render and notify
945   application.SendNotification();
946   application.Render();
947
948   // Activate the grid layout so that the items will be created and added to ItemView
949   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
950   view.ActivateLayout(0, stageSize, 0.1f);
951
952   // Wait for 0.1 second
953   Wait(application, 100);
954
955   DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
956
957   END_TEST;
958 }
959
960 int UtcDaliItemViewSetGetProperty(void)
961 {
962   ToolkitTestApplication application;
963
964   // Create the ItemView actor
965   TestItemFactory factory;
966   ItemView view = ItemView::New(factory);
967   DALI_TEST_CHECK(view);
968
969   // Event side properties
970
971   // Test "minimumSwipeSpeed" property
972   DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED  );
973   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
974   view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
975   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
976
977   // Test "minimumSwipeDistance" property
978   DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE  );
979   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
980   view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
981   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
982
983   // Test "wheelScrollDistanceStep" property
984   DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP  );
985   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
986   view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
987   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
988
989   // Test "snapToItemEnabled" property
990   DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED  );
991   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
992   view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
993   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
994
995   // Test "refreshInterval" property
996   DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL  );
997   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
998   view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
999   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
1000
1001   // Test "layout" property
1002   DALI_TEST_CHECK( view.GetPropertyIndex("layout") == ItemView::Property::LAYOUT  );
1003   Property::Map gridLayoutProperty;
1004   gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
1005   gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
1006   gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
1007   gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
1008
1009   Property::Map depthLayoutProperty;
1010   depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
1011   depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
1012   depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
1013
1014   Property::Map spiralLayoutPrperty;
1015   spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
1016   spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
1017   spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
1018
1019   Property::Map listLayoutPrperty;
1020   listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
1021   listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
1022
1023
1024   Property::Array layoutArray;
1025   layoutArray.PushBack(gridLayoutProperty);
1026   layoutArray.PushBack(depthLayoutProperty);
1027   layoutArray.PushBack(spiralLayoutPrperty);
1028   layoutArray.PushBack(listLayoutPrperty);
1029
1030   view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1031
1032   Property::Array getLayoutArray;
1033   DALI_TEST_CHECK( view.GetProperty( ItemView::Property::LAYOUT ).Get( getLayoutArray ) );
1034
1035   //Check that the result is the same as
1036   DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
1037   Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
1038
1039   for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
1040   {
1041     KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
1042     if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
1043     {
1044       int layoutType = propertyPair.second.Get<int>();
1045       DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
1046     }
1047     else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
1048     {
1049       Vector3 size = propertyPair.second.Get<Vector3>();
1050       DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
1051     }
1052     else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
1053     {
1054       float spacing = propertyPair.second.Get<float>();
1055       DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
1056     }
1057     else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
1058     {
1059       int number = propertyPair.second.Get<int>();
1060       DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
1061     }
1062   }
1063   view.SetProperty( ItemView::Property::LAYOUT, layoutArray);
1064
1065
1066   // Test "overshootEnabled" property
1067   DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED  );
1068   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
1069   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
1070   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
1071
1072   // Test "overshootSize" property
1073   DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE  );
1074   Vector2 overshootSize = Vector2(100.0f,100.0f);
1075   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
1076   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
1077
1078   // Animatable properties
1079
1080   // Test "layoutPosition" property
1081   DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION  );
1082   view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
1083   Wait(application);
1084   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
1085
1086   // Test "scrollSpeed" property
1087   DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED  );
1088   view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
1089   Wait(application);
1090   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
1091
1092   // Test "overshoot" property
1093   DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT  );
1094   view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
1095   Wait(application);
1096   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
1097
1098   // Test "scrollDirection" property
1099   DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION  );
1100   view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
1101   Wait(application);
1102   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
1103
1104   // Test "layoutOrientation" property
1105   DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION  );
1106   view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
1107   Wait(application);
1108   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
1109
1110   // Test "scrollContentSize" property
1111   DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE  );
1112   view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
1113   Wait(application);
1114   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
1115
1116   END_TEST;
1117 }
1118
1119
1120 int UtcDaliItemViewOvershootVertical(void)
1121 {
1122   ToolkitTestApplication application;
1123   Dali::Stage stage = Dali::Stage::GetCurrent();
1124
1125   // Create the ItemView actor
1126   TestItemFactory factory;
1127   ItemView view = ItemView::New(factory);
1128
1129   // Create a grid layout and add it to ItemView
1130   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1131   view.AddLayout(*gridLayout);
1132   stage.Add(view);
1133
1134   // Activate the grid layout so that the items will be created and added to ItemView
1135   Vector3 stageSize(stage.GetSize());
1136   view.ActivateLayout(0, stageSize, 0.5f);
1137
1138   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1139   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1140
1141   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1142
1143   Wait(application);
1144
1145   // Do a pan starting from 100,100 and moving down
1146   Vector2 pos(100.0f, 100.0f);
1147   SendPan(application, Gesture::Possible, pos);
1148   SendPan(application, Gesture::Started, pos);
1149   pos.y += 5.0f;
1150   Wait(application, 100);
1151
1152   for(int i = 0;i<200;i++)
1153   {
1154     SendPan(application, Gesture::Continuing, pos);
1155     pos.y += 5.0f;
1156     Wait(application);
1157   }
1158
1159   SendPan(application, Gesture::Finished, pos);
1160   Wait(application, 100);
1161
1162   // Do a pan starting from 100,100 and moving up
1163   pos = Vector2(100.0f, 300.0f);
1164   SendPan(application, Gesture::Possible, pos);
1165   SendPan(application, Gesture::Started, pos);
1166   pos.y -= 5.0f;
1167   Wait(application, 100);
1168
1169   for(int i = 0;i<200;i++)
1170   {
1171     SendPan(application, Gesture::Continuing, pos);
1172     pos.y -= 5.0f;
1173     Wait(application);
1174   }
1175
1176   SendPan(application, Gesture::Finished, pos);
1177   Wait(application, 100);
1178   END_TEST;
1179 }
1180
1181 int UtcDaliItemViewOvershootHorizontal(void)
1182 {
1183   ToolkitTestApplication application;
1184   Dali::Stage stage = Dali::Stage::GetCurrent();
1185
1186   // Create the ItemView actor
1187   TestItemFactory factory;
1188   ItemView view = ItemView::New(factory);
1189
1190   // Create a grid layout and add it to ItemView
1191   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1192   view.AddLayout(*gridLayout);
1193   stage.Add(view);
1194
1195   // Activate the grid layout so that the items will be created and added to ItemView
1196   Vector3 stageSize(stage.GetSize());
1197   view.ActivateLayout(0, stageSize, 0.5f);
1198
1199   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1200   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1201
1202   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1203
1204   Wait(application);
1205
1206   // Do a pan starting from 100,100 and moving left
1207   Vector2 pos(100.0f, 100.0f);
1208   SendPan(application, Gesture::Possible, pos);
1209   SendPan(application, Gesture::Started, pos);
1210   pos.x -= 5.0f;
1211   Wait(application, 100);
1212
1213   for(int i = 0;i<200;i++)
1214   {
1215     SendPan(application, Gesture::Continuing, pos);
1216     pos.x -= 5.0f;
1217     Wait(application);
1218   }
1219
1220   SendPan(application, Gesture::Finished, pos);
1221   Wait(application, 100);
1222
1223   // Do a pan starting from 100,100 and moving right
1224   pos = Vector2(100.0f, 100.0f);
1225   SendPan(application, Gesture::Possible, pos);
1226   SendPan(application, Gesture::Started, pos);
1227   pos.x += 5.0f;
1228   Wait(application, 100);
1229
1230   for(int i = 0;i<200;i++)
1231   {
1232     SendPan(application, Gesture::Continuing, pos);
1233     pos.x += 5.0f;
1234     Wait(application);
1235   }
1236
1237   SendPan(application, Gesture::Finished, pos);
1238   Wait(application, 100);
1239
1240   END_TEST;
1241 }
1242
1243 int UtcDaliItemEnableDisableRefresh(void)
1244 {
1245   ToolkitTestApplication application;
1246   Dali::Stage stage = Dali::Stage::GetCurrent();
1247
1248   // Create the ItemView actor
1249   TestItemFactory factory;
1250   ItemView view = ItemView::New(factory);
1251
1252   // Create a grid layout and add it to ItemView
1253   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
1254   view.AddLayout(*gridLayout);
1255   stage.Add(view);
1256
1257   // Activate the grid layout so that the items will be created and added to ItemView
1258   Vector3 stageSize(stage.GetSize());
1259   view.ActivateLayout(0, stageSize, 0.5f);
1260
1261   //Connect to signal scroll updated
1262   view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
1263
1264   Property::Map attributes;
1265   view.DoAction("enableRefresh", attributes );
1266   gOnScrollUpdateCalled = true;
1267   view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1268   application.SendNotification();
1269   application.Render(1000);
1270   DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
1271
1272
1273   view.DoAction("disableRefresh", attributes );
1274   gOnScrollUpdateCalled = false;
1275   view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
1276   application.SendNotification();
1277   application.Render(1000);
1278
1279   DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );
1280
1281   END_TEST;
1282 }