2 * Copyright (c) 2020 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.
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"
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;
67 int UtcDaliToolBarNew(void)
69 ToolkitTestApplication application;
70 tet_infoline(" UtcDaliToolBarNew");
74 DALI_TEST_CHECK( !toolbar );
76 toolbar = ToolBar::New();
78 DALI_TEST_CHECK( toolbar );
80 ToolBar toolbar2(toolbar);
82 DALI_TEST_CHECK( toolbar2 == toolbar );
84 //Additional check to ensure object is created by checking if it's registered
85 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
86 DALI_TEST_CHECK( registry );
88 gObjectCreatedCallBackCalled = false;
89 registry.ObjectCreatedSignal().Connect(&TestCallback);
91 ToolBar toolbar = ToolBar::New();
93 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
95 Actor actor = toolbar;
96 toolbar = ToolBar::DownCast( actor );
98 DALI_TEST_CHECK( toolbar );
102 int UtcDaliToolBarAddControl01(void)
104 ToolkitTestApplication application;
105 tet_infoline(" UtcDaliToolBarAddControl01");
109 Actor control1 = CreateColorActor( Color::RED );
110 control1.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
111 Actor control2 = CreateColorActor( Color::RED );
112 control2.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
113 Actor control3 = CreateColorActor( Color::RED );
114 control3.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
115 Actor control4 = CreateColorActor( Color::RED );
116 control4.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
117 Actor control5 = CreateColorActor( Color::RED );
118 control5.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
120 ToolBar toolbar = ToolBar::New();
121 toolbar.SetProperty( Actor::Property::SIZE, Vector2( 600.f, 100.f ) );
123 application.Render();
124 application.SendNotification();
125 application.Render();
126 application.SendNotification();
128 toolbar.Add( control1 );
129 toolbar.AddControl( control2, 0.1f, Alignment::HORIZONTAL_LEFT, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
130 toolbar.AddControl( control3, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
131 toolbar.AddControl( control4, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
132 toolbar.AddControl( control5, 0.1f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
134 Actor control6 = CreateColorActor( Color::RED );
135 control6.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
136 Actor control7 = CreateColorActor( Color::RED );
137 control7.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
138 Actor control8 = CreateColorActor( Color::RED );
139 control8.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
141 application.Render();
142 application.SendNotification();
143 application.Render();
144 application.SendNotification();
146 toolbar.AddControl( control6, 0.4f, Alignment::HORIZONTAL_LEFT, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
147 toolbar.AddControl( control7, 0.2f, Alignment::HORIZONTAL_CENTER, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
148 toolbar.AddControl( control8, 0.2f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
152 tet_result(TET_FAIL);
155 tet_result(TET_PASS);
159 int UtcDaliToolBarAddControl02(void)
161 ToolkitTestApplication application;
162 tet_infoline(" UtcDaliToolBarAddControl02");
164 bool daliAssert = false;
168 Actor control = CreateColorActor( Color::RED );
170 ToolBar toolbar = ToolBar::New();
172 toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
174 catch( DaliException e )
177 tet_result(TET_PASS);
181 tet_result(TET_FAIL);
186 tet_result(TET_FAIL);
191 int UtcDaliToolBarRemoveControl01(void)
193 ToolkitTestApplication application;
194 tet_infoline(" UtcDaliToolBarRemoveControl01");
198 Actor control = CreateColorActor( Color::RED );
200 ToolBar toolbar = ToolBar::New();
201 toolbar.AddControl( control, 0.1f, Alignment::HORIZONTAL_LEFT );
203 toolbar.RemoveControl( control );
207 tet_result(TET_FAIL);
210 tet_result(TET_PASS);
214 int UtcDaliToolBarRemoveControl02(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliToolBarRemoveControl02");
221 Actor control01 = CreateColorActor( Color::RED );
222 Actor control02 = CreateColorActor( Color::RED );
224 ToolBar toolbar01 = ToolBar::New();
225 ToolBar toolbar02 = ToolBar::New();
226 toolbar01.AddControl( control01, 0.1f, Alignment::HORIZONTAL_LEFT );
227 toolbar02.AddControl( control02, 0.1f, Alignment::HORIZONTAL_LEFT );
229 toolbar02.RemoveControl( control01 );
231 catch( Dali::DaliException& e )
233 DALI_TEST_PRINT_ASSERT( e );
234 DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
238 tet_result(TET_FAIL);
243 Actor control = CreateColorActor( Color::RED );
245 ToolBar toolbar = ToolBar::New();
246 toolbar.AddControl( control, 0.1f, Alignment::HORIZONTAL_LEFT );
248 toolbar.RemoveControl( control );
249 toolbar.RemoveControl( control );
253 tet_result(TET_FAIL);
256 tet_result(TET_PASS);