Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / default-controls / utc-Dali-DefaultControls.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/tool-bar/tool-bar.h>
25 #include <dali-toolkit/public-api/controls/view/view.h>
26 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
27 #include <dali-toolkit/public-api/controls/default-controls/push-button-factory.h>
28 #include <dali-toolkit/public-api/controls/default-controls/check-button-factory.h>
29
30 #include <dali-toolkit-test-suite-utils.h>
31
32 using namespace Dali;
33 using namespace Toolkit;
34
35 static void Startup();
36 static void Cleanup();
37
38 extern "C" {
39   void (*tet_startup)() = Startup;
40   void (*tet_cleanup)() = Cleanup;
41 }
42
43 enum {
44   POSITIVE_TC_IDX = 0x01,
45   NEGATIVE_TC_IDX,
46 };
47
48 #define MAX_NUMBER_OF_TESTS 10000
49 extern "C" {
50   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
51 }
52
53 // Add test functionality for all APIs in the class (Positive and Negative)
54 TEST_FUNCTION( UtcDaliDefaultControlsCreateSolidColorActor, POSITIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliDefaultControlsCreatePushButton, POSITIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliDefaultControlsCreateCheckBoxButton, POSITIVE_TC_IDX );
57
58 // Called only once before first test is run.
59 static void Startup()
60 {
61 }
62
63 // Called only once after last test is run
64 static void Cleanup()
65 {
66 }
67
68 static void UtcDaliDefaultControlsCreateSolidColorActor()
69 {
70   ToolkitTestApplication application;
71
72   tet_infoline(" UtcDaliDefaultControlsCreateSolidColorActor");
73
74   ImageActor image1 = CreateSolidColorActor( Color::RED );
75   ImageActor image2 = CreateSolidColorActor( Color::RED, true, Color::BLUE, 2 );
76   ImageActor image3 = CreateSolidColorActor( Color::RED, true, Color::BLUE, 12 );
77
78   DALI_TEST_CHECK(image1);
79   DALI_TEST_CHECK(image2);
80   DALI_TEST_CHECK(!image3);
81 }
82
83 static void UtcDaliDefaultControlsCreatePushButton()
84 {
85   ToolkitTestApplication application;
86
87   tet_infoline(" UtcDaliDefaultControlsCreatePushButton");
88
89   const std::string imagePath( "Facke image path" );
90   const std::string voidImagePath( "" );
91
92   ImageActor image = CreateSolidColorActor( Color::RED );
93   ImageActor voidImage;
94
95   PushButton button0, button1, button2, button3, button4, button5, button6;
96
97   try
98   {
99     button0 = CreatePushButton( voidImagePath, voidImagePath, voidImagePath, voidImagePath, voidImagePath );
100     button1 = CreatePushButton( imagePath, voidImagePath, voidImagePath, voidImagePath, voidImagePath );
101     button2 = CreatePushButton( voidImagePath, imagePath, voidImagePath, voidImagePath, voidImagePath );
102     button3 = CreatePushButton( voidImagePath, voidImagePath, imagePath, voidImagePath, voidImagePath );
103     button4 = CreatePushButton( voidImagePath, voidImagePath, voidImagePath, imagePath, voidImagePath );
104     button5 = CreatePushButton( voidImagePath, voidImagePath, voidImagePath, voidImagePath, imagePath );
105     button6 = CreatePushButton( imagePath, imagePath, imagePath, imagePath, imagePath );
106   }
107   catch( ... )
108   {
109     tet_result( TET_FAIL );
110   }
111
112   DALI_TEST_CHECK( button0 );
113   DALI_TEST_CHECK( button1 );
114   DALI_TEST_CHECK( button2 );
115   DALI_TEST_CHECK( button3 );
116   DALI_TEST_CHECK( button4 );
117   DALI_TEST_CHECK( button5 );
118   DALI_TEST_CHECK( button6 );
119
120   try
121   {
122     button0 = CreatePushButton( voidImage, voidImage, voidImage, voidImage, voidImage );
123     button1 = CreatePushButton( image, voidImage, voidImage, voidImage, voidImage );
124     button2 = CreatePushButton( voidImage, image, voidImage, voidImage, voidImage );
125     button3 = CreatePushButton( voidImage, voidImage, image, voidImage, voidImage );
126     button4 = CreatePushButton( voidImage, voidImage, voidImage, image, voidImage );
127     button5 = CreatePushButton( voidImage, voidImage, voidImage, voidImage, image );
128     button6 = CreatePushButton( image, image, image, image, image );
129   }
130   catch( ... )
131   {
132     tet_result( TET_FAIL );
133   }
134
135   DALI_TEST_CHECK( button0 );
136   DALI_TEST_CHECK( button1 );
137   DALI_TEST_CHECK( button2 );
138   DALI_TEST_CHECK( button3 );
139   DALI_TEST_CHECK( button4 );
140   DALI_TEST_CHECK( button5 );
141   DALI_TEST_CHECK( button6 );
142
143   try
144   {
145     button0 = CreatePushButton( voidImagePath );
146     button1 = CreatePushButton( imagePath );
147   }
148   catch( ... )
149   {
150     tet_result( TET_FAIL );
151   }
152
153   DALI_TEST_CHECK( button0 );
154   DALI_TEST_CHECK( button1 );
155
156   try
157   {
158     button0 = CreatePushButton( voidImage );
159     button1 = CreatePushButton( image );
160   }
161   catch( ... )
162   {
163     tet_result( TET_FAIL );
164   }
165
166   DALI_TEST_CHECK( button0 );
167   DALI_TEST_CHECK( button1 );
168 }
169
170 static void UtcDaliDefaultControlsCreateCheckBoxButton()
171 {
172   ToolkitTestApplication application;
173
174   tet_infoline(" UtcDaliDefaultControlsCreateCheckBoxButton");
175
176   const std::string imagePath( "Facke image path" );
177   const std::string voidImagePath( "" );
178
179   ImageActor image = CreateSolidColorActor( Color::RED );
180   ImageActor voidImage;
181
182   CheckBoxButton button0, button1, button2, button3, button4, button5;
183
184   try
185   {
186     button0 = CreateCheckBoxButton( voidImagePath, voidImagePath, voidImagePath, voidImagePath );
187     button1 = CreateCheckBoxButton( imagePath, voidImagePath, voidImagePath, voidImagePath );
188     button2 = CreateCheckBoxButton( voidImagePath, imagePath, voidImagePath, voidImagePath );
189     button3 = CreateCheckBoxButton( voidImagePath, voidImagePath, imagePath, voidImagePath );
190     button4 = CreateCheckBoxButton( voidImagePath, voidImagePath, voidImagePath, imagePath );
191     button5 = CreateCheckBoxButton( imagePath, imagePath, imagePath, imagePath );
192   }
193   catch( ... )
194   {
195     tet_result( TET_FAIL );
196   }
197
198   DALI_TEST_CHECK( button0 );
199   DALI_TEST_CHECK( button1 );
200   DALI_TEST_CHECK( button2 );
201   DALI_TEST_CHECK( button3 );
202   DALI_TEST_CHECK( button4 );
203   DALI_TEST_CHECK( button5 );
204
205   try
206   {
207     button0 = CreateCheckBoxButton( voidImage, voidImage, voidImage, voidImage );
208     button1 = CreateCheckBoxButton( image, voidImage, voidImage, voidImage );
209     button2 = CreateCheckBoxButton( voidImage, image, voidImage, voidImage );
210     button3 = CreateCheckBoxButton( voidImage, voidImage, image, voidImage );
211     button4 = CreateCheckBoxButton( voidImage, voidImage, voidImage, image );
212     button5 = CreateCheckBoxButton( image, image, image, image );
213   }
214   catch( ... )
215   {
216     tet_result( TET_FAIL );
217   }
218
219   DALI_TEST_CHECK( button0 );
220   DALI_TEST_CHECK( button1 );
221   DALI_TEST_CHECK( button2 );
222   DALI_TEST_CHECK( button3 );
223   DALI_TEST_CHECK( button4 );
224   DALI_TEST_CHECK( button5 );
225
226   try
227   {
228     button0 = CreateCheckBoxButton( voidImagePath, voidImagePath );
229     button1 = CreateCheckBoxButton( voidImagePath, imagePath );
230     button2 = CreateCheckBoxButton( imagePath, voidImagePath );
231     button3 = CreateCheckBoxButton( imagePath, imagePath );
232   }
233   catch( ... )
234   {
235     tet_result( TET_FAIL );
236   }
237
238   DALI_TEST_CHECK( button0 );
239   DALI_TEST_CHECK( button1 );
240   DALI_TEST_CHECK( button2 );
241   DALI_TEST_CHECK( button3 );
242
243   try
244   {
245     button0 = CreateCheckBoxButton( voidImage, voidImage );
246     button2 = CreateCheckBoxButton( voidImage, image );
247     button3 = CreateCheckBoxButton( voidImage, image );
248     button4 = CreateCheckBoxButton( image, image );
249   }
250   catch( ... )
251   {
252     tet_result( TET_FAIL );
253   }
254
255   DALI_TEST_CHECK( button0 );
256   DALI_TEST_CHECK( button1 );
257   DALI_TEST_CHECK( button2 );
258   DALI_TEST_CHECK( button3 );
259 }