Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / navigation-frame / utc-Dali-Page.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <tet_api.h>
22
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>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 static void Startup();
33 static void Cleanup();
34
35 namespace
36 {
37
38 static bool gObjectCreatedCallBackCalled;
39 static void TestCallback(BaseHandle handle)
40 {
41   gObjectCreatedCallBackCalled = true;
42 }
43
44 }
45
46 extern "C" {
47   void (*tet_startup)() = Startup;
48   void (*tet_cleanup)() = Cleanup;
49 }
50
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();
59
60 enum {
61   POSITIVE_TC_IDX = 0x01,
62   NEGATIVE_TC_IDX,
63 };
64
65 // Add test functionality for all APIs in the class (Positive and Negative)
66 extern "C" {
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 },
76     { NULL, 0 }
77   };
78 }
79
80 // Called only once before first test is run.
81 static void Startup()
82 {
83 }
84
85 // Called only once after last test is run
86 static void Cleanup()
87 {
88 }
89
90
91 static void UtcDaliPageNew()
92 {
93   ToolkitTestApplication application;
94   tet_infoline("UtcDaliPageNew");
95
96   Page naviItem;
97   // Check that this handle is uninitialized
98   DALI_TEST_CHECK( !naviItem );
99
100   naviItem = Page::New();
101   // Check that the Dali resource is successfully created
102   DALI_TEST_CHECK( naviItem );
103
104   Page naviItem2( naviItem );
105   DALI_TEST_CHECK( naviItem2 == naviItem );
106
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 );
112   {
113     Page naviItem = Page::New();
114   }
115   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
116 }
117
118 static void UtcDaliPageDownCast()
119 {
120   ToolkitTestApplication application;
121   tet_infoline( "UtcDaliPageDownCast" );
122
123   Page naviItem = Page::New();
124   BaseHandle handle( naviItem );
125
126   Page newNaviItem = Page::DownCast( handle );
127   DALI_TEST_CHECK( naviItem );
128   DALI_TEST_CHECK( newNaviItem == naviItem );
129 }
130
131 static void UtcDaliPageSetGetTitle()
132 {
133   ToolkitTestApplication application;
134   tet_infoline( "UtcDaliPageSetGetTitle" );
135
136   Page naviItem = Page::New();
137   DALI_TEST_CHECK( naviItem.GetTitle().empty() );
138
139   std::string str( "ItemTitle" );
140   naviItem.SetTitle( str );
141   DALI_TEST_CHECK( naviItem.GetTitle() == str );
142 }
143
144 static void UtcDaliPageSetGetSubTitle()
145 {
146   ToolkitTestApplication application;
147   tet_infoline( "UtcDaliPageSetGetSubTitle" );
148
149   Page naviItem = Page::New();
150   DALI_TEST_CHECK( naviItem.GetSubTitle().empty() );
151
152   std::string str( "ItemSubTitle" );
153   naviItem.SetSubTitle( str );
154   DALI_TEST_CHECK( naviItem.GetSubTitle() == str );
155 }
156
157 static void UtcDaliPageSetGetTitleIcon()
158 {
159   ToolkitTestApplication application;
160   tet_infoline( "UtcDaliPageSetGetTitleIcon" );
161
162   Page naviItem = Page::New();
163   DALI_TEST_CHECK( !naviItem.GetTitleIcon() );
164
165   Actor titleIcon = Actor::New();
166   naviItem.SetTitleIcon( titleIcon );
167   DALI_TEST_CHECK( naviItem.GetTitleIcon() == titleIcon );
168 }
169
170 static void UtcDaliPageAddGetToolBarControl()
171 {
172   ToolkitTestApplication application;
173   tet_infoline( "UtcDaliPageAddGetToolBarControl" );
174
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() );
179
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 );
185
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 );
191
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 );
197
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 );
203
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 );
209
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 );
217 }
218
219 static void UtcDaliPageAddGetTitleBarControl()
220 {
221   ToolkitTestApplication application;
222   tet_infoline( "UtcDaliPageAddGetTitleBarControl" );
223
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() );
228
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 );
234
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 );
240
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 );
246
247   // check the content of the three successfully added Controls
248   DALI_TEST_CHECK( container[0] == firstControl );
249   DALI_TEST_CHECK( container[1] == thirdControl );
250 }
251
252 static void UtcDaliPageSetGetPopupMenu()
253 {
254   ToolkitTestApplication application;
255   tet_infoline( "UtcDaliPageSetGetPopupMenu" );
256
257   Page naviItem = Page::New();
258   DALI_TEST_CHECK( !naviItem.GetPopupMenu() );
259
260   Toolkit::Popup menu = Toolkit::Popup::New();
261   naviItem.SetPopupMenu( menu );
262   DALI_TEST_CHECK( menu == naviItem.GetPopupMenu() );
263 }