Button Upgrade to use Text Visual
[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 UtcDaliEffectsViewAddRemoveDropShadow(void)
101 {
102   ToolkitTestApplication application;
103   tet_infoline("UtcDaliEffectsViewAddRemoveDropShadow");
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
191 int UtcDaliEffectsViewGetTypeP(void)
192 {
193   ToolkitTestApplication application;
194
195   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
196   DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
197
198   view.Reset();
199   view = EffectsView::New( EffectsView::EMBOSS );
200   DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
201
202   END_TEST;
203 }
204
205 int UtcDaliEffectsViewOnStage(void)
206 {
207   ToolkitTestApplication application;
208
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 );
213
214   stage.Add( view );
215   application.SendNotification();
216   application.Render();
217   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
218
219   END_TEST;
220 }
221
222 int UtcDaliEffectsViewOffStage(void)
223 {
224   ToolkitTestApplication application;
225
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 );
230
231   stage.Add( view );
232   application.SendNotification();
233   application.Render();
234   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
235
236   stage.Remove( view );
237   application.SendNotification();
238   application.Render();
239   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
240
241   END_TEST;
242 }
243
244 int UtcDaliEffectsViewRefreshP(void)
245 {
246   ToolkitTestApplication application;
247
248   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
249   try
250   {
251     view.Refresh();
252     DALI_TEST_CHECK( true );
253   }
254   catch( ... )
255   {
256     DALI_TEST_CHECK( false ); // Should not get here!
257   }
258
259   END_TEST;
260 }
261
262 int UtcDaliEffectsViewRefreshN(void)
263 {
264   ToolkitTestApplication application;
265
266   EffectsView view;
267   try
268   {
269     view.Refresh();
270     DALI_TEST_CHECK( false ); // Should not get here
271   }
272   catch( ... )
273   {
274     DALI_TEST_CHECK( true );
275   }
276
277   END_TEST;
278 }
279
280 int UtcDaliEffectsViewSetPixelFormatP(void)
281 {
282   ToolkitTestApplication application;
283
284   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
285   try
286   {
287     view.SetPixelFormat( Pixel::RGBA8888 );
288     DALI_TEST_CHECK( true );
289   }
290   catch( ... )
291   {
292     DALI_TEST_CHECK( false ); // Should not get here!
293   }
294
295   END_TEST;
296 }
297
298 int UtcDaliEffectsViewSetPixelFormatN(void)
299 {
300   ToolkitTestApplication application;
301
302   EffectsView view;
303   try
304   {
305     view.SetPixelFormat( Pixel::RGBA8888 );
306     DALI_TEST_CHECK( false ); // Should not get here
307   }
308   catch( ... )
309   {
310     DALI_TEST_CHECK( true );
311   }
312
313   END_TEST;
314 }
315
316 int UtcDaliEffectsViewSizeProperty(void)
317 {
318   ToolkitTestApplication application;
319
320   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
321
322   Property::Index idx = view.GetPropertyIndex( "effectSize" );
323   DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
324
325   view.SetProperty( idx, 5 );
326   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
327   int size;
328   DALI_TEST_CHECK( value.Get(size) );
329   DALI_TEST_CHECK( size == 5 );
330
331   END_TEST;
332 }
333
334 int UtcDaliEffectsViewOffsetProperty(void)
335 {
336   ToolkitTestApplication application;
337
338   EffectsView view = EffectsView::New( EffectsView::EMBOSS );
339   Stage::GetCurrent().Add( view );
340
341   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
342   Vector3 offsetValue;
343   DALI_TEST_CHECK( value.Get(offsetValue) );
344   DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
345
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 );
353
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 );
358   animation.Play();
359   application.SendNotification();
360   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
361
362   value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
363   value.Get(offsetValue);
364   DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
365
366   END_TEST;
367 }
368
369 int UtcDaliEffectsViewColorProperty(void)
370 {
371   ToolkitTestApplication application;
372
373   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
374   Stage::GetCurrent().Add( view );
375
376   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
377   Vector4 colorValue;
378   DALI_TEST_CHECK( value.Get(colorValue) );
379   DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
380
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 );
388
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 );
393   animation.Play();
394   application.SendNotification();
395   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
396
397   value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
398   value.Get(colorValue);
399   DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
400
401   END_TEST;
402 }
403
404 int UtcDaliEffectsViewGetSetBackgroundColor(void)
405 {
406   ToolkitTestApplication application;
407
408   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
409   view.SetBackgroundColor( Color::RED );
410   DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
411
412   view.SetBackgroundColor( Color::YELLOW );
413   DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
414
415   END_TEST;
416 }
417
418 int UtcDaliEffectsViewSetBackgroundColorN(void)
419 {
420   ToolkitTestApplication application;
421
422   EffectsView view;
423   try
424   {
425     view.SetBackgroundColor( Color::RED );
426     DALI_TEST_CHECK( false ); // Should not get here
427   }
428   catch( ... )
429   {
430     DALI_TEST_CHECK( true );
431   }
432
433   END_TEST;
434 }
435
436 int UtcDaliEffectsViewGetBackgroundColorN(void)
437 {
438   ToolkitTestApplication application;
439
440   EffectsView view;
441   try
442   {
443     Vector4 color = view.GetBackgroundColor();
444     (void)color;
445     DALI_TEST_CHECK( false ); // Should not get here
446   }
447   catch( ... )
448   {
449     DALI_TEST_CHECK( true );
450   }
451
452   END_TEST;
453 }
454
455 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
456 {
457   ToolkitTestApplication application;
458
459   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
460   view.SetSize(100.f, 100.f);
461
462   Stage stage = Stage::GetCurrent();
463   stage.Add( view );
464   application.SendNotification();
465   application.Render();
466
467   RenderTaskList renderTaskList = stage.GetRenderTaskList();
468   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
469
470   view.SetRefreshOnDemand( true );
471   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
472
473   view.SetRefreshOnDemand( false );
474   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
475
476   END_TEST;
477 }
478
479 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
480 {
481   ToolkitTestApplication application;
482
483   EffectsView view;
484   try
485   {
486     view.SetRefreshOnDemand( false );
487     DALI_TEST_CHECK( false ); // Should not get here
488   }
489   catch( ... )
490   {
491     DALI_TEST_CHECK( true );
492   }
493
494   END_TEST;
495 }
496
497 int UtcDaliEffectsViewSizeSet(void)
498 {
499   ToolkitTestApplication application;
500   Stage stage = Stage::GetCurrent();
501
502   {
503     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
504     view.SetSize( 200.0f, 200.0f, 0.0f );
505     stage.Add( view );
506     application.SendNotification();
507     application.Render();
508     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
509   }
510
511   {
512     EffectsView view = EffectsView::New(EffectsView::EMBOSS);
513     view.SetSize( 200.0f, 200.0f, 0.0f );
514     stage.Add( view );
515     application.SendNotification();
516     application.Render();
517
518     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
519   }
520
521   {
522     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
523     view.SetSize( 200.0f, 200.0f, 0.0f );
524     stage.Add( view );
525     application.SendNotification();
526     application.Render();
527
528     stage.Remove( view );
529     application.SendNotification();
530     application.Render();
531
532     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
533   }
534
535   END_TEST;
536 }
537
538 int UtcDaliEffectsViewTypeRegistry(void)
539 {
540   ToolkitTestApplication application;
541
542   TypeRegistry typeRegistry = TypeRegistry::Get();
543   DALI_TEST_CHECK( typeRegistry );
544
545   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
546   DALI_TEST_CHECK( typeInfo );
547
548   BaseHandle handle = typeInfo.CreateInstance();
549   DALI_TEST_CHECK( handle );
550
551   EffectsView view = EffectsView::DownCast( handle );
552   DALI_TEST_CHECK( view );
553
554   END_TEST;
555 }