2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
25 #include "dummy-control.h"
28 using namespace Toolkit;
32 static bool gObjectCreatedCallBackCalled;
34 static void TestCallback(BaseHandle handle)
36 gObjectCreatedCallBackCalled = true;
39 Actor CreateColorActor(const Vector4& color)
41 DummyControl solidColorActor = DummyControl::New();
42 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(solidColorActor.GetImplementation());
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);
51 return solidColorActor;
56 void dali_toolbar_startup(void)
58 test_return_value = TET_UNDEF;
61 void dali_toolbar_cleanup(void)
63 test_return_value = TET_PASS;
66 int UtcDaliToolBarNew(void)
68 ToolkitTestApplication application;
69 tet_infoline(" UtcDaliToolBarNew");
73 DALI_TEST_CHECK(!toolbar);
75 toolbar = ToolBar::New();
77 DALI_TEST_CHECK(toolbar);
79 ToolBar toolbar2(toolbar);
81 DALI_TEST_CHECK(toolbar2 == toolbar);
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);
87 gObjectCreatedCallBackCalled = false;
88 registry.ObjectCreatedSignal().Connect(&TestCallback);
90 ToolBar toolbar = ToolBar::New();
92 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
94 Actor actor = toolbar;
95 toolbar = ToolBar::DownCast(actor);
97 DALI_TEST_CHECK(toolbar);
101 int UtcDaliToolBarAddControl01(void)
103 ToolkitTestApplication application;
104 tet_infoline(" UtcDaliToolBarAddControl01");
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));
119 ToolBar toolbar = ToolBar::New();
120 toolbar.SetProperty(Actor::Property::SIZE, Vector2(600.f, 100.f));
122 application.Render();
123 application.SendNotification();
124 application.Render();
125 application.SendNotification();
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));
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));
140 application.Render();
141 application.SendNotification();
142 application.Render();
143 application.SendNotification();
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));
151 tet_result(TET_FAIL);
154 tet_result(TET_PASS);
158 int UtcDaliToolBarAddControl02(void)
160 ToolkitTestApplication application;
161 tet_infoline(" UtcDaliToolBarAddControl02");
163 bool daliAssert = false;
167 Actor control = CreateColorActor(Color::RED);
169 ToolBar toolbar = ToolBar::New();
171 toolbar.AddControl(control, 0.1f, static_cast<Alignment::Type>(99), Alignment::Padding(1.f, 1.f, 1.f, 1.f));
173 catch(DaliException e)
176 tet_result(TET_PASS);
180 tet_result(TET_FAIL);
185 tet_result(TET_FAIL);
190 int UtcDaliToolBarRemoveControl01(void)
192 ToolkitTestApplication application;
193 tet_infoline(" UtcDaliToolBarRemoveControl01");
197 Actor control = CreateColorActor(Color::RED);
199 ToolBar toolbar = ToolBar::New();
200 toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
202 toolbar.RemoveControl(control);
206 tet_result(TET_FAIL);
209 tet_result(TET_PASS);
213 int UtcDaliToolBarRemoveControl02(void)
215 ToolkitTestApplication application;
216 tet_infoline(" UtcDaliToolBarRemoveControl02");
220 Actor control01 = CreateColorActor(Color::RED);
221 Actor control02 = CreateColorActor(Color::RED);
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);
228 toolbar02.RemoveControl(control01);
230 catch(Dali::DaliException& e)
232 DALI_TEST_PRINT_ASSERT(e);
233 DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
237 tet_result(TET_FAIL);
242 Actor control = CreateColorActor(Color::RED);
244 ToolBar toolbar = ToolBar::New();
245 toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
247 toolbar.RemoveControl(control);
248 toolbar.RemoveControl(control);
252 tet_result(TET_FAIL);
255 tet_result(TET_PASS);