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.
20 #include <dali-test-suite-utils.h>
21 #include <dali/dali.h>
22 #include <dali/internal/system/common/command-line-options.h>
27 using namespace Dali::Internal::Adaptor;
29 // Called only once before first test is run.
30 void command_line_options_startup(void)
32 test_return_value = TET_UNDEF;
33 optind = 0; // Reset opt for test
36 // Called only once after last test is run
37 void command_line_options_cleanup(void)
39 test_return_value = TET_PASS;
42 int UtcDaliCommandLineOptionsNoArgs(void)
47 const char* argList[1] = {"program"};
48 char** argv = const_cast<char**>(argList);
50 CommandLineOptions options(&argc, &argv);
52 DALI_TEST_EQUALS(argc, 1, TEST_LOCATION);
55 DALI_TEST_EQUALS(options.stageWidth, 0, TEST_LOCATION);
56 DALI_TEST_EQUALS(options.stageHeight, 0, TEST_LOCATION);
57 DALI_TEST_EQUALS(options.stageDPI, "", TEST_LOCATION);
62 int UtcDaliCommandLineOptionsDaliShortArgs(void)
66 const char* argList[] =
76 int argc(sizeof(argList) / sizeof(argList[0]));
77 char** argv = const_cast<char**>(argList);
79 CommandLineOptions options(&argc, &argv);
81 // Should strip out the height and width
82 DALI_TEST_EQUALS(argc, 1, 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[] =
103 int argc(sizeof(argList) / sizeof(argList[0]));
104 char** argv = const_cast<char**>(argList);
106 CommandLineOptions options(&argc, &argv);
108 // Should strip out the height and width
109 DALI_TEST_EQUALS(argc, 1, TEST_LOCATION);
112 DALI_TEST_EQUALS(options.stageWidth, 800, TEST_LOCATION);
113 DALI_TEST_EQUALS(options.stageHeight, 1000, TEST_LOCATION);
114 DALI_TEST_EQUALS(options.stageDPI, "3x4", TEST_LOCATION);
119 int UtcDaliCommandLineOptionsDaliLongArgsSpaces(void)
123 const char* argList[] =
133 int argc(sizeof(argList) / sizeof(argList[0]));
134 char** argv = const_cast<char**>(argList);
136 CommandLineOptions options(&argc, &argv);
138 // Should strip out the height and width
139 DALI_TEST_EQUALS(argc, 1, TEST_LOCATION);
142 DALI_TEST_EQUALS(options.stageWidth, 800, TEST_LOCATION);
143 DALI_TEST_EQUALS(options.stageHeight, 1000, TEST_LOCATION);
144 DALI_TEST_EQUALS(options.stageDPI, "3x4", TEST_LOCATION);
149 int UtcDaliCommandLineOptionsNonDaliArgs(void)
153 const char* argList[] =
160 int argc(sizeof(argList) / sizeof(argList[0]));
161 char** argv = const_cast<char**>(argList);
163 CommandLineOptions options(&argc, &argv);
165 // Should still be the same
166 DALI_TEST_EQUALS(argc, 4, TEST_LOCATION);
168 // Ensure order has not changed
169 DALI_TEST_EQUALS(argList[0], "program", TEST_LOCATION);
170 DALI_TEST_EQUALS(argList[1], "hello-world", TEST_LOCATION);
171 DALI_TEST_EQUALS(argList[2], "-y", TEST_LOCATION);
172 DALI_TEST_EQUALS(argList[3], "600", TEST_LOCATION);
177 int UtcDaliCommandLineOptionsMixture(void)
179 optind = 0; // Reset opt for test
181 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[] =
225 int argc(sizeof(argList) / sizeof(argList[0]));
226 char** argv = const_cast<char**>(argList);
228 CommandLineOptions options(&argc, &argv);
230 // Should still be the same
231 DALI_TEST_EQUALS(argc, 5, TEST_LOCATION);
233 // Ensure order of program name and unhandled options has not changed
234 DALI_TEST_EQUALS(argList[0], "program", TEST_LOCATION);
235 DALI_TEST_EQUALS(argList[1], "-r", TEST_LOCATION);
236 DALI_TEST_EQUALS(argList[2], "hello-world", TEST_LOCATION);
237 DALI_TEST_EQUALS(argList[3], "-y", TEST_LOCATION);
238 DALI_TEST_EQUALS(argList[4], "600", TEST_LOCATION);
243 int UtcDaliCommandLineOptionsMixtureDaliOpsAtEnd(void)
247 const char* argList[] =
258 int argc(sizeof(argList) / sizeof(argList[0]));
259 char** argv = const_cast<char**>(argList);
261 CommandLineOptions options(&argc, &argv);
263 // Should still be the same
264 DALI_TEST_EQUALS(argc, 5, TEST_LOCATION);
266 // Ensure order of program name and unhandled options has not changed
267 DALI_TEST_EQUALS(argList[0], "program", TEST_LOCATION);
268 DALI_TEST_EQUALS(argList[1], "hello-world", TEST_LOCATION);
269 DALI_TEST_EQUALS(argList[2], "-y", TEST_LOCATION);
270 DALI_TEST_EQUALS(argList[3], "600", TEST_LOCATION);
271 DALI_TEST_EQUALS(argList[4], "-r", TEST_LOCATION);