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

Side by Side Diff: minidump/minidump_file_writer_test.cc

Issue 459973002: Add MinidumpMemoryWriter, MinidumpMemoryListWriter, and their test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 4 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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ASSERT_GE(sizeof(kZeroes), kStream3Padding); 210 ASSERT_GE(sizeof(kZeroes), kStream3Padding);
211 EXPECT_EQ(0, memcmp(stream2_data + kStream2Size, kZeroes, kStream3Padding)); 211 EXPECT_EQ(0, memcmp(stream2_data + kStream2Size, kZeroes, kStream3Padding));
212 212
213 const uint8_t* stream3_data = 213 const uint8_t* stream3_data =
214 reinterpret_cast<const uint8_t*>(&file_writer.string()[kStream3Offset]); 214 reinterpret_cast<const uint8_t*>(&file_writer.string()[kStream3Offset]);
215 215
216 std::string expected_stream3(kStream3Size, kStream3Value); 216 std::string expected_stream3(kStream3Size, kStream3Value);
217 EXPECT_EQ(0, memcmp(stream3_data, expected_stream3.c_str(), kStream3Size)); 217 EXPECT_EQ(0, memcmp(stream3_data, expected_stream3.c_str(), kStream3Size));
218 } 218 }
219 219
220 TEST(MinidumpFileWriter, ZeroLengthStream) {
221 MinidumpFileWriter minidump_file;
222
223 const size_t kStreamSize = 0;
224 const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d);
225 TestStream stream(kStreamType, kStreamSize, 0);
226 minidump_file.AddStream(&stream);
227
228 StringFileWriter file_writer;
229 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
230
231 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
232 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
233 const size_t kFileSize = kStreamOffset + kStreamSize;
234
235 ASSERT_EQ(kFileSize, file_writer.string().size());
236
237 const MINIDUMP_HEADER* header =
238 reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
239
240 EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_SIGNATURE), header->Signature);
241 EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_VERSION), header->Version);
242 EXPECT_EQ(1u, header->NumberOfStreams);
243 EXPECT_EQ(kDirectoryOffset, header->StreamDirectoryRva);
244 EXPECT_EQ(0u, header->CheckSum);
245 EXPECT_EQ(0u, header->TimeDateStamp);
246 EXPECT_EQ(MiniDumpNormal, header->Flags);
247
248 const MINIDUMP_DIRECTORY* directory =
249 reinterpret_cast<const MINIDUMP_DIRECTORY*>(
250 &file_writer.string()[kDirectoryOffset]);
251
252 EXPECT_EQ(kStreamType, directory->StreamType);
253 EXPECT_EQ(kStreamSize, directory->Location.DataSize);
254 EXPECT_EQ(kStreamOffset, directory->Location.Rva);
255 }
256
220 TEST(MinidumpFileWriterDeathTest, SameStreamType) { 257 TEST(MinidumpFileWriterDeathTest, SameStreamType) {
221 MinidumpFileWriter minidump_file; 258 MinidumpFileWriter minidump_file;
222 259
223 const size_t kStream1Size = 5; 260 const size_t kStream1Size = 5;
224 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); 261 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d);
225 const uint8_t kStream1Value = 0x5a; 262 const uint8_t kStream1Value = 0x5a;
226 TestStream stream1(kStream1Type, kStream1Size, kStream1Value); 263 TestStream stream1(kStream1Type, kStream1Size, kStream1Value);
227 minidump_file.AddStream(&stream1); 264 minidump_file.AddStream(&stream1);
228 265
229 // It is an error to add a second stream of the same type. 266 // It is an error to add a second stream of the same type.
230 const size_t kStream2Size = 3; 267 const size_t kStream2Size = 3;
231 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x4d); 268 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x4d);
232 const uint8_t kStream2Value = 0xa5; 269 const uint8_t kStream2Value = 0xa5;
233 TestStream stream2(kStream2Type, kStream2Size, kStream2Value); 270 TestStream stream2(kStream2Type, kStream2Size, kStream2Value);
234 ASSERT_DEATH(minidump_file.AddStream(&stream2), "already present"); 271 ASSERT_DEATH(minidump_file.AddStream(&stream2), "already present");
235 } 272 }
236 273
237 } // namespace 274 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698