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

Unified Diff: base/json/json_writer_unittest.cc

Issue 1141793003: Update from https://crrev.com/329939 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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/json/json_parser.cc ('k') | base/json/string_escape_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_writer_unittest.cc
diff --git a/base/json/json_writer_unittest.cc b/base/json/json_writer_unittest.cc
index ae46800dde686f9a3255f57dc8a99bc5b28fd445..5ac2590a0d87ee16d5803c95e43d65529a9ce1bd 100644
--- a/base/json/json_writer_unittest.cc
+++ b/base/json/json_writer_unittest.cc
@@ -12,75 +12,63 @@ TEST(JSONWriterTest, BasicTypes) {
std::string output_js;
// Test null.
- Value* root = Value::CreateNullValue();
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ EXPECT_TRUE(JSONWriter::Write(Value::CreateNullValue().get(), &output_js));
EXPECT_EQ("null", output_js);
- delete root;
// Test empty dict.
- root = new DictionaryValue;
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ DictionaryValue dict;
+ EXPECT_TRUE(JSONWriter::Write(&dict, &output_js));
EXPECT_EQ("{}", output_js);
- delete root;
// Test empty list.
- root = new ListValue;
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ ListValue list;
+ EXPECT_TRUE(JSONWriter::Write(&list, &output_js));
EXPECT_EQ("[]", output_js);
- delete root;
// Test integer values.
- root = new FundamentalValue(42);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ FundamentalValue int_value(42);
+ EXPECT_TRUE(JSONWriter::Write(&int_value, &output_js));
EXPECT_EQ("42", output_js);
- delete root;
// Test boolean values.
- root = new FundamentalValue(true);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ FundamentalValue bool_value(true);
+ EXPECT_TRUE(JSONWriter::Write(&bool_value, &output_js));
EXPECT_EQ("true", output_js);
- delete root;
// Test Real values should always have a decimal or an 'e'.
- root = new FundamentalValue(1.0);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ FundamentalValue double_value(1.0);
+ EXPECT_TRUE(JSONWriter::Write(&double_value, &output_js));
EXPECT_EQ("1.0", output_js);
- delete root;
// Test Real values in the the range (-1, 1) must have leading zeros
- root = new FundamentalValue(0.2);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ FundamentalValue double_value2(0.2);
+ EXPECT_TRUE(JSONWriter::Write(&double_value2, &output_js));
EXPECT_EQ("0.2", output_js);
- delete root;
// Test Real values in the the range (-1, 1) must have leading zeros
- root = new FundamentalValue(-0.8);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ FundamentalValue double_value3(-0.8);
+ EXPECT_TRUE(JSONWriter::Write(&double_value3, &output_js));
EXPECT_EQ("-0.8", output_js);
- delete root;
// Test String values.
- root = new StringValue("foo");
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ StringValue string_value("foo");
+ EXPECT_TRUE(JSONWriter::Write(&string_value, &output_js));
EXPECT_EQ("\"foo\"", output_js);
- delete root;
}
-
TEST(JSONWriterTest, NestedTypes) {
std::string output_js;
// Writer unittests like empty list/dict nesting,
// list list nesting, etc.
DictionaryValue root_dict;
- ListValue* list = new ListValue;
- root_dict.Set("list", list);
- DictionaryValue* inner_dict = new DictionaryValue;
- list->Append(inner_dict);
+ scoped_ptr<ListValue> list(new ListValue());
+ scoped_ptr<DictionaryValue> inner_dict(new DictionaryValue());
inner_dict->SetInteger("inner int", 10);
- ListValue* inner_list = new ListValue;
- list->Append(inner_list);
- list->Append(new FundamentalValue(true));
+ list->Append(inner_dict.Pass());
+ list->Append(make_scoped_ptr(new ListValue()));
+ list->AppendBoolean(true);
+ root_dict.Set("list", list.Pass());
// Test the pretty-printer.
EXPECT_TRUE(JSONWriter::Write(&root_dict, &output_js));
@@ -109,17 +97,17 @@ TEST(JSONWriterTest, KeysWithPeriods) {
std::string output_js;
DictionaryValue period_dict;
- period_dict.SetWithoutPathExpansion("a.b", new FundamentalValue(3));
- period_dict.SetWithoutPathExpansion("c", new FundamentalValue(2));
- DictionaryValue* period_dict2 = new DictionaryValue;
- period_dict2->SetWithoutPathExpansion("g.h.i.j", new FundamentalValue(1));
- period_dict.SetWithoutPathExpansion("d.e.f", period_dict2);
+ period_dict.SetIntegerWithoutPathExpansion("a.b", 3);
+ period_dict.SetIntegerWithoutPathExpansion("c", 2);
+ scoped_ptr<DictionaryValue> period_dict2(new DictionaryValue());
+ period_dict2->SetIntegerWithoutPathExpansion("g.h.i.j", 1);
+ period_dict.SetWithoutPathExpansion("d.e.f", period_dict2.Pass());
EXPECT_TRUE(JSONWriter::Write(&period_dict, &output_js));
EXPECT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js);
DictionaryValue period_dict3;
- period_dict3.Set("a.b", new FundamentalValue(2));
- period_dict3.SetWithoutPathExpansion("a.b", new FundamentalValue(1));
+ period_dict3.SetInteger("a.b", 2);
+ period_dict3.SetIntegerWithoutPathExpansion("a.b", 1);
EXPECT_TRUE(JSONWriter::Write(&period_dict3, &output_js));
EXPECT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js);
}
@@ -129,18 +117,17 @@ TEST(JSONWriterTest, BinaryValues) {
// Binary values should return errors unless suppressed via the
// OPTIONS_OMIT_BINARY_VALUES flag.
- Value* root = BinaryValue::CreateWithCopiedBuffer("asdf", 4);
- EXPECT_FALSE(JSONWriter::Write(root, &output_js));
+ scoped_ptr<Value> root(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
+ EXPECT_FALSE(JSONWriter::Write(root.get(), &output_js));
EXPECT_TRUE(JSONWriter::WriteWithOptions(
- root, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js));
+ root.get(), JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js));
EXPECT_TRUE(output_js.empty());
- delete root;
ListValue binary_list;
binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
- binary_list.Append(new FundamentalValue(5));
+ binary_list.Append(make_scoped_ptr(new FundamentalValue(5)));
binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
- binary_list.Append(new FundamentalValue(2));
+ binary_list.Append(make_scoped_ptr(new FundamentalValue(2)));
binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
EXPECT_FALSE(JSONWriter::Write(&binary_list, &output_js));
EXPECT_TRUE(JSONWriter::WriteWithOptions(
@@ -148,11 +135,14 @@ TEST(JSONWriterTest, BinaryValues) {
EXPECT_EQ("[5,2]", output_js);
DictionaryValue binary_dict;
- binary_dict.Set("a", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
- binary_dict.Set("b", new FundamentalValue(5));
- binary_dict.Set("c", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
- binary_dict.Set("d", new FundamentalValue(2));
- binary_dict.Set("e", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
+ binary_dict.Set(
+ "a", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
+ binary_dict.SetInteger("b", 5);
+ binary_dict.Set(
+ "c", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
+ binary_dict.SetInteger("d", 2);
+ binary_dict.Set(
+ "e", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
EXPECT_FALSE(JSONWriter::Write(&binary_dict, &output_js));
EXPECT_TRUE(JSONWriter::WriteWithOptions(
&binary_dict, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js));
« no previous file with comments | « base/json/json_parser.cc ('k') | base/json/string_escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698