2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
30 using namespace Dali::Toolkit;
32 void utc_dali_toolkit_super_blur_view_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_super_blur_view_cleanup(void)
39 test_return_value = TET_PASS;
45 const int BLUR_LEVELS = 3;
46 const int RENDER_FRAME_INTERVAL = 16;
47 const char* TEST_IMAGE_FILE_NAME("image.png");
48 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
51 gObjectCreatedCallBackCalled = true;
55 * Simulate time passed by.
57 * @note this will always process at least 1 frame (1/60 sec)
59 * @param application Test application instance
60 * @param duration Time to pass in milliseconds.
61 * @return The actual time passed in milliseconds
63 int Wait(ToolkitTestApplication& application, int duration = 0)
67 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
69 application.SendNotification();
70 application.Render(RENDER_FRAME_INTERVAL);
71 time += RENDER_FRAME_INTERVAL;
77 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
79 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
82 PixelBuffer* pixbuf = imageData.GetBuffer();
83 unsigned int size = width * height;
85 for( size_t i = 0; i < size; i++ )
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;
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();
103 void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
105 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
106 Integration::ResourcePointer resource(bitmap);
107 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
110 class SignalHandler : public Dali::ConnectionTracker
118 void Callback( SuperBlurView handle )
121 tet_infoline( "Signal called" );
124 unsigned int GetCalls() const
130 unsigned int mCalls; ///< Keeps track of how many times the signal has been called.
136 int UtcDaliSuperBlurViewNew(void)
138 ToolkitTestApplication application;
140 tet_infoline(" UtcDaliSuperBlurViewNew ");
142 // Test default constructor.
143 SuperBlurView blurView;
144 DALI_TEST_CHECK( !blurView );
146 // Test object creation
147 blurView = SuperBlurView::New( BLUR_LEVELS );
148 DALI_TEST_CHECK( blurView );
150 //Additional check to ensure object is created by checking if it's registered
151 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
152 DALI_TEST_CHECK( registry );
154 gObjectCreatedCallBackCalled = false;
155 registry.ObjectCreatedSignal().Connect( &TestCallback );
157 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
159 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
161 // Test copy constructor
162 SuperBlurView blurViewCopy2( blurView );
163 DALI_TEST_CHECK( blurViewCopy2 );
167 actorView = blurView;
168 SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
169 DALI_TEST_CHECK( downCastView );
173 int UtcDaliSuperBlurViewCreate(void)
175 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliSuperBlurViewNew ");
179 // Test default constructor.
180 SuperBlurView blurView;
181 DALI_TEST_CHECK( !blurView );
183 // Test object creation
184 TypeInfo type = TypeRegistry::Get().GetTypeInfo("SuperBlurView");
187 Dali::BaseHandle handle = type.CreateInstance();
190 blurView = Dali::Toolkit::SuperBlurView::DownCast( handle );
194 DALI_TEST_CHECK( blurView );
200 int UtcDaliSuperBlurViewSetImage(void)
202 ToolkitTestApplication application;
204 tet_infoline(" UtcDaliSuperBlurViewSetImage ");
206 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
207 blurView.SetSize( 100.f, 100.f );
209 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
210 blurView.SetImage( inputImage );
211 // start multiple guassian blur call, each guassian blur creates two render tasks
212 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
215 // create image renderers for the original image and each blurred image
216 Stage::GetCurrent().Add( blurView );
218 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
221 Stage::GetCurrent().Remove( blurView );
227 int UtcDaliSuperBlurViewSetImage2(void)
229 ToolkitTestApplication application;
230 Stage stage = Stage::GetCurrent();
232 tet_infoline(" UtcDaliSuperBlurViewSetImage2 - test setting a second image ");
234 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
235 blurView.SetSize( 100.f, 100.f );
237 tet_infoline("Call SetImage and add blurview to stage");
238 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
239 blurView.SetImage( inputImage );
241 // start multiple guassian blur call, each guassian blur creates two render tasks
242 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
244 // create image renderers for the original image and each blurred image
245 stage.Add( blurView );
247 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
249 tet_infoline("Wait for a second to allow blur to finish");
250 Wait(application, 1000);
252 tet_infoline("Remove from stage");
253 Stage::GetCurrent().Remove( blurView );
256 tet_infoline("Test that there are no render tasks remaining");
257 DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
259 tet_infoline("Call SetImage a second time and add blurview back to stage");
260 Image inputImage2 = CreateSolidColorImage( application, Color::CYAN, 50, 50 );
261 blurView.SetImage( inputImage2 );
262 // start multiple guassian blur call, each guassian blur creates two render tasks
263 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
266 // create image renderers for the original image and each blurred image
267 Stage::GetCurrent().Add( blurView );
269 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
271 tet_infoline("Wait for a second to allow blur to finish");
272 Wait(application, 1000);
274 tet_infoline("Remove from stage");
275 Stage::GetCurrent().Remove( blurView );
278 tet_infoline("Test that there are no render tasks remaining");
279 DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
285 int UtcDaliSuperBlurViewSetProperty(void)
287 ToolkitTestApplication application;
289 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
291 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
292 // create image renderers for the original image and each blurred image
293 Stage::GetCurrent().Add( blurView );
294 blurView.SetSize( 100.f, 100.f );
296 tet_infoline(" Set property map. Set height and width large enough to avoid atlassing");
299 LoadBitmapResource( application.GetPlatform(), width, height );
301 Property::Map propertyMap;
302 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
303 propertyMap["width"] = width;
304 propertyMap["height"] = height;
306 // Will create ResourceImage
307 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
310 // start multiple guassian blur call, each guassian blur creates two render tasks
311 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
319 int UtcDaliSuperBlurViewGetProperty(void)
321 ToolkitTestApplication application;
323 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
325 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
326 blurView.SetSize( 100.f, 100.f );
328 tet_infoline(" Set property map.");
330 int height(513); // Value large enough to avoid future atlassing
331 LoadBitmapResource( application.GetPlatform(), width, height );
333 Property::Map propertyMap;
334 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
335 propertyMap["width"] = width;
336 propertyMap["height"] = height;
338 // Will create ResourceImage
339 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
342 // create image renderers for the original image and each blurred image
343 Stage::GetCurrent().Add( blurView );
345 Property::Value imageProperty = blurView.GetProperty(SuperBlurView::Property::IMAGE);
346 Property::Map* map = imageProperty.GetMap();
347 DALI_TEST_CHECK( map != NULL );
350 Property::Map& mapRef = *map;
351 DALI_TEST_EQUALS( mapRef["filename"], TEST_IMAGE_FILE_NAME, TEST_LOCATION );
358 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
360 ToolkitTestApplication application;
362 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
364 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
365 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
367 blurView.SetBlurStrength( 0.65f );
369 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
373 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
375 ToolkitTestApplication application;
377 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
379 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
380 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
383 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
384 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
386 blurView.SetBlurStrength( 0.65f );
388 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
389 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
393 int UtcDaliSuperBlurViewGetBlurredImage(void)
395 ToolkitTestApplication application;
397 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
399 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
400 blurView.SetSize( 100.f,100.f );
401 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
402 blurView.SetImage( inputImage );
404 Wait(application, 200); // Make sure all the gaussian blur finished
406 Image image1 = blurView.GetBlurredImage( 1 );
407 DALI_TEST_CHECK( image1 );
409 Image image2 = blurView.GetBlurredImage( 2 );
410 DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
411 DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
413 Image image3 = blurView.GetBlurredImage( 3 );
414 DALI_TEST_CHECK( FrameBufferImage::DownCast( image3 ) );
419 int UtcDaliSuperBlurViewBlurSignal(void)
421 ToolkitTestApplication application;
423 tet_infoline(" UtcDaliSuperBlurViewSignal ");
425 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
426 blurView.SetSize( 100.f, 100.f );
428 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
429 blurView.SetImage( inputImage );
430 // start multiple guassian blur call, each guassian blur creates two render tasks
431 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
433 SignalHandler signalHandler;
434 blurView.BlurFinishedSignal().Connect(&signalHandler, &SignalHandler::Callback);
436 // create image renderers for the original image and each blurred image
437 Stage::GetCurrent().Add( blurView );
438 Wait(application, 1000);
440 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
441 //DALI_TEST_EQUALS(signalHandler.GetCalls(), 1, TEST_LOCATION);