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