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