OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 421 |
422 PickleIterator iter(pickle); | 422 PickleIterator iter(pickle); |
423 const char* outdata_char = NULL; | 423 const char* outdata_char = NULL; |
424 EXPECT_TRUE(iter.ReadBytes(&outdata_char, sizeof(data))); | 424 EXPECT_TRUE(iter.ReadBytes(&outdata_char, sizeof(data))); |
425 | 425 |
426 int outdata; | 426 int outdata; |
427 memcpy(&outdata, outdata_char, sizeof(outdata)); | 427 memcpy(&outdata, outdata_char, sizeof(outdata)); |
428 EXPECT_EQ(data, outdata); | 428 EXPECT_EQ(data, outdata); |
429 } | 429 } |
430 | 430 |
| 431 // Checks that when a pickle is deep-copied, the result is not larger than |
| 432 // needed. |
| 433 TEST(PickleTest, DeepCopyResize) { |
| 434 Pickle pickle; |
| 435 while (pickle.capacity_after_header() != pickle.payload_size()) |
| 436 pickle.WriteBool(true); |
| 437 |
| 438 // Make a deep copy. |
| 439 Pickle pickle2(pickle); |
| 440 |
| 441 // Check that there isn't any extraneous capacity. |
| 442 EXPECT_EQ(pickle.capacity_after_header(), pickle2.capacity_after_header()); |
| 443 } |
| 444 |
431 } // namespace base | 445 } // namespace base |
OLD | NEW |