2 * Copyright (c) 2016 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/public-api/rendering/renderer.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
31 using namespace Dali::Toolkit;
33 void utc_dali_toolkit_bubble_emitter_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_bubble_emitter_cleanup(void)
40 test_return_value = TET_PASS;
47 const int RENDER_FRAME_INTERVAL = 16;
49 static bool gObjectCreatedCallBackCalled;
50 static void TestCallback(BaseHandle handle)
52 gObjectCreatedCallBackCalled = true;
56 * Simulate time passed by.
58 * @note this will always process at least 1 frame (1/60 sec)
60 * @param application Test application instance
61 * @param duration Time to pass in milliseconds.
62 * @return The actual time passed in milliseconds
64 static int Wait(ToolkitTestApplication& application, int duration = 0)
68 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
70 application.SendNotification();
71 application.Render(RENDER_FRAME_INTERVAL);
72 time += RENDER_FRAME_INTERVAL;
78 static Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
80 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
83 PixelBuffer* pixbuf = imageData.GetBuffer();
84 unsigned int size = width * height;
86 for( size_t i = 0; i < size; i++ )
88 pixbuf[i*4+0] = 0xFF * color.r;
89 pixbuf[i*4+1] = 0xFF * color.g;
90 pixbuf[i*4+2] = 0xFF * color.b;
91 pixbuf[i*4+3] = 0xFF * color.a;
95 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
96 application.SendNotification();
97 application.Render(RENDER_FRAME_INTERVAL);
98 application.Render(RENDER_FRAME_INTERVAL);
99 application.SendNotification();
106 int UtcDaliBubbleEmitterNew(void)
108 ToolkitTestApplication application;
110 tet_infoline(" UtcDaliBubbleEmitterNew ");
112 // Test default constructor
113 BubbleEmitter emitter;
114 DALI_TEST_CHECK( !emitter );
116 // Test object creation
117 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
118 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
119 DALI_TEST_CHECK( emitter );
121 // Additional check to ensure object is created by checking if it's registered
122 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
123 DALI_TEST_CHECK( registry );
124 gObjectCreatedCallBackCalled = false;
125 registry.ObjectCreatedSignal().Connect( &TestCallback );
127 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
129 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
131 // Test copy constructor
132 BubbleEmitter emitterCopy( emitter );
133 DALI_TEST_CHECK( emitterCopy );
136 Handle handleEmitter;
137 handleEmitter = emitter;
138 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
139 DALI_TEST_CHECK( downCastEmitter );
143 int UtcDaliBubbleEmitterDownCast01(void)
145 ToolkitTestApplication application;
147 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
149 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
150 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
152 BaseHandle handle(emitter);
153 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
154 DALI_TEST_EQUALS( (bool)emitter2, true, TEST_LOCATION );
158 int UtcDaliBubbleEmitterDownCast02(void)
160 ToolkitTestApplication application;
162 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
164 Handle handle = Handle::New(); // Create a custom object
165 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
166 DALI_TEST_EQUALS( (bool)emitter, false, TEST_LOCATION );
170 int UtcDaliBubbleEmitterGetRootActor(void)
172 ToolkitTestApplication application;
173 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
175 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
176 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 270, Vector2( 5.f, 10.f ));
178 Actor root = emitter.GetRootActor();
179 DALI_TEST_CHECK( root );
180 DALI_TEST_CHECK( root.GetChildCount() == 3 );
184 int UtcDaliBubbleEmitterSetBackground(void)
186 ToolkitTestApplication application;
187 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
189 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
190 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
192 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
193 unsigned int taskCount = taskList.GetTaskCount();
195 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
196 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
198 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
200 Wait(application, 500);
201 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
205 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
206 // To test that the bubble-shape image is successfully switched in the sampler
207 /*int UtcDaliBubbleEmitterSetShapeImage(void)
211 int UtcDaliBubbleEmitterSetBubbleScale(void)
213 ToolkitTestApplication application;
214 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
216 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
217 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
218 DALI_TEST_CHECK(emitter);
219 Actor root = emitter.GetRootActor();
220 Stage::GetCurrent().Add( root );
221 root.SetPosition( Vector3::ZERO );
222 root.SetParentOrigin( ParentOrigin::CENTER );
223 root.SetAnchorPoint( AnchorPoint::CENTER );
225 TestGlAbstraction& gl = application.GetGlAbstraction();
230 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
231 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
233 emitter.SetBubbleScale( 2.f );
235 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
236 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
238 emitter.SetBubbleScale( 0.5f );
240 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
241 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
246 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
248 ToolkitTestApplication application;
249 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
251 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
252 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
256 emitter.SetBubbleDensity( 3.f );
257 DALI_TEST_CHECK(true);
259 catch(Dali::DaliException& e)
261 DALI_TEST_PRINT_ASSERT( e );
262 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
267 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
269 ToolkitTestApplication application;
270 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
272 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
273 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
277 emitter.SetBubbleDensity( 10.f );
279 catch(Dali::DaliException& e)
281 DALI_TEST_PRINT_ASSERT( e );
282 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
287 int UtcDaliBubbleEmitterEmitBubble(void)
289 ToolkitTestApplication application;
290 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
292 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
293 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
295 Actor root = emitter.GetRootActor();
296 Actor bubbleMesh = root.GetChildAt( 0 );
297 Stage::GetCurrent().Add( root );
298 DALI_TEST_CHECK( bubbleMesh );
300 Property::Index propertyIndex0 = bubbleMesh.GetPropertyIndex( "uPercentage[0]" );
301 Property::Index propertyIndex1 = bubbleMesh.GetPropertyIndex( "uPercentage[1]" );
302 float value0, value1;
304 Animation animation = Animation::New( 0.5f );
305 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
306 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
307 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
308 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
309 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
310 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
314 Wait(application, 300);
315 propertyIndex0 = bubbleMesh.GetPropertyIndex( "uPercentage[0]" );
316 propertyIndex1 = bubbleMesh.GetPropertyIndex( "uPercentage[1]" );
317 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
318 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
319 DALI_TEST_CHECK( value0 >= 0.6f );
320 DALI_TEST_CHECK( value1 >= 0.6f );
322 Wait(application,500);
323 (bubbleMesh.GetProperty(propertyIndex0)).Get( value0 );
324 (bubbleMesh.GetProperty(propertyIndex1)).Get( value1 );
325 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
326 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
330 int UtcDaliBubbleEmitterRestore(void)
332 ToolkitTestApplication application;
333 tet_infoline( " UtcDaliBubbleEmitterRestore " );
335 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
336 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 90, Vector2( 5.f, 10.f ));
337 Actor root = emitter.GetRootActor();
338 Stage::GetCurrent().Add( root );
339 root.SetPosition( Vector3::ZERO );
340 root.SetParentOrigin( ParentOrigin::CENTER );
341 root.SetAnchorPoint( AnchorPoint::CENTER );
343 Actor bubbleMesh = root.GetChildAt( 0 );
344 Renderer renderer = bubbleMesh.GetRendererAt( 0 );
345 DALI_TEST_CHECK( renderer );
347 TestGlAbstraction& gl = application.GetGlAbstraction();
349 float percentageValue;
350 Vector4 startEndPosValue;
352 Animation animation = Animation::New( 0.5f );
353 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
357 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
358 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
360 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
361 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
362 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
365 Wait(application, 200);
368 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
369 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
371 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
372 DALI_TEST_EQUALS( startEndPosValue.x, 40.f, TEST_LOCATION );
373 DALI_TEST_EQUALS( startEndPosValue.y, 40.f, TEST_LOCATION );
376 application.SendNotification();
377 application.Render();
379 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
380 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
382 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
383 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );