Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-EffectsView.cpp
1 /*
2  * Copyright (c) 2022 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 <stdlib.h>
19 #include <iostream>
20 #include <sstream>
21
22 #include <dali-toolkit-test-suite-utils.h>
23
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 void dali_effectsview_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void dali_effectsview_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 int UtcDaliEffectsViewNew(void)
41 {
42   ToolkitTestApplication application;
43
44   EffectsView view;
45   DALI_TEST_CHECK(!view);
46
47   view = EffectsView::New(EffectsView::DROP_SHADOW);
48   DALI_TEST_CHECK(view);
49
50   application.GetScene().Add(view);
51
52   view.Reset();
53   view = EffectsView::New(EffectsView::EMBOSS);
54   DALI_TEST_CHECK(view);
55
56   application.SendNotification();
57   application.Render();
58
59   END_TEST;
60 }
61
62 int UtcDaliEffectsViewCopyAndAssignment(void)
63 {
64   ToolkitTestApplication application;
65
66   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
67   DALI_TEST_CHECK(view);
68
69   EffectsView copy(view);
70   DALI_TEST_CHECK(copy == view);
71
72   EffectsView assign;
73   DALI_TEST_CHECK(!assign);
74   assign = view;
75   DALI_TEST_CHECK(assign == view);
76
77   // Self assignment
78   assign = assign;
79   DALI_TEST_CHECK(assign);
80   DALI_TEST_CHECK(assign == view);
81
82   END_TEST;
83 }
84
85 int UtcDaliEffectsViewDownCast(void)
86 {
87   ToolkitTestApplication application;
88
89   BaseHandle view = EffectsView::New(EffectsView::EMBOSS);
90   DALI_TEST_CHECK(EffectsView::DownCast(view));
91
92   BaseHandle empty;
93   DALI_TEST_CHECK(!EffectsView::DownCast(empty));
94
95   BaseHandle another = Actor::New();
96   DALI_TEST_CHECK(!EffectsView::DownCast(another));
97
98   END_TEST;
99 }
100
101 // Positive test case for a method
102 int UtcDaliEffectsViewAddRemoveDropShadow(void)
103 {
104   ToolkitTestApplication application;
105   tet_infoline("UtcDaliEffectsViewAddRemoveDropShadow");
106
107   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
108   DALI_TEST_CHECK(view);
109
110   Actor actor = Actor::New();
111   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
112
113   view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
114   view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
115   view.Add(actor);
116   application.GetScene().Add(view);
117
118   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
119   DALI_TEST_CHECK(actor.GetParent());
120   DALI_TEST_CHECK(actor.GetParent() != view);
121
122   view.Remove(actor);
123
124   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
125   END_TEST;
126 }
127
128 int UtcDaliEffectsViewAddRemoveEmboss(void)
129 {
130   ToolkitTestApplication application;
131   tet_infoline("UtcDaliEffectsViewAddRemoveEmboss");
132
133   tet_infoline("Checking number of render tasks = 1");
134   application.SendNotification();
135   application.Render();
136   Integration::Scene stage = application.GetScene();
137   DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION);
138
139   tet_infoline("Create effects view");
140
141   EffectsView view = EffectsView::New(EffectsView::EMBOSS);
142   Vector3     offsetSet(2.f, 3.f, 4.f);
143   Vector4     colorSet(0.2f, 0.3f, 0.4f, 0.5f);
144   view.SetProperty(EffectsView::Property::EFFECT_OFFSET, offsetSet);
145   view.SetProperty(EffectsView::Property::EFFECT_COLOR, colorSet);
146   Vector3   offsetAnimate(4.f, 6.f, 8.f);
147   float     durationSeconds(0.05f);
148   Animation animation = Animation::New(durationSeconds);
149   animation.AnimateTo(Property(view, EffectsView::Property::EFFECT_OFFSET), offsetAnimate);
150   animation.Play();
151
152   DALI_TEST_CHECK(view);
153
154   Actor actor = Actor::New();
155   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
156   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
157
158   view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
159
160   view.Add(actor);
161   view.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
162
163   stage.Add(view);
164
165   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
166
167   application.SendNotification();
168   application.Render();
169
170   tet_infoline("Removing view from stage disables view");
171   stage.Remove(view);
172
173   tet_infoline("Checking number of render tasks = 1");
174   DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION);
175
176   tet_infoline("Adding view to stage again re-enables view");
177   stage.Add(view);
178
179   tet_infoline("Removing view from stage disables view");
180   DALI_TEST_GREATER(stage.GetRenderTaskList().GetTaskCount(), 1u, TEST_LOCATION);
181   stage.Remove(view);
182   view.Reset();
183
184   tet_infoline("Checking number of render tasks = 1");
185   DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION);
186
187   END_TEST;
188 }
189
190 int UtcDaliEffectsViewGetTypeP(void)
191 {
192   ToolkitTestApplication application;
193
194   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
195   DALI_TEST_CHECK(view.GetType() == EffectsView::DROP_SHADOW);
196
197   view.Reset();
198   view = EffectsView::New(EffectsView::EMBOSS);
199   DALI_TEST_CHECK(view.GetType() == EffectsView::EMBOSS);
200
201   END_TEST;
202 }
203
204 int UtcDaliEffectsViewOnStage(void)
205 {
206   ToolkitTestApplication application;
207
208   EffectsView view = EffectsView::New(EffectsView::EMBOSS);
209   view.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
210   Integration::Scene stage = application.GetScene();
211   DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() == 1);
212
213   stage.Add(view);
214   application.SendNotification();
215   application.Render();
216   DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() > 1);
217
218   END_TEST;
219 }
220
221 int UtcDaliEffectsViewOffStage(void)
222 {
223   ToolkitTestApplication application;
224
225   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
226   view.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
227   Integration::Scene stage = application.GetScene();
228   DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() == 1);
229
230   stage.Add(view);
231   application.SendNotification();
232   application.Render();
233   DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() > 1);
234
235   stage.Remove(view);
236   application.SendNotification();
237   application.Render();
238   DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() == 1);
239
240   END_TEST;
241 }
242
243 int UtcDaliEffectsViewRefreshP(void)
244 {
245   ToolkitTestApplication application;
246
247   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
248   try
249   {
250     view.Refresh();
251     DALI_TEST_CHECK(true);
252   }
253   catch(...)
254   {
255     DALI_TEST_CHECK(false); // Should not get here!
256   }
257
258   END_TEST;
259 }
260
261 int UtcDaliEffectsViewRefreshN(void)
262 {
263   ToolkitTestApplication application;
264
265   EffectsView view;
266   try
267   {
268     view.Refresh();
269     DALI_TEST_CHECK(false); // Should not get here
270   }
271   catch(...)
272   {
273     DALI_TEST_CHECK(true);
274   }
275
276   END_TEST;
277 }
278
279 int UtcDaliEffectsViewSetPixelFormatP(void)
280 {
281   ToolkitTestApplication application;
282
283   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
284   try
285   {
286     view.SetPixelFormat(Pixel::RGBA8888);
287     DALI_TEST_CHECK(true);
288   }
289   catch(...)
290   {
291     DALI_TEST_CHECK(false); // Should not get here!
292   }
293
294   END_TEST;
295 }
296
297 int UtcDaliEffectsViewSetPixelFormatN(void)
298 {
299   ToolkitTestApplication application;
300
301   EffectsView view;
302   try
303   {
304     view.SetPixelFormat(Pixel::RGBA8888);
305     DALI_TEST_CHECK(false); // Should not get here
306   }
307   catch(...)
308   {
309     DALI_TEST_CHECK(true);
310   }
311
312   END_TEST;
313 }
314
315 int UtcDaliEffectsViewSizeProperty(void)
316 {
317   ToolkitTestApplication application;
318
319   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
320
321   Property::Index idx = view.GetPropertyIndex("effectSize");
322   DALI_TEST_EQUALS(idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION);
323
324   view.SetProperty(idx, 5);
325   Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_SIZE);
326   int             size;
327   DALI_TEST_CHECK(value.Get(size));
328   DALI_TEST_CHECK(size == 5);
329
330   END_TEST;
331 }
332
333 int UtcDaliEffectsViewOffsetProperty(void)
334 {
335   ToolkitTestApplication application;
336
337   EffectsView view = EffectsView::New(EffectsView::EMBOSS);
338   application.GetScene().Add(view);
339
340   Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_OFFSET);
341   Vector3         offsetValue;
342   DALI_TEST_CHECK(value.Get(offsetValue));
343   DALI_TEST_EQUALS(offsetValue, Vector3::ZERO, TEST_LOCATION);
344
345   Vector3 offsetSet(2.f, 3.f, 4.f);
346   view.SetProperty(EffectsView::Property::EFFECT_OFFSET, offsetSet);
347   application.SendNotification();
348   application.Render(0);
349   value = view.GetProperty(EffectsView::Property::EFFECT_OFFSET);
350   value.Get(offsetValue);
351   DALI_TEST_EQUALS(offsetValue, offsetSet, TEST_LOCATION);
352
353   Vector3   offsetAnimate(4.f, 6.f, 8.f);
354   float     durationSeconds(0.05f);
355   Animation animation = Animation::New(durationSeconds);
356   animation.AnimateTo(Property(view, EffectsView::Property::EFFECT_OFFSET), offsetAnimate);
357   animation.Play();
358   application.SendNotification();
359   application.Render(static_cast<unsigned int>(durationSeconds * 1000.0f) + 1u /*just beyond the animation duration*/);
360
361   value = view.GetCurrentProperty(EffectsView::Property::EFFECT_OFFSET);
362   value.Get(offsetValue);
363   DALI_TEST_EQUALS(offsetValue, offsetAnimate, TEST_LOCATION);
364
365   END_TEST;
366 }
367
368 int UtcDaliEffectsViewColorProperty(void)
369 {
370   ToolkitTestApplication application;
371
372   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
373   application.GetScene().Add(view);
374
375   Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_COLOR);
376   Vector4         colorValue;
377   DALI_TEST_CHECK(value.Get(colorValue));
378   DALI_TEST_EQUALS(colorValue, Color::WHITE, TEST_LOCATION);
379
380   Vector4 colorSet(0.2f, 0.3f, 0.4f, 0.5f);
381   view.SetProperty(EffectsView::Property::EFFECT_COLOR, colorSet);
382   application.SendNotification();
383   application.Render(0);
384   value = view.GetProperty(EffectsView::Property::EFFECT_COLOR);
385   value.Get(colorValue);
386   DALI_TEST_EQUALS(colorValue, colorSet, TEST_LOCATION);
387
388   Vector4   colorAnimate(0.5f, 0.6f, 0.8f, 1.f);
389   float     durationSeconds(0.05f);
390   Animation animation = Animation::New(durationSeconds);
391   animation.AnimateTo(Property(view, EffectsView::Property::EFFECT_COLOR), colorAnimate);
392   animation.Play();
393   application.SendNotification();
394   application.Render(static_cast<unsigned int>(durationSeconds * 1000.0f) + 1u /*just beyond the animation duration*/);
395
396   value = view.GetCurrentProperty(EffectsView::Property::EFFECT_COLOR);
397   value.Get(colorValue);
398   DALI_TEST_EQUALS(colorValue, colorAnimate, TEST_LOCATION);
399
400   END_TEST;
401 }
402
403 int UtcDaliEffectsViewGetSetBackgroundColor(void)
404 {
405   ToolkitTestApplication application;
406
407   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
408   view.SetBackgroundColor(Color::RED);
409   DALI_TEST_CHECK(Color::RED == view.GetBackgroundColor());
410
411   view.SetBackgroundColor(Color::YELLOW);
412   DALI_TEST_CHECK(Color::YELLOW == view.GetBackgroundColor());
413
414   END_TEST;
415 }
416
417 int UtcDaliEffectsViewSetBackgroundColorN(void)
418 {
419   ToolkitTestApplication application;
420
421   EffectsView view;
422   try
423   {
424     view.SetBackgroundColor(Color::RED);
425     DALI_TEST_CHECK(false); // Should not get here
426   }
427   catch(...)
428   {
429     DALI_TEST_CHECK(true);
430   }
431
432   END_TEST;
433 }
434
435 int UtcDaliEffectsViewGetBackgroundColorN(void)
436 {
437   ToolkitTestApplication application;
438
439   EffectsView view;
440   try
441   {
442     Vector4 color = view.GetBackgroundColor();
443     (void)color;
444     DALI_TEST_CHECK(false); // Should not get here
445   }
446   catch(...)
447   {
448     DALI_TEST_CHECK(true);
449   }
450
451   END_TEST;
452 }
453
454 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
455 {
456   ToolkitTestApplication application;
457
458   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
459   view.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
460
461   Integration::Scene stage = application.GetScene();
462   stage.Add(view);
463   application.SendNotification();
464   application.Render();
465
466   RenderTaskList renderTaskList = stage.GetRenderTaskList();
467   DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ALWAYS);
468
469   view.SetRefreshOnDemand(true);
470   DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ONCE);
471
472   view.SetRefreshOnDemand(false);
473   DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ALWAYS);
474
475   END_TEST;
476 }
477
478 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
479 {
480   ToolkitTestApplication application;
481
482   EffectsView view;
483   try
484   {
485     view.SetRefreshOnDemand(false);
486     DALI_TEST_CHECK(false); // Should not get here
487   }
488   catch(...)
489   {
490     DALI_TEST_CHECK(true);
491   }
492
493   END_TEST;
494 }
495
496 int UtcDaliEffectsViewSizeSet(void)
497 {
498   ToolkitTestApplication application;
499   Integration::Scene     stage = application.GetScene();
500
501   {
502     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
503     view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
504     stage.Add(view);
505     application.SendNotification();
506     application.Render();
507     DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3(200.0f, 200.0f, 0.0f), TEST_LOCATION);
508   }
509
510   {
511     EffectsView view = EffectsView::New(EffectsView::EMBOSS);
512     view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
513     stage.Add(view);
514     application.SendNotification();
515     application.Render();
516
517     DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3(200.0f, 200.0f, 0.0f), TEST_LOCATION);
518   }
519
520   {
521     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
522     view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
523     stage.Add(view);
524     application.SendNotification();
525     application.Render();
526
527     stage.Remove(view);
528     application.SendNotification();
529     application.Render();
530
531     DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3(200.0f, 200.0f, 0.0f), TEST_LOCATION);
532   }
533
534   END_TEST;
535 }
536
537 int UtcDaliEffectsViewTypeRegistry(void)
538 {
539   ToolkitTestApplication application;
540
541   TypeRegistry typeRegistry = TypeRegistry::Get();
542   DALI_TEST_CHECK(typeRegistry);
543
544   TypeInfo typeInfo = typeRegistry.GetTypeInfo("EffectsView");
545   DALI_TEST_CHECK(typeInfo);
546
547   BaseHandle handle = typeInfo.CreateInstance();
548   DALI_TEST_CHECK(handle);
549
550   EffectsView view = EffectsView::DownCast(handle);
551   DALI_TEST_CHECK(view);
552
553   END_TEST;
554 }