2 * Copyright (c) 2023 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);
80 int bufferSize = width * height * GetBytesPerPixel(Pixel::RGBA8888);
81 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
83 for(uint32_t i = 0; i < width * height; ++i)
85 buffer[i * 4 + 0] = static_cast<uint8_t>(color.r * 255.0f);
86 buffer[i * 4 + 1] = static_cast<uint8_t>(color.g * 255.0f);
87 buffer[i * 4 + 2] = static_cast<uint8_t>(color.b * 255.0f);
88 buffer[i * 4 + 3] = static_cast<uint8_t>(color.a * 255.0f);
91 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
92 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
98 int UtcDaliBubbleEmitterNew(void)
100 ToolkitTestApplication application;
102 tet_infoline(" UtcDaliBubbleEmitterNew ");
104 // Test default constructor
105 BubbleEmitter emitter;
106 DALI_TEST_CHECK(!emitter);
108 // Test object creation
109 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
110 emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
111 DALI_TEST_CHECK(emitter);
113 // Additional check to ensure object is created by checking if it's registered
114 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
115 DALI_TEST_CHECK(registry);
116 gObjectCreatedCallBackCalled = false;
117 registry.ObjectCreatedSignal().Connect(&TestCallback);
119 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
121 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
123 // Test copy constructor
124 BubbleEmitter emitterCopy(emitter);
125 DALI_TEST_CHECK(emitterCopy);
128 Handle handleEmitter;
129 handleEmitter = emitter;
130 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast(handleEmitter);
131 DALI_TEST_CHECK(downCastEmitter);
135 int UtcDaliBubbleEmitterDownCast01(void)
137 ToolkitTestApplication application;
139 tet_infoline(" UtcDaliBubbleEmitterDownCast01 ");
141 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
142 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
144 BaseHandle handle(emitter);
145 BubbleEmitter emitter2 = BubbleEmitter::DownCast(handle);
146 DALI_TEST_EQUALS((bool)emitter2, true, TEST_LOCATION);
150 int UtcDaliBubbleEmitterDownCast02(void)
152 ToolkitTestApplication application;
154 tet_infoline(" UtcDaliBubbleEmitterDownCast02 ");
156 Handle handle = Handle::New(); // Create a custom object
157 BubbleEmitter emitter = BubbleEmitter::DownCast(handle);
158 DALI_TEST_EQUALS((bool)emitter, false, TEST_LOCATION);
162 int UtcDaliBubbleEmitterGetRootActor(void)
164 ToolkitTestApplication application;
165 tet_infoline(" UtcDaliBubbleEmitterGetRootActor ");
167 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
168 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 270, Vector2(5.f, 10.f));
170 Actor root = emitter.GetRootActor();
171 DALI_TEST_CHECK(root);
172 DALI_TEST_CHECK(root.GetChildCount() == 0);
176 int UtcDaliBubbleEmitterSetBackground(void)
178 ToolkitTestApplication application;
179 tet_infoline(" UtcDaliBubbleEmitterSetBackground ");
181 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
182 BubbleEmitter emitter = BubbleEmitter::New(Vector2(50.f, 50.f), shapeImage, 200, Vector2(5.f, 10.f));
184 RenderTaskList taskList = application.GetScene().GetRenderTaskList();
185 unsigned int taskCount = taskList.GetTaskCount();
187 Texture bgImage = CreateSolidColorTexture(application, Color::RED, 50, 50);
188 emitter.SetBackground(bgImage, Vector3(0.f, 0.f, 0.5f));
190 DALI_TEST_CHECK(taskList.GetTaskCount() == taskCount + 1);
192 Wait(application, 500);
193 DALI_TEST_CHECK(taskList.GetTaskCount() == taskCount);
197 //TODO: test case for BubbleEmitter::SetShapeImage(Image)
198 // To test that the bubble-shape image is successfully switched in the sampler
199 /*int UtcDaliBubbleEmitterSetShapeImage(void)
203 int UtcDaliBubbleEmitterSetBubbleScale(void)
205 ToolkitTestApplication application;
206 tet_infoline(" UtcDaliBubbleEmitterSetBubbleScale ");
208 static std::vector<UniformData> customUniforms =
210 UniformData("uDynamicScale", Property::Type::FLOAT),
213 TestGraphicsController& graphics = application.GetGraphicsController();
214 graphics.AddCustomUniforms(customUniforms);
216 Texture shapeImage = CreateSolidColorTexture(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 application.GetScene().Add(root);
221 root.SetProperty(Actor::Property::POSITION, Vector3::ZERO);
222 root.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
223 root.SetProperty(Actor::Property::ANCHOR_POINT, 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 Texture shapeImage = CreateSolidColorTexture(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 Texture shapeImage = CreateSolidColorTexture(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 Texture shapeImage1 = CreateSolidColorTexture(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 Renderer bubbleRenderer = root.GetRendererAt(0);
297 application.GetScene().Add(root);
298 DALI_TEST_CHECK(bubbleRenderer);
300 Property::Index propertyIndex0 = bubbleRenderer.GetPropertyIndex("uPercentage[0]");
301 Property::Index propertyIndex1 = bubbleRenderer.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 (bubbleRenderer.GetProperty(propertyIndex0)).Get(value0);
308 (bubbleRenderer.GetProperty(propertyIndex1)).Get(value1);
309 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION);
310 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION);
311 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
312 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
313 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION);
314 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION);
318 Wait(application, 300);
319 propertyIndex0 = bubbleRenderer.GetPropertyIndex("uPercentage[0]");
320 propertyIndex1 = bubbleRenderer.GetPropertyIndex("uPercentage[1]");
321 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
322 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
323 DALI_TEST_CHECK(value0 >= 0.6f);
324 DALI_TEST_CHECK(value1 >= 0.6f);
326 Wait(application, 500);
327 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value0);
328 (bubbleRenderer.GetCurrentProperty(propertyIndex0)).Get(value1);
329 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION);
330 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION);
334 int UtcDaliBubbleEmitterRestore(void)
336 ToolkitTestApplication application;
337 tet_infoline(" UtcDaliBubbleEmitterRestore ");
339 static std::vector<UniformData> customUniforms =
341 UniformData("uPercentage[90]", Property::Type::FLOAT),
342 UniformData("uStartEndPosition[90]", Property::Type::VECTOR4),
345 TestGraphicsController& graphics = application.GetGraphicsController();
346 graphics.AddCustomUniforms(customUniforms);
348 Vector2 movementArea(50.f, 50.f);
349 Texture shapeImage = CreateSolidColorTexture(application, Color::GREEN, 5, 5);
350 BubbleEmitter emitter = BubbleEmitter::New(movementArea, shapeImage, 90, Vector2(5.f, 10.f));
351 Actor root = emitter.GetRootActor();
352 application.GetScene().Add(root);
353 root.SetProperty(Actor::Property::POSITION, Vector3::ZERO);
354 root.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
355 root.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
357 Renderer renderer = root.GetRendererAt(0);
358 DALI_TEST_CHECK(renderer);
360 TestGlAbstraction& gl = application.GetGlAbstraction();
362 float percentageValue;
363 Vector4 startEndPosValue;
365 Animation animation = Animation::New(0.5f);
366 emitter.EmitBubble(animation, Vector2(40.f, 40.f), Vector2(-5.f, -5.f), Vector2(30.f, 30.f));
370 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
371 DALI_TEST_EQUALS(percentageValue, 0.f, TEST_LOCATION);
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 Wait(application, 200);
381 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
382 DALI_TEST_CHECK(percentageValue < 0.5f && percentageValue >= 0.4);
384 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uStartEndPosition[0]", startEndPosValue));
385 DALI_TEST_EQUALS(startEndPosValue.x, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
386 DALI_TEST_EQUALS(startEndPosValue.y, 40.f - movementArea.x * 0.5f, TEST_LOCATION);
389 application.SendNotification();
390 application.Render();
392 DALI_TEST_CHECK(gl.GetUniformValue<float>("uPercentage[0]", percentageValue));
393 DALI_TEST_EQUALS(percentageValue, 0.f, TEST_LOCATION);
395 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uStartEndPosition[0]", startEndPosValue));
396 DALI_TEST_EQUALS(startEndPosValue, Vector4::ZERO, TEST_LOCATION);