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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/public-api/controls/navigation-frame/page.h>
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include <dali-toolkit/public-api/controls/popup/popup.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Dali::Toolkit;
32 static void Startup();
33 static void Cleanup();
38 static bool gObjectCreatedCallBackCalled;
39 static void TestCallback(BaseHandle handle)
41 gObjectCreatedCallBackCalled = true;
47 void (*tet_startup)() = Startup;
48 void (*tet_cleanup)() = Cleanup;
51 static void UtcDaliPageNew();
52 static void UtcDaliPageDownCast();
53 static void UtcDaliPageSetGetTitle();
54 static void UtcDaliPageSetGetSubTitle();
55 static void UtcDaliPageSetGetTitleIcon();
56 static void UtcDaliPageAddGetToolBarControl();
57 static void UtcDaliPageAddGetTitleBarControl();
58 static void UtcDaliPageSetGetPopupMenu();
61 POSITIVE_TC_IDX = 0x01,
65 // Add test functionality for all APIs in the class (Positive and Negative)
67 struct tet_testlist tet_testlist[] = {
68 { UtcDaliPageNew, POSITIVE_TC_IDX },
69 { UtcDaliPageDownCast, POSITIVE_TC_IDX },
70 { UtcDaliPageSetGetTitle, POSITIVE_TC_IDX },
71 { UtcDaliPageSetGetSubTitle, POSITIVE_TC_IDX },
72 { UtcDaliPageSetGetTitleIcon, POSITIVE_TC_IDX },
73 { UtcDaliPageAddGetToolBarControl, POSITIVE_TC_IDX },
74 { UtcDaliPageAddGetTitleBarControl, POSITIVE_TC_IDX },
75 { UtcDaliPageSetGetPopupMenu, POSITIVE_TC_IDX },
80 // Called only once before first test is run.
85 // Called only once after last test is run
91 static void UtcDaliPageNew()
93 ToolkitTestApplication application;
94 tet_infoline("UtcDaliPageNew");
97 // Check that this handle is uninitialized
98 DALI_TEST_CHECK( !naviItem );
100 naviItem = Page::New();
101 // Check that the Dali resource is successfully created
102 DALI_TEST_CHECK( naviItem );
104 Page naviItem2( naviItem );
105 DALI_TEST_CHECK( naviItem2 == naviItem );
107 // Additional check to ensure the object is created by checking whether it is registered
108 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
109 DALI_TEST_CHECK( registry );
110 gObjectCreatedCallBackCalled = false;
111 registry.ObjectCreatedSignal().Connect( TestCallback );
113 Page naviItem = Page::New();
115 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
118 static void UtcDaliPageDownCast()
120 ToolkitTestApplication application;
121 tet_infoline( "UtcDaliPageDownCast" );
123 Page naviItem = Page::New();
124 BaseHandle handle( naviItem );
126 Page newNaviItem = Page::DownCast( handle );
127 DALI_TEST_CHECK( naviItem );
128 DALI_TEST_CHECK( newNaviItem == naviItem );
131 static void UtcDaliPageSetGetTitle()
133 ToolkitTestApplication application;
134 tet_infoline( "UtcDaliPageSetGetTitle" );
136 Page naviItem = Page::New();
137 DALI_TEST_CHECK( naviItem.GetTitle().empty() );
139 std::string str( "ItemTitle" );
140 naviItem.SetTitle( str );
141 DALI_TEST_CHECK( naviItem.GetTitle() == str );
144 static void UtcDaliPageSetGetSubTitle()
146 ToolkitTestApplication application;
147 tet_infoline( "UtcDaliPageSetGetSubTitle" );
149 Page naviItem = Page::New();
150 DALI_TEST_CHECK( naviItem.GetSubTitle().empty() );
152 std::string str( "ItemSubTitle" );
153 naviItem.SetSubTitle( str );
154 DALI_TEST_CHECK( naviItem.GetSubTitle() == str );
157 static void UtcDaliPageSetGetTitleIcon()
159 ToolkitTestApplication application;
160 tet_infoline( "UtcDaliPageSetGetTitleIcon" );
162 Page naviItem = Page::New();
163 DALI_TEST_CHECK( !naviItem.GetTitleIcon() );
165 Actor titleIcon = Actor::New();
166 naviItem.SetTitleIcon( titleIcon );
167 DALI_TEST_CHECK( naviItem.GetTitleIcon() == titleIcon );
170 static void UtcDaliPageAddGetToolBarControl()
172 ToolkitTestApplication application;
173 tet_infoline( "UtcDaliPageAddGetToolBarControl" );
175 Page naviItem = Page::New();
176 Page::ControlOnBarContainer container = naviItem.GetControlsOnToolBar();
177 // Check that the container is empty in the beginning
178 DALI_TEST_CHECK( container.empty() );
180 // Add control, check whether adding successfully, also check the container size
181 PushButton firstControl = PushButton::New();
182 DALI_TEST_CHECK( naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft) );
183 container = naviItem.GetControlsOnToolBar();
184 DALI_TEST_CHECK( container.size() == 1 );
186 // Add control, check whether adding successfully, also check the container size
187 PushButton secondControl = PushButton::New();
188 DALI_TEST_CHECK( naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter) );
189 container = naviItem.GetControlsOnToolBar();
190 DALI_TEST_CHECK( container.size() == 2 );
192 // The control adding fails, as the alignment is not HorizontalLeft/HorizontalCenter/HorizontalRight
193 PushButton thirdControl = PushButton::New();
194 DALI_TEST_CHECK( !naviItem.AddControlToToolBar(thirdControl, Alignment::VerticalCenter) );
195 container = naviItem.GetControlsOnToolBar();
196 DALI_TEST_CHECK( container.size() == 2 );
198 // Add control, check whether adding successfully, also check the container size
199 PushButton fourthControl = PushButton::New();
200 DALI_TEST_CHECK( naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight) );
201 container = naviItem.GetControlsOnToolBar();
202 DALI_TEST_CHECK( container.size() == 3 );
204 // The control adding fails, as the control itself is uninitialized
205 PushButton fifthControl;
206 DALI_TEST_CHECK( !naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalCenter) );
207 container = naviItem.GetControlsOnToolBar();
208 DALI_TEST_CHECK( container.size() == 3 );
210 // check the content of the three successfully added ControlOnBar objects
211 DALI_TEST_CHECK( container[0]->control == firstControl );
212 DALI_TEST_CHECK( container[0]->alignment == Alignment::HorizontalLeft );
213 DALI_TEST_CHECK( container[1]->control == secondControl );
214 DALI_TEST_CHECK( container[1]->alignment == Alignment::HorizontalCenter );
215 DALI_TEST_CHECK( container[2]->control == fourthControl );
216 DALI_TEST_CHECK( container[2]->alignment == Alignment::HorizontalRight );
219 static void UtcDaliPageAddGetTitleBarControl()
221 ToolkitTestApplication application;
222 tet_infoline( "UtcDaliPageAddGetTitleBarControl" );
224 Page naviItem = Page::New();
225 ActorContainer container = naviItem.GetControlsOnTitleBar();
226 // Check that the container is empty in the beginning
227 DALI_TEST_CHECK( container.empty() );
229 // Add control, check whether adding successfully, also check the container size
230 PushButton firstControl = PushButton::New();
231 DALI_TEST_CHECK( naviItem.AddControlToTitleBar(firstControl) );
232 container = naviItem.GetControlsOnTitleBar();
233 DALI_TEST_CHECK( container.size() == 1 );
235 // The control adding fails, as the control itself is uninitialized
236 PushButton secondControl;
237 DALI_TEST_CHECK( !naviItem.AddControlToTitleBar(secondControl) );
238 container = naviItem.GetControlsOnTitleBar();
239 DALI_TEST_CHECK( container.size() == 1 );
241 // Add control, check whether adding successfully, also check the container size
242 PushButton thirdControl = PushButton::New();
243 DALI_TEST_CHECK( naviItem.AddControlToTitleBar(thirdControl) );
244 container = naviItem.GetControlsOnTitleBar();
245 DALI_TEST_CHECK( container.size() == 2 );
247 // check the content of the three successfully added Controls
248 DALI_TEST_CHECK( container[0] == firstControl );
249 DALI_TEST_CHECK( container[1] == thirdControl );
252 static void UtcDaliPageSetGetPopupMenu()
254 ToolkitTestApplication application;
255 tet_infoline( "UtcDaliPageSetGetPopupMenu" );
257 Page naviItem = Page::New();
258 DALI_TEST_CHECK( !naviItem.GetPopupMenu() );
260 Toolkit::Popup menu = Toolkit::Popup::New();
261 naviItem.SetPopupMenu( menu );
262 DALI_TEST_CHECK( menu == naviItem.GetPopupMenu() );