OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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_handle_writer.h" | 15 #include "minidump/minidump_handle_writer.h" |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "gtest/gtest.h" | 20 #include "gtest/gtest.h" |
21 #include "minidump/minidump_file_writer.h" | 21 #include "minidump/minidump_file_writer.h" |
22 #include "minidump/test/minidump_file_writer_test_util.h" | 22 #include "minidump/test/minidump_file_writer_test_util.h" |
23 #include "minidump/test/minidump_string_writer_test_util.h" | 23 #include "minidump/test/minidump_string_writer_test_util.h" |
24 #include "minidump/test/minidump_writable_test_util.h" | 24 #include "minidump/test/minidump_writable_test_util.h" |
25 #include "util/file/string_file.h" | 25 #include "util/file/string_file.h" |
| 26 #include "util/stdlib/move.h" |
26 | 27 |
27 namespace crashpad { | 28 namespace crashpad { |
28 namespace test { | 29 namespace test { |
29 namespace { | 30 namespace { |
30 | 31 |
31 // The handle data stream is expected to be the only stream. | 32 // The handle data stream is expected to be the only stream. |
32 void GetHandleDataStream( | 33 void GetHandleDataStream( |
33 const std::string& file_contents, | 34 const std::string& file_contents, |
34 const MINIDUMP_HANDLE_DATA_STREAM** handle_data_stream) { | 35 const MINIDUMP_HANDLE_DATA_STREAM** handle_data_stream) { |
35 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 36 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
(...skipping 14 matching lines...) Expand all Loading... |
50 | 51 |
51 *handle_data_stream = | 52 *handle_data_stream = |
52 MinidumpWritableAtLocationDescriptor<MINIDUMP_HANDLE_DATA_STREAM>( | 53 MinidumpWritableAtLocationDescriptor<MINIDUMP_HANDLE_DATA_STREAM>( |
53 file_contents, directory[kDirectoryIndex].Location); | 54 file_contents, directory[kDirectoryIndex].Location); |
54 ASSERT_TRUE(*handle_data_stream); | 55 ASSERT_TRUE(*handle_data_stream); |
55 } | 56 } |
56 | 57 |
57 TEST(MinidumpHandleDataWriter, Empty) { | 58 TEST(MinidumpHandleDataWriter, Empty) { |
58 MinidumpFileWriter minidump_file_writer; | 59 MinidumpFileWriter minidump_file_writer; |
59 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter()); | 60 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter()); |
60 minidump_file_writer.AddStream(handle_data_writer.Pass()); | 61 minidump_file_writer.AddStream(crashpad::move(handle_data_writer)); |
61 | 62 |
62 StringFile string_file; | 63 StringFile string_file; |
63 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 64 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
64 | 65 |
65 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 66 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
66 sizeof(MINIDUMP_HANDLE_DATA_STREAM), | 67 sizeof(MINIDUMP_HANDLE_DATA_STREAM), |
67 string_file.string().size()); | 68 string_file.string().size()); |
68 | 69 |
69 const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr; | 70 const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr; |
70 ASSERT_NO_FATAL_FAILURE( | 71 ASSERT_NO_FATAL_FAILURE( |
(...skipping 12 matching lines...) Expand all Loading... |
83 handle_snapshot.attributes = 0x12345678; | 84 handle_snapshot.attributes = 0x12345678; |
84 handle_snapshot.granted_access = 0x9abcdef0; | 85 handle_snapshot.granted_access = 0x9abcdef0; |
85 handle_snapshot.pointer_count = 4567; | 86 handle_snapshot.pointer_count = 4567; |
86 handle_snapshot.handle_count = 9876; | 87 handle_snapshot.handle_count = 9876; |
87 | 88 |
88 std::vector<HandleSnapshot> snapshot; | 89 std::vector<HandleSnapshot> snapshot; |
89 snapshot.push_back(handle_snapshot); | 90 snapshot.push_back(handle_snapshot); |
90 | 91 |
91 handle_data_writer->InitializeFromSnapshot(snapshot); | 92 handle_data_writer->InitializeFromSnapshot(snapshot); |
92 | 93 |
93 minidump_file_writer.AddStream(handle_data_writer.Pass()); | 94 minidump_file_writer.AddStream(crashpad::move(handle_data_writer)); |
94 | 95 |
95 StringFile string_file; | 96 StringFile string_file; |
96 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 97 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
97 | 98 |
98 const size_t kTypeNameStringDataLength = | 99 const size_t kTypeNameStringDataLength = |
99 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16); | 100 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16); |
100 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 101 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
101 sizeof(MINIDUMP_HANDLE_DATA_STREAM) + | 102 sizeof(MINIDUMP_HANDLE_DATA_STREAM) + |
102 sizeof(MINIDUMP_HANDLE_DESCRIPTOR) + sizeof(MINIDUMP_STRING) + | 103 sizeof(MINIDUMP_HANDLE_DESCRIPTOR) + sizeof(MINIDUMP_STRING) + |
103 kTypeNameStringDataLength, | 104 kTypeNameStringDataLength, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 handle_snapshot2.granted_access = 0x0fedcba9; | 142 handle_snapshot2.granted_access = 0x0fedcba9; |
142 handle_snapshot2.pointer_count = 7654; | 143 handle_snapshot2.pointer_count = 7654; |
143 handle_snapshot2.handle_count = 6789; | 144 handle_snapshot2.handle_count = 6789; |
144 | 145 |
145 std::vector<HandleSnapshot> snapshot; | 146 std::vector<HandleSnapshot> snapshot; |
146 snapshot.push_back(handle_snapshot); | 147 snapshot.push_back(handle_snapshot); |
147 snapshot.push_back(handle_snapshot2); | 148 snapshot.push_back(handle_snapshot2); |
148 | 149 |
149 handle_data_writer->InitializeFromSnapshot(snapshot); | 150 handle_data_writer->InitializeFromSnapshot(snapshot); |
150 | 151 |
151 minidump_file_writer.AddStream(handle_data_writer.Pass()); | 152 minidump_file_writer.AddStream(crashpad::move(handle_data_writer)); |
152 | 153 |
153 StringFile string_file; | 154 StringFile string_file; |
154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 155 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
155 | 156 |
156 const size_t kTypeNameStringDataLength = | 157 const size_t kTypeNameStringDataLength = |
157 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16); | 158 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16); |
158 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 159 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
159 sizeof(MINIDUMP_HANDLE_DATA_STREAM) + | 160 sizeof(MINIDUMP_HANDLE_DATA_STREAM) + |
160 (sizeof(MINIDUMP_HANDLE_DESCRIPTOR) * 2) + | 161 (sizeof(MINIDUMP_HANDLE_DESCRIPTOR) * 2) + |
161 sizeof(MINIDUMP_STRING) + kTypeNameStringDataLength, | 162 sizeof(MINIDUMP_STRING) + kTypeNameStringDataLength, |
(...skipping 30 matching lines...) Expand all Loading... |
192 EXPECT_EQ(handle_snapshot2.granted_access, handle_descriptor2->GrantedAccess); | 193 EXPECT_EQ(handle_snapshot2.granted_access, handle_descriptor2->GrantedAccess); |
193 EXPECT_EQ(handle_snapshot2.handle_count, handle_descriptor2->HandleCount); | 194 EXPECT_EQ(handle_snapshot2.handle_count, handle_descriptor2->HandleCount); |
194 EXPECT_EQ(handle_snapshot2.pointer_count, handle_descriptor2->PointerCount); | 195 EXPECT_EQ(handle_snapshot2.pointer_count, handle_descriptor2->PointerCount); |
195 | 196 |
196 EXPECT_EQ(handle_descriptor->TypeNameRva, handle_descriptor2->TypeNameRva); | 197 EXPECT_EQ(handle_descriptor->TypeNameRva, handle_descriptor2->TypeNameRva); |
197 } | 198 } |
198 | 199 |
199 } // namespace | 200 } // namespace |
200 } // namespace test | 201 } // namespace test |
201 } // namespace crashpad | 202 } // namespace crashpad |
OLD | NEW |