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_bubble_emitter_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_bubble_emitter_cleanup(void)
38 test_return_value = TET_PASS;
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 static 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 static 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 UtcDaliBubbleEmitterNew(void)
106 ToolkitTestApplication application;
108 tet_infoline(" UtcDaliBubbleEmitterNew ");
110 // Test default constructor
111 BubbleEmitter emitter;
112 DALI_TEST_CHECK( !emitter );
114 // Test object creation
115 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
116 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
117 DALI_TEST_CHECK( emitter );
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 );
122 gObjectCreatedCallBackCalled = false;
123 registry.ObjectCreatedSignal().Connect( &TestCallback );
125 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
127 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129 // Test copy constructor
130 BubbleEmitter emitterCopy( emitter );
131 DALI_TEST_CHECK( emitterCopy );
134 Handle handleEmitter;
135 handleEmitter = emitter;
136 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
137 DALI_TEST_CHECK( downCastEmitter );
141 int UtcDaliBubbleEmitterDownCast01(void)
143 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
147 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
148 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
150 BaseHandle handle(emitter);
151 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
152 DALI_TEST_EQUALS( (bool)emitter2, true, TEST_LOCATION );
156 int UtcDaliBubbleEmitterDownCast02(void)
158 ToolkitTestApplication application;
160 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
162 Handle handle = Handle::New(); // Create a custom object
163 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
164 DALI_TEST_EQUALS( (bool)emitter, false, TEST_LOCATION );
168 int UtcDaliBubbleEmitterGetRootActor(void)
170 ToolkitTestApplication application;
171 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
173 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
174 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 270, Vector2( 5.f, 10.f ));
176 Actor root = emitter.GetRootActor();
177 DALI_TEST_CHECK( root );
178 DALI_TEST_CHECK( root.GetChildCount() == 3 );
182 int UtcDaliBubbleEmitterSetBackground(void)
184 ToolkitTestApplication application;
185 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
187 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
188 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
190 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
191 unsigned int taskCount = taskList.GetTaskCount();
193 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
194 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
196 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
198 Wait(application, 500);
199 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
203 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
204 // To test that the bubble-shape image is successfully switched in the sampler
205 /*int UtcDaliBubbleEmitterSetShapeImage(void)
209 int UtcDaliBubbleEmitterSetBubbleScale(void)
211 ToolkitTestApplication application;
212 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
214 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
215 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
216 Actor root = emitter.GetRootActor();
217 Stage::GetCurrent().Add( root );
219 TestGlAbstraction& gl = application.GetGlAbstraction();
224 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
225 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
227 emitter.SetBubbleScale( 2.f );
229 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
230 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
232 emitter.SetBubbleScale( 0.5f );
234 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
235 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
239 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
241 ToolkitTestApplication application;
242 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
244 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
245 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
249 emitter.SetBubbleDensity( 3.f );
250 DALI_TEST_CHECK(true);
252 catch(Dali::DaliException& e)
254 DALI_TEST_PRINT_ASSERT( e );
255 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
260 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
262 ToolkitTestApplication application;
263 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
265 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
266 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
270 emitter.SetBubbleDensity( 10.f );
272 catch(Dali::DaliException& e)
274 DALI_TEST_PRINT_ASSERT( e );
275 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
280 int UtcDaliBubbleEmitterSetBlendMode(void)
282 ToolkitTestApplication application;
283 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
285 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
286 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
287 Actor root = emitter.GetRootActor();
288 Stage::GetCurrent().Add( root );
290 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
292 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
293 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
294 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
295 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
297 emitter.SetBlendMode( true );
299 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
300 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
301 DALI_TEST_EQUALS( (GLenum)GL_ZERO, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
302 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
304 emitter.SetBlendMode( false );
306 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
307 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
308 DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
309 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
314 int UtcDaliBubbleEmitterEmitBubble(void)
316 ToolkitTestApplication application;
317 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
319 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
320 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
322 Actor root = emitter.GetRootActor();
323 Actor bubbleMesh = root.GetChildAt( 0 );
324 Stage::GetCurrent().Add( root );
325 DALI_TEST_CHECK( bubbleMesh );
327 Property::Index propertyIndex0 = bubbleMesh.GetPropertyIndex( "percentage-0" );
328 Property::Index propertyIndex1 = bubbleMesh.GetPropertyIndex( "percentage-1" );
329 float value0, value1;
331 Animation animation = Animation::New( 0.5f );
332 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
333 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
334 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
335 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
336 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
337 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
341 Wait(application, 300);
342 propertyIndex0 = bubbleMesh.GetPropertyIndex( "percentage-0" );
343 propertyIndex1 = bubbleMesh.GetPropertyIndex( "percentage-1" );
344 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
345 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
346 DALI_TEST_CHECK( value0 >= 0.6f );
347 DALI_TEST_CHECK( value1 >= 0.6f );
349 Wait(application,500);
350 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
351 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
352 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
353 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
357 int UtcDaliBubbleEmitterRestore(void)
359 ToolkitTestApplication application;
360 tet_infoline( " UtcDaliBubbleEmitterRestore " );
362 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
363 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 90, Vector2( 5.f, 10.f ));
364 Actor root = emitter.GetRootActor();
365 Stage::GetCurrent().Add( root );
367 Actor bubbleMesh = root.GetChildAt( 0 );
368 Renderer renderer = bubbleMesh.GetRendererAt( 0 );
369 DALI_TEST_CHECK( renderer );
371 TestGlAbstraction& gl = application.GetGlAbstraction();
373 float percentageValue;
374 Vector4 startEndPosValue;
376 Animation animation = Animation::New( 0.5f );
377 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
381 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
382 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
384 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
385 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
386 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
389 Wait(application, 200);
392 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
393 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
395 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
396 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
397 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
400 application.SendNotification();
401 application.Render();
403 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
404 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
406 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartAndEndPos[0]", startEndPosValue ) );
407 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );