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