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() );
127 int UtcDaliEffectsViewGetTypeP(void)
129 ToolkitTestApplication application;
131 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
132 DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
135 view = EffectsView::New( EffectsView::EMBOSS );
136 DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
141 int UtcDaliEffectsViewOnStage(void)
143 ToolkitTestApplication application;
145 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
146 view.SetSize(100.f, 100.f);
147 Stage stage = Stage::GetCurrent();
148 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
151 application.SendNotification();
152 application.Render();
153 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
158 int UtcDaliEffectsViewOffStage(void)
160 ToolkitTestApplication application;
162 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
163 view.SetSize(100.f, 100.f);
164 Stage stage = Stage::GetCurrent();
165 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
168 application.SendNotification();
169 application.Render();
170 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
172 stage.Remove( view );
173 application.SendNotification();
174 application.Render();
175 DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
180 int UtcDaliEffectsViewRefreshP(void)
182 ToolkitTestApplication application;
184 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
188 DALI_TEST_CHECK( true );
192 DALI_TEST_CHECK( false ); // Should not get here!
198 int UtcDaliEffectsViewRefreshN(void)
200 ToolkitTestApplication application;
206 DALI_TEST_CHECK( false ); // Should not get here
210 DALI_TEST_CHECK( true );
216 int UtcDaliEffectsViewSetPixelFormatP(void)
218 ToolkitTestApplication application;
220 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
223 view.SetPixelFormat( Pixel::RGBA8888 );
224 DALI_TEST_CHECK( true );
228 DALI_TEST_CHECK( false ); // Should not get here!
234 int UtcDaliEffectsViewSetPixelFormatN(void)
236 ToolkitTestApplication application;
241 view.SetPixelFormat( Pixel::RGBA8888 );
242 DALI_TEST_CHECK( false ); // Should not get here
246 DALI_TEST_CHECK( true );
252 int UtcDaliEffectsViewSizeProperty(void)
254 ToolkitTestApplication application;
256 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
258 Property::Index idx = view.GetPropertyIndex( "effectSize" );
259 DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
261 view.SetProperty( idx, 5 );
262 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
264 DALI_TEST_CHECK( value.Get(size) );
265 DALI_TEST_CHECK( size == 5 );
270 int UtcDaliEffectsViewOffsetProperty(void)
272 ToolkitTestApplication application;
274 EffectsView view = EffectsView::New( EffectsView::EMBOSS );
275 Stage::GetCurrent().Add( view );
277 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
279 DALI_TEST_CHECK( value.Get(offsetValue) );
280 DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
282 Vector3 offsetSet( 2.f, 3.f, 4.f );
283 view.SetProperty( EffectsView::Property::EFFECT_OFFSET, offsetSet);
284 application.SendNotification();
285 application.Render(0);
286 value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
287 value.Get(offsetValue);
288 DALI_TEST_EQUALS( offsetValue, offsetSet, TEST_LOCATION );
290 Vector3 offsetAnimate( 4.f, 6.f, 8.f );
291 float durationSeconds(0.05f);
292 Animation animation = Animation::New( durationSeconds );
293 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_OFFSET ), offsetAnimate );
295 application.SendNotification();
296 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
298 value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
299 value.Get(offsetValue);
300 DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
305 int UtcDaliEffectsViewColorProperty(void)
307 ToolkitTestApplication application;
309 EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
310 Stage::GetCurrent().Add( view );
312 Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
314 DALI_TEST_CHECK( value.Get(colorValue) );
315 DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
317 Vector4 colorSet( 0.2f, 0.3f, 0.4f, 0.5f );
318 view.SetProperty( EffectsView::Property::EFFECT_COLOR, colorSet);
319 application.SendNotification();
320 application.Render(0);
321 value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
322 value.Get(colorValue);
323 DALI_TEST_EQUALS( colorValue, colorSet, TEST_LOCATION );
325 Vector4 colorAnimate( 0.5f, 0.6f, 0.8f, 1.f );
326 float durationSeconds(0.05f);
327 Animation animation = Animation::New( durationSeconds );
328 animation.AnimateTo( Property(view,EffectsView::Property::EFFECT_COLOR ), colorAnimate );
330 application.SendNotification();
331 application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
333 value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
334 value.Get(colorValue);
335 DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
340 int UtcDaliEffectsViewGetSetBackgroundColor(void)
342 ToolkitTestApplication application;
344 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
345 view.SetBackgroundColor( Color::RED );
346 DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
348 view.SetBackgroundColor( Color::YELLOW );
349 DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
354 int UtcDaliEffectsViewSetBackgroundColorN(void)
356 ToolkitTestApplication application;
361 view.SetBackgroundColor( Color::RED );
362 DALI_TEST_CHECK( false ); // Should not get here
366 DALI_TEST_CHECK( true );
372 int UtcDaliEffectsViewGetBackgroundColorN(void)
374 ToolkitTestApplication application;
379 Vector4 color = view.GetBackgroundColor();
381 DALI_TEST_CHECK( false ); // Should not get here
385 DALI_TEST_CHECK( true );
391 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
393 ToolkitTestApplication application;
395 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
396 view.SetSize(100.f, 100.f);
398 Stage stage = Stage::GetCurrent();
400 application.SendNotification();
401 application.Render();
403 RenderTaskList renderTaskList = stage.GetRenderTaskList();
404 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
406 view.SetRefreshOnDemand( true );
407 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
409 view.SetRefreshOnDemand( false );
410 DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
415 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
417 ToolkitTestApplication application;
422 view.SetRefreshOnDemand( false );
423 DALI_TEST_CHECK( false ); // Should not get here
427 DALI_TEST_CHECK( true );
433 int UtcDaliEffectsViewSizeSet(void)
435 ToolkitTestApplication application;
436 Stage stage = Stage::GetCurrent();
439 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
440 view.SetSize( 200.0f, 200.0f, 0.0f );
442 application.SendNotification();
443 application.Render();
444 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
448 EffectsView view = EffectsView::New(EffectsView::EMBOSS);
449 view.SetSize( 200.0f, 200.0f, 0.0f );
451 application.SendNotification();
452 application.Render();
454 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
458 EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
459 view.SetSize( 200.0f, 200.0f, 0.0f );
461 application.SendNotification();
462 application.Render();
464 stage.Remove( view );
465 application.SendNotification();
466 application.Render();
468 DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
474 int UtcDaliEffectsViewTypeRegistry(void)
476 ToolkitTestApplication application;
478 TypeRegistry typeRegistry = TypeRegistry::Get();
479 DALI_TEST_CHECK( typeRegistry );
481 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
482 DALI_TEST_CHECK( typeInfo );
484 BaseHandle handle = typeInfo.CreateInstance();
485 DALI_TEST_CHECK( handle );
487 EffectsView view = EffectsView::DownCast( handle );
488 DALI_TEST_CHECK( view );