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