Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-Cluster.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21
22
23 using namespace Dali;
24 using namespace Dali::Toolkit;
25
26 namespace
27 {
28
29 static bool gObjectCreatedCallBackCalled;
30
31 static void TestCallback(BaseHandle handle)
32 {
33   gObjectCreatedCallBackCalled = true;
34 }
35
36 } // namespace
37
38
39 void cluster_startup(void)
40 {
41   test_return_value = TET_UNDEF;
42 }
43
44 void cluster_cleanup(void)
45 {
46   test_return_value = TET_PASS;
47 }
48
49 int UtcDaliClusterNew(void)
50 {
51   ToolkitTestApplication application;
52
53   // Create the Cluster actor
54   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
55   Cluster cluster = Cluster::New(style);
56
57   DALI_TEST_CHECK(cluster);
58
59   //Additional check to ensure object is created by checking if it's registered
60   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
61   DALI_TEST_CHECK( registry );
62
63   gObjectCreatedCallBackCalled = false;
64   registry.ObjectCreatedSignal().Connect(&TestCallback);
65   {
66     ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
67     Cluster cluster = Cluster::New(style);
68   }
69   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
70   END_TEST;
71 }
72
73 int UtcDaliClusterDownCast(void)
74 {
75   ToolkitTestApplication application;
76
77   // Create the Cluster actor
78   ClusterStyle style = ClusterStyleRandom::New();
79   const Cluster clusterConst = Cluster::New(style);
80   Cluster cluster(clusterConst);
81
82   BaseHandle handle(cluster);
83
84   Cluster newCluster = Cluster::DownCast( handle );
85   DALI_TEST_CHECK( cluster );
86   DALI_TEST_CHECK( newCluster == cluster );
87   END_TEST;
88 }
89
90 int UtcDaliClusterAddAndRemoveChild(void)
91 {
92   ToolkitTestApplication application;
93
94   // Create the Cluster actor
95   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
96   Cluster cluster = Cluster::New(style);
97
98   Actor childActor1 = Actor::New();
99   Actor childActor2 = Actor::New();
100   Actor childActor3 = Actor::New();
101   Actor childActor4 = Actor::New();
102
103   // Add the first child and check it is added to the end
104   cluster.AddChild(childActor1);
105   DALI_TEST_CHECK( cluster.GetChildAt(0) == childActor1);
106   DALI_TEST_CHECK( !cluster.GetChildAt(1) );
107   DALI_TEST_CHECK( cluster.GetTotalCount() == 1 );
108
109   // Add the second child to the given position and check it is added
110   cluster.AddChild(childActor2, 1);
111   DALI_TEST_CHECK( cluster.GetChildAt(1) == childActor2);
112   DALI_TEST_CHECK( cluster.GetTotalCount() == 2 );
113
114   // Add the third child with depth index 1 and check it is added to the end
115   cluster.AddChildAt(childActor3, 1);
116   DALI_TEST_CHECK( cluster.GetChildAt(2) == childActor3);
117   DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
118
119   // Add the fourth child with depth index 2 to the given position and check it is added
120   cluster.AddChildAt(childActor4, 2, 3);
121   DALI_TEST_CHECK( cluster.GetChildAt(3) == childActor4);
122   DALI_TEST_CHECK( cluster.GetTotalCount() == 4 );
123
124   // Remove the child in the given position and check it's removed
125   cluster.RemoveChildAt(3);
126   DALI_TEST_CHECK( !cluster.GetChildAt(3) );
127   DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
128   END_TEST;
129 }
130
131 int UtcDaliClusterExpandAndCollapseChild(void)
132 {
133   ToolkitTestApplication application;
134
135   // Create the Cluster actor
136   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
137   Cluster cluster = Cluster::New(style);
138
139   Actor childActor1 = Actor::New();
140   Actor childActor2 = Actor::New();
141   Actor childActor3 = Actor::New();
142   Actor childActor4 = Actor::New();
143
144   // Add the child actors
145   cluster.AddChild(childActor1);
146   cluster.AddChild(childActor2);
147   cluster.AddChildAt(childActor3, 1);
148   cluster.AddChildAt(childActor4, 2, 3);
149
150   // Expand child actor 3
151   cluster.ExpandChild(2);
152   DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
153
154   // Expand child actor 4
155   cluster.ExpandChild(3);
156   DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
157
158   // Collapse child actor 3
159   cluster.CollapseChild(2);
160   DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
161
162   // Expand all children
163   cluster.ExpandAllChildren();
164   DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
165
166   // Collpase all children
167   cluster.CollapseAllChildren();
168   DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
169
170   // Transform and restore the child
171   cluster.TransformChild(1, Vector3(10.0f, 10.0f, 1.0f), Vector3(1.0f, 1.0f, 1.0f), Quaternion(0.0f, Vector3::YAXIS), AlphaFunctions::EaseOut, 0.5f);
172   cluster.RestoreChild(1, AlphaFunctions::EaseOut, 0.25f, true);
173   END_TEST;
174 }
175
176 int UtcDaliClusterSetAndGetStyle(void)
177 {
178   ToolkitTestApplication application;
179
180   // Create the default cluster style
181   ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
182   DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
183
184   // Add style to background and title
185   Actor background = Actor::New();
186   Actor title = Actor::New();
187   defaultStyle.ApplyStyleToBackground(background, AlphaFunctions::EaseOut, 1.0f);
188   defaultStyle.ApplyStyleToTitle(title, AlphaFunctions::EaseOut, 1.0f);
189
190   // Create the Cluster actor with the default style
191   Cluster cluster = Cluster::New(defaultStyle);
192   DALI_TEST_CHECK( cluster.GetStyle() == defaultStyle );
193   cluster.SetBackgroundImage(background);
194   cluster.SetTitle(title);
195
196   // Create a new style and apply it to the cluster
197   ClusterStyle newStyle = ClusterStyleRandom::New();
198   cluster.SetStyle(newStyle);
199   DALI_TEST_CHECK( cluster.GetStyle() == newStyle );
200   END_TEST;
201 }