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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
28 using namespace Dali::Toolkit;
32 const unsigned int TOTAL_ITEM_NUMBER = 200;
34 Vector3 RollLayoutItemSizeFunction(float layoutWidth, float layoutHeight, float rowSpacing)
36 float height = (layoutHeight - rowSpacing) * 0.5f;
37 return Vector3(layoutWidth, height, height);
42 static void Startup();
43 static void Cleanup();
45 // Implementation of ItemFactory for providing actors to ItemView
46 class TestItemFactory : public ItemFactory
57 public: // From ItemFactory
60 * Query the number of items available from the factory.
61 * The maximum available item has an ID of GetNumberOfItems() - 1.
63 virtual unsigned int GetNumberOfItems()
65 return TOTAL_ITEM_NUMBER;
69 * Create an Actor to represent a visible item.
71 * @return the created actor.
73 virtual Actor NewItem(unsigned int itemId)
75 // Create an test actor for this item
76 ImageActor actor = CreateSolidColorActor(Color::RED);
77 actor.SetSize(64.0f, 64.0f);
83 void (*tet_startup)() = Startup;
84 void (*tet_cleanup)() = Cleanup;
87 static void UtcDaliRollLayoutNew();
88 static void UtcDaliRollLayoutSetAndGetRowSpacing();
89 static void UtcDaliRollLayoutSetAndGetItemSizeFunction();
90 static void UtcDaliRollLayoutSetAndGetScrollSpeedFactor();
91 static void UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed();
92 static void UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration();
93 static void UtcDaliRollLayoutConstraintLeft();
94 static void UtcDaliRollLayoutConstraintRight();
95 static void UtcDaliRollLayoutConstraintUp();
96 static void UtcDaliRollLayoutConstraintDown();
97 static void UtcDaliRollLayoutScrollDirection();
100 POSITIVE_TC_IDX = 0x01,
104 // Add test functionality for all APIs in the class (Positive and Negative)
106 struct tet_testlist tet_testlist[] = {
107 { UtcDaliRollLayoutNew, POSITIVE_TC_IDX },
108 { UtcDaliRollLayoutSetAndGetRowSpacing, POSITIVE_TC_IDX },
109 { UtcDaliRollLayoutSetAndGetItemSizeFunction, POSITIVE_TC_IDX },
110 { UtcDaliRollLayoutSetAndGetScrollSpeedFactor, POSITIVE_TC_IDX },
111 { UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed, POSITIVE_TC_IDX },
112 { UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration, POSITIVE_TC_IDX },
113 { UtcDaliRollLayoutConstraintLeft, POSITIVE_TC_IDX },
114 { UtcDaliRollLayoutConstraintRight, POSITIVE_TC_IDX },
115 { UtcDaliRollLayoutConstraintUp, POSITIVE_TC_IDX },
116 { UtcDaliRollLayoutConstraintDown, POSITIVE_TC_IDX },
117 { UtcDaliRollLayoutScrollDirection, POSITIVE_TC_IDX },
122 // Called only once before first test is run.
123 static void Startup()
127 // Called only once after last test is run
128 static void Cleanup()
133 static void UtcDaliRollLayoutNew()
135 ToolkitTestApplication application;
137 // Create a roll layout
138 RollLayoutPtr rollLayout = RollLayout::New();
140 DALI_TEST_CHECK(rollLayout);
143 static void UtcDaliRollLayoutSetAndGetRowSpacing()
145 ToolkitTestApplication application;
147 // Create a roll layout
148 RollLayoutPtr rollLayout = RollLayout::New();
150 // Set the row spacing
151 rollLayout->SetRowSpacing(10.0f);
153 // Check whether we get the correct row spacing
154 DALI_TEST_EQUALS(rollLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
157 static void UtcDaliRollLayoutSetAndGetItemSizeFunction()
159 ToolkitTestApplication application;
161 // Create a roll layout
162 RollLayoutPtr rollLayout = RollLayout::New();
164 // Set the item size function
165 rollLayout->SetItemSizeFunction(RollLayoutItemSizeFunction);
167 // Check whether we get the correct item size function
168 DALI_TEST_CHECK(rollLayout->GetItemSizeFunction() == RollLayoutItemSizeFunction);
171 static void UtcDaliRollLayoutSetAndGetScrollSpeedFactor()
173 ToolkitTestApplication application;
175 // Create a roll layout
176 RollLayoutPtr rollLayout = RollLayout::New();
178 // Set the scroll speed factor
179 rollLayout->SetScrollSpeedFactor(0.05f);
181 // Check whether we get the correct scroll speed factor
182 DALI_TEST_EQUALS(rollLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
185 static void UtcDaliRollLayoutSetAndGetMaximumSwipeSpeed()
187 ToolkitTestApplication application;
189 // Create a roll layout
190 RollLayoutPtr rollLayout = RollLayout::New();
192 // Set the maximum swipe speed
193 rollLayout->SetMaximumSwipeSpeed(50.0f);
195 // Check whether we get the correct maximum swipe speed
196 DALI_TEST_EQUALS(rollLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
199 static void UtcDaliRollLayoutSetAndGetItemFlickAnimationDuration()
201 ToolkitTestApplication application;
203 // Create a roll layout
204 RollLayoutPtr rollLayout = RollLayout::New();
206 // Set the flick animaiton duration
207 rollLayout->SetItemFlickAnimationDuration(0.35f);
209 // Check whether we get the correct flick animaiton duration
210 DALI_TEST_EQUALS( rollLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
213 static void UtcDaliRollLayoutConstraintLeft()
215 ToolkitTestApplication application;
217 // Create the ItemView actor
218 TestItemFactory factory;
219 ItemView view = ItemView::New(factory);
220 Vector3 vec(480.0f, 800.0f, 0.0f);
221 RollLayoutPtr rollLayout = RollLayout::New();
223 view.SetName("view actor");
224 view.AddLayout(*rollLayout);
227 Stage::GetCurrent().Add(view);
228 rollLayout->SetOrientation(ControlOrientation::Left);
229 view.ActivateLayout(0, vec, 0.0f);
231 application.SendNotification();
232 application.Render(0);
235 for(int i = 0; i < 10; ++i)
237 application.Render(16); // 60hz frames
240 // Confirm: we have actors in the view and they are positioned some distance from the origin.
241 int nonZeroCount = 0;
242 int elementsFound = 0;
243 for(unsigned int i = 0; i < 10; i++)
245 Actor testActor = view.GetItem(i);
249 Vector3 pos = testActor.GetCurrentPosition();
251 if (pos.LengthSquared() > 0.0f)
258 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
259 Stage::GetCurrent().Remove(view);
262 static void UtcDaliRollLayoutConstraintRight()
264 ToolkitTestApplication application;
266 // Create the ItemView actor
267 TestItemFactory factory;
268 ItemView view = ItemView::New(factory);
269 Vector3 vec(480.0f, 800.0f, 0.0f);
270 RollLayoutPtr rollLayout = RollLayout::New();
272 view.SetName("view actor");
273 view.AddLayout(*rollLayout);
276 Stage::GetCurrent().Add(view);
277 rollLayout->SetOrientation(ControlOrientation::Right);
278 view.ActivateLayout(0, vec, 0.0f);
280 application.SendNotification();
281 application.Render(0);
284 for(int i = 0; i < 10; ++i)
286 application.Render(16); // 60hz frames
289 // Confirm: we have actors in the view and they are positioned some distance from the origin.
290 int nonZeroCount = 0;
291 int elementsFound = 0;
292 for(unsigned int i = 0; i < 10; i++)
294 Actor testActor = view.GetItem(i);
298 Vector3 pos = testActor.GetCurrentPosition();
300 if (pos.LengthSquared() > 0.0f)
307 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
308 Stage::GetCurrent().Remove(view);
311 static void UtcDaliRollLayoutConstraintUp()
313 ToolkitTestApplication application;
315 // Create the ItemView actor
316 TestItemFactory factory;
317 ItemView view = ItemView::New(factory);
318 Vector3 vec(480.0f, 800.0f, 0.0f);
319 RollLayoutPtr rollLayout = RollLayout::New();
321 view.SetName("view actor");
322 view.AddLayout(*rollLayout);
325 Stage::GetCurrent().Add(view);
326 rollLayout->SetOrientation(ControlOrientation::Up);
327 view.ActivateLayout(0, vec, 0.0f);
329 application.SendNotification();
330 application.Render(0);
333 for(int i = 0; i < 10; ++i)
335 application.Render(16); // 60hz frames
338 // Confirm: we have actors in the view and they are positioned some distance from the origin.
339 int nonZeroCount = 0;
340 int elementsFound = 0;
341 for(unsigned int i = 0; i < 10; i++)
343 Actor testActor = view.GetItem(i);
347 Vector3 pos = testActor.GetCurrentPosition();
349 if (pos.LengthSquared() > 0.0f)
356 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
357 Stage::GetCurrent().Remove(view);
360 static void UtcDaliRollLayoutConstraintDown()
362 ToolkitTestApplication application;
364 // Create the ItemView actor
365 TestItemFactory factory;
366 ItemView view = ItemView::New(factory);
367 Vector3 vec(480.0f, 800.0f, 0.0f);
368 RollLayoutPtr rollLayout = RollLayout::New();
370 view.SetName("view actor");
371 view.AddLayout(*rollLayout);
374 Stage::GetCurrent().Add(view);
375 rollLayout->SetOrientation(ControlOrientation::Down);
376 view.ActivateLayout(0, vec, 0.0f);
378 application.SendNotification();
379 application.Render(0);
382 for(int i = 0; i < 10; ++i)
384 application.Render(16); // 60hz frames
387 // Confirm: we have actors in the view and they are positioned some distance from the origin.
388 int nonZeroCount = 0;
389 int elementsFound = 0;
390 for(unsigned int i = 0; i < 10; i++)
392 Actor testActor = view.GetItem(i);
396 Vector3 pos = testActor.GetCurrentPosition();
398 if (pos.LengthSquared() > 0.0f)
405 DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
406 Stage::GetCurrent().Remove(view);
409 static void UtcDaliRollLayoutScrollDirection()
411 ToolkitTestApplication application;
413 // Create the ItemView actor
414 TestItemFactory factory;
415 ItemView view = ItemView::New(factory);
416 Vector3 vec(480.0f, 800.0f, 0.0f);
417 RollLayoutPtr rollLayout = RollLayout::New();
419 view.SetName("view actor");
420 view.AddLayout(*rollLayout);
423 Stage::GetCurrent().Add(view);
424 rollLayout->SetOrientation(ControlOrientation::Left);
425 view.ActivateLayout(0, vec, 0.0f);
427 application.SendNotification();
428 application.Render(0);
430 ItemLayoutPtr layout = rollLayout;
433 for(int i = 0; i < 10; ++i)
435 application.Render(16); // 60hz frames
438 rollLayout->SetOrientation(ControlOrientation::Up);
439 view.ActivateLayout(0, vec, 0.0f);
440 application.SendNotification();
441 application.Render();
443 Degree deg = layout->GetScrollDirection();
444 DALI_TEST_CHECK(deg == 0.0f);
446 rollLayout->SetOrientation(ControlOrientation::Down);
447 view.ActivateLayout(0, vec, 0.0f);
448 application.SendNotification();
449 application.Render();
451 deg = layout->GetScrollDirection();
452 DALI_TEST_CHECK((deg == 180.0f));
454 layout->SetOrientation(ControlOrientation::Left);
455 view.ActivateLayout(0, vec, 0.0f);
456 application.SendNotification();
457 application.Render();
459 deg = layout->GetScrollDirection();
460 DALI_TEST_CHECK(deg == 90.f);
462 rollLayout->SetOrientation(ControlOrientation::Right);
463 view.ActivateLayout(0, vec, 0.0f);
464 application.SendNotification();
465 application.Render();
467 deg = layout->GetScrollDirection();
468 DALI_TEST_CHECK(deg == 270.0f);
470 Stage::GetCurrent().Remove(view);