(AutomatedTests) Synchronise TestSingletonService with Adaptor
[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 UtcDaliToolBarAddControl01(void)
85 {
86   ToolkitTestApplication application;
87   tet_infoline(" UtcDaliToolBarAddControl01");
88
89   try
90   {
91     ImageActor control1 = CreateSolidColorActor( Color::RED );
92     control1.SetSize( Vector2( 100.f, 100.f ) );
93     ImageActor control2 = CreateSolidColorActor( Color::RED );
94     control2.SetSize( Vector2( 100.f, 100.f ) );
95     ImageActor control3 = CreateSolidColorActor( Color::RED );
96     control3.SetSize( Vector2( 100.f, 100.f ) );
97     ImageActor control4 = CreateSolidColorActor( Color::RED );
98     control4.SetSize( Vector2( 100.f, 100.f ) );
99     ImageActor control5 = CreateSolidColorActor( Color::RED );
100     control5.SetSize( Vector2( 100.f, 100.f ) );
101
102     ToolBar toolbar = ToolBar::New();
103     toolbar.SetSize( Vector2( 600.f, 100.f ) );
104
105     application.Render();
106     application.SendNotification();
107     application.Render();
108     application.SendNotification();
109
110     toolbar.Add( control1 );
111     toolbar.AddControl( control2, 0.1f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
112     toolbar.AddControl( control3, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
113     toolbar.AddControl( control4, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
114     toolbar.AddControl( control5, 0.1f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
115
116     ImageActor control6 = CreateSolidColorActor( Color::RED );
117     control6.SetSize( Vector2( 100.f, 100.f ) );
118     ImageActor control7 = CreateSolidColorActor( Color::RED );
119     control7.SetSize( Vector2( 100.f, 100.f ) );
120     ImageActor control8 = CreateSolidColorActor( Color::RED );
121     control8.SetSize( Vector2( 100.f, 100.f ) );
122
123     application.Render();
124     application.SendNotification();
125     application.Render();
126     application.SendNotification();
127
128     toolbar.AddControl( control6, 0.4f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
129     toolbar.AddControl( control7, 0.2f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
130     toolbar.AddControl( control8, 0.2f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
131   }
132   catch( ... )
133   {
134     tet_result(TET_FAIL);
135   }
136
137   tet_result(TET_PASS);
138   END_TEST;
139 }
140
141 int UtcDaliToolBarAddControl02(void)
142 {
143   ToolkitTestApplication application;
144   tet_infoline(" UtcDaliToolBarAddControl02");
145
146   bool daliAssert = false;
147
148   try
149   {
150     ImageActor control = CreateSolidColorActor( Color::RED );
151
152     ToolBar toolbar = ToolBar::New();
153
154     toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
155   }
156   catch( DaliException e )
157   {
158     daliAssert = true;
159     tet_result(TET_PASS);
160   }
161   catch( ... )
162   {
163     tet_result(TET_FAIL);
164   }
165
166   if( !daliAssert )
167   {
168     tet_result(TET_FAIL);
169   }
170   END_TEST;
171 }
172
173 int UtcDaliToolBarRemoveControl01(void)
174 {
175   ToolkitTestApplication application;
176   tet_infoline(" UtcDaliToolBarRemoveControl01");
177
178   try
179   {
180     ImageActor control = CreateSolidColorActor( Color::RED );
181
182     ToolBar toolbar = ToolBar::New();
183     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
184
185     toolbar.RemoveControl( control );
186   }
187   catch( ... )
188   {
189     tet_result(TET_FAIL);
190   }
191
192   tet_result(TET_PASS);
193   END_TEST;
194 }
195
196 int UtcDaliToolBarRemoveControl02(void)
197 {
198   ToolkitTestApplication application;
199   tet_infoline(" UtcDaliToolBarRemoveControl02");
200
201   try
202   {
203     ImageActor control01 = CreateSolidColorActor( Color::RED );
204     ImageActor control02 = CreateSolidColorActor( Color::RED );
205
206     ToolBar toolbar01 = ToolBar::New();
207     ToolBar toolbar02 = ToolBar::New();
208     toolbar01.AddControl( control01, 0.1f, Alignment::HorizontalLeft );
209     toolbar02.AddControl( control02, 0.1f, Alignment::HorizontalLeft );
210
211     toolbar02.RemoveControl( control01 );
212   }
213   catch( Dali::DaliException& e )
214   {
215     DALI_TEST_PRINT_ASSERT( e );
216     DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
217   }
218   catch( ... )
219   {
220     tet_result(TET_FAIL);
221   }
222
223   try
224   {
225     ImageActor control = CreateSolidColorActor( Color::RED );
226
227     ToolBar toolbar = ToolBar::New();
228     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
229
230     toolbar.RemoveControl( control );
231     toolbar.RemoveControl( control );
232   }
233   catch( ... )
234   {
235     tet_result(TET_FAIL);
236   }
237
238   tet_result(TET_PASS);
239   END_TEST;
240 }