2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Dali::Toolkit;
29 static bool gObjectCreatedCallBackCalled;
31 static void TestCallback(BaseHandle handle)
33 gObjectCreatedCallBackCalled = true;
39 void cluster_startup(void)
41 test_return_value = TET_UNDEF;
44 void cluster_cleanup(void)
46 test_return_value = TET_PASS;
49 int UtcDaliClusterNew(void)
51 ToolkitTestApplication application;
53 // Create the Cluster actor
54 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
55 Cluster cluster = Cluster::New(style);
57 DALI_TEST_CHECK(cluster);
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 );
63 gObjectCreatedCallBackCalled = false;
64 registry.ObjectCreatedSignal().Connect(&TestCallback);
66 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
67 Cluster cluster = Cluster::New(style);
69 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
73 int UtcDaliClusterDownCast(void)
75 ToolkitTestApplication application;
77 // Create the Cluster actor
78 ClusterStyle style = ClusterStyleRandom::New();
79 const Cluster clusterConst = Cluster::New(style);
80 Cluster cluster(clusterConst);
82 BaseHandle handle(cluster);
84 Cluster newCluster = Cluster::DownCast( handle );
85 DALI_TEST_CHECK( cluster );
86 DALI_TEST_CHECK( newCluster == cluster );
90 int UtcDaliClusterAddAndRemoveChild(void)
92 ToolkitTestApplication application;
94 // Create the Cluster actor
95 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
96 Cluster cluster = Cluster::New(style);
98 Actor childActor1 = Actor::New();
99 Actor childActor2 = Actor::New();
100 Actor childActor3 = Actor::New();
101 Actor childActor4 = Actor::New();
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 );
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 );
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 );
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 );
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 );
131 int UtcDaliClusterExpandAndCollapseChild(void)
133 ToolkitTestApplication application;
135 // Create the Cluster actor
136 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
137 Cluster cluster = Cluster::New(style);
139 Actor childActor1 = Actor::New();
140 Actor childActor2 = Actor::New();
141 Actor childActor3 = Actor::New();
142 Actor childActor4 = Actor::New();
144 // Add the child actors
145 cluster.AddChild(childActor1);
146 cluster.AddChild(childActor2);
147 cluster.AddChildAt(childActor3, 1);
148 cluster.AddChildAt(childActor4, 2, 3);
150 // Expand child actor 3
151 cluster.ExpandChild(2);
152 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
154 // Expand child actor 4
155 cluster.ExpandChild(3);
156 DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
158 // Collapse child actor 3
159 cluster.CollapseChild(2);
160 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
162 // Expand all children
163 cluster.ExpandAllChildren();
164 DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
166 // Collpase all children
167 cluster.CollapseAllChildren();
168 DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
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);
176 int UtcDaliClusterSetAndGetStyle(void)
178 ToolkitTestApplication application;
180 // Create the default cluster style
181 ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
182 DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
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);
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);
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 );