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_context_writer.h" | 15 #include "minidump/minidump_context_writer.h" |
16 | 16 |
17 #include <stdint.h> | 17 #include <stdint.h> |
18 | 18 |
19 #include "gtest/gtest.h" | 19 #include "gtest/gtest.h" |
20 #include "minidump/minidump_context.h" | 20 #include "minidump/minidump_context.h" |
21 #include "minidump/test/minidump_context_test_util.h" | 21 #include "minidump/test/minidump_context_test_util.h" |
| 22 #include "minidump/test/minidump_writable_test_util.h" |
22 #include "util/file/string_file_writer.h" | 23 #include "util/file/string_file_writer.h" |
23 | 24 |
24 namespace crashpad { | 25 namespace crashpad { |
25 namespace test { | 26 namespace test { |
26 namespace { | 27 namespace { |
27 | 28 |
28 TEST(MinidumpContextWriter, MinidumpContextX86Writer) { | 29 TEST(MinidumpContextWriter, MinidumpContextX86Writer) { |
29 StringFileWriter file_writer; | 30 StringFileWriter file_writer; |
30 | 31 |
31 { | 32 { |
32 // Make sure that a context writer that’s untouched writes a zeroed-out | 33 // Make sure that a context writer that’s untouched writes a zeroed-out |
33 // context. | 34 // context. |
34 SCOPED_TRACE("zero"); | 35 SCOPED_TRACE("zero"); |
35 | 36 |
36 MinidumpContextX86Writer context_writer; | 37 MinidumpContextX86Writer context_writer; |
37 | 38 |
38 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); | 39 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); |
39 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); | 40 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); |
40 | 41 |
41 const MinidumpContextX86* observed = | 42 const MinidumpContextX86* observed = |
42 reinterpret_cast<const MinidumpContextX86*>(&file_writer.string()[0]); | 43 MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0); |
43 ExpectMinidumpContextX86(0, observed); | 44 ExpectMinidumpContextX86(0, observed); |
44 } | 45 } |
45 | 46 |
46 { | 47 { |
47 SCOPED_TRACE("nonzero"); | 48 SCOPED_TRACE("nonzero"); |
48 | 49 |
49 file_writer.Reset(); | 50 file_writer.Reset(); |
50 const uint32_t kSeed = 0x8086; | 51 const uint32_t kSeed = 0x8086; |
51 | 52 |
52 MinidumpContextX86Writer context_writer; | 53 MinidumpContextX86Writer context_writer; |
53 InitializeMinidumpContextX86(context_writer.context(), kSeed); | 54 InitializeMinidumpContextX86(context_writer.context(), kSeed); |
54 | 55 |
55 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); | 56 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); |
56 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); | 57 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); |
57 | 58 |
58 const MinidumpContextX86* observed = | 59 const MinidumpContextX86* observed = |
59 reinterpret_cast<const MinidumpContextX86*>(&file_writer.string()[0]); | 60 MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0); |
60 ExpectMinidumpContextX86(kSeed, observed); | 61 ExpectMinidumpContextX86(kSeed, observed); |
61 } | 62 } |
62 } | 63 } |
63 | 64 |
64 TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) { | 65 TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) { |
65 StringFileWriter file_writer; | 66 StringFileWriter file_writer; |
66 | 67 |
67 { | 68 { |
68 // Make sure that a context writer that’s untouched writes a zeroed-out | 69 // Make sure that a context writer that’s untouched writes a zeroed-out |
69 // context. | 70 // context. |
70 SCOPED_TRACE("zero"); | 71 SCOPED_TRACE("zero"); |
71 | 72 |
72 MinidumpContextAMD64Writer context_writer; | 73 MinidumpContextAMD64Writer context_writer; |
73 | 74 |
74 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); | 75 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); |
75 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); | 76 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); |
76 | 77 |
77 const MinidumpContextAMD64* observed = | 78 const MinidumpContextAMD64* observed = |
78 reinterpret_cast<const MinidumpContextAMD64*>(&file_writer.string()[0]); | 79 MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0); |
79 ExpectMinidumpContextAMD64(0, observed); | 80 ExpectMinidumpContextAMD64(0, observed); |
80 } | 81 } |
81 | 82 |
82 { | 83 { |
83 SCOPED_TRACE("nonzero"); | 84 SCOPED_TRACE("nonzero"); |
84 | 85 |
85 file_writer.Reset(); | 86 file_writer.Reset(); |
86 const uint32_t kSeed = 0x808664; | 87 const uint32_t kSeed = 0x808664; |
87 | 88 |
88 MinidumpContextAMD64Writer context_writer; | 89 MinidumpContextAMD64Writer context_writer; |
89 InitializeMinidumpContextAMD64(context_writer.context(), kSeed); | 90 InitializeMinidumpContextAMD64(context_writer.context(), kSeed); |
90 | 91 |
91 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); | 92 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); |
92 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); | 93 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); |
93 | 94 |
94 const MinidumpContextAMD64* observed = | 95 const MinidumpContextAMD64* observed = |
95 reinterpret_cast<const MinidumpContextAMD64*>(&file_writer.string()[0]); | 96 MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0); |
96 ExpectMinidumpContextAMD64(kSeed, observed); | 97 ExpectMinidumpContextAMD64(kSeed, observed); |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 } // namespace | 101 } // namespace |
101 } // namespace test | 102 } // namespace test |
102 } // namespace crashpad | 103 } // namespace crashpad |
OLD | NEW |