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