Revert "[Tizen] Add DALi Autofill implementation"
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / utc-Dali-CommandLineOptions.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 <getopt.h>
22 #include <dali/dali.h>
23 #include <dali/internal/system/common/command-line-options.h>
24 #include <dali-test-suite-utils.h>
25
26 using namespace Dali;
27 using namespace Dali::Internal::Adaptor;
28
29
30 // Called only once before first test is run.
31 void command_line_options_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34   optind = 0; // Reset opt for test
35 }
36
37 // Called only once after last test is run
38 void command_line_options_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int UtcDaliCommandLineOptionsNoArgs(void)
44 {
45   optind=0;
46
47   int argc( 1 );
48   const char* argList[1] = { "program" };
49   char** argv = const_cast<char**>(argList);
50
51   CommandLineOptions options( &argc, &argv );
52
53   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
54
55   // Check values
56   DALI_TEST_EQUALS( options.stageWidth, 0, TEST_LOCATION );
57   DALI_TEST_EQUALS( options.stageHeight, 0, TEST_LOCATION );
58   DALI_TEST_EQUALS( options.stageDPI, "", TEST_LOCATION );
59
60   END_TEST;
61 }
62
63 int UtcDaliCommandLineOptionsDaliShortArgs(void)
64 {
65   optind=0;
66
67   const char* argList[] =
68   {
69       "program",
70       "-w", "800",
71       "-h", "1000",
72       "-d", "4x5",
73   };
74   int argc( sizeof( argList ) / sizeof( argList[0] ) );
75   char** argv = const_cast<char**>(argList);
76
77   CommandLineOptions options( &argc, &argv );
78
79   // Should strip out the height and width
80   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
81
82   // Check values
83   DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
84   DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
85   DALI_TEST_EQUALS( options.stageDPI, "4x5", TEST_LOCATION );
86
87   END_TEST;
88 }
89
90 int UtcDaliCommandLineOptionsDaliLongArgsEqualsSign(void)
91 {
92   optind=0;
93
94   const char* argList[] =
95   {
96       "program",
97       "--width=800",
98       "--height=1000",
99       "--dpi=3x4",
100       "--help"
101   };
102   int argc( sizeof( argList ) / sizeof( argList[0] ) );
103   char** argv = const_cast<char**>(argList);
104
105   CommandLineOptions options( &argc, &argv );
106
107   // Should strip out the height and width
108   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
109
110   // Check values
111   DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
112   DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
113   DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
114
115   END_TEST;
116 }
117
118 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
119 {
120   optind=0;
121
122   const char* argList[] =
123   {
124       "program",
125       "--width", "800",
126       "--height", "1000",
127       "--dpi", "3x4",
128       "--help"
129   };
130   int argc( sizeof( argList ) / sizeof( argList[0] ) );
131   char** argv = const_cast<char**>(argList);
132
133   CommandLineOptions options( &argc, &argv );
134
135   // Should strip out the height and width
136   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
137
138   // Check values
139   DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
140   DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
141   DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
142
143   END_TEST;
144 }
145
146 int UtcDaliCommandLineOptionsNonDaliArgs(void)
147 {
148   optind=0;
149
150   const char* argList[] =
151   {
152       "program",
153       "hello-world",
154       "-y", "600",
155   };
156   int argc( sizeof( argList ) / sizeof( argList[0] ) );
157   char** argv = const_cast<char**>(argList);
158
159   CommandLineOptions options( &argc, &argv );
160
161   // Should still be the same
162   DALI_TEST_EQUALS( argc, 4, TEST_LOCATION );
163
164   // Ensure order has not changed
165   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
166   DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
167   DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
168   DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
169
170   END_TEST;
171 }
172
173 int UtcDaliCommandLineOptionsMixture(void)
174 {
175   optind = 0; // Reset opt for test
176
177   const char* argList[] =
178   {
179     "program",
180     "--width=800",
181     "hello-world",
182     "-y", "600",
183     "--height", "1000",
184     "-r",
185   };
186   int argc( sizeof( argList ) / sizeof( argList[0] ) );
187   char** argv = const_cast<char**>( argList );
188
189   CommandLineOptions options( &argc, &argv );
190
191   // Should still be the same
192   DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
193
194   // Ensure order of program name and unhandled options has not changed
195   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
196   DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
197   DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
198   DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
199   DALI_TEST_EQUALS( argList[4], "-r", TEST_LOCATION );
200
201   END_TEST;
202 }
203
204 int UtcDaliCommandLineOptionsMixtureDaliOpsAtStart(void)
205 {
206   optind=0;
207
208   const char* argList[] =
209   {
210       "program",
211       "--width=800",
212       "--height", "1000",
213       "-r",
214       "hello-world",
215       "-y", "600",
216   };
217   int argc( sizeof( argList ) / sizeof( argList[0] ) );
218   char** argv = const_cast<char**>( argList );
219
220   CommandLineOptions options( &argc, &argv );
221
222   // Should still be the same
223   DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
224
225   // Ensure order of program name and unhandled options has not changed
226   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
227   DALI_TEST_EQUALS( argList[1], "-r", TEST_LOCATION );
228   DALI_TEST_EQUALS( argList[2], "hello-world", TEST_LOCATION );
229   DALI_TEST_EQUALS( argList[3], "-y", TEST_LOCATION );
230   DALI_TEST_EQUALS( argList[4], "600", TEST_LOCATION );
231
232   END_TEST;
233 }
234
235 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
236 {
237   optind=0;
238
239   const char* argList[] =
240   {
241       "program",
242       "hello-world",
243       "-y", "600",
244       "-r",
245       "--width=800",
246       "--height", "1000",
247   };
248   int argc( sizeof( argList ) / sizeof( argList[0] ) );
249   char** argv = const_cast<char**>( argList );
250
251   CommandLineOptions options( &argc, &argv );
252
253   // Should still be the same
254   DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
255
256   // Ensure order of program name and unhandled options has not changed
257   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
258   DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
259   DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
260   DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
261   DALI_TEST_EQUALS( argList[4], "-r", TEST_LOCATION );
262
263   END_TEST;
264 }