Chromium Code Reviews| 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 0af8488d2651d598c7bb37b94658c2f45a1a711a..e20f0a4635f4b033d8135e44e05318d2ecea33f6 100644 |
| --- a/chrome/install_static/install_util_unittest.cc |
| +++ b/chrome/install_static/install_util_unittest.cc |
| @@ -130,4 +130,68 @@ TEST(InstallStaticTest, CompareVersions) { |
| EXPECT_EQ(-1, result); |
| } |
| +// Tests the install_static::GetSwitchValueFromCommandLine function. |
| +TEST(InstallStaticTest, GetSwitchValueFromCommandLineTest) { |
| + // Simple case with one switch. |
| + std::string value = |
| + GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=bar", "type"); |
| + EXPECT_EQ(value, "bar"); |
|
Lei Zhang
2016/06/15 23:20:46
The arguments are flipped around. As is, when this
ananta
2016/06/16 00:29:30
Done.
|
| + |
| + // Multiple switches with trailing spaces between them. |
| + value = GetSwitchValueFromCommandLine( |
| + "c:\\temp\\bleh.exe --type=bar --abc=def bleh", "abc"); |
| + EXPECT_EQ(value, "def"); |
| + |
| + // Multiple switches with trailing spaces and tabs between them. |
| + value = GetSwitchValueFromCommandLine( |
| + "c:\\temp\\bleh.exe --type=bar \t\t\t --abc=def bleh", "abc"); |
| + EXPECT_EQ(value, "def"); |
| + |
| + // Non existent switch. |
| + value = GetSwitchValueFromCommandLine( |
| + "c:\\temp\\bleh.exe --foo=bar --abc=def bleh", "type"); |
| + EXPECT_EQ(value, ""); |
| + |
| + // Non existent switch. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe", "type"); |
| + EXPECT_EQ(value, ""); |
| + |
| + // Non existent switch. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe type=bar", "type"); |
| + EXPECT_EQ(value, ""); |
| + |
| + // Trailing spaces after the switch. |
| + value = GetSwitchValueFromCommandLine( |
| + "c:\\temp\\bleh.exe --type=bar \t\t", "type"); |
| + EXPECT_EQ(value, "bar"); |
| + |
| + // Multiple switches with trailing spaces and tabs between them. |
| + value = GetSwitchValueFromCommandLine( |
| + "c:\\temp\\bleh.exe --type=bar \t\t --foo=bleh", "foo"); |
| + EXPECT_EQ(value, "bleh"); |
| + |
| + // Nothing after a switch. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=", "type"); |
| + EXPECT_TRUE(value.empty()); |
| + |
| + // Whitespace after a switch. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type= ", "type"); |
| + EXPECT_TRUE(value.empty()); |
| + |
| + // Just tabs after a switch. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=\t\t\t", |
| + "type"); |
| + EXPECT_TRUE(value.empty()); |
| + |
| + // Whitespace after the "=" before the value. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type= bar", |
| + "type"); |
| + EXPECT_EQ(value, "bar"); |
| + |
| + // Tabs after the "=" before the value. |
| + value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=\t\t\tbar", |
| + "type"); |
| + EXPECT_EQ(value, "bar"); |
| +} |
| + |
| } // namespace install_static |