2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <float.h> // for FLT_MAX
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Toolkit;
28 const unsigned int TOTAL_ITEM_NUMBER = 100;
29 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
32 // Implementation of ItemFactory for providing actors to ItemView
33 class TestItemFactory : public ItemFactory
39 * @param application class, stored as reference
45 public: // From ItemFactory
48 * Query the number of items available from the factory.
49 * The maximum available item has an ID of GetNumberOfItems() - 1.
51 virtual unsigned int GetNumberOfItems()
53 return TOTAL_ITEM_NUMBER;
57 * Create an Actor to represent a visible item.
59 * @return the created actor.
61 virtual Actor NewItem(unsigned int itemId)
63 // Create an image actor for this item
64 Image image = Image::New( TEST_IMAGE_FILE_NAME );
65 Actor actor = ImageActor::New(image);
75 int UtcDaliItemViewAddAndGetLayout(void)
77 ToolkitTestApplication application;
79 // Create the ItemView actor
80 TestItemFactory factory;
81 ItemView view = ItemView::New(factory);
83 // Create a grid layout and add it to ItemView
84 GridLayoutPtr gridLayout = GridLayout::New();
85 view.AddLayout(*gridLayout);
87 // As we have added one layout, check the number of layout is now 1
88 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
90 // Create a depth layout and add it to ItemView
91 DepthLayoutPtr depthLayout = DepthLayout::New();
92 view.AddLayout(*depthLayout);
94 // As we have added another layout, check the number of layout is now 2
95 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
97 // Create a spiral layout and add it to ItemView
98 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
99 view.AddLayout(*spiralLayout);
101 // As we have added another layout, check the number of layout is now 3
102 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
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);
111 int UtcDaliItemViewAddAndRemoveLayout(void)
113 ToolkitTestApplication application;
115 // Create the ItemView actor
116 TestItemFactory factory;
117 ItemView view = ItemView::New(factory);
119 // Create a grid layout and add it to ItemView
120 GridLayoutPtr gridLayout = GridLayout::New();
121 view.AddLayout(*gridLayout);
123 // As we have added one layout, check the number of layout is now 1
124 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
126 // Create a depth layout and add it to ItemView
127 DepthLayoutPtr depthLayout = DepthLayout::New();
128 view.AddLayout(*depthLayout);
130 // As we have added another layout, check the number of layout is now 2
131 DALI_TEST_CHECK(view.GetLayoutCount() == 2);
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);
137 // Remove the grid layout
138 view.RemoveLayout(0);
140 // As we have removed the grid layout, check the number of layout is now 1
141 DALI_TEST_CHECK(view.GetLayoutCount() == 1);
143 // Check we are getting the correct layout from ItemView
144 DALI_TEST_CHECK(view.GetLayout(0) == depthLayout);
146 // Remove the depth layout
147 view.RemoveLayout(0);
149 // As we also removed the depth layout, check the number of layout is now 0
150 DALI_TEST_CHECK(view.GetLayoutCount() == 0);
154 int UtcDaliItemViewActivateLayoutAndGetActiveLayout(void)
156 ToolkitTestApplication application;
158 // Create the ItemView actor
159 TestItemFactory factory;
160 ItemView view = ItemView::New(factory);
162 // Create a grid layout and add it to ItemView
163 GridLayoutPtr gridLayout = GridLayout::New();
164 view.AddLayout(*gridLayout);
166 // Create a depth layout and add it to ItemView
167 DepthLayoutPtr depthLayout = DepthLayout::New();
168 view.AddLayout(*depthLayout);
170 // Create a spiral layout and add it to ItemView
171 SpiralLayoutPtr spiralLayout = SpiralLayout::New();
172 view.AddLayout(*spiralLayout);
174 // As we have added three layouts, check the number of layout is now 3
175 DALI_TEST_CHECK(view.GetLayoutCount() == 3);
177 // Check there is no active layout at the moment
178 DALI_TEST_CHECK(view.GetActiveLayout() == NULL);
180 // Activate the depth layout
181 Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
182 view.ActivateLayout(1, stageSize, 0.5f);
184 // Check the current active layout is the depth layout
185 DALI_TEST_CHECK(view.GetActiveLayout() == depthLayout);
187 // Activate the grid layout
188 view.ActivateLayout(0, stageSize, 0.5f);
190 // Check the current active layout is the grid layout
191 DALI_TEST_CHECK(view.GetActiveLayout() == gridLayout);
193 // Activate the spiral layout
194 view.ActivateLayout(2, stageSize, 0.5f);
196 // Check the current active layout is the spiral layout
197 DALI_TEST_CHECK(view.GetActiveLayout() == spiralLayout);