| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 EXPECT_TRUE(cl.HasSwitch("input-translation")); | 66 EXPECT_TRUE(cl.HasSwitch("input-translation")); |
| 67 | 67 |
| 68 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); | 68 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); |
| 69 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); | 69 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); |
| 70 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); | 70 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); |
| 71 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); | 71 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); |
| 72 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( | 72 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( |
| 73 "other-switches")); | 73 "other-switches")); |
| 74 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); | 74 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); |
| 75 | 75 |
| 76 const std::vector<CommandLine::StringType>& args = cl.args(); | 76 const CommandLine::StringVector& args = cl.GetArgs(); |
| 77 ASSERT_EQ(6U, args.size()); | 77 ASSERT_EQ(6U, args.size()); |
| 78 | 78 |
| 79 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); | 79 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); |
| 80 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); | 80 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); |
| 81 ++iter; | 81 ++iter; |
| 82 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); | 82 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); |
| 83 ++iter; | 83 ++iter; |
| 84 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); | 84 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); |
| 85 ++iter; | 85 ++iter; |
| 86 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); | 86 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); | 128 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); |
| 129 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); | 129 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); |
| 130 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); | 130 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); |
| 131 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); | 131 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); |
| 132 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( | 132 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( |
| 133 "other-switches")); | 133 "other-switches")); |
| 134 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); | 134 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); |
| 135 EXPECT_EQ(kTricky, cl.GetSwitchValueNative("quotes")); | 135 EXPECT_EQ(kTricky, cl.GetSwitchValueNative("quotes")); |
| 136 | 136 |
| 137 const std::vector<CommandLine::StringType>& args = cl.args(); | 137 const CommandLine::StringVector& args = cl.GetArgs(); |
| 138 ASSERT_EQ(5U, args.size()); | 138 ASSERT_EQ(5U, args.size()); |
| 139 | 139 |
| 140 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); | 140 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); |
| 141 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); | 141 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); |
| 142 ++iter; | 142 ++iter; |
| 143 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); | 143 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); |
| 144 ++iter; | 144 ++iter; |
| 145 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); | 145 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); |
| 146 ++iter; | 146 ++iter; |
| 147 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); | 147 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); |
| 148 ++iter; | 148 ++iter; |
| 149 EXPECT_EQ(FILE_PATH_LITERAL("in the time of submarines..."), *iter); | 149 EXPECT_EQ(FILE_PATH_LITERAL("in the time of submarines..."), *iter); |
| 150 ++iter; | 150 ++iter; |
| 151 EXPECT_TRUE(iter == args.end()); | 151 EXPECT_TRUE(iter == args.end()); |
| 152 | 152 |
| 153 // Check that a generated string produces an equivalent command line. | 153 // Check that a generated string produces an equivalent command line. |
| 154 CommandLine cl_duplicate = CommandLine::FromString(cl.command_line_string()); | 154 CommandLine cl_duplicate = CommandLine::FromString(cl.command_line_string()); |
| 155 EXPECT_EQ(cl.command_line_string(), cl_duplicate.command_line_string()); | 155 EXPECT_EQ(cl.command_line_string(), cl_duplicate.command_line_string()); |
| 156 #endif | 156 #endif |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Tests behavior with an empty input string. | 159 // Tests behavior with an empty input string. |
| 160 TEST(CommandLineTest, EmptyString) { | 160 TEST(CommandLineTest, EmptyString) { |
| 161 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 162 CommandLine cl_from_string = CommandLine::FromString(L""); | 162 CommandLine cl_from_string = CommandLine::FromString(L""); |
| 163 EXPECT_TRUE(cl_from_string.command_line_string().empty()); | 163 EXPECT_TRUE(cl_from_string.command_line_string().empty()); |
| 164 EXPECT_TRUE(cl_from_string.GetProgram().empty()); | 164 EXPECT_TRUE(cl_from_string.GetProgram().empty()); |
| 165 EXPECT_EQ(1U, cl_from_string.argv().size()); | 165 EXPECT_EQ(1U, cl_from_string.argv().size()); |
| 166 EXPECT_TRUE(cl_from_string.args().empty()); | 166 EXPECT_TRUE(cl_from_string.GetArgs().empty()); |
| 167 #endif | 167 #endif |
| 168 CommandLine cl_from_argv(0, NULL); | 168 CommandLine cl_from_argv(0, NULL); |
| 169 EXPECT_TRUE(cl_from_argv.command_line_string().empty()); | 169 EXPECT_TRUE(cl_from_argv.command_line_string().empty()); |
| 170 EXPECT_TRUE(cl_from_argv.GetProgram().empty()); | 170 EXPECT_TRUE(cl_from_argv.GetProgram().empty()); |
| 171 EXPECT_EQ(1U, cl_from_argv.argv().size()); | 171 EXPECT_EQ(1U, cl_from_argv.argv().size()); |
| 172 EXPECT_TRUE(cl_from_argv.args().empty()); | 172 EXPECT_TRUE(cl_from_argv.GetArgs().empty()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Test methods for appending switches to a command line. | 175 // Test methods for appending switches to a command line. |
| 176 TEST(CommandLineTest, AppendSwitches) { | 176 TEST(CommandLineTest, AppendSwitches) { |
| 177 std::string switch1 = "switch1"; | 177 std::string switch1 = "switch1"; |
| 178 std::string switch2 = "switch2"; | 178 std::string switch2 = "switch2"; |
| 179 std::string value2 = "value"; | 179 std::string value2 = "value"; |
| 180 std::string switch3 = "switch3"; | 180 std::string switch3 = "switch3"; |
| 181 std::string value3 = "a value with spaces"; | 181 std::string value3 = "a value with spaces"; |
| 182 std::string switch4 = "switch4"; | 182 std::string switch4 = "switch4"; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 EXPECT_EQ(kProgramPath.value(), cl_program_path.GetProgram().value()); | 277 EXPECT_EQ(kProgramPath.value(), cl_program_path.GetProgram().value()); |
| 278 | 278 |
| 279 // Check that quotes are added to command line string paths containing spaces. | 279 // Check that quotes are added to command line string paths containing spaces. |
| 280 CommandLine::StringType cmd_string(cl_program_path.command_line_string()); | 280 CommandLine::StringType cmd_string(cl_program_path.command_line_string()); |
| 281 CommandLine::StringType program_string(cl_program_path.GetProgram().value()); | 281 CommandLine::StringType program_string(cl_program_path.GetProgram().value()); |
| 282 EXPECT_EQ('"', cmd_string[0]); | 282 EXPECT_EQ('"', cmd_string[0]); |
| 283 EXPECT_EQ(program_string, cmd_string.substr(1, program_string.length())); | 283 EXPECT_EQ(program_string, cmd_string.substr(1, program_string.length())); |
| 284 EXPECT_EQ('"', cmd_string[program_string.length() + 1]); | 284 EXPECT_EQ('"', cmd_string[program_string.length() + 1]); |
| 285 } | 285 } |
| 286 #endif | 286 #endif |
| OLD | NEW |