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