2 * Copyright (c) 2022 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>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
28 #include <dali/public-api/rendering/renderer.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;
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 Texture CreateSolidColorTexture(ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height)
78 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
83 int UtcDaliBubbleEmitterNew(void)
85 ToolkitTestApplication application;
87 tet_infoline(" UtcDaliBubbleEmitterNew ");
89 // Test default constructor
90 BubbleEmitter emitter;
91 DALI_TEST_CHECK(!emitter);
93 // Test object creation
94 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
95 emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
96 DALI_TEST_CHECK(emitter);
98 // Additional check to ensure object is created by checking if it's registered
99 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
100 DALI_TEST_CHECK(registry);
101 gObjectCreatedCallBackCalled = false;
102 registry.ObjectCreatedSignal().Connect(&TestCallback);
104 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
106 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
108 // Test copy constructor
109 BubbleEmitter emitterCopy(emitter);
110 DALI_TEST_CHECK(emitterCopy);
113 Handle handleEmitter;
114 handleEmitter = emitter;
115 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast(handleEmitter);
116 DALI_TEST_CHECK(downCastEmitter);
120 int UtcDaliBubbleEmitterDownCast01(void)
122 ToolkitTestApplication application;
124 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
126 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
127 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
129 BaseHandle handle(emitter);
130 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
131 DALI_TEST_EQUALS((bool)emitter2, true, TEST_LOCATION);
135 int UtcDaliBubbleEmitterDownCast02(void)
137 ToolkitTestApplication application;
139 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
141 Handle handle = Handle::New(); // Create a custom object
142 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
143 DALI_TEST_EQUALS((bool)emitter, false, TEST_LOCATION);
147 int UtcDaliBubbleEmitterGetRootActor(void)
149 ToolkitTestApplication application;
150 tet_infoline(" UtcDaliBubbleEmitterGetRootActor ");
152 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
153 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 270, Vector2(5.f, 10.f));
155 Actor root = emitter.GetRootActor();
156 DALI_TEST_CHECK(root);
157 DALI_TEST_CHECK(root.GetChildCount() == 0);
161 int UtcDaliBubbleEmitterSetBackground(void)
163 ToolkitTestApplication application;
164 tet_infoline(" UtcDaliBubbleEmitterSetBackground ");
166 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
167 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
169 RenderTaskList taskList = application.GetScene().GetRenderTaskList();
170 unsigned int taskCount = taskList.GetTaskCount();
172 Texture bgImage = CreateSolidColorTexture(application, Color::RED, 50, 50);
173 emitter.SetBackground(bgImage, Vector3(0.f, 0.f, 0.5f));
175 DALI_TEST_CHECK(taskList.GetTaskCount() == taskCount + 1);
177 Wait(application, 500);
178 DALI_TEST_CHECK(taskList.GetTaskCount() == taskCount);
182 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
183 // To test that the bubble-shape image is successfully switched in the sampler
184 /*int UtcDaliBubbleEmitterSetShapeImage(void)
188 int UtcDaliBubbleEmitterSetBubbleScale(void)
190 ToolkitTestApplication application;
191 tet_infoline(" UtcDaliBubbleEmitterSetBubbleScale ");
193 static std::vector<UniformData> customUniforms =
195 UniformData("uDynamicScale", Property::Type::FLOAT),
198 TestGraphicsController& graphics = application.GetGraphicsController();
199 graphics.AddCustomUniforms(customUniforms);
201 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
202 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 150, Vector2(5.f, 10.f));
203 DALI_TEST_CHECK(emitter);
204 Actor root = emitter.GetRootActor();
205 application.GetScene().Add(root);
206 root.SetProperty(Actor::Property::POSITION, Vector3::ZERO);
207 root.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
208 root.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
210 TestGlAbstraction& gl = application.GetGlAbstraction();
215 DALI_TEST_CHECK(gl.GetUniformValue<float>("uDynamicScale", scaleValue));
216 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION);
218 emitter.SetBubbleScale(2.f);
220 DALI_TEST_CHECK(gl.GetUniformValue<float>("uDynamicScale", scaleValue));
221 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION);
223 emitter.SetBubbleScale(0.5f);
225 DALI_TEST_CHECK(gl.GetUniformValue<float>("uDynamicScale", scaleValue));
226 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION);
231 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
233 ToolkitTestApplication application;
234 tet_infoline(" UtcDaliBubbleEmitterSetBubbleDensity ");
236 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
237 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
241 emitter.SetBubbleDensity(3.f);
242 DALI_TEST_CHECK(true);
244 catch(Dali::DaliException& e)
246 DALI_TEST_PRINT_ASSERT(e);
247 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION);
252 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
254 ToolkitTestApplication application;
255 tet_infoline(" UtcDaliBubbleEmitterSetBubbleDensity ");
257 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
258 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
262 emitter.SetBubbleDensity(10.f);
264 catch(Dali::DaliException& e)
266 DALI_TEST_PRINT_ASSERT(e);
267 DALI_TEST_ASSERT(e, "density > 0 && density <= 9", TEST_LOCATION);
272 int UtcDaliBubbleEmitterEmitBubble(void)
274 ToolkitTestApplication application;
275 tet_infoline(" UtcDaliBubbleEmitterEmitBubble ");
277 Texture shapeImage1 = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
278 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage1, 200, Vector2(5.f, 10.f));
280 Actor root = emitter.GetRootActor();
281 Renderer bubbleRenderer = root.GetRendererAt(0);
282 application.GetScene().Add(root);
283 DALI_TEST_CHECK(bubbleRenderer);
285 Property::Index propertyIndex0 = bubbleRenderer.GetPropertyIndex("uPercentage[0]");
286 Property::Index propertyIndex1 = bubbleRenderer.GetPropertyIndex("uPercentage[1]");
287 float value0, value1;
289 Animation animation = Animation::New(0.5f);
290 emitter.EmitBubble(animation, Vector2(40.f, 40.f), Vector2(-5.f, -5.f), Vector2(30.f, 30.f));
291 emitter.EmitBubble(animation, Vector2(10.f, 10.f), Vector2(5.f, 5.f), Vector2(30.f, 30.f));
292 (bubbleRenderer.GetProperty(propertyIndex0)).Get(value0);
293 (bubbleRenderer.GetProperty(propertyIndex1)).Get(value1);
294 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION);
295 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION);
296 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
297 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
298 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION);
299 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION);
303 Wait(application, 300);
304 propertyIndex0 = bubbleRenderer.GetPropertyIndex("uPercentage[0]");
305 propertyIndex1 = bubbleRenderer.GetPropertyIndex("uPercentage[1]");
306 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
307 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
308 DALI_TEST_CHECK(value0 >= 0.6f);
309 DALI_TEST_CHECK(value1 >= 0.6f);
311 Wait(application, 500);
312 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
313 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
314 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION);
315 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION);
319 int UtcDaliBubbleEmitterRestore(void)
321 ToolkitTestApplication application;
322 tet_infoline(" UtcDaliBubbleEmitterRestore ");
324 static std::vector<UniformData> customUniforms =
326 UniformData("uPercentage[90]", Property::Type::FLOAT),
327 UniformData("uStartEndPosition[90]", Property::Type::VECTOR4),
330 TestGraphicsController& graphics = application.GetGraphicsController();
331 graphics.AddCustomUniforms(customUniforms);
333 Vector2 movementArea(50.f, 50.f);
334 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
335 BubbleEmitter emitter = BubbleEmitter::New(movementArea, shapeImage, 90, Vector2(5.f, 10.f));
336 Actor root = emitter.GetRootActor();
337 application.GetScene().Add(root);
338 root.SetProperty(Actor::Property::POSITION, Vector3::ZERO);
339 root.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
340 root.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
342 Renderer renderer = root.GetRendererAt(0);
343 DALI_TEST_CHECK(renderer);
345 TestGlAbstraction& gl = application.GetGlAbstraction();
347 float percentageValue;
348 Vector4 startEndPosValue;
350 Animation animation = Animation::New(0.5f);
351 emitter.EmitBubble(animation, Vector2(40.f, 40.f), Vector2(-5.f, -5.f), Vector2(30.f, 30.f));
355 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
356 DALI_TEST_EQUALS(percentageValue, 0.f, TEST_LOCATION);
358 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uStartEndPosition[0]", startEndPosValue));
359 DALI_TEST_EQUALS(startEndPosValue.x, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
360 DALI_TEST_EQUALS(startEndPosValue.y, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
363 Wait(application, 200);
366 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
367 DALI_TEST_CHECK(percentageValue < 0.5f && percentageValue >= 0.4);
369 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uStartEndPosition[0]", startEndPosValue));
370 DALI_TEST_EQUALS(startEndPosValue.x, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
371 DALI_TEST_EQUALS(startEndPosValue.y, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
374 application.SendNotification();
375 application.Render();
377 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
378 DALI_TEST_EQUALS(percentageValue, 0.f, TEST_LOCATION);
380 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uStartEndPosition[0]", startEndPosValue));
381 DALI_TEST_EQUALS(startEndPosValue, Vector4::ZERO, TEST_LOCATION);