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::ResourceRequest* request = platform.GetRequest();
106 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
107 Integration::ResourcePointer resource(bitmap);
108 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
112 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
116 class SignalHandler : public Dali::ConnectionTracker
124 void Callback( SuperBlurView handle )
127 tet_infoline( "Signal called" );
130 unsigned int GetCalls() const
136 unsigned int mCalls; ///< Keeps track of how many times the signal has been called.
142 int UtcDaliSuperBlurViewNew(void)
144 ToolkitTestApplication application;
146 tet_infoline(" UtcDaliSuperBlurViewNew ");
148 // Test default constructor.
149 SuperBlurView blurView;
150 DALI_TEST_CHECK( !blurView );
152 // Test object creation
153 blurView = SuperBlurView::New( BLUR_LEVELS );
154 DALI_TEST_CHECK( blurView );
156 //Additional check to ensure object is created by checking if it's registered
157 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
158 DALI_TEST_CHECK( registry );
160 gObjectCreatedCallBackCalled = false;
161 registry.ObjectCreatedSignal().Connect( &TestCallback );
163 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
165 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
167 // Test copy constructor
168 SuperBlurView blurViewCopy2( blurView );
169 DALI_TEST_CHECK( blurViewCopy2 );
173 actorView = blurView;
174 SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
175 DALI_TEST_CHECK( downCastView );
179 int UtcDaliSuperBlurViewCreate(void)
181 ToolkitTestApplication application;
183 tet_infoline(" UtcDaliSuperBlurViewNew ");
185 // Test default constructor.
186 SuperBlurView blurView;
187 DALI_TEST_CHECK( !blurView );
189 // Test object creation
190 TypeInfo type = TypeRegistry::Get().GetTypeInfo("SuperBlurView");
193 Dali::BaseHandle handle = type.CreateInstance();
196 blurView = Dali::Toolkit::SuperBlurView::DownCast( handle );
200 DALI_TEST_CHECK( blurView );
206 int UtcDaliSuperBlurViewSetImage(void)
208 ToolkitTestApplication application;
210 tet_infoline(" UtcDaliSuperBlurViewSetImage ");
212 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
213 blurView.SetSize( 100.f, 100.f );
215 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
216 blurView.SetImage( inputImage );
217 // start multiple guassian blur call, each guassian blur creates two render tasks
218 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
221 // create image renderers for the original image and each blurred image
222 Stage::GetCurrent().Add( blurView );
224 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
227 Stage::GetCurrent().Remove( blurView );
233 int UtcDaliSuperBlurViewSetImage2(void)
235 ToolkitTestApplication application;
236 Stage stage = Stage::GetCurrent();
238 tet_infoline(" UtcDaliSuperBlurViewSetImage2 - test setting a second image ");
240 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
241 blurView.SetSize( 100.f, 100.f );
243 tet_infoline("Call SetImage and add blurview to stage");
244 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
245 blurView.SetImage( inputImage );
247 // start multiple guassian blur call, each guassian blur creates two render tasks
248 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
250 // create image renderers for the original image and each blurred image
251 stage.Add( blurView );
253 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
255 tet_infoline("Wait for a second to allow blur to finish");
256 Wait(application, 1000);
258 tet_infoline("Remove from stage");
259 Stage::GetCurrent().Remove( blurView );
262 tet_infoline("Test that there are no render tasks remaining");
263 DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
265 tet_infoline("Call SetImage a second time and add blurview back to stage");
266 Image inputImage2 = CreateSolidColorImage( application, Color::CYAN, 50, 50 );
267 blurView.SetImage( inputImage2 );
268 // start multiple guassian blur call, each guassian blur creates two render tasks
269 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
272 // create image renderers for the original image and each blurred image
273 Stage::GetCurrent().Add( blurView );
275 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
277 tet_infoline("Wait for a second to allow blur to finish");
278 Wait(application, 1000);
280 tet_infoline("Remove from stage");
281 Stage::GetCurrent().Remove( blurView );
284 tet_infoline("Test that there are no render tasks remaining");
285 DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
291 int UtcDaliSuperBlurViewSetProperty(void)
293 ToolkitTestApplication application;
295 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
297 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
298 // create image renderers for the original image and each blurred image
299 Stage::GetCurrent().Add( blurView );
300 blurView.SetSize( 100.f, 100.f );
302 tet_infoline(" Set property map. Set height and width large enough to avoid atlassing");
305 LoadBitmapResource( application.GetPlatform(), width, height );
307 Property::Map propertyMap;
308 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
309 propertyMap["width"] = width;
310 propertyMap["height"] = height;
312 // Will create ResourceImage
313 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
316 // start multiple guassian blur call, each guassian blur creates two render tasks
317 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
325 int UtcDaliSuperBlurViewGetProperty(void)
327 ToolkitTestApplication application;
329 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
331 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
332 blurView.SetSize( 100.f, 100.f );
334 tet_infoline(" Set property map.");
336 int height(513); // Value large enough to avoid future atlassing
337 LoadBitmapResource( application.GetPlatform(), width, height );
339 Property::Map propertyMap;
340 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
341 propertyMap["width"] = width;
342 propertyMap["height"] = height;
344 // Will create ResourceImage
345 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
348 // create image renderers for the original image and each blurred image
349 Stage::GetCurrent().Add( blurView );
351 Property::Value imageProperty = blurView.GetProperty(SuperBlurView::Property::IMAGE);
352 Property::Map* map = imageProperty.GetMap();
353 DALI_TEST_CHECK( map != NULL );
356 Property::Map& mapRef = *map;
357 DALI_TEST_EQUALS( mapRef["filename"], TEST_IMAGE_FILE_NAME, TEST_LOCATION );
364 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
366 ToolkitTestApplication application;
368 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
370 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
371 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
373 blurView.SetBlurStrength( 0.65f );
375 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
379 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
381 ToolkitTestApplication application;
383 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
385 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
386 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
389 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
390 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
392 blurView.SetBlurStrength( 0.65f );
394 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
395 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
399 int UtcDaliSuperBlurViewGetBlurredImage(void)
401 ToolkitTestApplication application;
403 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
405 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
406 blurView.SetSize( 100.f,100.f );
407 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
408 blurView.SetImage( inputImage );
410 Wait(application, 200); // Make sure all the gaussian blur finished
412 Image image1 = blurView.GetBlurredImage( 1 );
413 DALI_TEST_CHECK( image1 );
415 Image image2 = blurView.GetBlurredImage( 2 );
416 DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
417 DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
419 Image image3 = blurView.GetBlurredImage( 3 );
420 DALI_TEST_CHECK( FrameBufferImage::DownCast( image3 ) );
425 int UtcDaliSuperBlurViewBlurSignal(void)
427 ToolkitTestApplication application;
429 tet_infoline(" UtcDaliSuperBlurViewSignal ");
431 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
432 blurView.SetSize( 100.f, 100.f );
434 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
435 blurView.SetImage( inputImage );
436 // start multiple guassian blur call, each guassian blur creates two render tasks
437 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
439 SignalHandler signalHandler;
440 blurView.BlurFinishedSignal().Connect(&signalHandler, &SignalHandler::Callback);
442 // create image renderers for the original image and each blurred image
443 Stage::GetCurrent().Add( blurView );
444 Wait(application, 1000);
446 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
447 //DALI_TEST_EQUALS(signalHandler.GetCalls(), 1, TEST_LOCATION);