2 * Copyright (c) 2014 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 );
226 application.SendNotification();
227 application.Render();
228 Stage::GetCurrent().Remove( blurView );
234 int UtcDaliSuperBlurViewSetProperty(void)
236 ToolkitTestApplication application;
238 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
240 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
241 // create image renderers for the original image and each blurred image
242 Stage::GetCurrent().Add( blurView );
243 blurView.SetSize( 100.f, 100.f );
245 tet_infoline(" Set property map. Set height and width large enough to avoid atlassing");
248 LoadBitmapResource( application.GetPlatform(), width, height );
250 Property::Map propertyMap;
251 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
252 propertyMap["width"] = width;
253 propertyMap["height"] = height;
255 // Will create ResourceImage
256 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
259 // start multiple guassian blur call, each guassian blur creates two render tasks
260 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
268 int UtcDaliSuperBlurViewGetProperty(void)
270 ToolkitTestApplication application;
272 tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
274 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
275 blurView.SetSize( 100.f, 100.f );
277 tet_infoline(" Set property map.");
279 int height(513); // Value large enough to avoid future atlassing
280 LoadBitmapResource( application.GetPlatform(), width, height );
282 Property::Map propertyMap;
283 propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
284 propertyMap["width"] = width;
285 propertyMap["height"] = height;
287 // Will create ResourceImage
288 blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
291 // create image renderers for the original image and each blurred image
292 Stage::GetCurrent().Add( blurView );
294 Property::Value imageProperty = blurView.GetProperty(SuperBlurView::Property::IMAGE);
295 Property::Map* map = imageProperty.GetMap();
296 DALI_TEST_CHECK( map != NULL );
299 Property::Map& mapRef = *map;
300 DALI_TEST_EQUALS( mapRef["filename"], TEST_IMAGE_FILE_NAME, TEST_LOCATION );
307 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
309 ToolkitTestApplication application;
311 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
313 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
314 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
316 blurView.SetBlurStrength( 0.65f );
318 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
322 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
324 ToolkitTestApplication application;
326 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
328 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
329 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
332 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
333 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
335 blurView.SetBlurStrength( 0.65f );
337 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
338 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
342 int UtcDaliSuperBlurViewGetBlurredImage(void)
344 ToolkitTestApplication application;
346 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
348 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
349 blurView.SetSize( 100.f,100.f );
350 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
351 blurView.SetImage( inputImage );
353 Wait(application, 200); // Make sure all the gaussian blur finished
355 Image image1 = blurView.GetBlurredImage( 1 );
356 DALI_TEST_CHECK( image1 );
358 Image image2 = blurView.GetBlurredImage( 2 );
359 DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
360 DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
362 Image image3 = blurView.GetBlurredImage( 3 );
363 DALI_TEST_CHECK( FrameBufferImage::DownCast( image3 ) );
368 int UtcDaliSuperBlurViewBlurSignal(void)
370 ToolkitTestApplication application;
372 tet_infoline(" UtcDaliSuperBlurViewSignal ");
374 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
375 blurView.SetSize( 100.f, 100.f );
377 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
378 blurView.SetImage( inputImage );
379 // start multiple guassian blur call, each guassian blur creates two render tasks
380 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
382 SignalHandler signalHandler;
383 blurView.BlurFinishedSignal().Connect(&signalHandler, &SignalHandler::Callback);
385 // create image renderers for the original image and each blurred image
386 Stage::GetCurrent().Add( blurView );
387 Wait(application, 1000);
389 DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
390 //DALI_TEST_EQUALS(signalHandler.GetCalls(), 1, TEST_LOCATION);