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

Unified Diff: minidump/minidump_crashpad_info_writer_test.cc

Issue 703353002: Add MinidumpCrashpadInfoWriter::InitializeFromSnapshot() and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_module_annotations_list
Patch Set: Rebase Created 6 years, 1 month 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_crashpad_info_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_crashpad_info_writer_test.cc
diff --git a/minidump/minidump_crashpad_info_writer_test.cc b/minidump/minidump_crashpad_info_writer_test.cc
index 2840d348240194097bbef65285862c25f53397b6..279079654462e5dd0e314a16fc26895e9d62b775 100644
--- a/minidump/minidump_crashpad_info_writer_test.cc
+++ b/minidump/minidump_crashpad_info_writer_test.cc
@@ -21,7 +21,10 @@
#include "minidump/minidump_file_writer.h"
#include "minidump/minidump_module_crashpad_info_writer.h"
#include "minidump/test/minidump_file_writer_test_util.h"
+#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
+#include "snapshot/test/test_module_snapshot.h"
+#include "snapshot/test/test_process_snapshot.h"
#include "util/file/string_file_writer.h"
namespace crashpad {
@@ -51,6 +54,7 @@ void GetCrashpadInfoStream(const std::string& file_contents,
TEST(MinidumpCrashpadInfoWriter, Empty) {
MinidumpFileWriter minidump_file_writer;
auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter());
+ EXPECT_FALSE(crashpad_info_writer->IsUseful());
minidump_file_writer.AddStream(crashpad_info_writer.Pass());
@@ -80,6 +84,8 @@ TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) {
module_list_writer->AddModule(module_writer.Pass());
crashpad_info_writer->SetModuleList(module_list_writer.Pass());
+ EXPECT_TRUE(crashpad_info_writer->IsUseful());
+
minidump_file_writer.AddStream(crashpad_info_writer.Pass());
StringFileWriter file_writer;
@@ -102,10 +108,77 @@ TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) {
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
EXPECT_EQ(kMinidumpModuleListIndex, module->minidump_module_list_index);
+ EXPECT_EQ(0u, module->list_annotations.DataSize);
+ EXPECT_EQ(0u, module->list_annotations.Rva);
EXPECT_EQ(0u, module->simple_annotations.DataSize);
EXPECT_EQ(0u, module->simple_annotations.Rva);
}
+TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) {
+ const char kEntry[] = "This is a simple annotation in a list.";
+
+ // Test with a useless module, one that doesn’t carry anything that would
+ // require MinidumpCrashpadInfo or any child object.
+ auto process_snapshot = make_scoped_ptr(new TestProcessSnapshot());
+
+ auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot());
+ process_snapshot->AddModule(module_snapshot.Pass());
+
+ auto info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter());
+ info_writer->InitializeFromSnapshot(process_snapshot.get());
+ EXPECT_FALSE(info_writer->IsUseful());
+
+ // Try again with a useful module.
+ process_snapshot.reset(new TestProcessSnapshot());
+
+ module_snapshot.reset(new TestModuleSnapshot());
+ std::vector<std::string> annotations_list(1, std::string(kEntry));
+ module_snapshot->SetAnnotationsVector(annotations_list);
+ process_snapshot->AddModule(module_snapshot.Pass());
+
+ info_writer.reset(new MinidumpCrashpadInfoWriter());
+ info_writer->InitializeFromSnapshot(process_snapshot.get());
+ EXPECT_TRUE(info_writer->IsUseful());
+
+ MinidumpFileWriter minidump_file_writer;
+ minidump_file_writer.AddStream(info_writer.Pass());
+
+ StringFileWriter file_writer;
+ ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
+
+ const MinidumpCrashpadInfo* info;
+ const MinidumpModuleCrashpadInfoList* module_list;
+ ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream(
+ file_writer.string(), &info, &module_list));
+
+ EXPECT_EQ(MinidumpCrashpadInfo::kVersion, info->version);
+ ASSERT_TRUE(module_list);
+ ASSERT_EQ(1u, module_list->count);
+
+ const MinidumpModuleCrashpadInfo* module =
+ MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
+ file_writer.string(), module_list->children[0]);
+ ASSERT_TRUE(module);
+
+ EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
+ EXPECT_EQ(0u, module->minidump_module_list_index);
+
+ const MinidumpRVAList* list_annotations =
+ MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
+ file_writer.string(), module->list_annotations);
+ ASSERT_TRUE(list_annotations);
+
+ ASSERT_EQ(1u, list_annotations->count);
+ EXPECT_EQ(kEntry,
+ MinidumpUTF8StringAtRVAAsString(
+ file_writer.string(), list_annotations->children[0]));
+
+ const MinidumpSimpleStringDictionary* simple_annotations =
+ MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
+ file_writer.string(), module->simple_annotations);
+ EXPECT_FALSE(simple_annotations);
+}
+
} // namespace
} // namespace test
} // namespace crashpad
« no previous file with comments | « minidump/minidump_crashpad_info_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698