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

Side by Side Diff: base/values_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
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/values.h" 5 #include "base/values.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 std::unique_ptr<char[]> buffer(new char[15]); 120 std::unique_ptr<char[]> buffer(new char[15]);
121 char* original_buffer = buffer.get(); 121 char* original_buffer = buffer.get();
122 binary.reset(new BinaryValue(std::move(buffer), 15)); 122 binary.reset(new BinaryValue(std::move(buffer), 15));
123 ASSERT_TRUE(binary.get()); 123 ASSERT_TRUE(binary.get());
124 ASSERT_TRUE(binary->GetBuffer()); 124 ASSERT_TRUE(binary->GetBuffer());
125 ASSERT_EQ(original_buffer, binary->GetBuffer()); 125 ASSERT_EQ(original_buffer, binary->GetBuffer());
126 ASSERT_EQ(15U, binary->GetSize()); 126 ASSERT_EQ(15U, binary->GetSize());
127 127
128 char stack_buffer[42]; 128 char stack_buffer[42];
129 memset(stack_buffer, '!', 42); 129 memset(stack_buffer, '!', 42);
130 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); 130 binary = BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42);
131 ASSERT_TRUE(binary.get()); 131 ASSERT_TRUE(binary.get());
132 ASSERT_TRUE(binary->GetBuffer()); 132 ASSERT_TRUE(binary->GetBuffer());
133 ASSERT_NE(stack_buffer, binary->GetBuffer()); 133 ASSERT_NE(stack_buffer, binary->GetBuffer());
134 ASSERT_EQ(42U, binary->GetSize()); 134 ASSERT_EQ(42U, binary->GetSize());
135 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); 135 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
136 136
137 // Test overloaded GetAsBinary. 137 // Test overloaded GetAsBinary.
138 Value* narrow_value = binary.get(); 138 Value* narrow_value = binary.get();
139 const BinaryValue* narrow_binary = NULL; 139 const BinaryValue* narrow_binary = NULL;
140 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); 140 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary));
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 EXPECT_FALSE(main_list.GetList(1, NULL)); 1147 EXPECT_FALSE(main_list.GetList(1, NULL));
1148 EXPECT_FALSE(main_list.GetList(2, NULL)); 1148 EXPECT_FALSE(main_list.GetList(2, NULL));
1149 EXPECT_FALSE(main_list.GetList(3, NULL)); 1149 EXPECT_FALSE(main_list.GetList(3, NULL));
1150 EXPECT_FALSE(main_list.GetList(4, NULL)); 1150 EXPECT_FALSE(main_list.GetList(4, NULL));
1151 EXPECT_FALSE(main_list.GetList(5, NULL)); 1151 EXPECT_FALSE(main_list.GetList(5, NULL));
1152 EXPECT_TRUE(main_list.GetList(6, NULL)); 1152 EXPECT_TRUE(main_list.GetList(6, NULL));
1153 EXPECT_FALSE(main_list.GetList(7, NULL)); 1153 EXPECT_FALSE(main_list.GetList(7, NULL));
1154 } 1154 }
1155 1155
1156 } // namespace base 1156 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698