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