2 * Copyright (c) 2014 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 UtcDaliEffectsViewAddRemove(void)
102 ToolkitTestApplication application;
103 tet_infoline("UtcDaliGaussianBlurViewAddRemove");
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 );
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.SetSize(100.f, 100.f);
210 Stage stage = Stage::GetCurrent();
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.SetSize(100.f, 100.f);
227 Stage stage = Stage::GetCurrent();
228 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
231 application.SendNotification();
232 application.Render();
233 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
235 stage.Remove( view );
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 Stage::GetCurrent().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.GetProperty( 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 Stage::GetCurrent().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.GetProperty( 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.SetSize(100.f, 100.f);
461 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
502 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
503 view.SetSize( 200.0f, 200.0f, 0.0f );
505 application.SendNotification();
506 application.Render();
507 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
511 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
512 view.SetSize( 200.0f, 200.0f, 0.0f );
514 application.SendNotification();
515 application.Render();
517 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
521 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
522 view.SetSize( 200.0f, 200.0f, 0.0f );
524 application.SendNotification();
525 application.Render();
527 stage.Remove( view );
528 application.SendNotification();
529 application.Render();
531 DALI_TEST_EQUALS( view.GetCurrentSize(), 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 );