| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 344 |
| 345 // Check that quotes are added to command line string paths containing spaces. | 345 // Check that quotes are added to command line string paths containing spaces. |
| 346 CommandLine::StringType cmd_string(cl_program_path.GetCommandLineString()); | 346 CommandLine::StringType cmd_string(cl_program_path.GetCommandLineString()); |
| 347 CommandLine::StringType program_string(cl_program_path.GetProgram().value()); | 347 CommandLine::StringType program_string(cl_program_path.GetProgram().value()); |
| 348 EXPECT_EQ('"', cmd_string[0]); | 348 EXPECT_EQ('"', cmd_string[0]); |
| 349 EXPECT_EQ(program_string, cmd_string.substr(1, program_string.length())); | 349 EXPECT_EQ(program_string, cmd_string.substr(1, program_string.length())); |
| 350 EXPECT_EQ('"', cmd_string[program_string.length() + 1]); | 350 EXPECT_EQ('"', cmd_string[program_string.length() + 1]); |
| 351 } | 351 } |
| 352 #endif | 352 #endif |
| 353 | 353 |
| 354 TEST(CommandLineTest, RemoveSwitches) { |
| 355 std::string switch1 = "switch1"; |
| 356 std::string switch2 = "switch2"; |
| 357 std::string value2 = "value"; |
| 358 std::string switch3 = "switch3"; |
| 359 std::string value3 = "a value with spaces"; |
| 360 std::string switch4 = "switch4"; |
| 361 std::string value4 = "\"a value with quotes\""; |
| 362 std::string switch5 = "quotes"; |
| 363 CommandLine::StringType value5 = kTricky; |
| 364 |
| 365 CommandLine cl(FilePath(FILE_PATH_LITERAL("Program"))); |
| 366 |
| 367 cl.AppendSwitch(switch1); |
| 368 cl.AppendSwitchASCII(switch2, value2); |
| 369 cl.AppendSwitchASCII(switch3, value3); |
| 370 cl.AppendSwitchASCII(switch4, value4); |
| 371 cl.AppendSwitchNative(switch5, value5); |
| 372 |
| 373 EXPECT_TRUE(cl.HasSwitch(switch1)); |
| 374 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 375 EXPECT_TRUE(cl.HasSwitch(switch3)); |
| 376 EXPECT_TRUE(cl.HasSwitch(switch4)); |
| 377 EXPECT_TRUE(cl.HasSwitch(switch5)); |
| 378 |
| 379 // Ignore not-included switch. |
| 380 cl.RemoveSwitch("ignore_switch"); |
| 381 EXPECT_TRUE(cl.HasSwitch(switch1)); |
| 382 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 383 EXPECT_TRUE(cl.HasSwitch(switch3)); |
| 384 EXPECT_TRUE(cl.HasSwitch(switch4)); |
| 385 EXPECT_TRUE(cl.HasSwitch(switch5)); |
| 386 |
| 387 // Remove switches in the random order. |
| 388 cl.RemoveSwitch(switch3); |
| 389 EXPECT_FALSE(cl.HasSwitch(switch3)); |
| 390 EXPECT_TRUE(cl.HasSwitch(switch1)); |
| 391 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 392 EXPECT_TRUE(cl.HasSwitch(switch4)); |
| 393 EXPECT_TRUE(cl.HasSwitch(switch5)); |
| 394 |
| 395 cl.RemoveSwitch(switch1); |
| 396 EXPECT_FALSE(cl.HasSwitch(switch1)); |
| 397 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 398 EXPECT_TRUE(cl.HasSwitch(switch4)); |
| 399 EXPECT_TRUE(cl.HasSwitch(switch5)); |
| 400 |
| 401 cl.RemoveSwitch(switch4); |
| 402 EXPECT_FALSE(cl.HasSwitch(switch4)); |
| 403 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 404 EXPECT_TRUE(cl.HasSwitch(switch5)); |
| 405 |
| 406 cl.RemoveSwitch(switch5); |
| 407 EXPECT_FALSE(cl.HasSwitch(switch5)); |
| 408 EXPECT_TRUE(cl.HasSwitch(switch2)); |
| 409 |
| 410 cl.RemoveSwitch(switch2); |
| 411 EXPECT_FALSE(cl.HasSwitch(switch2)); |
| 412 |
| 413 EXPECT_EQ(FILE_PATH_LITERAL("Program"), cl.GetCommandLineString()); |
| 414 } |
| 415 |
| 354 // Calling Init multiple times should not modify the previous CommandLine. | 416 // Calling Init multiple times should not modify the previous CommandLine. |
| 355 TEST(CommandLineTest, Init) { | 417 TEST(CommandLineTest, Init) { |
| 356 CommandLine* initial = CommandLine::ForCurrentProcess(); | 418 CommandLine* initial = CommandLine::ForCurrentProcess(); |
| 357 EXPECT_FALSE(CommandLine::Init(0, NULL)); | 419 EXPECT_FALSE(CommandLine::Init(0, NULL)); |
| 358 CommandLine* current = CommandLine::ForCurrentProcess(); | 420 CommandLine* current = CommandLine::ForCurrentProcess(); |
| 359 EXPECT_EQ(initial, current); | 421 EXPECT_EQ(initial, current); |
| 360 } | 422 } |
| OLD | NEW |