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

Unified Diff: base/json/json_writer_unittest.cc

Issue 1138103002: base: Use scoped_ptr for ownership of pointers in unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrtests: . 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 | « no previous file | base/values_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 ec60b5eeae768e65b738f29e77b3bba1c01eedbc..1eb3c2b84a9d7efca69add7cac9980588a93e786 100644
--- a/base/json/json_writer_unittest.cc
+++ b/base/json/json_writer_unittest.cc
@@ -12,58 +12,49 @@ TEST(JSONWriterTest, BasicTypes) {
std::string output_js;
// Test null.
- Value* root = Value::CreateNullValue();
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ scoped_ptr<Value> root = make_scoped_ptr(Value::CreateNullValue());
Nico 2015/05/11 18:16:08 Do you need make_scoped_ptr here? Doesn't just
danakj 2015/05/11 18:17:51 Ya I can/should use that constructor instead, done
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("null", output_js);
- delete root;
// Test empty dict.
- root = new DictionaryValue;
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ root = make_scoped_ptr(new DictionaryValue);
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("{}", output_js);
- delete root;
// Test empty list.
- root = new ListValue;
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ root = make_scoped_ptr(new ListValue);
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("[]", output_js);
- delete root;
// Test integer values.
- root = new FundamentalValue(42);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ root = make_scoped_ptr(new FundamentalValue(42));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("42", output_js);
- delete root;
// Test boolean values.
- root = new FundamentalValue(true);
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ root = make_scoped_ptr(new FundamentalValue(true));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &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));
+ root = make_scoped_ptr(new FundamentalValue(1.0));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &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));
+ root = make_scoped_ptr(new FundamentalValue(0.2));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &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));
+ root = make_scoped_ptr(new FundamentalValue(-0.8));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("-0.8", output_js);
- delete root;
// Test String values.
- root = new StringValue("foo");
- EXPECT_TRUE(JSONWriter::Write(root, &output_js));
+ root = make_scoped_ptr(new StringValue("foo"));
+ EXPECT_TRUE(JSONWriter::Write(root.get(), &output_js));
EXPECT_EQ("\"foo\"", output_js);
- delete root;
}
@@ -128,18 +119,18 @@ 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 =
+ make_scoped_ptr(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(
« no previous file with comments | « no previous file | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698