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

Unified Diff: base/command_line_unittest.cc

Issue 1063933002: Take a StringPiece when looking up CommandLine switches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cmd
Patch Set: Override copy and assign. Created 5 years, 8 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
« base/command_line.cc ('K') | « 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 e395c85677ab3f36844e9572b535e8f4d77adc90..018d83f1add248ca85f8825a6789cb477fb7b1b1 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -60,17 +61,18 @@ TEST(CommandLineTest, CommandLineConstructor) {
cl.GetProgram().value());
EXPECT_TRUE(cl.HasSwitch("foo"));
- EXPECT_TRUE(cl.HasSwitch("bAr"));
- EXPECT_TRUE(cl.HasSwitch("baz"));
- EXPECT_TRUE(cl.HasSwitch("spaetzle"));
#if defined(OS_WIN)
- EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
+ EXPECT_TRUE(cl.HasSwitch("bar"));
+#else
+ EXPECT_FALSE(cl.HasSwitch("bar"));
#endif
+ 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("foo"));
EXPECT_EQ("", cl.GetSwitchValueASCII("bar"));
EXPECT_EQ("", cl.GetSwitchValueASCII("cruller"));
EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
@@ -128,13 +130,12 @@ TEST(CommandLineTest, CommandLineFromString) {
EXPECT_TRUE(cl.HasSwitch("bar"));
EXPECT_TRUE(cl.HasSwitch("baz"));
EXPECT_TRUE(cl.HasSwitch("spaetzle"));
- EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
EXPECT_TRUE(cl.HasSwitch("other-switches"));
EXPECT_TRUE(cl.HasSwitch("input-translation"));
EXPECT_TRUE(cl.HasSwitch("quotes"));
EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle"));
- EXPECT_EQ("", cl.GetSwitchValueASCII("Foo"));
+ EXPECT_EQ("", cl.GetSwitchValueASCII("foo"));
EXPECT_EQ("", cl.GetSwitchValueASCII("bar"));
EXPECT_EQ("", cl.GetSwitchValueASCII("cruller"));
EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
@@ -273,6 +274,7 @@ TEST(CommandLineTest, AppendSwitches) {
cl.AppendSwitchASCII(switch2, value2);
cl.AppendSwitchASCII(switch3, value3);
cl.AppendSwitchASCII(switch4, value4);
+ cl.AppendSwitchASCII(switch5, value4);
cl.AppendSwitchNative(switch5, value5);
EXPECT_TRUE(cl.HasSwitch(switch1));
@@ -291,6 +293,9 @@ TEST(CommandLineTest, AppendSwitches) {
L"--switch2=value "
L"--switch3=\"a value with spaces\" "
L"--switch4=\"\\\"a value with quotes\\\"\" "
+ // Even though the switches are unique, appending can add repeat
+ // switches to argv.
+ L"--quotes=\"\\\"a value with quotes\\\"\" "
L"--quotes=\"" + kTrickyQuoted + L"\"",
cl.GetCommandLineString());
#endif
@@ -379,4 +384,20 @@ TEST(CommandLineTest, Init) {
EXPECT_EQ(initial, current);
}
+// Test that copies of CommandLine have a valid StringPiece map.
+TEST(CommandLineTest, Copy) {
+ scoped_ptr<CommandLine> initial(new CommandLine(CommandLine::NO_PROGRAM));
+ initial->AppendSwitch("a");
+ initial->AppendSwitch("bbbbbbbbbbbbbbb");
+ initial->AppendSwitch("c");
+ CommandLine copy_constructed(*initial);
+ CommandLine assigned = *initial;
+ CommandLine::SwitchMap switch_map = initial->GetSwitches();
+ initial.reset();
+ for (const auto& pair : switch_map)
+ EXPECT_TRUE(copy_constructed.HasSwitch(pair.first));
+ for (const auto& pair : switch_map)
+ EXPECT_TRUE(assigned.HasSwitch(pair.first));
+}
+
} // namespace base
« base/command_line.cc ('K') | « base/command_line.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698