OLD | NEW |
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 "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // test copy constructor | 80 // test copy constructor |
81 Pickle pickle2(pickle); | 81 Pickle pickle2(pickle); |
82 VerifyResult(pickle2); | 82 VerifyResult(pickle2); |
83 | 83 |
84 // test operator= | 84 // test operator= |
85 Pickle pickle3; | 85 Pickle pickle3; |
86 pickle3 = pickle; | 86 pickle3 = pickle; |
87 VerifyResult(pickle3); | 87 VerifyResult(pickle3); |
88 } | 88 } |
89 | 89 |
| 90 // Tests that we can handle really small buffers. |
| 91 TEST(PickleTest, SmallBuffer) { |
| 92 scoped_array<char> buffer(new char[1]); |
| 93 |
| 94 // We should not touch the buffer. |
| 95 Pickle pickle(buffer.get(), 1); |
| 96 |
| 97 void* iter = NULL; |
| 98 int data; |
| 99 EXPECT_FALSE(pickle.ReadInt(&iter, &data)); |
| 100 } |
| 101 |
| 102 // Tests that we can handle improper headers. |
| 103 TEST(PickleTest, BigSize) { |
| 104 int buffer[] = { 0x56035200, 25, 40, 50 }; |
| 105 |
| 106 Pickle pickle(reinterpret_cast<char*>(buffer), sizeof(buffer)); |
| 107 |
| 108 void* iter = NULL; |
| 109 int data; |
| 110 EXPECT_FALSE(pickle.ReadInt(&iter, &data)); |
| 111 } |
| 112 |
| 113 TEST(PickleTest, UnalignedSize) { |
| 114 int buffer[] = { 10, 25, 40, 50 }; |
| 115 |
| 116 Pickle pickle(reinterpret_cast<char*>(buffer), sizeof(buffer)); |
| 117 |
| 118 void* iter = NULL; |
| 119 int data; |
| 120 EXPECT_FALSE(pickle.ReadInt(&iter, &data)); |
| 121 } |
| 122 |
90 TEST(PickleTest, ZeroLenStr) { | 123 TEST(PickleTest, ZeroLenStr) { |
91 Pickle pickle; | 124 Pickle pickle; |
92 EXPECT_TRUE(pickle.WriteString("")); | 125 EXPECT_TRUE(pickle.WriteString("")); |
93 | 126 |
94 void* iter = NULL; | 127 void* iter = NULL; |
95 std::string outstr; | 128 std::string outstr; |
96 EXPECT_TRUE(pickle.ReadString(&iter, &outstr)); | 129 EXPECT_TRUE(pickle.ReadString(&iter, &outstr)); |
97 EXPECT_EQ("", outstr); | 130 EXPECT_EQ("", outstr); |
98 } | 131 } |
99 | 132 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); | 299 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); |
267 | 300 |
268 void* iter = NULL; | 301 void* iter = NULL; |
269 const char* outdata_char; | 302 const char* outdata_char; |
270 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); | 303 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); |
271 | 304 |
272 int outdata; | 305 int outdata; |
273 memcpy(&outdata, outdata_char, sizeof(outdata)); | 306 memcpy(&outdata, outdata_char, sizeof(outdata)); |
274 EXPECT_EQ(data, outdata); | 307 EXPECT_EQ(data, outdata); |
275 } | 308 } |
OLD | NEW |