Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-ItemView.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19 #include <float.h>       // for FLT_MAX
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
23 using namespace Dali;
24 using namespace Toolkit;
25
26 namespace
27 {
28 const unsigned int TOTAL_ITEM_NUMBER = 100;
29 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
30
31
32 // Implementation of ItemFactory for providing actors to ItemView
33 class TestItemFactory : public ItemFactory
34 {
35 public:
36
37   /**
38    * Constructor
39    * @param application class, stored as reference
40    */
41   TestItemFactory()
42   {
43   }
44
45 public: // From ItemFactory
46
47   /**
48    * Query the number of items available from the factory.
49    * The maximum available item has an ID of GetNumberOfItems() - 1.
50    */
51   virtual unsigned int GetNumberOfItems()
52   {
53     return TOTAL_ITEM_NUMBER;
54   }
55
56   /**
57    * Create an Actor to represent a visible item.
58    * @param itemId
59    * @return the created actor.
60    */
61   virtual Actor NewItem(unsigned int itemId)
62   {
63     // Create an image actor for this item
64     Image image = Image::New( TEST_IMAGE_FILE_NAME );
65     Actor actor = ImageActor::New(image);
66
67     return actor;
68   }
69 };
70
71 } // namespace
72
73
74
75 int UtcDaliItemViewAddAndGetLayout(void)
76 {
77   ToolkitTestApplication application;
78
79   // Create the ItemView actor
80   TestItemFactory factory;
81   ItemView view = ItemView::New(factory);
82
83   // Create a grid layout and add it to ItemView
84   GridLayoutPtr gridLayout = GridLayout::New();
85   view.AddLayout(*gridLayout);
86
87   // As we have added one layout, check the number of layout is now 1
88   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
89
90   // Create a depth layout and add it to ItemView
91   DepthLayoutPtr depthLayout = DepthLayout::New();
92   view.AddLayout(*depthLayout);
93
94   // As we have added another layout, check the number of layout is now 2
95   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
96
97   // Create a spiral layout and add it to ItemView
98   SpiralLayoutPtr spiralLayout = SpiralLayout::New();
99   view.AddLayout(*spiralLayout);
100
101   // As we have added another layout, check the number of layout is now 3
102   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
103
104   // Check we are getting the correct layout from ItemView
105   DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
106   DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
107   DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
108   END_TEST;
109 }
110
111 int UtcDaliItemViewAddAndRemoveLayout(void)
112 {
113   ToolkitTestApplication application;
114
115   // Create the ItemView actor
116   TestItemFactory factory;
117   ItemView view = ItemView::New(factory);
118
119   // Create a grid layout and add it to ItemView
120   GridLayoutPtr gridLayout = GridLayout::New();
121   view.AddLayout(*gridLayout);
122
123   // As we have added one layout, check the number of layout is now 1
124   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
125
126   // Create a depth layout and add it to ItemView
127   DepthLayoutPtr depthLayout = DepthLayout::New();
128   view.AddLayout(*depthLayout);
129
130   // As we have added another layout, check the number of layout is now 2
131   DALI_TEST_CHECK(view.GetLayoutCount() == 2);
132
133   // Check we are getting the correct layout from ItemView
134   DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
135   DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
136
137   // Remove the grid layout
138   view.RemoveLayout(0);
139
140   // As we have removed the grid layout, check the number of layout is now 1
141   DALI_TEST_CHECK(view.GetLayoutCount() == 1);
142
143   // Check we are getting the correct layout from ItemView
144   DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
145
146   // Remove the depth layout
147   view.RemoveLayout(0);
148
149   // As we also removed the depth layout, check the number of layout is now 0
150   DALI_TEST_CHECK(view.GetLayoutCount() == 0);
151   END_TEST;
152 }
153
154 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
155 {
156   ToolkitTestApplication application;
157
158   // Create the ItemView actor
159   TestItemFactory factory;
160   ItemView view = ItemView::New(factory);
161
162   // Create a grid layout and add it to ItemView
163   GridLayoutPtr gridLayout = GridLayout::New();
164   view.AddLayout(*gridLayout);
165
166   // Create a depth layout and add it to ItemView
167   DepthLayoutPtr depthLayout = DepthLayout::New();
168   view.AddLayout(*depthLayout);
169
170   // Create a spiral layout and add it to ItemView
171   SpiralLayoutPtr spiralLayout = SpiralLayout::New();
172   view.AddLayout(*spiralLayout);
173
174   // As we have added three layouts, check the number of layout is now 3
175   DALI_TEST_CHECK(view.GetLayoutCount() == 3);
176
177   // Check there is no active layout at the moment
178   DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
179
180   // Activate the depth layout
181   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
182   view.ActivateLayout(1, stageSize, 0.5f);
183
184   // Check the current active layout is the depth layout
185   DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
186
187   // Activate the grid layout
188   view.ActivateLayout(0, stageSize, 0.5f);
189
190   // Check the current active layout is the grid layout
191   DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
192
193   // Activate the spiral layout
194   view.ActivateLayout(2, stageSize, 0.5f);
195
196   // Check the current active layout is the spiral layout
197   DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);
198   END_TEST;
199 }