4e332d18e61a6e0fd20fc42bfd341fa020992f90
[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.noVSyncOnRender, 0, TEST_LOCATION );
57   DALI_TEST_EQUALS( options.stageWidth, 0, TEST_LOCATION );
58   DALI_TEST_EQUALS( options.stageHeight, 0, TEST_LOCATION );
59   DALI_TEST_EQUALS( options.stageDPI, "", TEST_LOCATION );
60
61   END_TEST;
62 }
63
64 int UtcDaliCommandLineOptionsDaliShortArgs(void)
65 {
66   optind=0;
67
68   const char* argList[] =
69   {
70       "program",
71       "-w", "800",
72       "-h", "1000",
73       "-d", "4x5",
74   };
75   int argc( sizeof( argList ) / sizeof( argList[0] ) );
76   char** argv = const_cast<char**>(argList);
77
78   CommandLineOptions options( &argc, &argv );
79
80   // Should strip out the height and width
81   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
82
83   // Check values
84   DALI_TEST_EQUALS( options.noVSyncOnRender, 0, TEST_LOCATION );
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       "--no-vsync",
103       "--help"
104   };
105   int argc( sizeof( argList ) / sizeof( argList[0] ) );
106   char** argv = const_cast<char**>(argList);
107
108   CommandLineOptions options( &argc, &argv );
109
110   // Should strip out the height and width
111   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
112
113   // Check values
114   DALI_TEST_EQUALS( options.noVSyncOnRender, 1, TEST_LOCATION );
115   DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
116   DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
117   DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
118
119   END_TEST;
120 }
121
122 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
123 {
124   optind=0;
125
126   const char* argList[] =
127   {
128       "program",
129       "--width", "800",
130       "--height", "1000",
131       "--dpi", "3x4",
132       "--no-vsync",
133       "--help"
134   };
135   int argc( sizeof( argList ) / sizeof( argList[0] ) );
136   char** argv = const_cast<char**>(argList);
137
138   CommandLineOptions options( &argc, &argv );
139
140   // Should strip out the height and width
141   DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
142
143   // Check values
144   DALI_TEST_EQUALS( options.noVSyncOnRender, 1, TEST_LOCATION );
145   DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
146   DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
147   DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
148
149   END_TEST;
150 }
151
152 int UtcDaliCommandLineOptionsNonDaliArgs(void)
153 {
154   optind=0;
155
156   const char* argList[] =
157   {
158       "program",
159       "hello-world",
160       "-y", "600",
161   };
162   int argc( sizeof( argList ) / sizeof( argList[0] ) );
163   char** argv = const_cast<char**>(argList);
164
165   CommandLineOptions options( &argc, &argv );
166
167   // Should still be the same
168   DALI_TEST_EQUALS( argc, 4, TEST_LOCATION );
169
170   // Ensure order has not changed
171   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
172   DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
173   DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
174   DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
175
176   END_TEST;
177 }
178
179 int UtcDaliCommandLineOptionsMixture(void)
180 {
181   optind = 0; // Reset opt for test
182
183   const char* argList[] =
184   {
185     "program",
186     "--width=800",
187     "hello-world",
188     "-y", "600",
189     "--height", "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", "1000",
219       "-r",
220       "hello-world",
221       "-y", "600",
222   };
223   int argc( sizeof( argList ) / sizeof( argList[0] ) );
224   char** argv = const_cast<char**>( argList );
225
226   CommandLineOptions options( &argc, &argv );
227
228   // Should still be the same
229   DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
230
231   // Ensure order of program name and unhandled options has not changed
232   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
233   DALI_TEST_EQUALS( argList[1], "-r", TEST_LOCATION );
234   DALI_TEST_EQUALS( argList[2], "hello-world", TEST_LOCATION );
235   DALI_TEST_EQUALS( argList[3], "-y", TEST_LOCATION );
236   DALI_TEST_EQUALS( argList[4], "600", TEST_LOCATION );
237
238   END_TEST;
239 }
240
241 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
242 {
243   optind=0;
244
245   const char* argList[] =
246   {
247       "program",
248       "hello-world",
249       "-y", "600",
250       "-r",
251       "--width=800",
252       "--height", "1000",
253   };
254   int argc( sizeof( argList ) / sizeof( argList[0] ) );
255   char** argv = const_cast<char**>( argList );
256
257   CommandLineOptions options( &argc, &argv );
258
259   // Should still be the same
260   DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
261
262   // Ensure order of program name and unhandled options has not changed
263   DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
264   DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
265   DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
266   DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
267   DALI_TEST_EQUALS( argList[4], "-r", TEST_LOCATION );
268
269   END_TEST;
270 }