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 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-test-suite-utils.h>
29 void renderable_actor_startup(void)
31 test_return_value = TET_UNDEF;
34 void renderable_actor_cleanup(void)
36 test_return_value = TET_PASS;
42 static const char* TestTextHelloWorld = "Hello World";
43 static bool gIsActor1SortModifierCorrect;
44 static bool gIsActor2SortModifierCorrect;
45 const float gActor1SortModifierValue = 96.0f;
46 const float gActor2SortModifierValue = 53.0f;
48 static float TestSortFunction(const Vector3& position, float sortModifier)
50 if ( fabs(sortModifier - gActor1SortModifierValue) < 0.01)
51 gIsActor1SortModifierCorrect = true;
53 if ( fabs(sortModifier - gActor2SortModifierValue) < 0.01)
54 gIsActor2SortModifierCorrect = true;
61 int UtcDaliRenderableActorDownCast(void)
63 TestApplication application;
65 tet_infoline("Testing Dali::RenderableActor::DownCast()");
67 TextActor textActor = TextActor::New(TestTextHelloWorld);
69 Actor anActor = Actor::New();
70 anActor.Add( textActor );
72 Actor child = anActor.GetChildAt(0);
73 RenderableActor renderableActor = RenderableActor::DownCast( child );
74 DALI_TEST_CHECK( renderableActor );
76 renderableActor = NULL;
77 DALI_TEST_CHECK( !renderableActor );
79 renderableActor = DownCast< RenderableActor >( child );
80 DALI_TEST_CHECK( renderableActor );
82 renderableActor = DownCast< RenderableActor >( anActor );
83 DALI_TEST_CHECK( !renderableActor );
85 Actor unInitialzedActor;
86 renderableActor = RenderableActor::DownCast( unInitialzedActor );
87 DALI_TEST_CHECK( !renderableActor );
89 renderableActor = DownCast< RenderableActor >( unInitialzedActor );
90 DALI_TEST_CHECK( !renderableActor );
94 int UtcDaliRenderableActorSetSortModifier(void)
96 TestApplication application;
98 tet_infoline("Testing Dali::RenderableActor::SetSortModifier()");
102 TextActor actor = TextActor::New(TestTextHelloWorld);
103 Stage::GetCurrent().Add(actor);
105 actor.SetSortModifier( val );
107 float returnValue = actor.GetSortModifier();
109 //Verify through actor api
110 DALI_TEST_EQUALS(returnValue, val, TEST_LOCATION);
112 Stage::GetCurrent().Remove(actor);
115 //Verify through layer SetSortFunction
116 gIsActor1SortModifierCorrect = false;
117 gIsActor2SortModifierCorrect = false;
118 BitmapImage img = BitmapImage::New( 1,1 );
119 // create two transparent actors so there is something to sort
120 ImageActor actor1 = ImageActor::New( img );
121 ImageActor actor2 = ImageActor::New( img );
123 actor1.SetPosition( 0, 0, 0);
124 actor1.SetSortModifier( gActor1SortModifierValue );
125 actor1.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
127 actor2.SetPosition( 0, 0, 1);
128 actor2.SetSortModifier( gActor2SortModifierValue );
129 actor2.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
132 Stage::GetCurrent().Add( actor1 );
133 Stage::GetCurrent().Add( actor2 );
135 Layer root = Stage::GetCurrent().GetLayer( 0 );
136 root.SetSortFunction( TestSortFunction );
138 // flush the queue and render once
139 application.SendNotification();
140 application.Render();
142 DALI_TEST_CHECK( gIsActor1SortModifierCorrect && gIsActor2SortModifierCorrect );
147 int UtcDaliRenderableActorGetSortModifier(void)
149 TestApplication application;
151 tet_infoline("Testing Dali::RenderableActor::GetSortModifier()");
153 TextActor actor = TextActor::New(TestTextHelloWorld);
154 Stage::GetCurrent().Add(actor);
156 DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION);
158 Stage::GetCurrent().Remove(actor);
162 int UtcDaliRenderableActorSetGetBlendMode(void)
164 TestApplication application;
166 tet_infoline("Testing Dali::RenderableActor::SetBlendMode() / Dali::RenderableActor::GetBlendMode()");
168 TextActor actor = TextActor::New(TestTextHelloWorld);
170 actor.SetBlendMode( BlendingMode::OFF );
171 DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() );
173 actor.SetBlendMode( BlendingMode::AUTO );
174 DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() );
176 actor.SetBlendMode( BlendingMode::ON );
177 DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() );
181 int UtcDaliRenderableActorSetCullFace(void)
183 TestApplication application;
185 tet_infoline("Testing Dali::RenderableActor::SetCullFace()");
187 BitmapImage img = BitmapImage::New( 1,1 );
188 ImageActor actor = ImageActor::New( img );
189 ImageActor actor2 = ImageActor::New( img );
191 actor.SetSize(100.0f, 100.0f);
192 actor.SetParentOrigin(ParentOrigin::CENTER);
193 actor.SetAnchorPoint(AnchorPoint::CENTER);
195 actor2.SetSize(100.0f, 100.0f);
196 actor2.SetParentOrigin(ParentOrigin::CENTER);
197 actor2.SetAnchorPoint(AnchorPoint::CENTER);
199 Stage::GetCurrent().Add(actor);
200 Stage::GetCurrent().Add(actor2);
202 //Verify whether the correct GL calls are made when actor is face culled in front and back, and
203 // face culling is disabled for actor2
204 TraceCallStack& cullFaceTrace = application.GetGlAbstraction().GetCullFaceTrace();
205 cullFaceTrace.Enable(true);
206 actor.SetCullFace( CullFrontAndBack );
208 // flush the queue and render once
209 application.SendNotification();
210 application.Render();
212 cullFaceTrace.Enable(false);
213 std::stringstream out;
215 //Verify actor gl state
218 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Enable", out.str()), true, TEST_LOCATION);
222 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(1, "Enable", out.str()), true, TEST_LOCATION);
225 out << GL_FRONT_AND_BACK;
226 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(2, "CullFace", out.str()), true, TEST_LOCATION);
228 //Verify actor2 gl state
231 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(3, "Disable", out.str()), true, TEST_LOCATION);
233 //Verify state through the actor api
234 DALI_TEST_CHECK( CullFrontAndBack == actor.GetCullFace() );
235 DALI_TEST_CHECK( CullNone == actor2.GetCullFace() );
237 /**************************************************************/
239 //Verify whether the correct GL calls are made when actor2 is face culled in the front
240 cullFaceTrace.Reset();
241 cullFaceTrace.Enable(true);
242 actor2.SetCullFace( CullFront );
244 // flush the queue and render once
245 application.SendNotification();
246 application.Render();
248 cullFaceTrace.Enable(false);
250 //Verify actor gl state
253 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Enable", out.str()), true, TEST_LOCATION);
256 out << GL_FRONT_AND_BACK;
257 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(1, "CullFace", out.str()), true, TEST_LOCATION);
259 //Verify actor2 gl state
262 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(2, "Enable", out.str()), true, TEST_LOCATION);
266 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(3, "CullFace", out.str()), true, TEST_LOCATION);
268 //Verify state through the actor api
269 DALI_TEST_CHECK( CullFrontAndBack == actor.GetCullFace() );
270 DALI_TEST_CHECK( CullFront == actor2.GetCullFace() );
272 /**************************************************************/
273 //Verify whether the correct GL calls are made when face culling is disabled for both actors
274 cullFaceTrace.Reset();
275 cullFaceTrace.Enable(true);
276 actor.SetCullFace( CullNone );
277 actor2.SetCullFace( CullNone );
279 // flush the queue and render once
280 application.SendNotification();
281 application.Render();
283 cullFaceTrace.Enable(false);
287 DALI_TEST_EQUALS( cullFaceTrace.TestMethodAndParams(0, "Disable", out.str()), true, TEST_LOCATION);
289 //Verify state through the actor api
290 DALI_TEST_CHECK( CullNone == actor.GetCullFace() );
291 DALI_TEST_CHECK( CullNone == actor2.GetCullFace() );
293 Stage::GetCurrent().Remove(actor);
294 Stage::GetCurrent().Remove(actor2);
298 int UtcDaliRenderableActorGetCullFace(void)
300 TestApplication application;
302 tet_infoline("Testing Dali::RenderableActor::GetCullFace()");
304 TextActor textActor = TextActor::New(TestTextHelloWorld);
306 DALI_TEST_CHECK( CullNone == textActor.GetCullFace() );
308 ImageActor imageActor = ImageActor::New();
310 DALI_TEST_CHECK( CullNone == imageActor.GetCullFace() );
312 MeshActor meshActor = MeshActor::New();
314 DALI_TEST_CHECK( CullBack == meshActor.GetCullFace() );
318 int UtcDaliRenderableActorSetGetBlendFunc(void)
320 TestApplication application;
321 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
323 tet_infoline("Testing Dali::RenderableActor::UtcDaliRenderableActorSetGetBlendFunc()");
325 BitmapImage img = BitmapImage::New( 1,1 );
326 ImageActor actor = ImageActor::New( img );
327 Stage::GetCurrent().Add( actor );
328 application.SendNotification();
329 application.Render();
331 // Test the defaults as documented int blending.h
333 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
334 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
335 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
336 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
337 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
338 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
339 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
340 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
341 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
344 // Set to non-default values
345 actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
347 // Test that Set was successful
349 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
350 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
351 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
352 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
353 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
354 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
355 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
356 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
357 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
360 // Render & check GL commands
361 application.SendNotification();
362 application.Render();
363 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
364 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
365 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
366 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
368 // Set using separate alpha settings
369 actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
370 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
372 // Test that Set was successful
374 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
375 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
376 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
377 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
378 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
379 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
380 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
381 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
382 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
385 // Render & check GL commands
386 application.SendNotification();
387 application.Render();
388 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
389 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
390 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
391 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
395 int UtcDaliRenderableActorSetGetBlendEquation(void)
397 TestApplication application;
398 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
400 tet_infoline("Testing Dali::RenderableActor::SetBlendEquation()");
402 BitmapImage img = BitmapImage::New( 1,1 );
403 ImageActor actor = ImageActor::New( img );
404 Stage::GetCurrent().Add( actor );
405 application.SendNotification();
406 application.Render();
408 // Test the defaults as documented int blending.h
410 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
411 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
412 actor.GetBlendEquation( equationRgb, equationAlpha );
413 DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
414 DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
417 // Test the single blending equation setting
419 actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
420 BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
421 actor.GetBlendEquation( equationRgba, equationRgba );
422 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
425 actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
427 // Test that Set was successful
429 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
430 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
431 actor.GetBlendEquation( equationRgb, equationAlpha );
432 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
433 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
436 // Render & check GL commands
437 application.SendNotification();
438 application.Render();
439 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
440 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
444 int UtcDaliRenderableActorSetGetBlendColor(void)
446 TestApplication application;
447 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
449 tet_infoline("Testing Dali::RenderableActor::SetBlendColor()");
451 BitmapImage img = BitmapImage::New( 1,1 );
452 ImageActor actor = ImageActor::New( img );
453 Stage::GetCurrent().Add( actor );
454 application.SendNotification();
455 application.Render();
457 // Test the defaults as documented int blending.h
458 DALI_TEST_EQUALS( Vector4::ZERO, actor.GetBlendColor(), TEST_LOCATION );
460 actor.SetBlendColor( Color::RED );
462 // Test that Set was successful
463 DALI_TEST_EQUALS( Color::RED, actor.GetBlendColor(), TEST_LOCATION );
465 // Render & check GL commands
466 application.SendNotification();
467 application.Render();
468 DALI_TEST_EQUALS( Color::RED, glAbstraction.GetLastBlendColor(), TEST_LOCATION );
472 int UtcDaliRenderableActorSetGetAlpha(void)
474 TestApplication application;
476 tet_infoline("Testing Dali::RenderableActor::SetGetAlpha()");
478 BitmapImage img = BitmapImage::New( 1,1 );
479 ImageActor actor = ImageActor::New( img );
480 Stage::GetCurrent().Add( actor );
481 application.SendNotification();
482 application.Render();
484 // use the image alpha on actor
485 actor.SetBlendMode(BlendingMode::ON);
487 // Test that Set was successful
488 DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION );
490 // Now test that it can be set to false
491 actor.SetBlendMode(BlendingMode::OFF);
492 DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION );
496 int UtcDaliRenderableActorCreateDestroy(void)
498 tet_infoline("Testing Dali::RenderableActor::CreateDestroy()");
499 RenderableActor* ractor = new RenderableActor;
500 RenderableActor ractor2( *ractor );
501 DALI_TEST_CHECK( ractor );