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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Dali::Toolkit;
33 const int RENDER_FRAME_INTERVAL = 16;
35 static bool gObjectCreatedCallBackCalled;
36 static void TestCallback(BaseHandle handle)
38 gObjectCreatedCallBackCalled = true;
42 * Simulate time passed by.
44 * @note this will always process at least 1 frame (1/60 sec)
46 * @param application Test application instance
47 * @param duration Time to pass in milliseconds.
48 * @return The actual time passed in milliseconds
50 int Wait(ToolkitTestApplication& application, int duration = 0)
54 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
56 application.SendNotification();
57 application.Render(RENDER_FRAME_INTERVAL);
58 time += RENDER_FRAME_INTERVAL;
64 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
66 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
69 PixelBuffer* pixbuf = imageData.GetBuffer();
70 unsigned int size = width * height;
72 for( size_t i = 0; i < size; i++ )
74 pixbuf[i*4+0] = 0xFF * color.r;
75 pixbuf[i*4+1] = 0xFF * color.g;
76 pixbuf[i*4+2] = 0xFF * color.b;
77 pixbuf[i*4+3] = 0xFF * color.a;
81 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
82 application.SendNotification();
83 application.Render(RENDER_FRAME_INTERVAL);
84 application.Render(RENDER_FRAME_INTERVAL);
85 application.SendNotification();
91 static void Startup();
92 static void Cleanup();
95 void (*tet_startup)() = Startup;
96 void (*tet_cleanup)() = Cleanup;
100 POSITIVE_TC_IDX = 0x01,
104 #define MAX_NUMBER_OF_TESTS 10000
106 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
109 // Add test functionality for all APIs in the class (Positive and Negative)
110 TEST_FUNCTION( UtcDaliBubbleEmitterNew, POSITIVE_TC_IDX );
111 TEST_FUNCTION( UtcDaliBubbleEmitterGetRootActor, POSITIVE_TC_IDX );
112 TEST_FUNCTION( UtcDaliBubbleEmitterSetBackground, POSITIVE_TC_IDX );
113 TEST_FUNCTION( UtcDaliBubbleEmitterSetShapeImage, POSITIVE_TC_IDX );
114 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleScale, POSITIVE_TC_IDX );
115 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleDensity01, POSITIVE_TC_IDX );
116 TEST_FUNCTION( UtcDaliBubbleEmitterSetBubbleDensity02, POSITIVE_TC_IDX );
117 TEST_FUNCTION( UtcDaliBubbleEmitterSetBlendMode, POSITIVE_TC_IDX );
118 TEST_FUNCTION( UtcDaliBubbleEmitterEmitBubble, POSITIVE_TC_IDX );
119 TEST_FUNCTION( UtcDaliBubbleEmitterStartExplosion, POSITIVE_TC_IDX );
120 TEST_FUNCTION( UtcDaliBubbleEmitterRestore, POSITIVE_TC_IDX );
122 // Called only once before first test is run.
123 static void Startup()
127 // Called only once after last test is run
128 static void Cleanup()
132 static void UtcDaliBubbleEmitterNew()
134 ToolkitTestApplication application;
136 tet_infoline(" UtcDaliBubbleEmitterNew ");
138 // Test default constructor
139 BubbleEmitter emitter;
140 DALI_TEST_CHECK( !emitter );
142 // Test object creation
143 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
144 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
145 DALI_TEST_CHECK( emitter );
147 // Additional check to ensure object is created by checking if it's registered
148 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
149 DALI_TEST_CHECK( registry );
150 gObjectCreatedCallBackCalled = false;
151 registry.ObjectCreatedSignal().Connect( &TestCallback );
153 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
155 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
157 // Test copy constructor
158 BubbleEmitter emitterCopy( emitter );
159 DALI_TEST_CHECK( emitterCopy );
162 Handle handleEmitter;
163 handleEmitter = emitter;
164 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
165 DALI_TEST_CHECK( downCastEmitter );
168 static void UtcDaliBubbleEmitterGetRootActor()
170 ToolkitTestApplication application;
171 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
173 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
174 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
176 Actor root = emitter.GetRootActor();
177 DALI_TEST_CHECK( root );
178 DALI_TEST_CHECK( root.GetChildCount() == 3 );
181 static void UtcDaliBubbleEmitterSetBackground()
183 ToolkitTestApplication application;
184 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
186 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
187 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
189 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
190 unsigned int taskCount = taskList.GetTaskCount();
192 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
193 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
195 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
197 Wait(application, 500);
198 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
201 static void UtcDaliBubbleEmitterSetShapeImage()
203 ToolkitTestApplication application;
204 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
206 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
207 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
209 Actor root = emitter.GetRootActor();
210 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
211 Material material = bubbleMesh.GetMaterial();
213 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
215 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
216 emitter.SetShapeImage( shapeImage2 );
218 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
221 static void UtcDaliBubbleEmitterSetBubbleScale()
223 ToolkitTestApplication application;
224 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
226 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
227 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
229 Actor root = emitter.GetRootActor();
230 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
231 ShaderEffect effect = bubbleMesh.GetShaderEffect();
232 DALI_TEST_CHECK( effect );
234 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
236 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
237 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
239 emitter.SetBubbleScale( 2.f );
240 application.SendNotification();
241 application.Render();
242 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
243 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
245 emitter.SetBubbleScale( 0.5f );
246 application.SendNotification();
247 application.Render();
248 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
249 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
252 static void UtcDaliBubbleEmitterSetBubbleDensity01()
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( 3.f );
263 DALI_TEST_CHECK(true);
265 catch(Dali::DaliException& e)
267 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
268 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
272 static void UtcDaliBubbleEmitterSetBubbleDensity02()
274 ToolkitTestApplication application;
275 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
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 ));
282 emitter.SetBubbleDensity( 10.f );
284 catch(Dali::DaliException& e)
286 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
287 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
291 static void UtcDaliBubbleEmitterSetBlendMode()
293 ToolkitTestApplication application;
294 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
296 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
297 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
299 Actor root = emitter.GetRootActor();
300 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
302 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
304 emitter.SetBlendMode( true );
305 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
306 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
307 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
308 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
309 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
311 emitter.SetBlendMode( false );
312 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
313 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
314 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
315 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
316 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
319 static void UtcDaliBubbleEmitterEmitBubble()
321 ToolkitTestApplication application;
322 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
324 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
325 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
327 Actor root = emitter.GetRootActor();
328 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
329 ShaderEffect effect = bubbleMesh.GetShaderEffect();
330 DALI_TEST_CHECK( effect );
332 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
333 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
334 float value0, value1;
336 Animation animation = Animation::New( 0.5f );
337 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
338 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
339 (effect.GetProperty(propertyIndex0)).Get( value0 );
340 (effect.GetProperty(propertyIndex1)).Get( value1 );
341 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
342 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
346 Wait(application, 300);
347 (effect.GetProperty(propertyIndex0)).Get( value0 );
348 (effect.GetProperty(propertyIndex1)).Get( value1 );
349 DALI_TEST_CHECK( value0 >= 0.6f );
350 DALI_TEST_CHECK( value1 >= 0.6f );
352 Wait(application, 600);
353 (effect.GetProperty(propertyIndex0)).Get( value0 );
354 (effect.GetProperty(propertyIndex1)).Get( value1 );
355 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
356 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
359 static void UtcDaliBubbleEmitterStartExplosion()
361 ToolkitTestApplication application;
362 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
364 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
365 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
366 Actor root = emitter.GetRootActor();
367 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
368 ShaderEffect effect = bubbleMesh.GetShaderEffect();
369 DALI_TEST_CHECK( effect );
371 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
373 (effect.GetProperty(propertyIndex)).Get( value );
374 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
376 emitter.StartExplosion( 0.4, 4.f );
378 Wait(application, 200); // 0.2s
379 (effect.GetProperty(propertyIndex)).Get( value );
380 DALI_TEST_CHECK( value >= 2.f );
382 Wait(application, 100); // 0.3s
383 (effect.GetProperty(propertyIndex)).Get( value );
384 DALI_TEST_CHECK( value >= 3.f );
386 Wait(application, 100); // 0.4s
387 (effect.GetProperty(propertyIndex)).Get( value );
388 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
391 static void UtcDaliBubbleEmitterRestore()
393 ToolkitTestApplication application;
394 tet_infoline( " UtcDaliBubbleEmitterRestore " );
396 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
397 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
398 Actor root = emitter.GetRootActor();
399 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
400 ShaderEffect effect = bubbleMesh.GetShaderEffect();
401 DALI_TEST_CHECK( effect );
403 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
406 Animation animation = Animation::New( 0.5f );
407 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
408 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
409 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
412 Wait(application, 200);
415 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
416 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
419 application.SendNotification();
420 application.Render();
422 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
423 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );