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

Unified Diff: chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc

Issue 10127009: Make NameValuePairsParser support values that contain the 'equal' separator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 8 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
Index: chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc
diff --git a/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc
index ddbd908af698b5e23284f8435a7147081dbab506..dd70cd5b78cab408f29beb99a4b49b9400dc4665 100644
--- a/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc
+++ b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc
@@ -25,7 +25,7 @@ TEST(NameValuePairsParser, TestParseNameValuePairs) {
NameValuePairsParser parser(&map);
const std::string contents1 = "foo=Foo bar=Bar\nfoobar=FooBar\n";
EXPECT_TRUE(parser.ParseNameValuePairs(contents1, "=", " \n"));
- ASSERT_EQ(3U, map.size());
+ EXPECT_EQ(3U, map.size());
EXPECT_EQ("Foo", map["foo"]);
EXPECT_EQ("Bar", map["bar"]);
EXPECT_EQ("FooBar", map["foobar"]);
@@ -33,17 +33,22 @@ TEST(NameValuePairsParser, TestParseNameValuePairs) {
map.clear();
const std::string contents2 = "foo=Foo,bar=Bar";
EXPECT_TRUE(parser.ParseNameValuePairs(contents2, "=", ",\n"));
- ASSERT_EQ(2U, map.size());
+ EXPECT_EQ(2U, map.size());
EXPECT_EQ("Foo", map["foo"]);
EXPECT_EQ("Bar", map["bar"]);
map.clear();
const std::string contents3 = "foo=Foo=foo,bar=Bar";
- EXPECT_FALSE(parser.ParseNameValuePairs(contents3, "=", ",\n"));
+ EXPECT_TRUE(parser.ParseNameValuePairs(contents3, "=", ",\n"));
+ EXPECT_EQ(2U, map.size());
+ EXPECT_EQ("Foo=foo", map["foo"]);
+ EXPECT_EQ("Bar", map["bar"]);
map.clear();
const std::string contents4 = "foo=Foo,=Bar";
EXPECT_FALSE(parser.ParseNameValuePairs(contents4, "=", ",\n"));
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ("Foo", map["foo"]);
map.clear();
const std::string contents5 =
@@ -51,12 +56,38 @@ TEST(NameValuePairsParser, TestParseNameValuePairs) {
"\"initial_timezone\"=\"Asia/Tokyo\"\n"
"\"keyboard_layout\"=\"mozc-jp\"\n";
EXPECT_TRUE(parser.ParseNameValuePairs(contents5, "=", "\n"));
- ASSERT_EQ(3U, map.size());
+ EXPECT_EQ(3U, map.size());
EXPECT_EQ("ja", map["initial_locale"]);
EXPECT_EQ("Asia/Tokyo", map["initial_timezone"]);
EXPECT_EQ("mozc-jp", map["keyboard_layout"]);
}
+TEST(NameValuePairsParser, TestParseNameValuePairsWithComments) {
+ NameValuePairsParser::NameValueMap map;
+ NameValuePairsParser parser(&map);
+
+ const std::string contents1 = "foo=Foo,bar=#Bar,baz= 0 #Baz";
+ EXPECT_TRUE(parser.ParseNameValuePairsWithComments(
+ contents1, "=", ",\n", "#"));
+ EXPECT_EQ(3U, map.size());
+ EXPECT_EQ("Foo", map["foo"]);
+ EXPECT_EQ("", map["bar"]);
+ EXPECT_EQ("0", map["baz"]);
+
+ map.clear();
+ const std::string contents2 = "foo=";
+ EXPECT_TRUE(parser.ParseNameValuePairsWithComments(
+ contents2, "=", ",\n", "#"));
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ("", map["foo"]);
+
+ map.clear();
+ const std::string contents3 = " \t ,,#all empty,";
+ EXPECT_FALSE(parser.ParseNameValuePairsWithComments(
+ contents3, "=", ",\n", "#"));
+ EXPECT_EQ(0U, map.size());
+}
+
TEST(NameValuePairsParser, TestParseNameValuePairsFromTool) {
// Sample output is taken from the /usr/bin/crosssytem tool.
const char* command[] = { "/bin/echo",
@@ -64,19 +95,24 @@ TEST(NameValuePairsParser, TestParseNameValuePairsFromTool) {
"cros_debug = 1 # OS should allow debug\n" \
"dbg_reset = (error) # Debug reset mode request\n" \
"key#with_comment = some value # Multiple # comment # delims\n" \
- "key = # No value."
+ "key = # No value.\n" \
+ "vdat_timers = " \
+ "LFS=0,0 LF=1784220250,2971030570 LK=9064076660,9342689170 " \
+ "# Timer values from VbSharedData\n"
};
NameValuePairsParser::NameValueMap map;
NameValuePairsParser parser(&map);
parser.ParseNameValuePairsFromTool(
arraysize(command), command, "=", "\n", "#");
+ EXPECT_EQ(6u, map.size());
EXPECT_EQ("x86", map["arch"]);
EXPECT_EQ("1", map["cros_debug"]);
EXPECT_EQ("(error)", map["dbg_reset"]);
EXPECT_EQ("some value", map["key#with_comment"]);
EXPECT_EQ("", map["key"]);
- EXPECT_EQ(5u, map.size());
+ EXPECT_EQ("LFS=0,0 LF=1784220250,2971030570 LK=9064076660,9342689170",
+ map["vdat_timers"]);
}
} // namespace system

Powered by Google App Engine
This is Rietveld 408576698