Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1678)

Unified Diff: base/command_line_unittest.cc

Issue 11305010: Extract arguments reconstruction logic out of GetCommandLineString() into GetArgumentsString(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more quotes working only on OS_WIN Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/command_line.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/command_line_unittest.cc
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index d93ffb89873dca7ae0397203219977e84c74786b..372af37a3d12c3d2274ad68b7db6ee84b3a81b1f 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -178,6 +178,64 @@ TEST(CommandLineTest, EmptyString) {
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";
« no previous file with comments | « base/command_line.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698