OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 EXPECT_EQ(1U, cl_from_string.argv().size()); | 171 EXPECT_EQ(1U, cl_from_string.argv().size()); |
172 EXPECT_TRUE(cl_from_string.GetArgs().empty()); | 172 EXPECT_TRUE(cl_from_string.GetArgs().empty()); |
173 #endif | 173 #endif |
174 CommandLine cl_from_argv(0, NULL); | 174 CommandLine cl_from_argv(0, NULL); |
175 EXPECT_TRUE(cl_from_argv.GetCommandLineString().empty()); | 175 EXPECT_TRUE(cl_from_argv.GetCommandLineString().empty()); |
176 EXPECT_TRUE(cl_from_argv.GetProgram().empty()); | 176 EXPECT_TRUE(cl_from_argv.GetProgram().empty()); |
177 EXPECT_EQ(1U, cl_from_argv.argv().size()); | 177 EXPECT_EQ(1U, cl_from_argv.argv().size()); |
178 EXPECT_TRUE(cl_from_argv.GetArgs().empty()); | 178 EXPECT_TRUE(cl_from_argv.GetArgs().empty()); |
179 } | 179 } |
180 | 180 |
| 181 TEST(CommandLineTest, GetArgumentsString) { |
| 182 static const FilePath::CharType kPath1[] = |
| 183 FILE_PATH_LITERAL("C:\\Some File\\With Spaces.ggg"); |
| 184 static const FilePath::CharType kPath2[] = |
| 185 FILE_PATH_LITERAL("C:\\no\\spaces.ggg"); |
| 186 |
| 187 static const char kFirstArgName[] = "first-arg"; |
| 188 static const char kSecondArgName[] = "arg2"; |
| 189 static const char kThirdArgName[] = "arg with space"; |
| 190 static const char kFourthArgName[] = "nospace"; |
| 191 |
| 192 CommandLine cl(CommandLine::NO_PROGRAM); |
| 193 cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1)); |
| 194 cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2)); |
| 195 cl.AppendArg(kThirdArgName); |
| 196 cl.AppendArg(kFourthArgName); |
| 197 |
| 198 #if defined(OS_WIN) |
| 199 CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName)); |
| 200 CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName)); |
| 201 CommandLine::StringType expected_third_arg(UTF8ToUTF16(kThirdArgName)); |
| 202 CommandLine::StringType expected_fourth_arg(UTF8ToUTF16(kFourthArgName)); |
| 203 #elif defined(OS_POSIX) |
| 204 CommandLine::StringType expected_first_arg(kFirstArgName); |
| 205 CommandLine::StringType expected_second_arg(kSecondArgName); |
| 206 CommandLine::StringType expected_third_arg(kThirdArgName); |
| 207 CommandLine::StringType expected_fourth_arg(kFourthArgName); |
| 208 #endif |
| 209 |
| 210 #if defined(OS_WIN) |
| 211 #define QUOTE_ON_WIN FILE_PATH_LITERAL("\"") |
| 212 #else |
| 213 #define QUOTE_ON_WIN FILE_PATH_LITERAL("") |
| 214 #endif // OS_WIN |
| 215 |
| 216 CommandLine::StringType expected_str; |
| 217 expected_str.append(FILE_PATH_LITERAL("--")) |
| 218 .append(expected_first_arg) |
| 219 .append(FILE_PATH_LITERAL("=")) |
| 220 .append(QUOTE_ON_WIN) |
| 221 .append(kPath1) |
| 222 .append(QUOTE_ON_WIN) |
| 223 .append(FILE_PATH_LITERAL(" ")) |
| 224 .append(FILE_PATH_LITERAL("--")) |
| 225 .append(expected_second_arg) |
| 226 .append(FILE_PATH_LITERAL("=")) |
| 227 .append(QUOTE_ON_WIN) |
| 228 .append(kPath2) |
| 229 .append(QUOTE_ON_WIN) |
| 230 .append(FILE_PATH_LITERAL(" ")) |
| 231 .append(QUOTE_ON_WIN) |
| 232 .append(expected_third_arg) |
| 233 .append(QUOTE_ON_WIN) |
| 234 .append(FILE_PATH_LITERAL(" ")) |
| 235 .append(expected_fourth_arg); |
| 236 EXPECT_EQ(expected_str, cl.GetArgumentsString()); |
| 237 } |
| 238 |
181 // Test methods for appending switches to a command line. | 239 // Test methods for appending switches to a command line. |
182 TEST(CommandLineTest, AppendSwitches) { | 240 TEST(CommandLineTest, AppendSwitches) { |
183 std::string switch1 = "switch1"; | 241 std::string switch1 = "switch1"; |
184 std::string switch2 = "switch2"; | 242 std::string switch2 = "switch2"; |
185 std::string value2 = "value"; | 243 std::string value2 = "value"; |
186 std::string switch3 = "switch3"; | 244 std::string switch3 = "switch3"; |
187 std::string value3 = "a value with spaces"; | 245 std::string value3 = "a value with spaces"; |
188 std::string switch4 = "switch4"; | 246 std::string switch4 = "switch4"; |
189 std::string value4 = "\"a value with quotes\""; | 247 std::string value4 = "\"a value with quotes\""; |
190 std::string switch5 = "quotes"; | 248 std::string switch5 = "quotes"; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 349 } |
292 #endif | 350 #endif |
293 | 351 |
294 // Calling Init multiple times should not modify the previous CommandLine. | 352 // Calling Init multiple times should not modify the previous CommandLine. |
295 TEST(CommandLineTest, Init) { | 353 TEST(CommandLineTest, Init) { |
296 CommandLine* initial = CommandLine::ForCurrentProcess(); | 354 CommandLine* initial = CommandLine::ForCurrentProcess(); |
297 EXPECT_FALSE(CommandLine::Init(0, NULL)); | 355 EXPECT_FALSE(CommandLine::Init(0, NULL)); |
298 CommandLine* current = CommandLine::ForCurrentProcess(); | 356 CommandLine* current = CommandLine::ForCurrentProcess(); |
299 EXPECT_EQ(initial, current); | 357 EXPECT_EQ(initial, current); |
300 } | 358 } |
OLD | NEW |