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