Adding new test harness
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / 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 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21
22 using namespace Dali;
23 using namespace Dali::Toolkit;
24
25 void dali_page_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void dali_page_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 namespace
36 {
37 static bool gObjectCreatedCallBackCalled;
38 static void TestCallback(BaseHandle handle)
39 {
40   gObjectCreatedCallBackCalled = true;
41 }
42
43 }
44
45
46
47 int UtcDaliPageNew(void)
48 {
49   ToolkitTestApplication application;
50   tet_infoline("UtcDaliPageNew");
51
52   Page naviItem;
53   // Check that this handle is uninitialized
54   DALI_TEST_CHECK( !naviItem );
55
56   naviItem = Page::New();
57   // Check that the Dali resource is successfully created
58   DALI_TEST_CHECK( naviItem );
59
60   Page naviItem2( naviItem );
61   DALI_TEST_CHECK( naviItem2 == naviItem );
62
63   // Additional check to ensure the object is created by checking whether it is registered
64   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
65   DALI_TEST_CHECK( registry );
66   gObjectCreatedCallBackCalled = false;
67   registry.ObjectCreatedSignal().Connect( TestCallback );
68   {
69     Page naviItem = Page::New();
70   }
71   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
72   END_TEST;
73 }
74
75 int UtcDaliPageDownCast(void)
76 {
77   ToolkitTestApplication application;
78   tet_infoline( "UtcDaliPageDownCast" );
79
80   Page naviItem = Page::New();
81   BaseHandle handle( naviItem );
82
83   Page newNaviItem = Page::DownCast( handle );
84   DALI_TEST_CHECK( naviItem );
85   DALI_TEST_CHECK( newNaviItem == naviItem );
86   END_TEST;
87 }
88
89 int UtcDaliPageSetGetTitle(void)
90 {
91   ToolkitTestApplication application;
92   tet_infoline( "UtcDaliPageSetGetTitle" );
93
94   Page naviItem = Page::New();
95   DALI_TEST_CHECK( naviItem.GetTitle().empty() );
96
97   std::string str( "ItemTitle" );
98   naviItem.SetTitle( str );
99   DALI_TEST_CHECK( naviItem.GetTitle() == str );
100   END_TEST;
101 }
102
103 int UtcDaliPageSetGetSubTitle(void)
104 {
105   ToolkitTestApplication application;
106   tet_infoline( "UtcDaliPageSetGetSubTitle" );
107
108   Page naviItem = Page::New();
109   DALI_TEST_CHECK( naviItem.GetSubTitle().empty() );
110
111   std::string str( "ItemSubTitle" );
112   naviItem.SetSubTitle( str );
113   DALI_TEST_CHECK( naviItem.GetSubTitle() == str );
114   END_TEST;
115 }
116
117 int UtcDaliPageSetGetTitleIcon(void)
118 {
119   ToolkitTestApplication application;
120   tet_infoline( "UtcDaliPageSetGetTitleIcon" );
121
122   Page naviItem = Page::New();
123   DALI_TEST_CHECK( !naviItem.GetTitleIcon() );
124
125   Actor titleIcon = Actor::New();
126   naviItem.SetTitleIcon( titleIcon );
127   DALI_TEST_CHECK( naviItem.GetTitleIcon() == titleIcon );
128   END_TEST;
129 }
130
131 int UtcDaliPageAddGetToolBarControl(void)
132 {
133   ToolkitTestApplication application;
134   tet_infoline( "UtcDaliPageAddGetToolBarControl" );
135
136   Page naviItem = Page::New();
137   Page::ControlOnBarContainer container = naviItem.GetControlsOnToolBar();
138   // Check that the container is empty in the beginning
139   DALI_TEST_CHECK( container.empty() );
140
141   // Add control, check whether adding successfully, also check the container size
142   PushButton firstControl = PushButton::New();
143   DALI_TEST_CHECK( naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft) );
144   container = naviItem.GetControlsOnToolBar();
145   DALI_TEST_CHECK( container.size() == 1 );
146
147   // Add control, check whether adding successfully, also check the container size
148   PushButton secondControl = PushButton::New();
149   DALI_TEST_CHECK( naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter) );
150   container = naviItem.GetControlsOnToolBar();
151   DALI_TEST_CHECK( container.size() == 2 );
152
153   // The control adding fails, as the alignment is not HorizontalLeft/HorizontalCenter/HorizontalRight
154   PushButton thirdControl = PushButton::New();
155   DALI_TEST_CHECK( !naviItem.AddControlToToolBar(thirdControl, Alignment::VerticalCenter) );
156   container = naviItem.GetControlsOnToolBar();
157   DALI_TEST_CHECK( container.size() == 2 );
158
159   // Add control, check whether adding successfully, also check the container size
160   PushButton fourthControl = PushButton::New();
161   DALI_TEST_CHECK( naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight) );
162   container = naviItem.GetControlsOnToolBar();
163   DALI_TEST_CHECK( container.size() == 3 );
164
165   // The control adding fails, as the control itself is uninitialized
166   PushButton fifthControl;
167   DALI_TEST_CHECK( !naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalCenter) );
168   container = naviItem.GetControlsOnToolBar();
169   DALI_TEST_CHECK( container.size() == 3 );
170
171   // check the content of the three successfully added ControlOnBar objects
172   DALI_TEST_CHECK( container[0]->control == firstControl );
173   DALI_TEST_CHECK( container[0]->alignment == Alignment::HorizontalLeft );
174   DALI_TEST_CHECK( container[1]->control == secondControl );
175   DALI_TEST_CHECK( container[1]->alignment == Alignment::HorizontalCenter );
176   DALI_TEST_CHECK( container[2]->control == fourthControl );
177   DALI_TEST_CHECK( container[2]->alignment == Alignment::HorizontalRight );
178   END_TEST;
179 }
180
181 int UtcDaliPageAddGetTitleBarControl(void)
182 {
183   ToolkitTestApplication application;
184   tet_infoline( "UtcDaliPageAddGetTitleBarControl" );
185
186   Page naviItem = Page::New();
187   ActorContainer container = naviItem.GetControlsOnTitleBar();
188   // Check that the container is empty in the beginning
189   DALI_TEST_CHECK( container.empty() );
190
191   // Add control, check whether adding successfully, also check the container size
192   PushButton firstControl = PushButton::New();
193   DALI_TEST_CHECK( naviItem.AddControlToTitleBar(firstControl) );
194   container = naviItem.GetControlsOnTitleBar();
195   DALI_TEST_CHECK( container.size() == 1 );
196
197   // The control adding fails, as the control itself is uninitialized
198   PushButton secondControl;
199   DALI_TEST_CHECK( !naviItem.AddControlToTitleBar(secondControl) );
200   container = naviItem.GetControlsOnTitleBar();
201   DALI_TEST_CHECK( container.size() == 1 );
202
203   // Add control, check whether adding successfully, also check the container size
204   PushButton thirdControl = PushButton::New();
205   DALI_TEST_CHECK( naviItem.AddControlToTitleBar(thirdControl) );
206   container = naviItem.GetControlsOnTitleBar();
207   DALI_TEST_CHECK( container.size() == 2 );
208
209   // check the content of the three successfully added Controls
210   DALI_TEST_CHECK( container[0] == firstControl );
211   DALI_TEST_CHECK( container[1] == thirdControl );
212   END_TEST;
213 }
214
215 int UtcDaliPageSetGetPopupMenu(void)
216 {
217   ToolkitTestApplication application;
218   tet_infoline( "UtcDaliPageSetGetPopupMenu" );
219
220   Page naviItem = Page::New();
221   DALI_TEST_CHECK( !naviItem.GetPopupMenu() );
222
223   Toolkit::Popup menu = Toolkit::Popup::New();
224   naviItem.SetPopupMenu( menu );
225   DALI_TEST_CHECK( menu == naviItem.GetPopupMenu() );
226   END_TEST;
227 }