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