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