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