2 * Copyright (c) 2017 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/devel-api/object/handle-devel.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
32 using namespace Dali::Toolkit;
34 void utc_dali_toolkit_bubble_emitter_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_toolkit_bubble_emitter_cleanup(void)
41 test_return_value = TET_PASS;
48 const int RENDER_FRAME_INTERVAL = 16;
50 static bool gObjectCreatedCallBackCalled;
51 static void TestCallback(BaseHandle handle)
53 gObjectCreatedCallBackCalled = true;
57 * Simulate time passed by.
59 * @note this will always process at least 1 frame (1/60 sec)
61 * @param application Test application instance
62 * @param duration Time to pass in milliseconds.
63 * @return The actual time passed in milliseconds
65 static int Wait(ToolkitTestApplication& application, int duration = 0)
69 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
71 application.SendNotification();
72 application.Render(RENDER_FRAME_INTERVAL);
73 time += RENDER_FRAME_INTERVAL;
79 static Texture CreateSolidColorTexture( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
81 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
87 int UtcDaliBubbleEmitterNew(void)
89 ToolkitTestApplication application;
91 tet_infoline(" UtcDaliBubbleEmitterNew ");
93 // Test default constructor
94 BubbleEmitter emitter;
95 DALI_TEST_CHECK( !emitter );
97 // Test object creation
98 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
99 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
100 DALI_TEST_CHECK( emitter );
102 // Additional check to ensure object is created by checking if it's registered
103 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
104 DALI_TEST_CHECK( registry );
105 gObjectCreatedCallBackCalled = false;
106 registry.ObjectCreatedSignal().Connect( &TestCallback );
108 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
110 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
112 // Test copy constructor
113 BubbleEmitter emitterCopy( emitter );
114 DALI_TEST_CHECK( emitterCopy );
117 Handle handleEmitter;
118 handleEmitter = emitter;
119 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
120 DALI_TEST_CHECK( downCastEmitter );
124 int UtcDaliBubbleEmitterDownCast01(void)
126 ToolkitTestApplication application;
128 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
130 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
131 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
133 BaseHandle handle(emitter);
134 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
135 DALI_TEST_EQUALS( (bool)emitter2, true, TEST_LOCATION );
139 int UtcDaliBubbleEmitterDownCast02(void)
141 ToolkitTestApplication application;
143 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
145 Handle handle = Handle::New(); // Create a custom object
146 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
147 DALI_TEST_EQUALS( (bool)emitter, false, TEST_LOCATION );
151 int UtcDaliBubbleEmitterGetRootActor(void)
153 ToolkitTestApplication application;
154 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
156 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
157 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 270, Vector2( 5.f, 10.f ));
159 Actor root = emitter.GetRootActor();
160 DALI_TEST_CHECK( root );
161 DALI_TEST_CHECK( root.GetChildCount() == 0 );
165 int UtcDaliBubbleEmitterSetBackground(void)
167 ToolkitTestApplication application;
168 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
170 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
171 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
173 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
174 unsigned int taskCount = taskList.GetTaskCount();
176 Texture bgImage = CreateSolidColorTexture( application, Color::RED, 50, 50 );
177 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
179 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
181 Wait(application, 500);
182 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
186 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
187 // To test that the bubble-shape image is successfully switched in the sampler
188 /*int UtcDaliBubbleEmitterSetShapeImage(void)
192 int UtcDaliBubbleEmitterSetBubbleScale(void)
194 ToolkitTestApplication application;
195 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
197 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
198 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
199 DALI_TEST_CHECK(emitter);
200 Actor root = emitter.GetRootActor();
201 Stage::GetCurrent().Add( root );
202 root.SetPosition( Vector3::ZERO );
203 root.SetParentOrigin( ParentOrigin::CENTER );
204 root.SetAnchorPoint( AnchorPoint::CENTER );
206 TestGlAbstraction& gl = application.GetGlAbstraction();
211 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
212 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
214 emitter.SetBubbleScale( 2.f );
216 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
217 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
219 emitter.SetBubbleScale( 0.5f );
221 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
222 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
227 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
229 ToolkitTestApplication application;
230 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
232 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
233 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
237 emitter.SetBubbleDensity( 3.f );
238 DALI_TEST_CHECK(true);
240 catch(Dali::DaliException& e)
242 DALI_TEST_PRINT_ASSERT( e );
243 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
248 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
250 ToolkitTestApplication application;
251 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
253 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
254 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
258 emitter.SetBubbleDensity( 10.f );
260 catch(Dali::DaliException& e)
262 DALI_TEST_PRINT_ASSERT( e );
263 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
268 int UtcDaliBubbleEmitterEmitBubble(void)
270 ToolkitTestApplication application;
271 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
273 Texture shapeImage1 = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
274 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
276 Actor root = emitter.GetRootActor();
277 Renderer bubbleRenderer = root.GetRendererAt( 0 );
278 Stage::GetCurrent().Add( root );
279 DALI_TEST_CHECK( bubbleRenderer );
281 Property::Index propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
282 Property::Index propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
283 float value0, value1;
285 Animation animation = Animation::New( 0.5f );
286 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
287 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
288 (bubbleRenderer.GetProperty(propertyIndex0)).Get( value0 );
289 (bubbleRenderer.GetProperty(propertyIndex1)).Get( value1 );
290 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
291 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
292 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value0 );
293 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value1 );
294 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
295 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
299 Wait(application, 300);
300 propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
301 propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
302 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value0 );
303 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value1 );
304 DALI_TEST_CHECK( value0 >= 0.6f );
305 DALI_TEST_CHECK( value1 >= 0.6f );
307 Wait(application,500);
308 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value0 );
309 ( DevelHandle::GetCurrentProperty( bubbleRenderer, propertyIndex0 ) ).Get( value1 );
310 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
311 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
315 int UtcDaliBubbleEmitterRestore(void)
317 ToolkitTestApplication application;
318 tet_infoline( " UtcDaliBubbleEmitterRestore " );
320 Vector2 movementArea(50.f,50.f);
321 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
322 BubbleEmitter emitter = BubbleEmitter::New( movementArea,shapeImage, 90, Vector2( 5.f, 10.f ));
323 Actor root = emitter.GetRootActor();
324 Stage::GetCurrent().Add( root );
325 root.SetPosition( Vector3::ZERO );
326 root.SetParentOrigin( ParentOrigin::CENTER );
327 root.SetAnchorPoint( AnchorPoint::CENTER );
329 Renderer renderer = root.GetRendererAt( 0 );
330 DALI_TEST_CHECK( renderer );
332 TestGlAbstraction& gl = application.GetGlAbstraction();
334 float percentageValue;
335 Vector4 startEndPosValue;
337 Animation animation = Animation::New( 0.5f );
338 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
342 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
343 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
345 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
346 DALI_TEST_EQUALS( startEndPosValue.x, 40.f - movementArea.x*0.5f, TEST_LOCATION );
347 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
350 Wait(application, 200);
353 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
354 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
356 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
357 DALI_TEST_EQUALS( startEndPosValue.x, 40.f- movementArea.x*0.5f, TEST_LOCATION );
358 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
361 application.SendNotification();
362 application.Render();
364 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
365 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
367 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
368 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );