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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Dali::Toolkit;
33 const unsigned int TOTAL_ITEM_NUMBER = 200;
35 Vector3 RollLayoutItemSizeFunction(float layoutWidth, float layoutHeight, float rowSpacing)
37 float height = (layoutHeight - rowSpacing) * 0.5f;
38 return Vector3(layoutWidth, height, height);
43 static void Startup();
44 static void Cleanup();
46 // Implementation of ItemFactory for providing actors to ItemView
47 class TestItemFactory : public ItemFactory
58 public: // From ItemFactory
61 * Query the number of items available from the factory.
62 * The maximum available item has an ID of GetNumberOfItems() - 1.
64 virtual unsigned int GetNumberOfItems()
66 return TOTAL_ITEM_NUMBER;
70 * Create an Actor to represent a visible item.
72 * @return the created actor.
74 virtual Actor NewItem(unsigned int itemId)
76 // Create an test actor for this item
77 ImageActor actor = CreateSolidColorActor(Color::RED);
78 actor.SetSize(64.0f, 64.0f);
84 void (*tet_startup)() = Startup;
85 void (*tet_cleanup)() = Cleanup;
88 static void UtcDaliRollLayoutNew();
89 static void UtcDaliRollLayoutSetAndGetRowSpacing();
90 static void UtcDaliRollLayoutSetAndGetItemSizeFunction();
91 static void UtcDaliRollLayoutSetAndGetScrollSpeedFactor();
92 static void UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed();
93 static void UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration();
94 static void UtcDaliRollLayoutConstraintLeft();
95 static void UtcDaliRollLayoutConstraintRight();
96 static void UtcDaliRollLayoutConstraintUp();
97 static void UtcDaliRollLayoutConstraintDown();
98 static void UtcDaliRollLayoutScrollDirection();
101 POSITIVE_TC_IDX = 0x01,
105 // Add test functionality for all APIs in the class (Positive and Negative)
107 struct tet_testlist tet_testlist[] = {
108 { UtcDaliRollLayoutNew, POSITIVE_TC_IDX },
109 { UtcDaliRollLayoutSetAndGetRowSpacing, POSITIVE_TC_IDX },
110 { UtcDaliRollLayoutSetAndGetItemSizeFunction, POSITIVE_TC_IDX },
111 { UtcDaliRollLayoutSetAndGetScrollSpeedFactor, POSITIVE_TC_IDX },
112 { UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed, POSITIVE_TC_IDX },
113 { UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration, POSITIVE_TC_IDX },
114 { UtcDaliRollLayoutConstraintLeft, POSITIVE_TC_IDX },
115 { UtcDaliRollLayoutConstraintRight, POSITIVE_TC_IDX },
116 { UtcDaliRollLayoutConstraintUp, POSITIVE_TC_IDX },
117 { UtcDaliRollLayoutConstraintDown, POSITIVE_TC_IDX },
118 { UtcDaliRollLayoutScrollDirection, POSITIVE_TC_IDX },
123 // Called only once before first test is run.
124 static void Startup()
128 // Called only once after last test is run
129 static void Cleanup()
134 static void UtcDaliRollLayoutNew()
136 ToolkitTestApplication application;
138 // Create a roll layout
139 RollLayoutPtr rollLayout = RollLayout::New();
141 DALI_TEST_CHECK(rollLayout);
144 static void UtcDaliRollLayoutSetAndGetRowSpacing()
146 ToolkitTestApplication application;
148 // Create a roll layout
149 RollLayoutPtr rollLayout = RollLayout::New();
151 // Set the row spacing
152 rollLayout->SetRowSpacing(10.0f);
154 // Check whether we get the correct row spacing
155 DALI_TEST_EQUALS(rollLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
158 static void UtcDaliRollLayoutSetAndGetItemSizeFunction()
160 ToolkitTestApplication application;
162 // Create a roll layout
163 RollLayoutPtr rollLayout = RollLayout::New();
165 // Set the item size function
166 rollLayout->SetItemSizeFunction(RollLayoutItemSizeFunction);
168 // Check whether we get the correct item size function
169 DALI_TEST_CHECK(rollLayout->GetItemSizeFunction() == RollLayoutItemSizeFunction);
172 static void UtcDaliRollLayoutSetAndGetScrollSpeedFactor()
174 ToolkitTestApplication application;
176 // Create a roll layout
177 RollLayoutPtr rollLayout = RollLayout::New();
179 // Set the scroll speed factor
180 rollLayout->SetScrollSpeedFactor(0.05f);
182 // Check whether we get the correct scroll speed factor
183 DALI_TEST_EQUALS(rollLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
186 static void UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed()
188 ToolkitTestApplication application;
190 // Create a roll layout
191 RollLayoutPtr rollLayout = RollLayout::New();
193 // Set the maximum swipe speed
194 rollLayout->SetMaximumSwipeSpeed(50.0f);
196 // Check whether we get the correct maximum swipe speed
197 DALI_TEST_EQUALS(rollLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
200 static void UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration()
202 ToolkitTestApplication application;
204 // Create a roll layout
205 RollLayoutPtr rollLayout = RollLayout::New();
207 // Set the flick animaiton duration
208 rollLayout->SetItemFlickAnimationDuration(0.35f);
210 // Check whether we get the correct flick animaiton duration
211 DALI_TEST_EQUALS( rollLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
214 static void UtcDaliRollLayoutConstraintLeft()
216 ToolkitTestApplication application;
218 // Create the ItemView actor
219 TestItemFactory factory;
220 ItemView view = ItemView::New(factory);
221 Vector3 vec(480.0f, 800.0f, 0.0f);
222 RollLayoutPtr rollLayout = RollLayout::New();
224 view.SetName("view actor");
225 view.AddLayout(*rollLayout);
228 Stage::GetCurrent().Add(view);
229 rollLayout->SetOrientation(ControlOrientation::Left);
230 view.ActivateLayout(0, vec, 0.0f);
232 application.SendNotification();
233 application.Render(0);
236 for(int i = 0; i < 10; ++i)
238 application.Render(16); // 60hz frames
241 // Confirm: we have actors in the view and they are positioned some distance from the origin.
242 int nonZeroCount = 0;
243 int elementsFound = 0;
244 for(unsigned int i = 0; i < 10; i++)
246 Actor testActor = view.GetItem(i);
250 Vector3 pos = testActor.GetCurrentPosition();
252 if (pos.LengthSquared() > 0.0f)
259 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
260 Stage::GetCurrent().Remove(view);
263 static void UtcDaliRollLayoutConstraintRight()
265 ToolkitTestApplication application;
267 // Create the ItemView actor
268 TestItemFactory factory;
269 ItemView view = ItemView::New(factory);
270 Vector3 vec(480.0f, 800.0f, 0.0f);
271 RollLayoutPtr rollLayout = RollLayout::New();
273 view.SetName("view actor");
274 view.AddLayout(*rollLayout);
277 Stage::GetCurrent().Add(view);
278 rollLayout->SetOrientation(ControlOrientation::Right);
279 view.ActivateLayout(0, vec, 0.0f);
281 application.SendNotification();
282 application.Render(0);
285 for(int i = 0; i < 10; ++i)
287 application.Render(16); // 60hz frames
290 // Confirm: we have actors in the view and they are positioned some distance from the origin.
291 int nonZeroCount = 0;
292 int elementsFound = 0;
293 for(unsigned int i = 0; i < 10; i++)
295 Actor testActor = view.GetItem(i);
299 Vector3 pos = testActor.GetCurrentPosition();
301 if (pos.LengthSquared() > 0.0f)
308 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
309 Stage::GetCurrent().Remove(view);
312 static void UtcDaliRollLayoutConstraintUp()
314 ToolkitTestApplication application;
316 // Create the ItemView actor
317 TestItemFactory factory;
318 ItemView view = ItemView::New(factory);
319 Vector3 vec(480.0f, 800.0f, 0.0f);
320 RollLayoutPtr rollLayout = RollLayout::New();
322 view.SetName("view actor");
323 view.AddLayout(*rollLayout);
326 Stage::GetCurrent().Add(view);
327 rollLayout->SetOrientation(ControlOrientation::Up);
328 view.ActivateLayout(0, vec, 0.0f);
330 application.SendNotification();
331 application.Render(0);
334 for(int i = 0; i < 10; ++i)
336 application.Render(16); // 60hz frames
339 // Confirm: we have actors in the view and they are positioned some distance from the origin.
340 int nonZeroCount = 0;
341 int elementsFound = 0;
342 for(unsigned int i = 0; i < 10; i++)
344 Actor testActor = view.GetItem(i);
348 Vector3 pos = testActor.GetCurrentPosition();
350 if (pos.LengthSquared() > 0.0f)
357 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
358 Stage::GetCurrent().Remove(view);
361 static void UtcDaliRollLayoutConstraintDown()
363 ToolkitTestApplication application;
365 // Create the ItemView actor
366 TestItemFactory factory;
367 ItemView view = ItemView::New(factory);
368 Vector3 vec(480.0f, 800.0f, 0.0f);
369 RollLayoutPtr rollLayout = RollLayout::New();
371 view.SetName("view actor");
372 view.AddLayout(*rollLayout);
375 Stage::GetCurrent().Add(view);
376 rollLayout->SetOrientation(ControlOrientation::Down);
377 view.ActivateLayout(0, vec, 0.0f);
379 application.SendNotification();
380 application.Render(0);
383 for(int i = 0; i < 10; ++i)
385 application.Render(16); // 60hz frames
388 // Confirm: we have actors in the view and they are positioned some distance from the origin.
389 int nonZeroCount = 0;
390 int elementsFound = 0;
391 for(unsigned int i = 0; i < 10; i++)
393 Actor testActor = view.GetItem(i);
397 Vector3 pos = testActor.GetCurrentPosition();
399 if (pos.LengthSquared() > 0.0f)
406 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
407 Stage::GetCurrent().Remove(view);
410 static void UtcDaliRollLayoutScrollDirection()
412 ToolkitTestApplication application;
414 // Create the ItemView actor
415 TestItemFactory factory;
416 ItemView view = ItemView::New(factory);
417 Vector3 vec(480.0f, 800.0f, 0.0f);
418 RollLayoutPtr rollLayout = RollLayout::New();
420 view.SetName("view actor");
421 view.AddLayout(*rollLayout);
424 Stage::GetCurrent().Add(view);
425 rollLayout->SetOrientation(ControlOrientation::Left);
426 view.ActivateLayout(0, vec, 0.0f);
428 application.SendNotification();
429 application.Render(0);
431 ItemLayoutPtr layout = rollLayout;
434 for(int i = 0; i < 10; ++i)
436 application.Render(16); // 60hz frames
439 rollLayout->SetOrientation(ControlOrientation::Up);
440 view.ActivateLayout(0, vec, 0.0f);
441 application.SendNotification();
442 application.Render();
444 Degree deg = layout->GetScrollDirection();
445 DALI_TEST_CHECK(deg == 0.0f);
447 rollLayout->SetOrientation(ControlOrientation::Down);
448 view.ActivateLayout(0, vec, 0.0f);
449 application.SendNotification();
450 application.Render();
452 deg = layout->GetScrollDirection();
453 DALI_TEST_CHECK((deg == 180.0f));
455 layout->SetOrientation(ControlOrientation::Left);
456 view.ActivateLayout(0, vec, 0.0f);
457 application.SendNotification();
458 application.Render();
460 deg = layout->GetScrollDirection();
461 DALI_TEST_CHECK(deg == 90.f);
463 rollLayout->SetOrientation(ControlOrientation::Right);
464 view.ActivateLayout(0, vec, 0.0f);
465 application.SendNotification();
466 application.Render();
468 deg = layout->GetScrollDirection();
469 DALI_TEST_CHECK(deg == 270.0f);
471 Stage::GetCurrent().Remove(view);