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 28 matching lines...) Expand all Loading... |
39 { | 39 { |
40 SCOPED_TRACE("unset"); | 40 SCOPED_TRACE("unset"); |
41 file_writer.Reset(); | 41 file_writer.Reset(); |
42 crashpad::internal::MinidumpUTF16StringWriter string_writer; | 42 crashpad::internal::MinidumpUTF16StringWriter string_writer; |
43 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 43 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
44 ASSERT_EQ(6u, file_writer.string().size()); | 44 ASSERT_EQ(6u, file_writer.string().size()); |
45 | 45 |
46 const MINIDUMP_STRING* minidump_string = | 46 const MINIDUMP_STRING* minidump_string = |
47 MinidumpStringAtRVA(file_writer.string(), 0); | 47 MinidumpStringAtRVA(file_writer.string(), 0); |
48 EXPECT_TRUE(minidump_string); | 48 EXPECT_TRUE(minidump_string); |
49 EXPECT_EQ(string16(), MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 49 EXPECT_EQ(base::string16(), |
| 50 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
50 } | 51 } |
51 | 52 |
52 const struct { | 53 const struct { |
53 size_t input_length; | 54 size_t input_length; |
54 const char* input_string; | 55 const char* input_string; |
55 size_t output_length; | 56 size_t output_length; |
56 const char16 output_string[10]; | 57 const base::char16 output_string[10]; |
57 } kTestData[] = { | 58 } kTestData[] = { |
58 {0, "", 0, {}}, | 59 {0, "", 0, {}}, |
59 {1, "a", 1, {'a'}}, | 60 {1, "a", 1, {'a'}}, |
60 {2, "\0b", 2, {0, 'b'}}, | 61 {2, "\0b", 2, {0, 'b'}}, |
61 {3, "cde", 3, {'c', 'd', 'e'}}, | 62 {3, "cde", 3, {'c', 'd', 'e'}}, |
62 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, | 63 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, |
63 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, | 64 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, |
64 {2, "\303\251", 1, {0x00e9}}, // é | 65 {2, "\303\251", 1, {0x00e9}}, // é |
65 | 66 |
66 // oóöőo | 67 // oóöőo |
(...skipping 21 matching lines...) Expand all Loading... |
88 const size_t expected_utf16_units_with_nul = | 89 const size_t expected_utf16_units_with_nul = |
89 kTestData[index].output_length + 1; | 90 kTestData[index].output_length + 1; |
90 const size_t expected_utf16_bytes = | 91 const size_t expected_utf16_bytes = |
91 expected_utf16_units_with_nul * sizeof(MINIDUMP_STRING::Buffer[0]); | 92 expected_utf16_units_with_nul * sizeof(MINIDUMP_STRING::Buffer[0]); |
92 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, | 93 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, |
93 file_writer.string().size()); | 94 file_writer.string().size()); |
94 | 95 |
95 const MINIDUMP_STRING* minidump_string = | 96 const MINIDUMP_STRING* minidump_string = |
96 MinidumpStringAtRVA(file_writer.string(), 0); | 97 MinidumpStringAtRVA(file_writer.string(), 0); |
97 EXPECT_TRUE(minidump_string); | 98 EXPECT_TRUE(minidump_string); |
98 string16 expect_string = string16(kTestData[index].output_string, | 99 base::string16 expect_string = base::string16( |
99 kTestData[index].output_length); | 100 kTestData[index].output_string, kTestData[index].output_length); |
100 EXPECT_EQ(expect_string, | 101 EXPECT_EQ(expect_string, |
101 MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 102 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) { | 106 TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) { |
106 StringFileWriter file_writer; | 107 StringFileWriter file_writer; |
107 | 108 |
108 const char* kTestData[] = { | 109 const char* kTestData[] = { |
109 "\200", // continuation byte | 110 "\200", // continuation byte |
(...skipping 16 matching lines...) Expand all Loading... |
126 // that at least enough data was written for a string that has one unit and | 127 // that at least enough data was written for a string that has one unit and |
127 // a NUL terminator, make sure that the length field matches the length of | 128 // a NUL terminator, make sure that the length field matches the length of |
128 // data written, and make sure that at least one U+FFFD replacement | 129 // data written, and make sure that at least one U+FFFD replacement |
129 // character was written. | 130 // character was written. |
130 const MINIDUMP_STRING* minidump_string = | 131 const MINIDUMP_STRING* minidump_string = |
131 MinidumpStringAtRVA(file_writer.string(), 0); | 132 MinidumpStringAtRVA(file_writer.string(), 0); |
132 EXPECT_TRUE(minidump_string); | 133 EXPECT_TRUE(minidump_string); |
133 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - | 134 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - |
134 sizeof(MINIDUMP_STRING::Buffer[0]), | 135 sizeof(MINIDUMP_STRING::Buffer[0]), |
135 minidump_string->Length); | 136 minidump_string->Length); |
136 string16 output_string = | 137 base::string16 output_string = |
137 MinidumpStringAtRVAAsString(file_writer.string(), 0); | 138 MinidumpStringAtRVAAsString(file_writer.string(), 0); |
138 EXPECT_FALSE(output_string.empty()); | 139 EXPECT_FALSE(output_string.empty()); |
139 EXPECT_NE(string16::npos, output_string.find(0xfffd)); | 140 EXPECT_NE(base::string16::npos, output_string.find(0xfffd)); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { | 144 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { |
144 StringFileWriter file_writer; | 145 StringFileWriter file_writer; |
145 | 146 |
146 { | 147 { |
147 SCOPED_TRACE("unset"); | 148 SCOPED_TRACE("unset"); |
148 file_writer.Reset(); | 149 file_writer.Reset(); |
149 crashpad::internal::MinidumpUTF8StringWriter string_writer; | 150 crashpad::internal::MinidumpUTF8StringWriter string_writer; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const MinidumpUTF8String* minidump_string = | 193 const MinidumpUTF8String* minidump_string = |
193 MinidumpUTF8StringAtRVA(file_writer.string(), 0); | 194 MinidumpUTF8StringAtRVA(file_writer.string(), 0); |
194 EXPECT_TRUE(minidump_string); | 195 EXPECT_TRUE(minidump_string); |
195 EXPECT_EQ(test_string, | 196 EXPECT_EQ(test_string, |
196 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0)); | 197 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0)); |
197 } | 198 } |
198 } | 199 } |
199 | 200 |
200 struct MinidumpUTF16StringListWriterTraits { | 201 struct MinidumpUTF16StringListWriterTraits { |
201 using MinidumpStringListWriterType = MinidumpUTF16StringListWriter; | 202 using MinidumpStringListWriterType = MinidumpUTF16StringListWriter; |
202 static string16 ExpectationForUTF8(const std::string& utf8) { | 203 static base::string16 ExpectationForUTF8(const std::string& utf8) { |
203 return base::UTF8ToUTF16(utf8); | 204 return base::UTF8ToUTF16(utf8); |
204 } | 205 } |
205 static string16 ObservationAtRVA(const std::string& file_contents, RVA rva) { | 206 static base::string16 ObservationAtRVA(const std::string& file_contents, |
| 207 RVA rva) { |
206 return MinidumpStringAtRVAAsString(file_contents, rva); | 208 return MinidumpStringAtRVAAsString(file_contents, rva); |
207 } | 209 } |
208 }; | 210 }; |
209 | 211 |
210 struct MinidumpUTF8StringListWriterTraits { | 212 struct MinidumpUTF8StringListWriterTraits { |
211 using MinidumpStringListWriterType = MinidumpUTF8StringListWriter; | 213 using MinidumpStringListWriterType = MinidumpUTF8StringListWriter; |
212 static std::string ExpectationForUTF8(const std::string& utf8) { | 214 static std::string ExpectationForUTF8(const std::string& utf8) { |
213 return utf8; | 215 return utf8; |
214 } | 216 } |
215 static std::string ObservationAtRVA(const std::string& file_contents, | 217 static std::string ObservationAtRVA(const std::string& file_contents, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); | 252 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); |
251 } | 253 } |
252 | 254 |
253 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { | 255 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { |
254 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); | 256 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); |
255 } | 257 } |
256 | 258 |
257 } // namespace | 259 } // namespace |
258 } // namespace test | 260 } // namespace test |
259 } // namespace crashpad | 261 } // namespace crashpad |
OLD | NEW |