License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / toolbar / utc-Dali-ToolBar.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/integration-api/events/touch-event-integ.h>
24 #include <dali/dali.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 static void Startup();
32 static void Cleanup();
33
34 namespace
35 {
36 static bool gObjectCreatedCallBackCalled;
37
38 static void TestCallback(BaseHandle handle)
39 {
40   gObjectCreatedCallBackCalled = true;
41 }
42 } // namespace
43
44 extern "C" {
45   void (*tet_startup)() = Startup;
46   void (*tet_cleanup)() = Cleanup;
47 }
48
49 enum {
50   POSITIVE_TC_IDX = 0x01,
51   NEGATIVE_TC_IDX,
52 };
53
54 #define MAX_NUMBER_OF_TESTS 10000
55 extern "C" {
56   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
57 }
58
59 // Add test functionality for all APIs in the class (Positive and Negative)
60 TEST_FUNCTION( UtcDaliToolBarNew, POSITIVE_TC_IDX );
61 TEST_FUNCTION( UtcDaliToolBarSetBackground, POSITIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliToolBarAddControl01, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliToolBarAddControl02, NEGATIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliToolBarRemoveControl01, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliToolBarRemoveControl02, NEGATIVE_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
78 static void UtcDaliToolBarNew()
79 {
80   ToolkitTestApplication application;
81   tet_infoline(" UtcDaliToolBarNew");
82
83   ToolBar toolbar;
84
85   DALI_TEST_CHECK( !toolbar );
86
87   toolbar = ToolBar::New();
88
89   DALI_TEST_CHECK( toolbar );
90
91   ToolBar toolbar2(toolbar);
92
93   DALI_TEST_CHECK( toolbar2 == toolbar );
94
95   //Additional check to ensure object is created by checking if it's registered
96   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
97   DALI_TEST_CHECK( registry );
98
99   gObjectCreatedCallBackCalled = false;
100   registry.ObjectCreatedSignal().Connect(&TestCallback);
101   {
102     ToolBar toolbar = ToolBar::New();
103   }
104   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
105
106   Actor actor = toolbar;
107   toolbar == ToolBar::DownCast( actor );
108
109   DALI_TEST_CHECK( toolbar );
110 }
111
112 static void UtcDaliToolBarSetBackground()
113 {
114   ToolkitTestApplication application;
115   tet_infoline(" UtcDaliToolBarSetBackground");
116
117   try
118   {
119     ImageActor toolBarBackground = CreateSolidColorActor( Color::RED );
120
121     ToolBar toolbar = ToolBar::New();
122     toolbar.SetBackground( toolBarBackground );
123
124     Stage::GetCurrent().Add( toolbar );
125   }
126   catch( ... )
127   {
128     tet_result(TET_FAIL);
129   }
130
131   tet_result(TET_PASS);
132
133   application.SendNotification(); // VCC To be removed!!
134   application.Render();     // VCC To be removed!!
135 }
136
137 static void UtcDaliToolBarAddControl01()
138 {
139   ToolkitTestApplication application;
140   tet_infoline(" UtcDaliToolBarAddControl01");
141
142   try
143   {
144     ImageActor control1 = CreateSolidColorActor( Color::RED );
145     control1.SetSize( 100.f, 100.f );
146     ImageActor control2 = CreateSolidColorActor( Color::RED );
147     control2.SetSize( 100.f, 100.f );
148     ImageActor control3 = CreateSolidColorActor( Color::RED );
149     control3.SetSize( 100.f, 100.f );
150     ImageActor control4 = CreateSolidColorActor( Color::RED );
151     control4.SetSize( 100.f, 100.f );
152     ImageActor control5 = CreateSolidColorActor( Color::RED );
153     control5.SetSize( 100.f, 100.f );
154
155     ToolBar toolbar = ToolBar::New();
156     toolbar.SetSize( 600.f, 100.f );
157
158     application.Render();
159     application.SendNotification();
160     application.Render();
161     application.SendNotification();
162
163     toolbar.Add( control1 );
164     toolbar.AddControl( control2, 0.1f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
165     toolbar.AddControl( control3, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
166     toolbar.AddControl( control4, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
167     toolbar.AddControl( control5, 0.1f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
168
169     ImageActor control6 = CreateSolidColorActor( Color::RED );
170     control6.SetSize( 100.f, 100.f );
171     ImageActor control7 = CreateSolidColorActor( Color::RED );
172     control7.SetSize( 100.f, 100.f );
173     ImageActor control8 = CreateSolidColorActor( Color::RED );
174     control8.SetSize( 100.f, 100.f );
175
176     application.Render();
177     application.SendNotification();
178     application.Render();
179     application.SendNotification();
180
181     toolbar.AddControl( control6, 0.4f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
182     toolbar.AddControl( control7, 0.2f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
183     toolbar.AddControl( control8, 0.2f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
184   }
185   catch( ... )
186   {
187     tet_result(TET_FAIL);
188   }
189
190   tet_result(TET_PASS);
191 }
192
193 static void UtcDaliToolBarAddControl02()
194 {
195   ToolkitTestApplication application;
196   tet_infoline(" UtcDaliToolBarAddControl02");
197
198   bool daliAssert = false;
199
200   try
201   {
202     ImageActor control = CreateSolidColorActor( Color::RED );
203
204     ToolBar toolbar = ToolBar::New();
205
206     toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
207   }
208   catch( DaliException e )
209   {
210     daliAssert = true;
211     tet_result(TET_PASS);
212   }
213   catch( ... )
214   {
215     tet_result(TET_FAIL);
216   }
217
218   if( !daliAssert )
219   {
220     tet_result(TET_FAIL);
221   }
222 }
223
224 static void UtcDaliToolBarRemoveControl01()
225 {
226   ToolkitTestApplication application;
227   tet_infoline(" UtcDaliToolBarRemoveControl01");
228
229   try
230   {
231     ImageActor control = CreateSolidColorActor( Color::RED );
232
233     ToolBar toolbar = ToolBar::New();
234     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
235
236     toolbar.RemoveControl( control );
237   }
238   catch( ... )
239   {
240     tet_result(TET_FAIL);
241   }
242
243   tet_result(TET_PASS);
244 }
245
246 static void UtcDaliToolBarRemoveControl02()
247 {
248   ToolkitTestApplication application;
249   tet_infoline(" UtcDaliToolBarRemoveControl02");
250
251   try
252   {
253     ImageActor control01 = CreateSolidColorActor( Color::RED );
254     ImageActor control02 = CreateSolidColorActor( Color::RED );
255
256     ToolBar toolbar01 = ToolBar::New();
257     ToolBar toolbar02 = ToolBar::New();
258     toolbar01.AddControl( control01, 0.1f, Alignment::HorizontalLeft );
259     toolbar02.AddControl( control02, 0.1f, Alignment::HorizontalLeft );
260
261     toolbar02.RemoveControl( control01 );
262   }
263   catch( Dali::DaliException& e )
264   {
265     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
266     DALI_TEST_EQUALS(e.mCondition, "false", TEST_LOCATION);
267   }
268   catch( ... )
269   {
270     tet_result(TET_FAIL);
271   }
272
273   try
274   {
275     ImageActor control = CreateSolidColorActor( Color::RED );
276
277     ToolBar toolbar = ToolBar::New();
278     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
279
280     toolbar.RemoveControl( control );
281     toolbar.RemoveControl( control );
282   }
283   catch( ... )
284   {
285     tet_result(TET_FAIL);
286   }
287
288   tet_result(TET_PASS);
289 }