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, |
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_misc_info_writer.h" | 15 #include "minidump/minidump_misc_info_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 #include <string.h> | 18 #include <string.h> |
19 | 19 |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "gtest/gtest.h" | 25 #include "gtest/gtest.h" |
26 #include "minidump/minidump_file_writer.h" | 26 #include "minidump/minidump_file_writer.h" |
27 #include "minidump/test/minidump_file_writer_test_util.h" | 27 #include "minidump/test/minidump_file_writer_test_util.h" |
| 28 #include "minidump/test/minidump_writable_test_util.h" |
28 #include "util/file/string_file_writer.h" | 29 #include "util/file/string_file_writer.h" |
29 #include "util/stdlib/strlcpy.h" | 30 #include "util/stdlib/strlcpy.h" |
30 | 31 |
31 namespace crashpad { | 32 namespace crashpad { |
32 namespace test { | 33 namespace test { |
33 namespace { | 34 namespace { |
34 | 35 |
35 template <typename T> | 36 template <typename T> |
36 void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) { | 37 void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) { |
37 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 38 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
38 const size_t kMiscInfoStreamOffset = | 39 const size_t kMiscInfoStreamOffset = |
39 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 40 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
40 const size_t kMiscInfoStreamSize = sizeof(T); | 41 const size_t kMiscInfoStreamSize = sizeof(T); |
41 const size_t kFileSize = kMiscInfoStreamOffset + kMiscInfoStreamSize; | 42 const size_t kFileSize = kMiscInfoStreamOffset + kMiscInfoStreamSize; |
42 | 43 |
43 ASSERT_EQ(kFileSize, file_contents.size()); | 44 ASSERT_EQ(kFileSize, file_contents.size()); |
44 | 45 |
45 const MINIDUMP_DIRECTORY* directory; | 46 const MINIDUMP_DIRECTORY* directory; |
46 const MINIDUMP_HEADER* header = | 47 const MINIDUMP_HEADER* header = |
47 MinidumpHeaderAtStart(file_contents, &directory); | 48 MinidumpHeaderAtStart(file_contents, &directory); |
48 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); | 49 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); |
49 ASSERT_TRUE(directory); | 50 ASSERT_TRUE(directory); |
50 | 51 |
51 ASSERT_EQ(kMinidumpStreamTypeMiscInfo, directory[0].StreamType); | 52 ASSERT_EQ(kMinidumpStreamTypeMiscInfo, directory[0].StreamType); |
52 ASSERT_EQ(kMiscInfoStreamSize, directory[0].Location.DataSize); | 53 EXPECT_EQ(kMiscInfoStreamOffset, directory[0].Location.Rva); |
53 ASSERT_EQ(kMiscInfoStreamOffset, directory[0].Location.Rva); | |
54 | 54 |
55 *misc_info = | 55 *misc_info = MinidumpWritableAtLocationDescriptor<T>(file_contents, |
56 reinterpret_cast<const T*>(&file_contents[kMiscInfoStreamOffset]); | 56 directory[0].Location); |
57 | 57 ASSERT_TRUE(misc_info); |
58 ASSERT_EQ(kMiscInfoStreamSize, (*misc_info)->SizeOfInfo); | |
59 } | 58 } |
60 | 59 |
61 void ExpectNULPaddedString16Equal(const char16* expected, | 60 void ExpectNULPaddedString16Equal(const char16* expected, |
62 const char16* observed, | 61 const char16* observed, |
63 size_t size) { | 62 size_t size) { |
64 string16 expected_string(expected, size); | 63 string16 expected_string(expected, size); |
65 string16 observed_string(observed, size); | 64 string16 observed_string(observed, size); |
66 EXPECT_EQ(expected_string, observed_string); | 65 EXPECT_EQ(expected_string, observed_string); |
67 } | 66 } |
68 | 67 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 c16lcpy(expected.DbgBldStr, | 607 c16lcpy(expected.DbgBldStr, |
609 debug_build_string_utf16.c_str(), | 608 debug_build_string_utf16.c_str(), |
610 arraysize(expected.DbgBldStr)); | 609 arraysize(expected.DbgBldStr)); |
611 | 610 |
612 ExpectMiscInfoEqual(&expected, observed); | 611 ExpectMiscInfoEqual(&expected, observed); |
613 } | 612 } |
614 | 613 |
615 } // namespace | 614 } // namespace |
616 } // namespace test | 615 } // namespace test |
617 } // namespace crashpad | 616 } // namespace crashpad |
OLD | NEW |