| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 16 matching lines...) Expand all Loading... |
| 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("FLAN"), | 36 FILE_PATH_LITERAL("FLAN"), |
| 37 FILE_PATH_LITERAL("a"), |
| 37 FILE_PATH_LITERAL("--input-translation=45--output-rotation"), | 38 FILE_PATH_LITERAL("--input-translation=45--output-rotation"), |
| 38 FILE_PATH_LITERAL("--"), | 39 FILE_PATH_LITERAL("--"), |
| 39 FILE_PATH_LITERAL("--"), | 40 FILE_PATH_LITERAL("--"), |
| 40 FILE_PATH_LITERAL("--not-a-switch"), | 41 FILE_PATH_LITERAL("--not-a-switch"), |
| 41 FILE_PATH_LITERAL("\"in the time of submarines...\""), | 42 FILE_PATH_LITERAL("\"in the time of submarines...\""), |
| 42 FILE_PATH_LITERAL("unquoted arg-with-space")}; | 43 FILE_PATH_LITERAL("unquoted arg-with-space")}; |
| 43 CommandLine cl(arraysize(argv), argv); | 44 CommandLine cl(arraysize(argv), argv); |
| 44 | 45 |
| 45 EXPECT_FALSE(cl.GetCommandLineString().empty()); | 46 EXPECT_FALSE(cl.GetCommandLineString().empty()); |
| 46 EXPECT_FALSE(cl.HasSwitch("cruller")); | 47 EXPECT_FALSE(cl.HasSwitch("cruller")); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 | 68 |
| 68 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); | 69 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); |
| 69 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); | 70 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); |
| 70 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); | 71 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); |
| 71 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); | 72 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); |
| 72 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( | 73 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( |
| 73 "other-switches")); | 74 "other-switches")); |
| 74 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); | 75 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); |
| 75 | 76 |
| 76 const CommandLine::StringVector& args = cl.GetArgs(); | 77 const CommandLine::StringVector& args = cl.GetArgs(); |
| 77 ASSERT_EQ(6U, args.size()); | 78 ASSERT_EQ(7U, args.size()); |
| 78 | 79 |
| 79 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); | 80 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); |
| 80 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); | 81 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); |
| 81 ++iter; | 82 ++iter; |
| 82 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); | 83 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); |
| 83 ++iter; | 84 ++iter; |
| 85 EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter); |
| 86 ++iter; |
| 84 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); | 87 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); |
| 85 ++iter; | 88 ++iter; |
| 86 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); | 89 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); |
| 87 ++iter; | 90 ++iter; |
| 88 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter); | 91 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter); |
| 89 ++iter; | 92 ++iter; |
| 90 EXPECT_EQ(FILE_PATH_LITERAL("unquoted arg-with-space"), *iter); | 93 EXPECT_EQ(FILE_PATH_LITERAL("unquoted arg-with-space"), *iter); |
| 91 ++iter; | 94 ++iter; |
| 92 EXPECT_TRUE(iter == args.end()); | 95 EXPECT_TRUE(iter == args.end()); |
| 93 } | 96 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 288 } |
| 286 #endif | 289 #endif |
| 287 | 290 |
| 288 // Calling Init multiple times should not modify the previous CommandLine. | 291 // Calling Init multiple times should not modify the previous CommandLine. |
| 289 TEST(CommandLineTest, Init) { | 292 TEST(CommandLineTest, Init) { |
| 290 CommandLine* initial = CommandLine::ForCurrentProcess(); | 293 CommandLine* initial = CommandLine::ForCurrentProcess(); |
| 291 CommandLine::Init(0, NULL); | 294 CommandLine::Init(0, NULL); |
| 292 CommandLine* current = CommandLine::ForCurrentProcess(); | 295 CommandLine* current = CommandLine::ForCurrentProcess(); |
| 293 EXPECT_EQ(initial, current); | 296 EXPECT_EQ(initial, current); |
| 294 } | 297 } |
| OLD | NEW |