| Index: base/command_line_unittest.cc
|
| diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
|
| index 6fd64407a470e1be897dec37d94cdad114d80b91..d121a6952609c3c7680032bd3cdafe72738eae3b 100644
|
| --- a/base/command_line_unittest.cc
|
| +++ b/base/command_line_unittest.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -21,26 +21,93 @@
|
| #define TRICKY L"q\"bs1\\bs2\\\\bs3q\\\""
|
|
|
| TEST(CommandLineTest, CommandLineConstructor) {
|
| -#if defined(OS_WIN)
|
| - CommandLine cl = CommandLine::FromString(
|
| - L"program --foo= -bAr /Spaetzel=pierogi /Baz flim "
|
| - L"--other-switches=\"--dog=canine --cat=feline\" "
|
| - L"-spaetzle=Crepe -=loosevalue flan "
|
| - L"--input-translation=\"45\"--output-rotation "
|
| - L"--quotes=" TRICKY_QUOTED L" "
|
| - L"-- -- --not-a-switch "
|
| - L"\"in the time of submarines...\"");
|
| + const CommandLine::CharType* argv[] = {
|
| + FILE_PATH_LITERAL("program"),
|
| + FILE_PATH_LITERAL("--foo="),
|
| + FILE_PATH_LITERAL("-bar"),
|
| + FILE_PATH_LITERAL("-spaetzel=pierogi"),
|
| + FILE_PATH_LITERAL("-baz"),
|
| + FILE_PATH_LITERAL("flim"),
|
| + FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"),
|
| + FILE_PATH_LITERAL("-spaetzle=Crepe"),
|
| + FILE_PATH_LITERAL("-=loosevalue"),
|
| + FILE_PATH_LITERAL("flan"),
|
| + FILE_PATH_LITERAL("--input-translation=45--output-rotation"),
|
| + FILE_PATH_LITERAL("--"),
|
| + FILE_PATH_LITERAL("--"),
|
| + FILE_PATH_LITERAL("--not-a-switch"),
|
| + FILE_PATH_LITERAL("in the time of submarines...")};
|
| + CommandLine cl(arraysize(argv), argv);
|
| +
|
| EXPECT_FALSE(cl.command_line_string().empty());
|
| + EXPECT_FALSE(cl.HasSwitch("cruller"));
|
| + EXPECT_FALSE(cl.HasSwitch("flim"));
|
| + EXPECT_FALSE(cl.HasSwitch("program"));
|
| + EXPECT_FALSE(cl.HasSwitch("dog"));
|
| + EXPECT_FALSE(cl.HasSwitch("cat"));
|
| + EXPECT_FALSE(cl.HasSwitch("output-rotation"));
|
| + EXPECT_FALSE(cl.HasSwitch("not-a-switch"));
|
| + EXPECT_FALSE(cl.HasSwitch("--"));
|
| +
|
| + EXPECT_EQ(FilePath(FILE_PATH_LITERAL("program")).value(),
|
| + cl.GetProgram().value());
|
| +
|
| + EXPECT_TRUE(cl.HasSwitch("foo"));
|
| + EXPECT_TRUE(cl.HasSwitch("bar"));
|
| + EXPECT_TRUE(cl.HasSwitch("baz"));
|
| + EXPECT_TRUE(cl.HasSwitch("spaetzle"));
|
| + EXPECT_TRUE(cl.HasSwitch("other-switches"));
|
| + EXPECT_TRUE(cl.HasSwitch("input-translation"));
|
| +
|
| + EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle"));
|
| + EXPECT_EQ("", cl.GetSwitchValueASCII("Foo"));
|
| + EXPECT_EQ("", cl.GetSwitchValueASCII("bar"));
|
| + EXPECT_EQ("", cl.GetSwitchValueASCII("cruller"));
|
| + EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
|
| + "other-switches"));
|
| + EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));
|
| +
|
| + const std::vector<CommandLine::StringType>& args = cl.args();
|
| + ASSERT_EQ(5U, args.size());
|
| +
|
| + std::vector<CommandLine::StringType>::const_iterator iter = args.begin();
|
| + EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter);
|
| + ++iter;
|
| + EXPECT_EQ(FILE_PATH_LITERAL("flan"), *iter);
|
| + ++iter;
|
| + EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter);
|
| + ++iter;
|
| + EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter);
|
| + ++iter;
|
| +#if defined(OS_WIN)
|
| + EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter);
|
| #elif defined(OS_POSIX)
|
| - const char* argv[] = {"program", "--foo=", "-bar",
|
| - "-spaetzel=pierogi", "-baz", "flim",
|
| - "--other-switches=--dog=canine --cat=feline",
|
| - "-spaetzle=Crepe", "-=loosevalue", "flan",
|
| - "--input-translation=45--output-rotation",
|
| - "--", "--", "--not-a-switch",
|
| - "in the time of submarines..."};
|
| - CommandLine cl(arraysize(argv), argv);
|
| + EXPECT_EQ(FILE_PATH_LITERAL("in the time of submarines..."), *iter);
|
| #endif
|
| + ++iter;
|
| + EXPECT_TRUE(iter == args.end());
|
| +
|
| +//#if defined(OS_POSIX)
|
| +// // On Windows, arguments are quote-escaped and won't be exactly equivalent.
|
| +// // On all platforms, sanitized args won't be exactly equivalent.
|
| +// const std::vector<CommandLine::StringType>& argvec = cl.argv();
|
| +// for (size_t i = 0; i < argvec.size(); i++)
|
| +// EXPECT_EQ(0, argvec[i].compare(argv[i]));
|
| +//#endif
|
| +}
|
| +
|
| +TEST(CommandLineTest, CommandLineFromString) {
|
| +#if defined(OS_WIN)
|
| + CommandLine cl = CommandLine::FromString(
|
| + L"program --foo= -bAr /Spaetzel=pierogi /Baz flim "
|
| + L"--other-switches=\"--dog=canine --cat=feline\" "
|
| + L"-spaetzle=Crepe -=loosevalue flan "
|
| + L"--input-translation=\"45\"--output-rotation "
|
| + L"--quotes=" TRICKY_QUOTED L" "
|
| + L"-- -- --not-a-switch "
|
| + L"\"in the time of submarines...\"");
|
| +
|
| + EXPECT_FALSE(cl.command_line_string().empty());
|
| EXPECT_FALSE(cl.HasSwitch("cruller"));
|
| EXPECT_FALSE(cl.HasSwitch("flim"));
|
| EXPECT_FALSE(cl.HasSwitch("program"));
|
| @@ -57,14 +124,10 @@ TEST(CommandLineTest, CommandLineConstructor) {
|
| EXPECT_TRUE(cl.HasSwitch("bar"));
|
| EXPECT_TRUE(cl.HasSwitch("baz"));
|
| EXPECT_TRUE(cl.HasSwitch("spaetzle"));
|
| -#if defined(OS_WIN)
|
| EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
|
| -#endif
|
| EXPECT_TRUE(cl.HasSwitch("other-switches"));
|
| EXPECT_TRUE(cl.HasSwitch("input-translation"));
|
| -#if defined(OS_WIN)
|
| EXPECT_TRUE(cl.HasSwitch("quotes"));
|
| -#endif
|
|
|
| EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle"));
|
| EXPECT_EQ("", cl.GetSwitchValueASCII("Foo"));
|
| @@ -73,9 +136,7 @@ TEST(CommandLineTest, CommandLineConstructor) {
|
| EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
|
| "other-switches"));
|
| EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));
|
| -#if defined(OS_WIN)
|
| EXPECT_EQ(TRICKY, cl.GetSwitchValueNative("quotes"));
|
| -#endif
|
|
|
| const std::vector<CommandLine::StringType>& args = cl.args();
|
| ASSERT_EQ(5U, args.size());
|
| @@ -89,28 +150,21 @@ TEST(CommandLineTest, CommandLineConstructor) {
|
| ++iter;
|
| EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter);
|
| ++iter;
|
| - EXPECT_EQ(FILE_PATH_LITERAL("in the time of submarines..."), *iter);
|
| + EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter);
|
| ++iter;
|
| EXPECT_TRUE(iter == args.end());
|
| -#if defined(OS_POSIX)
|
| - const std::vector<std::string>& argvec = cl.argv();
|
| -
|
| - for (size_t i = 0; i < argvec.size(); i++) {
|
| - EXPECT_EQ(0, argvec[i].compare(argv[i]));
|
| - }
|
| #endif
|
| }
|
|
|
| // Tests behavior with an empty input string.
|
| TEST(CommandLineTest, EmptyString) {
|
| #if defined(OS_WIN)
|
| - CommandLine cl = CommandLine::FromString(L"");
|
| - EXPECT_TRUE(cl.command_line_string().empty());
|
| - EXPECT_TRUE(cl.GetProgram().empty());
|
| -#elif defined(OS_POSIX)
|
| + CommandLine cl_from_string = CommandLine::FromString(L"");
|
| + EXPECT_TRUE(cl_from_string.command_line_string().empty());
|
| + EXPECT_TRUE(cl_from_string.GetProgram().empty());
|
| +#endif
|
| CommandLine cl(0, NULL);
|
| EXPECT_TRUE(cl.argv().size() == 0);
|
| -#endif
|
| EXPECT_EQ(0U, cl.args().size());
|
| }
|
|
|
|
|