2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Dali::Toolkit;
30 void utc_dali_toolkit_bubble_emitter_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_bubble_emitter_cleanup(void)
37 test_return_value = TET_PASS;
44 const int RENDER_FRAME_INTERVAL = 16;
46 static bool gObjectCreatedCallBackCalled;
47 static void TestCallback(BaseHandle handle)
49 gObjectCreatedCallBackCalled = true;
53 * Simulate time passed by.
55 * @note this will always process at least 1 frame (1/60 sec)
57 * @param application Test application instance
58 * @param duration Time to pass in milliseconds.
59 * @return The actual time passed in milliseconds
61 static int Wait(ToolkitTestApplication& application, int duration = 0)
65 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
67 application.SendNotification();
68 application.Render(RENDER_FRAME_INTERVAL);
69 time += RENDER_FRAME_INTERVAL;
75 static Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
77 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
80 PixelBuffer* pixbuf = imageData.GetBuffer();
81 unsigned int size = width * height;
83 for( size_t i = 0; i < size; i++ )
85 pixbuf[i*4+0] = 0xFF * color.r;
86 pixbuf[i*4+1] = 0xFF * color.g;
87 pixbuf[i*4+2] = 0xFF * color.b;
88 pixbuf[i*4+3] = 0xFF * color.a;
92 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
93 application.SendNotification();
94 application.Render(RENDER_FRAME_INTERVAL);
95 application.Render(RENDER_FRAME_INTERVAL);
96 application.SendNotification();
103 int UtcDaliBubbleEmitterNew(void)
105 ToolkitTestApplication application;
107 tet_infoline(" UtcDaliBubbleEmitterNew ");
109 // Test default constructor
110 BubbleEmitter emitter;
111 DALI_TEST_CHECK( !emitter );
113 // Test object creation
114 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
115 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
116 DALI_TEST_CHECK( emitter );
118 // Additional check to ensure object is created by checking if it's registered
119 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
120 DALI_TEST_CHECK( registry );
121 gObjectCreatedCallBackCalled = false;
122 registry.ObjectCreatedSignal().Connect( &TestCallback );
124 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
126 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
128 // Test copy constructor
129 BubbleEmitter emitterCopy( emitter );
130 DALI_TEST_CHECK( emitterCopy );
133 Handle handleEmitter;
134 handleEmitter = emitter;
135 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
136 DALI_TEST_CHECK( downCastEmitter );
140 int UtcDaliBubbleEmitterGetRootActor(void)
142 ToolkitTestApplication application;
143 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
145 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
146 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
148 Actor root = emitter.GetRootActor();
149 DALI_TEST_CHECK( root );
150 DALI_TEST_CHECK( root.GetChildCount() == 3 );
154 int UtcDaliBubbleEmitterSetBackground(void)
156 ToolkitTestApplication application;
157 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
159 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
160 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
162 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
163 unsigned int taskCount = taskList.GetTaskCount();
165 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
166 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
168 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
170 Wait(application, 500);
171 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
175 int UtcDaliBubbleEmitterSetShapeImage(void)
177 ToolkitTestApplication application;
178 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
180 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
181 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
183 Actor root = emitter.GetRootActor();
184 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
185 Material material = bubbleMesh.GetMaterial();
187 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
189 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
190 emitter.SetShapeImage( shapeImage2 );
192 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
196 int UtcDaliBubbleEmitterSetBubbleScale(void)
198 ToolkitTestApplication application;
199 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
201 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
202 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
204 Actor root = emitter.GetRootActor();
205 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
206 ShaderEffect effect = bubbleMesh.GetShaderEffect();
207 DALI_TEST_CHECK( effect );
209 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
211 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
212 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
214 emitter.SetBubbleScale( 2.f );
215 application.SendNotification();
216 application.Render();
217 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
218 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
220 emitter.SetBubbleScale( 0.5f );
221 application.SendNotification();
222 application.Render();
223 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
224 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
228 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
230 ToolkitTestApplication application;
231 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
233 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
234 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
238 emitter.SetBubbleDensity( 3.f );
239 DALI_TEST_CHECK(true);
241 catch(Dali::DaliException& e)
243 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
244 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
249 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
251 ToolkitTestApplication application;
252 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
254 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
255 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
259 emitter.SetBubbleDensity( 10.f );
261 catch(Dali::DaliException& e)
263 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
264 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
269 int UtcDaliBubbleEmitterSetBlendMode(void)
271 ToolkitTestApplication application;
272 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
274 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
275 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
277 Actor root = emitter.GetRootActor();
278 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
280 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
282 emitter.SetBlendMode( true );
283 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
284 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
285 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
286 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
287 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
289 emitter.SetBlendMode( false );
290 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
291 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
292 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
293 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
294 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
298 int UtcDaliBubbleEmitterEmitBubble(void)
300 ToolkitTestApplication application;
301 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
303 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
304 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
306 Actor root = emitter.GetRootActor();
307 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
308 ShaderEffect effect = bubbleMesh.GetShaderEffect();
309 DALI_TEST_CHECK( effect );
311 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
312 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
313 float value0, value1;
315 Animation animation = Animation::New( 0.5f );
316 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
317 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
318 (effect.GetProperty(propertyIndex0)).Get( value0 );
319 (effect.GetProperty(propertyIndex1)).Get( value1 );
320 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
321 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
325 Wait(application, 300);
326 (effect.GetProperty(propertyIndex0)).Get( value0 );
327 (effect.GetProperty(propertyIndex1)).Get( value1 );
328 DALI_TEST_CHECK( value0 >= 0.6f );
329 DALI_TEST_CHECK( value1 >= 0.6f );
331 Wait(application, 600);
332 (effect.GetProperty(propertyIndex0)).Get( value0 );
333 (effect.GetProperty(propertyIndex1)).Get( value1 );
334 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
335 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
339 int UtcDaliBubbleEmitterStartExplosion(void)
341 ToolkitTestApplication application;
342 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
344 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
345 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
346 Actor root = emitter.GetRootActor();
347 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
348 ShaderEffect effect = bubbleMesh.GetShaderEffect();
349 DALI_TEST_CHECK( effect );
351 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
353 (effect.GetProperty(propertyIndex)).Get( value );
354 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
356 emitter.StartExplosion( 0.4, 4.f );
358 Wait(application, 200); // 0.2s
359 (effect.GetProperty(propertyIndex)).Get( value );
360 DALI_TEST_CHECK( value >= 2.f );
362 Wait(application, 100); // 0.3s
363 (effect.GetProperty(propertyIndex)).Get( value );
364 DALI_TEST_CHECK( value >= 3.f );
366 Wait(application, 100); // 0.4s
367 (effect.GetProperty(propertyIndex)).Get( value );
368 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
372 int UtcDaliBubbleEmitterRestore(void)
374 ToolkitTestApplication application;
375 tet_infoline( " UtcDaliBubbleEmitterRestore " );
377 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
378 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
379 Actor root = emitter.GetRootActor();
380 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
381 ShaderEffect effect = bubbleMesh.GetShaderEffect();
382 DALI_TEST_CHECK( effect );
384 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
387 Animation animation = Animation::New( 0.5f );
388 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
389 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
390 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
393 Wait(application, 200);
396 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
397 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
400 application.SendNotification();
401 application.Render();
403 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
404 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );