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