2 * Copyright (c) 2017 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.
21 #include <dali/devel-api/object/handle-devel.h>
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
27 using namespace Toolkit;
29 void dali_effectsview_startup(void)
31 test_return_value = TET_UNDEF;
34 void dali_effectsview_cleanup(void)
36 test_return_value = TET_PASS;
39 int UtcDaliEffectsViewNew(void)
41 ToolkitTestApplication application;
44 DALI_TEST_CHECK( !view );
46 view = EffectsView::New( EffectsView::DROP_SHADOW );
47 DALI_TEST_CHECK( view );
49 Stage::GetCurrent().Add( view );
52 view = EffectsView::New( EffectsView::EMBOSS );
53 DALI_TEST_CHECK( view );
55 application.SendNotification();
61 int UtcDaliEffectsViewCopyAndAssignment(void)
63 ToolkitTestApplication application;
65 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
66 DALI_TEST_CHECK( view );
68 EffectsView copy( view );
69 DALI_TEST_CHECK( copy == view );
72 DALI_TEST_CHECK( !assign );
74 DALI_TEST_CHECK( assign == view );
78 DALI_TEST_CHECK( assign );
79 DALI_TEST_CHECK( assign == view );
84 int UtcDaliEffectsViewDownCast(void)
86 ToolkitTestApplication application;
88 BaseHandle view = EffectsView::New( EffectsView::EMBOSS );
89 DALI_TEST_CHECK( EffectsView::DownCast( view ) );
92 DALI_TEST_CHECK( ! EffectsView::DownCast( empty ) );
94 BaseHandle another = Actor::New();
95 DALI_TEST_CHECK( ! EffectsView::DownCast( another ) );
100 // Positive test case for a method
101 int UtcDaliEffectsViewAddRemoveDropShadow(void)
103 ToolkitTestApplication application;
104 tet_infoline("UtcDaliEffectsViewAddRemoveDropShadow");
106 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
107 DALI_TEST_CHECK( view );
109 Actor actor = Actor::New();
110 DALI_TEST_CHECK( !actor.OnStage() );
113 view.SetParentOrigin(ParentOrigin::CENTER);
114 view.SetSize(Stage::GetCurrent().GetSize());
116 Stage::GetCurrent().Add(view);
118 DALI_TEST_CHECK( actor.OnStage() );
119 DALI_TEST_CHECK( actor.GetParent() );
120 DALI_TEST_CHECK( actor.GetParent() != view );
124 DALI_TEST_CHECK( !actor.OnStage() );
129 int UtcDaliEffectsViewAddRemoveEmboss(void)
131 ToolkitTestApplication application;
132 tet_infoline("UtcDaliEffectsViewAddRemoveEmboss");
134 tet_infoline("Checking number of render tasks = 1");
135 application.SendNotification();
136 application.Render();
137 Stage stage = Stage::GetCurrent();
138 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION );
140 tet_infoline("Create effects view");
142 EffectsView view = EffectsView::New( EffectsView::EMBOSS );
143 Vector3 offsetSet( 2.f, 3.f, 4.f );
144 Vector4 colorSet( 0.2f, 0.3f, 0.4f, 0.5f );
145 view.SetProperty( EffectsView::Property::EFFECT_OFFSET, offsetSet);
146 view.SetProperty( EffectsView::Property::EFFECT_COLOR, colorSet);
147 Vector3 offsetAnimate( 4.f, 6.f, 8.f );
148 float durationSeconds(0.05f);
149 Animation animation = Animation::New( durationSeconds );
150 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_OFFSET ), offsetAnimate );
153 DALI_TEST_CHECK( view );
155 Actor actor = Actor::New();
156 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
157 DALI_TEST_CHECK( !actor.OnStage() );
159 view.SetParentOrigin(ParentOrigin::CENTER);
162 view.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
166 DALI_TEST_CHECK( actor.OnStage() );
168 application.SendNotification();
169 application.Render();
171 tet_infoline("Removing view from stage disables view");
174 tet_infoline("Checking number of render tasks = 1");
175 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION );
177 tet_infoline("Adding view to stage again re-enables view");
180 tet_infoline("Removing view from stage disables view");
181 DALI_TEST_GREATER( stage.GetRenderTaskList().GetTaskCount(), 1u, TEST_LOCATION );
185 tet_infoline("Checking number of render tasks = 1");
186 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION );
192 int UtcDaliEffectsViewGetTypeP(void)
194 ToolkitTestApplication application;
196 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
197 DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
200 view = EffectsView::New( EffectsView::EMBOSS );
201 DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
206 int UtcDaliEffectsViewOnStage(void)
208 ToolkitTestApplication application;
210 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
211 view.SetSize(100.f, 100.f);
212 Stage stage = Stage::GetCurrent();
213 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
216 application.SendNotification();
217 application.Render();
218 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
223 int UtcDaliEffectsViewOffStage(void)
225 ToolkitTestApplication application;
227 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
228 view.SetSize(100.f, 100.f);
229 Stage stage = Stage::GetCurrent();
230 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
233 application.SendNotification();
234 application.Render();
235 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
237 stage.Remove( view );
238 application.SendNotification();
239 application.Render();
240 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
245 int UtcDaliEffectsViewRefreshP(void)
247 ToolkitTestApplication application;
249 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
253 DALI_TEST_CHECK( true );
257 DALI_TEST_CHECK( false ); // Should not get here!
263 int UtcDaliEffectsViewRefreshN(void)
265 ToolkitTestApplication application;
271 DALI_TEST_CHECK( false ); // Should not get here
275 DALI_TEST_CHECK( true );
281 int UtcDaliEffectsViewSetPixelFormatP(void)
283 ToolkitTestApplication application;
285 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
288 view.SetPixelFormat( Pixel::RGBA8888 );
289 DALI_TEST_CHECK( true );
293 DALI_TEST_CHECK( false ); // Should not get here!
299 int UtcDaliEffectsViewSetPixelFormatN(void)
301 ToolkitTestApplication application;
306 view.SetPixelFormat( Pixel::RGBA8888 );
307 DALI_TEST_CHECK( false ); // Should not get here
311 DALI_TEST_CHECK( true );
317 int UtcDaliEffectsViewSizeProperty(void)
319 ToolkitTestApplication application;
321 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
323 Property::Index idx = view.GetPropertyIndex( "effectSize" );
324 DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
326 view.SetProperty( idx, 5 );
327 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
329 DALI_TEST_CHECK( value.Get(size) );
330 DALI_TEST_CHECK( size == 5 );
335 int UtcDaliEffectsViewOffsetProperty(void)
337 ToolkitTestApplication application;
339 EffectsView view = EffectsView::New( EffectsView::EMBOSS );
340 Stage::GetCurrent().Add( view );
342 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
344 DALI_TEST_CHECK( value.Get(offsetValue) );
345 DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
347 Vector3 offsetSet( 2.f, 3.f, 4.f );
348 view.SetProperty( EffectsView::Property::EFFECT_OFFSET, offsetSet);
349 application.SendNotification();
350 application.Render(0);
351 value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
352 value.Get(offsetValue);
353 DALI_TEST_EQUALS( offsetValue, offsetSet, TEST_LOCATION );
355 Vector3 offsetAnimate( 4.f, 6.f, 8.f );
356 float durationSeconds(0.05f);
357 Animation animation = Animation::New( durationSeconds );
358 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_OFFSET ), offsetAnimate );
360 application.SendNotification();
361 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
363 value = DevelHandle::GetCurrentProperty( view, EffectsView::Property::EFFECT_OFFSET );
364 value.Get(offsetValue);
365 DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
370 int UtcDaliEffectsViewColorProperty(void)
372 ToolkitTestApplication application;
374 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
375 Stage::GetCurrent().Add( view );
377 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
379 DALI_TEST_CHECK( value.Get(colorValue) );
380 DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
382 Vector4 colorSet( 0.2f, 0.3f, 0.4f, 0.5f );
383 view.SetProperty( EffectsView::Property::EFFECT_COLOR, colorSet);
384 application.SendNotification();
385 application.Render(0);
386 value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
387 value.Get(colorValue);
388 DALI_TEST_EQUALS( colorValue, colorSet, TEST_LOCATION );
390 Vector4 colorAnimate( 0.5f, 0.6f, 0.8f, 1.f );
391 float durationSeconds(0.05f);
392 Animation animation = Animation::New( durationSeconds );
393 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_COLOR ), colorAnimate );
395 application.SendNotification();
396 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
398 value = DevelHandle::GetCurrentProperty( view, EffectsView::Property::EFFECT_COLOR );
399 value.Get(colorValue);
400 DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
405 int UtcDaliEffectsViewGetSetBackgroundColor(void)
407 ToolkitTestApplication application;
409 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
410 view.SetBackgroundColor( Color::RED );
411 DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
413 view.SetBackgroundColor( Color::YELLOW );
414 DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
419 int UtcDaliEffectsViewSetBackgroundColorN(void)
421 ToolkitTestApplication application;
426 view.SetBackgroundColor( Color::RED );
427 DALI_TEST_CHECK( false ); // Should not get here
431 DALI_TEST_CHECK( true );
437 int UtcDaliEffectsViewGetBackgroundColorN(void)
439 ToolkitTestApplication application;
444 Vector4 color = view.GetBackgroundColor();
446 DALI_TEST_CHECK( false ); // Should not get here
450 DALI_TEST_CHECK( true );
456 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
458 ToolkitTestApplication application;
460 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
461 view.SetSize(100.f, 100.f);
463 Stage stage = Stage::GetCurrent();
465 application.SendNotification();
466 application.Render();
468 RenderTaskList renderTaskList = stage.GetRenderTaskList();
469 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
471 view.SetRefreshOnDemand( true );
472 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
474 view.SetRefreshOnDemand( false );
475 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
480 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
482 ToolkitTestApplication application;
487 view.SetRefreshOnDemand( false );
488 DALI_TEST_CHECK( false ); // Should not get here
492 DALI_TEST_CHECK( true );
498 int UtcDaliEffectsViewSizeSet(void)
500 ToolkitTestApplication application;
501 Stage stage = Stage::GetCurrent();
504 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
505 view.SetSize( 200.0f, 200.0f, 0.0f );
507 application.SendNotification();
508 application.Render();
509 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
513 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
514 view.SetSize( 200.0f, 200.0f, 0.0f );
516 application.SendNotification();
517 application.Render();
519 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
523 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
524 view.SetSize( 200.0f, 200.0f, 0.0f );
526 application.SendNotification();
527 application.Render();
529 stage.Remove( view );
530 application.SendNotification();
531 application.Render();
533 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
539 int UtcDaliEffectsViewTypeRegistry(void)
541 ToolkitTestApplication application;
543 TypeRegistry typeRegistry = TypeRegistry::Get();
544 DALI_TEST_CHECK( typeRegistry );
546 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
547 DALI_TEST_CHECK( typeInfo );
549 BaseHandle handle = typeInfo.CreateInstance();
550 DALI_TEST_CHECK( handle );
552 EffectsView view = EffectsView::DownCast( handle );
553 DALI_TEST_CHECK( view );