2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <float.h> // for FLT_MAX
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
25 using namespace Toolkit;
29 const unsigned int TOTAL_ITEM_NUMBER = 100;
30 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
33 // Implementation of ItemFactory for providing actors to ItemView
34 class TestItemFactory : public ItemFactory
40 * @param application class, stored as reference
46 public: // From ItemFactory
49 * Query the number of items available from the factory.
50 * The maximum available item has an ID of GetNumberOfItems() - 1.
52 virtual unsigned int GetNumberOfItems()
54 return TOTAL_ITEM_NUMBER;
58 * Create an Actor to represent a visible item.
60 * @return the created actor.
62 virtual Actor NewItem(unsigned int itemId)
64 // Create an image actor for this item
65 Image image = Image::New( TEST_IMAGE_FILE_NAME );
66 Actor actor = ImageActor::New(image);
76 int UtcDaliItemViewAddAndGetLayout(void)
78 ToolkitTestApplication application;
80 // Create the ItemView actor
81 TestItemFactory factory;
82 ItemView view = ItemView::New(factory);
84 // Create a grid layout and add it to ItemView
85 GridLayoutPtr gridLayout = GridLayout::New();
86 view.AddLayout(*gridLayout);
88 // As we have added one layout, check the number of layout is now 1
89 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
91 // Create a depth layout and add it to ItemView
92 DepthLayoutPtr depthLayout = DepthLayout::New();
93 view.AddLayout(*depthLayout);
95 // As we have added another layout, check the number of layout is now 2
96 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
98 // Create a spiral layout and add it to ItemView
99 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
100 view.AddLayout(*spiralLayout);
102 // As we have added another layout, check the number of layout is now 3
103 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
105 // Check we are getting the correct layout from ItemView
106 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
107 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
108 DALI_TEST_CHECK(view.GetLayout(2) == spiralLayout);
112 int UtcDaliItemViewAddAndRemoveLayout(void)
114 ToolkitTestApplication application;
116 // Create the ItemView actor
117 TestItemFactory factory;
118 ItemView view = ItemView::New(factory);
120 // Create a grid layout and add it to ItemView
121 GridLayoutPtr gridLayout = GridLayout::New();
122 view.AddLayout(*gridLayout);
124 // As we have added one layout, check the number of layout is now 1
125 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
127 // Create a depth layout and add it to ItemView
128 DepthLayoutPtr depthLayout = DepthLayout::New();
129 view.AddLayout(*depthLayout);
131 // As we have added another layout, check the number of layout is now 2
132 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
134 // Check we are getting the correct layout from ItemView
135 DALI_TEST_CHECK(view.GetLayout(0) == gridLayout);
136 DALI_TEST_CHECK(view.GetLayout(1) == depthLayout);
138 // Remove the grid layout
139 view.RemoveLayout(0);
141 // As we have removed the grid layout, check the number of layout is now 1
142 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
144 // Check we are getting the correct layout from ItemView
145 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
147 // Remove the depth layout
148 view.RemoveLayout(0);
150 // As we also removed the depth layout, check the number of layout is now 0
151 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
155 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
157 ToolkitTestApplication application;
159 // Create the ItemView actor
160 TestItemFactory factory;
161 ItemView view = ItemView::New(factory);
163 // Create a grid layout and add it to ItemView
164 GridLayoutPtr gridLayout = GridLayout::New();
165 view.AddLayout(*gridLayout);
167 // Create a depth layout and add it to ItemView
168 DepthLayoutPtr depthLayout = DepthLayout::New();
169 view.AddLayout(*depthLayout);
171 // Create a spiral layout and add it to ItemView
172 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
173 view.AddLayout(*spiralLayout);
175 // As we have added three layouts, check the number of layout is now 3
176 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
178 // Check there is no active layout at the moment
179 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
181 // Activate the depth layout
182 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
183 view.ActivateLayout(1, stageSize, 0.5f);
185 // Check the current active layout is the depth layout
186 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
188 // Activate the grid layout
189 view.ActivateLayout(0, stageSize, 0.5f);
191 // Check the current active layout is the grid layout
192 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
194 // Activate the spiral layout
195 view.ActivateLayout(2, stageSize, 0.5f);
197 // Check the current active layout is the spiral layout
198 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);