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