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;
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();
105 int UtcDaliSuperBlurViewNew(void)
107 ToolkitTestApplication application;
109 tet_infoline(" UtcDaliSuperBlurViewNew ");
111 // Test default constructor.
112 SuperBlurView blurView;
113 DALI_TEST_CHECK( !blurView );
115 // Test object creation
116 blurView = SuperBlurView::New( BLUR_LEVELS );
117 DALI_TEST_CHECK( blurView );
119 //Additional check to ensure object is created by checking if it's registered
120 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
121 DALI_TEST_CHECK( registry );
123 gObjectCreatedCallBackCalled = false;
124 registry.ObjectCreatedSignal().Connect( &TestCallback );
126 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
128 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
130 // Test copy constructor
131 SuperBlurView blurViewCopy2( blurView );
132 DALI_TEST_CHECK( blurViewCopy2 );
136 actorView = blurView;
137 SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
138 DALI_TEST_CHECK( downCastView );
142 int UtcDaliSuperBlurViewSetImage(void)
144 ToolkitTestApplication application;
146 tet_infoline(" UtcDaliSuperBlurViewSetImage ");
148 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
149 // create image actors for the original image and each blurred image
150 DALI_TEST_CHECK( blurView.GetChildCount() == BLUR_LEVELS+1 );
152 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
153 blurView.SetImage( inputImage );
154 // start multiple guassian blur call, each guassian blur creates two render tasks
155 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == BLUR_LEVELS*2 + 1);
159 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
161 ToolkitTestApplication application;
163 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
165 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
166 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
168 blurView.SetBlurStrength( 0.65f );
170 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
174 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
176 ToolkitTestApplication application;
178 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
180 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
181 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
184 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
185 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
187 blurView.SetBlurStrength( 0.65f );
189 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
190 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
194 int UtcDaliSuperBlurViewGetBlurredImage(void)
196 ToolkitTestApplication application;
198 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
200 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
201 blurView.SetSize( 100.f,100.f );
202 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
203 blurView.SetImage( inputImage );
205 Wait(application, 200); // Make sure all the gaussian blur finished
207 Image image1 = blurView.GetBlurredImage( 1 );
208 DALI_TEST_CHECK( image1 );
210 Image image2 = blurView.GetBlurredImage( 2 );
211 DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
212 DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
214 Image image3 = blurView.GetBlurredImage( 3 );
215 DALI_TEST_CHECK( FrameBufferImage::DownCast( image2 ) );