Merge "Updated Gradient renderer to use SetTexture" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ItemView.cpp
1 /*
2  * Copyright (c) 2014 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
30 using namespace Dali;
31 using namespace Toolkit;
32
33 void utc_dali_toolkit_item_view_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_item_view_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45
46 const unsigned int TOTAL_ITEM_NUMBER = 100;
47 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
48
49 const int RENDER_FRAME_INTERVAL = 16;                     ///< Duration of each frame in ms. (at approx 60FPS)
50
51 static bool gObjectCreatedCallBackCalled;
52 static bool gOnLayoutActivatedCalled;                     ///< Whether the LayoutActivated signal was invoked.
53
54 static void TestCallback(BaseHandle handle)
55 {
56   gObjectCreatedCallBackCalled = true;
57 }
58
59 static void OnLayoutActivated()
60 {
61   gOnLayoutActivatedCalled = true;
62 }
63
64 // Generate a PanGestureEvent to send to Core
65 Integration::PanGestureEvent GeneratePan(
66     Gesture::State state,
67     const Vector2& previousPosition,
68     const Vector2& currentPosition,
69     unsigned long timeDelta,
70     unsigned int numberOfTouches = 1)
71 {
72   Integration::PanGestureEvent pan(state);
73
74   pan.previousPosition = previousPosition;
75   pan.currentPosition = currentPosition;
76   pan.timeDelta = timeDelta;
77   pan.numberOfTouches = numberOfTouches;
78
79   return pan;
80 }
81
82 /**
83  * Helper to generate PanGestureEvent
84  *
85  * @param[in] application Application instance
86  * @param[in] state The Gesture State
87  * @param[in] pos The current position of touch.
88  */
89 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
90 {
91   static Vector2 last;
92
93   if( (state == Gesture::Started) ||
94       (state == Gesture::Possible) )
95   {
96     last.x = pos.x;
97     last.y = pos.y;
98   }
99
100   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
101
102   last.x = pos.x;
103   last.y = pos.y;
104 }
105
106 /*
107  * Simulate time passed by.
108  *
109  * @note this will always process at least 1 frame (1/60 sec)
110  *
111  * @param application Test application instance
112  * @param duration Time to pass in milliseconds.
113  * @return The actual time passed in milliseconds
114  */
115 int Wait(ToolkitTestApplication& application, int duration = 0)
116 {
117   int time = 0;
118
119   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
120   {
121     application.SendNotification();
122     application.Render(RENDER_FRAME_INTERVAL);
123     time += RENDER_FRAME_INTERVAL;
124   }
125
126   return time;
127 }
128
129 // Implementation of ItemFactory for providing actors to ItemView
130 class TestItemFactory : public ItemFactory
131 {
132 public:
133
134   /**
135    * Constructor
136    * @param application class, stored as reference
137    */
138   TestItemFactory()
139   {
140   }
141
142 public: // From ItemFactory
143
144   /**
145    * Query the number of items available from the factory.
146    * The maximum available item has an ID of GetNumberOfItems() - 1.
147    */
148   virtual unsigned int GetNumberOfItems()
149   {
150     return TOTAL_ITEM_NUMBER;
151   }
152
153   /**
154    * Create an Actor to represent a visible item.
155    * @param itemId
156    * @return the created actor.
157    */
158   virtual Actor NewItem(unsigned int itemId)
159   {
160     // Create a renderable actor for this item
161     Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
162     Actor actor = CreateRenderableActor(image);
163
164     return actor;
165   }
166 };
167
168 } // namespace
169
170
171 int UtcDaliItemViewNew(void)
172 {
173   ToolkitTestApplication application;
174
175   // Create the ItemView actor
176   TestItemFactory factory;
177   ItemView view = ItemView::New(factory);
178
179   DALI_TEST_CHECK(view);
180
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 );
184
185   gObjectCreatedCallBackCalled = false;
186   registry.ObjectCreatedSignal().Connect(&TestCallback);
187   {
188     TestItemFactory factory;
189     ItemView view = ItemView::New(factory);
190   }
191   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
192   END_TEST;
193 }
194
195 int UtcDaliItemViewDownCast(void)
196 {
197   ToolkitTestApplication application;
198
199   // Create the ItemView actor
200   TestItemFactory factory;
201   const ItemView itemViewConst = ItemView::New(factory);
202   ItemView itemView(itemViewConst);
203
204   BaseHandle handle(itemView);
205
206   ItemView newItemView = ItemView::DownCast( handle );
207   DALI_TEST_CHECK( itemView );
208   DALI_TEST_CHECK( newItemView == itemView );
209   END_TEST;
210 }
211
212 int UtcDaliItemViewAddAndGetLayout(void)
213 {
214   ToolkitTestApplication application;
215
216   // Create the ItemView actor
217   TestItemFactory factory;
218   ItemView view = ItemView::New(factory);
219
220   // Create a grid layout and add it to ItemView
221   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
222   view.AddLayout(*gridLayout);
223
224   // As we have added one layout, check the number of layout is now 1
225   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
226
227   // Create a depth layout and add it to ItemView
228   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
229   view.AddLayout(*depthLayout);
230
231   // As we have added another layout, check the number of layout is now 2
232   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
233
234   // Create a spiral layout and add it to ItemView
235   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
236   view.AddLayout(*spiralLayout);
237
238   // As we have added another layout, check the number of layout is now 3
239   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
240
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);
245   END_TEST;
246 }
247
248 int UtcDaliItemViewAddAndRemoveLayout(void)
249 {
250   ToolkitTestApplication application;
251
252   // Create the ItemView actor
253   TestItemFactory factory;
254   ItemView view = ItemView::New(factory);
255
256   // Create a grid layout and add it to ItemView
257   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
258   view.AddLayout(*gridLayout);
259
260   // As we have added one layout, check the number of layout is now 1
261   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
262
263   // Create a depth layout and add it to ItemView
264   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
265   view.AddLayout(*depthLayout);
266
267   // As we have added another layout, check the number of layout is now 2
268   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
269
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);
273
274   // Remove the grid layout
275   view.RemoveLayout(0);
276
277   // As we have removed the grid layout, check the number of layout is now 1
278   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
279
280   // Check we are getting the correct layout from ItemView
281   DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
282
283   // Remove the depth layout
284   view.RemoveLayout(0);
285
286   // As we also removed the depth layout, check the number of layout is now 0
287   DALI_TEST_CHECK(view.GetLayoutCount() == 0);
288   END_TEST;
289 }
290
291 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
292 {
293   ToolkitTestApplication application;
294
295   // Create the ItemView actor
296   TestItemFactory factory;
297   ItemView view = ItemView::New(factory);
298
299   // Create a grid layout and add it to ItemView
300   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
301   view.AddLayout(*gridLayout);
302
303   // Create a depth layout and add it to ItemView
304   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
305   view.AddLayout(*depthLayout);
306
307   // Create a spiral layout and add it to ItemView
308   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
309   view.AddLayout(*spiralLayout);
310
311   // As we have added three layouts, check the number of layout is now 3
312   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
313
314   // Check there is no active layout at the moment
315   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
316
317   // Activate the depth layout
318   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
319   view.ActivateLayout(1, stageSize, 0.5f);
320
321   // Check the current active layout is the depth layout
322   DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
323
324   // Activate the grid layout
325   view.ActivateLayout(0, stageSize, 0.5f);
326
327   // Check the current active layout is the grid layout
328   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
329
330   // Activate the spiral layout
331   view.ActivateLayout(2, stageSize, 0.5f);
332
333   // Check the current active layout is the spiral layout
334   DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
335   END_TEST;
336 }
337
338 int UtcDaliItemViewDeactivateCurrentLayout(void)
339 {
340   ToolkitTestApplication application;
341
342   // Create the ItemView actor
343   TestItemFactory factory;
344   ItemView view = ItemView::New(factory);
345
346   // Create a grid layout and add it to ItemView
347   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
348   view.AddLayout(*gridLayout);
349
350   // Check there is no active layout at the moment
351   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
352
353   // Activate the grid layout
354   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
355   view.ActivateLayout(0, stageSize, 0.5f);
356
357   // Check the current active layout is the grid layout
358   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
359
360   // Deactivate the current layout
361   view.DeactivateCurrentLayout();
362
363   // Check there is no active layout at the moment
364   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
365   END_TEST;
366 }
367
368 int UtcDaliItemViewGetItemAndGetItemId(void)
369 {
370   ToolkitTestApplication application;
371
372   // Create the ItemView actor
373   TestItemFactory factory;
374   ItemView view = ItemView::New(factory);
375
376   // Create a grid layout and add it to ItemView
377   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
378   view.AddLayout(*gridLayout);
379
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);
383
384   // Get the item given the item ID
385   Actor itemActor = view.GetItem(2);
386
387   // Check we are getting the correct Item ID given the specified actor
388   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
389   END_TEST;
390 }
391
392 int UtcDaliItemViewRemoveItem(void)
393 {
394   ToolkitTestApplication application;
395
396   // Create the ItemView actor
397   TestItemFactory factory;
398   ItemView view = ItemView::New(factory);
399
400   // Create a grid layout and add it to ItemView
401   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
402   view.AddLayout(*gridLayout);
403
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);
407
408   // Get the item given the item ID 2 and 3
409   Actor oldItemActorID2 = view.GetItem(2);
410   Actor oldItemActorID3 = view.GetItem(3);
411
412   // Remove the item with ID 2
413   view.RemoveItem(2, 0.0f);
414
415   // Get the new item given the item ID 2
416   Actor newItemActorID2 = view.GetItem(2);
417
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);
422   END_TEST;
423 }
424
425 int UtcDaliItemViewGetCurrentLayoutPosition(void)
426 {
427   ToolkitTestApplication application;
428
429   // Create the ItemView actor
430   TestItemFactory factory;
431   ItemView view = ItemView::New(factory);
432
433   // Create a grid layout and add it to ItemView
434   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
435   view.AddLayout(*gridLayout);
436
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);
440
441   // Check the current layout position for the 10th items is 9.0f
442   DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
443   END_TEST;
444 }
445
446 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
447 {
448   ToolkitTestApplication application;
449
450   // Create the ItemView actor
451   TestItemFactory factory;
452   ItemView view = ItemView::New(factory);
453
454   // Set the minimum swipe speed to be 1.5f
455   view.SetMinimumSwipeSpeed(1.5f);
456
457   // Check the minimum swipe speed is 1.5f
458   DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
459   END_TEST;
460 }
461
462 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
463 {
464   ToolkitTestApplication application;
465
466   // Create the ItemView actor
467   TestItemFactory factory;
468   ItemView view = ItemView::New(factory);
469
470   // Set the minimum swipe distance to be 2.5f
471   view.SetMinimumSwipeDistance(2.5f);
472
473   // Check the minimum swipe distance is 2.5f
474   DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
475   END_TEST;
476 }
477
478 int UtcDaliItemViewSetAndGetAnchoring(void)
479 {
480   ToolkitTestApplication application;
481
482   // Create the ItemView actor
483   TestItemFactory factory;
484   ItemView view = ItemView::New(factory);
485
486   // Disable the anchor animation
487   view.SetAnchoring(false);
488
489   // Check the anchor animation is disabled
490   DALI_TEST_CHECK(view.GetAnchoring() == false);
491   END_TEST;
492 }
493
494 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
495 {
496   ToolkitTestApplication application;
497
498   // Create the ItemView actor
499   TestItemFactory factory;
500   ItemView view = ItemView::New(factory);
501
502   // Set the duration of anchor animation to be 1.5f
503   view.SetAnchoringDuration(1.5f);
504
505   // Check the duration of anchor animation is 1.5f
506   DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
507   END_TEST;
508 }
509
510 int UtcDaliItemViewSetAndGetRefreshInterval(void)
511 {
512   ToolkitTestApplication application;
513
514   // Create the ItemView actor
515   TestItemFactory factory;
516   ItemView view = ItemView::New(factory);
517
518   // Set the interval between refreshes to be 20
519   view.SetRefreshInterval(20);
520
521   view.Refresh();
522
523   // Check the interval between refreshes is 20
524   DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
525   END_TEST;
526 }
527
528 int UtcDaliItemViewScrollToItem(void)
529 {
530   ToolkitTestApplication application;
531
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 );
537
538   view.SetName("view actor");
539   view.AddLayout(*layout);
540   view.SetSize(vec);
541
542   Stage::GetCurrent().Add(view);
543   layout->SetOrientation(ControlOrientation::Up);
544   view.ActivateLayout(0, vec, 0.0f);
545
546   application.SendNotification();
547   application.Render(0);
548
549   // render 10 frames
550   for(int i = 0; i < 10; ++i)
551   {
552     application.Render(16); // 60hz frames
553   }
554
555   // Confirm: we have actors in the view.
556   std::vector<unsigned int> indices;
557   for(unsigned int i = 0; i < 10; i++)
558   {
559     Actor testActor = view.GetItem(i);
560     if (testActor)
561     {
562       indices.push_back(i);
563     }
564   }
565
566   try
567   {
568     if (!indices.empty())
569     {
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)
574       {
575         application.Render(16); // 60hz frames
576       }
577
578       std::size_t moveCount = 0;
579       for(std::size_t i = 0; i < indices.size(); i++)
580       {
581         float layoutPosBefore = view.GetCurrentLayoutPosition(i);
582         view.ScrollToItem(indices[i], 0.0f);
583         float layoutPosAfter = view.GetCurrentLayoutPosition(i);
584
585         if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
586         {
587           ++moveCount;
588         }
589       }
590
591       DALI_TEST_CHECK((moveCount == indices.size()));
592     }
593   }
594   catch(...)
595   {
596     tet_result(TET_FAIL);
597   }
598
599   Stage::GetCurrent().Remove(view);
600   END_TEST;
601 }
602
603 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
604 {
605   ToolkitTestApplication application;
606
607   // Create the ItemView actor
608   TestItemFactory factory;
609   ItemView view = ItemView::New(factory);
610
611   // Set the scroll distance step for the wheel event to be 100.0f
612   view.SetWheelScrollDistanceStep(100.0f);
613
614   // Check the scroll distance step is 100.0f
615   DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
616   END_TEST;
617 }
618
619 int UtcDaliItemViewInsertItemP(void)
620 {
621   ToolkitTestApplication application;
622
623   // Create the ItemView actor
624   TestItemFactory factory;
625   ItemView view = ItemView::New(factory);
626
627   // Create a grid layout and add it to ItemView
628   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
629   view.AddLayout(*gridLayout);
630
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);
634
635   // Get the item given the item ID
636   Actor itemActor = view.GetItem(2);
637
638   ItemId id = view.GetItemId( itemActor );
639
640   // Check we are getting the correct Item ID given the specified actor
641   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
642
643   Actor newActor = Actor::New();
644
645   view.InsertItem(Item(id, newActor), 0.5f);
646
647   DALI_TEST_CHECK(view.GetItem(2) == newActor);
648   END_TEST;
649 }
650
651 int UtcDaliItemViewInsertItemsP(void)
652 {
653   ToolkitTestApplication application;
654
655   // Create the ItemView actor
656   TestItemFactory factory;
657   ItemView view = ItemView::New(factory);
658
659   // Create a grid layout and add it to ItemView
660   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
661   view.AddLayout(*gridLayout);
662
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);
666
667   unsigned int itemCount = view.GetChildCount();
668
669   ItemContainer insertList;
670
671   for( unsigned int i = 0u; i < 10; ++i )
672   {
673     Actor child = view.GetChildAt( i );
674     Actor newActor = Actor::New();
675     newActor.SetName("Inserted");
676     insertList.push_back( Item( view.GetItemId(child), newActor ) );
677   }
678
679   if( !insertList.empty() )
680   {
681     view.InsertItems( insertList, 0.5f );
682   }
683
684   DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
685
686   ItemIdContainer removeList;
687
688   for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
689   {
690     Actor child = view.GetChildAt( i );
691
692     if( child.GetName() == "Inserted" )
693     {
694       removeList.push_back( view.GetItemId(child) );
695     }
696   }
697
698   if( ! removeList.empty() )
699   {
700     view.RemoveItems( removeList, 0.5f );
701   }
702
703   DALI_TEST_CHECK(view.GetChildCount() == itemCount);
704   END_TEST;
705 }
706
707 int UtcDaliItemViewReplaceItemP(void)
708 {
709   ToolkitTestApplication application;
710
711   // Create the ItemView actor
712   TestItemFactory factory;
713   ItemView view = ItemView::New(factory);
714
715   // Create a grid layout and add it to ItemView
716   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
717   view.AddLayout(*gridLayout);
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   Actor newActor = Actor::New();
724
725   view.ReplaceItem( Item( 0, newActor ), 0.5f );
726
727   DALI_TEST_CHECK(view.GetItem(0) == newActor);
728   END_TEST;
729 }
730
731 int UtcDaliItemViewReplaceItemsP(void)
732 {
733   ToolkitTestApplication application;
734
735   // Create the ItemView actor
736   TestItemFactory factory;
737   ItemView view = ItemView::New(factory);
738
739   // Create a grid layout and add it to ItemView
740   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
741   view.AddLayout(*gridLayout);
742
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);
746
747   ItemContainer replaceList;
748
749   for( unsigned int i = 0u; i < 10; ++i )
750   {
751     Actor child = view.GetItem( i );
752     Actor newActor = Actor::New();
753     newActor.SetName("Replaced");
754
755     replaceList.push_back( Item( i, newActor ) );
756   }
757
758   if( !replaceList.empty() )
759   {
760     view.ReplaceItems( replaceList, 0.5f );
761   }
762
763   DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
764   DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
765   END_TEST;
766 }
767
768 int UtcDaliItemViewGetItemsRangeP(void)
769 {
770   ToolkitTestApplication application;
771
772   // Create the ItemView actor
773   TestItemFactory factory;
774   ItemView view = ItemView::New(factory);
775
776   // Create a grid layout and add it to ItemView
777   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
778   view.AddLayout(*gridLayout);
779
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);
783
784   ItemRange itemRange(0, 0);
785
786   view.GetItemsRange(itemRange);
787
788   DALI_TEST_CHECK(itemRange.Within(0));
789   END_TEST;
790 }
791
792 int UtcDaliItemViewSetItemsAnchorPointP(void)
793 {
794   ToolkitTestApplication application;
795
796   // Create the ItemView actor
797   TestItemFactory factory;
798   ItemView view = ItemView::New(factory);
799
800   // Create a grid layout and add it to ItemView
801   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
802   view.AddLayout(*gridLayout);
803
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);
807
808   Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
809
810   view.SetItemsAnchorPoint(anchorPoint);
811
812   DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
813   DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
814   END_TEST;
815 }
816
817 int UtcDaliItemViewSetItemsParentOriginP(void)
818 {
819   ToolkitTestApplication application;
820
821   // Create the ItemView actor
822   TestItemFactory factory;
823   ItemView view = ItemView::New(factory);
824
825   // Create a grid layout and add it to ItemView
826   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
827   view.AddLayout(*gridLayout);
828
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);
832
833   Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
834
835   view.SetItemsParentOrigin(parentOrigin);
836
837   DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
838   DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
839   END_TEST;
840 }
841
842 int UtcDaliItemFactoryGetExtention(void)
843 {
844   ToolkitTestApplication application;
845   TestItemFactory factory;
846   DALI_TEST_CHECK( factory.GetExtension() == NULL );
847   END_TEST;
848 }
849
850 int UtcDaliItemViewLayoutActivatedSignalP(void)
851 {
852   ToolkitTestApplication application;
853
854   // Create the ItemView actor
855   TestItemFactory factory;
856   ItemView view = ItemView::New(factory);
857
858   // Create a grid layout and add it to ItemView
859   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
860   view.AddLayout(*gridLayout);
861
862   Stage::GetCurrent().Add( view );
863
864   // Connect the layout activated signal
865   view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
866
867   gOnLayoutActivatedCalled = false;
868
869   // Render and notify
870   application.SendNotification();
871   application.Render();
872
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);
876
877   // Wait for 0.1 second
878   Wait(application, 100);
879
880   DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
881
882   END_TEST;
883 }
884
885 int UtcDaliItemViewSetGetProperty(void)
886 {
887   ToolkitTestApplication application;
888
889   // Create the ItemView actor
890   TestItemFactory factory;
891   ItemView view = ItemView::New(factory);
892   DALI_TEST_CHECK(view);
893
894   // Event side properties
895
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 );
901
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 );
907
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 );
913
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 );
919
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 );
925
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 );
931
932   // Animatable properties
933
934   // Test "layoutPosition" property
935   DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION  );
936   view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
937   Wait(application);
938   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
939
940   // Test "scrollSpeed" property
941   DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED  );
942   view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
943   Wait(application);
944   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
945
946   // Test "overshoot" property
947   DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT  );
948   view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
949   Wait(application);
950   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
951
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) );
955   Wait(application);
956   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
957
958   // Test "layoutOrientation" property
959   DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION  );
960   view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
961   Wait(application);
962   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
963
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 );
967   Wait(application);
968   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
969
970   END_TEST;
971 }
972
973
974 int UtcDaliItemViewOvershootVertical(void)
975 {
976   ToolkitTestApplication application;
977   Dali::Stage stage = Dali::Stage::GetCurrent();
978
979   // Create the ItemView actor
980   TestItemFactory factory;
981   ItemView view = ItemView::New(factory);
982
983   // Create a grid layout and add it to ItemView
984   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
985   view.AddLayout(*gridLayout);
986   stage.Add(view);
987
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);
991
992   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
993   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
994
995   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
996
997   Wait(application);
998
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);
1003   pos.y += 5.0f;
1004   Wait(application, 100);
1005
1006   for(int i = 0;i<200;i++)
1007   {
1008     SendPan(application, Gesture::Continuing, pos);
1009     pos.y += 5.0f;
1010     Wait(application);
1011   }
1012
1013   SendPan(application, Gesture::Finished, pos);
1014   Wait(application, 100);
1015
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);
1020   pos.y -= 5.0f;
1021   Wait(application, 100);
1022
1023   for(int i = 0;i<200;i++)
1024   {
1025     SendPan(application, Gesture::Continuing, pos);
1026     pos.y -= 5.0f;
1027     Wait(application);
1028   }
1029
1030   SendPan(application, Gesture::Finished, pos);
1031   Wait(application, 100);
1032   END_TEST;
1033 }
1034
1035 int UtcDaliItemViewOvershootHorizontal(void)
1036 {
1037   ToolkitTestApplication application;
1038   Dali::Stage stage = Dali::Stage::GetCurrent();
1039
1040   // Create the ItemView actor
1041   TestItemFactory factory;
1042   ItemView view = ItemView::New(factory);
1043
1044   // Create a grid layout and add it to ItemView
1045   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1046   view.AddLayout(*gridLayout);
1047   stage.Add(view);
1048
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);
1052
1053   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1054   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1055
1056   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1057
1058   Wait(application);
1059
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);
1064   pos.x -= 5.0f;
1065   Wait(application, 100);
1066
1067   for(int i = 0;i<200;i++)
1068   {
1069     SendPan(application, Gesture::Continuing, pos);
1070     pos.x -= 5.0f;
1071     Wait(application);
1072   }
1073
1074   SendPan(application, Gesture::Finished, pos);
1075   Wait(application, 100);
1076
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);
1081   pos.x += 5.0f;
1082   Wait(application, 100);
1083
1084   for(int i = 0;i<200;i++)
1085   {
1086     SendPan(application, Gesture::Continuing, pos);
1087     pos.x += 5.0f;
1088     Wait(application);
1089   }
1090
1091   SendPan(application, Gesture::Finished, pos);
1092   Wait(application, 100);
1093
1094   END_TEST;
1095 }