2 * Copyright (c) 2014 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/controls/renderer-factory/renderer-factory.h>
27 using namespace Toolkit;
31 static bool gObjectCreatedCallBackCalled;
33 static void TestCallback(BaseHandle handle)
35 gObjectCreatedCallBackCalled = true;
38 Actor CreateColorActor( const Vector4& color )
40 Actor solidColorActor = Actor::New();
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 );
49 return solidColorActor;
54 void dali_toolbar_startup(void)
56 test_return_value = TET_UNDEF;
59 void dali_toolbar_cleanup(void)
61 test_return_value = TET_PASS;
65 int UtcDaliToolBarNew(void)
67 ToolkitTestApplication application;
68 tet_infoline(" UtcDaliToolBarNew");
72 DALI_TEST_CHECK( !toolbar );
74 toolbar = ToolBar::New();
76 DALI_TEST_CHECK( toolbar );
78 ToolBar toolbar2(toolbar);
80 DALI_TEST_CHECK( toolbar2 == toolbar );
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 );
86 gObjectCreatedCallBackCalled = false;
87 registry.ObjectCreatedSignal().Connect(&TestCallback);
89 ToolBar toolbar = ToolBar::New();
91 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
93 Actor actor = toolbar;
94 toolbar == ToolBar::DownCast( actor );
96 DALI_TEST_CHECK( toolbar );
100 int UtcDaliToolBarAddControl01(void)
102 ToolkitTestApplication application;
103 tet_infoline(" UtcDaliToolBarAddControl01");
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 ) );
118 ToolBar toolbar = ToolBar::New();
119 toolbar.SetSize( Vector2( 600.f, 100.f ) );
121 application.Render();
122 application.SendNotification();
123 application.Render();
124 application.SendNotification();
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 ) );
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 ) );
139 application.Render();
140 application.SendNotification();
141 application.Render();
142 application.SendNotification();
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 ) );
150 tet_result(TET_FAIL);
153 tet_result(TET_PASS);
157 int UtcDaliToolBarAddControl02(void)
159 ToolkitTestApplication application;
160 tet_infoline(" UtcDaliToolBarAddControl02");
162 bool daliAssert = false;
166 Actor control = CreateColorActor( Color::RED );
168 ToolBar toolbar = ToolBar::New();
170 toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
172 catch( DaliException e )
175 tet_result(TET_PASS);
179 tet_result(TET_FAIL);
184 tet_result(TET_FAIL);
189 int UtcDaliToolBarRemoveControl01(void)
191 ToolkitTestApplication application;
192 tet_infoline(" UtcDaliToolBarRemoveControl01");
196 Actor control = CreateColorActor( Color::RED );
198 ToolBar toolbar = ToolBar::New();
199 toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
201 toolbar.RemoveControl( control );
205 tet_result(TET_FAIL);
208 tet_result(TET_PASS);
212 int UtcDaliToolBarRemoveControl02(void)
214 ToolkitTestApplication application;
215 tet_infoline(" UtcDaliToolBarRemoveControl02");
219 Actor control01 = CreateColorActor( Color::RED );
220 Actor control02 = CreateColorActor( Color::RED );
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 );
227 toolbar02.RemoveControl( control01 );
229 catch( Dali::DaliException& e )
231 DALI_TEST_PRINT_ASSERT( e );
232 DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
236 tet_result(TET_FAIL);
241 Actor control = CreateColorActor( Color::RED );
243 ToolBar toolbar = ToolBar::New();
244 toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
246 toolbar.RemoveControl( control );
247 toolbar.RemoveControl( control );
251 tet_result(TET_FAIL);
254 tet_result(TET_PASS);