Add Wayland support.
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / cluster / 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
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29 using namespace Dali::Toolkit;
30
31 namespace
32 {
33
34 static bool gObjectCreatedCallBackCalled;
35
36 static void TestCallback(BaseHandle handle)
37 {
38   gObjectCreatedCallBackCalled = true;
39 }
40
41 } // namespace
42
43 static void Startup();
44 static void Cleanup();
45
46 extern "C" {
47   void (*tet_startup)() = Startup;
48   void (*tet_cleanup)() = Cleanup;
49 }
50
51 enum {
52   POSITIVE_TC_IDX = 0x01,
53   NEGATIVE_TC_IDX,
54 };
55
56 #define MAX_NUMBER_OF_TESTS 10000
57 extern "C" {
58   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
59 }
60
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 );
67
68 // Called only once before first test is run.
69 static void Startup()
70 {
71 }
72
73 // Called only once after last test is run
74 static void Cleanup()
75 {
76 }
77
78 static void UtcDaliClusterNew()
79 {
80   ToolkitTestApplication application;
81
82   // Create the Cluster actor
83   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
84   Cluster cluster = Cluster::New(style);
85
86   DALI_TEST_CHECK(cluster);
87
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 );
91
92   gObjectCreatedCallBackCalled = false;
93   registry.ObjectCreatedSignal().Connect(&TestCallback);
94   {
95     ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
96     Cluster cluster = Cluster::New(style);
97   }
98   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
99 }
100
101 static void UtcDaliClusterDownCast()
102 {
103   ToolkitTestApplication application;
104
105   // Create the Cluster actor
106   ClusterStyle style = ClusterStyleRandom::New();
107   const Cluster clusterConst = Cluster::New(style);
108   Cluster cluster(clusterConst);
109
110   BaseHandle handle(cluster);
111
112   Cluster newCluster = Cluster::DownCast( handle );
113   DALI_TEST_CHECK( cluster );
114   DALI_TEST_CHECK( newCluster == cluster );
115 }
116
117 static void UtcDaliClusterAddAndRemoveChild()
118 {
119   ToolkitTestApplication application;
120
121   // Create the Cluster actor
122   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
123   Cluster cluster = Cluster::New(style);
124
125   Actor childActor1 = Actor::New();
126   Actor childActor2 = Actor::New();
127   Actor childActor3 = Actor::New();
128   Actor childActor4 = Actor::New();
129
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 );
135
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 );
140
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 );
145
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 );
150
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 );
155 }
156
157 static void UtcDaliClusterExpandAndCollapseChild()
158 {
159   ToolkitTestApplication application;
160
161   // Create the Cluster actor
162   ClusterStyle style = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
163   Cluster cluster = Cluster::New(style);
164
165   Actor childActor1 = Actor::New();
166   Actor childActor2 = Actor::New();
167   Actor childActor3 = Actor::New();
168   Actor childActor4 = Actor::New();
169
170   // Add the child actors
171   cluster.AddChild(childActor1);
172   cluster.AddChild(childActor2);
173   cluster.AddChildAt(childActor3, 1);
174   cluster.AddChildAt(childActor4, 2, 3);
175
176   // Expand child actor 3
177   cluster.ExpandChild(2);
178   DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
179
180   // Expand child actor 4
181   cluster.ExpandChild(3);
182   DALI_TEST_CHECK( cluster.GetExpandedCount() == 2 );
183
184   // Collapse child actor 3
185   cluster.CollapseChild(2);
186   DALI_TEST_CHECK( cluster.GetExpandedCount() == 1 );
187
188   // Expand all children
189   cluster.ExpandAllChildren();
190   DALI_TEST_CHECK( cluster.GetExpandedCount() == 4 );
191
192   // Collpase all children
193   cluster.CollapseAllChildren();
194   DALI_TEST_CHECK( cluster.GetExpandedCount() == 0 );
195
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);
199 }
200
201 static void UtcDaliClusterSetAndGetStyle()
202 {
203   ToolkitTestApplication application;
204
205   // Create the default cluster style
206   ClusterStyle defaultStyle = ClusterStyleStandard::New(ClusterStyleStandard::ClusterStyle1);
207   DALI_TEST_CHECK( defaultStyle.GetMaximumNumberOfChildren() > 0 );
208
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);
214
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);
220
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 );
225 }