Index: minidump/minidump_handle_writer_test.cc |
diff --git a/minidump/minidump_handle_writer_test.cc b/minidump/minidump_handle_writer_test.cc |
index 602ce1c37117d5689b3c06e59c24d438734287f9..e8f23eb5182c514e353a6ce63998a456cde3fc92 100644 |
--- a/minidump/minidump_handle_writer_test.cc |
+++ b/minidump/minidump_handle_writer_test.cc |
@@ -122,6 +122,80 @@ TEST(MinidumpHandleDataWriter, OneHandle) { |
EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount); |
} |
+TEST(MinidumpHandleDataWriter, RepeatedTypeName) { |
+ MinidumpFileWriter minidump_file_writer; |
+ auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter()); |
+ |
+ HandleSnapshot handle_snapshot; |
+ handle_snapshot.handle = 0x1234; |
+ handle_snapshot.type_name = "Something"; |
+ handle_snapshot.attributes = 0x12345678; |
+ handle_snapshot.granted_access = 0x9abcdef0; |
+ handle_snapshot.pointer_count = 4567; |
+ handle_snapshot.handle_count = 9876; |
+ |
+ HandleSnapshot handle_snapshot2; |
+ handle_snapshot2.handle = 0x4321; |
+ handle_snapshot2.type_name = "Something"; // Note: same as above. |
+ handle_snapshot2.attributes = 0x87654321; |
+ handle_snapshot2.granted_access = 0x0fedcba9; |
+ handle_snapshot2.pointer_count = 7654; |
+ handle_snapshot2.handle_count = 6789; |
+ |
+ std::vector<HandleSnapshot> snapshot; |
+ snapshot.push_back(handle_snapshot); |
+ snapshot.push_back(handle_snapshot2); |
+ |
+ handle_data_writer->InitializeFromSnapshot(snapshot); |
+ |
+ minidump_file_writer.AddStream(handle_data_writer.Pass()); |
+ |
+ StringFile string_file; |
+ ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
+ |
+ const size_t kTypeNameStringDataLength = |
+ (handle_snapshot.type_name.size() + 1) * sizeof(base::char16); |
+ ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
+ sizeof(MINIDUMP_HANDLE_DATA_STREAM) + |
+ (sizeof(MINIDUMP_HANDLE_DESCRIPTOR) * 2) + |
+ sizeof(MINIDUMP_STRING) + kTypeNameStringDataLength, |
+ string_file.string().size()); |
+ |
+ const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr; |
+ ASSERT_NO_FATAL_FAILURE( |
+ GetHandleDataStream(string_file.string(), &handle_data_stream)); |
+ |
+ EXPECT_EQ(2u, handle_data_stream->NumberOfDescriptors); |
+ const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor = |
+ reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>( |
+ &handle_data_stream[1]); |
+ EXPECT_EQ(handle_snapshot.handle, handle_descriptor->Handle); |
+ EXPECT_EQ(handle_snapshot.type_name, |
+ base::UTF16ToUTF8(MinidumpStringAtRVAAsString( |
+ string_file.string(), handle_descriptor->TypeNameRva))); |
+ EXPECT_EQ(0u, handle_descriptor->ObjectNameRva); |
+ EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes); |
+ EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess); |
+ EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount); |
+ EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount); |
+ |
+ const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor2 = |
+ reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>( |
+ reinterpret_cast<const unsigned char*>(&handle_data_stream[1]) + |
+ sizeof(MINIDUMP_HANDLE_DESCRIPTOR)); |
+ EXPECT_EQ(handle_snapshot2.handle, handle_descriptor2->Handle); |
+ EXPECT_EQ(handle_snapshot2.type_name, |
+ base::UTF16ToUTF8(MinidumpStringAtRVAAsString( |
+ string_file.string(), handle_descriptor2->TypeNameRva))); |
+ EXPECT_EQ(0u, handle_descriptor2->ObjectNameRva); |
+ EXPECT_EQ(handle_snapshot2.attributes, handle_descriptor2->Attributes); |
+ EXPECT_EQ(handle_snapshot2.granted_access, handle_descriptor2->GrantedAccess); |
+ EXPECT_EQ(handle_snapshot2.handle_count, handle_descriptor2->HandleCount); |
+ EXPECT_EQ(handle_snapshot2.pointer_count, handle_descriptor2->PointerCount); |
+ |
+ EXPECT_EQ(handle_descriptor->TypeNameRva, handle_descriptor2->TypeNameRva); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace crashpad |