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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Dali::Toolkit;
34 static bool gObjectCreatedCallBackCalled;
36 static void TestCallback(BaseHandle handle)
38 gObjectCreatedCallBackCalled = true;
43 static void Startup();
44 static void Cleanup();
47 void (*tet_startup)() = Startup;
48 void (*tet_cleanup)() = Cleanup;
52 POSITIVE_TC_IDX = 0x01,
56 #define MAX_NUMBER_OF_TESTS 10000
58 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
61 // Add test functionality for all APIs in the class (Positive and Negative)
62 TEST_FUNCTION( UtcDaliClusterNew, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliClusterDownCast, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliClusterAddAndRemoveChild, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliClusterExpandAndCollapseChild, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliClusterSetAndGetStyle, POSITIVE_TC_IDX );
68 // Called only once before first test is run.
73 // Called only once after last test is run
78 static void UtcDaliClusterNew()
80 ToolkitTestApplication application;
82 // Create the Cluster actor
83 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
84 Cluster cluster = Cluster::New(style);
86 DALI_TEST_CHECK(cluster);
88 //Additional check to ensure object is created by checking if it's registered
89 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
90 DALI_TEST_CHECK( registry );
92 gObjectCreatedCallBackCalled = false;
93 registry.ObjectCreatedSignal().Connect(&TestCallback);
95 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
96 Cluster cluster = Cluster::New(style);
98 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
101 static void UtcDaliClusterDownCast()
103 ToolkitTestApplication application;
105 // Create the Cluster actor
106 ClusterStyle style = ClusterStyleRandom::New();
107 const Cluster clusterConst = Cluster::New(style);
108 Cluster cluster(clusterConst);
110 BaseHandle handle(cluster);
112 Cluster newCluster = Cluster::DownCast( handle );
113 DALI_TEST_CHECK( cluster );
114 DALI_TEST_CHECK( newCluster == cluster );
117 static void UtcDaliClusterAddAndRemoveChild()
119 ToolkitTestApplication application;
121 // Create the Cluster actor
122 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
123 Cluster cluster = Cluster::New(style);
125 Actor childActor1 = Actor::New();
126 Actor childActor2 = Actor::New();
127 Actor childActor3 = Actor::New();
128 Actor childActor4 = Actor::New();
130 // Add the first child and check it is added to the end
131 cluster.AddChild(childActor1);
132 DALI_TEST_CHECK( cluster.GetChildAt(0) == childActor1);
133 DALI_TEST_CHECK( !cluster.GetChildAt(1) );
134 DALI_TEST_CHECK( cluster.GetTotalCount() == 1 );
136 // Add the second child to the given position and check it is added
137 cluster.AddChild(childActor2, 1);
138 DALI_TEST_CHECK( cluster.GetChildAt(1) == childActor2);
139 DALI_TEST_CHECK( cluster.GetTotalCount() == 2 );
141 // Add the third child with depth index 1 and check it is added to the end
142 cluster.AddChildAt(childActor3, 1);
143 DALI_TEST_CHECK( cluster.GetChildAt(2) == childActor3);
144 DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
146 // Add the fourth child with depth index 2 to the given position and check it is added
147 cluster.AddChildAt(childActor4, 2, 3);
148 DALI_TEST_CHECK( cluster.GetChildAt(3) == childActor4);
149 DALI_TEST_CHECK( cluster.GetTotalCount() == 4 );
151 // Remove the child in the given position and check it's removed
152 cluster.RemoveChildAt(3);
153 DALI_TEST_CHECK( !cluster.GetChildAt(3) );
154 DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
157 static void UtcDaliClusterExpandAndCollapseChild()
159 ToolkitTestApplication application;
161 // Create the Cluster actor
162 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
163 Cluster cluster = Cluster::New(style);
165 Actor childActor1 = Actor::New();
166 Actor childActor2 = Actor::New();
167 Actor childActor3 = Actor::New();
168 Actor childActor4 = Actor::New();
170 // Add the child actors
171 cluster.AddChild(childActor1);
172 cluster.AddChild(childActor2);
173 cluster.AddChildAt(childActor3, 1);
174 cluster.AddChildAt(childActor4, 2, 3);
176 // Expand child actor 3
177 cluster.ExpandChild(2);
178 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
180 // Expand child actor 4
181 cluster.ExpandChild(3);
182 DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
184 // Collapse child actor 3
185 cluster.CollapseChild(2);
186 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
188 // Expand all children
189 cluster.ExpandAllChildren();
190 DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
192 // Collpase all children
193 cluster.CollapseAllChildren();
194 DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
196 // Transform and restore the child
197 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);
198 cluster.RestoreChild(1, AlphaFunctions::EaseOut, 0.25f, true);
201 static void UtcDaliClusterSetAndGetStyle()
203 ToolkitTestApplication application;
205 // Create the default cluster style
206 ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
207 DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
209 // Add style to background and title
210 Actor background = Actor::New();
211 Actor title = Actor::New();
212 defaultStyle.ApplyStyleToBackground(background, AlphaFunctions::EaseOut, 1.0f);
213 defaultStyle.ApplyStyleToTitle(title, AlphaFunctions::EaseOut, 1.0f);
215 // Create the Cluster actor with the default style
216 Cluster cluster = Cluster::New(defaultStyle);
217 DALI_TEST_CHECK( cluster.GetStyle() == defaultStyle );
218 cluster.SetBackgroundImage(background);
219 cluster.SetTitle(title);
221 // Create a new style and apply it to the cluster
222 ClusterStyle newStyle = ClusterStyleRandom::New();
223 cluster.SetStyle(newStyle);
224 DALI_TEST_CHECK( cluster.GetStyle() == newStyle );