Disabling EmbossFilter now removes all render tasks.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-EffectsView.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <sstream>
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>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 void dali_effectsview_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void dali_effectsview_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 int UtcDaliEffectsViewNew(void)
39 {
40   ToolkitTestApplication application;
41
42   EffectsView view;
43   DALI_TEST_CHECK( !view );
44
45   view = EffectsView::New( EffectsView::DROP_SHADOW );
46   DALI_TEST_CHECK( view );
47
48   Stage::GetCurrent().Add( view );
49
50   view.Reset();
51   view = EffectsView::New( EffectsView::EMBOSS );
52   DALI_TEST_CHECK( view );
53
54   application.SendNotification();
55   application.Render();
56
57   END_TEST;
58 }
59
60 int UtcDaliEffectsViewCopyAndAssignment(void)
61 {
62   ToolkitTestApplication application;
63
64   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
65   DALI_TEST_CHECK( view );
66
67   EffectsView copy( view );
68   DALI_TEST_CHECK( copy == view );
69
70   EffectsView assign;
71   DALI_TEST_CHECK( !assign );
72   assign = view;
73   DALI_TEST_CHECK( assign == view );
74
75   // Self assignment
76   assign = assign;
77   DALI_TEST_CHECK( assign );
78   DALI_TEST_CHECK( assign == view );
79
80   END_TEST;
81 }
82
83 int UtcDaliEffectsViewDownCast(void)
84 {
85   ToolkitTestApplication application;
86
87   BaseHandle view = EffectsView::New( EffectsView::EMBOSS );
88   DALI_TEST_CHECK( EffectsView::DownCast( view ) );
89
90   BaseHandle empty;
91   DALI_TEST_CHECK( ! EffectsView::DownCast( empty ) );
92
93   BaseHandle another = Actor::New();
94   DALI_TEST_CHECK( ! EffectsView::DownCast( another ) );
95
96   END_TEST;
97 }
98
99 // Positive test case for a method
100 int UtcDaliEffectsViewAddRemove(void)
101 {
102   ToolkitTestApplication application;
103   tet_infoline("UtcDaliGaussianBlurViewAddRemove");
104
105   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
106   DALI_TEST_CHECK( view );
107
108   Actor actor = Actor::New();
109   DALI_TEST_CHECK( !actor.OnStage() );
110
111
112   view.SetParentOrigin(ParentOrigin::CENTER);
113   view.SetSize(Stage::GetCurrent().GetSize());
114   view.Add(actor);
115   Stage::GetCurrent().Add(view);
116
117   DALI_TEST_CHECK( actor.OnStage() );
118   DALI_TEST_CHECK( actor.GetParent() );
119   DALI_TEST_CHECK( actor.GetParent() != view );
120
121   view.Remove(actor);
122
123   DALI_TEST_CHECK( !actor.OnStage() );
124   END_TEST;
125 }
126
127
128 int UtcDaliEffectsViewAddRemoveEmboss(void)
129 {
130   ToolkitTestApplication application;
131   tet_infoline("UtcDaliEffectsViewAddRemoveEmboss");
132
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 );
138
139   tet_infoline("Create effects view");
140
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 );
150   animation.Play();
151
152   DALI_TEST_CHECK( view );
153
154   Actor actor = Actor::New();
155   actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
156   DALI_TEST_CHECK( !actor.OnStage() );
157
158   view.SetParentOrigin(ParentOrigin::CENTER);
159
160   view.Add(actor);
161   view.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
162
163   stage.Add(view);
164
165   DALI_TEST_CHECK( actor.OnStage() );
166
167   application.SendNotification();
168   application.Render();
169
170   tet_infoline("Removing view from stage disables view");
171   stage.Remove(view);
172
173   tet_infoline("Checking number of render tasks = 1");
174   DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION );
175
176   tet_infoline("Adding view to stage again re-enables view");
177   stage.Add(view);
178
179   tet_infoline("Removing view from stage disables view");
180   DALI_TEST_GREATER( stage.GetRenderTaskList().GetTaskCount(), 1u, TEST_LOCATION );
181   stage.Remove(view);
182   view.Reset();
183
184   tet_infoline("Checking number of render tasks = 1");
185   DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTaskCount(), 1, TEST_LOCATION );
186
187   END_TEST;
188 }
189
190 int UtcDaliEffectsViewGetTypeP(void)
191 {
192   ToolkitTestApplication application;
193
194   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
195   DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
196
197   view.Reset();
198   view = EffectsView::New( EffectsView::EMBOSS );
199   DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
200
201   END_TEST;
202 }
203
204 int UtcDaliEffectsViewOnStage(void)
205 {
206   ToolkitTestApplication application;
207
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 );
212
213   stage.Add( view );
214   application.SendNotification();
215   application.Render();
216   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
217
218   END_TEST;
219 }
220
221 int UtcDaliEffectsViewOffStage(void)
222 {
223   ToolkitTestApplication application;
224
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 );
229
230   stage.Add( view );
231   application.SendNotification();
232   application.Render();
233   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
234
235   stage.Remove( view );
236   application.SendNotification();
237   application.Render();
238   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
239
240   END_TEST;
241 }
242
243 int UtcDaliEffectsViewRefreshP(void)
244 {
245   ToolkitTestApplication application;
246
247   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
248   try
249   {
250     view.Refresh();
251     DALI_TEST_CHECK( true );
252   }
253   catch( ... )
254   {
255     DALI_TEST_CHECK( false ); // Should not get here!
256   }
257
258   END_TEST;
259 }
260
261 int UtcDaliEffectsViewRefreshN(void)
262 {
263   ToolkitTestApplication application;
264
265   EffectsView view;
266   try
267   {
268     view.Refresh();
269     DALI_TEST_CHECK( false ); // Should not get here
270   }
271   catch( ... )
272   {
273     DALI_TEST_CHECK( true );
274   }
275
276   END_TEST;
277 }
278
279 int UtcDaliEffectsViewSetPixelFormatP(void)
280 {
281   ToolkitTestApplication application;
282
283   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
284   try
285   {
286     view.SetPixelFormat( Pixel::RGBA8888 );
287     DALI_TEST_CHECK( true );
288   }
289   catch( ... )
290   {
291     DALI_TEST_CHECK( false ); // Should not get here!
292   }
293
294   END_TEST;
295 }
296
297 int UtcDaliEffectsViewSetPixelFormatN(void)
298 {
299   ToolkitTestApplication application;
300
301   EffectsView view;
302   try
303   {
304     view.SetPixelFormat( Pixel::RGBA8888 );
305     DALI_TEST_CHECK( false ); // Should not get here
306   }
307   catch( ... )
308   {
309     DALI_TEST_CHECK( true );
310   }
311
312   END_TEST;
313 }
314
315 int UtcDaliEffectsViewSizeProperty(void)
316 {
317   ToolkitTestApplication application;
318
319   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
320
321   Property::Index idx = view.GetPropertyIndex( "effectSize" );
322   DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
323
324   view.SetProperty( idx, 5 );
325   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
326   int size;
327   DALI_TEST_CHECK( value.Get(size) );
328   DALI_TEST_CHECK( size == 5 );
329
330   END_TEST;
331 }
332
333 int UtcDaliEffectsViewOffsetProperty(void)
334 {
335   ToolkitTestApplication application;
336
337   EffectsView view = EffectsView::New( EffectsView::EMBOSS );
338   Stage::GetCurrent().Add( view );
339
340   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
341   Vector3 offsetValue;
342   DALI_TEST_CHECK( value.Get(offsetValue) );
343   DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
344
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 );
352
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 );
357   animation.Play();
358   application.SendNotification();
359   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
360
361   value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
362   value.Get(offsetValue);
363   DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
364
365   END_TEST;
366 }
367
368 int UtcDaliEffectsViewColorProperty(void)
369 {
370   ToolkitTestApplication application;
371
372   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
373   Stage::GetCurrent().Add( view );
374
375   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
376   Vector4 colorValue;
377   DALI_TEST_CHECK( value.Get(colorValue) );
378   DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
379
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 );
387
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 );
392   animation.Play();
393   application.SendNotification();
394   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
395
396   value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
397   value.Get(colorValue);
398   DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
399
400   END_TEST;
401 }
402
403 int UtcDaliEffectsViewGetSetBackgroundColor(void)
404 {
405   ToolkitTestApplication application;
406
407   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
408   view.SetBackgroundColor( Color::RED );
409   DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
410
411   view.SetBackgroundColor( Color::YELLOW );
412   DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
413
414   END_TEST;
415 }
416
417 int UtcDaliEffectsViewSetBackgroundColorN(void)
418 {
419   ToolkitTestApplication application;
420
421   EffectsView view;
422   try
423   {
424     view.SetBackgroundColor( Color::RED );
425     DALI_TEST_CHECK( false ); // Should not get here
426   }
427   catch( ... )
428   {
429     DALI_TEST_CHECK( true );
430   }
431
432   END_TEST;
433 }
434
435 int UtcDaliEffectsViewGetBackgroundColorN(void)
436 {
437   ToolkitTestApplication application;
438
439   EffectsView view;
440   try
441   {
442     Vector4 color = view.GetBackgroundColor();
443     (void)color;
444     DALI_TEST_CHECK( false ); // Should not get here
445   }
446   catch( ... )
447   {
448     DALI_TEST_CHECK( true );
449   }
450
451   END_TEST;
452 }
453
454 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
455 {
456   ToolkitTestApplication application;
457
458   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
459   view.SetSize(100.f, 100.f);
460
461   Stage stage = Stage::GetCurrent();
462   stage.Add( view );
463   application.SendNotification();
464   application.Render();
465
466   RenderTaskList renderTaskList = stage.GetRenderTaskList();
467   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
468
469   view.SetRefreshOnDemand( true );
470   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
471
472   view.SetRefreshOnDemand( false );
473   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
474
475   END_TEST;
476 }
477
478 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
479 {
480   ToolkitTestApplication application;
481
482   EffectsView view;
483   try
484   {
485     view.SetRefreshOnDemand( false );
486     DALI_TEST_CHECK( false ); // Should not get here
487   }
488   catch( ... )
489   {
490     DALI_TEST_CHECK( true );
491   }
492
493   END_TEST;
494 }
495
496 int UtcDaliEffectsViewSizeSet(void)
497 {
498   ToolkitTestApplication application;
499   Stage stage = Stage::GetCurrent();
500
501   {
502     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
503     view.SetSize( 200.0f, 200.0f, 0.0f );
504     stage.Add( view );
505     application.SendNotification();
506     application.Render();
507     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
508   }
509
510   {
511     EffectsView view = EffectsView::New(EffectsView::EMBOSS);
512     view.SetSize( 200.0f, 200.0f, 0.0f );
513     stage.Add( view );
514     application.SendNotification();
515     application.Render();
516
517     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
518   }
519
520   {
521     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
522     view.SetSize( 200.0f, 200.0f, 0.0f );
523     stage.Add( view );
524     application.SendNotification();
525     application.Render();
526
527     stage.Remove( view );
528     application.SendNotification();
529     application.Render();
530
531     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
532   }
533
534   END_TEST;
535 }
536
537 int UtcDaliEffectsViewTypeRegistry(void)
538 {
539   ToolkitTestApplication application;
540
541   TypeRegistry typeRegistry = TypeRegistry::Get();
542   DALI_TEST_CHECK( typeRegistry );
543
544   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
545   DALI_TEST_CHECK( typeInfo );
546
547   BaseHandle handle = typeInfo.CreateInstance();
548   DALI_TEST_CHECK( handle );
549
550   EffectsView view = EffectsView::DownCast( handle );
551   DALI_TEST_CHECK( view );
552
553   END_TEST;
554 }