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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
28 using namespace Dali::Toolkit;
32 const int RENDER_FRAME_INTERVAL = 16;
34 static bool gObjectCreatedCallBackCalled;
35 static void TestCallback(BaseHandle handle)
37 gObjectCreatedCallBackCalled = true;
41 * Simulate time passed by.
43 * @note this will always process at least 1 frame (1/60 sec)
45 * @param application Test application instance
46 * @param duration Time to pass in milliseconds.
47 * @return The actual time passed in milliseconds
49 int Wait(ToolkitTestApplication& application, int duration = 0)
53 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
55 application.SendNotification();
56 application.Render(RENDER_FRAME_INTERVAL);
57 time += RENDER_FRAME_INTERVAL;
63 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
65 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
68 PixelBuffer* pixbuf = imageData.GetBuffer();
69 unsigned int size = width * height;
71 for( size_t i = 0; i < size; i++ )
73 pixbuf[i*4+0] = 0xFF * color.r;
74 pixbuf[i*4+1] = 0xFF * color.g;
75 pixbuf[i*4+2] = 0xFF * color.b;
76 pixbuf[i*4+3] = 0xFF * color.a;
80 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
81 application.SendNotification();
82 application.Render(RENDER_FRAME_INTERVAL);
83 application.Render(RENDER_FRAME_INTERVAL);
84 application.SendNotification();
90 static void Startup();
91 static void Cleanup();
94 void (*tet_startup)() = Startup;
95 void (*tet_cleanup)() = Cleanup;
99 POSITIVE_TC_IDX = 0x01,
103 #define MAX_NUMBER_OF_TESTS 10000
105 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
108 // Add test functionality for all APIs in the class (Positive and Negative)
109 TEST_FUNCTION( UtcDaliBubbleEmitterNew, POSITIVE_TC_IDX );
110 TEST_FUNCTION( UtcDaliBubbleEmitterGetRootActor, POSITIVE_TC_IDX );
111 TEST_FUNCTION( UtcDaliBubbleEmitterSetBackground, POSITIVE_TC_IDX );
112 TEST_FUNCTION( UtcDaliBubbleEmitterSetShapeImage, POSITIVE_TC_IDX );
113 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleScale, POSITIVE_TC_IDX );
114 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleDensity01, POSITIVE_TC_IDX );
115 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleDensity02, POSITIVE_TC_IDX );
116 TEST_FUNCTION( UtcDaliBubbleEmitterSetBlendMode, POSITIVE_TC_IDX );
117 TEST_FUNCTION( UtcDaliBubbleEmitterEmitBubble, POSITIVE_TC_IDX );
118 TEST_FUNCTION( UtcDaliBubbleEmitterStartExplosion, POSITIVE_TC_IDX );
119 TEST_FUNCTION( UtcDaliBubbleEmitterRestore, POSITIVE_TC_IDX );
121 // Called only once before first test is run.
122 static void Startup()
126 // Called only once after last test is run
127 static void Cleanup()
131 static void UtcDaliBubbleEmitterNew()
133 ToolkitTestApplication application;
135 tet_infoline(" UtcDaliBubbleEmitterNew ");
137 // Test default constructor
138 BubbleEmitter emitter;
139 DALI_TEST_CHECK( !emitter );
141 // Test object creation
142 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
143 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
144 DALI_TEST_CHECK( emitter );
146 // Additional check to ensure object is created by checking if it's registered
147 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
148 DALI_TEST_CHECK( registry );
149 gObjectCreatedCallBackCalled = false;
150 registry.ObjectCreatedSignal().Connect( &TestCallback );
152 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
154 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
156 // Test copy constructor
157 BubbleEmitter emitterCopy( emitter );
158 DALI_TEST_CHECK( emitterCopy );
161 Handle handleEmitter;
162 handleEmitter = emitter;
163 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
164 DALI_TEST_CHECK( downCastEmitter );
167 static void UtcDaliBubbleEmitterGetRootActor()
169 ToolkitTestApplication application;
170 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
172 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
173 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
175 Actor root = emitter.GetRootActor();
176 DALI_TEST_CHECK( root );
177 DALI_TEST_CHECK( root.GetChildCount() == 3 );
180 static void UtcDaliBubbleEmitterSetBackground()
182 ToolkitTestApplication application;
183 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
185 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
186 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
188 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
189 unsigned int taskCount = taskList.GetTaskCount();
191 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
192 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
194 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
196 Wait(application, 500);
197 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
200 static void UtcDaliBubbleEmitterSetShapeImage()
202 ToolkitTestApplication application;
203 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
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 Material material = bubbleMesh.GetMaterial();
212 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
214 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
215 emitter.SetShapeImage( shapeImage2 );
217 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
220 static void UtcDaliBubbleEmitterSetBubbleScale()
222 ToolkitTestApplication application;
223 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
225 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
226 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
228 Actor root = emitter.GetRootActor();
229 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
230 ShaderEffect effect = bubbleMesh.GetShaderEffect();
231 DALI_TEST_CHECK( effect );
233 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
235 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
236 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
238 emitter.SetBubbleScale( 2.f );
239 application.SendNotification();
240 application.Render();
241 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
242 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
244 emitter.SetBubbleScale( 0.5f );
245 application.SendNotification();
246 application.Render();
247 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
248 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
251 static void UtcDaliBubbleEmitterSetBubbleDensity01()
253 ToolkitTestApplication application;
254 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
256 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
257 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
261 emitter.SetBubbleDensity( 3.f );
262 DALI_TEST_CHECK(true);
264 catch(Dali::DaliException& e)
266 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
267 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
271 static void UtcDaliBubbleEmitterSetBubbleDensity02()
273 ToolkitTestApplication application;
274 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
276 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
277 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
281 emitter.SetBubbleDensity( 10.f );
283 catch(Dali::DaliException& e)
285 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
286 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
290 static void UtcDaliBubbleEmitterSetBlendMode()
292 ToolkitTestApplication application;
293 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
295 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
296 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
298 Actor root = emitter.GetRootActor();
299 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
301 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
303 emitter.SetBlendMode( true );
304 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
305 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
306 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
307 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
308 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
310 emitter.SetBlendMode( false );
311 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
312 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
313 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
314 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
315 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
318 static void UtcDaliBubbleEmitterEmitBubble()
320 ToolkitTestApplication application;
321 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
323 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
324 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
326 Actor root = emitter.GetRootActor();
327 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
328 ShaderEffect effect = bubbleMesh.GetShaderEffect();
329 DALI_TEST_CHECK( effect );
331 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
332 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
333 float value0, value1;
335 Animation animation = Animation::New( 0.5f );
336 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
337 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
338 (effect.GetProperty(propertyIndex0)).Get( value0 );
339 (effect.GetProperty(propertyIndex1)).Get( value1 );
340 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
341 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
345 Wait(application, 300);
346 (effect.GetProperty(propertyIndex0)).Get( value0 );
347 (effect.GetProperty(propertyIndex1)).Get( value1 );
348 DALI_TEST_CHECK( value0 >= 0.6f );
349 DALI_TEST_CHECK( value1 >= 0.6f );
351 Wait(application, 600);
352 (effect.GetProperty(propertyIndex0)).Get( value0 );
353 (effect.GetProperty(propertyIndex1)).Get( value1 );
354 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
355 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
358 static void UtcDaliBubbleEmitterStartExplosion()
360 ToolkitTestApplication application;
361 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
363 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
364 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
365 Actor root = emitter.GetRootActor();
366 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
367 ShaderEffect effect = bubbleMesh.GetShaderEffect();
368 DALI_TEST_CHECK( effect );
370 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
372 (effect.GetProperty(propertyIndex)).Get( value );
373 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
375 emitter.StartExplosion( 0.4, 4.f );
377 Wait(application, 200); // 0.2s
378 (effect.GetProperty(propertyIndex)).Get( value );
379 DALI_TEST_CHECK( value >= 2.f );
381 Wait(application, 100); // 0.3s
382 (effect.GetProperty(propertyIndex)).Get( value );
383 DALI_TEST_CHECK( value >= 3.f );
385 Wait(application, 100); // 0.4s
386 (effect.GetProperty(propertyIndex)).Get( value );
387 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
390 static void UtcDaliBubbleEmitterRestore()
392 ToolkitTestApplication application;
393 tet_infoline( " UtcDaliBubbleEmitterRestore " );
395 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
396 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
397 Actor root = emitter.GetRootActor();
398 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
399 ShaderEffect effect = bubbleMesh.GetShaderEffect();
400 DALI_TEST_CHECK( effect );
402 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
405 Animation animation = Animation::New( 0.5f );
406 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
407 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
408 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
411 Wait(application, 200);
414 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
415 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
418 application.SendNotification();
419 application.Render();
421 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
422 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );