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>
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 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
80 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
83 PixelBuffer* pixbuf = imageData.GetBuffer();
84 unsigned int size = width * height;
86 for( size_t i = 0; i < size; i++ )
88 pixbuf[i*4+0] = 0xFF * color.r;
89 pixbuf[i*4+1] = 0xFF * color.g;
90 pixbuf[i*4+2] = 0xFF * color.b;
91 pixbuf[i*4+3] = 0xFF * color.a;
95 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
96 application.SendNotification();
97 application.Render(RENDER_FRAME_INTERVAL);
98 application.Render(RENDER_FRAME_INTERVAL);
99 application.SendNotification();
106 int UtcDaliBubbleEmitterNew(void)
108 ToolkitTestApplication application;
110 tet_infoline(" UtcDaliBubbleEmitterNew ");
112 // Test default constructor
113 BubbleEmitter emitter;
114 DALI_TEST_CHECK( !emitter );
116 // Test object creation
117 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
118 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
119 DALI_TEST_CHECK( emitter );
121 // Additional check to ensure object is created by checking if it's registered
122 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
123 DALI_TEST_CHECK( registry );
124 gObjectCreatedCallBackCalled = false;
125 registry.ObjectCreatedSignal().Connect( &TestCallback );
127 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
129 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
131 // Test copy constructor
132 BubbleEmitter emitterCopy( emitter );
133 DALI_TEST_CHECK( emitterCopy );
136 Handle handleEmitter;
137 handleEmitter = emitter;
138 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
139 DALI_TEST_CHECK( downCastEmitter );
143 int UtcDaliBubbleEmitterGetRootActor(void)
145 ToolkitTestApplication application;
146 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
148 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
149 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
151 Actor root = emitter.GetRootActor();
152 DALI_TEST_CHECK( root );
153 DALI_TEST_CHECK( root.GetChildCount() == 3 );
157 int UtcDaliBubbleEmitterSetBackground(void)
159 ToolkitTestApplication application;
160 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
162 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
163 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
165 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
166 unsigned int taskCount = taskList.GetTaskCount();
168 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
169 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
171 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
173 Wait(application, 500);
174 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
178 int UtcDaliBubbleEmitterSetShapeImage(void)
180 ToolkitTestApplication application;
181 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
183 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
184 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
186 Actor root = emitter.GetRootActor();
187 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
188 Material material = bubbleMesh.GetMaterial();
190 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
192 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
193 emitter.SetShapeImage( shapeImage2 );
195 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
199 int UtcDaliBubbleEmitterSetBubbleScale(void)
201 ToolkitTestApplication application;
202 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
204 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
205 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
207 Actor root = emitter.GetRootActor();
208 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
209 ShaderEffect effect = bubbleMesh.GetShaderEffect();
210 DALI_TEST_CHECK( effect );
212 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
214 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
215 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
217 emitter.SetBubbleScale( 2.f );
218 application.SendNotification();
219 application.Render();
220 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
221 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
223 emitter.SetBubbleScale( 0.5f );
224 application.SendNotification();
225 application.Render();
226 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
227 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
231 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
233 ToolkitTestApplication application;
234 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
236 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
237 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 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 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
258 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 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 UtcDaliBubbleEmitterSetBlendMode(void)
274 ToolkitTestApplication application;
275 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
277 Image shapeImage1 = CreateSolidColorImage( 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 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
283 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
285 emitter.SetBlendMode( true );
286 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
287 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
288 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
289 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
290 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
292 emitter.SetBlendMode( false );
293 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
294 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
295 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
296 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
297 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
301 int UtcDaliBubbleEmitterEmitBubble(void)
303 ToolkitTestApplication application;
304 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
306 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
307 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
309 Actor root = emitter.GetRootActor();
310 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
311 ShaderEffect effect = bubbleMesh.GetShaderEffect();
312 DALI_TEST_CHECK( effect );
314 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
315 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
316 float value0, value1;
318 Animation animation = Animation::New( 0.5f );
319 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
320 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
321 (effect.GetProperty(propertyIndex0)).Get( value0 );
322 (effect.GetProperty(propertyIndex1)).Get( value1 );
323 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
324 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
328 Wait(application, 300);
329 (effect.GetProperty(propertyIndex0)).Get( value0 );
330 (effect.GetProperty(propertyIndex1)).Get( value1 );
331 DALI_TEST_CHECK( value0 >= 0.6f );
332 DALI_TEST_CHECK( value1 >= 0.6f );
334 Wait(application, 600);
335 (effect.GetProperty(propertyIndex0)).Get( value0 );
336 (effect.GetProperty(propertyIndex1)).Get( value1 );
337 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
338 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
342 int UtcDaliBubbleEmitterStartExplosion(void)
344 ToolkitTestApplication application;
345 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
347 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
348 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
349 Actor root = emitter.GetRootActor();
350 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
351 ShaderEffect effect = bubbleMesh.GetShaderEffect();
352 DALI_TEST_CHECK( effect );
354 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
356 (effect.GetProperty(propertyIndex)).Get( value );
357 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
359 emitter.StartExplosion( 0.4, 4.f );
361 Wait(application, 200); // 0.2s
362 (effect.GetProperty(propertyIndex)).Get( value );
363 DALI_TEST_CHECK( value >= 2.f );
365 Wait(application, 100); // 0.3s
366 (effect.GetProperty(propertyIndex)).Get( value );
367 DALI_TEST_CHECK( value >= 3.f );
369 Wait(application, 100); // 0.4s
370 (effect.GetProperty(propertyIndex)).Get( value );
371 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
375 int UtcDaliBubbleEmitterRestore(void)
377 ToolkitTestApplication application;
378 tet_infoline( " UtcDaliBubbleEmitterRestore " );
380 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
381 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
382 Actor root = emitter.GetRootActor();
383 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
384 ShaderEffect effect = bubbleMesh.GetShaderEffect();
385 DALI_TEST_CHECK( effect );
387 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
390 Animation animation = Animation::New( 0.5f );
391 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
392 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
393 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
396 Wait(application, 200);
399 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
400 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
403 application.SendNotification();
404 application.Render();
406 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
407 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );