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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 44 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
45 ASSERT_EQ(6u, file_writer.string().size()); | 45 ASSERT_EQ(6u, file_writer.string().size()); |
46 | 46 |
47 const MINIDUMP_STRING* minidump_string = | 47 const MINIDUMP_STRING* minidump_string = |
48 MinidumpStringAtRVA(file_writer.string(), 0); | 48 MinidumpStringAtRVA(file_writer.string(), 0); |
49 EXPECT_TRUE(minidump_string); | 49 EXPECT_TRUE(minidump_string); |
50 EXPECT_EQ(base::string16(), | 50 EXPECT_EQ(base::string16(), |
51 MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 51 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
52 } | 52 } |
53 | 53 |
54 #if defined(OS_WIN) | |
Mark Mentovai
2015/02/05 14:37:42
COMPILER_MSVC, not OS_WIN.
Make sure the rest of
| |
55 #pragma warning(push) | |
56 // Can't generate default constructor, assignment operator, can never be | |
Mark Mentovai
2015/02/05 14:37:42
This is OK, but I’m surprised to see this kind of
scottmg
2015/02/05 17:09:39
It's the const. Removing that seems better?
| |
57 // instantiated. | |
58 #pragma warning(disable: 4510 4512 4610) | |
59 #endif // OS_WIN | |
54 const struct { | 60 const struct { |
55 size_t input_length; | 61 size_t input_length; |
56 const char* input_string; | 62 const char* input_string; |
57 size_t output_length; | 63 size_t output_length; |
58 const base::char16 output_string[10]; | 64 const base::char16 output_string[10]; |
59 } kTestData[] = { | 65 } kTestData[] = { |
60 {0, "", 0, {}}, | 66 {0, "", 0, {}}, |
61 {1, "a", 1, {'a'}}, | 67 {1, "a", 1, {'a'}}, |
62 {2, "\0b", 2, {0, 'b'}}, | 68 {2, "\0b", 2, {0, 'b'}}, |
63 {3, "cde", 3, {'c', 'd', 'e'}}, | 69 {3, "cde", 3, {'c', 'd', 'e'}}, |
64 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, | 70 {9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}, |
65 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, | 71 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, |
66 {2, "\303\251", 1, {0x00e9}}, // é | 72 {2, "\303\251", 1, {0x00e9}}, // é |
67 | 73 |
68 // oóöőo | 74 // oóöőo |
69 {8, "o\303\263\303\266\305\221o", 5, {'o', 0x00f3, 0x00f6, 0x151, 'o'}}, | 75 {8, "o\303\263\303\266\305\221o", 5, {'o', 0x00f3, 0x00f6, 0x151, 'o'}}, |
70 {4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP) | 76 {4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP) |
71 }; | 77 }; |
78 #if defined(OS_WIN) | |
79 #pragma warning(pop) | |
80 #endif // OS_WIN | |
72 | 81 |
73 for (size_t index = 0; index < arraysize(kTestData); ++index) { | 82 for (size_t index = 0; index < arraysize(kTestData); ++index) { |
74 SCOPED_TRACE(base::StringPrintf( | 83 SCOPED_TRACE(base::StringPrintf( |
75 "index %zu, input %s", index, kTestData[index].input_string)); | 84 "index %zu, input %s", index, kTestData[index].input_string)); |
76 | 85 |
77 // Make sure that the expected output string with its NUL terminator fits in | 86 // Make sure that the expected output string with its NUL terminator fits in |
78 // the space provided. | 87 // the space provided. |
79 ASSERT_EQ( | 88 ASSERT_EQ( |
80 0, | 89 0, |
81 kTestData[index] | 90 kTestData[index] |
82 .output_string[arraysize(kTestData[index].output_string) - 1]); | 91 .output_string[arraysize(kTestData[index].output_string) - 1]); |
83 | 92 |
84 file_writer.Reset(); | 93 file_writer.Reset(); |
85 crashpad::internal::MinidumpUTF16StringWriter string_writer; | 94 crashpad::internal::MinidumpUTF16StringWriter string_writer; |
86 string_writer.SetUTF8(std::string(kTestData[index].input_string, | 95 string_writer.SetUTF8(std::string(kTestData[index].input_string, |
87 kTestData[index].input_length)); | 96 kTestData[index].input_length)); |
88 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 97 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
89 | 98 |
90 const size_t expected_utf16_units_with_nul = | 99 const size_t expected_utf16_units_with_nul = |
91 kTestData[index].output_length + 1; | 100 kTestData[index].output_length + 1; |
101 MINIDUMP_STRING tmp = {0}; (void)tmp; | |
Mark Mentovai
2015/02/05 14:37:42
ALLOW_UNUSED_LOCAL here and on line 145.
scottmg
2015/02/05 17:09:39
Done.
| |
92 const size_t expected_utf16_bytes = | 102 const size_t expected_utf16_bytes = |
93 expected_utf16_units_with_nul * sizeof(MINIDUMP_STRING::Buffer[0]); | 103 expected_utf16_units_with_nul * sizeof(tmp.Buffer[0]); |
94 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, | 104 ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes, |
95 file_writer.string().size()); | 105 file_writer.string().size()); |
96 | 106 |
97 const MINIDUMP_STRING* minidump_string = | 107 const MINIDUMP_STRING* minidump_string = |
98 MinidumpStringAtRVA(file_writer.string(), 0); | 108 MinidumpStringAtRVA(file_writer.string(), 0); |
99 EXPECT_TRUE(minidump_string); | 109 EXPECT_TRUE(minidump_string); |
100 base::string16 expect_string = base::string16( | 110 base::string16 expect_string = base::string16( |
101 kTestData[index].output_string, kTestData[index].output_length); | 111 kTestData[index].output_string, kTestData[index].output_length); |
102 EXPECT_EQ(expect_string, | 112 EXPECT_EQ(expect_string, |
103 MinidumpStringAtRVAAsString(file_writer.string(), 0)); | 113 MinidumpStringAtRVAAsString(file_writer.string(), 0)); |
(...skipping 21 matching lines...) Expand all Loading... | |
125 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); | 135 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); |
126 | 136 |
127 // The requirements for conversion of invalid UTF-8 input are lax. Make sure | 137 // 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 | 138 // 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 | 139 // 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 | 140 // data written, and make sure that at least one U+FFFD replacement |
131 // character was written. | 141 // character was written. |
132 const MINIDUMP_STRING* minidump_string = | 142 const MINIDUMP_STRING* minidump_string = |
133 MinidumpStringAtRVA(file_writer.string(), 0); | 143 MinidumpStringAtRVA(file_writer.string(), 0); |
134 EXPECT_TRUE(minidump_string); | 144 EXPECT_TRUE(minidump_string); |
145 MINIDUMP_STRING tmp = {0}; (void)tmp; | |
135 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - | 146 EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - |
136 sizeof(MINIDUMP_STRING::Buffer[0]), | 147 sizeof(tmp.Buffer[0]), |
137 minidump_string->Length); | 148 minidump_string->Length); |
138 base::string16 output_string = | 149 base::string16 output_string = |
139 MinidumpStringAtRVAAsString(file_writer.string(), 0); | 150 MinidumpStringAtRVAAsString(file_writer.string(), 0); |
140 EXPECT_FALSE(output_string.empty()); | 151 EXPECT_FALSE(output_string.empty()); |
141 EXPECT_NE(base::string16::npos, output_string.find(0xfffd)); | 152 EXPECT_NE(base::string16::npos, output_string.find(0xfffd)); |
142 } | 153 } |
143 } | 154 } |
144 | 155 |
145 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { | 156 TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { |
146 StringFileWriter file_writer; | 157 StringFileWriter file_writer; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); | 264 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); |
254 } | 265 } |
255 | 266 |
256 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { | 267 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { |
257 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); | 268 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); |
258 } | 269 } |
259 | 270 |
260 } // namespace | 271 } // namespace |
261 } // namespace test | 272 } // namespace test |
262 } // namespace crashpad | 273 } // namespace crashpad |
OLD | NEW |