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 <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Dali::Toolkit;
28 const unsigned int TOTAL_ITEM_NUMBER = 200;
30 Vector3 RollLayoutItemSizeFunction(float layoutWidth, float layoutHeight, float rowSpacing)
32 float height = (layoutHeight - rowSpacing) * 0.5f;
33 return Vector3(layoutWidth, height, height);
39 // Implementation of ItemFactory for providing actors to ItemView
40 class TestItemFactory : public ItemFactory
51 public: // From ItemFactory
54 * Query the number of items available from the factory.
55 * The maximum available item has an ID of GetNumberOfItems() - 1.
57 virtual unsigned int GetNumberOfItems()
59 return TOTAL_ITEM_NUMBER;
63 * Create an Actor to represent a visible item.
65 * @return the created actor.
67 virtual Actor NewItem(unsigned int itemId)
69 // Create an test actor for this item
70 ImageActor actor = CreateSolidColorActor(Color::RED);
71 actor.SetSize(64.0f, 64.0f);
76 void dali_roll_layout_startup(void)
78 test_return_value = TET_UNDEF;
81 void dali_roll_layout_cleanup(void)
83 test_return_value = TET_PASS;
88 int UtcDaliRollLayoutNew(void)
90 ToolkitTestApplication application;
92 // Create a roll layout
93 RollLayoutPtr rollLayout = RollLayout::New();
95 DALI_TEST_CHECK(rollLayout);
99 int UtcDaliRollLayoutSetAndGetRowSpacing(void)
101 ToolkitTestApplication application;
103 // Create a roll layout
104 RollLayoutPtr rollLayout = RollLayout::New();
106 // Set the row spacing
107 rollLayout->SetRowSpacing(10.0f);
109 // Check whether we get the correct row spacing
110 DALI_TEST_EQUALS(rollLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
114 int UtcDaliRollLayoutSetAndGetItemSizeFunction(void)
116 ToolkitTestApplication application;
118 // Create a roll layout
119 RollLayoutPtr rollLayout = RollLayout::New();
121 // Set the item size function
122 rollLayout->SetItemSizeFunction(RollLayoutItemSizeFunction);
124 // Check whether we get the correct item size function
125 DALI_TEST_CHECK(rollLayout->GetItemSizeFunction() == RollLayoutItemSizeFunction);
129 int UtcDaliRollLayoutSetAndGetScrollSpeedFactor(void)
131 ToolkitTestApplication application;
133 // Create a roll layout
134 RollLayoutPtr rollLayout = RollLayout::New();
136 // Set the scroll speed factor
137 rollLayout->SetScrollSpeedFactor(0.05f);
139 // Check whether we get the correct scroll speed factor
140 DALI_TEST_EQUALS(rollLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
144 int UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed(void)
146 ToolkitTestApplication application;
148 // Create a roll layout
149 RollLayoutPtr rollLayout = RollLayout::New();
151 // Set the maximum swipe speed
152 rollLayout->SetMaximumSwipeSpeed(50.0f);
154 // Check whether we get the correct maximum swipe speed
155 DALI_TEST_EQUALS(rollLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
159 int UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration(void)
161 ToolkitTestApplication application;
163 // Create a roll layout
164 RollLayoutPtr rollLayout = RollLayout::New();
166 // Set the flick animaiton duration
167 rollLayout->SetItemFlickAnimationDuration(0.35f);
169 // Check whether we get the correct flick animaiton duration
170 DALI_TEST_EQUALS( rollLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
174 int UtcDaliRollLayoutConstraintLeft(void)
176 ToolkitTestApplication application;
178 // Create the ItemView actor
179 TestItemFactory factory;
180 ItemView view = ItemView::New(factory);
181 Vector3 vec(480.0f, 800.0f, 0.0f);
182 RollLayoutPtr rollLayout = RollLayout::New();
184 view.SetName("view actor");
185 view.AddLayout(*rollLayout);
188 Stage::GetCurrent().Add(view);
189 rollLayout->SetOrientation(ControlOrientation::Left);
190 view.ActivateLayout(0, vec, 0.0f);
192 application.SendNotification();
193 application.Render(0);
196 for(int i = 0; i < 10; ++i)
198 application.Render(16); // 60hz frames
201 // Confirm: we have actors in the view and they are positioned some distance from the origin.
202 int nonZeroCount = 0;
203 int elementsFound = 0;
204 for(unsigned int i = 0; i < 10; i++)
206 Actor testActor = view.GetItem(i);
210 Vector3 pos = testActor.GetCurrentPosition();
212 if (pos.LengthSquared() > 0.0f)
219 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
220 Stage::GetCurrent().Remove(view);
224 int UtcDaliRollLayoutConstraintRight(void)
226 ToolkitTestApplication application;
228 // Create the ItemView actor
229 TestItemFactory factory;
230 ItemView view = ItemView::New(factory);
231 Vector3 vec(480.0f, 800.0f, 0.0f);
232 RollLayoutPtr rollLayout = RollLayout::New();
234 view.SetName("view actor");
235 view.AddLayout(*rollLayout);
238 Stage::GetCurrent().Add(view);
239 rollLayout->SetOrientation(ControlOrientation::Right);
240 view.ActivateLayout(0, vec, 0.0f);
242 application.SendNotification();
243 application.Render(0);
246 for(int i = 0; i < 10; ++i)
248 application.Render(16); // 60hz frames
251 // Confirm: we have actors in the view and they are positioned some distance from the origin.
252 int nonZeroCount = 0;
253 int elementsFound = 0;
254 for(unsigned int i = 0; i < 10; i++)
256 Actor testActor = view.GetItem(i);
260 Vector3 pos = testActor.GetCurrentPosition();
262 if (pos.LengthSquared() > 0.0f)
269 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
270 Stage::GetCurrent().Remove(view);
274 int UtcDaliRollLayoutConstraintUp(void)
276 ToolkitTestApplication application;
278 // Create the ItemView actor
279 TestItemFactory factory;
280 ItemView view = ItemView::New(factory);
281 Vector3 vec(480.0f, 800.0f, 0.0f);
282 RollLayoutPtr rollLayout = RollLayout::New();
284 view.SetName("view actor");
285 view.AddLayout(*rollLayout);
288 Stage::GetCurrent().Add(view);
289 rollLayout->SetOrientation(ControlOrientation::Up);
290 view.ActivateLayout(0, vec, 0.0f);
292 application.SendNotification();
293 application.Render(0);
296 for(int i = 0; i < 10; ++i)
298 application.Render(16); // 60hz frames
301 // Confirm: we have actors in the view and they are positioned some distance from the origin.
302 int nonZeroCount = 0;
303 int elementsFound = 0;
304 for(unsigned int i = 0; i < 10; i++)
306 Actor testActor = view.GetItem(i);
310 Vector3 pos = testActor.GetCurrentPosition();
312 if (pos.LengthSquared() > 0.0f)
319 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
320 Stage::GetCurrent().Remove(view);
324 int UtcDaliRollLayoutConstraintDown(void)
326 ToolkitTestApplication application;
328 // Create the ItemView actor
329 TestItemFactory factory;
330 ItemView view = ItemView::New(factory);
331 Vector3 vec(480.0f, 800.0f, 0.0f);
332 RollLayoutPtr rollLayout = RollLayout::New();
334 view.SetName("view actor");
335 view.AddLayout(*rollLayout);
338 Stage::GetCurrent().Add(view);
339 rollLayout->SetOrientation(ControlOrientation::Down);
340 view.ActivateLayout(0, vec, 0.0f);
342 application.SendNotification();
343 application.Render(0);
346 for(int i = 0; i < 10; ++i)
348 application.Render(16); // 60hz frames
351 // Confirm: we have actors in the view and they are positioned some distance from the origin.
352 int nonZeroCount = 0;
353 int elementsFound = 0;
354 for(unsigned int i = 0; i < 10; i++)
356 Actor testActor = view.GetItem(i);
360 Vector3 pos = testActor.GetCurrentPosition();
362 if (pos.LengthSquared() > 0.0f)
369 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
370 Stage::GetCurrent().Remove(view);
374 int UtcDaliRollLayoutScrollDirection(void)
376 ToolkitTestApplication application;
378 // Create the ItemView actor
379 TestItemFactory factory;
380 ItemView view = ItemView::New(factory);
381 Vector3 vec(480.0f, 800.0f, 0.0f);
382 RollLayoutPtr rollLayout = RollLayout::New();
384 view.SetName("view actor");
385 view.AddLayout(*rollLayout);
388 Stage::GetCurrent().Add(view);
389 rollLayout->SetOrientation(ControlOrientation::Left);
390 view.ActivateLayout(0, vec, 0.0f);
392 application.SendNotification();
393 application.Render(0);
395 ItemLayoutPtr layout = rollLayout;
398 for(int i = 0; i < 10; ++i)
400 application.Render(16); // 60hz frames
403 rollLayout->SetOrientation(ControlOrientation::Up);
404 view.ActivateLayout(0, vec, 0.0f);
405 application.SendNotification();
406 application.Render();
408 Degree deg = layout->GetScrollDirection();
409 DALI_TEST_CHECK(deg == 0.0f);
411 rollLayout->SetOrientation(ControlOrientation::Down);
412 view.ActivateLayout(0, vec, 0.0f);
413 application.SendNotification();
414 application.Render();
416 deg = layout->GetScrollDirection();
417 DALI_TEST_CHECK((deg == 180.0f));
419 layout->SetOrientation(ControlOrientation::Left);
420 view.ActivateLayout(0, vec, 0.0f);
421 application.SendNotification();
422 application.Render();
424 deg = layout->GetScrollDirection();
425 DALI_TEST_CHECK(deg == 90.f);
427 rollLayout->SetOrientation(ControlOrientation::Right);
428 view.ActivateLayout(0, vec, 0.0f);
429 application.SendNotification();
430 application.Render();
432 deg = layout->GetScrollDirection();
433 DALI_TEST_CHECK(deg == 270.0f);
435 Stage::GetCurrent().Remove(view);