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