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 #include <dali/dali.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali-test-suite-utils.h>
28 void renderable_actor_startup(void)
30 test_return_value = TET_UNDEF;
33 void renderable_actor_cleanup(void)
35 test_return_value = TET_PASS;
41 static const char* TestTextHelloWorld = "Hello World";
42 static bool gIsActor1SortModifierCorrect;
43 static bool gIsActor2SortModifierCorrect;
44 const float gActor1SortModifierValue = 96.0f;
45 const float gActor2SortModifierValue = 53.0f;
47 static float TestSortFunction(const Vector3& position, float sortModifier)
49 if ( fabs(sortModifier - gActor1SortModifierValue) < 0.01)
50 gIsActor1SortModifierCorrect = true;
52 if ( fabs(sortModifier - gActor2SortModifierValue) < 0.01)
53 gIsActor2SortModifierCorrect = true;
60 int UtcDaliRenderableActorDownCast(void)
62 TestApplication application;
64 tet_infoline("Testing Dali::RenderableActor::DownCast()");
66 TextActor textActor = TextActor::New(TestTextHelloWorld);
68 Actor anActor = Actor::New();
69 anActor.Add( textActor );
71 Actor child = anActor.GetChildAt(0);
72 RenderableActor renderableActor = RenderableActor::DownCast( child );
73 DALI_TEST_CHECK( renderableActor );
75 renderableActor = NULL;
76 DALI_TEST_CHECK( !renderableActor );
78 renderableActor = DownCast< RenderableActor >( child );
79 DALI_TEST_CHECK( renderableActor );
81 renderableActor = DownCast< RenderableActor >( anActor );
82 DALI_TEST_CHECK( !renderableActor );
84 Actor unInitialzedActor;
85 renderableActor = RenderableActor::DownCast( unInitialzedActor );
86 DALI_TEST_CHECK( !renderableActor );
88 renderableActor = DownCast< RenderableActor >( unInitialzedActor );
89 DALI_TEST_CHECK( !renderableActor );
93 int UtcDaliRenderableActorSetSortModifier(void)
95 TestApplication application;
97 tet_infoline("Testing Dali::RenderableActor::SetSortModifier()");
101 TextActor actor = TextActor::New(TestTextHelloWorld);
102 Stage::GetCurrent().Add(actor);
104 actor.SetSortModifier( val );
106 float returnValue = actor.GetSortModifier();
108 //Verify through actor api
109 DALI_TEST_EQUALS(returnValue, val, TEST_LOCATION);
111 Stage::GetCurrent().Remove(actor);
114 //Verify through layer SetSortFunction
115 gIsActor1SortModifierCorrect = false;
116 gIsActor2SortModifierCorrect = false;
117 BitmapImage img = BitmapImage::New( 1,1 );
118 // create two transparent actors so there is something to sort
119 ImageActor actor1 = ImageActor::New( img );
120 ImageActor actor2 = ImageActor::New( img );
122 actor1.SetPosition( 0, 0, 0);
123 actor1.SetSortModifier( gActor1SortModifierValue );
124 actor1.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
126 actor2.SetPosition( 0, 0, 1);
127 actor2.SetSortModifier( gActor2SortModifierValue );
128 actor2.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
131 Stage::GetCurrent().Add( actor1 );
132 Stage::GetCurrent().Add( actor2 );
134 Layer root = Stage::GetCurrent().GetLayer( 0 );
135 root.SetSortFunction( TestSortFunction );
137 // flush the queue and render once
138 application.SendNotification();
139 application.Render();
141 DALI_TEST_CHECK( gIsActor1SortModifierCorrect && gIsActor2SortModifierCorrect );
146 int UtcDaliRenderableActorGetSortModifier(void)
148 TestApplication application;
150 tet_infoline("Testing Dali::RenderableActor::GetSortModifier()");
152 TextActor actor = TextActor::New(TestTextHelloWorld);
153 Stage::GetCurrent().Add(actor);
155 DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION);
157 Stage::GetCurrent().Remove(actor);
161 int UtcDaliRenderableActorSetGetBlendMode(void)
163 TestApplication application;
165 tet_infoline("Testing Dali::RenderableActor::SetBlendMode() / Dali::RenderableActor::GetBlendMode()");
167 TextActor actor = TextActor::New(TestTextHelloWorld);
169 actor.SetBlendMode( BlendingMode::OFF );
170 DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() );
172 actor.SetBlendMode( BlendingMode::AUTO );
173 DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() );
175 actor.SetBlendMode( BlendingMode::ON );
176 DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() );
180 int UtcDaliRenderableActorSetCullFace(void)
182 TestApplication application;
184 tet_infoline("Testing Dali::RenderableActor::SetCullFace()");
186 BitmapImage img = BitmapImage::New( 1,1 );
187 ImageActor actor = ImageActor::New( img );
188 ImageActor actor2 = ImageActor::New( img );
190 actor.SetSize(100.0f, 100.0f);
191 actor.SetParentOrigin(ParentOrigin::CENTER);
192 actor.SetAnchorPoint(AnchorPoint::CENTER);
194 actor2.SetSize(100.0f, 100.0f);
195 actor2.SetParentOrigin(ParentOrigin::CENTER);
196 actor2.SetAnchorPoint(AnchorPoint::CENTER);
198 Stage::GetCurrent().Add(actor);
199 Stage::GetCurrent().Add(actor2);
201 //Verify whether the correct GL calls are made when actor is face culled in front and back, and
202 // face culling is disabled for actor2
203 TraceCallStack& cullFaceTrace = application.GetGlAbstraction().GetCullFaceTrace();
204 cullFaceTrace.Enable(true);
205 actor.SetCullFace( CullFrontAndBack );
207 // flush the queue and render once
208 application.SendNotification();
209 application.Render();
211 cullFaceTrace.Enable(false);
212 std::stringstream out;
214 //Verify actor gl state
217 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Enable", out.str()), true, TEST_LOCATION);
221 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(1, "Enable", out.str()), true, TEST_LOCATION);
224 out << GL_FRONT_AND_BACK;
225 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(2, "CullFace", out.str()), true, TEST_LOCATION);
227 //Verify actor2 gl state
230 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(3, "Disable", out.str()), true, TEST_LOCATION);
232 //Verify state through the actor api
233 DALI_TEST_CHECK( CullFrontAndBack == actor.GetCullFace() );
234 DALI_TEST_CHECK( CullNone == actor2.GetCullFace() );
236 /**************************************************************/
238 //Verify whether the correct GL calls are made when actor2 is face culled in the front
239 cullFaceTrace.Reset();
240 cullFaceTrace.Enable(true);
241 actor2.SetCullFace( CullFront );
243 // flush the queue and render once
244 application.SendNotification();
245 application.Render();
247 cullFaceTrace.Enable(false);
249 //Verify actor gl state
252 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Enable", out.str()), true, TEST_LOCATION);
255 out << GL_FRONT_AND_BACK;
256 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(1, "CullFace", out.str()), true, TEST_LOCATION);
258 //Verify actor2 gl state
261 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(2, "Enable", out.str()), true, TEST_LOCATION);
265 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(3, "CullFace", out.str()), true, TEST_LOCATION);
267 //Verify state through the actor api
268 DALI_TEST_CHECK( CullFrontAndBack == actor.GetCullFace() );
269 DALI_TEST_CHECK( CullFront == actor2.GetCullFace() );
271 /**************************************************************/
272 //Verify whether the correct GL calls are made when face culling is disabled for both actors
273 cullFaceTrace.Reset();
274 cullFaceTrace.Enable(true);
275 actor.SetCullFace( CullNone );
276 actor2.SetCullFace( CullNone );
278 // flush the queue and render once
279 application.SendNotification();
280 application.Render();
282 cullFaceTrace.Enable(false);
286 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Disable", out.str()), true, TEST_LOCATION);
288 //Verify state through the actor api
289 DALI_TEST_CHECK( CullNone == actor.GetCullFace() );
290 DALI_TEST_CHECK( CullNone == actor2.GetCullFace() );
292 Stage::GetCurrent().Remove(actor);
293 Stage::GetCurrent().Remove(actor2);
297 int UtcDaliRenderableActorGetCullFace(void)
299 TestApplication application;
301 tet_infoline("Testing Dali::RenderableActor::GetCullFace()");
303 TextActor textActor = TextActor::New(TestTextHelloWorld);
305 DALI_TEST_CHECK( CullNone == textActor.GetCullFace() );
307 ImageActor imageActor = ImageActor::New();
309 DALI_TEST_CHECK( CullNone == imageActor.GetCullFace() );
311 MeshActor meshActor = MeshActor::New();
313 DALI_TEST_CHECK( CullBack == meshActor.GetCullFace() );
317 int UtcDaliRenderableActorSetGetBlendFunc(void)
319 TestApplication application;
320 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
322 tet_infoline("Testing Dali::RenderableActor::UtcDaliRenderableActorSetGetBlendFunc()");
324 BitmapImage img = BitmapImage::New( 1,1 );
325 ImageActor actor = ImageActor::New( img );
326 Stage::GetCurrent().Add( actor );
327 application.SendNotification();
328 application.Render();
330 // Test the defaults as documented int blending.h
332 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
333 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
334 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
335 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
336 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
337 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
338 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
339 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
340 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
343 // Set to non-default values
344 actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
346 // Test that Set was successful
348 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
349 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
350 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
351 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
352 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
353 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
354 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
355 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
356 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
359 // Render & check GL commands
360 application.SendNotification();
361 application.Render();
362 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
363 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
364 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
365 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
367 // Set using separate alpha settings
368 actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
369 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
371 // Test that Set was successful
373 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
374 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
375 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
376 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
377 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
378 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
379 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
380 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
381 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
384 // Render & check GL commands
385 application.SendNotification();
386 application.Render();
387 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
388 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
389 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
390 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
394 int UtcDaliRenderableActorSetGetBlendEquation(void)
396 TestApplication application;
397 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
399 tet_infoline("Testing Dali::RenderableActor::SetBlendEquation()");
401 BitmapImage img = BitmapImage::New( 1,1 );
402 ImageActor actor = ImageActor::New( img );
403 Stage::GetCurrent().Add( actor );
404 application.SendNotification();
405 application.Render();
407 // Test the defaults as documented int blending.h
409 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
410 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
411 actor.GetBlendEquation( equationRgb, equationAlpha );
412 DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
413 DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
416 // Test the single blending equation setting
418 actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
419 BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
420 actor.GetBlendEquation( equationRgba, equationRgba );
421 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
424 actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
426 // Test that Set was successful
428 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
429 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
430 actor.GetBlendEquation( equationRgb, equationAlpha );
431 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
432 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
435 // Render & check GL commands
436 application.SendNotification();
437 application.Render();
438 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
439 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
443 int UtcDaliRenderableActorSetGetBlendColor(void)
445 TestApplication application;
446 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
448 tet_infoline("Testing Dali::RenderableActor::SetBlendColor()");
450 BitmapImage img = BitmapImage::New( 1,1 );
451 ImageActor actor = ImageActor::New( img );
452 Stage::GetCurrent().Add( actor );
453 application.SendNotification();
454 application.Render();
456 // Test the defaults as documented int blending.h
457 DALI_TEST_EQUALS( Vector4::ZERO, actor.GetBlendColor(), TEST_LOCATION );
459 actor.SetBlendColor( Color::RED );
461 // Test that Set was successful
462 DALI_TEST_EQUALS( Color::RED, actor.GetBlendColor(), TEST_LOCATION );
464 // Render & check GL commands
465 application.SendNotification();
466 application.Render();
467 DALI_TEST_EQUALS( Color::RED, glAbstraction.GetLastBlendColor(), TEST_LOCATION );
471 int UtcDaliRenderableActorSetGetAlpha(void)
473 TestApplication application;
475 tet_infoline("Testing Dali::RenderableActor::SetGetAlpha()");
477 BitmapImage img = BitmapImage::New( 1,1 );
478 ImageActor actor = ImageActor::New( img );
479 Stage::GetCurrent().Add( actor );
480 application.SendNotification();
481 application.Render();
483 // use the image alpha on actor
484 actor.SetBlendMode(BlendingMode::ON);
486 // Test that Set was successful
487 DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION );
489 // Now test that it can be set to false
490 actor.SetBlendMode(BlendingMode::OFF);
491 DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION );
495 int UtcDaliRenderableActorCreateDestroy(void)
497 tet_infoline("Testing Dali::RenderableActor::CreateDestroy()");
498 RenderableActor* ractor = new RenderableActor;
499 RenderableActor ractor2( *ractor );
500 DALI_TEST_CHECK( ractor );