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_string_writer.h" | 15 #include "minidump/minidump_string_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 #include <sys/types.h> | 18 #include <sys/types.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/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" |
25 #include "gtest/gtest.h" | 26 #include "gtest/gtest.h" |
| 27 #include "minidump/test/minidump_rva_list_test_util.h" |
26 #include "minidump/test/minidump_string_writer_test_util.h" | 28 #include "minidump/test/minidump_string_writer_test_util.h" |
| 29 #include "minidump/test/minidump_writable_test_util.h" |
27 #include "util/file/string_file_writer.h" | 30 #include "util/file/string_file_writer.h" |
28 | 31 |
29 namespace crashpad { | 32 namespace crashpad { |
30 namespace test { | 33 namespace test { |
31 namespace { | 34 namespace { |
32 | 35 |
33 TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) { | 36 TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) { |
34 StringFileWriter file_writer; | 37 StringFileWriter file_writer; |
35 | 38 |
36 { | 39 { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 file_writer.string().size()); | 190 file_writer.string().size()); |
188 | 191 |
189 const MinidumpUTF8String* minidump_string = | 192 const MinidumpUTF8String* minidump_string = |
190 MinidumpUTF8StringAtRVA(file_writer.string(), 0); | 193 MinidumpUTF8StringAtRVA(file_writer.string(), 0); |
191 EXPECT_TRUE(minidump_string); | 194 EXPECT_TRUE(minidump_string); |
192 EXPECT_EQ(test_string, | 195 EXPECT_EQ(test_string, |
193 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0)); | 196 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0)); |
194 } | 197 } |
195 } | 198 } |
196 | 199 |
| 200 struct MinidumpUTF16StringListWriterTraits { |
| 201 using MinidumpStringListWriterType = internal::MinidumpUTF16StringListWriter; |
| 202 static string16 ExpectationForUTF8(const std::string& utf8) { |
| 203 return base::UTF8ToUTF16(utf8); |
| 204 } |
| 205 static string16 ObservationAtRVA(const std::string& file_contents, RVA rva) { |
| 206 return MinidumpStringAtRVAAsString(file_contents, rva); |
| 207 } |
| 208 }; |
| 209 |
| 210 struct MinidumpUTF8StringListWriterTraits { |
| 211 using MinidumpStringListWriterType = internal::MinidumpUTF8StringListWriter; |
| 212 static std::string ExpectationForUTF8(const std::string& utf8) { |
| 213 return utf8; |
| 214 } |
| 215 static std::string ObservationAtRVA(const std::string& file_contents, |
| 216 RVA rva) { |
| 217 return MinidumpUTF8StringAtRVAAsString(file_contents, rva); |
| 218 } |
| 219 }; |
| 220 |
| 221 template <typename Traits> |
| 222 void MinidumpStringListTest() { |
| 223 std::vector<std::string> strings; |
| 224 strings.push_back(std::string("One")); |
| 225 strings.push_back(std::string()); |
| 226 strings.push_back(std::string("3")); |
| 227 strings.push_back(std::string("\360\237\222\251")); |
| 228 |
| 229 typename Traits::MinidumpStringListWriterType string_list_writer; |
| 230 EXPECT_FALSE(string_list_writer.IsUseful()); |
| 231 string_list_writer.InitializeFromVector(strings); |
| 232 EXPECT_TRUE(string_list_writer.IsUseful()); |
| 233 |
| 234 StringFileWriter file_writer; |
| 235 |
| 236 ASSERT_TRUE(string_list_writer.WriteEverything(&file_writer)); |
| 237 |
| 238 const MinidumpRVAList* list = |
| 239 MinidumpRVAListAtStart(file_writer.string(), strings.size()); |
| 240 ASSERT_TRUE(list); |
| 241 |
| 242 for (size_t index = 0; index < strings.size(); ++index) { |
| 243 EXPECT_EQ(Traits::ExpectationForUTF8(strings[index]), |
| 244 Traits::ObservationAtRVA(file_writer.string(), |
| 245 list->children[index])); |
| 246 } |
| 247 } |
| 248 |
| 249 TEST(MinidumpStringWriter, MinidumpUTF16StringList) { |
| 250 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); |
| 251 } |
| 252 |
| 253 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { |
| 254 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); |
| 255 } |
| 256 |
197 } // namespace | 257 } // namespace |
198 } // namespace test | 258 } // namespace test |
199 } // namespace crashpad | 259 } // namespace crashpad |
OLD | NEW |