Use new animatable registered properties in ScrollView
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ToolBar.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 #include <dali/integration-api/events/touch-event-integ.h>
23
24 using namespace Dali;
25 using namespace Toolkit;
26
27 namespace
28 {
29 static bool gObjectCreatedCallBackCalled;
30
31 static void TestCallback(BaseHandle handle)
32 {
33   gObjectCreatedCallBackCalled = true;
34 }
35 } // namespace
36
37 void dali_toolbar_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void dali_toolbar_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47
48 int UtcDaliToolBarNew(void)
49 {
50   ToolkitTestApplication application;
51   tet_infoline(" UtcDaliToolBarNew");
52
53   ToolBar toolbar;
54
55   DALI_TEST_CHECK( !toolbar );
56
57   toolbar = ToolBar::New();
58
59   DALI_TEST_CHECK( toolbar );
60
61   ToolBar toolbar2(toolbar);
62
63   DALI_TEST_CHECK( toolbar2 == toolbar );
64
65   //Additional check to ensure object is created by checking if it's registered
66   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
67   DALI_TEST_CHECK( registry );
68
69   gObjectCreatedCallBackCalled = false;
70   registry.ObjectCreatedSignal().Connect(&TestCallback);
71   {
72     ToolBar toolbar = ToolBar::New();
73   }
74   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
75
76   Actor actor = toolbar;
77   toolbar == ToolBar::DownCast( actor );
78
79   DALI_TEST_CHECK( toolbar );
80   END_TEST;
81 }
82
83 int UtcDaliToolBarSetBackground(void)
84 {
85   ToolkitTestApplication application;
86   tet_infoline(" UtcDaliToolBarSetBackground");
87
88   try
89   {
90     ImageActor toolBarBackground = CreateSolidColorActor( Color::RED );
91
92     ToolBar toolbar = ToolBar::New();
93     toolbar.SetBackground( toolBarBackground );
94
95     Stage::GetCurrent().Add( toolbar );
96   }
97   catch( ... )
98   {
99     tet_result(TET_FAIL);
100   }
101
102   tet_result(TET_PASS);
103
104   application.SendNotification(); // VCC To be removed!!
105   application.Render();     // VCC To be removed!!
106   END_TEST;
107 }
108
109 int UtcDaliToolBarAddControl01(void)
110 {
111   ToolkitTestApplication application;
112   tet_infoline(" UtcDaliToolBarAddControl01");
113
114   try
115   {
116     ImageActor control1 = CreateSolidColorActor( Color::RED );
117     control1.SetPreferredSize( Vector2( 100.f, 100.f ) );
118     control1.SetResizePolicy( FIXED, ALL_DIMENSIONS );
119     ImageActor control2 = CreateSolidColorActor( Color::RED );
120     control2.SetPreferredSize( Vector2( 100.f, 100.f ) );
121     control2.SetResizePolicy( FIXED, ALL_DIMENSIONS );
122     ImageActor control3 = CreateSolidColorActor( Color::RED );
123     control3.SetPreferredSize( Vector2( 100.f, 100.f ) );
124     control3.SetResizePolicy( FIXED, ALL_DIMENSIONS );
125     ImageActor control4 = CreateSolidColorActor( Color::RED );
126     control4.SetPreferredSize( Vector2( 100.f, 100.f ) );
127     control4.SetResizePolicy( FIXED, ALL_DIMENSIONS );
128     ImageActor control5 = CreateSolidColorActor( Color::RED );
129     control5.SetPreferredSize( Vector2( 100.f, 100.f ) );
130     control5.SetResizePolicy( FIXED, ALL_DIMENSIONS );
131
132     ToolBar toolbar = ToolBar::New();
133     toolbar.SetPreferredSize( Vector2( 600.f, 100.f ) );
134
135     application.Render();
136     application.SendNotification();
137     application.Render();
138     application.SendNotification();
139
140     toolbar.Add( control1 );
141     toolbar.AddControl( control2, 0.1f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
142     toolbar.AddControl( control3, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
143     toolbar.AddControl( control4, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
144     toolbar.AddControl( control5, 0.1f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
145
146     ImageActor control6 = CreateSolidColorActor( Color::RED );
147     control6.SetPreferredSize( Vector2( 100.f, 100.f ) );
148     control6.SetResizePolicy( FIXED, ALL_DIMENSIONS );
149     ImageActor control7 = CreateSolidColorActor( Color::RED );
150     control7.SetPreferredSize( Vector2( 100.f, 100.f ) );
151     control7.SetResizePolicy( FIXED, ALL_DIMENSIONS );
152     ImageActor control8 = CreateSolidColorActor( Color::RED );
153     control8.SetPreferredSize( Vector2( 100.f, 100.f ) );
154     control8.SetResizePolicy( FIXED, ALL_DIMENSIONS );
155
156     application.Render();
157     application.SendNotification();
158     application.Render();
159     application.SendNotification();
160
161     toolbar.AddControl( control6, 0.4f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
162     toolbar.AddControl( control7, 0.2f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
163     toolbar.AddControl( control8, 0.2f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
164   }
165   catch( ... )
166   {
167     tet_result(TET_FAIL);
168   }
169
170   tet_result(TET_PASS);
171   END_TEST;
172 }
173
174 int UtcDaliToolBarAddControl02(void)
175 {
176   ToolkitTestApplication application;
177   tet_infoline(" UtcDaliToolBarAddControl02");
178
179   bool daliAssert = false;
180
181   try
182   {
183     ImageActor control = CreateSolidColorActor( Color::RED );
184
185     ToolBar toolbar = ToolBar::New();
186
187     toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
188   }
189   catch( DaliException e )
190   {
191     daliAssert = true;
192     tet_result(TET_PASS);
193   }
194   catch( ... )
195   {
196     tet_result(TET_FAIL);
197   }
198
199   if( !daliAssert )
200   {
201     tet_result(TET_FAIL);
202   }
203   END_TEST;
204 }
205
206 int UtcDaliToolBarRemoveControl01(void)
207 {
208   ToolkitTestApplication application;
209   tet_infoline(" UtcDaliToolBarRemoveControl01");
210
211   try
212   {
213     ImageActor control = CreateSolidColorActor( Color::RED );
214
215     ToolBar toolbar = ToolBar::New();
216     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
217
218     toolbar.RemoveControl( control );
219   }
220   catch( ... )
221   {
222     tet_result(TET_FAIL);
223   }
224
225   tet_result(TET_PASS);
226   END_TEST;
227 }
228
229 int UtcDaliToolBarRemoveControl02(void)
230 {
231   ToolkitTestApplication application;
232   tet_infoline(" UtcDaliToolBarRemoveControl02");
233
234   try
235   {
236     ImageActor control01 = CreateSolidColorActor( Color::RED );
237     ImageActor control02 = CreateSolidColorActor( Color::RED );
238
239     ToolBar toolbar01 = ToolBar::New();
240     ToolBar toolbar02 = ToolBar::New();
241     toolbar01.AddControl( control01, 0.1f, Alignment::HorizontalLeft );
242     toolbar02.AddControl( control02, 0.1f, Alignment::HorizontalLeft );
243
244     toolbar02.RemoveControl( control01 );
245   }
246   catch( Dali::DaliException& e )
247   {
248     DALI_TEST_PRINT_ASSERT( e );
249     DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
250   }
251   catch( ... )
252   {
253     tet_result(TET_FAIL);
254   }
255
256   try
257   {
258     ImageActor control = CreateSolidColorActor( Color::RED );
259
260     ToolBar toolbar = ToolBar::New();
261     toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
262
263     toolbar.RemoveControl( control );
264     toolbar.RemoveControl( control );
265   }
266   catch( ... )
267   {
268     tet_result(TET_FAIL);
269   }
270
271   tet_result(TET_PASS);
272   END_TEST;
273 }