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

Side by Side Diff: minidump/minidump_module_writer_test.cc

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