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

Side by Side Diff: snapshot/minidump/process_snapshot_minidump_test.cc

Issue 932153003: Add ProcessSnapshotMinidump, the beginning of the minidump variant of the Snapshot family (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 10 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "snapshot/minidump/process_snapshot_minidump.h"
16
17 #include <string.h>
18 #include <windows.h>
19 #include <dbghelp.h>
20
21 #include "base/memory/scoped_ptr.h"
22 #include "gtest/gtest.h"
23 #include "util/file/string_file.h"
24
25 namespace crashpad {
26 namespace test {
27 namespace {
28
29 TEST(ProcessSnapshotMinidump, EmptyFile) {
30 StringFile string_file;
31 ProcessSnapshotMinidump process_snapshot;
32
33 EXPECT_FALSE(process_snapshot.Initialize(&string_file));
34 }
35
36 TEST(ProcessSnapshotMinidump, InvalidSignatureAndVersion) {
37 StringFile string_file;
38
39 MINIDUMP_HEADER header = {};
40
41 EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
42
43 ProcessSnapshotMinidump process_snapshot;
44 EXPECT_FALSE(process_snapshot.Initialize(&string_file));
45 }
46
47 TEST(ProcessSnapshotMinidump, Empty) {
48 StringFile string_file;
49
50 MINIDUMP_HEADER header = {};
51 header.Signature = MINIDUMP_SIGNATURE;
52 header.Version = MINIDUMP_VERSION;
53
54 EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
55
56 ProcessSnapshotMinidump process_snapshot;
57 EXPECT_TRUE(process_snapshot.Initialize(&string_file));
58 }
59
60 TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) {
61 StringFile string_file;
62
63 MINIDUMP_HEADER header = {};
64 EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
65
66 MinidumpSimpleStringDictionaryEntry entry0 = {};
67 entry0.key = string_file.SeekGet();
68 const char kKey0[] = "the first key";
69 MinidumpUTF8String string = {};
70 string.Length = strlen(kKey0);
71 EXPECT_TRUE(string_file.Write(&string, sizeof(string)));
72 EXPECT_TRUE(string_file.Write(kKey0, sizeof(kKey0)));
73
74 entry0.value = string_file.SeekGet();
75 const char kValue0[] = "THE FIRST VALUE EVER!";
76 string.Length = strlen(kValue0);
77 EXPECT_TRUE(string_file.Write(&string, sizeof(string)));
78 EXPECT_TRUE(string_file.Write(kValue0, sizeof(kValue0)));
79
80 MinidumpSimpleStringDictionaryEntry entry1 = {};
81 entry1.key = string_file.SeekGet();
82 const char kKey1[] = "2key";
83 string.Length = strlen(kKey1);
84 EXPECT_TRUE(string_file.Write(&string, sizeof(string)));
85 EXPECT_TRUE(string_file.Write(kKey1, sizeof(kKey1)));
86
87 entry1.value = string_file.SeekGet();
88 const char kValue1[] = "THE FIRST VALUE EVER!";
Robert Sesek 2015/02/19 15:13:19 SECOND VALUE EVER?
89 string.Length = strlen(kValue1);
90 EXPECT_TRUE(string_file.Write(&string, sizeof(string)));
91 EXPECT_TRUE(string_file.Write(kValue1, sizeof(kValue1)));
92
93 MinidumpCrashpadInfo crashpad_info = {};
94 crashpad_info.version = MinidumpCrashpadInfo::kVersion;
95
96 crashpad_info.simple_annotations.Rva = string_file.SeekGet();
97 MinidumpSimpleStringDictionary simple_string_dictionary = {};
98 simple_string_dictionary.count = 2;
99 EXPECT_TRUE(string_file.Write(&simple_string_dictionary,
100 sizeof(simple_string_dictionary)));
101 EXPECT_TRUE(string_file.Write(&entry0, sizeof(entry0)));
102 EXPECT_TRUE(string_file.Write(&entry1, sizeof(entry1)));
103 crashpad_info.simple_annotations.DataSize =
104 simple_string_dictionary.count *
105 sizeof(simple_string_dictionary.entries[0]);
106
107 MINIDUMP_DIRECTORY crashpad_info_directory = {};
108 crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo;
109 crashpad_info_directory.Location.Rva = string_file.SeekGet();
110 EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info)));
111 crashpad_info_directory.Location.DataSize = sizeof(crashpad_info);
112
113 header.StreamDirectoryRva = string_file.SeekGet();
114 EXPECT_TRUE(string_file.Write(&crashpad_info_directory,
115 sizeof(crashpad_info_directory)));
116
117 header.Signature = MINIDUMP_SIGNATURE;
118 header.Version = MINIDUMP_VERSION;
119 header.NumberOfStreams = 1;
120 EXPECT_TRUE(string_file.SeekSet(0));
121 EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
122
123 ProcessSnapshotMinidump process_snapshot;
124 EXPECT_TRUE(process_snapshot.Initialize(&string_file));
125
126 const auto annotations_simple_map = process_snapshot.AnnotationsSimpleMap();
127 EXPECT_EQ(2u, annotations_simple_map.size());
128
129 auto it = annotations_simple_map.find(kKey0);
130 ASSERT_NE(it, annotations_simple_map.end());
131 EXPECT_EQ(kValue0, it->second);
132
133 it = annotations_simple_map.find(kKey1);
134 ASSERT_NE(it, annotations_simple_map.end());
135 EXPECT_EQ(kValue1, it->second);
136 }
137
138 } // namespace
139 } // namespace test
140 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698