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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
25 using namespace Dali::Toolkit;
30 static bool gObjectCreatedCallBackCalled;
32 static void TestCallback(BaseHandle handle)
34 gObjectCreatedCallBackCalled = true;
40 void cluster_startup(void)
42 test_return_value = TET_UNDEF;
45 void cluster_cleanup(void)
47 test_return_value = TET_PASS;
50 int UtcDaliClusterNew(void)
52 ToolkitTestApplication application;
54 // Create the Cluster actor
55 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
56 Cluster cluster = Cluster::New(style);
58 DALI_TEST_CHECK(cluster);
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 );
64 gObjectCreatedCallBackCalled = false;
65 registry.ObjectCreatedSignal().Connect(&TestCallback);
67 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
68 Cluster cluster = Cluster::New(style);
70 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
74 int UtcDaliClusterDownCast(void)
76 ToolkitTestApplication application;
78 // Create the Cluster actor
79 ClusterStyle style = ClusterStyleRandom::New();
80 const Cluster clusterConst = Cluster::New(style);
81 Cluster cluster(clusterConst);
83 BaseHandle handle(cluster);
85 Cluster newCluster = Cluster::DownCast( handle );
86 DALI_TEST_CHECK( cluster );
87 DALI_TEST_CHECK( newCluster == cluster );
91 int UtcDaliClusterAddAndRemoveChild(void)
93 ToolkitTestApplication application;
95 // Create the Cluster actor
96 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
97 Cluster cluster = Cluster::New(style);
99 Actor childActor1 = Actor::New();
100 Actor childActor2 = Actor::New();
101 Actor childActor3 = Actor::New();
102 Actor childActor4 = Actor::New();
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 );
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 );
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 );
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 );
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 );
132 int UtcDaliClusterExpandAndCollapseChild(void)
134 ToolkitTestApplication application;
136 // Create the Cluster actor
137 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
138 Cluster cluster = Cluster::New(style);
140 Actor childActor1 = Actor::New();
141 Actor childActor2 = Actor::New();
142 Actor childActor3 = Actor::New();
143 Actor childActor4 = Actor::New();
145 // Add the child actors
146 cluster.AddChild(childActor1);
147 cluster.AddChild(childActor2);
148 cluster.AddChildAt(childActor3, 1);
149 cluster.AddChildAt(childActor4, 2, 3);
151 // Expand child actor 3
152 cluster.ExpandChild(2);
153 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
155 // Expand child actor 4
156 cluster.ExpandChild(3);
157 DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
159 // Collapse child actor 3
160 cluster.CollapseChild(2);
161 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
163 // Expand all children
164 cluster.ExpandAllChildren();
165 DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
167 // Collpase all children
168 cluster.CollapseAllChildren();
169 DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
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);
177 int UtcDaliClusterSetAndGetStyle(void)
179 ToolkitTestApplication application;
181 // Create the default cluster style
182 ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
183 DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
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);
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);
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 );