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

Side by Side Diff: base/json/json_writer_unittest.cc

Issue 2065793002: Return a unique_ptr from BinaryValue::CreateWithCopiedBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android and CrOS Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/values.h » ('j') | chrome/browser/chromeos/extensions/wallpaper_api.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_writer.h" 5 #include "base/json/json_writer.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 binary_list.Append(WrapUnique(new FundamentalValue(5))); 122 binary_list.Append(WrapUnique(new FundamentalValue(5)));
123 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); 123 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
124 binary_list.Append(WrapUnique(new FundamentalValue(2))); 124 binary_list.Append(WrapUnique(new FundamentalValue(2)));
125 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); 125 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
126 EXPECT_FALSE(JSONWriter::Write(binary_list, &output_js)); 126 EXPECT_FALSE(JSONWriter::Write(binary_list, &output_js));
127 EXPECT_TRUE(JSONWriter::WriteWithOptions( 127 EXPECT_TRUE(JSONWriter::WriteWithOptions(
128 binary_list, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js)); 128 binary_list, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js));
129 EXPECT_EQ("[5,2]", output_js); 129 EXPECT_EQ("[5,2]", output_js);
130 130
131 DictionaryValue binary_dict; 131 DictionaryValue binary_dict;
132 binary_dict.Set( 132 binary_dict.Set("a", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
133 "a", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
134 binary_dict.SetInteger("b", 5); 133 binary_dict.SetInteger("b", 5);
135 binary_dict.Set( 134 binary_dict.Set("c", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
136 "c", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
137 binary_dict.SetInteger("d", 2); 135 binary_dict.SetInteger("d", 2);
138 binary_dict.Set( 136 binary_dict.Set("e", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
139 "e", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4)));
140 EXPECT_FALSE(JSONWriter::Write(binary_dict, &output_js)); 137 EXPECT_FALSE(JSONWriter::Write(binary_dict, &output_js));
141 EXPECT_TRUE(JSONWriter::WriteWithOptions( 138 EXPECT_TRUE(JSONWriter::WriteWithOptions(
142 binary_dict, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js)); 139 binary_dict, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js));
143 EXPECT_EQ("{\"b\":5,\"d\":2}", output_js); 140 EXPECT_EQ("{\"b\":5,\"d\":2}", output_js);
144 } 141 }
145 142
146 TEST(JSONWriterTest, DoublesAsInts) { 143 TEST(JSONWriterTest, DoublesAsInts) {
147 std::string output_js; 144 std::string output_js;
148 145
149 // Test allowing a double with no fractional part to be written as an integer. 146 // Test allowing a double with no fractional part to be written as an integer.
150 FundamentalValue double_value(1e10); 147 FundamentalValue double_value(1e10);
151 EXPECT_TRUE(JSONWriter::WriteWithOptions( 148 EXPECT_TRUE(JSONWriter::WriteWithOptions(
152 double_value, JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION, 149 double_value, JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION,
153 &output_js)); 150 &output_js));
154 EXPECT_EQ("10000000000", output_js); 151 EXPECT_EQ("10000000000", output_js);
155 } 152 }
156 153
157 } // namespace base 154 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/values.h » ('j') | chrome/browser/chromeos/extensions/wallpaper_api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698