Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ToolBar.cpp
1 /*
2  * Copyright (c) 2022 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 <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/tool-bar/tool-bar.h>
21 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <stdlib.h>
24 #include <iostream>
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 int UtcDaliToolBarNew(void)
67 {
68   ToolkitTestApplication application;
69   tet_infoline(" UtcDaliToolBarNew");
70
71   ToolBar toolbar;
72
73   DALI_TEST_CHECK(!toolbar);
74
75   toolbar = ToolBar::New();
76
77   DALI_TEST_CHECK(toolbar);
78
79   ToolBar toolbar2(toolbar);
80
81   DALI_TEST_CHECK(toolbar2 == toolbar);
82
83   //Additional check to ensure object is created by checking if it's registered
84   ObjectRegistry registry = application.GetCore().GetObjectRegistry();
85   DALI_TEST_CHECK(registry);
86
87   gObjectCreatedCallBackCalled = false;
88   registry.ObjectCreatedSignal().Connect(&TestCallback);
89   {
90     ToolBar toolbar = ToolBar::New();
91   }
92   DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
93
94   Actor actor = toolbar;
95   toolbar     = ToolBar::DownCast(actor);
96
97   DALI_TEST_CHECK(toolbar);
98   END_TEST;
99 }
100
101 int UtcDaliToolBarAddControl01(void)
102 {
103   ToolkitTestApplication application;
104   tet_infoline(" UtcDaliToolBarAddControl01");
105
106   try
107   {
108     Actor control1 = CreateColorActor(Color::RED);
109     control1.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
110     Actor control2 = CreateColorActor(Color::RED);
111     control2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
112     Actor control3 = CreateColorActor(Color::RED);
113     control3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
114     Actor control4 = CreateColorActor(Color::RED);
115     control4.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
116     Actor control5 = CreateColorActor(Color::RED);
117     control5.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
118
119     ToolBar toolbar = ToolBar::New();
120     toolbar.SetProperty(Actor::Property::SIZE, Vector2(600.f, 100.f));
121
122     application.Render();
123     application.SendNotification();
124     application.Render();
125     application.SendNotification();
126
127     toolbar.Add(control1);
128     toolbar.AddControl(control2, 0.1f, Alignment::HORIZONTAL_LEFT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
129     toolbar.AddControl(control3, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
130     toolbar.AddControl(control4, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
131     toolbar.AddControl(control5, 0.1f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
132
133     Actor control6 = CreateColorActor(Color::RED);
134     control6.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
135     Actor control7 = CreateColorActor(Color::RED);
136     control7.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
137     Actor control8 = CreateColorActor(Color::RED);
138     control8.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
139
140     application.Render();
141     application.SendNotification();
142     application.Render();
143     application.SendNotification();
144
145     toolbar.AddControl(control6, 0.4f, Alignment::HORIZONTAL_LEFT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
146     toolbar.AddControl(control7, 0.2f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
147     toolbar.AddControl(control8, 0.2f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
148   }
149   catch(...)
150   {
151     tet_result(TET_FAIL);
152   }
153
154   tet_result(TET_PASS);
155   END_TEST;
156 }
157
158 int UtcDaliToolBarAddControl02(void)
159 {
160   ToolkitTestApplication application;
161   tet_infoline(" UtcDaliToolBarAddControl02");
162
163   bool daliAssert = false;
164
165   try
166   {
167     Actor control = CreateColorActor(Color::RED);
168
169     ToolBar toolbar = ToolBar::New();
170
171     toolbar.AddControl(control, 0.1f, static_cast<Alignment::Type>(99), Alignment::Padding(1.f, 1.f, 1.f, 1.f));
172   }
173   catch(DaliException e)
174   {
175     daliAssert = true;
176     tet_result(TET_PASS);
177   }
178   catch(...)
179   {
180     tet_result(TET_FAIL);
181   }
182
183   if(!daliAssert)
184   {
185     tet_result(TET_FAIL);
186   }
187   END_TEST;
188 }
189
190 int UtcDaliToolBarRemoveControl01(void)
191 {
192   ToolkitTestApplication application;
193   tet_infoline(" UtcDaliToolBarRemoveControl01");
194
195   try
196   {
197     Actor control = CreateColorActor(Color::RED);
198
199     ToolBar toolbar = ToolBar::New();
200     toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
201
202     toolbar.RemoveControl(control);
203   }
204   catch(...)
205   {
206     tet_result(TET_FAIL);
207   }
208
209   tet_result(TET_PASS);
210   END_TEST;
211 }
212
213 int UtcDaliToolBarRemoveControl02(void)
214 {
215   ToolkitTestApplication application;
216   tet_infoline(" UtcDaliToolBarRemoveControl02");
217
218   try
219   {
220     Actor control01 = CreateColorActor(Color::RED);
221     Actor control02 = CreateColorActor(Color::RED);
222
223     ToolBar toolbar01 = ToolBar::New();
224     ToolBar toolbar02 = ToolBar::New();
225     toolbar01.AddControl(control01, 0.1f, Alignment::HORIZONTAL_LEFT);
226     toolbar02.AddControl(control02, 0.1f, Alignment::HORIZONTAL_LEFT);
227
228     toolbar02.RemoveControl(control01);
229   }
230   catch(Dali::DaliException& e)
231   {
232     DALI_TEST_PRINT_ASSERT(e);
233     DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
234   }
235   catch(...)
236   {
237     tet_result(TET_FAIL);
238   }
239
240   try
241   {
242     Actor control = CreateColorActor(Color::RED);
243
244     ToolBar toolbar = ToolBar::New();
245     toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
246
247     toolbar.RemoveControl(control);
248     toolbar.RemoveControl(control);
249   }
250   catch(...)
251   {
252     tet_result(TET_FAIL);
253   }
254
255   tet_result(TET_PASS);
256   END_TEST;
257 }