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/bubble-effect/bubble-emitter.h>
30 using namespace Dali::Toolkit;
32 void utc_dali_toolkit_bubble_emitter_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_bubble_emitter_cleanup(void)
39 test_return_value = TET_PASS;
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 static 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 static 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 UtcDaliBubbleEmitterNew(void)
107 ToolkitTestApplication application;
109 tet_infoline(" UtcDaliBubbleEmitterNew ");
111 // Test default constructor
112 BubbleEmitter emitter;
113 DALI_TEST_CHECK( !emitter );
115 // Test object creation
116 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
117 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
118 DALI_TEST_CHECK( emitter );
120 // Additional check to ensure object is created by checking if it's registered
121 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
122 DALI_TEST_CHECK( registry );
123 gObjectCreatedCallBackCalled = false;
124 registry.ObjectCreatedSignal().Connect( &TestCallback );
126 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
128 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
130 // Test copy constructor
131 BubbleEmitter emitterCopy( emitter );
132 DALI_TEST_CHECK( emitterCopy );
135 Handle handleEmitter;
136 handleEmitter = emitter;
137 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
138 DALI_TEST_CHECK( downCastEmitter );
142 int UtcDaliBubbleEmitterDownCast01(void)
144 ToolkitTestApplication application;
146 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
148 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
149 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
151 BaseHandle handle(emitter);
152 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
153 DALI_TEST_EQUALS( (bool)emitter2, true, TEST_LOCATION );
157 int UtcDaliBubbleEmitterDownCast02(void)
159 ToolkitTestApplication application;
161 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
163 Handle handle = Handle::New(); // Create a custom object
164 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
165 DALI_TEST_EQUALS( (bool)emitter, false, TEST_LOCATION );
169 int UtcDaliBubbleEmitterGetRootActor(void)
171 ToolkitTestApplication application;
172 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
174 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
175 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 270, Vector2( 5.f, 10.f ));
177 Actor root = emitter.GetRootActor();
178 DALI_TEST_CHECK( root );
179 DALI_TEST_CHECK( root.GetChildCount() == 3 );
183 int UtcDaliBubbleEmitterSetBackground(void)
185 ToolkitTestApplication application;
186 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
188 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
189 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
191 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
192 unsigned int taskCount = taskList.GetTaskCount();
194 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
195 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
197 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
199 Wait(application, 500);
200 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
204 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
205 // To test that the bubble-shape image is successfully switched in the sampler
206 /*int UtcDaliBubbleEmitterSetShapeImage(void)
210 int UtcDaliBubbleEmitterSetBubbleScale(void)
212 ToolkitTestApplication application;
213 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
215 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
216 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
217 Actor root = emitter.GetRootActor();
218 Stage::GetCurrent().Add( root );
220 TestGlAbstraction& gl = application.GetGlAbstraction();
225 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
226 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
228 emitter.SetBubbleScale( 2.f );
230 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
231 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
233 emitter.SetBubbleScale( 0.5f );
235 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
236 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
240 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
242 ToolkitTestApplication application;
243 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
245 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
246 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
250 emitter.SetBubbleDensity( 3.f );
251 DALI_TEST_CHECK(true);
253 catch(Dali::DaliException& e)
255 DALI_TEST_PRINT_ASSERT( e );
256 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
261 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
263 ToolkitTestApplication application;
264 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
266 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
267 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
271 emitter.SetBubbleDensity( 10.f );
273 catch(Dali::DaliException& e)
275 DALI_TEST_PRINT_ASSERT( e );
276 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
281 int UtcDaliBubbleEmitterSetBlendMode(void)
283 ToolkitTestApplication application;
284 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
286 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
287 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
288 Actor root = emitter.GetRootActor();
289 Stage::GetCurrent().Add( root );
291 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
293 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
294 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
295 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
296 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
298 emitter.SetBlendMode( true );
300 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
301 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
302 DALI_TEST_EQUALS( (GLenum)GL_ZERO, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
303 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
305 emitter.SetBlendMode( false );
307 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
308 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
309 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
310 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
315 int UtcDaliBubbleEmitterEmitBubble(void)
317 ToolkitTestApplication application;
318 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
320 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
321 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
323 Actor root = emitter.GetRootActor();
324 Actor bubbleMesh = root.GetChildAt( 0 );
325 Stage::GetCurrent().Add( root );
326 DALI_TEST_CHECK( bubbleMesh );
328 Property::Index propertyIndex0 = bubbleMesh.GetPropertyIndex( "percentage-0" );
329 Property::Index propertyIndex1 = bubbleMesh.GetPropertyIndex( "percentage-1" );
330 float value0, value1;
332 Animation animation = Animation::New( 0.5f );
333 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
334 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
335 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
336 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
337 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
338 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
342 Wait(application, 300);
343 propertyIndex0 = bubbleMesh.GetPropertyIndex( "percentage-0" );
344 propertyIndex1 = bubbleMesh.GetPropertyIndex( "percentage-1" );
345 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
346 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
347 DALI_TEST_CHECK( value0 >= 0.6f );
348 DALI_TEST_CHECK( value1 >= 0.6f );
350 Wait(application,500);
351 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
352 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
353 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
354 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
358 int UtcDaliBubbleEmitterRestore(void)
360 ToolkitTestApplication application;
361 tet_infoline( " UtcDaliBubbleEmitterRestore " );
363 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
364 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 90, Vector2( 5.f, 10.f ));
365 Actor root = emitter.GetRootActor();
366 Stage::GetCurrent().Add( root );
368 Actor bubbleMesh = root.GetChildAt( 0 );
369 Renderer renderer = bubbleMesh.GetRendererAt( 0 );
370 DALI_TEST_CHECK( renderer );
372 TestGlAbstraction& gl = application.GetGlAbstraction();
374 float percentageValue;
375 Vector4 startEndPosValue;
377 Animation animation = Animation::New( 0.5f );
378 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
382 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
383 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
385 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
386 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
387 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
390 Wait(application, 200);
393 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
394 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
396 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
397 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
398 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
401 application.SendNotification();
402 application.Render();
404 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
405 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
407 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
408 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );