2 * Copyright (c) 2021 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 = application.GetCore().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 = application.GetScene().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 static std::vector<UniformData> customUniforms =
198 UniformData("uDynamicScale", Property::Type::FLOAT),
201 TestGraphicsController& graphics = application.GetGraphicsController();
202 graphics.AddCustomUniforms(customUniforms);
204 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
205 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f ));
206 DALI_TEST_CHECK(emitter);
207 Actor root = emitter.GetRootActor();
208 application.GetScene().Add( root );
209 root.SetProperty( Actor::Property::POSITION, Vector3::ZERO );
210 root.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
211 root.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
213 TestGlAbstraction& gl = application.GetGlAbstraction();
218 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
219 DALI_TEST_EQUALS( scaleValue, 1.f, TEST_LOCATION );
221 emitter.SetBubbleScale( 2.f );
223 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
224 DALI_TEST_EQUALS( scaleValue, 2.f, TEST_LOCATION );
226 emitter.SetBubbleScale( 0.5f );
228 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uDynamicScale", scaleValue ) );
229 DALI_TEST_EQUALS( scaleValue, 0.5f, TEST_LOCATION );
234 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
236 ToolkitTestApplication application;
237 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
239 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
240 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
244 emitter.SetBubbleDensity( 3.f );
245 DALI_TEST_CHECK(true);
247 catch(Dali::DaliException& e)
249 DALI_TEST_PRINT_ASSERT( e );
250 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
255 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
257 ToolkitTestApplication application;
258 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
260 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
261 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
265 emitter.SetBubbleDensity( 10.f );
267 catch(Dali::DaliException& e)
269 DALI_TEST_PRINT_ASSERT( e );
270 DALI_TEST_ASSERT(e, "density > 0 && density <= 9", TEST_LOCATION );
275 int UtcDaliBubbleEmitterEmitBubble(void)
277 ToolkitTestApplication application;
278 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
280 Texture shapeImage1 = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
281 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
283 Actor root = emitter.GetRootActor();
284 Renderer bubbleRenderer = root.GetRendererAt( 0 );
285 application.GetScene().Add( root );
286 DALI_TEST_CHECK( bubbleRenderer );
288 Property::Index propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
289 Property::Index propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
290 float value0, value1;
292 Animation animation = Animation::New( 0.5f );
293 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
294 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
295 (bubbleRenderer.GetProperty(propertyIndex0)).Get( value0 );
296 (bubbleRenderer.GetProperty(propertyIndex1)).Get( value1 );
297 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
298 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
299 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
300 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
301 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
302 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
306 Wait(application, 300);
307 propertyIndex0 = bubbleRenderer.GetPropertyIndex( "uPercentage[0]" );
308 propertyIndex1 = bubbleRenderer.GetPropertyIndex( "uPercentage[1]" );
309 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
310 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
311 DALI_TEST_CHECK( value0 >= 0.6f );
312 DALI_TEST_CHECK( value1 >= 0.6f );
314 Wait(application,500);
315 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value0 );
316 ( bubbleRenderer.GetCurrentProperty( propertyIndex0 ) ).Get( value1 );
317 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
318 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
322 int UtcDaliBubbleEmitterRestore(void)
324 #ifdef OLD_GRAPHICS_TEST
325 ToolkitTestApplication application;
326 tet_infoline( " UtcDaliBubbleEmitterRestore " );
328 static std::vector<UniformData> customUniforms =
330 UniformData("uPercentage[0]", Property::Type::FLOAT),
331 UniformData("uStartEndPosition[0]", Property::Type::VECTOR4),
334 TestGraphicsController& graphics = application.GetGraphicsController();
335 graphics.AddCustomUniforms(customUniforms);
337 Vector2 movementArea(50.f,50.f);
338 Texture shapeImage = CreateSolidColorTexture( application, Color::GREEN, 5, 5 );
339 BubbleEmitter emitter = BubbleEmitter::New( movementArea,shapeImage, 90, Vector2( 5.f, 10.f ));
340 Actor root = emitter.GetRootActor();
341 application.GetScene().Add( root );
342 root.SetProperty( Actor::Property::POSITION, Vector3::ZERO );
343 root.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
344 root.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
346 Renderer renderer = root.GetRendererAt( 0 );
347 DALI_TEST_CHECK( renderer );
349 TestGlAbstraction& gl = application.GetGlAbstraction();
351 float percentageValue;
352 Vector4 startEndPosValue;
354 Animation animation = Animation::New( 0.5f );
355 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
359 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
360 DALI_TEST_EQUALS( percentageValue, 0.f, TEST_LOCATION );
362 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
363 DALI_TEST_EQUALS( startEndPosValue.x, 40.f - movementArea.x*0.5f, TEST_LOCATION );
364 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
367 Wait(application, 200);
370 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uPercentage[0]", percentageValue ) );
371 DALI_TEST_CHECK( percentageValue < 0.5f && percentageValue >= 0.4);
373 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uStartEndPosition[0]", startEndPosValue ) );
374 DALI_TEST_EQUALS( startEndPosValue.x, 40.f- movementArea.x*0.5f, TEST_LOCATION );
375 DALI_TEST_EQUALS( startEndPosValue.y, 40.f- movementArea.x*0.5f, TEST_LOCATION );
378 application.SendNotification();
379 application.Render();
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>( "uStartEndPosition[0]", startEndPosValue ) );
385 DALI_TEST_EQUALS( startEndPosValue, Vector4::ZERO, TEST_LOCATION );
387 tet_result(TET_PASS);