2 * Copyright (c) 2015 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.
19 #include <dali/public-api/dali-core.h>
21 #include <cfloat> // For FLT_MAX
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/hover-event-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <mesh-builder.h>
33 void utc_dali_actor_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_actor_cleanup(void)
40 test_return_value = TET_PASS;
45 bool gTouchCallBackCalled=false;
46 bool gHoverCallBackCalled=false;
49 * Simulates a Down Touch at 25.0, 25.0.
50 * @param[in] app Test Application instance.
52 int SimulateTouchForSetOverlayHitTest(TestApplication& app)
54 app.SendNotification();
56 app.SendNotification();
59 gTouchCallBackCalled = false;
61 // simulate a touch event
62 Dali::Integration::Point point;
63 point.SetState( PointState::DOWN );
64 point.SetScreenPosition( Vector2( 25.0f, 25.0f ) );
65 Dali::Integration::TouchEvent event;
66 event.AddPoint( point );
67 app.ProcessEvent( event );
69 app.SendNotification();
71 app.SendNotification();
77 static bool gTestConstraintCalled;
81 void operator()( Vector4& color, const PropertyInputContainer& /* inputs */ )
83 gTestConstraintCalled = true;
88 * TestConstraint reference.
89 * When constraint is called, the resultRef is updated
90 * with the value supplied.
93 struct TestConstraintRef
95 TestConstraintRef(unsigned int& resultRef, unsigned int value)
96 : mResultRef(resultRef),
101 void operator()( T& current, const PropertyInputContainer& /* inputs */ )
106 unsigned int& mResultRef;
110 static bool TestCallback(Actor actor, const TouchEvent& event)
112 gTouchCallBackCalled = true;
117 static bool TestCallback3(Actor actor, const HoverEvent& event)
119 gHoverCallBackCalled = true;
124 static Vector3 gSetSize;
125 static bool gSetSizeCallBackCalled;
126 void SetSizeCallback( Actor actor, const Vector3& size )
128 gSetSizeCallBackCalled = true;
131 // validation stuff for onstage & offstage signals
132 static std::vector< std::string > gActorNamesOnOffStage;
133 static int gOnStageCallBackCalled;
134 void OnStageCallback( Actor actor )
136 ++gOnStageCallBackCalled;
137 gActorNamesOnOffStage.push_back( actor.GetName() );
138 DALI_TEST_CHECK( actor.OnStage() == true );
140 static int gOffStageCallBackCalled;
141 void OffStageCallback( Actor actor )
143 ++gOffStageCallBackCalled;
144 gActorNamesOnOffStage.push_back( actor.GetName() );
145 DALI_TEST_CHECK( actor.OnStage() == false );
148 struct PositionComponentConstraint
150 PositionComponentConstraint(){}
152 void operator()( Vector3& pos, const PropertyInputContainer& inputs )
154 const Matrix& m = inputs[0]->GetMatrix();
157 m.GetTransformComponents(pos, rot, scale);
161 struct OrientationComponentConstraint
163 OrientationComponentConstraint(){}
165 void operator()( Quaternion& orientation, const PropertyInputContainer& inputs )
167 const Quaternion& parentOrientation = inputs[0]->GetQuaternion();
170 orientation = parentOrientation;
175 static bool gOnRelayoutCallBackCalled = false;
176 static std::vector< std::string > gActorNamesRelayout;
178 void OnRelayoutCallback( Actor actor )
180 gOnRelayoutCallBackCalled = true;
181 gActorNamesRelayout.push_back( actor.GetName() );
184 } // anonymous namespace
187 //& purpose: Testing New API
188 int UtcDaliActorNew(void)
190 TestApplication application;
192 Actor actor = Actor::New();
194 DALI_TEST_CHECK(actor);
198 //& purpose: Testing Dali::Actor::DownCast()
199 int UtcDaliActorDownCastP(void)
201 TestApplication application;
202 tet_infoline("Testing Dali::Actor::DownCast()");
204 Actor actor = Actor::New();
205 BaseHandle object(actor);
206 Actor actor2 = Actor::DownCast(object);
207 DALI_TEST_CHECK(actor2);
211 //& purpose: Testing Dali::Actor::DownCast()
212 int UtcDaliActorDownCastN(void)
214 TestApplication application;
215 tet_infoline("Testing Dali::Actor::DownCast()");
217 BaseHandle unInitializedObject;
218 Actor actor = Actor::DownCast(unInitializedObject);
219 DALI_TEST_CHECK(!actor);
223 //& purpose: Testing Dali::Actor::GetName()
224 int UtcDaliActorGetName(void)
226 TestApplication application;
228 Actor actor = Actor::New();
230 DALI_TEST_CHECK(actor.GetName().empty());
234 //& purpose: Testing Dali::Actor::SetName()
235 int UtcDaliActorSetName(void)
237 TestApplication application;
239 string str("ActorName");
240 Actor actor = Actor::New();
243 DALI_TEST_CHECK(actor.GetName() == str);
247 int UtcDaliActorGetId(void)
249 tet_infoline("Testing Dali::Actor::UtcDaliActorGetId()");
250 TestApplication application;
252 Actor first = Actor::New();
253 Actor second = Actor::New();
254 Actor third = Actor::New();
256 DALI_TEST_CHECK(first.GetId() != second.GetId());
257 DALI_TEST_CHECK(second.GetId() != third.GetId());
261 int UtcDaliActorIsRoot(void)
263 TestApplication application;
265 Actor actor = Actor::New();
266 DALI_TEST_CHECK(!actor.IsRoot());
268 // get the root layer
269 actor = Stage::GetCurrent().GetLayer( 0 );
270 DALI_TEST_CHECK( actor.IsRoot() );
274 int UtcDaliActorOnStage(void)
276 TestApplication application;
278 Actor actor = Actor::New();
279 DALI_TEST_CHECK( !actor.OnStage() );
281 // get the root layer
282 actor = Stage::GetCurrent().GetLayer( 0 );
283 DALI_TEST_CHECK( actor.OnStage() );
287 int UtcDaliActorIsLayer(void)
289 TestApplication application;
291 Actor actor = Actor::New();
292 DALI_TEST_CHECK( !actor.IsLayer() );
294 // get the root layer
295 actor = Stage::GetCurrent().GetLayer( 0 );
296 DALI_TEST_CHECK( actor.IsLayer() );
300 int UtcDaliActorGetLayer(void)
302 TestApplication application;
304 Actor actor = Actor::New();
305 Stage::GetCurrent().Add(actor);
306 Layer layer = actor.GetLayer();
308 DALI_TEST_CHECK(layer);
310 // get the root layers layer
311 actor = Stage::GetCurrent().GetLayer( 0 );
312 DALI_TEST_CHECK( actor.GetLayer() );
316 int UtcDaliActorAddP(void)
318 tet_infoline("Testing Actor::Add");
319 TestApplication application;
321 Actor parent = Actor::New();
322 Actor child = Actor::New();
324 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
328 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
330 Actor parent2 = Actor::New();
331 parent2.Add( child );
333 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
334 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
336 // try Adding to same parent again, works
337 parent2.Add( child );
338 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
340 // try reparenting an orphaned child
342 Actor temporaryParent = Actor::New();
343 temporaryParent.Add( child );
344 DALI_TEST_EQUALS( parent2.GetChildCount(), 0u, TEST_LOCATION );
346 // temporaryParent has now died, reparent the orphaned child
347 parent2.Add( child );
348 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
353 int UtcDaliActorAddN(void)
355 tet_infoline("Testing Actor::Add");
356 TestApplication application;
358 Actor child = Actor::New();
360 Actor parent2 = Actor::New();
361 parent2.Add( child );
366 parent2.Add( parent2 );
367 tet_printf("Assertion test failed - no Exception\n" );
368 tet_result(TET_FAIL);
370 catch(Dali::DaliException& e)
372 DALI_TEST_PRINT_ASSERT( e );
373 DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION);
374 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
378 tet_printf("Assertion test failed - wrong Exception\n" );
379 tet_result(TET_FAIL);
382 // try reparenting root
385 parent2.Add( Stage::GetCurrent().GetLayer( 0 ) );
386 tet_printf("Assertion test failed - no Exception\n" );
387 tet_result(TET_FAIL);
389 catch(Dali::DaliException& e)
391 DALI_TEST_PRINT_ASSERT( e );
392 DALI_TEST_ASSERT(e, "!child.IsRoot()", TEST_LOCATION);
393 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
397 tet_printf("Assertion test failed - wrong Exception\n" );
398 tet_result(TET_FAIL);
405 parent2.Add( empty );
406 tet_printf("Assertion test failed - no Exception\n" );
407 tet_result(TET_FAIL);
409 catch(Dali::DaliException& e)
411 DALI_TEST_PRINT_ASSERT( e );
412 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
413 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
417 tet_printf("Assertion test failed - wrong Exception\n" );
418 tet_result(TET_FAIL);
424 int UtcDaliActorRemoveN(void)
426 tet_infoline("Testing Actor::Remove");
427 TestApplication application;
429 Actor parent = Actor::New();
430 Actor child = Actor::New();
431 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
434 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
436 parent.Remove(child);
437 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
439 // remove again, no problem
440 parent.Remove(child);
441 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
445 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
446 // try Remove self, its a no-op
447 parent.Remove( parent );
448 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
454 parent.Remove( empty );
455 tet_printf("Assertion test failed - no Exception\n" );
456 tet_result(TET_FAIL);
458 catch(Dali::DaliException& e)
460 DALI_TEST_PRINT_ASSERT( e );
461 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
462 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
466 tet_printf("Assertion test failed - wrong Exception\n" );
467 tet_result(TET_FAIL);
472 int UtcDaliActorRemoveP(void)
474 TestApplication application;
476 Actor parent = Actor::New();
477 Actor child = Actor::New();
478 Actor random = Actor::New();
480 Stage::GetCurrent().Add( parent );
482 DALI_TEST_CHECK(parent.GetChildCount() == 0);
486 DALI_TEST_CHECK(parent.GetChildCount() == 1);
488 parent.Remove(random);
490 DALI_TEST_CHECK(parent.GetChildCount() == 1);
492 Stage::GetCurrent().Remove( parent );
494 DALI_TEST_CHECK(parent.GetChildCount() == 1);
498 int UtcDaliActorGetChildCount(void)
500 TestApplication application;
502 Actor parent = Actor::New();
503 Actor child = Actor::New();
505 DALI_TEST_CHECK(parent.GetChildCount() == 0);
509 DALI_TEST_CHECK(parent.GetChildCount() == 1);
513 int UtcDaliActorGetChildren01(void)
515 TestApplication application;
517 Actor parent = Actor::New();
518 Actor first = Actor::New();
519 Actor second = Actor::New();
520 Actor third = Actor::New();
526 DALI_TEST_CHECK(parent.GetChildAt(0) == first);
527 DALI_TEST_CHECK(parent.GetChildAt(1) == second);
528 DALI_TEST_CHECK(parent.GetChildAt(2) == third);
532 int UtcDaliActorGetChildren02(void)
534 TestApplication application;
536 Actor parent = Actor::New();
537 Actor first = Actor::New();
538 Actor second = Actor::New();
539 Actor third = Actor::New();
545 const Actor& constParent = parent;
547 DALI_TEST_CHECK(constParent.GetChildAt(0) == first);
548 DALI_TEST_CHECK(constParent.GetChildAt(1) == second);
549 DALI_TEST_CHECK(constParent.GetChildAt(2) == third);
553 int UtcDaliActorGetParent01(void)
555 TestApplication application;
557 Actor parent = Actor::New();
558 Actor child = Actor::New();
562 DALI_TEST_CHECK(child.GetParent() == parent);
566 int UtcDaliActorGetParent02(void)
568 TestApplication application;
570 Actor actor = Actor::New();
572 DALI_TEST_CHECK(!actor.GetParent());
576 int UtcDaliActorSetParentOrigin(void)
578 TestApplication application;
580 Actor actor = Actor::New();
582 Vector3 vector(0.7f, 0.8f, 0.9f);
583 DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
585 actor.SetParentOrigin(vector);
587 // flush the queue and render once
588 application.SendNotification();
589 application.Render();
591 DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
593 Stage::GetCurrent().Add( actor );
595 actor.SetParentOrigin( Vector3( 0.1f, 0.2f, 0.3f ) );
597 // flush the queue and render once
598 application.SendNotification();
599 application.Render();
601 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentParentOrigin(), TEST_LOCATION );
603 Stage::GetCurrent().Remove( actor );
607 int UtcDaliActorSetParentOriginIndividual(void)
609 TestApplication application;
611 Actor actor = Actor::New();
613 Vector3 vector(0.7f, 0.8f, 0.9f);
614 DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
616 actor.SetProperty( Actor::Property::PARENT_ORIGIN_X, vector.x );
618 // flush the queue and render once
619 application.SendNotification();
620 application.Render();
622 DALI_TEST_EQUALS( vector.x, actor.GetCurrentParentOrigin().x, TEST_LOCATION );
624 actor.SetProperty( Actor::Property::PARENT_ORIGIN_Y, vector.y );
626 // flush the queue and render once
627 application.SendNotification();
628 application.Render();
630 DALI_TEST_EQUALS( vector.y, actor.GetCurrentParentOrigin().y, TEST_LOCATION );
632 actor.SetProperty( Actor::Property::PARENT_ORIGIN_Z, vector.z );
634 // flush the queue and render once
635 application.SendNotification();
636 application.Render();
638 DALI_TEST_EQUALS( vector.z, actor.GetCurrentParentOrigin().z, TEST_LOCATION );
643 int UtcDaliActorGetCurrentParentOrigin(void)
645 TestApplication application;
647 Actor actor = Actor::New();
649 Vector3 vector(0.7f, 0.8f, 0.9f);
650 DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
652 actor.SetParentOrigin(vector);
654 // flush the queue and render once
655 application.SendNotification();
656 application.Render();
658 DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
662 int UtcDaliActorSetAnchorPoint(void)
664 TestApplication application;
666 Actor actor = Actor::New();
668 Vector3 vector(0.7f, 0.8f, 0.9f);
669 DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
671 actor.SetAnchorPoint(vector);
673 // flush the queue and render once
674 application.SendNotification();
675 application.Render();
677 DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
679 Stage::GetCurrent().Add( actor );
681 actor.SetAnchorPoint( Vector3( 0.1f, 0.2f, 0.3f ) );
682 // flush the queue and render once
683 application.SendNotification();
684 application.Render();
686 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentAnchorPoint(), TEST_LOCATION );
688 Stage::GetCurrent().Remove( actor );
692 int UtcDaliActorSetAnchorPointIndividual(void)
694 TestApplication application;
696 Actor actor = Actor::New();
698 Vector3 vector(0.7f, 0.8f, 0.9f);
699 DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
701 actor.SetProperty( Actor::Property::ANCHOR_POINT_X, vector.x );
703 // flush the queue and render once
704 application.SendNotification();
705 application.Render();
707 DALI_TEST_EQUALS( vector.x, actor.GetCurrentAnchorPoint().x, TEST_LOCATION );
709 actor.SetProperty( Actor::Property::ANCHOR_POINT_Y, vector.y );
711 // flush the queue and render once
712 application.SendNotification();
713 application.Render();
715 DALI_TEST_EQUALS( vector.y, actor.GetCurrentAnchorPoint().y, TEST_LOCATION );
717 actor.SetProperty( Actor::Property::ANCHOR_POINT_Z, vector.z );
719 // flush the queue and render once
720 application.SendNotification();
721 application.Render();
723 DALI_TEST_EQUALS( vector.z, actor.GetCurrentAnchorPoint().z, TEST_LOCATION );
728 int UtcDaliActorGetCurrentAnchorPoint(void)
730 TestApplication application;
732 Actor actor = Actor::New();
734 Vector3 vector(0.7f, 0.8f, 0.9f);
735 DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
737 actor.SetAnchorPoint(vector);
739 // flush the queue and render once
740 application.SendNotification();
741 application.Render();
743 DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
747 // SetSize(float width, float height)
748 int UtcDaliActorSetSize01(void)
750 TestApplication application;
752 Actor actor = Actor::New();
753 Vector3 vector(100.0f, 100.0f, 0.0f);
755 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
757 actor.SetSize(vector.x, vector.y);
759 // flush the queue and render once
760 application.SendNotification();
761 application.Render();
763 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
767 // SetSize(float width, float height, float depth)
768 int UtcDaliActorSetSize02(void)
770 TestApplication application;
772 Actor actor = Actor::New();
773 Vector3 vector(100.0f, 100.0f, 100.0f);
775 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
777 actor.SetSize(vector.x, vector.y, vector.z);
779 // flush the queue and render once
780 application.SendNotification();
781 application.Render();
783 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
787 // SetSize(Vector2 size)
788 int UtcDaliActorSetSize03(void)
790 TestApplication application;
792 Actor actor = Actor::New();
793 Vector3 vector(100.0f, 100.0f, 0.0f);
795 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
797 actor.SetSize(Vector2(vector.x, vector.y));
799 // flush the queue and render once
800 application.SendNotification();
801 application.Render();
803 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
807 // SetSize(Vector3 size)
808 int UtcDaliActorSetSize04(void)
810 TestApplication application;
812 Actor actor = Actor::New();
813 Vector3 vector(100.0f, 100.0f, 100.0f);
815 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
817 actor.SetSize(vector);
819 // flush the queue and render once
820 application.SendNotification();
821 application.Render();
823 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
825 Stage::GetCurrent().Add( actor );
826 actor.SetSize( Vector3( 0.1f, 0.2f, 0.3f ) );
828 // flush the queue and render once
829 application.SendNotification();
830 application.Render();
832 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentSize(), TEST_LOCATION );
833 Stage::GetCurrent().Remove( actor );
837 int UtcDaliActorSetSizeIndividual(void)
839 TestApplication application;
841 Actor actor = Actor::New();
843 Vector3 vector(0.7f, 0.8f, 0.9f);
844 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
846 actor.SetProperty( Actor::Property::SIZE_WIDTH, vector.width );
848 // flush the queue and render once
849 application.SendNotification();
850 application.Render();
852 DALI_TEST_EQUALS( vector.width, actor.GetCurrentSize().width, TEST_LOCATION );
854 actor.SetProperty( Actor::Property::SIZE_HEIGHT, vector.height );
856 // flush the queue and render once
857 application.SendNotification();
858 application.Render();
860 DALI_TEST_EQUALS( vector.height, actor.GetCurrentSize().height, TEST_LOCATION );
862 actor.SetProperty( Actor::Property::SIZE_DEPTH, vector.depth );
864 // flush the queue and render once
865 application.SendNotification();
866 application.Render();
868 DALI_TEST_EQUALS( vector.depth, actor.GetCurrentSize().depth, TEST_LOCATION );
874 int UtcDaliActorGetCurrentSize(void)
876 TestApplication application;
878 Actor actor = Actor::New();
879 Vector3 vector(100.0f, 100.0f, 20.0f);
881 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
883 actor.SetSize(vector);
885 // flush the queue and render once
886 application.SendNotification();
887 application.Render();
889 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
893 int UtcDaliActorGetNaturalSize(void)
895 TestApplication application;
897 Actor actor = Actor::New();
898 Vector3 vector( 0.0f, 0.0f, 0.0f );
900 DALI_TEST_CHECK( actor.GetNaturalSize() == vector );
905 int UtcDaliActorGetCurrentSizeImmediate(void)
907 TestApplication application;
909 Actor actor = Actor::New();
910 Vector3 vector(100.0f, 100.0f, 20.0f);
912 DALI_TEST_CHECK(vector != actor.GetTargetSize());
913 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
915 actor.SetSize(vector);
917 DALI_TEST_CHECK(vector == actor.GetTargetSize());
918 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
920 // flush the queue and render once
921 application.SendNotification();
922 application.Render();
924 DALI_TEST_CHECK(vector == actor.GetTargetSize());
925 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
928 // Build the animation
929 const float durationSeconds = 2.0f;
930 Animation animation = Animation::New( durationSeconds );
931 const Vector3 targetValue( 10.0f, 20.0f, 30.0f );
932 animation.AnimateTo( Property( actor, Actor::Property::SIZE ), targetValue );
934 DALI_TEST_CHECK( actor.GetTargetSize() == targetValue );
936 // Start the animation
939 application.SendNotification();
940 application.Render( static_cast<unsigned int>( durationSeconds * 1000.0f ) );
942 DALI_TEST_CHECK( actor.GetTargetSize() == targetValue );
947 // SetPosition(float x, float y)
948 int UtcDaliActorSetPosition01(void)
950 TestApplication application;
952 Actor actor = Actor::New();
954 // Set to random to start off with
955 actor.SetPosition(Vector3(120.0f, 120.0f, 0.0f));
957 Vector3 vector(100.0f, 100.0f, 0.0f);
959 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
961 actor.SetPosition(vector.x, vector.y);
962 // flush the queue and render once
963 application.SendNotification();
964 application.Render();
965 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
967 Stage::GetCurrent().Add( actor );
968 actor.SetPosition( Vector3( 0.1f, 0.2f, 0.3f ) );
969 // flush the queue and render once
970 application.SendNotification();
971 application.Render();
972 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentPosition(), TEST_LOCATION );
977 // flush the queue and render once
978 application.SendNotification();
979 application.Render();
980 DALI_TEST_EQUALS( Vector3( 1.0f, 1.1f, 1.2f ), actor.GetCurrentPosition(), TEST_LOCATION );
982 actor.TranslateBy( Vector3( 0.1f, 0.1f, 0.1f ) );
983 // flush the queue and render once
984 application.SendNotification();
985 application.Render();
986 DALI_TEST_EQUALS( Vector3( 1.1f, 1.2f, 1.3f ), actor.GetCurrentPosition(), Math::MACHINE_EPSILON_10000, TEST_LOCATION );
988 Stage::GetCurrent().Remove( actor );
992 // SetPosition(float x, float y, float z)
993 int UtcDaliActorSetPosition02(void)
995 TestApplication application;
997 Actor actor = Actor::New();
999 // Set to random to start off with
1000 actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
1002 Vector3 vector(100.0f, 100.0f, 100.0f);
1004 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1006 actor.SetPosition(vector.x, vector.y, vector.z);
1008 // flush the queue and render once
1009 application.SendNotification();
1010 application.Render();
1012 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1016 // SetPosition(Vector3 position)
1017 int UtcDaliActorSetPosition03(void)
1019 TestApplication application;
1021 Actor actor = Actor::New();
1023 // Set to random to start off with
1024 actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
1026 Vector3 vector(100.0f, 100.0f, 100.0f);
1028 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1030 actor.SetPosition(vector);
1032 // flush the queue and render once
1033 application.SendNotification();
1034 application.Render();
1036 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1040 int UtcDaliActorSetX(void)
1042 TestApplication application;
1044 Actor actor = Actor::New();
1046 Vector3 vector(100.0f, 0.0f, 0.0f);
1048 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1052 // flush the queue and render once
1053 application.SendNotification();
1054 application.Render();
1056 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1060 int UtcDaliActorSetY(void)
1062 TestApplication application;
1064 Actor actor = Actor::New();
1066 Vector3 vector(0.0f, 100.0f, 0.0f);
1068 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1072 // flush the queue and render once
1073 application.SendNotification();
1074 application.Render();
1076 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1080 int UtcDaliActorSetZ(void)
1082 TestApplication application;
1084 Actor actor = Actor::New();
1086 Vector3 vector(0.0f, 0.0f, 100.0f);
1088 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1092 // flush the queue and render once
1093 application.SendNotification();
1094 application.Render();
1096 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1100 int UtcDaliActorSetPositionProperties(void)
1102 TestApplication application;
1104 Actor actor = Actor::New();
1106 Vector3 vector(0.7f, 0.8f, 0.9f);
1107 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1109 actor.SetProperty( Actor::Property::POSITION_X, vector.x );
1111 // flush the queue and render once
1112 application.SendNotification();
1113 application.Render();
1115 DALI_TEST_EQUALS( vector.x, actor.GetCurrentPosition().x, TEST_LOCATION );
1117 actor.SetProperty( Actor::Property::POSITION_Y, vector.y );
1119 // flush the queue and render once
1120 application.SendNotification();
1121 application.Render();
1123 DALI_TEST_EQUALS( vector.y, actor.GetCurrentPosition().y, TEST_LOCATION );
1125 actor.SetProperty( Actor::Property::POSITION_Z, vector.z );
1127 // flush the queue and render once
1128 application.SendNotification();
1129 application.Render();
1131 DALI_TEST_EQUALS( vector.z, actor.GetCurrentPosition().z, TEST_LOCATION );
1136 int UtcDaliActorTranslateBy(void)
1138 TestApplication application;
1140 Actor actor = Actor::New();
1141 Vector3 vector(100.0f, 100.0f, 100.0f);
1143 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1145 actor.SetPosition(vector);
1147 // flush the queue and render once
1148 application.SendNotification();
1149 application.Render();
1151 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1153 actor.TranslateBy(vector);
1155 // flush the queue and render once
1156 application.SendNotification();
1157 application.Render();
1159 DALI_TEST_CHECK(vector*2.0f == actor.GetCurrentPosition());
1163 int UtcDaliActorGetCurrentPosition(void)
1165 TestApplication application;
1167 Actor actor = Actor::New();
1168 Vector3 setVector(100.0f, 100.0f, 0.0f);
1169 actor.SetPosition(setVector);
1171 // flush the queue and render once
1172 application.SendNotification();
1173 application.Render();
1175 DALI_TEST_CHECK(actor.GetCurrentPosition() == setVector);
1179 int UtcDaliActorGetCurrentWorldPosition(void)
1181 TestApplication application;
1183 Actor parent = Actor::New();
1184 Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1185 parent.SetPosition( parentPosition );
1186 parent.SetParentOrigin( ParentOrigin::CENTER );
1187 parent.SetAnchorPoint( AnchorPoint::CENTER );
1188 Stage::GetCurrent().Add( parent );
1190 Actor child = Actor::New();
1191 child.SetParentOrigin( ParentOrigin::CENTER );
1192 child.SetAnchorPoint( AnchorPoint::CENTER );
1193 Vector3 childPosition( 6.0f, 6.0f, 6.0f );
1194 child.SetPosition( childPosition );
1195 parent.Add( child );
1197 // The actors should not have a world position yet
1198 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1199 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1201 application.SendNotification();
1202 application.Render(0);
1204 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1205 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1207 // The actors should have a world position now
1208 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1209 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1213 int UtcDaliActorInheritPosition(void)
1215 tet_infoline("Testing Actor::SetPositionInheritanceMode");
1216 TestApplication application;
1218 Actor parent = Actor::New();
1219 Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1220 parent.SetPosition( parentPosition );
1221 parent.SetParentOrigin( ParentOrigin::CENTER );
1222 parent.SetAnchorPoint( AnchorPoint::CENTER );
1223 Stage::GetCurrent().Add( parent );
1225 Actor child = Actor::New();
1226 child.SetParentOrigin( ParentOrigin::CENTER );
1227 child.SetAnchorPoint( AnchorPoint::CENTER );
1228 Vector3 childPosition( 10.0f, 11.0f, 12.0f );
1229 child.SetPosition( childPosition );
1230 parent.Add( child );
1232 // The actors should not have a world position yet
1233 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1234 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1236 // first test default, which is to inherit position
1237 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::INHERIT_PARENT_POSITION, TEST_LOCATION );
1238 application.SendNotification();
1239 application.Render(0); // should only really call Update as Render is not required to update scene
1240 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1241 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1242 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1243 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1246 //Change child position
1247 Vector3 childOffset( -1.0f, 1.0f, 0.0f );
1248 child.SetPosition( childOffset );
1250 // Change inheritance mode to not inherit
1251 child.SetPositionInheritanceMode( Dali::DONT_INHERIT_POSITION );
1252 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::DONT_INHERIT_POSITION, TEST_LOCATION );
1253 application.SendNotification();
1254 application.Render(0); // should only really call Update as Render is not required to update scene
1255 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1256 DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1257 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1258 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
1262 int UtcDaliActorSetInheritPosition(void)
1264 tet_infoline("Testing Actor::SetInheritPosition");
1265 TestApplication application;
1267 Actor parent = Actor::New();
1268 Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1269 parent.SetPosition( parentPosition );
1270 parent.SetParentOrigin( ParentOrigin::CENTER );
1271 parent.SetAnchorPoint( AnchorPoint::CENTER );
1272 Stage::GetCurrent().Add( parent );
1274 Actor child = Actor::New();
1275 child.SetParentOrigin( ParentOrigin::CENTER );
1276 child.SetAnchorPoint( AnchorPoint::CENTER );
1277 Vector3 childPosition( 10.0f, 11.0f, 12.0f );
1278 child.SetPosition( childPosition );
1279 parent.Add( child );
1281 // The actors should not have a world position yet
1282 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1283 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1285 // first test default, which is to inherit position
1286 DALI_TEST_EQUALS( child.IsPositionInherited(), true, TEST_LOCATION );
1287 application.SendNotification();
1288 application.Render(0); // should only really call Update as Render is not required to update scene
1289 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1290 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1291 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1292 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1294 //Change child position
1295 Vector3 childOffset( -1.0f, 1.0f, 0.0f );
1296 child.SetPosition( childOffset );
1298 // Use local position as world postion
1299 child.SetInheritPosition( false );
1300 DALI_TEST_EQUALS( child.IsPositionInherited(), false, TEST_LOCATION );
1301 application.SendNotification();
1302 application.Render(0); // should only really call Update as Render is not required to update scene
1303 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1304 DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1305 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1306 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
1308 //Change back to inherit position from parent
1309 child.SetInheritPosition( true );
1310 DALI_TEST_EQUALS( child.IsPositionInherited(), true, TEST_LOCATION );
1311 application.SendNotification();
1312 application.Render(0); // should only really call Update as Render is not required to update scene
1313 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1314 DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1315 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1316 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childOffset, TEST_LOCATION );
1320 // SetOrientation(float angleRadians, Vector3 axis)
1321 int UtcDaliActorSetOrientation01(void)
1323 TestApplication application;
1325 Quaternion rotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f));
1326 Actor actor = Actor::New();
1328 actor.SetOrientation(rotation);
1330 // flush the queue and render once
1331 application.SendNotification();
1332 application.Render();
1334 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1338 int UtcDaliActorSetOrientation02(void)
1340 TestApplication application;
1342 Actor actor = Actor::New();
1344 Radian angle( 0.785f );
1345 Vector3 axis(1.0f, 1.0f, 0.0f);
1347 actor.SetOrientation( angle, axis);
1348 Quaternion rotation( angle, axis );
1349 // flush the queue and render once
1350 application.SendNotification();
1351 application.Render();
1352 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1354 Stage::GetCurrent().Add( actor );
1355 actor.RotateBy( Degree( 360 ), axis);
1356 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1358 actor.SetOrientation( Degree( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) );
1359 Quaternion result( Radian( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) );
1360 // flush the queue and render once
1361 application.SendNotification();
1362 application.Render();
1363 DALI_TEST_EQUALS( result, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1365 actor.SetOrientation( angle, axis);
1366 // flush the queue and render once
1367 application.SendNotification();
1368 application.Render();
1369 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1371 Stage::GetCurrent().Remove( actor );
1375 // SetOrientation(float angleRadians, Vector3 axis)
1376 int UtcDaliActorSetOrientationProperty(void)
1378 TestApplication application;
1380 Quaternion rotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f));
1381 Actor actor = Actor::New();
1383 actor.SetProperty( Actor::Property::ORIENTATION, rotation );
1385 // flush the queue and render once
1386 application.SendNotification();
1387 application.Render();
1389 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1393 // RotateBy(float angleRadians, Vector3 axis)
1394 int UtcDaliActorRotateBy01(void)
1396 TestApplication application;
1398 Actor actor = Actor::New();
1400 Radian angle( M_PI * 0.25f );
1401 actor.RotateBy(( angle ), Vector3::ZAXIS);
1402 // flush the queue and render once
1403 application.SendNotification();
1404 application.Render();
1405 DALI_TEST_EQUALS(Quaternion( angle, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1407 Stage::GetCurrent().Add( actor );
1409 actor.RotateBy( angle, Vector3::ZAXIS);
1410 // flush the queue and render once
1411 application.SendNotification();
1412 application.Render();
1413 DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1415 Stage::GetCurrent().Remove( actor );
1419 // RotateBy(Quaternion relativeRotation)
1420 int UtcDaliActorRotateBy02(void)
1422 TestApplication application;
1424 Actor actor = Actor::New();
1426 Radian angle( M_PI * 0.25f );
1427 Quaternion rotation(angle, Vector3::ZAXIS);
1428 actor.RotateBy(rotation);
1429 // flush the queue and render once
1430 application.SendNotification();
1431 application.Render();
1432 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1434 actor.RotateBy(rotation);
1435 // flush the queue and render once
1436 application.SendNotification();
1437 application.Render();
1438 DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1442 int UtcDaliActorGetCurrentOrientation(void)
1444 TestApplication application;
1445 Actor actor = Actor::New();
1447 Quaternion rotation(Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f));
1448 actor.SetOrientation(rotation);
1449 // flush the queue and render once
1450 application.SendNotification();
1451 application.Render();
1452 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1456 int UtcDaliActorGetCurrentWorldOrientation(void)
1458 tet_infoline("Testing Actor::GetCurrentWorldRotation");
1459 TestApplication application;
1461 Actor parent = Actor::New();
1462 Radian rotationAngle( Degree(90.0f) );
1463 Quaternion rotation( rotationAngle, Vector3::YAXIS );
1464 parent.SetOrientation( rotation );
1465 Stage::GetCurrent().Add( parent );
1467 Actor child = Actor::New();
1468 child.SetOrientation( rotation );
1469 parent.Add( child );
1471 // The actors should not have a world rotation yet
1472 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION );
1473 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION );
1475 application.SendNotification();
1476 application.Render(0);
1478 DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1479 DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1481 // The actors should have a world rotation now
1482 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1483 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1485 // turn off child rotation inheritance
1486 child.SetInheritOrientation( false );
1487 DALI_TEST_EQUALS( child.IsOrientationInherited(), false, TEST_LOCATION );
1488 application.SendNotification();
1489 application.Render(0);
1491 // The actors should have a world rotation now
1492 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1493 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), rotation, 0.001, TEST_LOCATION );
1497 // SetScale(float scale)
1498 int UtcDaliActorSetScale01(void)
1500 TestApplication application;
1502 Actor actor = Actor::New();
1504 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1505 actor.SetScale(0.25f);
1507 Vector3 scale(10.0f, 10.0f, 10.0f);
1508 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1510 actor.SetScale(scale.x);
1512 // flush the queue and render once
1513 application.SendNotification();
1514 application.Render();
1516 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1520 // SetScale(float scaleX, float scaleY, float scaleZ)
1521 int UtcDaliActorSetScale02(void)
1523 TestApplication application;
1524 Vector3 scale(10.0f, 10.0f, 10.0f);
1526 Actor actor = Actor::New();
1528 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1529 actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1531 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1533 actor.SetScale(scale.x, scale.y, scale.z);
1534 // flush the queue and render once
1535 application.SendNotification();
1536 application.Render();
1537 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1539 // add to stage and test
1540 Stage::GetCurrent().Add( actor );
1541 actor.SetScale( 2.0f, 2.0f, 2.0f );
1542 // flush the queue and render once
1543 application.SendNotification();
1544 application.Render();
1545 DALI_TEST_EQUALS( Vector3( 2.0f, 2.0f, 2.0f ), actor.GetCurrentScale(), 0.001, TEST_LOCATION);
1547 Stage::GetCurrent().Remove( actor );
1552 // SetScale(Vector3 scale)
1553 int UtcDaliActorSetScale03(void)
1555 TestApplication application;
1556 Vector3 scale(10.0f, 10.0f, 10.0f);
1558 Actor actor = Actor::New();
1560 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1561 actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1563 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1565 actor.SetScale(scale);
1567 // flush the queue and render once
1568 application.SendNotification();
1569 application.Render();
1571 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1575 int UtcDaliActorSetScaleIndividual(void)
1577 TestApplication application;
1579 Actor actor = Actor::New();
1581 Vector3 vector(0.7f, 0.8f, 0.9f);
1582 DALI_TEST_CHECK(vector != actor.GetCurrentScale());
1584 actor.SetProperty( Actor::Property::SCALE_X, vector.x );
1586 // flush the queue and render once
1587 application.SendNotification();
1588 application.Render();
1590 DALI_TEST_EQUALS( vector.x, actor.GetCurrentScale().x, TEST_LOCATION );
1592 actor.SetProperty( Actor::Property::SCALE_Y, vector.y );
1594 // flush the queue and render once
1595 application.SendNotification();
1596 application.Render();
1598 DALI_TEST_EQUALS( vector.y, actor.GetCurrentScale().y, TEST_LOCATION );
1600 actor.SetProperty( Actor::Property::SCALE_Z, vector.z );
1602 // flush the queue and render once
1603 application.SendNotification();
1604 application.Render();
1606 DALI_TEST_EQUALS( vector.z, actor.GetCurrentScale().z, TEST_LOCATION );
1611 int UtcDaliActorScaleBy(void)
1613 TestApplication application;
1614 Actor actor = Actor::New();
1615 Vector3 vector(100.0f, 100.0f, 100.0f);
1617 DALI_TEST_CHECK(vector != actor.GetCurrentScale());
1619 actor.SetScale(vector);
1621 // flush the queue and render once
1622 application.SendNotification();
1623 application.Render();
1625 DALI_TEST_CHECK(vector == actor.GetCurrentScale());
1627 actor.ScaleBy(vector);
1629 // flush the queue and render once
1630 application.SendNotification();
1631 application.Render();
1633 DALI_TEST_CHECK(vector*100.0f == actor.GetCurrentScale());
1637 int UtcDaliActorGetCurrentScale(void)
1639 TestApplication application;
1640 Vector3 scale(12.0f, 1.0f, 2.0f);
1642 Actor actor = Actor::New();
1644 actor.SetScale(scale);
1646 // flush the queue and render once
1647 application.SendNotification();
1648 application.Render();
1650 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1654 int UtcDaliActorGetCurrentWorldScale(void)
1656 TestApplication application;
1658 Actor parent = Actor::New();
1659 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1660 parent.SetScale( parentScale );
1661 Stage::GetCurrent().Add( parent );
1663 Actor child = Actor::New();
1664 Vector3 childScale( 2.0f, 2.0f, 2.0f );
1665 child.SetScale( childScale );
1666 parent.Add( child );
1668 // The actors should not have a scale yet
1669 DALI_TEST_EQUALS( parent.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1670 DALI_TEST_EQUALS( child.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1672 // The actors should not have a world scale yet
1673 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1674 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1676 application.SendNotification();
1677 application.Render(0);
1679 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
1680 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
1682 // The actors should have a world scale now
1683 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
1684 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1688 int UtcDaliActorInheritScale(void)
1690 tet_infoline("Testing Actor::SetInheritScale");
1691 TestApplication application;
1693 Actor parent = Actor::New();
1694 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1695 parent.SetScale( parentScale );
1696 Stage::GetCurrent().Add( parent );
1698 Actor child = Actor::New();
1699 Vector3 childScale( 2.0f, 2.0f, 2.0f );
1700 child.SetScale( childScale );
1701 parent.Add( child );
1703 application.SendNotification();
1704 application.Render(0);
1706 DALI_TEST_EQUALS( child.IsScaleInherited(), true, TEST_LOCATION );
1707 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1709 child.SetInheritScale( false );
1710 DALI_TEST_EQUALS( child.IsScaleInherited(), false, TEST_LOCATION );
1712 application.SendNotification();
1713 application.Render(0);
1715 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), childScale, TEST_LOCATION );
1719 int UtcDaliActorSetVisible(void)
1721 TestApplication application;
1723 Actor actor = Actor::New();
1724 actor.SetVisible(false);
1725 // flush the queue and render once
1726 application.SendNotification();
1727 application.Render();
1728 DALI_TEST_CHECK(actor.IsVisible() == false);
1730 actor.SetVisible(true);
1731 // flush the queue and render once
1732 application.SendNotification();
1733 application.Render();
1734 DALI_TEST_CHECK(actor.IsVisible() == true);
1736 // put actor on stage
1737 Stage::GetCurrent().Add( actor );
1738 actor.SetVisible(false);
1739 // flush the queue and render once
1740 application.SendNotification();
1741 application.Render();
1742 DALI_TEST_CHECK(actor.IsVisible() == false);
1746 int UtcDaliActorIsVisible(void)
1748 TestApplication application;
1750 Actor actor = Actor::New();
1752 DALI_TEST_CHECK(actor.IsVisible() == true);
1756 int UtcDaliActorSetOpacity(void)
1758 TestApplication application;
1760 Actor actor = Actor::New();
1761 // initial opacity is 1
1762 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1764 actor.SetOpacity( 0.4f);
1765 // flush the queue and render once
1766 application.SendNotification();
1767 application.Render();
1768 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.4f, TEST_LOCATION );
1770 // change opacity, actor is on stage to change is not immediate
1771 actor.SetOpacity( actor.GetCurrentOpacity() + 0.1f );
1772 // flush the queue and render once
1773 application.SendNotification();
1774 application.Render();
1775 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1777 // put actor on stage
1778 Stage::GetCurrent().Add( actor );
1780 // change opacity, actor is on stage to change is not immediate
1781 actor.SetOpacity( 0.9f );
1782 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1783 // flush the queue and render once
1784 application.SendNotification();
1785 application.Render();
1786 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.9f, TEST_LOCATION );
1788 // change opacity, actor is on stage to change is not immediate
1789 actor.SetOpacity( actor.GetCurrentOpacity() - 0.9f );
1790 // flush the queue and render once
1791 application.SendNotification();
1792 application.Render();
1793 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1797 int UtcDaliActorGetCurrentOpacity(void)
1799 TestApplication application;
1801 Actor actor = Actor::New();
1802 DALI_TEST_CHECK(actor.GetCurrentOpacity() != 0.5f);
1804 actor.SetOpacity(0.5f);
1805 // flush the queue and render once
1806 application.SendNotification();
1807 application.Render();
1808 DALI_TEST_CHECK(actor.GetCurrentOpacity() == 0.5f);
1812 int UtcDaliActorSetSensitive(void)
1814 TestApplication application;
1815 Actor actor = Actor::New();
1817 bool sensitive = !actor.IsSensitive();
1819 actor.SetSensitive(sensitive);
1821 DALI_TEST_CHECK(sensitive == actor.IsSensitive());
1825 int UtcDaliActorIsSensitive(void)
1827 TestApplication application;
1828 Actor actor = Actor::New();
1829 actor.SetSensitive(false);
1831 DALI_TEST_CHECK(false == actor.IsSensitive());
1835 int UtcDaliActorSetColor(void)
1837 TestApplication application;
1838 Actor actor = Actor::New();
1839 Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1841 DALI_TEST_CHECK(color != actor.GetCurrentColor());
1843 actor.SetColor(color);
1844 // flush the queue and render once
1845 application.SendNotification();
1846 application.Render();
1847 DALI_TEST_CHECK(color == actor.GetCurrentColor());
1849 actor.SetColor( actor.GetCurrentColor() + Vector4( -0.4f, -0.5f, -0.6f, -0.4f ) );
1850 // flush the queue and render once
1851 application.SendNotification();
1852 application.Render();
1853 DALI_TEST_EQUALS( Vector4( 0.6f, 0.5f, 0.4f, 0.1f ), actor.GetCurrentColor(), TEST_LOCATION );
1855 Stage::GetCurrent().Add( actor );
1856 actor.SetColor( color );
1857 // flush the queue and render once
1858 application.SendNotification();
1859 application.Render();
1860 DALI_TEST_EQUALS( color, actor.GetCurrentColor(), TEST_LOCATION );
1862 actor.SetColor( actor.GetCurrentColor() + Vector4( 1.1f, 1.1f, 1.1f, 1.1f ) );
1863 // flush the queue and render once
1864 application.SendNotification();
1865 application.Render();
1866 // Actor color is not clamped
1867 DALI_TEST_EQUALS( Vector4( 2.1f, 2.1f, 2.1f, 1.6f ), actor.GetCurrentColor(), TEST_LOCATION );
1868 // world color is clamped
1869 DALI_TEST_EQUALS( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), actor.GetCurrentWorldColor(), TEST_LOCATION );
1871 Stage::GetCurrent().Remove( actor );
1875 int UtcDaliActorSetColorIndividual(void)
1877 TestApplication application;
1879 Actor actor = Actor::New();
1881 Vector4 vector(0.7f, 0.8f, 0.9f, 0.6f);
1882 DALI_TEST_CHECK(vector != actor.GetCurrentColor());
1884 actor.SetProperty( Actor::Property::COLOR_RED, vector.r );
1886 // flush the queue and render once
1887 application.SendNotification();
1888 application.Render();
1890 DALI_TEST_EQUALS( vector.r, actor.GetCurrentColor().r, TEST_LOCATION );
1892 actor.SetProperty( Actor::Property::COLOR_GREEN, vector.g );
1894 // flush the queue and render once
1895 application.SendNotification();
1896 application.Render();
1898 DALI_TEST_EQUALS( vector.g, actor.GetCurrentColor().g, TEST_LOCATION );
1900 actor.SetProperty( Actor::Property::COLOR_BLUE, vector.b );
1902 // flush the queue and render once
1903 application.SendNotification();
1904 application.Render();
1906 DALI_TEST_EQUALS( vector.b, actor.GetCurrentColor().b, TEST_LOCATION );
1908 actor.SetProperty( Actor::Property::COLOR_ALPHA, vector.a );
1910 // flush the queue and render once
1911 application.SendNotification();
1912 application.Render();
1914 DALI_TEST_EQUALS( vector.a, actor.GetCurrentColor().a, TEST_LOCATION );
1920 int UtcDaliActorGetCurrentColor(void)
1922 TestApplication application;
1923 Actor actor = Actor::New();
1924 Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1926 actor.SetColor(color);
1927 // flush the queue and render once
1928 application.SendNotification();
1929 application.Render();
1930 DALI_TEST_CHECK(color == actor.GetCurrentColor());
1934 int UtcDaliActorGetCurrentWorldColor(void)
1936 tet_infoline("Actor::GetCurrentWorldColor");
1937 TestApplication application;
1939 Actor parent = Actor::New();
1940 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 0.8f );
1941 parent.SetColor( parentColor );
1942 Stage::GetCurrent().Add( parent );
1944 Actor child = Actor::New();
1945 Vector4 childColor( 0.5f, 0.6f, 0.5f, 1.0f );
1946 child.SetColor( childColor );
1947 parent.Add( child );
1949 DALI_TEST_EQUALS( parent.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1950 DALI_TEST_EQUALS( child.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1952 // verify the default color mode
1953 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, child.GetColorMode(), TEST_LOCATION );
1955 // The actors should not have a world color yet
1956 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1957 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1959 application.SendNotification();
1960 application.Render(0);
1962 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
1963 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1965 // The actors should have a world color now
1966 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1967 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Vector4( childColor.r, childColor.g, childColor.b, childColor.a * parentColor.a), TEST_LOCATION );
1970 child.SetColorMode( USE_OWN_COLOR );
1971 application.SendNotification();
1972 application.Render(0);
1973 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), childColor, TEST_LOCATION );
1976 child.SetColorMode( USE_PARENT_COLOR );
1977 application.SendNotification();
1978 application.Render(0);
1979 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1980 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1983 child.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
1984 application.SendNotification();
1985 application.Render(0);
1986 Vector4 expectedColor( childColor );
1987 expectedColor.a *= parentColor.a;
1988 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1989 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), expectedColor, TEST_LOCATION );
1993 int UtcDaliActorSetColorMode(void)
1995 tet_infoline("Actor::SetColorMode");
1996 TestApplication application;
1997 Actor actor = Actor::New();
1998 Actor child = Actor::New();
2001 actor.SetColorMode( USE_OWN_COLOR );
2002 DALI_TEST_EQUALS( USE_OWN_COLOR, actor.GetColorMode(), TEST_LOCATION );
2004 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
2005 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
2007 actor.SetColorMode( USE_PARENT_COLOR );
2008 DALI_TEST_EQUALS( USE_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
2010 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
2011 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, actor.GetColorMode(), TEST_LOCATION );
2015 int UtcDaliActorScreenToLocal(void)
2017 TestApplication application;
2018 Actor actor = Actor::New();
2019 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2020 actor.SetSize(100.0f, 100.0f);
2021 actor.SetPosition(10.0f, 10.0f);
2022 Stage::GetCurrent().Add(actor);
2024 // flush the queue and render once
2025 application.SendNotification();
2026 application.Render();
2031 application.SendNotification();
2032 application.Render();
2034 DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, 50.0f, 50.0f) );
2036 DALI_TEST_EQUALS(localX, 40.0f, 0.01f, TEST_LOCATION);
2037 DALI_TEST_EQUALS(localY, 40.0f, 0.01f, TEST_LOCATION);
2041 int UtcDaliActorSetLeaveRequired(void)
2043 TestApplication application;
2045 Actor actor = Actor::New();
2047 actor.SetLeaveRequired(false);
2048 DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
2050 actor.SetLeaveRequired(true);
2051 DALI_TEST_CHECK(actor.GetLeaveRequired() == true);
2055 int UtcDaliActorGetLeaveRequired(void)
2057 TestApplication application;
2059 Actor actor = Actor::New();
2061 DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
2065 int UtcDaliActorSetKeyboardFocusable(void)
2067 TestApplication application;
2069 Actor actor = Actor::New();
2071 actor.SetKeyboardFocusable(true);
2072 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == true);
2074 actor.SetKeyboardFocusable(false);
2075 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
2079 int UtcDaliActorIsKeyboardFocusable(void)
2081 TestApplication application;
2083 Actor actor = Actor::New();
2085 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
2089 int UtcDaliActorRemoveConstraints(void)
2091 tet_infoline(" UtcDaliActorRemoveConstraints");
2092 TestApplication application;
2094 gTestConstraintCalled = false;
2096 Actor actor = Actor::New();
2098 Constraint constraint = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraint() );
2100 actor.RemoveConstraints();
2102 DALI_TEST_CHECK( gTestConstraintCalled == false );
2104 Stage::GetCurrent().Add( actor );
2107 // flush the queue and render once
2108 application.SendNotification();
2109 application.Render();
2111 actor.RemoveConstraints();
2113 DALI_TEST_CHECK( gTestConstraintCalled == true );
2117 int UtcDaliActorRemoveConstraintTag(void)
2119 tet_infoline(" UtcDaliActorRemoveConstraintTag");
2120 TestApplication application;
2122 Actor actor = Actor::New();
2124 // 1. Apply Constraint1 and Constraint2, and test...
2125 unsigned int result1 = 0u;
2126 unsigned int result2 = 0u;
2128 unsigned constraint1Tag = 1u;
2129 Constraint constraint1 = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraintRef<Vector4>(result1, 1) );
2130 constraint1.SetTag( constraint1Tag );
2131 constraint1.Apply();
2133 unsigned constraint2Tag = 2u;
2134 Constraint constraint2 = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraintRef<Vector4>(result2, 2) );
2135 constraint2.SetTag( constraint2Tag );
2136 constraint2.Apply();
2138 Stage::GetCurrent().Add( actor );
2139 // flush the queue and render once
2140 application.SendNotification();
2141 application.Render();
2143 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2144 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2146 // 2. Remove Constraint1 and test...
2149 actor.RemoveConstraints(constraint1Tag);
2150 // make color property dirty, which will trigger constraints to be reapplied.
2151 actor.SetColor( Color::WHITE );
2152 // flush the queue and render once
2153 application.SendNotification();
2154 application.Render();
2156 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2157 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2159 // 3. Re-Apply Constraint1 and test...
2162 constraint1.Apply();
2163 // make color property dirty, which will trigger constraints to be reapplied.
2164 actor.SetColor( Color::WHITE );
2165 // flush the queue and render once
2166 application.SendNotification();
2167 application.Render();
2169 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2170 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2172 // 2. Remove Constraint2 and test...
2175 actor.RemoveConstraints(constraint2Tag);
2176 // make color property dirty, which will trigger constraints to be reapplied.
2177 actor.SetColor( Color::WHITE );
2178 // flush the queue and render once
2179 application.SendNotification();
2180 application.Render();
2182 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2183 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2185 // 2. Remove Constraint1 as well and test...
2188 actor.RemoveConstraints(constraint1Tag);
2189 // make color property dirty, which will trigger constraints to be reapplied.
2190 actor.SetColor( Color::WHITE );
2191 // flush the queue and render once
2192 application.SendNotification();
2193 application.Render();
2195 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2196 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2200 int UtcDaliActorTouchedSignal(void)
2202 TestApplication application;
2204 gTouchCallBackCalled = false;
2206 // get the root layer
2207 Actor actor = Stage::GetCurrent().GetRootLayer();
2208 DALI_TEST_CHECK( gTouchCallBackCalled == false );
2210 application.SendNotification();
2211 application.Render();
2213 // connect to its touch signal
2214 actor.TouchedSignal().Connect( TestCallback );
2216 // simulate a touch event in the middle of the screen
2217 Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
2218 Dali::Integration::Point point;
2219 point.SetDeviceId( 1 );
2220 point.SetState( PointState::DOWN );
2221 point.SetScreenPosition( Vector2( touchPoint.x, touchPoint.y ) );
2222 Dali::Integration::TouchEvent event;
2223 event.AddPoint( point );
2224 application.ProcessEvent( event );
2226 DALI_TEST_CHECK( gTouchCallBackCalled == true );
2230 int UtcDaliActorHoveredSignal(void)
2232 TestApplication application;
2234 gHoverCallBackCalled = false;
2236 // get the root layer
2237 Actor actor = Stage::GetCurrent().GetRootLayer();
2238 DALI_TEST_CHECK( gHoverCallBackCalled == false );
2240 application.SendNotification();
2241 application.Render();
2243 // connect to its hover signal
2244 actor.HoveredSignal().Connect( TestCallback3 );
2246 // simulate a hover event in the middle of the screen
2247 Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
2248 Dali::Integration::Point point;
2249 point.SetDeviceId( 1 );
2250 point.SetState( PointState::MOTION );
2251 point.SetScreenPosition( Vector2( touchPoint.x, touchPoint.y ) );
2252 Dali::Integration::HoverEvent event;
2253 event.AddPoint( point );
2254 application.ProcessEvent( event );
2256 DALI_TEST_CHECK( gHoverCallBackCalled == true );
2260 int UtcDaliActorOnOffStageSignal(void)
2262 tet_infoline("Testing Dali::Actor::OnStageSignal() and OffStageSignal()");
2264 TestApplication application;
2267 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2268 gActorNamesOnOffStage.clear();
2270 Actor parent = Actor::New();
2271 parent.SetName( "parent" );
2272 parent.OnStageSignal().Connect( OnStageCallback );
2273 parent.OffStageSignal().Connect( OffStageCallback );
2275 DALI_TEST_CHECK( gOnStageCallBackCalled == 0 );
2276 DALI_TEST_CHECK( gOffStageCallBackCalled == 0 );
2278 // add parent to stage
2279 Stage::GetCurrent().Add( parent );
2280 // onstage emitted, offstage not
2281 DALI_TEST_EQUALS( gOnStageCallBackCalled, 1, TEST_LOCATION );
2282 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2283 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2285 // test adding a child, should get onstage emitted
2287 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2288 gActorNamesOnOffStage.clear();
2290 Actor child = Actor::New();
2291 child.SetName( "child" );
2292 child.OnStageSignal().Connect( OnStageCallback );
2293 child.OffStageSignal().Connect( OffStageCallback );
2294 parent.Add( child ); // add child
2295 // onstage emitted, offstage not
2296 DALI_TEST_EQUALS( gOnStageCallBackCalled, 1, TEST_LOCATION );
2297 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2298 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2300 // test removing parent from stage
2302 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2303 gActorNamesOnOffStage.clear();
2305 Stage::GetCurrent().Remove( parent );
2306 // onstage not emitted, offstage is
2307 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2308 DALI_TEST_EQUALS( gOffStageCallBackCalled, 2, TEST_LOCATION );
2309 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2310 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2312 // test adding parent back to stage
2314 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2315 gActorNamesOnOffStage.clear();
2317 Stage::GetCurrent().Add( parent );
2318 // onstage emitted, offstage not
2319 DALI_TEST_EQUALS( gOnStageCallBackCalled, 2, TEST_LOCATION );
2320 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2321 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2322 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2324 // test removing child
2326 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2327 gActorNamesOnOffStage.clear();
2329 parent.Remove( child );
2330 // onstage not emitted, offstage is
2331 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2332 DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2333 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2335 // test removing parent
2337 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2338 gActorNamesOnOffStage.clear();
2340 Stage::GetCurrent().Remove( parent );
2341 // onstage not emitted, offstage is
2342 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2343 DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2344 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2348 int UtcDaliActorFindChildByName(void)
2350 tet_infoline("Testing Dali::Actor::FindChildByName()");
2351 TestApplication application;
2353 Actor parent = Actor::New();
2354 parent.SetName( "parent" );
2355 Actor first = Actor::New();
2356 first .SetName( "first" );
2357 Actor second = Actor::New();
2358 second.SetName( "second" );
2363 Actor found = parent.FindChildByName( "foo" );
2364 DALI_TEST_CHECK( !found );
2366 found = parent.FindChildByName( "parent" );
2367 DALI_TEST_CHECK( found == parent );
2369 found = parent.FindChildByName( "first" );
2370 DALI_TEST_CHECK( found == first );
2372 found = parent.FindChildByName( "second" );
2373 DALI_TEST_CHECK( found == second );
2377 int UtcDaliActorFindChildById(void)
2379 tet_infoline("Testing Dali::Actor::UtcDaliActorFindChildById()");
2380 TestApplication application;
2382 Actor parent = Actor::New();
2383 Actor first = Actor::New();
2384 Actor second = Actor::New();
2389 Actor found = parent.FindChildById( 100000 );
2390 DALI_TEST_CHECK( !found );
2392 found = parent.FindChildById( parent.GetId() );
2393 DALI_TEST_CHECK( found == parent );
2395 found = parent.FindChildById( first.GetId() );
2396 DALI_TEST_CHECK( found == first );
2398 found = parent.FindChildById( second.GetId() );
2399 DALI_TEST_CHECK( found == second );
2403 int UtcDaliActorHitTest(void)
2408 HitTestData( const Vector3& scale, const Vector2& touchPoint, bool result )
2410 mTouchPoint( touchPoint ),
2415 Vector2 mTouchPoint;
2419 TestApplication application;
2420 tet_infoline(" UtcDaliActorHitTest");
2422 // Fill a vector with different hit tests.
2423 struct HitTestData* hitTestData[] = {
2424 // scale touch point result
2425 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 289.f, 400.f ), true ), // touch point close to the right edge (inside)
2426 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), false ), // touch point close to the right edge (outside)
2427 new HitTestData( Vector3( 110.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), true ), // same point as above with a wider scale. Should be inside.
2428 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 200.f, 451.f ), false ), // touch point close to the down edge (outside)
2429 new HitTestData( Vector3( 100.f, 110.f, 1.f ), Vector2( 200.f, 451.f ), true ), // same point as above with a wider scale. Should be inside.
2433 // get the root layer
2434 Actor actor = Actor::New();
2435 actor.SetAnchorPoint( AnchorPoint::CENTER );
2436 actor.SetParentOrigin( ParentOrigin::CENTER );
2438 Stage::GetCurrent().Add( actor );
2440 gTouchCallBackCalled = false;
2442 unsigned int index = 0;
2443 while( NULL != hitTestData[index] )
2445 actor.SetSize( 1.f, 1.f );
2446 actor.SetScale( hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z );
2448 // flush the queue and render once
2449 application.SendNotification();
2450 application.Render();
2452 DALI_TEST_CHECK( !gTouchCallBackCalled );
2454 // connect to its touch signal
2455 actor.TouchedSignal().Connect(TestCallback);
2457 Dali::Integration::Point point;
2458 point.SetState( PointState::DOWN );
2459 point.SetScreenPosition( Vector2( hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y ) );
2460 Dali::Integration::TouchEvent event;
2461 event.AddPoint( point );
2463 // flush the queue and render once
2464 application.SendNotification();
2465 application.Render();
2466 application.ProcessEvent( event );
2468 DALI_TEST_CHECK( gTouchCallBackCalled == hitTestData[index]->mResult );
2470 if( gTouchCallBackCalled != hitTestData[index]->mResult )
2471 tet_printf("Test failed:\nScale %f %f %f\nTouchPoint %f, %f\nResult %d\n",
2472 hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z,
2473 hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y,
2474 hitTestData[index]->mResult );
2476 gTouchCallBackCalled = false;
2482 int UtcDaliActorSetDrawMode(void)
2484 TestApplication app;
2485 tet_infoline(" UtcDaliActorSetDrawModeOverlay");
2487 Actor a = Actor::New();
2489 Stage::GetCurrent().Add(a);
2490 app.SendNotification();
2492 app.SendNotification();
2495 DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Ensure overlay is off by default
2497 a.SetDrawMode( DrawMode::OVERLAY_2D );
2498 app.SendNotification();
2501 DALI_TEST_CHECK( DrawMode::OVERLAY_2D == a.GetDrawMode() ); // Check Actor is overlay
2503 a.SetDrawMode( DrawMode::NORMAL );
2504 app.SendNotification();
2507 DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Check Actor is normal
2511 int UtcDaliActorSetDrawModeOverlayRender(void)
2513 TestApplication app;
2514 tet_infoline(" UtcDaliActorSetDrawModeOverlayRender");
2516 app.SendNotification();
2519 std::vector<GLuint> ids;
2520 ids.push_back( 8 ); // first rendered actor
2521 ids.push_back( 9 ); // second rendered actor
2522 ids.push_back( 10 ); // third rendered actor
2523 app.GetGlAbstraction().SetNextTextureIds( ids );
2525 BufferImage imageA = BufferImage::New(16, 16);
2526 BufferImage imageB = BufferImage::New(16, 16);
2527 BufferImage imageC = BufferImage::New(16, 16);
2528 Actor a = CreateRenderableActor( imageA );
2529 Actor b = CreateRenderableActor( imageB );
2530 Actor c = CreateRenderableActor( imageC );
2532 // Render a,b,c as regular non-overlays. so order will be:
2536 Stage::GetCurrent().Add(a);
2537 Stage::GetCurrent().Add(b);
2538 Stage::GetCurrent().Add(c);
2540 app.SendNotification();
2543 // Should be 3 textures changes.
2544 const std::vector<GLuint>& boundTextures = app.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
2545 typedef std::vector<GLuint>::size_type TextureSize;
2546 DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>( 3 ), TEST_LOCATION );
2547 if( boundTextures.size() == 3 )
2549 DALI_TEST_CHECK( boundTextures[0] == 8u );
2550 DALI_TEST_CHECK( boundTextures[1] == 9u );
2551 DALI_TEST_CHECK( boundTextures[2] == 10u );
2554 // Now texture ids have been set, we can monitor their render order.
2555 // render a as an overlay (last), so order will be:
2559 a.SetDrawMode( DrawMode::OVERLAY_2D );
2560 app.GetGlAbstraction().ClearBoundTextures();
2562 app.SendNotification();
2565 // Should be 3 texture changes.
2566 DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>(3), TEST_LOCATION );
2567 if( boundTextures.size() == 3 )
2569 DALI_TEST_CHECK( boundTextures[0] == 9u );
2570 DALI_TEST_CHECK( boundTextures[1] == 10u );
2571 DALI_TEST_CHECK( boundTextures[2] == 8u );
2576 int UtcDaliActorGetCurrentWorldMatrix(void)
2578 TestApplication app;
2579 tet_infoline(" UtcDaliActorGetCurrentWorldMatrix");
2581 Actor parent = Actor::New();
2582 parent.SetParentOrigin(ParentOrigin::CENTER);
2583 parent.SetAnchorPoint(AnchorPoint::CENTER);
2584 Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2585 Radian rotationAngle(Degree(85.0f));
2586 Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2587 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2588 parent.SetPosition( parentPosition );
2589 parent.SetOrientation( parentRotation );
2590 parent.SetScale( parentScale );
2591 Stage::GetCurrent().Add( parent );
2593 Actor child = Actor::New();
2594 child.SetParentOrigin(ParentOrigin::CENTER);
2595 Vector3 childPosition( 0.0f, 0.0f, 100.0f );
2596 Radian childRotationAngle(Degree(23.0f));
2597 Quaternion childRotation( childRotationAngle, Vector3::YAXIS );
2598 Vector3 childScale( 2.0f, 2.0f, 2.0f );
2599 child.SetPosition( childPosition );
2600 child.SetOrientation( childRotation );
2601 child.SetScale( childScale );
2602 parent.Add( child );
2604 app.SendNotification();
2607 app.SendNotification();
2609 Matrix parentMatrix(false);
2610 parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
2612 Matrix childMatrix(false);
2613 childMatrix.SetTransformComponents( childScale, childRotation, childPosition );
2615 //Child matrix should be the composition of child and parent
2616 Matrix childWorldMatrix(false);
2617 Matrix::Multiply( childWorldMatrix, childMatrix, parentMatrix);
2619 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
2620 DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), childWorldMatrix, 0.001, TEST_LOCATION );
2626 int UtcDaliActorConstrainedToWorldMatrix(void)
2628 TestApplication app;
2629 tet_infoline(" UtcDaliActorConstrainedToWorldMatrix");
2631 Actor parent = Actor::New();
2632 parent.SetParentOrigin(ParentOrigin::CENTER);
2633 parent.SetAnchorPoint(AnchorPoint::CENTER);
2634 Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2635 Radian rotationAngle(Degree(85.0f));
2636 Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2637 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2638 parent.SetPosition( parentPosition );
2639 parent.SetOrientation( parentRotation );
2640 parent.SetScale( parentScale );
2641 Stage::GetCurrent().Add( parent );
2643 Actor child = Actor::New();
2644 child.SetParentOrigin(ParentOrigin::CENTER);
2645 Constraint posConstraint = Constraint::New<Vector3>( child, Actor::Property::POSITION, PositionComponentConstraint() );
2646 posConstraint.AddSource( Source( parent, Actor::Property::WORLD_MATRIX ) );
2647 posConstraint.Apply();
2649 Stage::GetCurrent().Add( child );
2651 app.SendNotification();
2654 app.SendNotification();
2656 Matrix parentMatrix(false);
2657 parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
2659 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
2660 DALI_TEST_EQUALS( child.GetCurrentPosition(), parent.GetCurrentPosition(), 0.001, TEST_LOCATION );
2664 int UtcDaliActorConstrainedToOrientation(void)
2666 TestApplication app;
2667 tet_infoline(" UtcDaliActorConstrainedToOrientation");
2669 Actor parent = Actor::New();
2670 parent.SetParentOrigin(ParentOrigin::CENTER);
2671 parent.SetAnchorPoint(AnchorPoint::CENTER);
2672 Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2673 Radian rotationAngle(Degree(85.0f));
2674 Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2675 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2676 parent.SetPosition( parentPosition );
2677 parent.SetOrientation( parentRotation );
2678 parent.SetScale( parentScale );
2679 Stage::GetCurrent().Add( parent );
2681 Actor child = Actor::New();
2682 child.SetParentOrigin(ParentOrigin::CENTER);
2683 Constraint posConstraint = Constraint::New<Quaternion>( child, Actor::Property::ORIENTATION, OrientationComponentConstraint() );
2684 posConstraint.AddSource( Source( parent, Actor::Property::ORIENTATION ) );
2685 posConstraint.Apply();
2687 Stage::GetCurrent().Add( child );
2689 app.SendNotification();
2692 app.SendNotification();
2694 DALI_TEST_EQUALS( child.GetCurrentOrientation(), parent.GetCurrentOrientation(), 0.001, TEST_LOCATION );
2698 int UtcDaliActorUnparent(void)
2700 TestApplication app;
2701 tet_infoline(" UtcDaliActorUnparent");
2703 Actor parent = Actor::New();
2704 Stage::GetCurrent().Add( parent );
2706 Actor child = Actor::New();
2708 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2709 DALI_TEST_CHECK( !child.GetParent() );
2711 // Test that calling Unparent with no parent is a NOOP
2714 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2715 DALI_TEST_CHECK( !child.GetParent() );
2717 // Test that Unparent works
2718 parent.Add( child );
2720 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
2721 DALI_TEST_CHECK( parent == child.GetParent() );
2725 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2726 DALI_TEST_CHECK( !child.GetParent() );
2728 // Test that UnparentAndReset works
2729 parent.Add( child );
2731 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
2732 DALI_TEST_CHECK( parent == child.GetParent() );
2734 UnparentAndReset( child );
2736 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2737 DALI_TEST_CHECK( !child );
2739 // Test that UnparentAndReset is a NOOP with empty handle
2740 UnparentAndReset( child );
2742 DALI_TEST_CHECK( !child );
2746 int UtcDaliActorGetChildAt(void)
2748 TestApplication app;
2749 tet_infoline(" UtcDaliActorGetChildAt");
2751 Actor parent = Actor::New();
2752 Stage::GetCurrent().Add( parent );
2754 Actor child0 = Actor::New();
2755 parent.Add( child0 );
2757 Actor child1 = Actor::New();
2758 parent.Add( child1 );
2760 Actor child2 = Actor::New();
2761 parent.Add( child2 );
2763 DALI_TEST_EQUALS( parent.GetChildAt( 0 ), child0, TEST_LOCATION );
2764 DALI_TEST_EQUALS( parent.GetChildAt( 1 ), child1, TEST_LOCATION );
2765 DALI_TEST_EQUALS( parent.GetChildAt( 2 ), child2, TEST_LOCATION );
2769 int UtcDaliActorSetGetOverlay(void)
2771 TestApplication app;
2772 tet_infoline(" UtcDaliActorSetGetOverlay");
2774 Actor parent = Actor::New();
2775 parent.SetDrawMode(DrawMode::OVERLAY_2D );
2776 DALI_TEST_CHECK( parent.GetDrawMode() == DrawMode::OVERLAY_2D );
2781 int UtcDaliActorCreateDestroy(void)
2783 Actor* actor = new Actor;
2784 DALI_TEST_CHECK( actor );
2791 struct PropertyStringIndex
2793 const char * const name;
2794 const Property::Index index;
2795 const Property::Type type;
2798 const PropertyStringIndex PROPERTY_TABLE[] =
2800 { "parentOrigin", Actor::Property::PARENT_ORIGIN, Property::VECTOR3 },
2801 { "parentOriginX", Actor::Property::PARENT_ORIGIN_X, Property::FLOAT },
2802 { "parentOriginY", Actor::Property::PARENT_ORIGIN_Y, Property::FLOAT },
2803 { "parentOriginZ", Actor::Property::PARENT_ORIGIN_Z, Property::FLOAT },
2804 { "anchorPoint", Actor::Property::ANCHOR_POINT, Property::VECTOR3 },
2805 { "anchorPointX", Actor::Property::ANCHOR_POINT_X, Property::FLOAT },
2806 { "anchorPointY", Actor::Property::ANCHOR_POINT_Y, Property::FLOAT },
2807 { "anchorPointZ", Actor::Property::ANCHOR_POINT_Z, Property::FLOAT },
2808 { "size", Actor::Property::SIZE, Property::VECTOR3 },
2809 { "sizeWidth", Actor::Property::SIZE_WIDTH, Property::FLOAT },
2810 { "sizeHeight", Actor::Property::SIZE_HEIGHT, Property::FLOAT },
2811 { "sizeDepth", Actor::Property::SIZE_DEPTH, Property::FLOAT },
2812 { "position", Actor::Property::POSITION, Property::VECTOR3 },
2813 { "positionX", Actor::Property::POSITION_X, Property::FLOAT },
2814 { "positionY", Actor::Property::POSITION_Y, Property::FLOAT },
2815 { "positionZ", Actor::Property::POSITION_Z, Property::FLOAT },
2816 { "worldPosition", Actor::Property::WORLD_POSITION, Property::VECTOR3 },
2817 { "worldPositionX", Actor::Property::WORLD_POSITION_X, Property::FLOAT },
2818 { "worldPositionY", Actor::Property::WORLD_POSITION_Y, Property::FLOAT },
2819 { "worldPositionZ", Actor::Property::WORLD_POSITION_Z, Property::FLOAT },
2820 { "orientation", Actor::Property::ORIENTATION, Property::ROTATION },
2821 { "worldOrientation", Actor::Property::WORLD_ORIENTATION, Property::ROTATION },
2822 { "scale", Actor::Property::SCALE, Property::VECTOR3 },
2823 { "scaleX", Actor::Property::SCALE_X, Property::FLOAT },
2824 { "scaleY", Actor::Property::SCALE_Y, Property::FLOAT },
2825 { "scaleZ", Actor::Property::SCALE_Z, Property::FLOAT },
2826 { "worldScale", Actor::Property::WORLD_SCALE, Property::VECTOR3 },
2827 { "visible", Actor::Property::VISIBLE, Property::BOOLEAN },
2828 { "color", Actor::Property::COLOR, Property::VECTOR4 },
2829 { "colorRed", Actor::Property::COLOR_RED, Property::FLOAT },
2830 { "colorGreen", Actor::Property::COLOR_GREEN, Property::FLOAT },
2831 { "colorBlue", Actor::Property::COLOR_BLUE, Property::FLOAT },
2832 { "colorAlpha", Actor::Property::COLOR_ALPHA, Property::FLOAT },
2833 { "worldColor", Actor::Property::WORLD_COLOR, Property::VECTOR4 },
2834 { "worldMatrix", Actor::Property::WORLD_MATRIX, Property::MATRIX },
2835 { "name", Actor::Property::NAME, Property::STRING },
2836 { "sensitive", Actor::Property::SENSITIVE, Property::BOOLEAN },
2837 { "leaveRequired", Actor::Property::LEAVE_REQUIRED, Property::BOOLEAN },
2838 { "inheritOrientation", Actor::Property::INHERIT_ORIENTATION, Property::BOOLEAN },
2839 { "inheritScale", Actor::Property::INHERIT_SCALE, Property::BOOLEAN },
2840 { "colorMode", Actor::Property::COLOR_MODE, Property::STRING },
2841 { "positionInheritance", Actor::Property::POSITION_INHERITANCE, Property::STRING },
2842 { "drawMode", Actor::Property::DRAW_MODE, Property::STRING },
2843 { "sizeModeFactor", Actor::Property::SIZE_MODE_FACTOR, Property::VECTOR3 },
2844 { "widthResizePolicy", Actor::Property::WIDTH_RESIZE_POLICY, Property::STRING },
2845 { "heightResizePolicy", Actor::Property::HEIGHT_RESIZE_POLICY, Property::STRING },
2846 { "sizeScalePolicy", Actor::Property::SIZE_SCALE_POLICY, Property::STRING },
2847 { "widthForHeight", Actor::Property::WIDTH_FOR_HEIGHT, Property::BOOLEAN },
2848 { "heightForWidth", Actor::Property::HEIGHT_FOR_WIDTH, Property::BOOLEAN },
2849 { "padding", Actor::Property::PADDING, Property::VECTOR4 },
2850 { "minimumSize", Actor::Property::MINIMUM_SIZE, Property::VECTOR2 },
2851 { "maximumSize", Actor::Property::MAXIMUM_SIZE, Property::VECTOR2 },
2852 { "inheritPosition", Actor::Property::INHERIT_POSITION, Property::BOOLEAN },
2853 { "batchParent", Actor::Property::BATCH_PARENT, Property::BOOLEAN },
2854 { "clippingMode", Actor::Property::CLIPPING_MODE, Property::STRING },
2856 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2857 } // unnamed namespace
2859 int UtcDaliActorProperties(void)
2861 TestApplication app;
2863 Actor actor = Actor::New();
2865 for ( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2867 tet_printf( "Checking %s == %d\n", PROPERTY_TABLE[i].name, PROPERTY_TABLE[i].index );
2868 DALI_TEST_EQUALS( actor.GetPropertyName( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].name, TEST_LOCATION );
2869 DALI_TEST_EQUALS( actor.GetPropertyIndex( PROPERTY_TABLE[i].name ), PROPERTY_TABLE[i].index, TEST_LOCATION );
2870 DALI_TEST_EQUALS( actor.GetPropertyType( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].type, TEST_LOCATION );
2875 int UtcDaliRelayoutProperties_ResizePolicies(void)
2877 TestApplication app;
2879 Actor actor = Actor::New();
2882 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_RESIZE_POLICY ).Get< std::string >(), "USE_NATURAL_SIZE", TEST_LOCATION );
2883 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_RESIZE_POLICY ).Get< std::string >(), "USE_NATURAL_SIZE", TEST_LOCATION );
2885 // Set resize policy for all dimensions
2886 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
2887 for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i)
2889 DALI_TEST_EQUALS( actor.GetResizePolicy( static_cast< Dimension::Type >( 1 << i ) ), ResizePolicy::USE_NATURAL_SIZE, TEST_LOCATION );
2892 // Set individual dimensions
2893 const char* const widthPolicy = "FILL_TO_PARENT";
2894 const char* const heightPolicy = "FIXED";
2896 actor.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, widthPolicy );
2897 actor.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, heightPolicy );
2899 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_RESIZE_POLICY ).Get< std::string >(), widthPolicy, TEST_LOCATION );
2900 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_RESIZE_POLICY ).Get< std::string >(), heightPolicy, TEST_LOCATION );
2905 int UtcDaliRelayoutProperties_SizeScalePolicy(void)
2907 TestApplication app;
2909 Actor actor = Actor::New();
2912 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), "USE_SIZE_SET", TEST_LOCATION );
2913 DALI_TEST_EQUALS( actor.GetSizeScalePolicy(), SizeScalePolicy::USE_SIZE_SET, TEST_LOCATION );
2915 SizeScalePolicy::Type policy = SizeScalePolicy::FILL_WITH_ASPECT_RATIO;
2916 actor.SetSizeScalePolicy( policy );
2917 DALI_TEST_EQUALS( actor.GetSizeScalePolicy(), policy, TEST_LOCATION );
2920 const char* const policy1 = "FIT_WITH_ASPECT_RATIO";
2921 const char* const policy2 = "FILL_WITH_ASPECT_RATIO";
2923 actor.SetProperty( Actor::Property::SIZE_SCALE_POLICY, policy1 );
2924 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), policy1, TEST_LOCATION );
2926 actor.SetProperty( Actor::Property::SIZE_SCALE_POLICY, policy2 );
2927 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), policy2, TEST_LOCATION );
2932 int UtcDaliRelayoutProperties_SizeModeFactor(void)
2934 TestApplication app;
2936 Actor actor = Actor::New();
2939 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_MODE_FACTOR ).Get< Vector3 >(), Vector3( 1.0f, 1.0f, 1.0f ), TEST_LOCATION );
2940 DALI_TEST_EQUALS( actor.GetSizeModeFactor(), Vector3( 1.0f, 1.0f, 1.0f ), TEST_LOCATION );
2942 Vector3 sizeMode( 1.0f, 2.0f, 3.0f );
2943 actor.SetSizeModeFactor( sizeMode );
2944 DALI_TEST_EQUALS( actor.GetSizeModeFactor(), sizeMode, TEST_LOCATION );
2947 Vector3 sizeMode1( 2.0f, 3.0f, 4.0f );
2949 actor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, sizeMode1 );
2950 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_MODE_FACTOR ).Get< Vector3 >(), sizeMode1, TEST_LOCATION );
2955 int UtcDaliRelayoutProperties_DimensionDependency(void)
2957 TestApplication app;
2959 Actor actor = Actor::New();
2962 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), false, TEST_LOCATION );
2963 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_FOR_WIDTH ).Get< bool >(), false, TEST_LOCATION );
2966 actor.SetProperty( Actor::Property::WIDTH_FOR_HEIGHT, true );
2967 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), true, TEST_LOCATION );
2969 actor.SetProperty( Actor::Property::HEIGHT_FOR_WIDTH, true );
2970 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_FOR_WIDTH ).Get< bool >(), true, TEST_LOCATION );
2972 // Test setting another resize policy
2973 actor.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, "FIXED" );
2974 DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), false, TEST_LOCATION );
2979 int UtcDaliRelayoutProperties_Padding(void)
2981 TestApplication app;
2983 Actor actor = Actor::New();
2986 Vector4 padding( 1.0f, 2.0f, 3.0f, 4.0f );
2989 actor.SetProperty( Actor::Property::PADDING, padding );
2990 Vector4 paddingResult = actor.GetProperty( Actor::Property::PADDING ).Get< Vector4 >();
2992 DALI_TEST_EQUALS( paddingResult, padding, Math::MACHINE_EPSILON_0, TEST_LOCATION );
2997 int UtcDaliRelayoutProperties_MinimumMaximumSize(void)
2999 TestApplication app;
3001 Actor actor = Actor::New();
3004 Vector2 minSize( 1.0f, 2.0f );
3006 actor.SetProperty( Actor::Property::MINIMUM_SIZE, minSize );
3007 Vector2 resultMin = actor.GetProperty( Actor::Property::MINIMUM_SIZE ).Get< Vector2 >();
3009 DALI_TEST_EQUALS( resultMin, minSize, Math::MACHINE_EPSILON_0, TEST_LOCATION );
3011 Vector2 maxSize( 3.0f, 4.0f );
3013 actor.SetProperty( Actor::Property::MAXIMUM_SIZE, maxSize );
3014 Vector2 resultMax = actor.GetProperty( Actor::Property::MAXIMUM_SIZE ).Get< Vector2 >();
3016 DALI_TEST_EQUALS( resultMax, maxSize, Math::MACHINE_EPSILON_0, TEST_LOCATION );
3021 int UtcDaliActorGetHeightForWidth(void)
3023 TestApplication app;
3025 Actor actor = Actor::New();
3027 DALI_TEST_EQUALS( actor.GetHeightForWidth( 1.0f ), 1.0f, TEST_LOCATION );
3032 int UtcDaliActorGetWidthForHeight(void)
3034 TestApplication app;
3036 Actor actor = Actor::New();
3038 DALI_TEST_EQUALS( actor.GetWidthForHeight( 1.0f ), 1.0f, TEST_LOCATION );
3043 int UtcDaliActorGetRelayoutSize(void)
3045 TestApplication app;
3047 Actor actor = Actor::New();
3049 // Add actor to stage
3050 Stage::GetCurrent().Add( actor );
3052 DALI_TEST_EQUALS( actor.GetRelayoutSize( Dimension::WIDTH ), 0.0f, TEST_LOCATION );
3054 actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::WIDTH );
3055 actor.SetSize( Vector2( 1.0f, 0.0f ) );
3057 // Flush the queue and render once
3058 app.SendNotification();
3061 DALI_TEST_EQUALS( actor.GetRelayoutSize( Dimension::WIDTH ), 1.0f, TEST_LOCATION );
3066 int UtcDaliActorSetPadding(void)
3068 TestApplication app;
3070 Actor actor = Actor::New();
3073 actor.GetPadding( padding );
3075 DALI_TEST_EQUALS( padding.left, 0.0f, TEST_LOCATION );
3076 DALI_TEST_EQUALS( padding.right, 0.0f, TEST_LOCATION );
3077 DALI_TEST_EQUALS( padding.bottom, 0.0f, TEST_LOCATION );
3078 DALI_TEST_EQUALS( padding.top, 0.0f, TEST_LOCATION );
3080 Padding padding2( 1.0f, 2.0f, 3.0f, 4.0f );
3081 actor.SetPadding( padding2 );
3083 actor.GetPadding( padding );
3085 DALI_TEST_EQUALS( padding.left, padding2.left, TEST_LOCATION );
3086 DALI_TEST_EQUALS( padding.right, padding2.right, TEST_LOCATION );
3087 DALI_TEST_EQUALS( padding.bottom, padding2.bottom, TEST_LOCATION );
3088 DALI_TEST_EQUALS( padding.top, padding2.top, TEST_LOCATION );
3093 int UtcDaliActorSetMinimumSize(void)
3095 TestApplication app;
3097 Actor actor = Actor::New();
3099 Vector2 size = actor.GetMinimumSize();
3101 DALI_TEST_EQUALS( size.width, 0.0f, TEST_LOCATION );
3102 DALI_TEST_EQUALS( size.height, 0.0f, TEST_LOCATION );
3104 Vector2 size2( 1.0f, 2.0f );
3105 actor.SetMinimumSize( size2 );
3107 size = actor.GetMinimumSize();
3109 DALI_TEST_EQUALS( size.width, size2.width, TEST_LOCATION );
3110 DALI_TEST_EQUALS( size.height, size2.height, TEST_LOCATION );
3115 int UtcDaliActorSetMaximumSize(void)
3117 TestApplication app;
3119 Actor actor = Actor::New();
3121 Vector2 size = actor.GetMaximumSize();
3123 DALI_TEST_EQUALS( size.width, FLT_MAX, TEST_LOCATION );
3124 DALI_TEST_EQUALS( size.height, FLT_MAX, TEST_LOCATION );
3126 Vector2 size2( 1.0f, 2.0f );
3127 actor.SetMaximumSize( size2 );
3129 size = actor.GetMaximumSize();
3131 DALI_TEST_EQUALS( size.width, size2.width, TEST_LOCATION );
3132 DALI_TEST_EQUALS( size.height, size2.height, TEST_LOCATION );
3137 int UtcDaliActorOnRelayoutSignal(void)
3139 tet_infoline("Testing Dali::Actor::OnRelayoutSignal()");
3141 TestApplication application;
3144 gOnRelayoutCallBackCalled = false;
3145 gActorNamesRelayout.clear();
3147 Actor actor = Actor::New();
3148 actor.SetName( "actor" );
3149 actor.OnRelayoutSignal().Connect( OnRelayoutCallback );
3152 DALI_TEST_CHECK( ! gOnRelayoutCallBackCalled );
3154 // Add actor to stage
3155 Stage::GetCurrent().Add( actor );
3157 actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
3158 actor.SetSize( Vector2( 1.0f, 2.0 ) );
3160 // Flush the queue and render once
3161 application.SendNotification();
3162 application.Render();
3164 // OnRelayout emitted
3165 DALI_TEST_EQUALS( gOnRelayoutCallBackCalled, true, TEST_LOCATION );
3166 DALI_TEST_EQUALS( "actor", gActorNamesRelayout[ 0 ], TEST_LOCATION );
3171 int UtcDaliActorGetHierachyDepth(void)
3173 TestApplication application;
3174 tet_infoline("Testing Dali::Actor::GetHierarchyDepth()");
3177 /* Build tree of actors:
3187 * GetHierarchyDepth should return 1 for A, 2 for B and C, and 3 for D, E and F.
3189 Stage stage( Stage::GetCurrent() );
3191 Actor actorA = Actor::New();
3192 Actor actorB = Actor::New();
3193 Actor actorC = Actor::New();
3194 Actor actorD = Actor::New();
3195 Actor actorE = Actor::New();
3196 Actor actorF = Actor::New();
3198 //Test that root actor has depth equal 0
3199 DALI_TEST_EQUALS( 0, stage.GetRootLayer().GetHierarchyDepth(), TEST_LOCATION );
3201 //Test actors return depth -1 when not connected to the tree
3202 DALI_TEST_EQUALS( -1, actorA.GetHierarchyDepth(), TEST_LOCATION );
3203 DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION );
3204 DALI_TEST_EQUALS( -1, actorC.GetHierarchyDepth(), TEST_LOCATION );
3205 DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION );
3206 DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION );
3207 DALI_TEST_EQUALS( -1, actorF.GetHierarchyDepth(), TEST_LOCATION );
3209 //Create the hierarchy
3210 stage.Add( actorA );
3211 actorA.Add( actorB );
3212 actorA.Add( actorC );
3213 actorB.Add( actorD );
3214 actorB.Add( actorE );
3215 actorC.Add( actorF );
3217 //Test actors return correct depth
3218 DALI_TEST_EQUALS( 1, actorA.GetHierarchyDepth(), TEST_LOCATION );
3219 DALI_TEST_EQUALS( 2, actorB.GetHierarchyDepth(), TEST_LOCATION );
3220 DALI_TEST_EQUALS( 2, actorC.GetHierarchyDepth(), TEST_LOCATION );
3221 DALI_TEST_EQUALS( 3, actorD.GetHierarchyDepth(), TEST_LOCATION );
3222 DALI_TEST_EQUALS( 3, actorE.GetHierarchyDepth(), TEST_LOCATION );
3223 DALI_TEST_EQUALS( 3, actorF.GetHierarchyDepth(), TEST_LOCATION );
3225 //Removing actorB from the hierarchy. actorB, actorD and actorE should now have depth equal -1
3226 actorA.Remove( actorB );
3228 DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION );
3229 DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION );
3230 DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION );
3232 //Removing actorA from the stage. All actors should have depth equal -1
3233 stage.Remove( actorA );
3235 DALI_TEST_EQUALS( -1, actorA.GetHierarchyDepth(), TEST_LOCATION );
3236 DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION );
3237 DALI_TEST_EQUALS( -1, actorC.GetHierarchyDepth(), TEST_LOCATION );
3238 DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION );
3239 DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION );
3240 DALI_TEST_EQUALS( -1, actorF.GetHierarchyDepth(), TEST_LOCATION );
3245 int UtcDaliActorAnchorPointPropertyAsString(void)
3247 TestApplication application;
3249 Actor actor = Actor::New();
3251 actor.SetProperty( Actor::Property::ANCHOR_POINT, "TOP_LEFT" );
3252 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
3254 actor.SetProperty( Actor::Property::ANCHOR_POINT, "TOP_CENTER" );
3255 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
3257 actor.SetProperty( Actor::Property::ANCHOR_POINT, "TOP_RIGHT" );
3258 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
3260 actor.SetProperty( Actor::Property::ANCHOR_POINT, "CENTER_LEFT" );
3261 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::CENTER_LEFT, TEST_LOCATION );
3263 actor.SetProperty( Actor::Property::ANCHOR_POINT, "CENTER" );
3264 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::CENTER, TEST_LOCATION );
3266 actor.SetProperty( Actor::Property::ANCHOR_POINT, "CENTER_RIGHT" );
3267 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::CENTER_RIGHT, TEST_LOCATION );
3269 actor.SetProperty( Actor::Property::ANCHOR_POINT, "BOTTOM_LEFT" );
3270 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::BOTTOM_LEFT, TEST_LOCATION );
3272 actor.SetProperty( Actor::Property::ANCHOR_POINT, "BOTTOM_CENTER" );
3273 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::BOTTOM_CENTER, TEST_LOCATION );
3275 actor.SetProperty( Actor::Property::ANCHOR_POINT, "BOTTOM_RIGHT" );
3276 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::BOTTOM_RIGHT, TEST_LOCATION );
3278 // Invalid should not change anything
3279 actor.SetProperty( Actor::Property::ANCHOR_POINT, "INVALID_ARG" );
3280 DALI_TEST_EQUALS( actor.GetCurrentAnchorPoint(), ParentOrigin::BOTTOM_RIGHT, TEST_LOCATION );
3285 int UtcDaliActorParentOriginPropertyAsString(void)
3287 TestApplication application;
3289 Actor actor = Actor::New();
3291 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "TOP_LEFT" );
3292 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
3294 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "TOP_CENTER" );
3295 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
3297 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "TOP_RIGHT" );
3298 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
3300 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "CENTER_LEFT" );
3301 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::CENTER_LEFT, TEST_LOCATION );
3303 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "CENTER" );
3304 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::CENTER, TEST_LOCATION );
3306 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "CENTER_RIGHT" );
3307 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::CENTER_RIGHT, TEST_LOCATION );
3309 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "BOTTOM_LEFT" );
3310 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::BOTTOM_LEFT, TEST_LOCATION );
3312 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "BOTTOM_CENTER" );
3313 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::BOTTOM_CENTER, TEST_LOCATION );
3315 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "BOTTOM_RIGHT" );
3316 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::BOTTOM_RIGHT, TEST_LOCATION );
3318 // Invalid should not change anything
3319 actor.SetProperty( Actor::Property::PARENT_ORIGIN, "INVALID_ARG" );
3320 DALI_TEST_EQUALS( actor.GetCurrentParentOrigin(), ParentOrigin::BOTTOM_RIGHT, TEST_LOCATION );
3325 int UtcDaliActorColorModePropertyAsString(void)
3327 TestApplication application;
3329 Actor actor = Actor::New();
3331 actor.SetProperty( Actor::Property::COLOR_MODE, "USE_OWN_COLOR" );
3332 DALI_TEST_EQUALS( actor.GetColorMode(), USE_OWN_COLOR, TEST_LOCATION );
3334 actor.SetProperty( Actor::Property::COLOR_MODE, "USE_PARENT_COLOR" );
3335 DALI_TEST_EQUALS( actor.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
3337 actor.SetProperty( Actor::Property::COLOR_MODE, "USE_OWN_MULTIPLY_PARENT_COLOR" );
3338 DALI_TEST_EQUALS( actor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
3340 actor.SetProperty( Actor::Property::COLOR_MODE, "USE_OWN_MULTIPLY_PARENT_ALPHA" );
3341 DALI_TEST_EQUALS( actor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_ALPHA, TEST_LOCATION );
3343 // Invalid should not change anything
3344 actor.SetProperty( Actor::Property::COLOR_MODE, "INVALID_ARG" );
3345 DALI_TEST_EQUALS( actor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_ALPHA, TEST_LOCATION );
3350 int UtcDaliActorPositionInheritancePropertyAsString(void)
3352 TestApplication application;
3354 Actor actor = Actor::New();
3356 actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "INHERIT_PARENT_POSITION" );
3357 DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), INHERIT_PARENT_POSITION, TEST_LOCATION );
3359 actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "USE_PARENT_POSITION" );
3360 DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION, TEST_LOCATION );
3362 actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "USE_PARENT_POSITION_PLUS_LOCAL_POSITION" );
3363 DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION_PLUS_LOCAL_POSITION, TEST_LOCATION );
3365 actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "DONT_INHERIT_POSITION" );
3366 DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
3368 // Invalid should not change anything
3369 actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "INVALID_ARG" );
3370 DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
3375 int UtcDaliActorDrawModePropertyAsString(void)
3377 TestApplication application;
3379 Actor actor = Actor::New();
3381 actor.SetProperty( Actor::Property::DRAW_MODE, "NORMAL" );
3382 DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::NORMAL, TEST_LOCATION );
3384 actor.SetProperty( Actor::Property::DRAW_MODE, "OVERLAY_2D" );
3385 DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
3387 actor.SetProperty( Actor::Property::DRAW_MODE, "STENCIL" );
3388 DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
3390 // Invalid should not change anything
3391 actor.SetProperty( Actor::Property::DRAW_MODE, "INVALID_ARG" );
3392 DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
3397 int UtcDaliActorAddRendererP(void)
3399 tet_infoline("Testing Actor::AddRenderer");
3400 TestApplication application;
3402 Actor actor = Actor::New();
3404 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3406 Geometry geometry = CreateQuadGeometry();
3407 Shader shader = CreateShader();
3408 Renderer renderer = Renderer::New(geometry, shader);
3410 actor.AddRenderer( renderer );
3411 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
3412 DALI_TEST_EQUALS( actor.GetRendererAt(0), renderer, TEST_LOCATION );
3417 int UtcDaliActorAddRendererN(void)
3419 tet_infoline("Testing Actor::AddRenderer");
3420 TestApplication application;
3422 Actor actor = Actor::New();
3428 actor.AddRenderer( renderer );
3429 tet_printf("Assertion test failed - no Exception\n" );
3430 tet_result(TET_FAIL);
3432 catch(Dali::DaliException& e)
3434 DALI_TEST_PRINT_ASSERT( e );
3435 DALI_TEST_ASSERT(e, "Renderer handle is empty", TEST_LOCATION);
3436 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3440 tet_printf("Assertion test failed - wrong Exception\n" );
3441 tet_result(TET_FAIL);
3447 int UtcDaliActorAddRendererOnStage(void)
3449 tet_infoline("Testing Actor::AddRenderer");
3450 TestApplication application;
3452 Actor actor = Actor::New();
3453 Stage::GetCurrent().Add(actor);
3455 application.SendNotification();
3456 application.Render(0);
3458 Geometry geometry = CreateQuadGeometry();
3459 Shader shader = CreateShader();
3460 Renderer renderer = Renderer::New(geometry, shader);
3462 application.SendNotification();
3463 application.Render(0);
3467 actor.AddRenderer( renderer );
3468 tet_result(TET_PASS);
3472 tet_result(TET_FAIL);
3478 int UtcDaliActorRemoveRendererP1(void)
3480 tet_infoline("Testing Actor::RemoveRenderer");
3481 TestApplication application;
3483 Actor actor = Actor::New();
3485 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3487 Geometry geometry = CreateQuadGeometry();
3488 Shader shader = CreateShader();
3489 Renderer renderer = Renderer::New(geometry, shader);
3491 actor.AddRenderer( renderer );
3492 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
3493 DALI_TEST_EQUALS( actor.GetRendererAt(0), renderer, TEST_LOCATION );
3495 actor.RemoveRenderer(renderer);
3496 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3502 int UtcDaliActorRemoveRendererP2(void)
3504 tet_infoline("Testing Actor::RemoveRenderer");
3505 TestApplication application;
3507 Actor actor = Actor::New();
3509 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3511 Geometry geometry = CreateQuadGeometry();
3512 Shader shader = CreateShader();
3513 Renderer renderer = Renderer::New(geometry, shader);
3515 actor.AddRenderer( renderer );
3516 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
3517 DALI_TEST_EQUALS( actor.GetRendererAt(0), renderer, TEST_LOCATION );
3519 actor.RemoveRenderer(0);
3520 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3527 int UtcDaliActorRemoveRendererN(void)
3529 tet_infoline("Testing Actor::RemoveRenderer");
3530 TestApplication application;
3532 Actor actor = Actor::New();
3534 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
3536 Geometry geometry = CreateQuadGeometry();
3537 Shader shader = CreateShader();
3538 Renderer renderer = Renderer::New(geometry, shader);
3540 actor.AddRenderer( renderer );
3541 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
3542 DALI_TEST_EQUALS( actor.GetRendererAt(0), renderer, TEST_LOCATION );
3544 actor.RemoveRenderer(10);
3545 DALI_TEST_EQUALS( actor.GetRendererAt(0), renderer, TEST_LOCATION );
3546 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
3551 // Clipping test helper functions:
3552 Actor CreateActorWithContent()
3554 BufferImage image = BufferImage::New( 16u, 16u );
3555 Actor actor = CreateRenderableActor( image );
3557 // Setup dimensions and position so actor is not skipped by culling.
3558 actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
3559 actor.SetSize( 16.0f, 16.0f );
3560 actor.SetParentOrigin( ParentOrigin::CENTER );
3561 actor.SetAnchorPoint( AnchorPoint::CENTER );
3566 void GenerateTrace( TestApplication& application, TraceCallStack& enabledDisableTrace, TraceCallStack& stencilTrace )
3568 enabledDisableTrace.Reset();
3569 stencilTrace.Reset();
3570 enabledDisableTrace.Enable( true );
3571 stencilTrace.Enable( true );
3573 application.SendNotification();
3574 application.Render();
3576 enabledDisableTrace.Enable( false );
3577 stencilTrace.Enable( false );
3580 void CheckColorMask( TestGlAbstraction& glAbstraction, bool maskValue )
3582 const TestGlAbstraction::ColorMaskParams& colorMaskParams = glAbstraction.GetColorMaskParams();
3584 DALI_TEST_EQUALS<bool>( colorMaskParams.red, maskValue, TEST_LOCATION );
3585 DALI_TEST_EQUALS<bool>( colorMaskParams.green, maskValue, TEST_LOCATION );
3586 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, maskValue, TEST_LOCATION );
3587 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, maskValue, TEST_LOCATION );
3590 int UtcDaliActorPropertyClippingP(void)
3592 // This test checks the clippingMode property.
3593 tet_infoline( "Testing Actor::Property::CLIPPING_MODE P" );
3594 TestApplication application;
3596 Actor actor = Actor::New();
3598 // Check default clippingEnabled value.
3599 Property::Value getValue( actor.GetProperty( Actor::Property::CLIPPING_MODE ) );
3602 bool getValueResult = getValue.Get( value );
3603 DALI_TEST_CHECK( getValueResult );
3605 if( getValueResult )
3607 DALI_TEST_EQUALS<int>( value, ClippingMode::DISABLED, TEST_LOCATION );
3610 // Check setting the property.
3611 actor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
3613 // Check the new value was set.
3614 getValue = actor.GetProperty( Actor::Property::CLIPPING_MODE );
3615 getValueResult = getValue.Get( value );
3616 DALI_TEST_CHECK( getValueResult );
3618 if( getValueResult )
3620 DALI_TEST_EQUALS<int>( value, ClippingMode::CLIP_CHILDREN, TEST_LOCATION );
3626 int UtcDaliActorPropertyClippingN(void)
3628 // Negative test case for Clipping.
3629 tet_infoline( "Testing Actor::Property::CLIPPING_MODE N" );
3630 TestApplication application;
3632 Actor actor = Actor::New();
3634 // Check default clippingEnabled value.
3635 Property::Value getValue( actor.GetProperty( Actor::Property::CLIPPING_MODE ) );
3638 bool getValueResult = getValue.Get( value );
3639 DALI_TEST_CHECK( getValueResult );
3641 if( getValueResult )
3643 DALI_TEST_EQUALS<int>( value, ClippingMode::DISABLED, TEST_LOCATION );
3646 // Check setting an invalid property value won't change the current property value.
3647 actor.SetProperty( Actor::Property::CLIPPING_MODE, "INVALID_PROPERTY" );
3649 getValue = actor.GetProperty( Actor::Property::CLIPPING_MODE );
3650 getValueResult = getValue.Get( value );
3651 DALI_TEST_CHECK( getValueResult );
3653 if( getValueResult )
3655 DALI_TEST_EQUALS<int>( value, ClippingMode::DISABLED, TEST_LOCATION );
3661 int UtcDaliActorPropertyClippingActor(void)
3663 // This test checks that an actor is correctly setup for clipping.
3664 tet_infoline( "Testing Actor::Property::CLIPPING_MODE actor" );
3665 TestApplication application;
3667 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3668 TraceCallStack& stencilTrace = glAbstraction.GetStencilFunctionTrace();
3669 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
3670 size_t startIndex = 0u;
3672 // Create a clipping actor.
3673 Actor actorDepth1Clip = CreateActorWithContent();
3674 actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
3675 Stage::GetCurrent().Add( actorDepth1Clip );
3677 // Gather the call trace.
3678 GenerateTrace( application, enabledDisableTrace, stencilTrace );
3680 // Check we are writing to the color buffer.
3681 CheckColorMask( glAbstraction, true );
3683 // Check the stencil buffer was enabled.
3684 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "2960" ) ); // 2960 is GL_STENCIL_TEST
3686 // Check the stencil buffer was cleared.
3687 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "ClearStencil", "0", startIndex ) );
3689 // Check the correct setup was done to write to the first bit-plane (only) of the stencil buffer.
3690 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc", "514, 1, 0", startIndex ) ); // 514 is GL_EQUAL, But testing no bit-planes for the first clipping node.
3691 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilMask", "1", startIndex ) );
3692 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7681, 7681", startIndex ) ); // GL_KEEP, GL_REPLACE, GL_REPLACE
3697 int UtcDaliActorPropertyClippingNestedChildren(void)
3699 // This test checks that a hierarchy of actors are clipped correctly by
3700 // writing to and reading from the correct bit-planes of the stencil buffer.
3701 tet_infoline( "Testing Actor::Property::CLIPPING_MODE nested children" );
3702 TestApplication application;
3703 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3704 TraceCallStack& stencilTrace = glAbstraction.GetStencilFunctionTrace();
3705 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
3707 // Create a clipping actor.
3708 Actor actorDepth1Clip = CreateActorWithContent();
3709 actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
3710 Stage::GetCurrent().Add( actorDepth1Clip );
3712 // Create a child actor.
3713 Actor childDepth2 = CreateActorWithContent();
3714 actorDepth1Clip.Add( childDepth2 );
3716 // Create another clipping actor.
3717 Actor childDepth2Clip = CreateActorWithContent();
3718 childDepth2Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
3719 childDepth2.Add( childDepth2Clip );
3721 // Create another 2 child actors. We do this so 2 nodes will have the same clipping ID.
3722 // This tests the sort algorithm.
3723 Actor childDepth3 = CreateActorWithContent();
3724 childDepth2Clip.Add( childDepth3 );
3725 Actor childDepth4 = CreateActorWithContent();
3726 childDepth3.Add( childDepth4 );
3728 // Gather the call trace.
3729 GenerateTrace( application, enabledDisableTrace, stencilTrace );
3731 // Check we are writing to the color buffer.
3732 CheckColorMask( glAbstraction, true );
3734 // Check the stencil buffer was enabled.
3735 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "2960" ) ); // 2960 is GL_STENCIL_TEST
3737 // Perform the test twice, once for 2D layer, and once for 3D.
3738 for( unsigned int i = 0u ; i < 2u; ++i )
3740 size_t startIndex = 0u;
3742 // Check the stencil buffer was cleared.
3743 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "ClearStencil", "0", startIndex ) );
3745 // Check the correct setup was done to write to the first bit-plane (only) of the stencil buffer.
3746 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc", "514, 1, 0", startIndex ) ); // 514 is GL_EQUAL, But testing no bit-planes for the first clipping node.
3747 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilMask", "1", startIndex ) ); // Write to the first bit-plane
3748 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7681, 7681", startIndex ) ); // GL_KEEP, GL_REPLACE, GL_REPLACE
3750 // Check the correct setup was done to test against first bit-plane (only) of the stencil buffer.
3751 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc", "514, 1, 255", startIndex ) ); // 514 is GL_EQUAL
3752 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7680, 7680", startIndex ) ); // GL_KEEP, GL_KEEP, GL_KEEP
3754 // Check we are set up to write to the second bitplane of the stencil buffer (only).
3755 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc", "514, 3, 1", startIndex ) ); // 514 is GL_EQUAL, Test both bit-planes 1 & 2
3756 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilMask", "3", startIndex ) ); // Write to second (and previous) bit-planes
3757 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7681, 7681", startIndex ) ); // GL_KEEP, GL_REPLACE, GL_REPLACE
3759 // Check we are set up to test against both the first and second bit-planes of the stencil buffer.
3760 // (Both must be set to pass the check).
3761 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc", "514, 3, 255", startIndex ) ); // 514 is GL_EQUAL, Test both bit-planes 1 & 2
3762 DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7680, 7680", startIndex ) ); // GL_KEEP, GL_KEEP, GL_KEEP
3764 // If we are on the first loop, set the layer to 3D and loop to perform the test again.
3767 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_3D );
3768 GenerateTrace( application, enabledDisableTrace, stencilTrace );
3775 int UtcDaliActorPropertyClippingActorWithRendererOverride(void)
3777 // This test checks that an actor with clipping will be ignored if overridden by the Renderer properties.
3778 tet_infoline( "Testing Actor::Property::CLIPPING_MODE actor with renderer override" );
3779 TestApplication application;
3781 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3782 TraceCallStack& stencilTrace = glAbstraction.GetStencilFunctionTrace();
3783 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
3785 // Create a clipping actor.
3786 Actor actorDepth1Clip = CreateActorWithContent();
3787 actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
3788 Stage::GetCurrent().Add( actorDepth1Clip );
3790 // Turn the RenderMode to just "COLOR" at the Renderer level to ignore the clippingMode.
3791 actorDepth1Clip.GetRendererAt( 0 ).SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
3793 // Gather the call trace.
3794 GenerateTrace( application, enabledDisableTrace, stencilTrace );
3796 // Check we are writing to the color buffer.
3797 CheckColorMask( glAbstraction, true );
3799 // Check the stencil buffer was not enabled.
3800 DALI_TEST_CHECK( !enabledDisableTrace.FindMethodAndParams( "Enable", "2960" ) ); // 2960 is GL_STENCIL_TEST
3802 // Check stencil functions are not called.
3803 DALI_TEST_CHECK( !stencilTrace.FindMethod( "StencilFunc" ) );
3804 DALI_TEST_CHECK( !stencilTrace.FindMethod( "StencilMask" ) );
3805 DALI_TEST_CHECK( !stencilTrace.FindMethod( "StencilOp" ) );