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

Side by Side Diff: base/pickle_unittest.cc

Issue 46056: Change Pickle to double its capacity by default, rather than increasing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/pickle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 data_ptr[i] = 'G'; 160 data_ptr[i] = 'G';
161 161
162 // construct a message that will be exactly the size of one payload unit, 162 // construct a message that will be exactly the size of one payload unit,
163 // note that any data will have a 4-byte header indicating the size 163 // note that any data will have a 4-byte header indicating the size
164 const size_t payload_size_after_header = unit - sizeof(uint32); 164 const size_t payload_size_after_header = unit - sizeof(uint32);
165 Pickle pickle; 165 Pickle pickle;
166 pickle.WriteData(data_ptr, 166 pickle.WriteData(data_ptr,
167 static_cast<int>(payload_size_after_header - sizeof(uint32))); 167 static_cast<int>(payload_size_after_header - sizeof(uint32)));
168 size_t cur_payload = payload_size_after_header; 168 size_t cur_payload = payload_size_after_header;
169 169
170 EXPECT_EQ(pickle.capacity(), unit); 170 // note: we assume 'unit' is a power of 2
171 EXPECT_EQ(unit, pickle.capacity());
171 EXPECT_EQ(pickle.payload_size(), payload_size_after_header); 172 EXPECT_EQ(pickle.payload_size(), payload_size_after_header);
172 173
173 // fill out a full page (noting data header) 174 // fill out a full page (noting data header)
174 pickle.WriteData(data_ptr, static_cast<int>(unit - sizeof(uint32))); 175 pickle.WriteData(data_ptr, static_cast<int>(unit - sizeof(uint32)));
175 cur_payload += unit; 176 cur_payload += unit;
176 EXPECT_EQ(unit * 2, pickle.capacity()); 177 EXPECT_EQ(unit * 2, pickle.capacity());
177 EXPECT_EQ(cur_payload, pickle.payload_size()); 178 EXPECT_EQ(cur_payload, pickle.payload_size());
178 179
179 // one more byte should expand the capacity by one unit 180 // one more byte should double the capacity
180 pickle.WriteData(data_ptr, 1); 181 pickle.WriteData(data_ptr, 1);
181 cur_payload += 5; 182 cur_payload += 5;
182 EXPECT_EQ(unit * 3, pickle.capacity()); 183 EXPECT_EQ(unit * 4, pickle.capacity());
183 EXPECT_EQ(cur_payload, pickle.payload_size()); 184 EXPECT_EQ(cur_payload, pickle.payload_size());
184 } 185 }
185 186
186 namespace { 187 namespace {
187 188
188 struct CustomHeader : Pickle::Header { 189 struct CustomHeader : Pickle::Header {
189 int blah; 190 int blah;
190 }; 191 };
191 192
192 } // namespace 193 } // namespace
(...skipping 17 matching lines...) Expand all
210 TEST(PickleTest, EqualsOperator) { 211 TEST(PickleTest, EqualsOperator) {
211 Pickle source; 212 Pickle source;
212 source.WriteInt(1); 213 source.WriteInt(1);
213 214
214 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()), 215 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()),
215 source.size()); 216 source.size());
216 Pickle copy; 217 Pickle copy;
217 copy = copy_refs_source_buffer; 218 copy = copy_refs_source_buffer;
218 ASSERT_EQ(source.size(), copy.size()); 219 ASSERT_EQ(source.size(), copy.size());
219 } 220 }
OLDNEW
« no previous file with comments | « base/pickle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698