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

Side by Side Diff: minidump/minidump_memory_writer_test.cc

Issue 664283002: Refactor minidump test utilities for MinidumpWritable, … (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « minidump/minidump_file_writer_test.cc ('k') | minidump/minidump_misc_info_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 29 matching lines...) Expand all
40 const MINIDUMP_MEMORY_LIST** memory_list, 40 const MINIDUMP_MEMORY_LIST** memory_list,
41 const uint32_t expected_streams) { 41 const uint32_t expected_streams) {
42 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 42 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
43 const size_t kMemoryListStreamOffset = 43 const size_t kMemoryListStreamOffset =
44 kDirectoryOffset + expected_streams * sizeof(MINIDUMP_DIRECTORY); 44 kDirectoryOffset + expected_streams * sizeof(MINIDUMP_DIRECTORY);
45 const size_t kMemoryDescriptorsOffset = 45 const size_t kMemoryDescriptorsOffset =
46 kMemoryListStreamOffset + sizeof(MINIDUMP_MEMORY_LIST); 46 kMemoryListStreamOffset + sizeof(MINIDUMP_MEMORY_LIST);
47 47
48 ASSERT_GE(file_contents.size(), kMemoryDescriptorsOffset); 48 ASSERT_GE(file_contents.size(), kMemoryDescriptorsOffset);
49 49
50 const MINIDUMP_DIRECTORY* directory;
50 const MINIDUMP_HEADER* header = 51 const MINIDUMP_HEADER* header =
51 reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]); 52 MinidumpHeaderAtStart(file_contents, &directory);
53 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, expected_streams, 0));
54 ASSERT_TRUE(directory);
52 55
53 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, expected_streams, 0)); 56 size_t directory_index = 0;
54
55 const MINIDUMP_DIRECTORY* directory =
56 reinterpret_cast<const MINIDUMP_DIRECTORY*>(
57 &file_contents[kDirectoryOffset]);
58
59 if (expected_streams > 1) { 57 if (expected_streams > 1) {
60 ASSERT_EQ(kBogusStreamType, directory->StreamType); 58 ASSERT_EQ(kBogusStreamType, directory[directory_index].StreamType);
61 ASSERT_EQ(0u, directory->Location.DataSize); 59 ASSERT_EQ(0u, directory[directory_index].Location.DataSize);
62 ASSERT_EQ(kMemoryListStreamOffset, directory->Location.Rva); 60 ASSERT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva);
63 ++directory; 61 ++directory_index;
64 } 62 }
65 63
66 ASSERT_EQ(kMinidumpStreamTypeMemoryList, directory->StreamType); 64 ASSERT_EQ(kMinidumpStreamTypeMemoryList,
67 ASSERT_GE(directory->Location.DataSize, sizeof(MINIDUMP_MEMORY_LIST)); 65 directory[directory_index].StreamType);
68 ASSERT_EQ(kMemoryListStreamOffset, directory->Location.Rva); 66 ASSERT_GE(directory[directory_index].Location.DataSize,
67 sizeof(MINIDUMP_MEMORY_LIST));
68 ASSERT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva);
69 69
70 *memory_list = reinterpret_cast<const MINIDUMP_MEMORY_LIST*>( 70 *memory_list = reinterpret_cast<const MINIDUMP_MEMORY_LIST*>(
71 &file_contents[kMemoryListStreamOffset]); 71 &file_contents[kMemoryListStreamOffset]);
72 72
73 ASSERT_EQ(sizeof(MINIDUMP_MEMORY_LIST) + 73 ASSERT_EQ(sizeof(MINIDUMP_MEMORY_LIST) +
74 (*memory_list)->NumberOfMemoryRanges * 74 (*memory_list)->NumberOfMemoryRanges *
75 sizeof(MINIDUMP_MEMORY_DESCRIPTOR), 75 sizeof(MINIDUMP_MEMORY_DESCRIPTOR),
76 directory->Location.DataSize); 76 directory[directory_index].Location.DataSize);
77 } 77 }
78 78
79 TEST(MinidumpMemoryWriter, EmptyMemoryList) { 79 TEST(MinidumpMemoryWriter, EmptyMemoryList) {
80 MinidumpFileWriter minidump_file_writer; 80 MinidumpFileWriter minidump_file_writer;
81 MinidumpMemoryListWriter memory_list_writer; 81 MinidumpMemoryListWriter memory_list_writer;
82 82
83 minidump_file_writer.AddStream(&memory_list_writer); 83 minidump_file_writer.AddStream(&memory_list_writer);
84 84
85 StringFileWriter file_writer; 85 StringFileWriter file_writer;
86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 &memory_list->MemoryRanges[1], 291 &memory_list->MemoryRanges[1],
292 file_writer.string(), 292 file_writer.string(),
293 kValue1, 293 kValue1,
294 true); 294 true);
295 } 295 }
296 } 296 }
297 297
298 } // namespace 298 } // namespace
299 } // namespace test 299 } // namespace test
300 } // namespace crashpad 300 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_file_writer_test.cc ('k') | minidump/minidump_misc_info_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698