2 * Copyright (c) 2014 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-toolkit/dali-toolkit.h>
27 #include <dali/devel-api/actors/mesh-actor.h>
28 #include <dali/devel-api/modeling/material.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 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
81 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
84 PixelBuffer* pixbuf = imageData.GetBuffer();
85 unsigned int size = width * height;
87 for( size_t i = 0; i < size; i++ )
89 pixbuf[i*4+0] = 0xFF * color.r;
90 pixbuf[i*4+1] = 0xFF * color.g;
91 pixbuf[i*4+2] = 0xFF * color.b;
92 pixbuf[i*4+3] = 0xFF * color.a;
96 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
97 application.SendNotification();
98 application.Render(RENDER_FRAME_INTERVAL);
99 application.Render(RENDER_FRAME_INTERVAL);
100 application.SendNotification();
107 int UtcDaliBubbleEmitterNew(void)
109 ToolkitTestApplication application;
111 tet_infoline(" UtcDaliBubbleEmitterNew ");
113 // Test default constructor
114 BubbleEmitter emitter;
115 DALI_TEST_CHECK( !emitter );
117 // Test object creation
118 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
119 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
120 DALI_TEST_CHECK( emitter );
122 // Additional check to ensure object is created by checking if it's registered
123 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
124 DALI_TEST_CHECK( registry );
125 gObjectCreatedCallBackCalled = false;
126 registry.ObjectCreatedSignal().Connect( &TestCallback );
128 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
130 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
132 // Test copy constructor
133 BubbleEmitter emitterCopy( emitter );
134 DALI_TEST_CHECK( emitterCopy );
137 Handle handleEmitter;
138 handleEmitter = emitter;
139 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
140 DALI_TEST_CHECK( downCastEmitter );
144 int UtcDaliBubbleEmitterGetRootActor(void)
146 ToolkitTestApplication application;
147 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
149 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
150 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
152 Actor root = emitter.GetRootActor();
153 DALI_TEST_CHECK( root );
154 DALI_TEST_CHECK( root.GetChildCount() == 3 );
158 int UtcDaliBubbleEmitterSetBackground(void)
160 ToolkitTestApplication application;
161 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
163 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
164 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
166 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
167 unsigned int taskCount = taskList.GetTaskCount();
169 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
170 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
172 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
174 Wait(application, 500);
175 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
179 int UtcDaliBubbleEmitterSetShapeImage(void)
181 ToolkitTestApplication application;
182 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
184 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
185 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
187 Actor root = emitter.GetRootActor();
188 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
189 Material material = bubbleMesh.GetMaterial();
191 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
193 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
194 emitter.SetShapeImage( shapeImage2 );
196 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
200 int UtcDaliBubbleEmitterSetBubbleScale(void)
202 ToolkitTestApplication application;
203 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
205 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
206 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
208 Actor root = emitter.GetRootActor();
209 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
210 ShaderEffect effect = bubbleMesh.GetShaderEffect();
211 DALI_TEST_CHECK( effect );
213 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
215 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
216 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
218 emitter.SetBubbleScale( 2.f );
219 application.SendNotification();
220 application.Render();
221 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
222 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
224 emitter.SetBubbleScale( 0.5f );
225 application.SendNotification();
226 application.Render();
227 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
228 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
232 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
234 ToolkitTestApplication application;
235 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
237 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
238 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
242 emitter.SetBubbleDensity( 3.f );
243 DALI_TEST_CHECK(true);
245 catch(Dali::DaliException& e)
247 DALI_TEST_PRINT_ASSERT( e );
248 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
253 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
255 ToolkitTestApplication application;
256 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
258 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
259 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
263 emitter.SetBubbleDensity( 10.f );
265 catch(Dali::DaliException& e)
267 DALI_TEST_PRINT_ASSERT( e );
268 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
273 int UtcDaliBubbleEmitterSetBlendMode(void)
275 ToolkitTestApplication application;
276 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
278 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
279 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
281 Actor root = emitter.GetRootActor();
282 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
284 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
286 emitter.SetBlendMode( true );
287 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
288 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
289 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
290 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
291 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
293 emitter.SetBlendMode( false );
294 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
295 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
296 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
297 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
298 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
302 int UtcDaliBubbleEmitterEmitBubble(void)
304 ToolkitTestApplication application;
305 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
307 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
308 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
310 Actor root = emitter.GetRootActor();
311 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
312 ShaderEffect effect = bubbleMesh.GetShaderEffect();
313 DALI_TEST_CHECK( effect );
315 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
316 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
317 float value0, value1;
319 Animation animation = Animation::New( 0.5f );
320 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
321 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
322 (effect.GetProperty(propertyIndex0)).Get( value0 );
323 (effect.GetProperty(propertyIndex1)).Get( value1 );
324 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
325 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
329 Wait(application, 300);
330 (effect.GetProperty(propertyIndex0)).Get( value0 );
331 (effect.GetProperty(propertyIndex1)).Get( value1 );
332 DALI_TEST_CHECK( value0 >= 0.6f );
333 DALI_TEST_CHECK( value1 >= 0.6f );
335 Wait(application, 600);
336 (effect.GetProperty(propertyIndex0)).Get( value0 );
337 (effect.GetProperty(propertyIndex1)).Get( value1 );
338 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
339 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
343 int UtcDaliBubbleEmitterStartExplosion(void)
345 ToolkitTestApplication application;
346 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
348 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
349 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
350 Actor root = emitter.GetRootActor();
351 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
352 ShaderEffect effect = bubbleMesh.GetShaderEffect();
353 DALI_TEST_CHECK( effect );
355 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
357 (effect.GetProperty(propertyIndex)).Get( value );
358 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
360 emitter.StartExplosion( 0.4, 4.f );
362 Wait(application, 200); // 0.2s
363 (effect.GetProperty(propertyIndex)).Get( value );
364 DALI_TEST_CHECK( value >= 2.f );
366 Wait(application, 100); // 0.3s
367 (effect.GetProperty(propertyIndex)).Get( value );
368 DALI_TEST_CHECK( value >= 3.f );
370 Wait(application, 100); // 0.4s
371 (effect.GetProperty(propertyIndex)).Get( value );
372 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
376 int UtcDaliBubbleEmitterRestore(void)
378 ToolkitTestApplication application;
379 tet_infoline( " UtcDaliBubbleEmitterRestore " );
381 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
382 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
383 Actor root = emitter.GetRootActor();
384 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
385 ShaderEffect effect = bubbleMesh.GetShaderEffect();
386 DALI_TEST_CHECK( effect );
388 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
391 Animation animation = Animation::New( 0.5f );
392 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
393 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
394 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
397 Wait(application, 200);
400 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
401 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
404 application.SendNotification();
405 application.Render();
407 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
408 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );