2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28 using Dali::Internal::SceneGraph::ConstraintBase;
30 int UtcDaliConstraintNewInput1OffStage(void)
33 * Test that the Constraint is correctly added/removed when an object
34 * providing the input property is added/removed from the stage
36 TestApplication application;
38 Actor parent = Actor::New();
39 Stage::GetCurrent().Add( parent );
41 Actor actor = Actor::New();
44 Actor sibling1 = Actor::New();
45 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
46 parent.Add( sibling1 );
48 Vector3 startValue( 0.0f, 0.0f, 0.0f );
49 DALI_TEST_EQUALS( 0u, ConstraintBase::GetCurrentInstanceCount(), TEST_LOCATION );
50 DALI_TEST_EQUALS( 0u, ConstraintBase::GetTotalInstanceCount(), TEST_LOCATION );
53 * Test that the Constraint is correctly applied on a clean Node
55 application.SendNotification();
56 application.Render(0);
57 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
59 // Apply constraint with a parent input property
61 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
62 Source( sibling1, Actor::Property::POSITION ),
63 EqualToConstraint() );
65 actor.ApplyConstraint( constraint );
66 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
68 application.SendNotification();
69 application.Render(0);
70 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(1.0f, 2.0f, 3.0f)/*from sibling1*/, TEST_LOCATION );
71 DALI_TEST_EQUALS( 1u, ConstraintBase::GetCurrentInstanceCount(), TEST_LOCATION );
72 DALI_TEST_EQUALS( 1u, ConstraintBase::GetTotalInstanceCount(), TEST_LOCATION );
74 // Remove sibling1 providing the input property
76 parent.Remove( sibling1 );
77 actor.SetPosition( Vector3(2.0f, 2.0f, 2.0f) ); // This should be effective
79 application.SendNotification();
80 application.Render(0);
81 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(2.0f, 2.0f, 2.0f)/*from SetPosition*/, TEST_LOCATION );
82 DALI_TEST_EQUALS( 0u/*should have been removed*/, ConstraintBase::GetCurrentInstanceCount(), TEST_LOCATION );
83 DALI_TEST_EQUALS( 1u, ConstraintBase::GetTotalInstanceCount(), TEST_LOCATION );
85 // Add sibling1 back again (re-enables constraint)
87 parent.Add( sibling1 );
88 actor.SetPosition( Vector3(3.0f, 3.0f, 3.0f) ); // This should NOT be effective
90 application.SendNotification();
91 application.Render(0);
92 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(1.0f, 2.0f, 3.0f)/*from sibling1*/, TEST_LOCATION );
93 DALI_TEST_EQUALS( 1u, ConstraintBase::GetCurrentInstanceCount(), TEST_LOCATION );
94 DALI_TEST_EQUALS( 2u/*recreated once*/, ConstraintBase::GetTotalInstanceCount(), TEST_LOCATION );