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>
29 using namespace Dali::Toolkit;
31 void utc_dali_toolkit_super_blur_view_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_super_blur_view_cleanup(void)
38 test_return_value = TET_PASS;
44 const int BLUR_LEVELS = 3;
45 const int RENDER_FRAME_INTERVAL = 16;
47 static bool gObjectCreatedCallBackCalled;
48 static void TestCallback(BaseHandle handle)
50 gObjectCreatedCallBackCalled = true;
54 * Simulate time passed by.
56 * @note this will always process at least 1 frame (1/60 sec)
58 * @param application Test application instance
59 * @param duration Time to pass in milliseconds.
60 * @return The actual time passed in milliseconds
62 int Wait(ToolkitTestApplication& application, int duration = 0)
66 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
68 application.SendNotification();
69 application.Render(RENDER_FRAME_INTERVAL);
70 time += RENDER_FRAME_INTERVAL;
76 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
78 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
81 PixelBuffer* pixbuf = imageData.GetBuffer();
82 unsigned int size = width * height;
84 for( size_t i = 0; i < size; i++ )
86 pixbuf[i*4+0] = 0xFF * color.r;
87 pixbuf[i*4+1] = 0xFF * color.g;
88 pixbuf[i*4+2] = 0xFF * color.b;
89 pixbuf[i*4+3] = 0xFF * color.a;
93 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
94 application.SendNotification();
95 application.Render(RENDER_FRAME_INTERVAL);
96 application.Render(RENDER_FRAME_INTERVAL);
97 application.SendNotification();
104 int UtcDaliSuperBlurViewNew(void)
106 ToolkitTestApplication application;
108 tet_infoline(" UtcDaliSuperBlurViewNew ");
110 // Test default constructor.
111 SuperBlurView blurView;
112 DALI_TEST_CHECK( !blurView );
114 // Test object creation
115 blurView = SuperBlurView::New( BLUR_LEVELS );
116 DALI_TEST_CHECK( blurView );
118 //Additional check to ensure object is created by checking if it's registered
119 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
120 DALI_TEST_CHECK( registry );
122 gObjectCreatedCallBackCalled = false;
123 registry.ObjectCreatedSignal().Connect( &TestCallback );
125 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
127 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129 // Test copy constructor
130 SuperBlurView blurViewCopy2( blurView );
131 DALI_TEST_CHECK( blurViewCopy2 );
135 actorView = blurView;
136 SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
137 DALI_TEST_CHECK( downCastView );
141 int UtcDaliSuperBlurViewSetImage(void)
143 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliSuperBlurViewSetImage ");
147 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
148 // create image actors for the original image and each blurred image
149 DALI_TEST_CHECK( blurView.GetChildCount() == BLUR_LEVELS+1 );
151 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
152 blurView.SetImage( inputImage );
153 // start multiple guassian blur call, each guassian blur creates two render tasks
154 DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == BLUR_LEVELS*2 + 1);
158 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
160 ToolkitTestApplication application;
162 tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
164 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
165 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
167 blurView.SetBlurStrength( 0.65f );
169 DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
173 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
175 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
179 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
180 Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
183 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
184 DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
186 blurView.SetBlurStrength( 0.65f );
188 (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
189 DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
193 int UtcDaliSuperBlurViewGetBlurredImage(void)
195 ToolkitTestApplication application;
197 tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
199 SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
200 blurView.SetSize( 100.f,100.f );
201 Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
202 blurView.SetImage( inputImage );
204 Wait(application, 200); // Make sure all the gaussian blur finished
206 Image image1 = blurView.GetBlurredImage( 1 );
207 DALI_TEST_CHECK( image1 );
209 Image image2 = blurView.GetBlurredImage( 2 );
210 DALI_TEST_EQUALS( image2.GetWidth(), 25, TEST_LOCATION );
211 DALI_TEST_EQUALS( image2.GetHeight(), 25, TEST_LOCATION );
213 Image image3 = blurView.GetBlurredImage( 3 );
214 DALI_TEST_CHECK( FrameBufferImage::DownCast( image2 ) );