Extract arguments reconstruction logic out of GetCommandLineString() into GetArgumentsString().
BUG=To get arguments we had to GetCommandLineString() and piece out the program: http://code.google.com/searchframe#OAMlx_jo-ck/src/chrome/installer/util/install_util.cc&exact_package=chromium&q=GetCommandLineString&type=cs&l=125
TEST=base_unittests.exe --gtest_filter=CommandLineTest*
Review URL: https://chromiumcodereview.appspot.com/11305010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164740 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index d93ffb89..372af37 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -178,6 +178,64 @@
EXPECT_TRUE(cl_from_argv.GetArgs().empty());
}
+TEST(CommandLineTest, GetArgumentsString) {
+ static const FilePath::CharType kPath1[] =
+ FILE_PATH_LITERAL("C:\\Some File\\With Spaces.ggg");
+ static const FilePath::CharType kPath2[] =
+ FILE_PATH_LITERAL("C:\\no\\spaces.ggg");
+
+ static const char kFirstArgName[] = "first-arg";
+ static const char kSecondArgName[] = "arg2";
+ static const char kThirdArgName[] = "arg with space";
+ static const char kFourthArgName[] = "nospace";
+
+ CommandLine cl(CommandLine::NO_PROGRAM);
+ cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1));
+ cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2));
+ cl.AppendArg(kThirdArgName);
+ cl.AppendArg(kFourthArgName);
+
+#if defined(OS_WIN)
+ CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName));
+ CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName));
+ CommandLine::StringType expected_third_arg(UTF8ToUTF16(kThirdArgName));
+ CommandLine::StringType expected_fourth_arg(UTF8ToUTF16(kFourthArgName));
+#elif defined(OS_POSIX)
+ CommandLine::StringType expected_first_arg(kFirstArgName);
+ CommandLine::StringType expected_second_arg(kSecondArgName);
+ CommandLine::StringType expected_third_arg(kThirdArgName);
+ CommandLine::StringType expected_fourth_arg(kFourthArgName);
+#endif
+
+#if defined(OS_WIN)
+#define QUOTE_ON_WIN FILE_PATH_LITERAL("\"")
+#else
+#define QUOTE_ON_WIN FILE_PATH_LITERAL("")
+#endif // OS_WIN
+
+ CommandLine::StringType expected_str;
+ expected_str.append(FILE_PATH_LITERAL("--"))
+ .append(expected_first_arg)
+ .append(FILE_PATH_LITERAL("="))
+ .append(QUOTE_ON_WIN)
+ .append(kPath1)
+ .append(QUOTE_ON_WIN)
+ .append(FILE_PATH_LITERAL(" "))
+ .append(FILE_PATH_LITERAL("--"))
+ .append(expected_second_arg)
+ .append(FILE_PATH_LITERAL("="))
+ .append(QUOTE_ON_WIN)
+ .append(kPath2)
+ .append(QUOTE_ON_WIN)
+ .append(FILE_PATH_LITERAL(" "))
+ .append(QUOTE_ON_WIN)
+ .append(expected_third_arg)
+ .append(QUOTE_ON_WIN)
+ .append(FILE_PATH_LITERAL(" "))
+ .append(expected_fourth_arg);
+ EXPECT_EQ(expected_str, cl.GetArgumentsString());
+}
+
// Test methods for appending switches to a command line.
TEST(CommandLineTest, AppendSwitches) {
std::string switch1 = "switch1";