Removed ImageActor usage from automated-tests
[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 int UtcDaliEffectsViewGetTypeP(void)
128 {
129   ToolkitTestApplication application;
130
131   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
132   DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
133
134   view.Reset();
135   view = EffectsView::New( EffectsView::EMBOSS );
136   DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
137
138   END_TEST;
139 }
140
141 int UtcDaliEffectsViewOnStage(void)
142 {
143   ToolkitTestApplication application;
144
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 );
149
150   stage.Add( view );
151   application.SendNotification();
152   application.Render();
153   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
154
155   END_TEST;
156 }
157
158 int UtcDaliEffectsViewOffStage(void)
159 {
160   ToolkitTestApplication application;
161
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 );
166
167   stage.Add( view );
168   application.SendNotification();
169   application.Render();
170   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
171
172   stage.Remove( view );
173   application.SendNotification();
174   application.Render();
175   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
176
177   END_TEST;
178 }
179
180 int UtcDaliEffectsViewRefreshP(void)
181 {
182   ToolkitTestApplication application;
183
184   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
185   try
186   {
187     view.Refresh();
188     DALI_TEST_CHECK( true );
189   }
190   catch( ... )
191   {
192     DALI_TEST_CHECK( false ); // Should not get here!
193   }
194
195   END_TEST;
196 }
197
198 int UtcDaliEffectsViewRefreshN(void)
199 {
200   ToolkitTestApplication application;
201
202   EffectsView view;
203   try
204   {
205     view.Refresh();
206     DALI_TEST_CHECK( false ); // Should not get here
207   }
208   catch( ... )
209   {
210     DALI_TEST_CHECK( true );
211   }
212
213   END_TEST;
214 }
215
216 int UtcDaliEffectsViewSetPixelFormatP(void)
217 {
218   ToolkitTestApplication application;
219
220   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
221   try
222   {
223     view.SetPixelFormat( Pixel::RGBA8888 );
224     DALI_TEST_CHECK( true );
225   }
226   catch( ... )
227   {
228     DALI_TEST_CHECK( false ); // Should not get here!
229   }
230
231   END_TEST;
232 }
233
234 int UtcDaliEffectsViewSetPixelFormatN(void)
235 {
236   ToolkitTestApplication application;
237
238   EffectsView view;
239   try
240   {
241     view.SetPixelFormat( Pixel::RGBA8888 );
242     DALI_TEST_CHECK( false ); // Should not get here
243   }
244   catch( ... )
245   {
246     DALI_TEST_CHECK( true );
247   }
248
249   END_TEST;
250 }
251
252 int UtcDaliEffectsViewSizeProperty(void)
253 {
254   ToolkitTestApplication application;
255
256   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
257
258   Property::Index idx = view.GetPropertyIndex( "effectSize" );
259   DALI_TEST_EQUALS( idx, (Property::Index)EffectsView::Property::EFFECT_SIZE, TEST_LOCATION );
260
261   view.SetProperty( idx, 5 );
262   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_SIZE );
263   int size;
264   DALI_TEST_CHECK( value.Get(size) );
265   DALI_TEST_CHECK( size == 5 );
266
267   END_TEST;
268 }
269
270 int UtcDaliEffectsViewOffsetProperty(void)
271 {
272   ToolkitTestApplication application;
273
274   EffectsView view = EffectsView::New( EffectsView::EMBOSS );
275   Stage::GetCurrent().Add( view );
276
277   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
278   Vector3 offsetValue;
279   DALI_TEST_CHECK( value.Get(offsetValue) );
280   DALI_TEST_EQUALS( offsetValue, Vector3::ZERO, TEST_LOCATION );
281
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 );
289
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 );
294   animation.Play();
295   application.SendNotification();
296   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
297
298   value = view.GetProperty( EffectsView::Property::EFFECT_OFFSET );
299   value.Get(offsetValue);
300   DALI_TEST_EQUALS( offsetValue, offsetAnimate, TEST_LOCATION );
301
302   END_TEST;
303 }
304
305 int UtcDaliEffectsViewColorProperty(void)
306 {
307   ToolkitTestApplication application;
308
309   EffectsView view = EffectsView::New( EffectsView::DROP_SHADOW );
310   Stage::GetCurrent().Add( view );
311
312   Property::Value value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
313   Vector4 colorValue;
314   DALI_TEST_CHECK( value.Get(colorValue) );
315   DALI_TEST_EQUALS( colorValue, Color::WHITE, TEST_LOCATION );
316
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 );
324
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 );
329   animation.Play();
330   application.SendNotification();
331   application.Render(static_cast<unsigned int>(durationSeconds*1000.0f) + 1u/*just beyond the animation duration*/);
332
333   value = view.GetProperty( EffectsView::Property::EFFECT_COLOR );
334   value.Get(colorValue);
335   DALI_TEST_EQUALS( colorValue, colorAnimate, TEST_LOCATION );
336
337   END_TEST;
338 }
339
340 int UtcDaliEffectsViewGetSetBackgroundColor(void)
341 {
342   ToolkitTestApplication application;
343
344   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
345   view.SetBackgroundColor( Color::RED );
346   DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
347
348   view.SetBackgroundColor( Color::YELLOW );
349   DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
350
351   END_TEST;
352 }
353
354 int UtcDaliEffectsViewSetBackgroundColorN(void)
355 {
356   ToolkitTestApplication application;
357
358   EffectsView view;
359   try
360   {
361     view.SetBackgroundColor( Color::RED );
362     DALI_TEST_CHECK( false ); // Should not get here
363   }
364   catch( ... )
365   {
366     DALI_TEST_CHECK( true );
367   }
368
369   END_TEST;
370 }
371
372 int UtcDaliEffectsViewGetBackgroundColorN(void)
373 {
374   ToolkitTestApplication application;
375
376   EffectsView view;
377   try
378   {
379     Vector4 color = view.GetBackgroundColor();
380     (void)color;
381     DALI_TEST_CHECK( false ); // Should not get here
382   }
383   catch( ... )
384   {
385     DALI_TEST_CHECK( true );
386   }
387
388   END_TEST;
389 }
390
391 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
392 {
393   ToolkitTestApplication application;
394
395   EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
396   view.SetSize(100.f, 100.f);
397
398   Stage stage = Stage::GetCurrent();
399   stage.Add( view );
400   application.SendNotification();
401   application.Render();
402
403   RenderTaskList renderTaskList = stage.GetRenderTaskList();
404   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
405
406   view.SetRefreshOnDemand( true );
407   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
408
409   view.SetRefreshOnDemand( false );
410   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
411
412   END_TEST;
413 }
414
415 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
416 {
417   ToolkitTestApplication application;
418
419   EffectsView view;
420   try
421   {
422     view.SetRefreshOnDemand( false );
423     DALI_TEST_CHECK( false ); // Should not get here
424   }
425   catch( ... )
426   {
427     DALI_TEST_CHECK( true );
428   }
429
430   END_TEST;
431 }
432
433 int UtcDaliEffectsViewSizeSet(void)
434 {
435   ToolkitTestApplication application;
436   Stage stage = Stage::GetCurrent();
437
438   {
439     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
440     view.SetSize( 200.0f, 200.0f, 0.0f );
441     stage.Add( view );
442     application.SendNotification();
443     application.Render();
444     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
445   }
446
447   {
448     EffectsView view = EffectsView::New(EffectsView::EMBOSS);
449     view.SetSize( 200.0f, 200.0f, 0.0f );
450     stage.Add( view );
451     application.SendNotification();
452     application.Render();
453
454     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
455   }
456
457   {
458     EffectsView view = EffectsView::New(EffectsView::DROP_SHADOW);
459     view.SetSize( 200.0f, 200.0f, 0.0f );
460     stage.Add( view );
461     application.SendNotification();
462     application.Render();
463
464     stage.Remove( view );
465     application.SendNotification();
466     application.Render();
467
468     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
469   }
470
471   END_TEST;
472 }
473
474 int UtcDaliEffectsViewTypeRegistry(void)
475 {
476   ToolkitTestApplication application;
477
478   TypeRegistry typeRegistry = TypeRegistry::Get();
479   DALI_TEST_CHECK( typeRegistry );
480
481   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
482   DALI_TEST_CHECK( typeInfo );
483
484   BaseHandle handle = typeInfo.CreateInstance();
485   DALI_TEST_CHECK( handle );
486
487   EffectsView view = EffectsView::DownCast( handle );
488   DALI_TEST_CHECK( view );
489
490   END_TEST;
491 }