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