NativeImageSource with tbm_surface for tizen 3.0 wayland
[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();
46   DALI_TEST_CHECK( view );
47
48   Stage::GetCurrent().Add( view );
49
50   application.SendNotification();
51   application.Render();
52
53   END_TEST;
54 }
55
56 int UtcDaliEffectsViewCopyAndAssignment(void)
57 {
58   ToolkitTestApplication application;
59
60   EffectsView view = EffectsView::New();
61   DALI_TEST_CHECK( view );
62
63   EffectsView copy( view );
64   DALI_TEST_CHECK( copy == view );
65
66   EffectsView assign;
67   DALI_TEST_CHECK( !assign );
68   assign = view;
69   DALI_TEST_CHECK( assign == view );
70
71   // Self assignment
72   assign = assign;
73   DALI_TEST_CHECK( assign );
74   DALI_TEST_CHECK( assign == view );
75
76   END_TEST;
77 }
78
79 int UtcDaliEffectsViewDownCast(void)
80 {
81   ToolkitTestApplication application;
82
83   BaseHandle view = EffectsView::New();
84   DALI_TEST_CHECK( EffectsView::DownCast( view ) );
85
86   BaseHandle empty;
87   DALI_TEST_CHECK( ! EffectsView::DownCast( empty ) );
88
89   BaseHandle another = Actor::New();
90   DALI_TEST_CHECK( ! EffectsView::DownCast( another ) );
91
92   END_TEST;
93 }
94
95 int UtcDaliEffectsViewSetGetTypeP(void)
96 {
97   ToolkitTestApplication application;
98
99   EffectsView view = EffectsView::New();
100   DALI_TEST_CHECK( view.GetType() == EffectsView::INVALID_TYPE );
101
102   view.SetType( EffectsView::DROP_SHADOW );
103   DALI_TEST_CHECK( view.GetType() == EffectsView::DROP_SHADOW );
104
105   view.SetType( EffectsView::EMBOSS );
106   DALI_TEST_CHECK( view.GetType() == EffectsView::EMBOSS );
107
108   END_TEST;
109 }
110
111 int UtcDaliEffectsViewSetTypeN(void)
112 {
113   ToolkitTestApplication application;
114
115   EffectsView view;
116   try
117   {
118     view.SetType( EffectsView::DROP_SHADOW );
119     DALI_TEST_CHECK( false ); // Should not get here
120   }
121   catch( ... )
122   {
123     DALI_TEST_CHECK( true );
124   }
125
126   END_TEST;
127 }
128
129 int UtcDaliEffectsViewGetTypeN(void)
130 {
131   ToolkitTestApplication application;
132
133   EffectsView view;
134   try
135   {
136     EffectsView::EffectType type = view.GetType();
137     (void) type;
138     DALI_TEST_CHECK( false ); // Should not get here
139   }
140   catch( ... )
141   {
142     DALI_TEST_CHECK( true );
143   }
144
145   END_TEST;
146 }
147
148 int UtcDaliEffectsViewEnableP(void)
149 {
150   ToolkitTestApplication application;
151
152   EffectsView view = EffectsView::New();
153   Stage stage = Stage::GetCurrent();
154   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
155
156   view.Enable();
157   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
158
159   END_TEST;
160 }
161
162 int UtcDaliEffectsViewEnableN(void)
163 {
164   ToolkitTestApplication application;
165
166   EffectsView view;
167   try
168   {
169     view.Enable();
170     DALI_TEST_CHECK( false ); // Should not get here
171   }
172   catch( ... )
173   {
174     DALI_TEST_CHECK( true );
175   }
176
177   END_TEST;
178 }
179
180 int UtcDaliEffectsViewDisableP(void)
181 {
182   ToolkitTestApplication application;
183
184   EffectsView view = EffectsView::New();
185   Stage stage = Stage::GetCurrent();
186   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
187
188   view.Enable();
189   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() > 1 );
190
191   view.Disable();
192   DALI_TEST_CHECK( stage.GetRenderTaskList().GetTaskCount() == 1 );
193
194   END_TEST;
195 }
196
197 int UtcDaliEffectsViewDisableN(void)
198 {
199   ToolkitTestApplication application;
200
201   EffectsView view;
202   try
203   {
204     view.Disable();
205     DALI_TEST_CHECK( false ); // Should not get here
206   }
207   catch( ... )
208   {
209     DALI_TEST_CHECK( true );
210   }
211
212   END_TEST;
213 }
214
215 int UtcDaliEffectsViewRefreshP(void)
216 {
217   ToolkitTestApplication application;
218
219   EffectsView view = EffectsView::New();
220   try
221   {
222     view.Refresh();
223     DALI_TEST_CHECK( true );
224   }
225   catch( ... )
226   {
227     DALI_TEST_CHECK( false ); // Should not get here!
228   }
229
230   END_TEST;
231 }
232
233 int UtcDaliEffectsViewRefreshN(void)
234 {
235   ToolkitTestApplication application;
236
237   EffectsView view;
238   try
239   {
240     view.Refresh();
241     DALI_TEST_CHECK( false ); // Should not get here
242   }
243   catch( ... )
244   {
245     DALI_TEST_CHECK( true );
246   }
247
248   END_TEST;
249 }
250
251 int UtcDaliEffectsViewSetPixelFormatP(void)
252 {
253   ToolkitTestApplication application;
254
255   EffectsView view = EffectsView::New();
256   try
257   {
258     view.SetPixelFormat( Pixel::RGBA8888 );
259     DALI_TEST_CHECK( true );
260   }
261   catch( ... )
262   {
263     DALI_TEST_CHECK( false ); // Should not get here!
264   }
265
266   END_TEST;
267 }
268
269 int UtcDaliEffectsViewSetPixelFormatN(void)
270 {
271   ToolkitTestApplication application;
272
273   EffectsView view;
274   try
275   {
276     view.SetPixelFormat( Pixel::RGBA8888 );
277     DALI_TEST_CHECK( false ); // Should not get here
278   }
279   catch( ... )
280   {
281     DALI_TEST_CHECK( true );
282   }
283
284   END_TEST;
285 }
286
287 int UtcDaliEffectsViewSetGetOutputImage(void)
288 {
289   ToolkitTestApplication application;
290
291   EffectsView view = EffectsView::New();
292   FrameBufferImage image = FrameBufferImage::New();
293   DALI_TEST_CHECK( image );
294
295   view.SetOutputImage( image );
296   DALI_TEST_CHECK( view.GetOutputImage() == image );
297
298   // Replace with another image
299   FrameBufferImage image2 = FrameBufferImage::New();
300   DALI_TEST_CHECK( image2 );
301   view.SetOutputImage( image2 );
302   DALI_TEST_CHECK( view.GetOutputImage() == image2 );
303
304   // Remove output image
305   view.SetOutputImage( FrameBufferImage() );
306   DALI_TEST_CHECK( ! view.GetOutputImage() );
307
308   END_TEST;
309 }
310
311 int UtcDaliEffectsViewSetOutputImageN(void)
312 {
313   ToolkitTestApplication application;
314
315   EffectsView view;
316   try
317   {
318     view.SetOutputImage( FrameBufferImage::New() );
319     DALI_TEST_CHECK( false ); // Should not get here
320   }
321   catch( ... )
322   {
323     DALI_TEST_CHECK( true );
324   }
325
326   END_TEST;
327 }
328
329 int UtcDaliEffectsViewGetOutputImageN(void)
330 {
331   ToolkitTestApplication application;
332
333   EffectsView view;
334   try
335   {
336     FrameBufferImage image = view.GetOutputImage();
337     (void)image;
338     DALI_TEST_CHECK( false ); // Should not get here
339   }
340   catch( ... )
341   {
342     DALI_TEST_CHECK( true );
343   }
344
345   END_TEST;
346 }
347
348 int UtcDaliEffectsViewGetEffectSizePropertyIndexP(void)
349 {
350   ToolkitTestApplication application;
351
352   EffectsView view = EffectsView::New();
353   DALI_TEST_CHECK( Property::INVALID_INDEX != view.GetEffectSizePropertyIndex() );
354
355   END_TEST;
356 }
357
358 int UtcDaliEffectsViewGetEffectSizePropertyIndexN(void)
359 {
360   ToolkitTestApplication application;
361
362   EffectsView view;
363   try
364   {
365     Property::Index index = view.GetEffectSizePropertyIndex();
366     (void)index;
367     DALI_TEST_CHECK( false ); // Should not get here
368   }
369   catch( ... )
370   {
371     DALI_TEST_CHECK( true );
372   }
373
374   END_TEST;
375 }
376
377 int UtcDaliEffectsViewGetEffectStrengthPropertyIndexP(void)
378 {
379   ToolkitTestApplication application;
380
381   EffectsView view = EffectsView::New();
382   DALI_TEST_CHECK( Property::INVALID_INDEX != view.GetEffectStrengthPropertyIndex() );
383
384   END_TEST;
385 }
386
387 int UtcDaliEffectsViewGetEffectStrengthPropertyIndexN(void)
388 {
389   ToolkitTestApplication application;
390
391   EffectsView view;
392   try
393   {
394     Property::Index index = view.GetEffectStrengthPropertyIndex();
395     (void)index;
396     DALI_TEST_CHECK( false ); // Should not get here
397   }
398   catch( ... )
399   {
400     DALI_TEST_CHECK( true );
401   }
402
403   END_TEST;
404 }
405
406 int UtcDaliEffectsViewGetEffectOffsetPropertyIndexP(void)
407 {
408   ToolkitTestApplication application;
409
410   EffectsView view = EffectsView::New();
411   DALI_TEST_CHECK( Property::INVALID_INDEX != view.GetEffectOffsetPropertyIndex() );
412
413   END_TEST;
414 }
415
416 int UtcDaliEffectsViewGetEffectOffsetPropertyIndexN(void)
417 {
418   ToolkitTestApplication application;
419
420   EffectsView view;
421   try
422   {
423     Property::Index index = view.GetEffectOffsetPropertyIndex();
424     (void)index;
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 UtcDaliEffectsViewGetEffectColorPropertyIndexP(void)
436 {
437   ToolkitTestApplication application;
438
439   EffectsView view = EffectsView::New();
440   DALI_TEST_CHECK( Property::INVALID_INDEX != view.GetEffectColorPropertyIndex() );
441
442   END_TEST;
443 }
444
445 int UtcDaliEffectsViewGetEffectColorPropertyIndexN(void)
446 {
447   ToolkitTestApplication application;
448
449   EffectsView view;
450   try
451   {
452     Property::Index index = view.GetEffectColorPropertyIndex();
453     (void)index;
454     DALI_TEST_CHECK( false ); // Should not get here
455   }
456   catch( ... )
457   {
458     DALI_TEST_CHECK( true );
459   }
460
461   END_TEST;
462 }
463
464 int UtcDaliEffectsViewGetSetBackgroundColor(void)
465 {
466   ToolkitTestApplication application;
467
468   EffectsView view = EffectsView::New();
469   view.SetBackgroundColor( Color::RED );
470   DALI_TEST_CHECK( Color::RED == view.GetBackgroundColor() );
471
472   view.SetBackgroundColor( Color::YELLOW );
473   DALI_TEST_CHECK( Color::YELLOW == view.GetBackgroundColor() );
474
475   END_TEST;
476 }
477
478 int UtcDaliEffectsViewSetBackgroundColorN(void)
479 {
480   ToolkitTestApplication application;
481
482   EffectsView view;
483   try
484   {
485     view.SetBackgroundColor( Color::RED );
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 UtcDaliEffectsViewGetBackgroundColorN(void)
497 {
498   ToolkitTestApplication application;
499
500   EffectsView view;
501   try
502   {
503     Vector4 color = view.GetBackgroundColor();
504     (void)color;
505     DALI_TEST_CHECK( false ); // Should not get here
506   }
507   catch( ... )
508   {
509     DALI_TEST_CHECK( true );
510   }
511
512   END_TEST;
513 }
514
515 int UtcDaliEffectsViewSetRefreshOnDemandP(void)
516 {
517   ToolkitTestApplication application;
518
519   EffectsView view = EffectsView::New();
520   FrameBufferImage image = FrameBufferImage::New();
521   view.SetOutputImage( image );
522   view.Enable();
523
524   Stage stage = Stage::GetCurrent();
525   stage.Add( view );
526
527   RenderTaskList renderTaskList = stage.GetRenderTaskList();
528   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
529   DALI_TEST_CHECK( renderTaskList.GetTask( 2 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
530
531   view.SetRefreshOnDemand( true );
532   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
533   DALI_TEST_CHECK( renderTaskList.GetTask( 2 ).GetRefreshRate() == RenderTask::REFRESH_ONCE );
534
535   view.SetRefreshOnDemand( false );
536   DALI_TEST_CHECK( renderTaskList.GetTask( 1 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
537   DALI_TEST_CHECK( renderTaskList.GetTask( 2 ).GetRefreshRate() == RenderTask::REFRESH_ALWAYS );
538
539   END_TEST;
540 }
541
542 int UtcDaliEffectsViewSetRefreshOnDemandN(void)
543 {
544   ToolkitTestApplication application;
545
546   EffectsView view;
547   try
548   {
549     view.SetRefreshOnDemand( false );
550     DALI_TEST_CHECK( false ); // Should not get here
551   }
552   catch( ... )
553   {
554     DALI_TEST_CHECK( true );
555   }
556
557   END_TEST;
558 }
559
560 int UtcDaliEffectsViewSizeSet(void)
561 {
562   ToolkitTestApplication application;
563   Stage stage = Stage::GetCurrent();
564
565   {
566     EffectsView view = EffectsView::New();
567     view.SetSize( 200.0f, 200.0f, 0.0f );
568     stage.Add( view );
569     view.Enable();
570     application.SendNotification();
571     application.Render();
572     view.Disable();
573     application.SendNotification();
574     application.Render();
575
576     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
577   }
578
579   {
580     EffectsView view = EffectsView::New();
581     view.SetOutputImage( FrameBufferImage::New( 200, 200 ) );
582     view.SetType( EffectsView::EMBOSS );
583     view.SetSize( 200.0f, 200.0f, 0.0f );
584     stage.Add( view );
585     application.SendNotification();
586     application.Render();
587
588     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
589   }
590
591   {
592     EffectsView view = EffectsView::New();
593     view.SetType( EffectsView::DROP_SHADOW );
594     view.SetSize( 200.0f, 200.0f, 0.0f );
595     stage.Add( view );
596     application.SendNotification();
597     application.Render();
598
599     stage.Remove( view );
600     application.SendNotification();
601     application.Render();
602
603     DALI_TEST_EQUALS( view.GetCurrentSize(), Vector3( 200.0f, 200.0f, 0.0f ), TEST_LOCATION );
604   }
605
606   END_TEST;
607 }
608
609 int UtcDaliEffectsViewTypeRegistry(void)
610 {
611   ToolkitTestApplication application;
612
613   TypeRegistry typeRegistry = TypeRegistry::Get();
614   DALI_TEST_CHECK( typeRegistry );
615
616   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "EffectsView" );
617   DALI_TEST_CHECK( typeInfo );
618
619   BaseHandle handle = typeInfo.CreateInstance();
620   DALI_TEST_CHECK( handle );
621
622   EffectsView view = EffectsView::DownCast( handle );
623   DALI_TEST_CHECK( view );
624
625   END_TEST;
626 }