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

Unified Diff: chrome/install_static/install_util_unittest.cc

Issue 2543503003: Handle spaces and quotes in chrome_elf command line parser (Closed)
Patch Set: Created 4 years 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
Index: chrome/install_static/install_util_unittest.cc
diff --git a/chrome/install_static/install_util_unittest.cc b/chrome/install_static/install_util_unittest.cc
index 59b5749f83bd8686c5bec494c40c4d0781d8d8ad..0e3619250a1b08ec0d9ab74979a2c636a9378079 100644
--- a/chrome/install_static/install_util_unittest.cc
+++ b/chrome/install_static/install_util_unittest.cc
@@ -90,16 +90,72 @@ TEST(InstallStaticTest, GetSwitchValueFromCommandLineTest) {
value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\t",
L"type");
EXPECT_TRUE(value.empty());
+}
- // Whitespace after the "=" before the value.
- value =
- GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= bar", L"type");
- EXPECT_EQ(L"bar", value);
-
- // Tabs after the "=" before the value.
- value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\tbar",
- L"type");
- EXPECT_EQ(value, L"bar");
+TEST(InstallStaticTest, SpacesAndQuotesInCommandLineArguments) {
+ std::vector<std::wstring> tokenized;
+
+ tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\"");
+ ASSERT_EQ(1, tokenized.size());
+ EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]);
+
+ tokenized = TokenizeCommandLineToArray(L"x.exe");
+ ASSERT_EQ(1, tokenized.size());
+ EXPECT_EQ(L"x.exe", tokenized[0]);
+
+ tokenized = TokenizeCommandLineToArray(L"\"c:\\with space\\something.exe\"");
+ ASSERT_EQ(1, tokenized.size());
+ EXPECT_EQ(L"c:\\with space\\something.exe", tokenized[0]);
+
+ tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" arg");
+ ASSERT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"arg", tokenized[1]);
+
+ tokenized = TokenizeCommandLineToArray(L"\"C:\\with space\\b.exe\" \"arg\"");
+ ASSERT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"arg", tokenized[1]);
+
+ tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" c:\\tmp\\");
+ ASSERT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"c:\\tmp\\", tokenized[1]);
+
+ tokenized =
+ TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" \"c:\\some file path\\\"");
+ ASSERT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"c:\\some file path\"", tokenized[1]);
+
+ tokenized = TokenizeCommandLineToArray(
+ L"\"C:\\with space\\b.exe\" \\\\x\\\\ \\\\y\\\\");
+ ASSERT_EQ(3, tokenized.size());
+ EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"\\\\x\\\\", tokenized[1]);
+ EXPECT_EQ(L"\\\\y\\\\", tokenized[2]);
+
+ tokenized = TokenizeCommandLineToArray(
+ L"\"C:\\with space\\b.exe\" \"\\\\space quoted\\\\\"");
+ ASSERT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"\\\\space quoted\\", tokenized[1]);
+
+ tokenized = TokenizeCommandLineToArray(
+ L"\"C:\\with space\\b.exe\" --stuff -x -Y \"c:\\some thing\\\" "
+ L"weewaa ");
+ EXPECT_EQ(5, tokenized.size());
+ EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"--stuff", tokenized[1]);
+ EXPECT_EQ(L"-x", tokenized[2]);
+ EXPECT_EQ(L"-Y", tokenized[3]);
+ EXPECT_EQ(L"c:\\some thing\" weewaa ", tokenized[4]);
+
+ tokenized = TokenizeCommandLineToArray(
+ L"\"C:\\with space\\b.exe\" --stuff=\"d:\\stuff and things\"");
+ EXPECT_EQ(2, tokenized.size());
+ EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]);
+ EXPECT_EQ(L"--stuff=d:\\stuff and things", tokenized[1]);
}
TEST(InstallStaticTest, BrowserProcessTest) {
« chrome/install_static/install_util.cc ('K') | « chrome/install_static/install_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698