Remove constaints from BloomView, GaussianBlurView & Magnifier
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-DepthLayout.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <float.h>       // for FLT_MAX
20 #include <stdlib.h>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
24 using namespace Dali;
25 using namespace Toolkit;
26
27 namespace
28 {
29 const unsigned int TOTAL_ITEM_NUMBER = 200;
30
31 Vector3 DepthLayoutItemSizeFunction(unsigned int numberOfColumns, float layoutWidth)
32 {
33   float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * 0.8f;
34   return Vector3(width, width, width);
35 }
36
37 float DepthLayoutBottomMarginFunction(float layoutHeight)
38 {
39   return layoutHeight * 0.25f;
40 }
41
42 float DepthLayoutColumnPositionFunction(unsigned int numberOfColumns, unsigned int columnNumber, const Vector3& itemSize, float layoutWidth)
43 {
44   float availableSpace = layoutWidth - itemSize.width * numberOfColumns;
45   float leftMargin = availableSpace / numberOfColumns * 0.5f;
46   float columnPosition = leftMargin + itemSize.width * 0.5f + columnNumber * (itemSize.width + availableSpace / numberOfColumns);
47   return columnPosition - layoutWidth * 0.5f;
48 }
49 } // namespace
50
51
52 // Implementation of ItemFactory for providing actors to ItemView
53 class TestItemFactory : public ItemFactory
54 {
55 public:
56
57   /**
58    * Constructor
59    * @param application class, stored as reference
60    */
61   TestItemFactory()
62   {
63   }
64
65 public: // From ItemFactory
66
67   /**
68    * Query the number of items available from the factory.
69    * The maximum available item has an ID of GetNumberOfItems() - 1.
70    */
71   virtual unsigned int GetNumberOfItems()
72   {
73     return TOTAL_ITEM_NUMBER;
74   }
75
76   /**
77    * Create an Actor to represent a visible item.
78    * @param itemId
79    * @return the created actor.
80    */
81   virtual Actor NewItem(unsigned int itemId)
82   {
83     // Create an test actor for this item
84     ImageActor actor = CreateSolidColorActor(Color::RED);
85     actor.SetSize(64.0f, 64.0f);
86
87     return actor;
88   }
89 };
90
91
92 void depth_layout_startup(void)
93 {
94 }
95
96 void depth_layout_cleanup(void)
97 {
98 }
99
100 int UtcDaliDepthLayoutNew(void)
101 {
102   ToolkitTestApplication application;
103
104   // Create a depth layout
105   DepthLayoutPtr depthLayout = DepthLayout::New();
106
107   DALI_TEST_CHECK(depthLayout);
108   END_TEST;
109 }
110
111 int UtcDaliDepthLayoutSetAndGetNumberOfColumns(void)
112 {
113   ToolkitTestApplication application;
114
115   // Create a depth layout
116   DepthLayoutPtr depthLayout = DepthLayout::New();
117
118   // Set the number of columns
119   depthLayout->SetNumberOfColumns(5);
120
121   // Check whether we get the correct number of columns
122   DALI_TEST_CHECK(depthLayout->GetNumberOfColumns() == 5);
123   END_TEST;
124 }
125
126 int UtcDaliDepthLayoutSetAndGetNumberOfRows(void)
127 {
128   ToolkitTestApplication application;
129
130   // Create a depth layout
131   DepthLayoutPtr depthLayout = DepthLayout::New();
132
133   // Set the number of rows
134   depthLayout->SetNumberOfRows(15);
135
136   // Check whether we get the correct number of rows
137   DALI_TEST_CHECK(depthLayout->GetNumberOfRows() == 15);
138   END_TEST;
139 }
140
141 int UtcDaliDepthLayoutSetAndGetRowSpacing(void)
142 {
143   ToolkitTestApplication application;
144
145   // Create a depth layout
146   DepthLayoutPtr depthLayout = DepthLayout::New();
147
148   // Set the row spacing
149   depthLayout->SetRowSpacing(30.0f);
150
151   // Check whether we get the correct row spacing
152   DALI_TEST_EQUALS(depthLayout->GetRowSpacing(), 30.0f, TEST_LOCATION );
153   END_TEST;
154 }
155
156 int UtcDaliDepthLayoutSetAndGetTiltAngle(void)
157 {
158   ToolkitTestApplication application;
159
160   // Create a depth layout
161   DepthLayoutPtr depthLayout = DepthLayout::New();
162
163   // Set the tilt angle
164   depthLayout->SetTiltAngle(Degree(25.0f));
165
166   // Check whether we get the correct tilt angle
167   DALI_TEST_EQUALS(float(depthLayout->GetTiltAngle()), 25.0f, 0.001f, TEST_LOCATION );
168   END_TEST;
169 }
170
171 int UtcDaliDepthLayoutSetAndGetItemSizeFunction(void)
172 {
173   ToolkitTestApplication application;
174
175   // Create a depth layout
176   DepthLayoutPtr depthLayout = DepthLayout::New();
177
178   // Set the item size function
179   depthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunction);
180
181   // Check whether we get the correct item size function
182   DALI_TEST_CHECK(depthLayout->GetItemSizeFunction() == DepthLayoutItemSizeFunction);
183   END_TEST;
184 }
185
186 int UtcDaliDepthLayoutSetAndGetBottomMarginFunction(void)
187 {
188   ToolkitTestApplication application;
189
190   // Create a depth layout
191   DepthLayoutPtr depthLayout = DepthLayout::New();
192
193   // Set the bottom margin function
194   depthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunction);
195
196   // Check whether we get the correct bottom margin function
197   DALI_TEST_CHECK(depthLayout->GetBottomMarginFunction() == DepthLayoutBottomMarginFunction);
198   END_TEST;
199 }
200
201 int UtcDaliDepthLayoutSetAndGetItemTiltAngle(void)
202 {
203   ToolkitTestApplication application;
204
205   // Create a depth layout
206   DepthLayoutPtr depthLayout = DepthLayout::New();
207
208   // Set the item's tilt angle
209   depthLayout->SetItemTiltAngle(Degree(5.0f));
210
211   // Check whether we get the correct item's tilt angle
212   DALI_TEST_EQUALS(float(depthLayout->GetItemTiltAngle()), 5.0f, 0.001f, TEST_LOCATION );
213   END_TEST;
214 }
215
216 int UtcDaliDepthLayoutSetAndGetColumnPositionFunction(void)
217 {
218   ToolkitTestApplication application;
219
220   // Create a depth layout
221   DepthLayoutPtr depthLayout = DepthLayout::New();
222
223   // Set the column position function
224   depthLayout->SetColumnPositionFunction(DepthLayoutColumnPositionFunction);
225
226   // Check whether we get the correct column position function
227   DALI_TEST_CHECK(depthLayout->GetColumnPositionFunction() == DepthLayoutColumnPositionFunction);
228   END_TEST;
229 }
230
231 int UtcDaliDepthLayoutSetAndGetScrollSpeedFactor(void)
232 {
233   ToolkitTestApplication application;
234
235   // Create a depth layout
236   DepthLayoutPtr depthLayout = DepthLayout::New();
237
238   // Set the scroll speed factor
239   depthLayout->SetScrollSpeedFactor(0.05f);
240
241   // Check whether we get the correct scroll speed factor
242   DALI_TEST_EQUALS(depthLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
243   END_TEST;
244 }
245
246 int UtcDaliDepthLayoutSetAndGetMaximumSwipeSpeed(void)
247 {
248   ToolkitTestApplication application;
249
250   // Create a depth layout
251   DepthLayoutPtr depthLayout = DepthLayout::New();
252
253   // Set the maximum swipe speed
254   depthLayout->SetMaximumSwipeSpeed(50.0f);
255
256   // Check whether we get the correct maximum swipe speed
257   DALI_TEST_EQUALS(depthLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
258   END_TEST;
259 }
260
261 int UtcDaliDepthLayoutSetAndGetItemFlickAnimationDuration(void)
262 {
263   ToolkitTestApplication application;
264
265   // Create a depth layout
266   DepthLayoutPtr depthLayout = DepthLayout::New();
267
268   // Set the flick animaiton duration
269   depthLayout->SetItemFlickAnimationDuration(0.35f);
270
271   // Check whether we get the correct flick animaiton duration
272   DALI_TEST_EQUALS( depthLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
273   END_TEST;
274 }
275
276 int UtcDaliDepthLayoutConstraintLeft(void)
277 {
278   ToolkitTestApplication application;
279
280   // Create the ItemView actor
281   TestItemFactory factory;
282   ItemView view = ItemView::New(factory);
283   Vector3 vec(480.0f, 800.0f, 0.0f);
284   DepthLayoutPtr navigationLayout = DepthLayout::New();
285   navigationLayout->SetNumberOfColumns(6);
286
287   view.SetName("view actor");
288   view.AddLayout(*navigationLayout);
289   view.SetSize(vec);
290
291   Stage::GetCurrent().Add(view);
292   navigationLayout->SetOrientation(ControlOrientation::Left);
293   view.ActivateLayout(0, vec, 0.0f);
294
295   application.SendNotification();
296   application.Render(0);
297
298   // render 10 frames
299   for(int i = 0; i < 10; ++i)
300   {
301     application.Render(16); // 60hz frames
302   }
303
304   // Confirm: we have actors in the view and they are positioned some distance from the origin.
305   int nonZeroCount = 0;
306   int elementsFound = 0;
307   for(unsigned int i = 0; i < 10; i++)
308   {
309     Actor testActor = view.GetItem(i);
310     if (testActor)
311     {
312       elementsFound++;
313       Vector3 pos = testActor.GetCurrentPosition();
314
315       if (pos.LengthSquared() > 0.0f)
316       {
317         nonZeroCount++;
318       }
319     }
320   }
321
322   DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
323   Stage::GetCurrent().Remove(view);
324   END_TEST;
325 }
326
327 int UtcDaliDepthLayoutConstraintRight(void)
328 {
329   ToolkitTestApplication application;
330
331   // Create the ItemView actor
332   TestItemFactory factory;
333   ItemView view = ItemView::New(factory);
334   Vector3 vec(480.0f, 800.0f, 0.0f);
335   DepthLayoutPtr navigationLayout = DepthLayout::New();
336   navigationLayout->SetNumberOfColumns(6);
337
338   view.SetName("view actor");
339   view.AddLayout(*navigationLayout);
340   view.SetSize(vec);
341
342   Stage::GetCurrent().Add(view);
343   navigationLayout->SetOrientation(ControlOrientation::Right);
344   view.ActivateLayout(0, vec, 0.0f);
345
346   application.SendNotification();
347   application.Render(0);
348
349   // render 10 frames
350   for(int i = 0; i < 10; ++i)
351   {
352     application.Render(16); // 60hz frames
353   }
354
355   // Confirm: we have actors in the view and they are positioned some distance from the origin.
356   int nonZeroCount = 0;
357   int elementsFound = 0;
358   for(unsigned int i = 0; i < 10; i++)
359   {
360     Actor testActor = view.GetItem(i);
361     if (testActor)
362     {
363       elementsFound++;
364       Vector3 pos = testActor.GetCurrentPosition();
365
366       if (pos.LengthSquared() > 0.0f)
367       {
368         nonZeroCount++;
369       }
370     }
371   }
372
373   DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
374   Stage::GetCurrent().Remove(view);
375   END_TEST;
376 }
377
378 int UtcDaliDepthLayoutConstraintUp(void)
379 {
380   ToolkitTestApplication application;
381
382   // Create the ItemView actor
383   TestItemFactory factory;
384   ItemView view = ItemView::New(factory);
385   Vector3 vec(480.0f, 800.0f, 0.0f);
386   DepthLayoutPtr navigationLayout = DepthLayout::New();
387   navigationLayout->SetNumberOfColumns(6);
388
389   view.SetName("view actor");
390   view.AddLayout(*navigationLayout);
391   view.SetSize(vec);
392
393   Stage::GetCurrent().Add(view);
394   navigationLayout->SetOrientation(ControlOrientation::Up);
395   view.ActivateLayout(0, vec, 0.0f);
396
397   application.SendNotification();
398   application.Render(0);
399
400   // render 10 frames
401   for(int i = 0; i < 10; ++i)
402   {
403     application.Render(16); // 60hz frames
404   }
405
406   // Confirm: we have actors in the view and they are positioned some distance from the origin.
407   int nonZeroCount = 0;
408   int elementsFound = 0;
409   for(unsigned int i = 0; i < 10; i++)
410   {
411     Actor testActor = view.GetItem(i);
412     if (testActor)
413     {
414       elementsFound++;
415       Vector3 pos = testActor.GetCurrentPosition();
416
417       if (pos.LengthSquared() > 0.0f)
418       {
419         nonZeroCount++;
420       }
421     }
422   }
423
424   DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
425   Stage::GetCurrent().Remove(view);
426   END_TEST;
427 }
428
429 int UtcDaliDepthLayoutConstraintDown(void)
430 {
431   ToolkitTestApplication application;
432
433   // Create the ItemView actor
434   TestItemFactory factory;
435   ItemView view = ItemView::New(factory);
436   Vector3 vec(480.0f, 800.0f, 0.0f);
437   DepthLayoutPtr navigationLayout = DepthLayout::New();
438   navigationLayout->SetNumberOfColumns(6);
439
440   view.SetName("view actor");
441   view.AddLayout(*navigationLayout);
442   view.SetSize(vec);
443
444   Stage::GetCurrent().Add(view);
445   navigationLayout->SetOrientation(ControlOrientation::Down);
446   view.ActivateLayout(0, vec, 0.0f);
447
448   application.SendNotification();
449   application.Render(0);
450
451   // render 10 frames
452   for(int i = 0; i < 10; ++i)
453   {
454     application.Render(16); // 60hz frames
455   }
456
457   // Confirm: we have actors in the view and they are positioned some distance from the origin.
458   int nonZeroCount = 0;
459   int elementsFound = 0;
460   for(unsigned int i = 0; i < 10; i++)
461   {
462     Actor testActor = view.GetItem(i);
463     if (testActor)
464     {
465       elementsFound++;
466       Vector3 pos = testActor.GetCurrentPosition();
467
468       if (pos.LengthSquared() > 0.0f)
469       {
470         nonZeroCount++;
471       }
472     }
473   }
474
475   DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
476   Stage::GetCurrent().Remove(view);
477   END_TEST;
478 }
479
480 int UtcDaliDepthLayoutGetScrollToPosition(void)
481 {
482   ToolkitTestApplication application;
483
484   // Create the ItemView actor
485   TestItemFactory factory;
486   ItemView view = ItemView::New(factory);
487   Vector3 vec(480.0f, 800.0f, 0.0f);
488   DepthLayoutPtr layout = DepthLayout::New();
489
490   view.SetName("view actor");
491   view.AddLayout(*layout);
492   view.SetSize(vec);
493
494   Stage::GetCurrent().Add(view);
495   layout->SetOrientation(ControlOrientation::Up);
496   view.ActivateLayout(0, vec, 0.0f);
497
498   application.SendNotification();
499   application.Render(0);
500
501   // render 10 frames
502   for(int i = 0; i < 10; ++i)
503   {
504     application.Render(16); // 60hz frames
505   }
506
507   // Confirm: we have actors in the view.
508   std::vector<unsigned int> indices;
509   for(unsigned int i = 0; i < 10; i++)
510   {
511     Actor testActor = view.GetItem(i);
512     if (testActor)
513     {
514       indices.push_back(i);
515     }
516   }
517
518   try
519   {
520     if (!indices.empty())
521     {
522       const unsigned int firstTargetIndex = indices[indices.size()-1];
523       // scroll to last item
524       view.ScrollToItem(firstTargetIndex, 0.00f);
525       application.Render(16); // 60hz frames
526
527       std::size_t moveCount = 0;
528       for(std::size_t i = 0; i < indices.size(); i++)
529       {
530         float layoutPosBefore = view.GetCurrentLayoutPosition(i);
531         view.ScrollToItem(indices[i], 0.0f);
532
533         application.Render(16); // 60hz frame
534
535         float layoutPosAfter = view.GetCurrentLayoutPosition(i);
536
537         if (fabs(layoutPosBefore-layoutPosAfter) <= FLT_EPSILON)
538         {
539           ++moveCount;
540         }
541       }
542
543       DALI_TEST_CHECK((moveCount == indices.size()));
544     }
545   }
546   catch(...)
547   {
548     tet_result(TET_FAIL);
549   }
550
551   Stage::GetCurrent().Remove(view);
552   END_TEST;
553 }
554
555 int UtcDaliDepthLayoutScrollDirection(void)
556 {
557   ToolkitTestApplication application;
558
559   // Create the ItemView actor
560   TestItemFactory factory;
561   ItemView view = ItemView::New(factory);
562   Vector3 vec(480.0f, 800.0f, 0.0f);
563   DepthLayoutPtr navigationLayout = DepthLayout::New();
564
565   view.SetName("view actor");
566   view.AddLayout(*navigationLayout);
567   view.SetSize(vec);
568
569   Stage::GetCurrent().Add(view);
570   navigationLayout->SetOrientation(ControlOrientation::Left);
571   view.ActivateLayout(0, vec, 0.0f);
572
573   application.SendNotification();
574   application.Render(0);
575
576   ItemLayoutPtr layout = navigationLayout;
577
578   // render 10 frames
579   for(int i = 0; i < 10; ++i)
580   {
581     application.Render(16); // 60hz frames
582   }
583
584   navigationLayout->SetOrientation(ControlOrientation::Up);
585   view.ActivateLayout(0, vec, 0.0f);
586   application.SendNotification();
587   application.Render();
588
589   Degree deg = layout->GetScrollDirection();
590   DALI_TEST_CHECK(deg == 180.0f);
591
592   navigationLayout->SetOrientation(ControlOrientation::Down);
593   view.ActivateLayout(0, vec, 0.0f);
594   application.SendNotification();
595   application.Render();
596
597   deg = layout->GetScrollDirection();
598   DALI_TEST_CHECK((deg == 0.0f));
599
600   layout->SetOrientation(ControlOrientation::Left);
601   view.ActivateLayout(0, vec, 0.0f);
602   application.SendNotification();
603   application.Render();
604
605   deg = layout->GetScrollDirection();
606   DALI_TEST_CHECK(deg == 270.0f);
607
608   navigationLayout->SetOrientation(ControlOrientation::Right);
609   view.ActivateLayout(0, vec, 0.0f);
610   application.SendNotification();
611   application.Render();
612
613   deg = layout->GetScrollDirection();
614   DALI_TEST_CHECK(deg == 90.0f);
615
616   Stage::GetCurrent().Remove(view);
617   END_TEST;
618 }