Merge changes I555b7cf0,I1be28edf,I605de844,I87caee64 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   gridLayout->SetOrientation(ControlOrientation::Down);
349   view.AddLayout(*gridLayout);
350
351   // Check there is no active layout at the moment
352   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
353
354   // Activate the grid layout
355   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
356   view.ActivateLayout(0, stageSize, 0.5f);
357
358   // Check the current active layout is the grid layout
359   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
360
361   // Deactivate the current layout
362   view.DeactivateCurrentLayout();
363
364   // Check there is no active layout at the moment
365   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
366   END_TEST;
367 }
368
369 int UtcDaliItemViewGetItemAndGetItemId(void)
370 {
371   ToolkitTestApplication application;
372
373   // Create the ItemView actor
374   TestItemFactory factory;
375   ItemView view = ItemView::New(factory);
376
377   // Create a grid layout and add it to ItemView
378   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
379   gridLayout->SetOrientation(ControlOrientation::Left);
380   view.AddLayout(*gridLayout);
381
382   // Activate the grid layout so that the items will be created and added to ItemView
383   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
384   view.ActivateLayout(0, stageSize, 0.5f);
385
386   // Get the item given the item ID
387   Actor itemActor = view.GetItem(2);
388
389   // Check we are getting the correct Item ID given the specified actor
390   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
391   END_TEST;
392 }
393
394 int UtcDaliItemViewRemoveItem(void)
395 {
396   ToolkitTestApplication application;
397
398   // Create the ItemView actor
399   TestItemFactory factory;
400   ItemView view = ItemView::New(factory);
401
402   // Create a grid layout and add it to ItemView
403   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
404   gridLayout->SetOrientation(ControlOrientation::Right);
405   view.AddLayout(*gridLayout);
406
407   // Activate the grid layout so that the items will be created and added to ItemView
408   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
409   view.ActivateLayout(0, stageSize, 0.5f);
410
411   // Get the item given the item ID 2 and 3
412   Actor oldItemActorID2 = view.GetItem(2);
413   Actor oldItemActorID3 = view.GetItem(3);
414
415   // Remove the item with ID 2
416   view.RemoveItem(2, 0.0f);
417
418   // Get the new item given the item ID 2
419   Actor newItemActorID2 = view.GetItem(2);
420
421   // Check the original item with item ID 2 was deleted and now item ID 2 represents the original item with ID 3
422   DALI_TEST_CHECK(view.GetItemId(newItemActorID2) == 2);
423   DALI_TEST_CHECK(oldItemActorID2 != newItemActorID2);
424   DALI_TEST_CHECK(newItemActorID2 = oldItemActorID3);
425   END_TEST;
426 }
427
428 int UtcDaliItemViewGetCurrentLayoutPosition(void)
429 {
430   ToolkitTestApplication application;
431
432   // Create the ItemView actor
433   TestItemFactory factory;
434   ItemView view = ItemView::New(factory);
435
436   // Create a depth layout and add it to ItemView
437   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
438   depthLayout->SetOrientation(ControlOrientation::Up);
439   view.AddLayout(*depthLayout);
440
441   // Activate the grid layout so that the items will be created and added to ItemView
442   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
443   view.ActivateLayout(0, stageSize, 0.0f);
444
445   // Check the current layout position for the 10th items is 9.0f
446   DALI_TEST_EQUALS(view.GetCurrentLayoutPosition(9), 9.0f, TEST_LOCATION );
447   END_TEST;
448 }
449
450 int UtcDaliItemViewSetAndGetMinimumSwipeSpeed(void)
451 {
452   ToolkitTestApplication application;
453
454   // Create the ItemView actor
455   TestItemFactory factory;
456   ItemView view = ItemView::New(factory);
457
458   // Set the minimum swipe speed to be 1.5f
459   view.SetMinimumSwipeSpeed(1.5f);
460
461   // Check the minimum swipe speed is 1.5f
462   DALI_TEST_EQUALS(view.GetMinimumSwipeSpeed(), 1.5f, TEST_LOCATION );
463   END_TEST;
464 }
465
466 int UtcDaliItemViewSetAndGetMinimumSwipeDistance(void)
467 {
468   ToolkitTestApplication application;
469
470   // Create the ItemView actor
471   TestItemFactory factory;
472   ItemView view = ItemView::New(factory);
473
474   // Set the minimum swipe distance to be 2.5f
475   view.SetMinimumSwipeDistance(2.5f);
476
477   // Check the minimum swipe distance is 2.5f
478   DALI_TEST_EQUALS(view.GetMinimumSwipeDistance(), 2.5f, TEST_LOCATION );
479   END_TEST;
480 }
481
482 int UtcDaliItemViewSetAndGetAnchoring(void)
483 {
484   ToolkitTestApplication application;
485
486   // Create the ItemView actor
487   TestItemFactory factory;
488   ItemView view = ItemView::New(factory);
489
490   // Disable the anchor animation
491   view.SetAnchoring(false);
492
493   // Check the anchor animation is disabled
494   DALI_TEST_CHECK(view.GetAnchoring() == false);
495   END_TEST;
496 }
497
498 int UtcDaliItemViewSetAndGetAnchoringDuration(void)
499 {
500   ToolkitTestApplication application;
501
502   // Create the ItemView actor
503   TestItemFactory factory;
504   ItemView view = ItemView::New(factory);
505
506   // Set the duration of anchor animation to be 1.5f
507   view.SetAnchoringDuration(1.5f);
508
509   // Check the duration of anchor animation is 1.5f
510   DALI_TEST_EQUALS(view.GetAnchoringDuration(), 1.5f, TEST_LOCATION );
511   END_TEST;
512 }
513
514 int UtcDaliItemViewSetAndGetRefreshInterval(void)
515 {
516   ToolkitTestApplication application;
517
518   // Create the ItemView actor
519   TestItemFactory factory;
520   ItemView view = ItemView::New(factory);
521
522   // Set the interval between refreshes to be 20
523   view.SetRefreshInterval(20);
524
525   view.Refresh();
526
527   // Check the interval between refreshes is 20
528   DALI_TEST_CHECK(view.GetRefreshInterval() == 20);
529   END_TEST;
530 }
531
532 int UtcDaliItemViewScrollToItem(void)
533 {
534   ToolkitTestApplication application;
535
536   // Create the ItemView actor
537   TestItemFactory factory;
538   ItemView view = ItemView::New(factory);
539   Vector3 vec(480.0f, 800.0f, 0.0f);
540   ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
541
542   view.SetName("view actor");
543   view.AddLayout(*layout);
544   view.SetSize(vec);
545
546   Stage::GetCurrent().Add(view);
547   layout->SetOrientation(ControlOrientation::Down);
548   view.ActivateLayout(0, vec, 0.0f);
549
550   application.SendNotification();
551   application.Render(0);
552
553   // render 10 frames
554   for(int i = 0; i < 10; ++i)
555   {
556     application.Render(16); // 60hz frames
557   }
558
559   // Confirm: we have actors in the view.
560   std::vector<unsigned int> indices;
561   for(unsigned int i = 0; i < 10; i++)
562   {
563     Actor testActor = view.GetItem(i);
564     if (testActor)
565     {
566       indices.push_back(i);
567     }
568   }
569
570   try
571   {
572     if (!indices.empty())
573     {
574       const unsigned int firstTargetIndex = indices[indices.size()-1];
575       // scroll to last item
576       view.ScrollToItem(firstTargetIndex, 0.00f);
577       for(int i = 0; i < 10; ++i)
578       {
579         application.Render(16); // 60hz frames
580       }
581
582       std::size_t moveCount = 0;
583       for(std::size_t i = 0; i < indices.size(); i++)
584       {
585         float layoutPosBefore = view.GetCurrentLayoutPosition(i);
586         view.ScrollToItem(indices[i], 0.0f);
587         float layoutPosAfter = view.GetCurrentLayoutPosition(i);
588
589         if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
590         {
591           ++moveCount;
592         }
593       }
594
595       DALI_TEST_CHECK((moveCount == indices.size()));
596     }
597   }
598   catch(...)
599   {
600     tet_result(TET_FAIL);
601   }
602
603   Stage::GetCurrent().Remove(view);
604   END_TEST;
605 }
606
607 int UtcDaliItemViewSetAndGetWheelScrollDistanceStep(void)
608 {
609   ToolkitTestApplication application;
610
611   // Create the ItemView actor
612   TestItemFactory factory;
613   ItemView view = ItemView::New(factory);
614
615   // Set the scroll distance step for the wheel event to be 100.0f
616   view.SetWheelScrollDistanceStep(100.0f);
617
618   // Check the scroll distance step is 100.0f
619   DALI_TEST_EQUALS(view.GetWheelScrollDistanceStep(), 100.0f, TEST_LOCATION );
620   END_TEST;
621 }
622
623 int UtcDaliItemViewInsertItemP(void)
624 {
625   ToolkitTestApplication application;
626
627   // Create the ItemView actor
628   TestItemFactory factory;
629   ItemView view = ItemView::New(factory);
630
631   // Create a depth layout and add it to ItemView
632   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
633   depthLayout->SetOrientation(ControlOrientation::Left);
634   view.AddLayout(*depthLayout);
635
636   // Activate the grid layout so that the items will be created and added to ItemView
637   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
638   view.ActivateLayout(0, stageSize, 0.5f);
639
640   // Get the item given the item ID
641   Actor itemActor = view.GetItem(2);
642
643   ItemId id = view.GetItemId( itemActor );
644
645   // Check we are getting the correct Item ID given the specified actor
646   DALI_TEST_CHECK(view.GetItemId(itemActor) == 2);
647
648   Actor newActor = Actor::New();
649
650   view.InsertItem(Item(id, newActor), 0.5f);
651
652   DALI_TEST_CHECK(view.GetItem(2) == newActor);
653   END_TEST;
654 }
655
656 int UtcDaliItemViewInsertItemsP(void)
657 {
658   ToolkitTestApplication application;
659
660   // Create the ItemView actor
661   TestItemFactory factory;
662   ItemView view = ItemView::New(factory);
663
664   // Create a depth layout and add it to ItemView
665   ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
666   depthLayout->SetOrientation(ControlOrientation::Right);
667   view.AddLayout(*depthLayout);
668
669   // Activate the grid layout so that the items will be created and added to ItemView
670   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
671   view.ActivateLayout(0, stageSize, 0.5f);
672
673   unsigned int itemCount = view.GetChildCount();
674
675   ItemContainer insertList;
676
677   for( unsigned int i = 0u; i < 10; ++i )
678   {
679     Actor child = view.GetChildAt( i );
680     Actor newActor = Actor::New();
681     newActor.SetName("Inserted");
682     insertList.push_back( Item( view.GetItemId(child), newActor ) );
683   }
684
685   if( !insertList.empty() )
686   {
687     view.InsertItems( insertList, 0.5f );
688   }
689
690   DALI_TEST_CHECK(view.GetChildCount() == itemCount + 10);
691
692   ItemIdContainer removeList;
693
694   for( unsigned int i = 0u; i < view.GetChildCount(); ++i )
695   {
696     Actor child = view.GetChildAt( i );
697
698     if( child.GetName() == "Inserted" )
699     {
700       removeList.push_back( view.GetItemId(child) );
701     }
702   }
703
704   if( ! removeList.empty() )
705   {
706     view.RemoveItems( removeList, 0.5f );
707   }
708
709   DALI_TEST_CHECK(view.GetChildCount() == itemCount);
710   END_TEST;
711 }
712
713 int UtcDaliItemViewReplaceItemP(void)
714 {
715   ToolkitTestApplication application;
716
717   // Create the ItemView actor
718   TestItemFactory factory;
719   ItemView view = ItemView::New(factory);
720
721   // Create a spiral layout and add it to ItemView
722   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
723   view.AddLayout(*spiralLayout);
724
725   // Activate the grid layout so that the items will be created and added to ItemView
726   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
727   view.ActivateLayout(0, stageSize, 0.5f);
728
729   Actor newActor = Actor::New();
730
731   view.ReplaceItem( Item( 0, newActor ), 0.5f );
732
733   DALI_TEST_CHECK(view.GetItem(0) == newActor);
734   END_TEST;
735 }
736
737 int UtcDaliItemViewReplaceItemsP(void)
738 {
739   ToolkitTestApplication application;
740
741   // Create the ItemView actor
742   TestItemFactory factory;
743   ItemView view = ItemView::New(factory);
744
745   // Create a spiral layout and add it to ItemView
746   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
747   spiralLayout->SetOrientation( ControlOrientation::Down );
748   view.AddLayout(*spiralLayout);
749
750   // Activate the grid layout so that the items will be created and added to ItemView
751   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
752   view.ActivateLayout(0, stageSize, 0.5f);
753
754   ItemContainer replaceList;
755
756   for( unsigned int i = 0u; i < 10; ++i )
757   {
758     Actor child = view.GetItem( i );
759     Actor newActor = Actor::New();
760     newActor.SetName("Replaced");
761
762     replaceList.push_back( Item( i, newActor ) );
763   }
764
765   if( !replaceList.empty() )
766   {
767     view.ReplaceItems( replaceList, 0.5f );
768   }
769
770   DALI_TEST_CHECK(view.GetItem(0).GetName() == "Replaced");
771   DALI_TEST_CHECK(view.GetItem(8).GetName() == "Replaced");
772   END_TEST;
773 }
774
775 int UtcDaliItemViewGetItemsRangeP(void)
776 {
777   ToolkitTestApplication application;
778
779   // Create the ItemView actor
780   TestItemFactory factory;
781   ItemView view = ItemView::New(factory);
782
783   // Create a spiral layout and add it to ItemView
784   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
785   spiralLayout->SetOrientation( ControlOrientation::Left );
786   view.AddLayout(*spiralLayout);
787
788   // Activate the grid layout so that the items will be created and added to ItemView
789   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
790   view.ActivateLayout(0, stageSize, 0.5f);
791
792   ItemRange itemRange(0, 0);
793
794   view.GetItemsRange(itemRange);
795
796   DALI_TEST_CHECK(itemRange.Within(0));
797   END_TEST;
798 }
799
800 int UtcDaliItemViewSetItemsAnchorPointP(void)
801 {
802   ToolkitTestApplication application;
803
804   // Create the ItemView actor
805   TestItemFactory factory;
806   ItemView view = ItemView::New(factory);
807
808   // Create a spiral layout and add it to ItemView
809   ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
810   spiralLayout->SetOrientation( ControlOrientation::Right );
811   view.AddLayout(*spiralLayout);
812
813   // Activate the grid layout so that the items will be created and added to ItemView
814   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
815   view.ActivateLayout(0, stageSize, 0.5f);
816
817   Vector3 anchorPoint(10.0f, 10.0f, 0.0f);
818
819   view.SetItemsAnchorPoint(anchorPoint);
820
821   DALI_TEST_CHECK(view.GetItemsAnchorPoint() == anchorPoint);
822   DALI_TEST_CHECK(view.GetItem(0).GetCurrentAnchorPoint() == anchorPoint);
823   END_TEST;
824 }
825
826 int UtcDaliItemViewSetItemsParentOriginP(void)
827 {
828   ToolkitTestApplication application;
829
830   // Create the ItemView actor
831   TestItemFactory factory;
832   ItemView view = ItemView::New(factory);
833
834   // Create a grid layout and add it to ItemView
835   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
836   view.AddLayout(*gridLayout);
837
838   // Activate the grid layout so that the items will be created and added to ItemView
839   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
840   view.ActivateLayout(0, stageSize, 0.5f);
841
842   Vector3 parentOrigin(10.0f, 10.0f, 0.0f);
843
844   view.SetItemsParentOrigin(parentOrigin);
845
846   DALI_TEST_CHECK(view.GetItemsParentOrigin() == parentOrigin);
847   DALI_TEST_CHECK(view.GetItem(0).GetCurrentParentOrigin() == parentOrigin);
848   END_TEST;
849 }
850
851 int UtcDaliItemFactoryGetExtention(void)
852 {
853   ToolkitTestApplication application;
854   TestItemFactory factory;
855   DALI_TEST_CHECK( factory.GetExtension() == NULL );
856   END_TEST;
857 }
858
859 int UtcDaliItemViewLayoutActivatedSignalP(void)
860 {
861   ToolkitTestApplication application;
862
863   // Create the ItemView actor
864   TestItemFactory factory;
865   ItemView view = ItemView::New(factory);
866
867   // Create a grid layout and add it to ItemView
868   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
869   view.AddLayout(*gridLayout);
870
871   Stage::GetCurrent().Add( view );
872
873   // Connect the layout activated signal
874   view.LayoutActivatedSignal().Connect( &OnLayoutActivated );
875
876   gOnLayoutActivatedCalled = false;
877
878   // Render and notify
879   application.SendNotification();
880   application.Render();
881
882   // Activate the grid layout so that the items will be created and added to ItemView
883   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
884   view.ActivateLayout(0, stageSize, 0.1f);
885
886   // Wait for 0.1 second
887   Wait(application, 100);
888
889   DALI_TEST_EQUALS( gOnLayoutActivatedCalled, true, TEST_LOCATION );
890
891   END_TEST;
892 }
893
894 int UtcDaliItemViewSetGetProperty(void)
895 {
896   ToolkitTestApplication application;
897
898   // Create the ItemView actor
899   TestItemFactory factory;
900   ItemView view = ItemView::New(factory);
901   DALI_TEST_CHECK(view);
902
903   // Event side properties
904
905   // Test "minimumSwipeSpeed" property
906   DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED  );
907   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), view.GetMinimumSwipeSpeed(), TEST_LOCATION );
908   view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f );
909   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get<float>(), 2.5f, TEST_LOCATION );
910
911   // Test "minimumSwipeDistance" property
912   DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE  );
913   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), view.GetMinimumSwipeDistance(), TEST_LOCATION );
914   view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f );
915   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get<float>(), 8.725f, TEST_LOCATION );
916
917   // Test "wheelScrollDistanceStep" property
918   DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP  );
919   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), view.GetWheelScrollDistanceStep(), TEST_LOCATION );
920   view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f );
921   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get<float>(), 5.0f, TEST_LOCATION );
922
923   // Test "snapToItemEnabled" property
924   DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED  );
925   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), view.GetAnchoring(), TEST_LOCATION );
926   view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true );
927   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get<bool>(), true, TEST_LOCATION );
928
929   // Test "refreshInterval" property
930   DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL  );
931   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), view.GetRefreshInterval(), TEST_LOCATION );
932   view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
933   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
934
935   // Test "overshootEnabled" property
936   DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED  );
937   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
938   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
939   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
940
941   // Animatable properties
942
943   // Test "layoutPosition" property
944   DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION  );
945   view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f );
946   Wait(application);
947   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get<float>(), 20.5f, TEST_LOCATION );
948
949   // Test "scrollSpeed" property
950   DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED  );
951   view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f );
952   Wait(application);
953   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get<float>(), 3.35f, TEST_LOCATION );
954
955   // Test "overshoot" property
956   DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT  );
957   view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f );
958   Wait(application);
959   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get<float>(), 0.15f, TEST_LOCATION );
960
961   // Test "scrollDirection" property
962   DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION  );
963   view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) );
964   Wait(application);
965   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get<Vector2>(), Vector2(0.85f, 0.5f), TEST_LOCATION );
966
967   // Test "layoutOrientation" property
968   DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION  );
969   view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 );
970   Wait(application);
971   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get<int>(), 2, TEST_LOCATION );
972
973   // Test "scrollContentSize" property
974   DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE  );
975   view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f );
976   Wait(application);
977   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get<float>(), 250.0f, TEST_LOCATION );
978
979   END_TEST;
980 }
981
982
983 int UtcDaliItemViewOvershootVertical(void)
984 {
985   ToolkitTestApplication application;
986   Dali::Stage stage = Dali::Stage::GetCurrent();
987
988   // Create the ItemView actor
989   TestItemFactory factory;
990   ItemView view = ItemView::New(factory);
991
992   // Create a grid layout and add it to ItemView
993   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
994   view.AddLayout(*gridLayout);
995   stage.Add(view);
996
997   // Activate the grid layout so that the items will be created and added to ItemView
998   Vector3 stageSize(stage.GetSize());
999   view.ActivateLayout(0, stageSize, 0.5f);
1000
1001   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1002   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1003
1004   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1005
1006   Wait(application);
1007
1008   // Do a pan starting from 100,100 and moving down
1009   Vector2 pos(100.0f, 100.0f);
1010   SendPan(application, Gesture::Possible, pos);
1011   SendPan(application, Gesture::Started, pos);
1012   pos.y += 5.0f;
1013   Wait(application, 100);
1014
1015   for(int i = 0;i<200;i++)
1016   {
1017     SendPan(application, Gesture::Continuing, pos);
1018     pos.y += 5.0f;
1019     Wait(application);
1020   }
1021
1022   SendPan(application, Gesture::Finished, pos);
1023   Wait(application, 100);
1024
1025   // Do a pan starting from 100,100 and moving up
1026   pos = Vector2(100.0f, 300.0f);
1027   SendPan(application, Gesture::Possible, pos);
1028   SendPan(application, Gesture::Started, pos);
1029   pos.y -= 5.0f;
1030   Wait(application, 100);
1031
1032   for(int i = 0;i<200;i++)
1033   {
1034     SendPan(application, Gesture::Continuing, pos);
1035     pos.y -= 5.0f;
1036     Wait(application);
1037   }
1038
1039   SendPan(application, Gesture::Finished, pos);
1040   Wait(application, 100);
1041   END_TEST;
1042 }
1043
1044 int UtcDaliItemViewOvershootHorizontal(void)
1045 {
1046   ToolkitTestApplication application;
1047   Dali::Stage stage = Dali::Stage::GetCurrent();
1048
1049   // Create the ItemView actor
1050   TestItemFactory factory;
1051   ItemView view = ItemView::New(factory);
1052
1053   // Create a grid layout and add it to ItemView
1054   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
1055   view.AddLayout(*gridLayout);
1056   stage.Add(view);
1057
1058   // Activate the grid layout so that the items will be created and added to ItemView
1059   Vector3 stageSize(stage.GetSize());
1060   view.ActivateLayout(0, stageSize, 0.5f);
1061
1062   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
1063   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
1064
1065   view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
1066
1067   Wait(application);
1068
1069   // Do a pan starting from 100,100 and moving left
1070   Vector2 pos(100.0f, 100.0f);
1071   SendPan(application, Gesture::Possible, pos);
1072   SendPan(application, Gesture::Started, pos);
1073   pos.x -= 5.0f;
1074   Wait(application, 100);
1075
1076   for(int i = 0;i<200;i++)
1077   {
1078     SendPan(application, Gesture::Continuing, pos);
1079     pos.x -= 5.0f;
1080     Wait(application);
1081   }
1082
1083   SendPan(application, Gesture::Finished, pos);
1084   Wait(application, 100);
1085
1086   // Do a pan starting from 100,100 and moving right
1087   pos = Vector2(100.0f, 100.0f);
1088   SendPan(application, Gesture::Possible, pos);
1089   SendPan(application, Gesture::Started, pos);
1090   pos.x += 5.0f;
1091   Wait(application, 100);
1092
1093   for(int i = 0;i<200;i++)
1094   {
1095     SendPan(application, Gesture::Continuing, pos);
1096     pos.x += 5.0f;
1097     Wait(application);
1098   }
1099
1100   SendPan(application, Gesture::Finished, pos);
1101   Wait(application, 100);
1102
1103   END_TEST;
1104 }