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

Side by Side Diff: minidump/minidump_module_writer_test.cc

Issue 1513573005: Provide std::move() in compat instead of using crashpad::move() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years 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
« no previous file with comments | « minidump/minidump_module_writer.cc ('k') | minidump/minidump_rva_list_writer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_module_writer.h" 15 #include "minidump/minidump_module_writer.h"
16 16
17 #include <windows.h> 17 #include <windows.h>
18 #include <dbghelp.h> 18 #include <dbghelp.h>
19 #include <stdint.h> 19 #include <stdint.h>
20 #include <string.h> 20 #include <string.h>
21 #include <sys/types.h> 21 #include <sys/types.h>
22 22
23 #include <utility>
24
23 #include "base/format_macros.h" 25 #include "base/format_macros.h"
24 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
26 #include "gtest/gtest.h" 28 #include "gtest/gtest.h"
27 #include "minidump/minidump_extensions.h" 29 #include "minidump/minidump_extensions.h"
28 #include "minidump/minidump_file_writer.h" 30 #include "minidump/minidump_file_writer.h"
29 #include "minidump/test/minidump_file_writer_test_util.h" 31 #include "minidump/test/minidump_file_writer_test_util.h"
30 #include "minidump/test/minidump_string_writer_test_util.h" 32 #include "minidump/test/minidump_string_writer_test_util.h"
31 #include "minidump/test/minidump_writable_test_util.h" 33 #include "minidump/test/minidump_writable_test_util.h"
32 #include "snapshot/test/test_module_snapshot.h" 34 #include "snapshot/test/test_module_snapshot.h"
33 #include "test/gtest_death_check.h" 35 #include "test/gtest_death_check.h"
34 #include "util/file/string_file.h" 36 #include "util/file/string_file.h"
35 #include "util/misc/implicit_cast.h" 37 #include "util/misc/implicit_cast.h"
36 #include "util/stdlib/move.h"
37 #include "util/misc/uuid.h" 38 #include "util/misc/uuid.h"
38 #include "util/stdlib/pointer_container.h" 39 #include "util/stdlib/pointer_container.h"
39 40
40 namespace crashpad { 41 namespace crashpad {
41 namespace test { 42 namespace test {
42 namespace { 43 namespace {
43 44
44 void GetModuleListStream(const std::string& file_contents, 45 void GetModuleListStream(const std::string& file_contents,
45 const MINIDUMP_MODULE_LIST** module_list) { 46 const MINIDUMP_MODULE_LIST** module_list) {
46 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 47 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
(...skipping 15 matching lines...) Expand all
62 63
63 *module_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( 64 *module_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
64 file_contents, directory[0].Location); 65 file_contents, directory[0].Location);
65 ASSERT_TRUE(module_list); 66 ASSERT_TRUE(module_list);
66 } 67 }
67 68
68 TEST(MinidumpModuleWriter, EmptyModuleList) { 69 TEST(MinidumpModuleWriter, EmptyModuleList) {
69 MinidumpFileWriter minidump_file_writer; 70 MinidumpFileWriter minidump_file_writer;
70 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); 71 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter());
71 72
72 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 73 minidump_file_writer.AddStream(std::move(module_list_writer));
73 74
74 StringFile string_file; 75 StringFile string_file;
75 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 76 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
76 77
77 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 78 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
78 sizeof(MINIDUMP_MODULE_LIST), 79 sizeof(MINIDUMP_MODULE_LIST),
79 string_file.string().size()); 80 string_file.string().size());
80 81
81 const MINIDUMP_MODULE_LIST* module_list = nullptr; 82 const MINIDUMP_MODULE_LIST* module_list = nullptr;
82 ASSERT_NO_FATAL_FAILURE( 83 ASSERT_NO_FATAL_FAILURE(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 271
271 TEST(MinidumpModuleWriter, EmptyModule) { 272 TEST(MinidumpModuleWriter, EmptyModule) {
272 MinidumpFileWriter minidump_file_writer; 273 MinidumpFileWriter minidump_file_writer;
273 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); 274 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter());
274 275
275 const char kModuleName[] = "test_executable"; 276 const char kModuleName[] = "test_executable";
276 277
277 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); 278 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter());
278 module_writer->SetName(kModuleName); 279 module_writer->SetName(kModuleName);
279 280
280 module_list_writer->AddModule(crashpad::move(module_writer)); 281 module_list_writer->AddModule(std::move(module_writer));
281 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 282 minidump_file_writer.AddStream(std::move(module_list_writer));
282 283
283 StringFile string_file; 284 StringFile string_file;
284 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 285 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
285 286
286 ASSERT_GT(string_file.string().size(), 287 ASSERT_GT(string_file.string().size(),
287 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 288 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
288 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE)); 289 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
289 290
290 const MINIDUMP_MODULE_LIST* module_list = nullptr; 291 const MINIDUMP_MODULE_LIST* module_list = nullptr;
291 ASSERT_NO_FATAL_FAILURE( 292 ASSERT_NO_FATAL_FAILURE(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 kProductVersionLS >> 16, 354 kProductVersionLS >> 16,
354 kProductVersionLS & 0xffff); 355 kProductVersionLS & 0xffff);
355 module_writer->SetFileFlagsAndMask(kFileFlags, kFileFlagsMask); 356 module_writer->SetFileFlagsAndMask(kFileFlags, kFileFlagsMask);
356 module_writer->SetFileOS(kFileOS); 357 module_writer->SetFileOS(kFileOS);
357 module_writer->SetFileTypeAndSubtype(kFileType, kFileSubtype); 358 module_writer->SetFileTypeAndSubtype(kFileType, kFileSubtype);
358 359
359 auto codeview_pdb70_writer = 360 auto codeview_pdb70_writer =
360 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB70Writer()); 361 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB70Writer());
361 codeview_pdb70_writer->SetPDBName(kPDBName); 362 codeview_pdb70_writer->SetPDBName(kPDBName);
362 codeview_pdb70_writer->SetUUIDAndAge(pdb_uuid, kPDBAge); 363 codeview_pdb70_writer->SetUUIDAndAge(pdb_uuid, kPDBAge);
363 module_writer->SetCodeViewRecord(crashpad::move(codeview_pdb70_writer)); 364 module_writer->SetCodeViewRecord(std::move(codeview_pdb70_writer));
364 365
365 auto misc_debug_writer = 366 auto misc_debug_writer =
366 make_scoped_ptr(new MinidumpModuleMiscDebugRecordWriter()); 367 make_scoped_ptr(new MinidumpModuleMiscDebugRecordWriter());
367 misc_debug_writer->SetDataType(kDebugType); 368 misc_debug_writer->SetDataType(kDebugType);
368 misc_debug_writer->SetData(kDebugName, kDebugUTF16); 369 misc_debug_writer->SetData(kDebugName, kDebugUTF16);
369 module_writer->SetMiscDebugRecord(crashpad::move(misc_debug_writer)); 370 module_writer->SetMiscDebugRecord(std::move(misc_debug_writer));
370 371
371 module_list_writer->AddModule(crashpad::move(module_writer)); 372 module_list_writer->AddModule(std::move(module_writer));
372 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 373 minidump_file_writer.AddStream(std::move(module_list_writer));
373 374
374 StringFile string_file; 375 StringFile string_file;
375 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 376 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
376 377
377 ASSERT_GT(string_file.string().size(), 378 ASSERT_GT(string_file.string().size(),
378 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 379 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
379 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE)); 380 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
380 381
381 const MINIDUMP_MODULE_LIST* module_list = nullptr; 382 const MINIDUMP_MODULE_LIST* module_list = nullptr;
382 ASSERT_NO_FATAL_FAILURE( 383 ASSERT_NO_FATAL_FAILURE(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 const char kDebugName[] = "d1n05.dbg"; 429 const char kDebugName[] = "d1n05.dbg";
429 const bool kDebugUTF16 = true; 430 const bool kDebugUTF16 = true;
430 431
431 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); 432 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter());
432 module_writer->SetName(kModuleName); 433 module_writer->SetName(kModuleName);
433 434
434 auto codeview_pdb20_writer = 435 auto codeview_pdb20_writer =
435 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB20Writer()); 436 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB20Writer());
436 codeview_pdb20_writer->SetPDBName(kPDBName); 437 codeview_pdb20_writer->SetPDBName(kPDBName);
437 codeview_pdb20_writer->SetTimestampAndAge(kPDBTimestamp, kPDBAge); 438 codeview_pdb20_writer->SetTimestampAndAge(kPDBTimestamp, kPDBAge);
438 module_writer->SetCodeViewRecord(crashpad::move(codeview_pdb20_writer)); 439 module_writer->SetCodeViewRecord(std::move(codeview_pdb20_writer));
439 440
440 auto misc_debug_writer = 441 auto misc_debug_writer =
441 make_scoped_ptr(new MinidumpModuleMiscDebugRecordWriter()); 442 make_scoped_ptr(new MinidumpModuleMiscDebugRecordWriter());
442 misc_debug_writer->SetDataType(kDebugType); 443 misc_debug_writer->SetDataType(kDebugType);
443 misc_debug_writer->SetData(kDebugName, kDebugUTF16); 444 misc_debug_writer->SetData(kDebugName, kDebugUTF16);
444 module_writer->SetMiscDebugRecord(crashpad::move(misc_debug_writer)); 445 module_writer->SetMiscDebugRecord(std::move(misc_debug_writer));
445 446
446 module_list_writer->AddModule(crashpad::move(module_writer)); 447 module_list_writer->AddModule(std::move(module_writer));
447 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 448 minidump_file_writer.AddStream(std::move(module_list_writer));
448 449
449 StringFile string_file; 450 StringFile string_file;
450 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 451 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
451 452
452 ASSERT_GT(string_file.string().size(), 453 ASSERT_GT(string_file.string().size(),
453 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 454 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
454 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE)); 455 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
455 456
456 const MINIDUMP_MODULE_LIST* module_list = nullptr; 457 const MINIDUMP_MODULE_LIST* module_list = nullptr;
457 ASSERT_NO_FATAL_FAILURE( 458 ASSERT_NO_FATAL_FAILURE(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 506
506 auto module_writer_0 = make_scoped_ptr(new MinidumpModuleWriter()); 507 auto module_writer_0 = make_scoped_ptr(new MinidumpModuleWriter());
507 module_writer_0->SetName(kModuleName0); 508 module_writer_0->SetName(kModuleName0);
508 module_writer_0->SetImageBaseAddress(kModuleBase0); 509 module_writer_0->SetImageBaseAddress(kModuleBase0);
509 module_writer_0->SetImageSize(kModuleSize0); 510 module_writer_0->SetImageSize(kModuleSize0);
510 511
511 auto codeview_pdb70_writer_0 = 512 auto codeview_pdb70_writer_0 =
512 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB70Writer()); 513 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB70Writer());
513 codeview_pdb70_writer_0->SetPDBName(kPDBName0); 514 codeview_pdb70_writer_0->SetPDBName(kPDBName0);
514 codeview_pdb70_writer_0->SetUUIDAndAge(pdb_uuid_0, kPDBAge0); 515 codeview_pdb70_writer_0->SetUUIDAndAge(pdb_uuid_0, kPDBAge0);
515 module_writer_0->SetCodeViewRecord(crashpad::move(codeview_pdb70_writer_0)); 516 module_writer_0->SetCodeViewRecord(std::move(codeview_pdb70_writer_0));
516 517
517 module_list_writer->AddModule(crashpad::move(module_writer_0)); 518 module_list_writer->AddModule(std::move(module_writer_0));
518 519
519 auto module_writer_1 = make_scoped_ptr(new MinidumpModuleWriter()); 520 auto module_writer_1 = make_scoped_ptr(new MinidumpModuleWriter());
520 module_writer_1->SetName(kModuleName1); 521 module_writer_1->SetName(kModuleName1);
521 module_writer_1->SetImageBaseAddress(kModuleBase1); 522 module_writer_1->SetImageBaseAddress(kModuleBase1);
522 module_writer_1->SetImageSize(kModuleSize1); 523 module_writer_1->SetImageSize(kModuleSize1);
523 524
524 module_list_writer->AddModule(crashpad::move(module_writer_1)); 525 module_list_writer->AddModule(std::move(module_writer_1));
525 526
526 auto module_writer_2 = make_scoped_ptr(new MinidumpModuleWriter()); 527 auto module_writer_2 = make_scoped_ptr(new MinidumpModuleWriter());
527 module_writer_2->SetName(kModuleName2); 528 module_writer_2->SetName(kModuleName2);
528 module_writer_2->SetImageBaseAddress(kModuleBase2); 529 module_writer_2->SetImageBaseAddress(kModuleBase2);
529 module_writer_2->SetImageSize(kModuleSize2); 530 module_writer_2->SetImageSize(kModuleSize2);
530 531
531 auto codeview_pdb70_writer_2 = 532 auto codeview_pdb70_writer_2 =
532 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB20Writer()); 533 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB20Writer());
533 codeview_pdb70_writer_2->SetPDBName(kPDBName2); 534 codeview_pdb70_writer_2->SetPDBName(kPDBName2);
534 codeview_pdb70_writer_2->SetTimestampAndAge(kPDBTimestamp2, kPDBAge2); 535 codeview_pdb70_writer_2->SetTimestampAndAge(kPDBTimestamp2, kPDBAge2);
535 module_writer_2->SetCodeViewRecord(crashpad::move(codeview_pdb70_writer_2)); 536 module_writer_2->SetCodeViewRecord(std::move(codeview_pdb70_writer_2));
536 537
537 module_list_writer->AddModule(crashpad::move(module_writer_2)); 538 module_list_writer->AddModule(std::move(module_writer_2));
538 539
539 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 540 minidump_file_writer.AddStream(std::move(module_list_writer));
540 541
541 StringFile string_file; 542 StringFile string_file;
542 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 543 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
543 544
544 ASSERT_GT(string_file.string().size(), 545 ASSERT_GT(string_file.string().size(),
545 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 546 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
546 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE)); 547 sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
547 548
548 const MINIDUMP_MODULE_LIST* module_list = nullptr; 549 const MINIDUMP_MODULE_LIST* module_list = nullptr;
549 ASSERT_NO_FATAL_FAILURE( 550 ASSERT_NO_FATAL_FAILURE(
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 module_pdbs[index], 723 module_pdbs[index],
723 uuids[index], 724 uuids[index],
724 ages[index]); 725 ages[index]);
725 module_snapshots.push_back(module_snapshot); 726 module_snapshots.push_back(module_snapshot);
726 } 727 }
727 728
728 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); 729 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter());
729 module_list_writer->InitializeFromSnapshot(module_snapshots); 730 module_list_writer->InitializeFromSnapshot(module_snapshots);
730 731
731 MinidumpFileWriter minidump_file_writer; 732 MinidumpFileWriter minidump_file_writer;
732 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 733 minidump_file_writer.AddStream(std::move(module_list_writer));
733 734
734 StringFile string_file; 735 StringFile string_file;
735 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 736 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
736 737
737 const MINIDUMP_MODULE_LIST* module_list = nullptr; 738 const MINIDUMP_MODULE_LIST* module_list = nullptr;
738 ASSERT_NO_FATAL_FAILURE( 739 ASSERT_NO_FATAL_FAILURE(
739 GetModuleListStream(string_file.string(), &module_list)); 740 GetModuleListStream(string_file.string(), &module_list));
740 741
741 ASSERT_EQ(3u, module_list->NumberOfModules); 742 ASSERT_EQ(3u, module_list->NumberOfModules);
742 743
(...skipping 10 matching lines...) Expand all
753 nullptr, 754 nullptr,
754 0, 755 0,
755 false)); 756 false));
756 } 757 }
757 } 758 }
758 759
759 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { 760 TEST(MinidumpModuleWriterDeathTest, NoModuleName) {
760 MinidumpFileWriter minidump_file_writer; 761 MinidumpFileWriter minidump_file_writer;
761 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); 762 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter());
762 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); 763 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter());
763 module_list_writer->AddModule(crashpad::move(module_writer)); 764 module_list_writer->AddModule(std::move(module_writer));
764 minidump_file_writer.AddStream(crashpad::move(module_list_writer)); 765 minidump_file_writer.AddStream(std::move(module_list_writer));
765 766
766 StringFile string_file; 767 StringFile string_file;
767 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), 768 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file),
768 "name_"); 769 "name_");
769 } 770 }
770 771
771 } // namespace 772 } // namespace
772 } // namespace test 773 } // namespace test
773 } // namespace crashpad 774 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_module_writer.cc ('k') | minidump/minidump_rva_list_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698