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-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
26 using namespace Toolkit;
28 void dali_effectsview_startup(void)
30 test_return_value = TET_UNDEF;
33 void dali_effectsview_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliEffectsViewNew(void)
40 ToolkitTestApplication application;
43 DALI_TEST_CHECK( !view );
45 view = EffectsView::New( EffectsView::DROP_SHADOW );
46 DALI_TEST_CHECK( view );
48 Stage::GetCurrent().Add( view );
51 view = EffectsView::New( EffectsView::EMBOSS );
52 DALI_TEST_CHECK( view );
54 application.SendNotification();
60 int UtcDaliEffectsViewCopyAndAssignment(void)
62 ToolkitTestApplication application;
64 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
65 DALI_TEST_CHECK( view );
67 EffectsView copy( view );
68 DALI_TEST_CHECK( copy == view );
71 DALI_TEST_CHECK( !assign );
73 DALI_TEST_CHECK( assign == view );
77 DALI_TEST_CHECK( assign );
78 DALI_TEST_CHECK( assign == view );
83 int UtcDaliEffectsViewDownCast(void)
85 ToolkitTestApplication application;
87 BaseHandle view = EffectsView::New( EffectsView::EMBOSS );
88 DALI_TEST_CHECK( EffectsView::DownCast( view ) );
91 DALI_TEST_CHECK( ! EffectsView::DownCast( empty ) );
93 BaseHandle another = Actor::New();
94 DALI_TEST_CHECK( ! EffectsView::DownCast( another ) );
99 // Positive test case for a method
100 int UtcDaliEffectsViewAddRemoveDropShadow(void)
102 ToolkitTestApplication application;
103 tet_infoline("UtcDaliEffectsViewAddRemoveDropShadow");
105 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
106 DALI_TEST_CHECK( view );
108 Actor actor = Actor::New();
109 DALI_TEST_CHECK( !actor.OnStage() );
112 view.SetParentOrigin(ParentOrigin::CENTER);
113 view.SetSize(Stage::GetCurrent().GetSize());
115 Stage::GetCurrent().Add(view);
117 DALI_TEST_CHECK( actor.OnStage() );
118 DALI_TEST_CHECK( actor.GetParent() );
119 DALI_TEST_CHECK( actor.GetParent() != view );
123 DALI_TEST_CHECK( !actor.OnStage() );
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 Stage stage = Stage::GetCurrent();
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.OnStage() );
158 view.SetParentOrigin(ParentOrigin::CENTER);
161 view.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
165 DALI_TEST_CHECK( actor.OnStage() );
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 );
191 int UtcDaliEffectsViewGetTypeP(void)
193 ToolkitTestApplication application;
195 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
196 DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
199 view = EffectsView::New( EffectsView::EMBOSS );
200 DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
205 int UtcDaliEffectsViewOnStage(void)
207 ToolkitTestApplication application;
209 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
210 view.SetSize(100.f, 100.f);
211 Stage stage = Stage::GetCurrent();
212 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
215 application.SendNotification();
216 application.Render();
217 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
222 int UtcDaliEffectsViewOffStage(void)
224 ToolkitTestApplication application;
226 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
227 view.SetSize(100.f, 100.f);
228 Stage stage = Stage::GetCurrent();
229 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
232 application.SendNotification();
233 application.Render();
234 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
236 stage.Remove( view );
237 application.SendNotification();
238 application.Render();
239 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
244 int UtcDaliEffectsViewRefreshP(void)
246 ToolkitTestApplication application;
248 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
252 DALI_TEST_CHECK( true );
256 DALI_TEST_CHECK( false ); // Should not get here!
262 int UtcDaliEffectsViewRefreshN(void)
264 ToolkitTestApplication application;
270 DALI_TEST_CHECK( false ); // Should not get here
274 DALI_TEST_CHECK( true );
280 int UtcDaliEffectsViewSetPixelFormatP(void)
282 ToolkitTestApplication application;
284 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
287 view.SetPixelFormat( Pixel::RGBA8888 );
288 DALI_TEST_CHECK( true );
292 DALI_TEST_CHECK( false ); // Should not get here!
298 int UtcDaliEffectsViewSetPixelFormatN(void)
300 ToolkitTestApplication application;
305 view.SetPixelFormat( Pixel::RGBA8888 );
306 DALI_TEST_CHECK( false ); // Should not get here
310 DALI_TEST_CHECK( true );
316 int UtcDaliEffectsViewSizeProperty(void)
318 ToolkitTestApplication application;
320 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
322 Property::Index idx = view.GetPropertyIndex( "effectSize" );
323 DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
325 view.SetProperty( idx, 5 );
326 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
328 DALI_TEST_CHECK( value.Get(size) );
329 DALI_TEST_CHECK( size == 5 );
334 int UtcDaliEffectsViewOffsetProperty(void)
336 ToolkitTestApplication application;
338 EffectsView view = EffectsView::New( EffectsView::EMBOSS );
339 Stage::GetCurrent().Add( view );
341 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
343 DALI_TEST_CHECK( value.Get(offsetValue) );
344 DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
346 Vector3 offsetSet( 2.f, 3.f, 4.f );
347 view.SetProperty( EffectsView::Property::EFFECT_OFFSET, offsetSet);
348 application.SendNotification();
349 application.Render(0);
350 value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
351 value.Get(offsetValue);
352 DALI_TEST_EQUALS( offsetValue, offsetSet, TEST_LOCATION );
354 Vector3 offsetAnimate( 4.f, 6.f, 8.f );
355 float durationSeconds(0.05f);
356 Animation animation = Animation::New( durationSeconds );
357 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_OFFSET ), offsetAnimate );
359 application.SendNotification();
360 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
362 value = view.GetCurrentProperty( EffectsView::Property::EFFECT_OFFSET );
363 value.Get(offsetValue);
364 DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
369 int UtcDaliEffectsViewColorProperty(void)
371 ToolkitTestApplication application;
373 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
374 Stage::GetCurrent().Add( view );
376 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
378 DALI_TEST_CHECK( value.Get(colorValue) );
379 DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
381 Vector4 colorSet( 0.2f, 0.3f, 0.4f, 0.5f );
382 view.SetProperty( EffectsView::Property::EFFECT_COLOR, colorSet);
383 application.SendNotification();
384 application.Render(0);
385 value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
386 value.Get(colorValue);
387 DALI_TEST_EQUALS( colorValue, colorSet, TEST_LOCATION );
389 Vector4 colorAnimate( 0.5f, 0.6f, 0.8f, 1.f );
390 float durationSeconds(0.05f);
391 Animation animation = Animation::New( durationSeconds );
392 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_COLOR ), colorAnimate );
394 application.SendNotification();
395 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
397 value = view.GetCurrentProperty( EffectsView::Property::EFFECT_COLOR );
398 value.Get(colorValue);
399 DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
404 int UtcDaliEffectsViewGetSetBackgroundColor(void)
406 ToolkitTestApplication application;
408 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
409 view.SetBackgroundColor( Color::RED );
410 DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
412 view.SetBackgroundColor( Color::YELLOW );
413 DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
418 int UtcDaliEffectsViewSetBackgroundColorN(void)
420 ToolkitTestApplication application;
425 view.SetBackgroundColor( Color::RED );
426 DALI_TEST_CHECK( false ); // Should not get here
430 DALI_TEST_CHECK( true );
436 int UtcDaliEffectsViewGetBackgroundColorN(void)
438 ToolkitTestApplication application;
443 Vector4 color = view.GetBackgroundColor();
445 DALI_TEST_CHECK( false ); // Should not get here
449 DALI_TEST_CHECK( true );
455 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
457 ToolkitTestApplication application;
459 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
460 view.SetSize(100.f, 100.f);
462 Stage stage = Stage::GetCurrent();
464 application.SendNotification();
465 application.Render();
467 RenderTaskList renderTaskList = stage.GetRenderTaskList();
468 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
470 view.SetRefreshOnDemand( true );
471 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
473 view.SetRefreshOnDemand( false );
474 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
479 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
481 ToolkitTestApplication application;
486 view.SetRefreshOnDemand( false );
487 DALI_TEST_CHECK( false ); // Should not get here
491 DALI_TEST_CHECK( true );
497 int UtcDaliEffectsViewSizeSet(void)
499 ToolkitTestApplication application;
500 Stage stage = Stage::GetCurrent();
503 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
504 view.SetSize( 200.0f, 200.0f, 0.0f );
506 application.SendNotification();
507 application.Render();
508 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
512 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
513 view.SetSize( 200.0f, 200.0f, 0.0f );
515 application.SendNotification();
516 application.Render();
518 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
522 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
523 view.SetSize( 200.0f, 200.0f, 0.0f );
525 application.SendNotification();
526 application.Render();
528 stage.Remove( view );
529 application.SendNotification();
530 application.Render();
532 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
538 int UtcDaliEffectsViewTypeRegistry(void)
540 ToolkitTestApplication application;
542 TypeRegistry typeRegistry = TypeRegistry::Get();
543 DALI_TEST_CHECK( typeRegistry );
545 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
546 DALI_TEST_CHECK( typeInfo );
548 BaseHandle handle = typeInfo.CreateInstance();
549 DALI_TEST_CHECK( handle );
551 EffectsView view = EffectsView::DownCast( handle );
552 DALI_TEST_CHECK( view );