2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/controls/navigation-frame/page.h>
24 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
25 #include <dali-toolkit/public-api/controls/popup/popup.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Dali::Toolkit;
31 static void Startup();
32 static void Cleanup();
37 static bool gObjectCreatedCallBackCalled;
38 static void TestCallback(BaseHandle handle)
40 gObjectCreatedCallBackCalled = true;
46 void (*tet_startup)() = Startup;
47 void (*tet_cleanup)() = Cleanup;
50 static void UtcDaliPageNew();
51 static void UtcDaliPageDownCast();
52 static void UtcDaliPageSetGetTitle();
53 static void UtcDaliPageSetGetSubTitle();
54 static void UtcDaliPageSetGetTitleIcon();
55 static void UtcDaliPageAddGetToolBarControl();
56 static void UtcDaliPageAddGetTitleBarControl();
57 static void UtcDaliPageSetGetPopupMenu();
60 POSITIVE_TC_IDX = 0x01,
64 // Add test functionality for all APIs in the class (Positive and Negative)
66 struct tet_testlist tet_testlist[] = {
67 { UtcDaliPageNew, POSITIVE_TC_IDX },
68 { UtcDaliPageDownCast, POSITIVE_TC_IDX },
69 { UtcDaliPageSetGetTitle, POSITIVE_TC_IDX },
70 { UtcDaliPageSetGetSubTitle, POSITIVE_TC_IDX },
71 { UtcDaliPageSetGetTitleIcon, POSITIVE_TC_IDX },
72 { UtcDaliPageAddGetToolBarControl, POSITIVE_TC_IDX },
73 { UtcDaliPageAddGetTitleBarControl, POSITIVE_TC_IDX },
74 { UtcDaliPageSetGetPopupMenu, POSITIVE_TC_IDX },
79 // Called only once before first test is run.
84 // Called only once after last test is run
90 static void UtcDaliPageNew()
92 ToolkitTestApplication application;
93 tet_infoline("UtcDaliPageNew");
96 // Check that this handle is uninitialized
97 DALI_TEST_CHECK( !naviItem );
99 naviItem = Page::New();
100 // Check that the Dali resource is successfully created
101 DALI_TEST_CHECK( naviItem );
103 Page naviItem2( naviItem );
104 DALI_TEST_CHECK( naviItem2 == naviItem );
106 // Additional check to ensure the object is created by checking whether it is registered
107 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
108 DALI_TEST_CHECK( registry );
109 gObjectCreatedCallBackCalled = false;
110 registry.ObjectCreatedSignal().Connect( TestCallback );
112 Page naviItem = Page::New();
114 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
117 static void UtcDaliPageDownCast()
119 ToolkitTestApplication application;
120 tet_infoline( "UtcDaliPageDownCast" );
122 Page naviItem = Page::New();
123 BaseHandle handle( naviItem );
125 Page newNaviItem = Page::DownCast( handle );
126 DALI_TEST_CHECK( naviItem );
127 DALI_TEST_CHECK( newNaviItem == naviItem );
130 static void UtcDaliPageSetGetTitle()
132 ToolkitTestApplication application;
133 tet_infoline( "UtcDaliPageSetGetTitle" );
135 Page naviItem = Page::New();
136 DALI_TEST_CHECK( naviItem.GetTitle().empty() );
138 std::string str( "ItemTitle" );
139 naviItem.SetTitle( str );
140 DALI_TEST_CHECK( naviItem.GetTitle() == str );
143 static void UtcDaliPageSetGetSubTitle()
145 ToolkitTestApplication application;
146 tet_infoline( "UtcDaliPageSetGetSubTitle" );
148 Page naviItem = Page::New();
149 DALI_TEST_CHECK( naviItem.GetSubTitle().empty() );
151 std::string str( "ItemSubTitle" );
152 naviItem.SetSubTitle( str );
153 DALI_TEST_CHECK( naviItem.GetSubTitle() == str );
156 static void UtcDaliPageSetGetTitleIcon()
158 ToolkitTestApplication application;
159 tet_infoline( "UtcDaliPageSetGetTitleIcon" );
161 Page naviItem = Page::New();
162 DALI_TEST_CHECK( !naviItem.GetTitleIcon() );
164 Actor titleIcon = Actor::New();
165 naviItem.SetTitleIcon( titleIcon );
166 DALI_TEST_CHECK( naviItem.GetTitleIcon() == titleIcon );
169 static void UtcDaliPageAddGetToolBarControl()
171 ToolkitTestApplication application;
172 tet_infoline( "UtcDaliPageAddGetToolBarControl" );
174 Page naviItem = Page::New();
175 Page::ControlOnBarContainer container = naviItem.GetControlsOnToolBar();
176 // Check that the container is empty in the beginning
177 DALI_TEST_CHECK( container.empty() );
179 // Add control, check whether adding successfully, also check the container size
180 PushButton firstControl = PushButton::New();
181 DALI_TEST_CHECK( naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft) );
182 container = naviItem.GetControlsOnToolBar();
183 DALI_TEST_CHECK( container.size() == 1 );
185 // Add control, check whether adding successfully, also check the container size
186 PushButton secondControl = PushButton::New();
187 DALI_TEST_CHECK( naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter) );
188 container = naviItem.GetControlsOnToolBar();
189 DALI_TEST_CHECK( container.size() == 2 );
191 // The control adding fails, as the alignment is not HorizontalLeft/HorizontalCenter/HorizontalRight
192 PushButton thirdControl = PushButton::New();
193 DALI_TEST_CHECK( !naviItem.AddControlToToolBar(thirdControl, Alignment::VerticalCenter) );
194 container = naviItem.GetControlsOnToolBar();
195 DALI_TEST_CHECK( container.size() == 2 );
197 // Add control, check whether adding successfully, also check the container size
198 PushButton fourthControl = PushButton::New();
199 DALI_TEST_CHECK( naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight) );
200 container = naviItem.GetControlsOnToolBar();
201 DALI_TEST_CHECK( container.size() == 3 );
203 // The control adding fails, as the control itself is uninitialized
204 PushButton fifthControl;
205 DALI_TEST_CHECK( !naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalCenter) );
206 container = naviItem.GetControlsOnToolBar();
207 DALI_TEST_CHECK( container.size() == 3 );
209 // check the content of the three successfully added ControlOnBar objects
210 DALI_TEST_CHECK( container[0]->control == firstControl );
211 DALI_TEST_CHECK( container[0]->alignment == Alignment::HorizontalLeft );
212 DALI_TEST_CHECK( container[1]->control == secondControl );
213 DALI_TEST_CHECK( container[1]->alignment == Alignment::HorizontalCenter );
214 DALI_TEST_CHECK( container[2]->control == fourthControl );
215 DALI_TEST_CHECK( container[2]->alignment == Alignment::HorizontalRight );
218 static void UtcDaliPageAddGetTitleBarControl()
220 ToolkitTestApplication application;
221 tet_infoline( "UtcDaliPageAddGetTitleBarControl" );
223 Page naviItem = Page::New();
224 ActorContainer container = naviItem.GetControlsOnTitleBar();
225 // Check that the container is empty in the beginning
226 DALI_TEST_CHECK( container.empty() );
228 // Add control, check whether adding successfully, also check the container size
229 PushButton firstControl = PushButton::New();
230 DALI_TEST_CHECK( naviItem.AddControlToTitleBar(firstControl) );
231 container = naviItem.GetControlsOnTitleBar();
232 DALI_TEST_CHECK( container.size() == 1 );
234 // The control adding fails, as the control itself is uninitialized
235 PushButton secondControl;
236 DALI_TEST_CHECK( !naviItem.AddControlToTitleBar(secondControl) );
237 container = naviItem.GetControlsOnTitleBar();
238 DALI_TEST_CHECK( container.size() == 1 );
240 // Add control, check whether adding successfully, also check the container size
241 PushButton thirdControl = PushButton::New();
242 DALI_TEST_CHECK( naviItem.AddControlToTitleBar(thirdControl) );
243 container = naviItem.GetControlsOnTitleBar();
244 DALI_TEST_CHECK( container.size() == 2 );
246 // check the content of the three successfully added Controls
247 DALI_TEST_CHECK( container[0] == firstControl );
248 DALI_TEST_CHECK( container[1] == thirdControl );
251 static void UtcDaliPageSetGetPopupMenu()
253 ToolkitTestApplication application;
254 tet_infoline( "UtcDaliPageSetGetPopupMenu" );
256 Page naviItem = Page::New();
257 DALI_TEST_CHECK( !naviItem.GetPopupMenu() );
259 Toolkit::Popup menu = Toolkit::Popup::New();
260 naviItem.SetPopupMenu( menu );
261 DALI_TEST_CHECK( menu == naviItem.GetPopupMenu() );