2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Dali::Toolkit;
30 void utc_dali_toolkit_super_blur_view_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_super_blur_view_cleanup(void)
37 test_return_value = TET_PASS;
43 const int BLUR_LEVELS = 3;
44 const int RENDER_FRAME_INTERVAL = 16;
46 static bool gObjectCreatedCallBackCalled;
47 static void TestCallback(BaseHandle handle)
49 gObjectCreatedCallBackCalled = true;
53 * Simulate time passed by.
55 * @note this will always process at least 1 frame (1/60 sec)
57 * @param application Test application instance
58 * @param duration Time to pass in milliseconds.
59 * @return The actual time passed in milliseconds
61 int Wait(ToolkitTestApplication& application, int duration = 0)
65 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
67 application.SendNotification();
68 application.Render(RENDER_FRAME_INTERVAL);
69 time += RENDER_FRAME_INTERVAL;
75 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
77 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
80 PixelBuffer* pixbuf = imageData.GetBuffer();
81 unsigned int size = width * height;
83 for( size_t i = 0; i < size; i++ )
85 pixbuf[i*4+0] = 0xFF * color.r;
86 pixbuf[i*4+1] = 0xFF * color.g;
87 pixbuf[i*4+2] = 0xFF * color.b;
88 pixbuf[i*4+3] = 0xFF * color.a;
92 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
93 application.SendNotification();
94 application.Render(RENDER_FRAME_INTERVAL);
95 application.Render(RENDER_FRAME_INTERVAL);
96 application.SendNotification();
103 int UtcDaliSuperBlurViewNew(void)
105 ToolkitTestApplication application;
107 tet_infoline(" UtcDaliSuperBlurViewNew ");
109 // Test default constructor.
110 SuperBlurView blurView;
111 DALI_TEST_CHECK( !blurView );
113 // Test object creation
114 blurView = SuperBlurView::New( BLUR_LEVELS );
115 DALI_TEST_CHECK( blurView );
117 //Additional check to ensure object is created by checking if it's registered
118 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
119 DALI_TEST_CHECK( registry );
121 gObjectCreatedCallBackCalled = false;
122 registry.ObjectCreatedSignal().Connect( &TestCallback );
124 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
126 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
128 // Test copy constructor
129 SuperBlurView blurViewCopy2( blurView );
130 DALI_TEST_CHECK( blurViewCopy2 );
134 actorView = blurView;
135 SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
136 DALI_TEST_CHECK( downCastView );
140 int UtcDaliSuperBlurViewSetImage(void)
142 ToolkitTestApplication application;
144 tet_infoline(" UtcDaliSuperBlurViewSetImage ");
146 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
147 // create image actors for the original image and each blurred image
148 DALI_TEST_CHECK( blurView.GetChildCount() == BLUR_LEVELS+1 );
150 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
151 blurView.SetImage( inputImage );
152 // start multiple guassian blur call, each guassian blur creates two render tasks
153 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == BLUR_LEVELS*2 + 1);
157 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
159 ToolkitTestApplication application;
161 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
163 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
164 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
166 blurView.SetBlurStrength( 0.65f );
168 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
172 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
174 ToolkitTestApplication application;
176 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
178 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
179 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
182 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
183 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
185 blurView.SetBlurStrength( 0.65f );
187 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
188 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
192 int UtcDaliSuperBlurViewGetBlurredImage(void)
194 ToolkitTestApplication application;
196 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
198 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
199 blurView.SetSize( 100.f,100.f );
200 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
201 blurView.SetImage( inputImage );
203 Wait(application, 200); // Make sure all the gaussian blur finished
205 Image image1 = blurView.GetBlurredImage( 1 );
206 DALI_TEST_CHECK( image1 );
208 Image image2 = blurView.GetBlurredImage( 2 );
209 DALI_TEST_CHECK( image2.GetWidth() == 25 );
210 DALI_TEST_CHECK( image2.GetHeight() == 25 );
212 Image image3 = blurView.GetBlurredImage( 3 );
213 DALI_TEST_CHECK( FrameBufferImage::DownCast( image2 ) );