| 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 15 matching lines...) Expand all Loading... |
| 26 const CommandLine::CharType* argv[] = { | 26 const CommandLine::CharType* argv[] = { |
| 27 FILE_PATH_LITERAL("program"), | 27 FILE_PATH_LITERAL("program"), |
| 28 FILE_PATH_LITERAL("--foo="), | 28 FILE_PATH_LITERAL("--foo="), |
| 29 FILE_PATH_LITERAL("-bAr"), | 29 FILE_PATH_LITERAL("-bAr"), |
| 30 FILE_PATH_LITERAL("-spaetzel=pierogi"), | 30 FILE_PATH_LITERAL("-spaetzel=pierogi"), |
| 31 FILE_PATH_LITERAL("-baz"), | 31 FILE_PATH_LITERAL("-baz"), |
| 32 FILE_PATH_LITERAL("flim"), | 32 FILE_PATH_LITERAL("flim"), |
| 33 FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"), | 33 FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"), |
| 34 FILE_PATH_LITERAL("-spaetzle=Crepe"), | 34 FILE_PATH_LITERAL("-spaetzle=Crepe"), |
| 35 FILE_PATH_LITERAL("-=loosevalue"), | 35 FILE_PATH_LITERAL("-=loosevalue"), |
| 36 FILE_PATH_LITERAL("-"), |
| 36 FILE_PATH_LITERAL("FLAN"), | 37 FILE_PATH_LITERAL("FLAN"), |
| 37 FILE_PATH_LITERAL("a"), | 38 FILE_PATH_LITERAL("a"), |
| 38 FILE_PATH_LITERAL("--input-translation=45--output-rotation"), | 39 FILE_PATH_LITERAL("--input-translation=45--output-rotation"), |
| 39 FILE_PATH_LITERAL("--"), | 40 FILE_PATH_LITERAL("--"), |
| 40 FILE_PATH_LITERAL("--"), | 41 FILE_PATH_LITERAL("--"), |
| 41 FILE_PATH_LITERAL("--not-a-switch"), | 42 FILE_PATH_LITERAL("--not-a-switch"), |
| 42 FILE_PATH_LITERAL("\"in the time of submarines...\""), | 43 FILE_PATH_LITERAL("\"in the time of submarines...\""), |
| 43 FILE_PATH_LITERAL("unquoted arg-with-space")}; | 44 FILE_PATH_LITERAL("unquoted arg-with-space")}; |
| 44 CommandLine cl(arraysize(argv), argv); | 45 CommandLine cl(arraysize(argv), argv); |
| 45 | 46 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 | 69 |
| 69 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); | 70 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); |
| 70 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); | 71 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); |
| 71 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); | 72 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); |
| 72 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); | 73 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); |
| 73 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( | 74 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( |
| 74 "other-switches")); | 75 "other-switches")); |
| 75 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); | 76 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); |
| 76 | 77 |
| 77 const CommandLine::StringVector& args = cl.GetArgs(); | 78 const CommandLine::StringVector& args = cl.GetArgs(); |
| 78 ASSERT_EQ(7U, args.size()); | 79 ASSERT_EQ(8U, args.size()); |
| 79 | 80 |
| 80 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); | 81 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); |
| 81 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); | 82 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); |
| 82 ++iter; | 83 ++iter; |
| 84 EXPECT_EQ(FILE_PATH_LITERAL("-"), *iter); |
| 85 ++iter; |
| 83 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); | 86 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); |
| 84 ++iter; | 87 ++iter; |
| 85 EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter); | 88 EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter); |
| 86 ++iter; | 89 ++iter; |
| 87 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); | 90 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); |
| 88 ++iter; | 91 ++iter; |
| 89 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); | 92 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); |
| 90 ++iter; | 93 ++iter; |
| 91 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter); | 94 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter); |
| 92 ++iter; | 95 ++iter; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 291 } |
| 289 #endif | 292 #endif |
| 290 | 293 |
| 291 // Calling Init multiple times should not modify the previous CommandLine. | 294 // Calling Init multiple times should not modify the previous CommandLine. |
| 292 TEST(CommandLineTest, Init) { | 295 TEST(CommandLineTest, Init) { |
| 293 CommandLine* initial = CommandLine::ForCurrentProcess(); | 296 CommandLine* initial = CommandLine::ForCurrentProcess(); |
| 294 EXPECT_FALSE(CommandLine::Init(0, NULL)); | 297 EXPECT_FALSE(CommandLine::Init(0, NULL)); |
| 295 CommandLine* current = CommandLine::ForCurrentProcess(); | 298 CommandLine* current = CommandLine::ForCurrentProcess(); |
| 296 EXPECT_EQ(initial, current); | 299 EXPECT_EQ(initial, current); |
| 297 } | 300 } |
| OLD | NEW |