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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
28 using namespace Dali::Toolkit;
33 static bool gObjectCreatedCallBackCalled;
35 static void TestCallback(BaseHandle handle)
37 gObjectCreatedCallBackCalled = true;
42 static void Startup();
43 static void Cleanup();
46 void (*tet_startup)() = Startup;
47 void (*tet_cleanup)() = Cleanup;
51 POSITIVE_TC_IDX = 0x01,
55 #define MAX_NUMBER_OF_TESTS 10000
57 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
60 // Add test functionality for all APIs in the class (Positive and Negative)
61 TEST_FUNCTION( UtcDaliClusterNew, POSITIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliClusterDownCast, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliClusterAddAndRemoveChild, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliClusterExpandAndCollapseChild, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliClusterSetAndGetStyle, POSITIVE_TC_IDX );
67 // Called only once before first test is run.
72 // Called only once after last test is run
77 static void UtcDaliClusterNew()
79 ToolkitTestApplication application;
81 // Create the Cluster actor
82 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
83 Cluster cluster = Cluster::New(style);
85 DALI_TEST_CHECK(cluster);
87 //Additional check to ensure object is created by checking if it's registered
88 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
89 DALI_TEST_CHECK( registry );
91 gObjectCreatedCallBackCalled = false;
92 registry.ObjectCreatedSignal().Connect(&TestCallback);
94 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
95 Cluster cluster = Cluster::New(style);
97 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
100 static void UtcDaliClusterDownCast()
102 ToolkitTestApplication application;
104 // Create the Cluster actor
105 ClusterStyle style = ClusterStyleRandom::New();
106 const Cluster clusterConst = Cluster::New(style);
107 Cluster cluster(clusterConst);
109 BaseHandle handle(cluster);
111 Cluster newCluster = Cluster::DownCast( handle );
112 DALI_TEST_CHECK( cluster );
113 DALI_TEST_CHECK( newCluster == cluster );
116 static void UtcDaliClusterAddAndRemoveChild()
118 ToolkitTestApplication application;
120 // Create the Cluster actor
121 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
122 Cluster cluster = Cluster::New(style);
124 Actor childActor1 = Actor::New();
125 Actor childActor2 = Actor::New();
126 Actor childActor3 = Actor::New();
127 Actor childActor4 = Actor::New();
129 // Add the first child and check it is added to the end
130 cluster.AddChild(childActor1);
131 DALI_TEST_CHECK( cluster.GetChildAt(0) == childActor1);
132 DALI_TEST_CHECK( !cluster.GetChildAt(1) );
133 DALI_TEST_CHECK( cluster.GetTotalCount() == 1 );
135 // Add the second child to the given position and check it is added
136 cluster.AddChild(childActor2, 1);
137 DALI_TEST_CHECK( cluster.GetChildAt(1) == childActor2);
138 DALI_TEST_CHECK( cluster.GetTotalCount() == 2 );
140 // Add the third child with depth index 1 and check it is added to the end
141 cluster.AddChildAt(childActor3, 1);
142 DALI_TEST_CHECK( cluster.GetChildAt(2) == childActor3);
143 DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
145 // Add the fourth child with depth index 2 to the given position and check it is added
146 cluster.AddChildAt(childActor4, 2, 3);
147 DALI_TEST_CHECK( cluster.GetChildAt(3) == childActor4);
148 DALI_TEST_CHECK( cluster.GetTotalCount() == 4 );
150 // Remove the child in the given position and check it's removed
151 cluster.RemoveChildAt(3);
152 DALI_TEST_CHECK( !cluster.GetChildAt(3) );
153 DALI_TEST_CHECK( cluster.GetTotalCount() == 3 );
156 static void UtcDaliClusterExpandAndCollapseChild()
158 ToolkitTestApplication application;
160 // Create the Cluster actor
161 ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
162 Cluster cluster = Cluster::New(style);
164 Actor childActor1 = Actor::New();
165 Actor childActor2 = Actor::New();
166 Actor childActor3 = Actor::New();
167 Actor childActor4 = Actor::New();
169 // Add the child actors
170 cluster.AddChild(childActor1);
171 cluster.AddChild(childActor2);
172 cluster.AddChildAt(childActor3, 1);
173 cluster.AddChildAt(childActor4, 2, 3);
175 // Expand child actor 3
176 cluster.ExpandChild(2);
177 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
179 // Expand child actor 4
180 cluster.ExpandChild(3);
181 DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
183 // Collapse child actor 3
184 cluster.CollapseChild(2);
185 DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
187 // Expand all children
188 cluster.ExpandAllChildren();
189 DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
191 // Collpase all children
192 cluster.CollapseAllChildren();
193 DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
195 // Transform and restore the child
196 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);
197 cluster.RestoreChild(1, AlphaFunctions::EaseOut, 0.25f, true);
200 static void UtcDaliClusterSetAndGetStyle()
202 ToolkitTestApplication application;
204 // Create the default cluster style
205 ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
206 DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
208 // Add style to background and title
209 Actor background = Actor::New();
210 Actor title = Actor::New();
211 defaultStyle.ApplyStyleToBackground(background, AlphaFunctions::EaseOut, 1.0f);
212 defaultStyle.ApplyStyleToTitle(title, AlphaFunctions::EaseOut, 1.0f);
214 // Create the Cluster actor with the default style
215 Cluster cluster = Cluster::New(defaultStyle);
216 DALI_TEST_CHECK( cluster.GetStyle() == defaultStyle );
217 cluster.SetBackgroundImage(background);
218 cluster.SetTitle(title);
220 // Create a new style and apply it to the cluster
221 ClusterStyle newStyle = ClusterStyleRandom::New();
222 cluster.SetStyle(newStyle);
223 DALI_TEST_CHECK( cluster.GetStyle() == newStyle );