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

Unified Diff: third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc

Issue 2773813002: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 (Closed)
Patch Set: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc
diff --git a/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc b/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc
index 97d41eecf6f2ca749f9cf8dd1ff1cd45c38d9e06..3942e0e61ebfe3359f5bcffe2e470db854d7edb1 100644
--- a/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc
+++ b/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer_test.cc
@@ -32,7 +32,8 @@ namespace {
// The user stream is expected to be the only stream.
void GetUserStream(const std::string& file_contents,
MINIDUMP_LOCATION_DESCRIPTOR* user_stream_location,
- uint32_t stream_type) {
+ uint32_t stream_type,
+ size_t stream_size) {
const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
const size_t kUserStreamOffset =
kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
@@ -47,16 +48,36 @@ void GetUserStream(const std::string& file_contents,
ASSERT_EQ(stream_type, directory[kDirectoryIndex].StreamType);
EXPECT_EQ(kUserStreamOffset, directory[kDirectoryIndex].Location.Rva);
+ EXPECT_EQ(stream_size, directory[kDirectoryIndex].Location.DataSize);
*user_stream_location = directory[kDirectoryIndex].Location;
}
-TEST(MinidumpUserStreamWriter, NoData) {
+constexpr MinidumpStreamType kTestStreamId =
+ static_cast<MinidumpStreamType>(0x123456);
+
+TEST(MinidumpUserStreamWriter, InitializeFromSnapshotNoData) {
MinidumpFileWriter minidump_file_writer;
auto user_stream_writer = base::WrapUnique(new MinidumpUserStreamWriter());
- const uint32_t kTestStreamId = 0x123456;
auto stream =
base::WrapUnique(new UserMinidumpStream(kTestStreamId, nullptr));
user_stream_writer->InitializeFromSnapshot(stream.get());
+ ASSERT_TRUE(minidump_file_writer.AddStream(std::move(user_stream_writer)));
+
+ StringFile string_file;
+ ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
+
+ ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY),
+ string_file.string().size());
+
+ MINIDUMP_LOCATION_DESCRIPTOR user_stream_location;
+ ASSERT_NO_FATAL_FAILURE(GetUserStream(
+ string_file.string(), &user_stream_location, kTestStreamId, 0u));
+}
+
+TEST(MinidumpUserStreamWriter, InitializeFromBufferNoData) {
+ MinidumpFileWriter minidump_file_writer;
+ auto user_stream_writer = base::WrapUnique(new MinidumpUserStreamWriter());
+ user_stream_writer->InitializeFromBuffer(kTestStreamId, nullptr, 0);
minidump_file_writer.AddStream(std::move(user_stream_writer));
StringFile string_file;
@@ -67,14 +88,12 @@ TEST(MinidumpUserStreamWriter, NoData) {
MINIDUMP_LOCATION_DESCRIPTOR user_stream_location;
ASSERT_NO_FATAL_FAILURE(GetUserStream(
- string_file.string(), &user_stream_location, kTestStreamId));
- EXPECT_EQ(0u, user_stream_location.DataSize);
+ string_file.string(), &user_stream_location, kTestStreamId, 0u));
}
-TEST(MinidumpUserStreamWriter, OneStream) {
+TEST(MinidumpUserStreamWriter, InitializeFromSnapshotOneStream) {
MinidumpFileWriter minidump_file_writer;
auto user_stream_writer = base::WrapUnique(new MinidumpUserStreamWriter());
- const uint32_t kTestStreamId = 0x123456;
TestMemorySnapshot* test_data = new TestMemorySnapshot();
test_data->SetAddress(97865);
@@ -84,6 +103,30 @@ TEST(MinidumpUserStreamWriter, OneStream) {
auto stream =
base::WrapUnique(new UserMinidumpStream(kTestStreamId, test_data));
user_stream_writer->InitializeFromSnapshot(stream.get());
+ ASSERT_TRUE(minidump_file_writer.AddStream(std::move(user_stream_writer)));
+
+ StringFile string_file;
+ ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
+
+ ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + kStreamSize,
+ string_file.string().size());
+
+ MINIDUMP_LOCATION_DESCRIPTOR user_stream_location = {};
+ ASSERT_NO_FATAL_FAILURE(GetUserStream(
+ string_file.string(), &user_stream_location, kTestStreamId, kStreamSize));
+ const std::string stream_data = string_file.string().substr(
+ user_stream_location.Rva, user_stream_location.DataSize);
+ EXPECT_EQ(std::string(kStreamSize, 'c'), stream_data);
+}
+
+TEST(MinidumpUserStreamWriter, InitializeFromBufferOneStream) {
+ MinidumpFileWriter minidump_file_writer;
+ auto user_stream_writer = base::WrapUnique(new MinidumpUserStreamWriter());
+
+ const size_t kStreamSize = 128;
+ std::vector<uint8_t> data(kStreamSize, 'c');
+ user_stream_writer->InitializeFromBuffer(
+ kTestStreamId, &data[0], data.size());
minidump_file_writer.AddStream(std::move(user_stream_writer));
StringFile string_file;
@@ -92,10 +135,9 @@ TEST(MinidumpUserStreamWriter, OneStream) {
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + kStreamSize,
string_file.string().size());
- MINIDUMP_LOCATION_DESCRIPTOR user_stream_location;
+ MINIDUMP_LOCATION_DESCRIPTOR user_stream_location = {};
ASSERT_NO_FATAL_FAILURE(GetUserStream(
- string_file.string(), &user_stream_location, kTestStreamId));
- EXPECT_EQ(kStreamSize, user_stream_location.DataSize);
+ string_file.string(), &user_stream_location, kTestStreamId, kStreamSize));
const std::string stream_data = string_file.string().substr(
user_stream_location.Rva, user_stream_location.DataSize);
EXPECT_EQ(std::string(kStreamSize, 'c'), stream_data);

Powered by Google App Engine
This is Rietveld 408576698