Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: minidump/minidump_string_writer_test.cc

Issue 900323003: %zu to PRIuS in minidump (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@land-crash-report-db-win
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « minidump/minidump_rva_list_writer_test.cc ('k') | minidump/minidump_thread_writer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler_specific.h"
25 #include "base/format_macros.h"
25 #include "base/strings/string16.h" 26 #include "base/strings/string16.h"
26 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
28 #include "gtest/gtest.h" 29 #include "gtest/gtest.h"
29 #include "minidump/test/minidump_rva_list_test_util.h" 30 #include "minidump/test/minidump_rva_list_test_util.h"
30 #include "minidump/test/minidump_string_writer_test_util.h" 31 #include "minidump/test/minidump_string_writer_test_util.h"
31 #include "minidump/test/minidump_writable_test_util.h" 32 #include "minidump/test/minidump_writable_test_util.h"
32 #include "util/file/string_file_writer.h" 33 #include "util/file/string_file_writer.h"
33 34
34 namespace crashpad { 35 namespace crashpad {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}}, 67 {7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}},
67 {2, "\303\251", 1, {0x00e9}}, // é 68 {2, "\303\251", 1, {0x00e9}}, // é
68 69
69 // oóöőo 70 // oóöőo
70 {8, "o\303\263\303\266\305\221o", 5, {'o', 0x00f3, 0x00f6, 0x151, 'o'}}, 71 {8, "o\303\263\303\266\305\221o", 5, {'o', 0x00f3, 0x00f6, 0x151, 'o'}},
71 {4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP) 72 {4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP)
72 }; 73 };
73 74
74 for (size_t index = 0; index < arraysize(kTestData); ++index) { 75 for (size_t index = 0; index < arraysize(kTestData); ++index) {
75 SCOPED_TRACE(base::StringPrintf( 76 SCOPED_TRACE(base::StringPrintf(
76 "index %zu, input %s", index, kTestData[index].input_string)); 77 "index %" PRIuS ", input %s", index, kTestData[index].input_string));
77 78
78 // Make sure that the expected output string with its NUL terminator fits in 79 // Make sure that the expected output string with its NUL terminator fits in
79 // the space provided. 80 // the space provided.
80 ASSERT_EQ( 81 ASSERT_EQ(
81 0, 82 0,
82 kTestData[index] 83 kTestData[index]
83 .output_string[arraysize(kTestData[index].output_string) - 1]); 84 .output_string[arraysize(kTestData[index].output_string) - 1]);
84 85
85 file_writer.Reset(); 86 file_writer.Reset();
86 crashpad::internal::MinidumpUTF16StringWriter string_writer; 87 crashpad::internal::MinidumpUTF16StringWriter string_writer;
(...skipping 26 matching lines...) Expand all
113 const char* kTestData[] = { 114 const char* kTestData[] = {
114 "\200", // continuation byte 115 "\200", // continuation byte
115 "\300", // start byte followed by EOF 116 "\300", // start byte followed by EOF
116 "\310\177", // start byte without continuation 117 "\310\177", // start byte without continuation
117 "\340\200", // EOF in middle of 3-byte sequence 118 "\340\200", // EOF in middle of 3-byte sequence
118 "\340\200\115", // invalid 3-byte sequence 119 "\340\200\115", // invalid 3-byte sequence
119 "\303\0\251", // NUL in middle of valid sequence 120 "\303\0\251", // NUL in middle of valid sequence
120 }; 121 };
121 122
122 for (size_t index = 0; index < arraysize(kTestData); ++index) { 123 for (size_t index = 0; index < arraysize(kTestData); ++index) {
123 SCOPED_TRACE( 124 SCOPED_TRACE(base::StringPrintf(
124 base::StringPrintf("index %zu, input %s", index, kTestData[index])); 125 "index %" PRIuS ", input %s", index, kTestData[index]));
125 file_writer.Reset(); 126 file_writer.Reset();
126 crashpad::internal::MinidumpUTF16StringWriter string_writer; 127 crashpad::internal::MinidumpUTF16StringWriter string_writer;
127 string_writer.SetUTF8(kTestData[index]); 128 string_writer.SetUTF8(kTestData[index]);
128 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); 129 EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
129 130
130 // The requirements for conversion of invalid UTF-8 input are lax. Make sure 131 // The requirements for conversion of invalid UTF-8 input are lax. Make sure
131 // that at least enough data was written for a string that has one unit and 132 // that at least enough data was written for a string that has one unit and
132 // a NUL terminator, make sure that the length field matches the length of 133 // a NUL terminator, make sure that the length field matches the length of
133 // data written, and make sure that at least one U+FFFD replacement 134 // data written, and make sure that at least one U+FFFD replacement
134 // character was written. 135 // character was written.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 {7, "ret\nurn"}, 177 {7, "ret\nurn"},
177 {2, "\303\251"}, // é 178 {2, "\303\251"}, // é
178 179
179 // oóöőo 180 // oóöőo
180 {8, "o\303\263\303\266\305\221o"}, 181 {8, "o\303\263\303\266\305\221o"},
181 {4, "\360\220\204\202"}, // 𐄂 (non-BMP) 182 {4, "\360\220\204\202"}, // 𐄂 (non-BMP)
182 }; 183 };
183 184
184 for (size_t index = 0; index < arraysize(kTestData); ++index) { 185 for (size_t index = 0; index < arraysize(kTestData); ++index) {
185 SCOPED_TRACE(base::StringPrintf( 186 SCOPED_TRACE(base::StringPrintf(
186 "index %zu, input %s", index, kTestData[index].string)); 187 "index %" PRIuS ", input %s", index, kTestData[index].string));
187 188
188 file_writer.Reset(); 189 file_writer.Reset();
189 crashpad::internal::MinidumpUTF8StringWriter string_writer; 190 crashpad::internal::MinidumpUTF8StringWriter string_writer;
190 std::string test_string(kTestData[index].string, kTestData[index].length); 191 std::string test_string(kTestData[index].string, kTestData[index].length);
191 string_writer.SetUTF8(test_string); 192 string_writer.SetUTF8(test_string);
192 EXPECT_EQ(test_string, string_writer.UTF8()); 193 EXPECT_EQ(test_string, string_writer.UTF8());
193 EXPECT_TRUE(string_writer.WriteEverything(&file_writer)); 194 EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
194 195
195 const size_t expected_utf8_bytes_with_nul = kTestData[index].length + 1; 196 const size_t expected_utf8_bytes_with_nul = kTestData[index].length + 1;
196 ASSERT_EQ(sizeof(MinidumpUTF8String) + expected_utf8_bytes_with_nul, 197 ASSERT_EQ(sizeof(MinidumpUTF8String) + expected_utf8_bytes_with_nul,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>(); 259 MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>();
259 } 260 }
260 261
261 TEST(MinidumpStringWriter, MinidumpUTF8StringList) { 262 TEST(MinidumpStringWriter, MinidumpUTF8StringList) {
262 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>(); 263 MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>();
263 } 264 }
264 265
265 } // namespace 266 } // namespace
266 } // namespace test 267 } // namespace test
267 } // namespace crashpad 268 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_rva_list_writer_test.cc ('k') | minidump/minidump_thread_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698