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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 EXPECT_TRUE(pickle.WriteString("Domo")); | 164 EXPECT_TRUE(pickle.WriteString("Domo")); |
165 | 165 |
166 const char* start = reinterpret_cast<const char*>(pickle.data()); | 166 const char* start = reinterpret_cast<const char*>(pickle.data()); |
167 const char* end = start + pickle.size(); | 167 const char* end = start + pickle.size(); |
168 | 168 |
169 EXPECT_TRUE(end == Pickle::FindNext(pickle.header_size_, start, end)); | 169 EXPECT_TRUE(end == Pickle::FindNext(pickle.header_size_, start, end)); |
170 EXPECT_TRUE(NULL == Pickle::FindNext(pickle.header_size_, start, end - 1)); | 170 EXPECT_TRUE(NULL == Pickle::FindNext(pickle.header_size_, start, end - 1)); |
171 EXPECT_TRUE(end == Pickle::FindNext(pickle.header_size_, start, end + 1)); | 171 EXPECT_TRUE(end == Pickle::FindNext(pickle.header_size_, start, end + 1)); |
172 } | 172 } |
173 | 173 |
| 174 TEST(PickleTest, FindNextWithIncompleteHeader) { |
| 175 size_t header_size = sizeof(Pickle::Header); |
| 176 scoped_array<char> buffer(new char[header_size - 1]); |
| 177 memset(buffer.get(), 0x1, header_size - 1); |
| 178 |
| 179 const char* start = buffer.get(); |
| 180 const char* end = start + header_size - 1; |
| 181 |
| 182 EXPECT_TRUE(NULL == Pickle::FindNext(header_size, start, end)); |
| 183 } |
| 184 |
174 TEST(PickleTest, IteratorHasRoom) { | 185 TEST(PickleTest, IteratorHasRoom) { |
175 Pickle pickle; | 186 Pickle pickle; |
176 EXPECT_TRUE(pickle.WriteInt(1)); | 187 EXPECT_TRUE(pickle.WriteInt(1)); |
177 EXPECT_TRUE(pickle.WriteInt(2)); | 188 EXPECT_TRUE(pickle.WriteInt(2)); |
178 | 189 |
179 const void* iter = 0; | 190 const void* iter = 0; |
180 EXPECT_FALSE(pickle.IteratorHasRoomFor(iter, 1)); | 191 EXPECT_FALSE(pickle.IteratorHasRoomFor(iter, 1)); |
181 iter = pickle.payload(); | 192 iter = pickle.payload(); |
182 EXPECT_TRUE(pickle.IteratorHasRoomFor(iter, 0)); | 193 EXPECT_TRUE(pickle.IteratorHasRoomFor(iter, 0)); |
183 EXPECT_TRUE(pickle.IteratorHasRoomFor(iter, 1)); | 194 EXPECT_TRUE(pickle.IteratorHasRoomFor(iter, 1)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); | 310 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); |
300 | 311 |
301 void* iter = NULL; | 312 void* iter = NULL; |
302 const char* outdata_char; | 313 const char* outdata_char; |
303 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); | 314 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); |
304 | 315 |
305 int outdata; | 316 int outdata; |
306 memcpy(&outdata, outdata_char, sizeof(outdata)); | 317 memcpy(&outdata, outdata_char, sizeof(outdata)); |
307 EXPECT_EQ(data, outdata); | 318 EXPECT_EQ(data, outdata); |
308 } | 319 } |
OLD | NEW |