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 <windows.h> | 17 #include <windows.h> |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 | 20 |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
24 #include "base/compiler_specific.h" | |
24 #include "base/strings/string16.h" | 25 #include "base/strings/string16.h" |
25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
27 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
28 #include "minidump/test/minidump_rva_list_test_util.h" | 29 #include "minidump/test/minidump_rva_list_test_util.h" |
29 #include "minidump/test/minidump_string_writer_test_util.h" | 30 #include "minidump/test/minidump_string_writer_test_util.h" |
30 #include "minidump/test/minidump_writable_test_util.h" | 31 #include "minidump/test/minidump_writable_test_util.h" |
31 #include "util/file/string_file_writer.h" | 32 #include "util/file/string_file_writer.h" |
32 | 33 |
33 namespace crashpad { | 34 namespace crashpad { |
(...skipping 14 matching lines...) Expand all Loading... | |
48 MinidumpStringAtRVA(file_writer.string(), 0); | 49 MinidumpStringAtRVA(file_writer.string(), 0); |
49 EXPECT_TRUE(minidump_string); | 50 EXPECT_TRUE(minidump_string); |
50 EXPECT_EQ(base::string16(), | 51 EXPECT_EQ(base::string16(), |
51 MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 52 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
52 } | 53 } |
53 | 54 |
54 const struct { | 55 const struct { |
55 size_t input_length; | 56 size_t input_length; |
56 const char* input_string; | 57 const char* input_string; |
57 size_t output_length; | 58 size_t output_length; |
58 const base::char16 output_string[10]; | 59 base::char16 output_string[10]; |
Mark Mentovai
2015/02/05 17:14:52
Yeah, this is better. The data should be const eno
| |
59 } kTestData[] = { | 60 } kTestData[] = { |
60 {0, "", 0, {}}, | 61 {0, "", 0, {}}, |
61 {1, "a", 1, {'a'}}, | 62 {1, "a", 1, {'a'}}, |
62 {2, "\0b", 2, {0, 'b'}}, | 63 {2, "\0b", 2, {0, 'b'}}, |
63 {3, "cde", 3, {'c', 'd', 'e'}}, | 64 {3, "cde", 3, {'c', 'd', 'e'}}, |
64 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, | 65 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, |
65 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, | 66 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, |
66 {2, "\303\251", 1, {0x00e9}}, // é | 67 {2, "\303\251", 1, {0x00e9}}, // é |
67 | 68 |
68 // oóöőo | 69 // oóöőo |
(...skipping 13 matching lines...) Expand all Loading... | |
82 .output_string[arraysize(kTestData[index].output_string) - 1]); | 83 .output_string[arraysize(kTestData[index].output_string) - 1]); |
83 | 84 |
84 file_writer.Reset(); | 85 file_writer.Reset(); |
85 crashpad::internal::MinidumpUTF16StringWriter string_writer; | 86 crashpad::internal::MinidumpUTF16StringWriter string_writer; |
86 string_writer.SetUTF8(std::string(kTestData[index].input_string, | 87 string_writer.SetUTF8(std::string(kTestData[index].input_string, |
87 kTestData[index].input_length)); | 88 kTestData[index].input_length)); |
88 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 89 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
89 | 90 |
90 const size_t expected_utf16_units_with_nul = | 91 const size_t expected_utf16_units_with_nul = |
91 kTestData[index].output_length + 1; | 92 kTestData[index].output_length + 1; |
93 MINIDUMP_STRING tmp = {0}; | |
Mark Mentovai
2015/02/05 17:14:52
Is the initialization required? Line 138 too.
scottmg
2015/02/05 17:41:57
Yes, because of zero-sized array (same as https://
| |
94 ALLOW_UNUSED_LOCAL(tmp); | |
92 const size_t expected_utf16_bytes = | 95 const size_t expected_utf16_bytes = |
93 expected_utf16_units_with_nul * sizeof(MINIDUMP_STRING::Buffer[0]); | 96 expected_utf16_units_with_nul * sizeof(tmp.Buffer[0]); |
94 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, | 97 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, |
95 file_writer.string().size()); | 98 file_writer.string().size()); |
96 | 99 |
97 const MINIDUMP_STRING* minidump_string = | 100 const MINIDUMP_STRING* minidump_string = |
98 MinidumpStringAtRVA(file_writer.string(), 0); | 101 MinidumpStringAtRVA(file_writer.string(), 0); |
99 EXPECT_TRUE(minidump_string); | 102 EXPECT_TRUE(minidump_string); |
100 base::string16 expect_string = base::string16( | 103 base::string16 expect_string = base::string16( |
101 kTestData[index].output_string, kTestData[index].output_length); | 104 kTestData[index].output_string, kTestData[index].output_length); |
102 EXPECT_EQ(expect_string, | 105 EXPECT_EQ(expect_string, |
103 MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 106 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
(...skipping 21 matching lines...) Expand all Loading... | |
125 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 128 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
126 | 129 |
127 // The requirements for conversion of invalid UTF-8 input are lax. Make sure | 130 // The requirements for conversion of invalid UTF-8 input are lax. Make sure |
128 // that at least enough data was written for a string that has one unit and | 131 // that at least enough data was written for a string that has one unit and |
129 // a NUL terminator, make sure that the length field matches the length of | 132 // a NUL terminator, make sure that the length field matches the length of |
130 // data written, and make sure that at least one U+FFFD replacement | 133 // data written, and make sure that at least one U+FFFD replacement |
131 // character was written. | 134 // character was written. |
132 const MINIDUMP_STRING* minidump_string = | 135 const MINIDUMP_STRING* minidump_string = |
133 MinidumpStringAtRVA(file_writer.string(), 0); | 136 MinidumpStringAtRVA(file_writer.string(), 0); |
134 EXPECT_TRUE(minidump_string); | 137 EXPECT_TRUE(minidump_string); |
138 MINIDUMP_STRING tmp = {0}; | |
139 ALLOW_UNUSED_LOCAL(tmp); | |
135 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - | 140 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - |
136 sizeof(MINIDUMP_STRING::Buffer[0]), | 141 sizeof(tmp.Buffer[0]), |
137 minidump_string->Length); | 142 minidump_string->Length); |
138 base::string16 output_string = | 143 base::string16 output_string = |
139 MinidumpStringAtRVAAsString(file_writer.string(), 0); | 144 MinidumpStringAtRVAAsString(file_writer.string(), 0); |
140 EXPECT_FALSE(output_string.empty()); | 145 EXPECT_FALSE(output_string.empty()); |
141 EXPECT_NE(base::string16::npos, output_string.find(0xfffd)); | 146 EXPECT_NE(base::string16::npos, output_string.find(0xfffd)); |
142 } | 147 } |
143 } | 148 } |
144 | 149 |
145 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { | 150 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { |
146 StringFileWriter file_writer; | 151 StringFileWriter file_writer; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); | 258 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); |
254 } | 259 } |
255 | 260 |
256 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { | 261 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { |
257 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); | 262 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); |
258 } | 263 } |
259 | 264 |
260 } // namespace | 265 } // namespace |
261 } // namespace test | 266 } // namespace test |
262 } // namespace crashpad | 267 } // namespace crashpad |
OLD | NEW |