2 * Copyright (c) 2022 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.
22 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
28 using namespace Toolkit;
30 void dali_effectsview_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_effectsview_cleanup(void)
37 test_return_value = TET_PASS;
40 int UtcDaliEffectsViewNew(void)
42 ToolkitTestApplication application;
45 DALI_TEST_CHECK(!view);
47 view = EffectsView::New(EffectsView::DROP_SHADOW);
48 DALI_TEST_CHECK(view);
50 application.GetScene().Add(view);
53 view = EffectsView::New(EffectsView::EMBOSS);
54 DALI_TEST_CHECK(view);
56 application.SendNotification();
62 int UtcDaliEffectsViewCopyAndAssignment(void)
64 ToolkitTestApplication application;
66 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
67 DALI_TEST_CHECK(view);
69 EffectsView copy(view);
70 DALI_TEST_CHECK(copy == view);
73 DALI_TEST_CHECK(!assign);
75 DALI_TEST_CHECK(assign == view);
79 DALI_TEST_CHECK(assign);
80 DALI_TEST_CHECK(assign == view);
85 int UtcDaliEffectsViewDownCast(void)
87 ToolkitTestApplication application;
89 BaseHandle view = EffectsView::New(EffectsView::EMBOSS);
90 DALI_TEST_CHECK(EffectsView::DownCast(view));
93 DALI_TEST_CHECK(!EffectsView::DownCast(empty));
95 BaseHandle another = Actor::New();
96 DALI_TEST_CHECK(!EffectsView::DownCast(another));
101 // Positive test case for a method
102 int UtcDaliEffectsViewAddRemoveDropShadow(void)
104 ToolkitTestApplication application;
105 tet_infoline("UtcDaliEffectsViewAddRemoveDropShadow");
107 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
108 DALI_TEST_CHECK(view);
110 Actor actor = Actor::New();
111 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
113 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
114 view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
116 application.GetScene().Add(view);
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);
124 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
128 int UtcDaliEffectsViewAddRemoveEmboss(void)
130 ToolkitTestApplication application;
131 tet_infoline("UtcDaliEffectsViewAddRemoveEmboss");
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);
139 tet_infoline("Create effects view");
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);
152 DALI_TEST_CHECK(view);
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));
158 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
161 view.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
165 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
167 application.SendNotification();
168 application.Render();
170 tet_infoline("Removing view from stage disables view");
173 tet_infoline("Checking number of render tasks = 1");
174 DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION);
176 tet_infoline("Adding view to stage again re-enables view");
179 tet_infoline("Removing view from stage disables view");
180 DALI_TEST_GREATER(stage.GetRenderTaskList().GetTaskCount(), 1u, TEST_LOCATION);
184 tet_infoline("Checking number of render tasks = 1");
185 DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION);
190 int UtcDaliEffectsViewGetTypeP(void)
192 ToolkitTestApplication application;
194 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
195 DALI_TEST_CHECK(view.GetType() == EffectsView::DROP_SHADOW);
198 view = EffectsView::New(EffectsView::EMBOSS);
199 DALI_TEST_CHECK(view.GetType() == EffectsView::EMBOSS);
204 int UtcDaliEffectsViewOnStage(void)
206 ToolkitTestApplication application;
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);
214 application.SendNotification();
215 application.Render();
216 DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() > 1);
221 int UtcDaliEffectsViewOffStage(void)
223 ToolkitTestApplication application;
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);
231 application.SendNotification();
232 application.Render();
233 DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() > 1);
236 application.SendNotification();
237 application.Render();
238 DALI_TEST_CHECK(stage.GetRenderTaskList().GetTaskCount() == 1);
243 int UtcDaliEffectsViewRefreshP(void)
245 ToolkitTestApplication application;
247 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
251 DALI_TEST_CHECK(true);
255 DALI_TEST_CHECK(false); // Should not get here!
261 int UtcDaliEffectsViewRefreshN(void)
263 ToolkitTestApplication application;
269 DALI_TEST_CHECK(false); // Should not get here
273 DALI_TEST_CHECK(true);
279 int UtcDaliEffectsViewSetPixelFormatP(void)
281 ToolkitTestApplication application;
283 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
286 view.SetPixelFormat(Pixel::RGBA8888);
287 DALI_TEST_CHECK(true);
291 DALI_TEST_CHECK(false); // Should not get here!
297 int UtcDaliEffectsViewSetPixelFormatN(void)
299 ToolkitTestApplication application;
304 view.SetPixelFormat(Pixel::RGBA8888);
305 DALI_TEST_CHECK(false); // Should not get here
309 DALI_TEST_CHECK(true);
315 int UtcDaliEffectsViewSizeProperty(void)
317 ToolkitTestApplication application;
319 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
321 Property::Index idx = view.GetPropertyIndex("effectSize");
322 DALI_TEST_EQUALS(idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION);
324 view.SetProperty(idx, 5);
325 Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_SIZE);
327 DALI_TEST_CHECK(value.Get(size));
328 DALI_TEST_CHECK(size == 5);
333 int UtcDaliEffectsViewOffsetProperty(void)
335 ToolkitTestApplication application;
337 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
338 application.GetScene().Add(view);
340 Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_OFFSET);
342 DALI_TEST_CHECK(value.Get(offsetValue));
343 DALI_TEST_EQUALS(offsetValue, Vector3::ZERO, TEST_LOCATION);
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);
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);
358 application.SendNotification();
359 application.Render(static_cast<unsigned int>(durationSeconds * 1000.0f) + 1u /*just beyond the animation duration*/);
361 value = view.GetCurrentProperty(EffectsView::Property::EFFECT_OFFSET);
362 value.Get(offsetValue);
363 DALI_TEST_EQUALS(offsetValue, offsetAnimate, TEST_LOCATION);
368 int UtcDaliEffectsViewColorProperty(void)
370 ToolkitTestApplication application;
372 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
373 application.GetScene().Add(view);
375 Property::Value value = view.GetProperty(EffectsView::Property::EFFECT_COLOR);
377 DALI_TEST_CHECK(value.Get(colorValue));
378 DALI_TEST_EQUALS(colorValue, Color::WHITE, TEST_LOCATION);
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);
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);
393 application.SendNotification();
394 application.Render(static_cast<unsigned int>(durationSeconds * 1000.0f) + 1u /*just beyond the animation duration*/);
396 value = view.GetCurrentProperty(EffectsView::Property::EFFECT_COLOR);
397 value.Get(colorValue);
398 DALI_TEST_EQUALS(colorValue, colorAnimate, TEST_LOCATION);
403 int UtcDaliEffectsViewGetSetBackgroundColor(void)
405 ToolkitTestApplication application;
407 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
408 view.SetBackgroundColor(Color::RED);
409 DALI_TEST_CHECK(Color::RED == view.GetBackgroundColor());
411 view.SetBackgroundColor(Color::YELLOW);
412 DALI_TEST_CHECK(Color::YELLOW == view.GetBackgroundColor());
417 int UtcDaliEffectsViewSetBackgroundColorN(void)
419 ToolkitTestApplication application;
424 view.SetBackgroundColor(Color::RED);
425 DALI_TEST_CHECK(false); // Should not get here
429 DALI_TEST_CHECK(true);
435 int UtcDaliEffectsViewGetBackgroundColorN(void)
437 ToolkitTestApplication application;
442 Vector4 color = view.GetBackgroundColor();
444 DALI_TEST_CHECK(false); // Should not get here
448 DALI_TEST_CHECK(true);
454 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
456 ToolkitTestApplication application;
458 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
459 view.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
461 Integration::Scene stage = application.GetScene();
463 application.SendNotification();
464 application.Render();
466 RenderTaskList renderTaskList = stage.GetRenderTaskList();
467 DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ALWAYS);
469 view.SetRefreshOnDemand(true);
470 DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ONCE);
472 view.SetRefreshOnDemand(false);
473 DALI_TEST_CHECK(renderTaskList.GetTask(1).GetRefreshRate() == RenderTask::REFRESH_ALWAYS);
478 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
480 ToolkitTestApplication application;
485 view.SetRefreshOnDemand(false);
486 DALI_TEST_CHECK(false); // Should not get here
490 DALI_TEST_CHECK(true);
496 int UtcDaliEffectsViewSizeSet(void)
498 ToolkitTestApplication application;
499 Integration::Scene stage = application.GetScene();
502 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
503 view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
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);
511 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
512 view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
514 application.SendNotification();
515 application.Render();
517 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3(200.0f, 200.0f, 0.0f), TEST_LOCATION);
521 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
522 view.SetProperty(Actor::Property::SIZE, Vector3(200.0f, 200.0f, 0.0f));
524 application.SendNotification();
525 application.Render();
528 application.SendNotification();
529 application.Render();
531 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3(200.0f, 200.0f, 0.0f), TEST_LOCATION);
537 int UtcDaliEffectsViewTypeRegistry(void)
539 ToolkitTestApplication application;
541 TypeRegistry typeRegistry = TypeRegistry::Get();
542 DALI_TEST_CHECK(typeRegistry);
544 TypeInfo typeInfo = typeRegistry.GetTypeInfo("EffectsView");
545 DALI_TEST_CHECK(typeInfo);
547 BaseHandle handle = typeInfo.CreateInstance();
548 DALI_TEST_CHECK(handle);
550 EffectsView view = EffectsView::DownCast(handle);
551 DALI_TEST_CHECK(view);