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