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>
29 using namespace Dali::Toolkit;
31 void utc_dali_toolkit_bubble_emitter_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_bubble_emitter_cleanup(void)
38 test_return_value = TET_PASS;
45 const int RENDER_FRAME_INTERVAL = 16;
47 static bool gObjectCreatedCallBackCalled;
48 static void TestCallback(BaseHandle handle)
50 gObjectCreatedCallBackCalled = true;
54 * Simulate time passed by.
56 * @note this will always process at least 1 frame (1/60 sec)
58 * @param application Test application instance
59 * @param duration Time to pass in milliseconds.
60 * @return The actual time passed in milliseconds
62 static int Wait(ToolkitTestApplication& application, int duration = 0)
66 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
68 application.SendNotification();
69 application.Render(RENDER_FRAME_INTERVAL);
70 time += RENDER_FRAME_INTERVAL;
76 static Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
78 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
81 PixelBuffer* pixbuf = imageData.GetBuffer();
82 unsigned int size = width * height;
84 for( size_t i = 0; i < size; i++ )
86 pixbuf[i*4+0] = 0xFF * color.r;
87 pixbuf[i*4+1] = 0xFF * color.g;
88 pixbuf[i*4+2] = 0xFF * color.b;
89 pixbuf[i*4+3] = 0xFF * color.a;
93 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
94 application.SendNotification();
95 application.Render(RENDER_FRAME_INTERVAL);
96 application.Render(RENDER_FRAME_INTERVAL);
97 application.SendNotification();
104 int UtcDaliBubbleEmitterNew(void)
106 ToolkitTestApplication application;
108 tet_infoline(" UtcDaliBubbleEmitterNew ");
110 // Test default constructor
111 BubbleEmitter emitter;
112 DALI_TEST_CHECK( !emitter );
114 // Test object creation
115 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
116 emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
117 DALI_TEST_CHECK( emitter );
119 // Additional check to ensure object is created by checking if it's registered
120 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
121 DALI_TEST_CHECK( registry );
122 gObjectCreatedCallBackCalled = false;
123 registry.ObjectCreatedSignal().Connect( &TestCallback );
125 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
127 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129 // Test copy constructor
130 BubbleEmitter emitterCopy( emitter );
131 DALI_TEST_CHECK( emitterCopy );
134 Handle handleEmitter;
135 handleEmitter = emitter;
136 BubbleEmitter downCastEmitter = BubbleEmitter::DownCast( handleEmitter );
137 DALI_TEST_CHECK( downCastEmitter );
141 int UtcDaliBubbleEmitterGetRootActor(void)
143 ToolkitTestApplication application;
144 tet_infoline( " UtcDaliBubbleEmitterGetRootActor " );
146 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
147 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
149 Actor root = emitter.GetRootActor();
150 DALI_TEST_CHECK( root );
151 DALI_TEST_CHECK( root.GetChildCount() == 3 );
155 int UtcDaliBubbleEmitterSetBackground(void)
157 ToolkitTestApplication application;
158 tet_infoline( " UtcDaliBubbleEmitterSetBackground " );
160 Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
161 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 200, Vector2( 5.f, 10.f ));
163 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
164 unsigned int taskCount = taskList.GetTaskCount();
166 Image bgImage = CreateSolidColorImage( application, Color::RED, 50, 50 );
167 emitter.SetBackground( bgImage, Vector3(0.f, 0.f, 0.5f) );
169 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount+1 );
171 Wait(application, 500);
172 DALI_TEST_CHECK( taskList.GetTaskCount() == taskCount );
176 int UtcDaliBubbleEmitterSetShapeImage(void)
178 ToolkitTestApplication application;
179 tet_infoline( " UtcDaliBubbleEmitterSetShapeImage " );
181 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
182 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
184 Actor root = emitter.GetRootActor();
185 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
186 Material material = bubbleMesh.GetMaterial();
188 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage1 );
190 Image shapeImage2 = CreateSolidColorImage( application, Color::RED, 8, 8 );
191 emitter.SetShapeImage( shapeImage2 );
193 DALI_TEST_CHECK( material.GetDiffuseTexture() == shapeImage2 );
197 int UtcDaliBubbleEmitterSetBubbleScale(void)
199 ToolkitTestApplication application;
200 tet_infoline( " UtcDaliBubbleEmitterSetBubbleScale " );
202 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
203 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
205 Actor root = emitter.GetRootActor();
206 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
207 ShaderEffect effect = bubbleMesh.GetShaderEffect();
208 DALI_TEST_CHECK( effect );
210 Property::Index scalePropertyIndex = effect.GetPropertyIndex( "uDynamicScale" );
212 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
213 DALI_TEST_EQUALS(scaleValue, 1.f, TEST_LOCATION );
215 emitter.SetBubbleScale( 2.f );
216 application.SendNotification();
217 application.Render();
218 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
219 DALI_TEST_EQUALS(scaleValue, 2.f, TEST_LOCATION );
221 emitter.SetBubbleScale( 0.5f );
222 application.SendNotification();
223 application.Render();
224 (effect.GetProperty(scalePropertyIndex)).Get( scaleValue );
225 DALI_TEST_EQUALS(scaleValue, 0.5f, TEST_LOCATION );
229 int UtcDaliBubbleEmitterSetBubbleDensity01(void)
231 ToolkitTestApplication application;
232 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
234 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
235 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
239 emitter.SetBubbleDensity( 3.f );
240 DALI_TEST_CHECK(true);
242 catch(Dali::DaliException& e)
244 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
245 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
250 int UtcDaliBubbleEmitterSetBubbleDensity02(void)
252 ToolkitTestApplication application;
253 tet_infoline( " UtcDaliBubbleEmitterSetBubbleDensity " );
255 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
256 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
260 emitter.SetBubbleDensity( 10.f );
262 catch(Dali::DaliException& e)
264 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
265 DALI_TEST_ASSERT(e, "density>0 && density<=9", TEST_LOCATION );
270 int UtcDaliBubbleEmitterSetBlendMode(void)
272 ToolkitTestApplication application;
273 tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " );
275 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
276 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
278 Actor root = emitter.GetRootActor();
279 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
281 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
283 emitter.SetBlendMode( true );
284 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
285 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
286 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE );
287 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ZERO );
288 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
290 emitter.SetBlendMode( false );
291 bubbleMesh.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
292 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
293 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
294 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
295 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
299 int UtcDaliBubbleEmitterEmitBubble(void)
301 ToolkitTestApplication application;
302 tet_infoline( " UtcDaliBubbleEmitterEmitBubble " );
304 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
305 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
307 Actor root = emitter.GetRootActor();
308 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
309 ShaderEffect effect = bubbleMesh.GetShaderEffect();
310 DALI_TEST_CHECK( effect );
312 Property::Index propertyIndex0 = effect.GetPropertyIndex( "uPercentage[0]" );
313 Property::Index propertyIndex1 = effect.GetPropertyIndex( "uPercentage[1]" );
314 float value0, value1;
316 Animation animation = Animation::New( 0.5f );
317 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
318 emitter.EmitBubble( animation, Vector2(10.f,10.f), Vector2(5.f,5.f), Vector2(30.f,30.f) );
319 (effect.GetProperty(propertyIndex0)).Get( value0 );
320 (effect.GetProperty(propertyIndex1)).Get( value1 );
321 DALI_TEST_EQUALS(value0, 0.f, TEST_LOCATION );
322 DALI_TEST_EQUALS(value1, 0.f, TEST_LOCATION );
326 Wait(application, 300);
327 (effect.GetProperty(propertyIndex0)).Get( value0 );
328 (effect.GetProperty(propertyIndex1)).Get( value1 );
329 DALI_TEST_CHECK( value0 >= 0.6f );
330 DALI_TEST_CHECK( value1 >= 0.6f );
332 Wait(application, 600);
333 (effect.GetProperty(propertyIndex0)).Get( value0 );
334 (effect.GetProperty(propertyIndex1)).Get( value1 );
335 DALI_TEST_EQUALS(value0, 1.f, TEST_LOCATION );
336 DALI_TEST_EQUALS(value1, 1.f, TEST_LOCATION );
340 int UtcDaliBubbleEmitterStartExplosion(void)
342 ToolkitTestApplication application;
343 tet_infoline( " UtcDaliBubbleEmitterStartExplosion " );
345 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
346 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
347 Actor root = emitter.GetRootActor();
348 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
349 ShaderEffect effect = bubbleMesh.GetShaderEffect();
350 DALI_TEST_CHECK( effect );
352 Property::Index propertyIndex = effect.GetPropertyIndex( "uMagnification" );
354 (effect.GetProperty(propertyIndex)).Get( value );
355 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
357 emitter.StartExplosion( 0.4, 4.f );
359 Wait(application, 200); // 0.2s
360 (effect.GetProperty(propertyIndex)).Get( value );
361 DALI_TEST_CHECK( value >= 2.f );
363 Wait(application, 100); // 0.3s
364 (effect.GetProperty(propertyIndex)).Get( value );
365 DALI_TEST_CHECK( value >= 3.f );
367 Wait(application, 100); // 0.4s
368 (effect.GetProperty(propertyIndex)).Get( value );
369 DALI_TEST_EQUALS(value, 1.f, TEST_LOCATION );
373 int UtcDaliBubbleEmitterRestore(void)
375 ToolkitTestApplication application;
376 tet_infoline( " UtcDaliBubbleEmitterRestore " );
378 Image shapeImage1 = CreateSolidColorImage( application, Color::GREEN, 5, 5 );
379 BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage1, 200, Vector2( 5.f, 10.f ));
380 Actor root = emitter.GetRootActor();
381 MeshActor bubbleMesh = MeshActor::DownCast( root.GetChildAt( 0 ) );
382 ShaderEffect effect = bubbleMesh.GetShaderEffect();
383 DALI_TEST_CHECK( effect );
385 Property::Index percentagePropertyIndex = effect.GetPropertyIndex( "uPercentage[0]" );
388 Animation animation = Animation::New( 0.5f );
389 emitter.EmitBubble( animation, Vector2(40.f,40.f), Vector2(-5.f,-5.f), Vector2(30.f,30.f) );
390 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
391 DALI_TEST_EQUALS(percentage, 0.f, TEST_LOCATION );
394 Wait(application, 200);
397 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
398 DALI_TEST_CHECK( percentage < 0.5f && percentage >= 0.4);
401 application.SendNotification();
402 application.Render();
404 (effect.GetProperty(percentagePropertyIndex)).Get( percentage );
405 DALI_TEST_EQUALS(percentage, 1.f, TEST_LOCATION );