OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "minidump/minidump_extensions.h" | 24 #include "minidump/minidump_extensions.h" |
25 #include "minidump/minidump_file_writer.h" | 25 #include "minidump/minidump_file_writer.h" |
26 #include "minidump/minidump_module_crashpad_info_writer.h" | 26 #include "minidump/minidump_module_crashpad_info_writer.h" |
27 #include "minidump/minidump_simple_string_dictionary_writer.h" | 27 #include "minidump/minidump_simple_string_dictionary_writer.h" |
28 #include "minidump/test/minidump_file_writer_test_util.h" | 28 #include "minidump/test/minidump_file_writer_test_util.h" |
29 #include "minidump/test/minidump_string_writer_test_util.h" | 29 #include "minidump/test/minidump_string_writer_test_util.h" |
30 #include "minidump/test/minidump_writable_test_util.h" | 30 #include "minidump/test/minidump_writable_test_util.h" |
31 #include "snapshot/test/test_module_snapshot.h" | 31 #include "snapshot/test/test_module_snapshot.h" |
32 #include "snapshot/test/test_process_snapshot.h" | 32 #include "snapshot/test/test_process_snapshot.h" |
33 #include "util/file/string_file.h" | 33 #include "util/file/string_file.h" |
| 34 #include "util/stdlib/move.h" |
34 | 35 |
35 namespace crashpad { | 36 namespace crashpad { |
36 namespace test { | 37 namespace test { |
37 namespace { | 38 namespace { |
38 | 39 |
39 void GetCrashpadInfoStream( | 40 void GetCrashpadInfoStream( |
40 const std::string& file_contents, | 41 const std::string& file_contents, |
41 const MinidumpCrashpadInfo** crashpad_info, | 42 const MinidumpCrashpadInfo** crashpad_info, |
42 const MinidumpSimpleStringDictionary** simple_annotations, | 43 const MinidumpSimpleStringDictionary** simple_annotations, |
43 const MinidumpModuleCrashpadInfoList** module_list) { | 44 const MinidumpModuleCrashpadInfoList** module_list) { |
(...skipping 16 matching lines...) Expand all Loading... |
60 *module_list = | 61 *module_list = |
61 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>( | 62 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>( |
62 file_contents, (*crashpad_info)->module_list); | 63 file_contents, (*crashpad_info)->module_list); |
63 } | 64 } |
64 | 65 |
65 TEST(MinidumpCrashpadInfoWriter, Empty) { | 66 TEST(MinidumpCrashpadInfoWriter, Empty) { |
66 MinidumpFileWriter minidump_file_writer; | 67 MinidumpFileWriter minidump_file_writer; |
67 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 68 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
68 EXPECT_FALSE(crashpad_info_writer->IsUseful()); | 69 EXPECT_FALSE(crashpad_info_writer->IsUseful()); |
69 | 70 |
70 minidump_file_writer.AddStream(crashpad_info_writer.Pass()); | 71 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); |
71 | 72 |
72 StringFile string_file; | 73 StringFile string_file; |
73 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 74 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
74 | 75 |
75 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 76 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
76 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 77 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
77 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 78 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
78 | 79 |
79 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 80 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
80 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 81 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 14 matching lines...) Expand all Loading... |
95 report_id.InitializeFromString("01234567-89ab-cdef-0123-456789abcdef")); | 96 report_id.InitializeFromString("01234567-89ab-cdef-0123-456789abcdef")); |
96 crashpad_info_writer->SetReportID(report_id); | 97 crashpad_info_writer->SetReportID(report_id); |
97 | 98 |
98 UUID client_id; | 99 UUID client_id; |
99 ASSERT_TRUE( | 100 ASSERT_TRUE( |
100 client_id.InitializeFromString("00112233-4455-6677-8899-aabbccddeeff")); | 101 client_id.InitializeFromString("00112233-4455-6677-8899-aabbccddeeff")); |
101 crashpad_info_writer->SetClientID(client_id); | 102 crashpad_info_writer->SetClientID(client_id); |
102 | 103 |
103 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 104 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
104 | 105 |
105 minidump_file_writer.AddStream(crashpad_info_writer.Pass()); | 106 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); |
106 | 107 |
107 StringFile string_file; | 108 StringFile string_file; |
108 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 109 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
109 | 110 |
110 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 111 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
111 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 112 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
112 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 113 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
113 | 114 |
114 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 115 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
115 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 116 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 14 matching lines...) Expand all Loading... |
130 "something"; | 131 "something"; |
131 const char kValue[] = | 132 const char kValue[] = |
132 "the numerical amount denoted by an algebraic term; a magnitude, " | 133 "the numerical amount denoted by an algebraic term; a magnitude, " |
133 "quantity, or number"; | 134 "quantity, or number"; |
134 auto simple_string_dictionary_writer = | 135 auto simple_string_dictionary_writer = |
135 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 136 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
136 auto simple_string_dictionary_entry_writer = | 137 auto simple_string_dictionary_entry_writer = |
137 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 138 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
138 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); | 139 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); |
139 simple_string_dictionary_writer->AddEntry( | 140 simple_string_dictionary_writer->AddEntry( |
140 simple_string_dictionary_entry_writer.Pass()); | 141 crashpad::move(simple_string_dictionary_entry_writer)); |
141 crashpad_info_writer->SetSimpleAnnotations( | 142 crashpad_info_writer->SetSimpleAnnotations( |
142 simple_string_dictionary_writer.Pass()); | 143 crashpad::move(simple_string_dictionary_writer)); |
143 | 144 |
144 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 145 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
145 | 146 |
146 minidump_file_writer.AddStream(crashpad_info_writer.Pass()); | 147 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); |
147 | 148 |
148 StringFile string_file; | 149 StringFile string_file; |
149 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 150 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
150 | 151 |
151 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 152 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
152 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 153 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
153 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 154 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
154 | 155 |
155 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 156 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
156 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 157 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 13 matching lines...) Expand all Loading... |
170 | 171 |
171 TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) { | 172 TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) { |
172 const uint32_t kMinidumpModuleListIndex = 3; | 173 const uint32_t kMinidumpModuleListIndex = 3; |
173 | 174 |
174 MinidumpFileWriter minidump_file_writer; | 175 MinidumpFileWriter minidump_file_writer; |
175 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 176 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
176 | 177 |
177 auto module_list_writer = | 178 auto module_list_writer = |
178 make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter()); | 179 make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter()); |
179 auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 180 auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
180 module_list_writer->AddModule(module_writer.Pass(), kMinidumpModuleListIndex); | 181 module_list_writer->AddModule(crashpad::move(module_writer), kMinidumpModuleLi
stIndex); |
181 crashpad_info_writer->SetModuleList(module_list_writer.Pass()); | 182 crashpad_info_writer->SetModuleList(crashpad::move(module_list_writer)); |
182 | 183 |
183 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 184 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
184 | 185 |
185 minidump_file_writer.AddStream(crashpad_info_writer.Pass()); | 186 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); |
186 | 187 |
187 StringFile string_file; | 188 StringFile string_file; |
188 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 189 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
189 | 190 |
190 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 191 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
191 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 192 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
192 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 193 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
193 | 194 |
194 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 195 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
195 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 196 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 29 matching lines...) Expand all Loading... |
225 | 226 |
226 const char kKey[] = "version"; | 227 const char kKey[] = "version"; |
227 const char kValue[] = "40.0.2214.111"; | 228 const char kValue[] = "40.0.2214.111"; |
228 const char kEntry[] = "This is a simple annotation in a list."; | 229 const char kEntry[] = "This is a simple annotation in a list."; |
229 | 230 |
230 // Test with a useless module, one that doesn’t carry anything that would | 231 // Test with a useless module, one that doesn’t carry anything that would |
231 // require MinidumpCrashpadInfo or any child object. | 232 // require MinidumpCrashpadInfo or any child object. |
232 auto process_snapshot = make_scoped_ptr(new TestProcessSnapshot()); | 233 auto process_snapshot = make_scoped_ptr(new TestProcessSnapshot()); |
233 | 234 |
234 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); | 235 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); |
235 process_snapshot->AddModule(module_snapshot.Pass()); | 236 process_snapshot->AddModule(crashpad::move(module_snapshot)); |
236 | 237 |
237 auto info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 238 auto info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
238 info_writer->InitializeFromSnapshot(process_snapshot.get()); | 239 info_writer->InitializeFromSnapshot(process_snapshot.get()); |
239 EXPECT_FALSE(info_writer->IsUseful()); | 240 EXPECT_FALSE(info_writer->IsUseful()); |
240 | 241 |
241 // Try again with a useful module. | 242 // Try again with a useful module. |
242 process_snapshot.reset(new TestProcessSnapshot()); | 243 process_snapshot.reset(new TestProcessSnapshot()); |
243 | 244 |
244 process_snapshot->SetReportID(report_id); | 245 process_snapshot->SetReportID(report_id); |
245 process_snapshot->SetClientID(client_id); | 246 process_snapshot->SetClientID(client_id); |
246 | 247 |
247 std::map<std::string, std::string> annotations_simple_map; | 248 std::map<std::string, std::string> annotations_simple_map; |
248 annotations_simple_map[kKey] = kValue; | 249 annotations_simple_map[kKey] = kValue; |
249 process_snapshot->SetAnnotationsSimpleMap(annotations_simple_map); | 250 process_snapshot->SetAnnotationsSimpleMap(annotations_simple_map); |
250 | 251 |
251 module_snapshot.reset(new TestModuleSnapshot()); | 252 module_snapshot.reset(new TestModuleSnapshot()); |
252 std::vector<std::string> annotations_list(1, std::string(kEntry)); | 253 std::vector<std::string> annotations_list(1, std::string(kEntry)); |
253 module_snapshot->SetAnnotationsVector(annotations_list); | 254 module_snapshot->SetAnnotationsVector(annotations_list); |
254 process_snapshot->AddModule(module_snapshot.Pass()); | 255 process_snapshot->AddModule(crashpad::move(module_snapshot)); |
255 | 256 |
256 info_writer.reset(new MinidumpCrashpadInfoWriter()); | 257 info_writer.reset(new MinidumpCrashpadInfoWriter()); |
257 info_writer->InitializeFromSnapshot(process_snapshot.get()); | 258 info_writer->InitializeFromSnapshot(process_snapshot.get()); |
258 EXPECT_TRUE(info_writer->IsUseful()); | 259 EXPECT_TRUE(info_writer->IsUseful()); |
259 | 260 |
260 MinidumpFileWriter minidump_file_writer; | 261 MinidumpFileWriter minidump_file_writer; |
261 minidump_file_writer.AddStream(info_writer.Pass()); | 262 minidump_file_writer.AddStream(crashpad::move(info_writer)); |
262 | 263 |
263 StringFile string_file; | 264 StringFile string_file; |
264 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 265 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
265 | 266 |
266 const MinidumpCrashpadInfo* info = nullptr; | 267 const MinidumpCrashpadInfo* info = nullptr; |
267 const MinidumpSimpleStringDictionary* simple_annotations; | 268 const MinidumpSimpleStringDictionary* simple_annotations; |
268 const MinidumpModuleCrashpadInfoList* module_list; | 269 const MinidumpModuleCrashpadInfoList* module_list; |
269 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 270 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
270 string_file.string(), &info, &simple_annotations, &module_list)); | 271 string_file.string(), &info, &simple_annotations, &module_list)); |
271 | 272 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 307 |
307 const MinidumpSimpleStringDictionary* module_simple_annotations = | 308 const MinidumpSimpleStringDictionary* module_simple_annotations = |
308 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( | 309 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( |
309 string_file.string(), module->simple_annotations); | 310 string_file.string(), module->simple_annotations); |
310 EXPECT_FALSE(module_simple_annotations); | 311 EXPECT_FALSE(module_simple_annotations); |
311 } | 312 } |
312 | 313 |
313 } // namespace | 314 } // namespace |
314 } // namespace test | 315 } // namespace test |
315 } // namespace crashpad | 316 } // namespace crashpad |
OLD | NEW |