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, |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace crashpad { | 29 namespace crashpad { |
30 namespace test { | 30 namespace test { |
31 namespace { | 31 namespace { |
32 | 32 |
33 TEST(MinidumpFileWriter, Empty) { | 33 TEST(MinidumpFileWriter, Empty) { |
34 MinidumpFileWriter minidump_file; | 34 MinidumpFileWriter minidump_file; |
35 StringFileWriter file_writer; | 35 StringFileWriter file_writer; |
36 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); | 36 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); |
37 ASSERT_EQ(sizeof(MINIDUMP_HEADER), file_writer.string().size()); | 37 ASSERT_EQ(sizeof(MINIDUMP_HEADER), file_writer.string().size()); |
38 | 38 |
| 39 const MINIDUMP_DIRECTORY* directory; |
39 const MINIDUMP_HEADER* header = | 40 const MINIDUMP_HEADER* header = |
40 reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]); | 41 MinidumpHeaderAtStart(file_writer.string(), &directory); |
41 | |
42 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0)); | 42 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0)); |
| 43 EXPECT_FALSE(directory); |
43 } | 44 } |
44 | 45 |
45 class TestStream final : public internal::MinidumpStreamWriter { | 46 class TestStream final : public internal::MinidumpStreamWriter { |
46 public: | 47 public: |
47 TestStream(MinidumpStreamType stream_type, | 48 TestStream(MinidumpStreamType stream_type, |
48 size_t stream_size, | 49 size_t stream_size, |
49 uint8_t stream_value) | 50 uint8_t stream_value) |
50 : stream_data_(stream_size, stream_value), stream_type_(stream_type) {} | 51 : stream_data_(stream_size, stream_value), stream_type_(stream_type) {} |
51 | 52 |
52 ~TestStream() {} | 53 ~TestStream() {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 StringFileWriter file_writer; | 90 StringFileWriter file_writer; |
90 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); | 91 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); |
91 | 92 |
92 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 93 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
93 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 94 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
94 const size_t kFileSize = kStreamOffset + kStreamSize; | 95 const size_t kFileSize = kStreamOffset + kStreamSize; |
95 | 96 |
96 ASSERT_EQ(kFileSize, file_writer.string().size()); | 97 ASSERT_EQ(kFileSize, file_writer.string().size()); |
97 | 98 |
| 99 const MINIDUMP_DIRECTORY* directory; |
98 const MINIDUMP_HEADER* header = | 100 const MINIDUMP_HEADER* header = |
99 reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]); | 101 MinidumpHeaderAtStart(file_writer.string(), &directory); |
| 102 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp)); |
| 103 ASSERT_TRUE(directory); |
100 | 104 |
101 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp)); | 105 EXPECT_EQ(kStreamType, directory[0].StreamType); |
102 | 106 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); |
103 const MINIDUMP_DIRECTORY* directory = | 107 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); |
104 reinterpret_cast<const MINIDUMP_DIRECTORY*>( | |
105 &file_writer.string()[kDirectoryOffset]); | |
106 | |
107 EXPECT_EQ(kStreamType, directory->StreamType); | |
108 EXPECT_EQ(kStreamSize, directory->Location.DataSize); | |
109 EXPECT_EQ(kStreamOffset, directory->Location.Rva); | |
110 | 108 |
111 const uint8_t* stream_data = | 109 const uint8_t* stream_data = |
112 reinterpret_cast<const uint8_t*>(&file_writer.string()[kStreamOffset]); | 110 reinterpret_cast<const uint8_t*>(&file_writer.string()[kStreamOffset]); |
113 | 111 |
114 std::string expected_stream(kStreamSize, kStreamValue); | 112 std::string expected_stream(kStreamSize, kStreamValue); |
115 EXPECT_EQ(0, memcmp(stream_data, expected_stream.c_str(), kStreamSize)); | 113 EXPECT_EQ(0, memcmp(stream_data, expected_stream.c_str(), kStreamSize)); |
116 } | 114 } |
117 | 115 |
118 TEST(MinidumpFileWriter, ThreeStreams) { | 116 TEST(MinidumpFileWriter, ThreeStreams) { |
119 MinidumpFileWriter minidump_file; | 117 MinidumpFileWriter minidump_file; |
(...skipping 28 matching lines...) Expand all Loading... |
148 const size_t kStream1Offset = | 146 const size_t kStream1Offset = |
149 kDirectoryOffset + 3 * sizeof(MINIDUMP_DIRECTORY); | 147 kDirectoryOffset + 3 * sizeof(MINIDUMP_DIRECTORY); |
150 const size_t kStream2Padding = 3; | 148 const size_t kStream2Padding = 3; |
151 const size_t kStream2Offset = kStream1Offset + kStream1Size + kStream2Padding; | 149 const size_t kStream2Offset = kStream1Offset + kStream1Size + kStream2Padding; |
152 const size_t kStream3Padding = 1; | 150 const size_t kStream3Padding = 1; |
153 const size_t kStream3Offset = kStream2Offset + kStream2Size + kStream3Padding; | 151 const size_t kStream3Offset = kStream2Offset + kStream2Size + kStream3Padding; |
154 const size_t kFileSize = kStream3Offset + kStream3Size; | 152 const size_t kFileSize = kStream3Offset + kStream3Size; |
155 | 153 |
156 ASSERT_EQ(kFileSize, file_writer.string().size()); | 154 ASSERT_EQ(kFileSize, file_writer.string().size()); |
157 | 155 |
| 156 const MINIDUMP_DIRECTORY* directory; |
158 const MINIDUMP_HEADER* header = | 157 const MINIDUMP_HEADER* header = |
159 reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]); | 158 MinidumpHeaderAtStart(file_writer.string(), &directory); |
160 | |
161 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp)); | 159 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp)); |
162 | 160 ASSERT_TRUE(directory); |
163 const MINIDUMP_DIRECTORY* directory = | |
164 reinterpret_cast<const MINIDUMP_DIRECTORY*>( | |
165 &file_writer.string()[kDirectoryOffset]); | |
166 | 161 |
167 EXPECT_EQ(kStream1Type, directory[0].StreamType); | 162 EXPECT_EQ(kStream1Type, directory[0].StreamType); |
168 EXPECT_EQ(kStream1Size, directory[0].Location.DataSize); | 163 EXPECT_EQ(kStream1Size, directory[0].Location.DataSize); |
169 EXPECT_EQ(kStream1Offset, directory[0].Location.Rva); | 164 EXPECT_EQ(kStream1Offset, directory[0].Location.Rva); |
170 EXPECT_EQ(kStream2Type, directory[1].StreamType); | 165 EXPECT_EQ(kStream2Type, directory[1].StreamType); |
171 EXPECT_EQ(kStream2Size, directory[1].Location.DataSize); | 166 EXPECT_EQ(kStream2Size, directory[1].Location.DataSize); |
172 EXPECT_EQ(kStream2Offset, directory[1].Location.Rva); | 167 EXPECT_EQ(kStream2Offset, directory[1].Location.Rva); |
173 EXPECT_EQ(kStream3Type, directory[2].StreamType); | 168 EXPECT_EQ(kStream3Type, directory[2].StreamType); |
174 EXPECT_EQ(kStream3Size, directory[2].Location.DataSize); | 169 EXPECT_EQ(kStream3Size, directory[2].Location.DataSize); |
175 EXPECT_EQ(kStream3Offset, directory[2].Location.Rva); | 170 EXPECT_EQ(kStream3Offset, directory[2].Location.Rva); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 205 |
211 StringFileWriter file_writer; | 206 StringFileWriter file_writer; |
212 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); | 207 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); |
213 | 208 |
214 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 209 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
215 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 210 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
216 const size_t kFileSize = kStreamOffset + kStreamSize; | 211 const size_t kFileSize = kStreamOffset + kStreamSize; |
217 | 212 |
218 ASSERT_EQ(kFileSize, file_writer.string().size()); | 213 ASSERT_EQ(kFileSize, file_writer.string().size()); |
219 | 214 |
| 215 const MINIDUMP_DIRECTORY* directory; |
220 const MINIDUMP_HEADER* header = | 216 const MINIDUMP_HEADER* header = |
221 reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]); | 217 MinidumpHeaderAtStart(file_writer.string(), &directory); |
| 218 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); |
| 219 ASSERT_TRUE(directory); |
222 | 220 |
223 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); | 221 EXPECT_EQ(kStreamType, directory[0].StreamType); |
224 | 222 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); |
225 const MINIDUMP_DIRECTORY* directory = | 223 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); |
226 reinterpret_cast<const MINIDUMP_DIRECTORY*>( | |
227 &file_writer.string()[kDirectoryOffset]); | |
228 | |
229 EXPECT_EQ(kStreamType, directory->StreamType); | |
230 EXPECT_EQ(kStreamSize, directory->Location.DataSize); | |
231 EXPECT_EQ(kStreamOffset, directory->Location.Rva); | |
232 } | 224 } |
233 | 225 |
234 TEST(MinidumpFileWriterDeathTest, SameStreamType) { | 226 TEST(MinidumpFileWriterDeathTest, SameStreamType) { |
235 MinidumpFileWriter minidump_file; | 227 MinidumpFileWriter minidump_file; |
236 | 228 |
237 const size_t kStream1Size = 5; | 229 const size_t kStream1Size = 5; |
238 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); | 230 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); |
239 const uint8_t kStream1Value = 0x5a; | 231 const uint8_t kStream1Value = 0x5a; |
240 TestStream stream1(kStream1Type, kStream1Size, kStream1Value); | 232 TestStream stream1(kStream1Type, kStream1Size, kStream1Value); |
241 minidump_file.AddStream(&stream1); | 233 minidump_file.AddStream(&stream1); |
242 | 234 |
243 // It is an error to add a second stream of the same type. | 235 // It is an error to add a second stream of the same type. |
244 const size_t kStream2Size = 3; | 236 const size_t kStream2Size = 3; |
245 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x4d); | 237 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x4d); |
246 const uint8_t kStream2Value = 0xa5; | 238 const uint8_t kStream2Value = 0xa5; |
247 TestStream stream2(kStream2Type, kStream2Size, kStream2Value); | 239 TestStream stream2(kStream2Type, kStream2Size, kStream2Value); |
248 ASSERT_DEATH(minidump_file.AddStream(&stream2), "already present"); | 240 ASSERT_DEATH(minidump_file.AddStream(&stream2), "already present"); |
249 } | 241 } |
250 | 242 |
251 } // namespace | 243 } // namespace |
252 } // namespace test | 244 } // namespace test |
253 } // namespace crashpad | 245 } // namespace crashpad |
OLD | NEW |