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

Unified Diff: minidump/minidump_file_writer_test.cc

Issue 664283002: Refactor minidump test utilities for MinidumpWritable, … (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « minidump/minidump_exception_writer_test.cc ('k') | minidump/minidump_memory_writer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_file_writer_test.cc
diff --git a/minidump/minidump_file_writer_test.cc b/minidump/minidump_file_writer_test.cc
index 3f34287ca09ce36b65e1d579dc5030583345ae5a..51369f528f3b642dfe65c8f3737986e2cf14b491 100644
--- a/minidump/minidump_file_writer_test.cc
+++ b/minidump/minidump_file_writer_test.cc
@@ -36,10 +36,11 @@ TEST(MinidumpFileWriter, Empty) {
ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MINIDUMP_HEADER), file_writer.string().size());
+ const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
- reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
-
+ MinidumpHeaderAtStart(file_writer.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0));
+ EXPECT_FALSE(directory);
}
class TestStream final : public internal::MinidumpStreamWriter {
@@ -95,18 +96,15 @@ TEST(MinidumpFileWriter, OneStream) {
ASSERT_EQ(kFileSize, file_writer.string().size());
+ const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
- reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
-
+ MinidumpHeaderAtStart(file_writer.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp));
+ ASSERT_TRUE(directory);
- const MINIDUMP_DIRECTORY* directory =
- reinterpret_cast<const MINIDUMP_DIRECTORY*>(
- &file_writer.string()[kDirectoryOffset]);
-
- EXPECT_EQ(kStreamType, directory->StreamType);
- EXPECT_EQ(kStreamSize, directory->Location.DataSize);
- EXPECT_EQ(kStreamOffset, directory->Location.Rva);
+ EXPECT_EQ(kStreamType, directory[0].StreamType);
+ EXPECT_EQ(kStreamSize, directory[0].Location.DataSize);
+ EXPECT_EQ(kStreamOffset, directory[0].Location.Rva);
const uint8_t* stream_data =
reinterpret_cast<const uint8_t*>(&file_writer.string()[kStreamOffset]);
@@ -155,14 +153,11 @@ TEST(MinidumpFileWriter, ThreeStreams) {
ASSERT_EQ(kFileSize, file_writer.string().size());
+ const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
- reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
-
+ MinidumpHeaderAtStart(file_writer.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp));
-
- const MINIDUMP_DIRECTORY* directory =
- reinterpret_cast<const MINIDUMP_DIRECTORY*>(
- &file_writer.string()[kDirectoryOffset]);
+ ASSERT_TRUE(directory);
EXPECT_EQ(kStream1Type, directory[0].StreamType);
EXPECT_EQ(kStream1Size, directory[0].Location.DataSize);
@@ -217,18 +212,15 @@ TEST(MinidumpFileWriter, ZeroLengthStream) {
ASSERT_EQ(kFileSize, file_writer.string().size());
+ const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
- reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
-
+ MinidumpHeaderAtStart(file_writer.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
+ ASSERT_TRUE(directory);
- const MINIDUMP_DIRECTORY* directory =
- reinterpret_cast<const MINIDUMP_DIRECTORY*>(
- &file_writer.string()[kDirectoryOffset]);
-
- EXPECT_EQ(kStreamType, directory->StreamType);
- EXPECT_EQ(kStreamSize, directory->Location.DataSize);
- EXPECT_EQ(kStreamOffset, directory->Location.Rva);
+ EXPECT_EQ(kStreamType, directory[0].StreamType);
+ EXPECT_EQ(kStreamSize, directory[0].Location.DataSize);
+ EXPECT_EQ(kStreamOffset, directory[0].Location.Rva);
}
TEST(MinidumpFileWriterDeathTest, SameStreamType) {
« no previous file with comments | « minidump/minidump_exception_writer_test.cc ('k') | minidump/minidump_memory_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698