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 <dali/internal/system/common/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 = 0; // 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;
43 int UtcDaliCommandLineOptionsNoArgs(void)
48 const char* argList[1] = { "program" };
49 char** argv = const_cast<char**>(argList);
51 CommandLineOptions options( &argc, &argv );
53 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
56 DALI_TEST_EQUALS( options.stageWidth, 0, TEST_LOCATION );
57 DALI_TEST_EQUALS( options.stageHeight, 0, TEST_LOCATION );
58 DALI_TEST_EQUALS( options.stageDPI, "", TEST_LOCATION );
63 int UtcDaliCommandLineOptionsDaliShortArgs(void)
67 const char* argList[] =
74 int argc( sizeof( argList ) / sizeof( argList[0] ) );
75 char** argv = const_cast<char**>(argList);
77 CommandLineOptions options( &argc, &argv );
79 // Should strip out the height and width
80 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
83 DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
84 DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
85 DALI_TEST_EQUALS( options.stageDPI, "4x5", TEST_LOCATION );
90 int UtcDaliCommandLineOptionsDaliLongArgsEqualsSign(void)
94 const char* argList[] =
102 int argc( sizeof( argList ) / sizeof( argList[0] ) );
103 char** argv = const_cast<char**>(argList);
105 CommandLineOptions options( &argc, &argv );
107 // Should strip out the height and width
108 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
111 DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
112 DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
113 DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
118 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
122 const char* argList[] =
130 int argc( sizeof( argList ) / sizeof( argList[0] ) );
131 char** argv = const_cast<char**>(argList);
133 CommandLineOptions options( &argc, &argv );
135 // Should strip out the height and width
136 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
139 DALI_TEST_EQUALS( options.stageWidth, 800, TEST_LOCATION );
140 DALI_TEST_EQUALS( options.stageHeight, 1000, TEST_LOCATION );
141 DALI_TEST_EQUALS( options.stageDPI, "3x4", TEST_LOCATION );
146 int UtcDaliCommandLineOptionsNonDaliArgs(void)
150 const char* argList[] =
156 int argc( sizeof( argList ) / sizeof( argList[0] ) );
157 char** argv = const_cast<char**>(argList);
159 CommandLineOptions options( &argc, &argv );
161 // Should still be the same
162 DALI_TEST_EQUALS( argc, 4, TEST_LOCATION );
164 // Ensure order has not changed
165 DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
166 DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
167 DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
168 DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
173 int UtcDaliCommandLineOptionsMixture(void)
175 optind = 0; // Reset opt for test
177 const char* argList[] =
186 int argc( sizeof( argList ) / sizeof( argList[0] ) );
187 char** argv = const_cast<char**>( argList );
189 CommandLineOptions options( &argc, &argv );
191 // Should still be the same
192 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
194 // Ensure order of program name and unhandled options has not changed
195 DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
196 DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
197 DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
198 DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
199 DALI_TEST_EQUALS( argList[4], "-r", TEST_LOCATION );
204 int UtcDaliCommandLineOptionsMixtureDaliOpsAtStart(void)
208 const char* argList[] =
217 int argc( sizeof( argList ) / sizeof( argList[0] ) );
218 char** argv = const_cast<char**>( argList );
220 CommandLineOptions options( &argc, &argv );
222 // Should still be the same
223 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
225 // Ensure order of program name and unhandled options has not changed
226 DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
227 DALI_TEST_EQUALS( argList[1], "-r", TEST_LOCATION );
228 DALI_TEST_EQUALS( argList[2], "hello-world", TEST_LOCATION );
229 DALI_TEST_EQUALS( argList[3], "-y", TEST_LOCATION );
230 DALI_TEST_EQUALS( argList[4], "600", TEST_LOCATION );
235 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
239 const char* argList[] =
248 int argc( sizeof( argList ) / sizeof( argList[0] ) );
249 char** argv = const_cast<char**>( argList );
251 CommandLineOptions options( &argc, &argv );
253 // Should still be the same
254 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
256 // Ensure order of program name and unhandled options has not changed
257 DALI_TEST_EQUALS( argList[0], "program", TEST_LOCATION );
258 DALI_TEST_EQUALS( argList[1], "hello-world", TEST_LOCATION );
259 DALI_TEST_EQUALS( argList[2], "-y", TEST_LOCATION );
260 DALI_TEST_EQUALS( argList[3], "600", TEST_LOCATION );
261 DALI_TEST_EQUALS( argList[4], "-r", TEST_LOCATION );