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 ControlRenderer colorRenderer = factory.GetControlRenderer( color );
44 colorRenderer.SetOnStage( solidColorActor );
46 return solidColorActor;
51 void dali_toolbar_startup(void)
53 test_return_value = TET_UNDEF;
56 void dali_toolbar_cleanup(void)
58 test_return_value = TET_PASS;
62 int UtcDaliToolBarNew(void)
64 ToolkitTestApplication application;
65 tet_infoline(" UtcDaliToolBarNew");
69 DALI_TEST_CHECK( !toolbar );
71 toolbar = ToolBar::New();
73 DALI_TEST_CHECK( toolbar );
75 ToolBar toolbar2(toolbar);
77 DALI_TEST_CHECK( toolbar2 == toolbar );
79 //Additional check to ensure object is created by checking if it's registered
80 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
81 DALI_TEST_CHECK( registry );
83 gObjectCreatedCallBackCalled = false;
84 registry.ObjectCreatedSignal().Connect(&TestCallback);
86 ToolBar toolbar = ToolBar::New();
88 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
90 Actor actor = toolbar;
91 toolbar == ToolBar::DownCast( actor );
93 DALI_TEST_CHECK( toolbar );
97 int UtcDaliToolBarAddControl01(void)
99 ToolkitTestApplication application;
100 tet_infoline(" UtcDaliToolBarAddControl01");
104 Actor control1 = CreateColorActor( Color::RED );
105 control1.SetSize( Vector2( 100.f, 100.f ) );
106 Actor control2 = CreateColorActor( Color::RED );
107 control2.SetSize( Vector2( 100.f, 100.f ) );
108 Actor control3 = CreateColorActor( Color::RED );
109 control3.SetSize( Vector2( 100.f, 100.f ) );
110 Actor control4 = CreateColorActor( Color::RED );
111 control4.SetSize( Vector2( 100.f, 100.f ) );
112 Actor control5 = CreateColorActor( Color::RED );
113 control5.SetSize( Vector2( 100.f, 100.f ) );
115 ToolBar toolbar = ToolBar::New();
116 toolbar.SetSize( Vector2( 600.f, 100.f ) );
118 application.Render();
119 application.SendNotification();
120 application.Render();
121 application.SendNotification();
123 toolbar.Add( control1 );
124 toolbar.AddControl( control2, 0.1f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
125 toolbar.AddControl( control3, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
126 toolbar.AddControl( control4, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
127 toolbar.AddControl( control5, 0.1f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
129 Actor control6 = CreateColorActor( Color::RED );
130 control6.SetSize( Vector2( 100.f, 100.f ) );
131 Actor control7 = CreateColorActor( Color::RED );
132 control7.SetSize( Vector2( 100.f, 100.f ) );
133 Actor control8 = CreateColorActor( Color::RED );
134 control8.SetSize( Vector2( 100.f, 100.f ) );
136 application.Render();
137 application.SendNotification();
138 application.Render();
139 application.SendNotification();
141 toolbar.AddControl( control6, 0.4f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
142 toolbar.AddControl( control7, 0.2f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
143 toolbar.AddControl( control8, 0.2f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
147 tet_result(TET_FAIL);
150 tet_result(TET_PASS);
154 int UtcDaliToolBarAddControl02(void)
156 ToolkitTestApplication application;
157 tet_infoline(" UtcDaliToolBarAddControl02");
159 bool daliAssert = false;
163 Actor control = CreateColorActor( Color::RED );
165 ToolBar toolbar = ToolBar::New();
167 toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
169 catch( DaliException e )
172 tet_result(TET_PASS);
176 tet_result(TET_FAIL);
181 tet_result(TET_FAIL);
186 int UtcDaliToolBarRemoveControl01(void)
188 ToolkitTestApplication application;
189 tet_infoline(" UtcDaliToolBarRemoveControl01");
193 Actor control = CreateColorActor( Color::RED );
195 ToolBar toolbar = ToolBar::New();
196 toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
198 toolbar.RemoveControl( control );
202 tet_result(TET_FAIL);
205 tet_result(TET_PASS);
209 int UtcDaliToolBarRemoveControl02(void)
211 ToolkitTestApplication application;
212 tet_infoline(" UtcDaliToolBarRemoveControl02");
216 Actor control01 = CreateColorActor( Color::RED );
217 Actor control02 = CreateColorActor( Color::RED );
219 ToolBar toolbar01 = ToolBar::New();
220 ToolBar toolbar02 = ToolBar::New();
221 toolbar01.AddControl( control01, 0.1f, Alignment::HorizontalLeft );
222 toolbar02.AddControl( control02, 0.1f, Alignment::HorizontalLeft );
224 toolbar02.RemoveControl( control01 );
226 catch( Dali::DaliException& e )
228 DALI_TEST_PRINT_ASSERT( e );
229 DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
233 tet_result(TET_FAIL);
238 Actor control = CreateColorActor( Color::RED );
240 ToolBar toolbar = ToolBar::New();
241 toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
243 toolbar.RemoveControl( control );
244 toolbar.RemoveControl( control );
248 tet_result(TET_FAIL);
251 tet_result(TET_PASS);