Merge "Klockwork fixes: Distance field iteration Checking for null...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-Constraint.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22
23 #include <dali-test-suite-utils.h>
24 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
25
26 using namespace Dali;
27
28 using Dali::Internal::SceneGraph::ConstraintBase;
29
30 int UtcDaliConstraintNewInput1OffStage(void)
31 {
32   /**
33    * Test that the Constraint is correctly added/removed when an object
34    * providing the input property is added/removed from the stage
35    */
36   TestApplication application;
37
38   Actor parent = Actor::New();
39   Stage::GetCurrent().Add( parent );
40
41   Actor actor = Actor::New();
42   parent.Add( actor );
43
44   Actor sibling1 = Actor::New();
45   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
46   parent.Add( sibling1 );
47
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 );
51
52   /**
53    * Test that the Constraint is correctly applied on a clean Node
54    */
55   application.SendNotification();
56   application.Render(0);
57   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
58
59   // Apply constraint with a parent input property
60
61   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
62                                                     Source( sibling1, Actor::POSITION ),
63                                                     EqualToConstraint() );
64
65   actor.ApplyConstraint( constraint );
66   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
67
68   application.SendNotification();
69   application.Render(0);
70   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::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 );
73
74   // Remove sibling1 providing the input property
75
76   parent.Remove( sibling1 );
77   actor.SetPosition( Vector3(2.0f, 2.0f, 2.0f) ); // This should be effective
78
79   application.SendNotification();
80   application.Render(0);
81   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::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 );
84
85   // Add sibling1 back again (re-enables constraint)
86
87   parent.Add( sibling1 );
88   actor.SetPosition( Vector3(3.0f, 3.0f, 3.0f) ); // This should NOT be effective
89
90   application.SendNotification();
91   application.Render(0);
92   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::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 );
95
96   END_TEST;
97 }
98