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.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 );
64 int UtcDaliCommandLineOptionsDaliShortArgs(void)
68 const char* argList[] =
75 int argc( sizeof( argList ) / sizeof( argList[0] ) );
76 char** argv = const_cast<char**>(argList);
78 CommandLineOptions options( &argc, &argv );
80 // Should strip out the height and width
81 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
92 int UtcDaliCommandLineOptionsDaliLongArgsEqualsSign(void)
96 const char* argList[] =
105 int argc( sizeof( argList ) / sizeof( argList[0] ) );
106 char** argv = const_cast<char**>(argList);
108 CommandLineOptions options( &argc, &argv );
110 // Should strip out the height and width
111 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
122 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
126 const char* argList[] =
135 int argc( sizeof( argList ) / sizeof( argList[0] ) );
136 char** argv = const_cast<char**>(argList);
138 CommandLineOptions options( &argc, &argv );
140 // Should strip out the height and width
141 DALI_TEST_EQUALS( argc, 1, TEST_LOCATION );
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 );
152 int UtcDaliCommandLineOptionsNonDaliArgs(void)
156 const char* argList[] =
162 int argc( sizeof( argList ) / sizeof( argList[0] ) );
163 char** argv = const_cast<char**>(argList);
165 CommandLineOptions options( &argc, &argv );
167 // Should still be the same
168 DALI_TEST_EQUALS( argc, 4, TEST_LOCATION );
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 );
179 int UtcDaliCommandLineOptionsMixture(void)
181 optind = 0; // Reset opt for test
183 const char* argList[] =
192 int argc( sizeof( argList ) / sizeof( argList[0] ) );
193 char** argv = const_cast<char**>( argList );
195 CommandLineOptions options( &argc, &argv );
197 // Should still be the same
198 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );
210 int UtcDaliCommandLineOptionsMixtureDaliOpsAtStart(void)
214 const char* argList[] =
223 int argc( sizeof( argList ) / sizeof( argList[0] ) );
224 char** argv = const_cast<char**>( argList );
226 CommandLineOptions options( &argc, &argv );
228 // Should still be the same
229 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );
241 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
245 const char* argList[] =
254 int argc( sizeof( argList ) / sizeof( argList[0] ) );
255 char** argv = const_cast<char**>( argList );
257 CommandLineOptions options( &argc, &argv );
259 // Should still be the same
260 DALI_TEST_EQUALS( argc, 5, TEST_LOCATION );
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 );