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