(AutomatedTests) Synchronise TestSingletonService with Adaptor
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-SuperBlurView.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
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void utc_dali_toolkit_super_blur_view_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_super_blur_view_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42
43 namespace
44 {
45 const int BLUR_LEVELS = 3;
46 const int RENDER_FRAME_INTERVAL = 16;
47
48 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
50 {
51   gObjectCreatedCallBackCalled = true;
52 }
53
54 /*
55  * Simulate time passed by.
56  *
57  * @note this will always process at least 1 frame (1/60 sec)
58  *
59  * @param application Test application instance
60  * @param duration Time to pass in milliseconds.
61  * @return The actual time passed in milliseconds
62  */
63 int Wait(ToolkitTestApplication& application, int duration = 0)
64 {
65   int time = 0;
66
67   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
68   {
69     application.SendNotification();
70     application.Render(RENDER_FRAME_INTERVAL);
71     time += RENDER_FRAME_INTERVAL;
72   }
73
74   return time;
75 }
76
77 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
78 {
79   BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
80
81   // Create the image
82   PixelBuffer* pixbuf = imageData.GetBuffer();
83   unsigned int size = width * height;
84
85   for( size_t i = 0; i < size; i++ )
86     {
87       pixbuf[i*4+0] = 0xFF * color.r;
88       pixbuf[i*4+1] = 0xFF * color.g;
89       pixbuf[i*4+2] = 0xFF * color.b;
90       pixbuf[i*4+3] = 0xFF * color.a;
91     }
92   imageData.Update();
93
94   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
95   application.SendNotification();
96   application.Render(RENDER_FRAME_INTERVAL);
97   application.Render(RENDER_FRAME_INTERVAL);
98   application.SendNotification();
99
100   return imageData;
101 }
102 }//namespace
103
104
105 int UtcDaliSuperBlurViewNew(void)
106 {
107   ToolkitTestApplication application;
108
109   tet_infoline(" UtcDaliSuperBlurViewNew ");
110
111   // Test default constructor.
112   SuperBlurView blurView;
113   DALI_TEST_CHECK( !blurView );
114
115   // Test object creation
116   blurView = SuperBlurView::New( BLUR_LEVELS );
117   DALI_TEST_CHECK( blurView );
118
119   //Additional check to ensure object is created by checking if it's registered
120   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
121   DALI_TEST_CHECK( registry );
122
123   gObjectCreatedCallBackCalled = false;
124   registry.ObjectCreatedSignal().Connect( &TestCallback );
125   {
126     SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
127   }
128   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129
130   // Test copy constructor
131   SuperBlurView blurViewCopy2( blurView );
132   DALI_TEST_CHECK( blurViewCopy2 );
133
134   // Test down cast
135   Actor actorView;
136   actorView = blurView;
137   SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
138   DALI_TEST_CHECK( downCastView );
139   END_TEST;
140 }
141
142 int UtcDaliSuperBlurViewSetImage(void)
143 {
144   ToolkitTestApplication application;
145
146   tet_infoline(" UtcDaliSuperBlurViewSetImage ");
147
148   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
149   // create image actors for the original image and each blurred image
150   DALI_TEST_CHECK( blurView.GetChildCount() == BLUR_LEVELS+1 );
151
152   Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
153   blurView.SetImage( inputImage );
154   // start multiple guassian blur call, each guassian blur creates two render tasks
155   DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() ==  BLUR_LEVELS*2 + 1);
156   END_TEST;
157 }
158
159 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
160 {
161   ToolkitTestApplication application;
162
163   tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
164
165   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
166   DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
167
168   blurView.SetBlurStrength( 0.65f );
169   Wait(application);
170   DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
171   END_TEST;
172 }
173
174 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
175 {
176   ToolkitTestApplication application;
177
178   tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
179
180   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
181   Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
182
183   float blurStrength;
184   (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
185   DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
186
187   blurView.SetBlurStrength( 0.65f );
188   Wait(application);
189   (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
190   DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
191   END_TEST;
192 }
193
194 int UtcDaliSuperBlurViewGetBlurredImage(void)
195 {
196   ToolkitTestApplication application;
197
198   tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
199
200   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
201   blurView.SetSize( 100.f,100.f );
202   Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
203   blurView.SetImage( inputImage );
204
205   Wait(application, 200); // Make sure all the gaussian blur finished
206
207   Image image1 = blurView.GetBlurredImage( 1 );
208   DALI_TEST_CHECK( image1 );
209
210   Image image2 = blurView.GetBlurredImage( 2 );
211   DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
212   DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
213
214   Image image3 = blurView.GetBlurredImage( 3 );
215   DALI_TEST_CHECK( FrameBufferImage::DownCast( image2 ) );
216
217   END_TEST;
218 }