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 <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
23 using namespace Dali::Toolkit;
27 const unsigned int TOTAL_ITEM_NUMBER = 200;
29 Vector3 RollLayoutItemSizeFunction(float layoutWidth, float layoutHeight, float rowSpacing)
31 float height = (layoutHeight - rowSpacing) * 0.5f;
32 return Vector3(layoutWidth, height, height);
38 // Implementation of ItemFactory for providing actors to ItemView
39 class TestItemFactory : public ItemFactory
50 public: // From ItemFactory
53 * Query the number of items available from the factory.
54 * The maximum available item has an ID of GetNumberOfItems() - 1.
56 virtual unsigned int GetNumberOfItems()
58 return TOTAL_ITEM_NUMBER;
62 * Create an Actor to represent a visible item.
64 * @return the created actor.
66 virtual Actor NewItem(unsigned int itemId)
68 // Create an test actor for this item
69 ImageActor actor = CreateSolidColorActor(Color::RED);
70 actor.SetSize(64.0f, 64.0f);
75 void dali_roll_layout_startup(void)
77 test_return_value = TET_UNDEF;
80 void dali_roll_layout_cleanup(void)
82 test_return_value = TET_PASS;
87 int UtcDaliRollLayoutNew(void)
89 ToolkitTestApplication application;
91 // Create a roll layout
92 RollLayoutPtr rollLayout = RollLayout::New();
94 DALI_TEST_CHECK(rollLayout);
98 int UtcDaliRollLayoutSetAndGetRowSpacing(void)
100 ToolkitTestApplication application;
102 // Create a roll layout
103 RollLayoutPtr rollLayout = RollLayout::New();
105 // Set the row spacing
106 rollLayout->SetRowSpacing(10.0f);
108 // Check whether we get the correct row spacing
109 DALI_TEST_EQUALS(rollLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
113 int UtcDaliRollLayoutSetAndGetItemSizeFunction(void)
115 ToolkitTestApplication application;
117 // Create a roll layout
118 RollLayoutPtr rollLayout = RollLayout::New();
120 // Set the item size function
121 rollLayout->SetItemSizeFunction(RollLayoutItemSizeFunction);
123 // Check whether we get the correct item size function
124 DALI_TEST_CHECK(rollLayout->GetItemSizeFunction() == RollLayoutItemSizeFunction);
128 int UtcDaliRollLayoutSetAndGetScrollSpeedFactor(void)
130 ToolkitTestApplication application;
132 // Create a roll layout
133 RollLayoutPtr rollLayout = RollLayout::New();
135 // Set the scroll speed factor
136 rollLayout->SetScrollSpeedFactor(0.05f);
138 // Check whether we get the correct scroll speed factor
139 DALI_TEST_EQUALS(rollLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
143 int UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed(void)
145 ToolkitTestApplication application;
147 // Create a roll layout
148 RollLayoutPtr rollLayout = RollLayout::New();
150 // Set the maximum swipe speed
151 rollLayout->SetMaximumSwipeSpeed(50.0f);
153 // Check whether we get the correct maximum swipe speed
154 DALI_TEST_EQUALS(rollLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
158 int UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration(void)
160 ToolkitTestApplication application;
162 // Create a roll layout
163 RollLayoutPtr rollLayout = RollLayout::New();
165 // Set the flick animaiton duration
166 rollLayout->SetItemFlickAnimationDuration(0.35f);
168 // Check whether we get the correct flick animaiton duration
169 DALI_TEST_EQUALS( rollLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
173 int UtcDaliRollLayoutConstraintLeft(void)
175 ToolkitTestApplication application;
177 // Create the ItemView actor
178 TestItemFactory factory;
179 ItemView view = ItemView::New(factory);
180 Vector3 vec(480.0f, 800.0f, 0.0f);
181 RollLayoutPtr rollLayout = RollLayout::New();
183 view.SetName("view actor");
184 view.AddLayout(*rollLayout);
187 Stage::GetCurrent().Add(view);
188 rollLayout->SetOrientation(ControlOrientation::Left);
189 view.ActivateLayout(0, vec, 0.0f);
191 application.SendNotification();
192 application.Render(0);
195 for(int i = 0; i < 10; ++i)
197 application.Render(16); // 60hz frames
200 // Confirm: we have actors in the view and they are positioned some distance from the origin.
201 int nonZeroCount = 0;
202 int elementsFound = 0;
203 for(unsigned int i = 0; i < 10; i++)
205 Actor testActor = view.GetItem(i);
209 Vector3 pos = testActor.GetCurrentPosition();
211 if (pos.LengthSquared() > 0.0f)
218 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
219 Stage::GetCurrent().Remove(view);
223 int UtcDaliRollLayoutConstraintRight(void)
225 ToolkitTestApplication application;
227 // Create the ItemView actor
228 TestItemFactory factory;
229 ItemView view = ItemView::New(factory);
230 Vector3 vec(480.0f, 800.0f, 0.0f);
231 RollLayoutPtr rollLayout = RollLayout::New();
233 view.SetName("view actor");
234 view.AddLayout(*rollLayout);
237 Stage::GetCurrent().Add(view);
238 rollLayout->SetOrientation(ControlOrientation::Right);
239 view.ActivateLayout(0, vec, 0.0f);
241 application.SendNotification();
242 application.Render(0);
245 for(int i = 0; i < 10; ++i)
247 application.Render(16); // 60hz frames
250 // Confirm: we have actors in the view and they are positioned some distance from the origin.
251 int nonZeroCount = 0;
252 int elementsFound = 0;
253 for(unsigned int i = 0; i < 10; i++)
255 Actor testActor = view.GetItem(i);
259 Vector3 pos = testActor.GetCurrentPosition();
261 if (pos.LengthSquared() > 0.0f)
268 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
269 Stage::GetCurrent().Remove(view);
273 int UtcDaliRollLayoutConstraintUp(void)
275 ToolkitTestApplication application;
277 // Create the ItemView actor
278 TestItemFactory factory;
279 ItemView view = ItemView::New(factory);
280 Vector3 vec(480.0f, 800.0f, 0.0f);
281 RollLayoutPtr rollLayout = RollLayout::New();
283 view.SetName("view actor");
284 view.AddLayout(*rollLayout);
287 Stage::GetCurrent().Add(view);
288 rollLayout->SetOrientation(ControlOrientation::Up);
289 view.ActivateLayout(0, vec, 0.0f);
291 application.SendNotification();
292 application.Render(0);
295 for(int i = 0; i < 10; ++i)
297 application.Render(16); // 60hz frames
300 // Confirm: we have actors in the view and they are positioned some distance from the origin.
301 int nonZeroCount = 0;
302 int elementsFound = 0;
303 for(unsigned int i = 0; i < 10; i++)
305 Actor testActor = view.GetItem(i);
309 Vector3 pos = testActor.GetCurrentPosition();
311 if (pos.LengthSquared() > 0.0f)
318 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
319 Stage::GetCurrent().Remove(view);
323 int UtcDaliRollLayoutConstraintDown(void)
325 ToolkitTestApplication application;
327 // Create the ItemView actor
328 TestItemFactory factory;
329 ItemView view = ItemView::New(factory);
330 Vector3 vec(480.0f, 800.0f, 0.0f);
331 RollLayoutPtr rollLayout = RollLayout::New();
333 view.SetName("view actor");
334 view.AddLayout(*rollLayout);
337 Stage::GetCurrent().Add(view);
338 rollLayout->SetOrientation(ControlOrientation::Down);
339 view.ActivateLayout(0, vec, 0.0f);
341 application.SendNotification();
342 application.Render(0);
345 for(int i = 0; i < 10; ++i)
347 application.Render(16); // 60hz frames
350 // Confirm: we have actors in the view and they are positioned some distance from the origin.
351 int nonZeroCount = 0;
352 int elementsFound = 0;
353 for(unsigned int i = 0; i < 10; i++)
355 Actor testActor = view.GetItem(i);
359 Vector3 pos = testActor.GetCurrentPosition();
361 if (pos.LengthSquared() > 0.0f)
368 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
369 Stage::GetCurrent().Remove(view);
373 int UtcDaliRollLayoutScrollDirection(void)
375 ToolkitTestApplication application;
377 // Create the ItemView actor
378 TestItemFactory factory;
379 ItemView view = ItemView::New(factory);
380 Vector3 vec(480.0f, 800.0f, 0.0f);
381 RollLayoutPtr rollLayout = RollLayout::New();
383 view.SetName("view actor");
384 view.AddLayout(*rollLayout);
387 Stage::GetCurrent().Add(view);
388 rollLayout->SetOrientation(ControlOrientation::Left);
389 view.ActivateLayout(0, vec, 0.0f);
391 application.SendNotification();
392 application.Render(0);
394 ItemLayoutPtr layout = rollLayout;
397 for(int i = 0; i < 10; ++i)
399 application.Render(16); // 60hz frames
402 rollLayout->SetOrientation(ControlOrientation::Up);
403 view.ActivateLayout(0, vec, 0.0f);
404 application.SendNotification();
405 application.Render();
407 Degree deg = layout->GetScrollDirection();
408 DALI_TEST_CHECK(deg == 0.0f);
410 rollLayout->SetOrientation(ControlOrientation::Down);
411 view.ActivateLayout(0, vec, 0.0f);
412 application.SendNotification();
413 application.Render();
415 deg = layout->GetScrollDirection();
416 DALI_TEST_CHECK((deg == 180.0f));
418 layout->SetOrientation(ControlOrientation::Left);
419 view.ActivateLayout(0, vec, 0.0f);
420 application.SendNotification();
421 application.Render();
423 deg = layout->GetScrollDirection();
424 DALI_TEST_CHECK(deg == 90.f);
426 rollLayout->SetOrientation(ControlOrientation::Right);
427 view.ActivateLayout(0, vec, 0.0f);
428 application.SendNotification();
429 application.Render();
431 deg = layout->GetScrollDirection();
432 DALI_TEST_CHECK(deg == 270.0f);
434 Stage::GetCurrent().Remove(view);