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-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 Texture CreateSolidColorTexture( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
80 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
86 int UtcDaliBubbleEmitterNew(void)
88 ToolkitTestApplication application;
90 tet_infoline(" UtcDaliBubbleEmitterNew ");
92 // Test default constructor
93 BubbleEmitter emitter;
94 DALI_TEST_CHECK( !emitter );
96 // Test object creation
97 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
98 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
99 DALI_TEST_CHECK( emitter );
101 // Additional check to ensure object is created by checking if it's registered
102 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
103 DALI_TEST_CHECK( registry );
104 gObjectCreatedCallBackCalled = false;
105 registry.ObjectCreatedSignal().Connect( &TestCallback );
107 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
109 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
111 // Test copy constructor
112 BubbleEmitter emitterCopy( emitter );
113 DALI_TEST_CHECK( emitterCopy );
116 Handle handleEmitter;
117 handleEmitter = emitter;
118 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
119 DALI_TEST_CHECK( downCastEmitter );
123 int UtcDaliBubbleEmitterDownCast01(void)
125 ToolkitTestApplication application;
127 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
129 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
130 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
132 BaseHandle handle(emitter);
133 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
134 DALI_TEST_EQUALS( (bool)emitter2, true, TEST_LOCATION );
138 int UtcDaliBubbleEmitterDownCast02(void)
140 ToolkitTestApplication application;
142 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
144 Handle handle = Handle::New(); // Create a custom object
145 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
146 DALI_TEST_EQUALS( (bool)emitter, false, TEST_LOCATION );
150 int UtcDaliBubbleEmitterGetRootActor(void)
152 ToolkitTestApplication application;
153 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
155 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
156 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 270, Vector2( 5.f, 10.f ));
158 Actor root = emitter.GetRootActor();
159 DALI_TEST_CHECK( root );
160 DALI_TEST_CHECK( root.GetChildCount() == 0 );
164 int UtcDaliBubbleEmitterSetBackground(void)
166 ToolkitTestApplication application;
167 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
169 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
170 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
172 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
173 unsigned int taskCount = taskList.GetTaskCount();
175 Texture bgImage = CreateSolidColorTexture( application, Color::RED, 50, 50 );
176 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
178 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
180 Wait(application, 500);
181 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
185 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
186 // To test that the bubble-shape image is successfully switched in the sampler
187 /*int UtcDaliBubbleEmitterSetShapeImage(void)
191 int UtcDaliBubbleEmitterSetBubbleScale(void)
193 ToolkitTestApplication application;
194 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
196 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
197 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
198 DALI_TEST_CHECK(emitter);
199 Actor root = emitter.GetRootActor();
200 Stage::GetCurrent().Add( root );
201 root.SetProperty( Actor::Property::POSITION, Vector3::ZERO );
202 root.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
203 root.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
205 TestGlAbstraction& gl = application.GetGlAbstraction();
210 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
211 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
213 emitter.SetBubbleScale( 2.f );
215 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
216 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
218 emitter.SetBubbleScale( 0.5f );
220 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
221 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
226 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
228 ToolkitTestApplication application;
229 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
231 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
232 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
236 emitter.SetBubbleDensity( 3.f );
237 DALI_TEST_CHECK(true);
239 catch(Dali::DaliException& e)
241 DALI_TEST_PRINT_ASSERT( e );
242 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
247 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
249 ToolkitTestApplication application;
250 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
252 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
253 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
257 emitter.SetBubbleDensity( 10.f );
259 catch(Dali::DaliException& e)
261 DALI_TEST_PRINT_ASSERT( e );
262 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
267 int UtcDaliBubbleEmitterEmitBubble(void)
269 ToolkitTestApplication application;
270 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
272 Texture shapeImage1 = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
273 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
275 Actor root = emitter.GetRootActor();
276 Renderer bubbleRenderer = root.GetRendererAt( 0 );
277 Stage::GetCurrent().Add( root );
278 DALI_TEST_CHECK( bubbleRenderer );
280 Property::Index propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
281 Property::Index propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
282 float value0, value1;
284 Animation animation = Animation::New( 0.5f );
285 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
286 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
287 (bubbleRenderer.GetProperty(propertyIndex0)).Get( value0 );
288 (bubbleRenderer.GetProperty(propertyIndex1)).Get( value1 );
289 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
290 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
291 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
292 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
293 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
294 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
298 Wait(application, 300);
299 propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
300 propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
301 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
302 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
303 DALI_TEST_CHECK( value0 >= 0.6f );
304 DALI_TEST_CHECK( value1 >= 0.6f );
306 Wait(application,500);
307 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
308 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
309 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
310 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
314 int UtcDaliBubbleEmitterRestore(void)
316 ToolkitTestApplication application;
317 tet_infoline( " UtcDaliBubbleEmitterRestore " );
319 Vector2 movementArea(50.f,50.f);
320 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
321 BubbleEmitter emitter = BubbleEmitter::New( movementArea,shapeImage, 90, Vector2( 5.f, 10.f ));
322 Actor root = emitter.GetRootActor();
323 Stage::GetCurrent().Add( root );
324 root.SetProperty( Actor::Property::POSITION, Vector3::ZERO );
325 root.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
326 root.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
328 Renderer renderer = root.GetRendererAt( 0 );
329 DALI_TEST_CHECK( renderer );
331 TestGlAbstraction& gl = application.GetGlAbstraction();
333 float percentageValue;
334 Vector4 startEndPosValue;
336 Animation animation = Animation::New( 0.5f );
337 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
341 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
342 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
344 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
345 DALI_TEST_EQUALS( startEndPosValue.x, 40.f - movementArea.x*0.5f, TEST_LOCATION );
346 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
349 Wait(application, 200);
352 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
353 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
355 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
356 DALI_TEST_EQUALS( startEndPosValue.x, 40.f- movementArea.x*0.5f, TEST_LOCATION );
357 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
360 application.SendNotification();
361 application.Render();
363 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
364 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
366 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
367 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );