2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/dali.h>
23 #include <command-line-options.h>
24 #include <dali-test-suite-utils.h>
27 using namespace Dali::Internal::Adaptor;
30 // Called only once before first test is run.
31 void command_line_options_startup(void)
33 test_return_value = TET_UNDEF;
34 optind = 1; // Reset opt for test
37 // Called only once after last test is run
38 void command_line_options_cleanup(void)
40 test_return_value = TET_PASS;
45 int gOriginalOptIndValue(0);
49 int UtcDaliCommandLineOptionsNoArgs(void)
54 const char* argList[1] = { "program" };
55 char** argv = const_cast<char**>(argList);
57 CommandLineOptions options( &argc, &argv );
59 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
70 int UtcDaliCommandLineOptionsDaliShortArgs(void)
74 const char* argList[] =
81 int argc( sizeof( argList ) / sizeof( argList[0] ) );
82 char** argv = const_cast<char**>(argList);
84 CommandLineOptions options( &argc, &argv );
86 // Should strip out the height and width
87 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
98 int UtcDaliCommandLineOptionsDaliLongArgsEqualsSign(void)
102 const char* argList[] =
111 int argc( sizeof( argList ) / sizeof( argList[0] ) );
112 char** argv = const_cast<char**>(argList);
114 CommandLineOptions options( &argc, &argv );
116 // Should strip out the height and width
117 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
128 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
132 const char* argList[] =
141 int argc( sizeof( argList ) / sizeof( argList[0] ) );
142 char** argv = const_cast<char**>(argList);
144 CommandLineOptions options( &argc, &argv );
146 // Should strip out the height and width
147 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
158 int UtcDaliCommandLineOptionsNonDaliArgs(void)
162 const char* argList[] =
168 int argc( sizeof( argList ) / sizeof( argList[0] ) );
169 char** argv = const_cast<char**>(argList);
171 CommandLineOptions options( &argc, &argv );
173 // Should still be the same
174 DALI_TEST_EQUALS( argc, 4, TEST_LOCATION );
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 );
185 int UtcDaliCommandLineOptionsMixture(void)
187 optind = 1; // Reset opt for test
198 int argc( sizeof( argList ) / sizeof( argList[0] ) );
199 char** argv = argList;
201 CommandLineOptions options( &argc, &argv );
203 // Should still be the same
204 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );
216 int UtcDaliCommandLineOptionsMixtureDaliOpsAtStart(void)
229 int argc( sizeof( argList ) / sizeof( argList[0] ) );
230 char** argv = argList;
232 CommandLineOptions options( &argc, &argv );
234 // Should still be the same
235 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );
247 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
260 int argc( sizeof( argList ) / sizeof( argList[0] ) );
261 char** argv = argList;
263 CommandLineOptions options( &argc, &argv );
265 // Should still be the same
266 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );