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