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 "util/stdlib/strlcpy.h" | 15 #include "util/stdlib/strlcpy.h" |
16 | 16 |
17 #include <string.h> | 17 #include <string.h> |
18 | 18 |
19 #include <algorithm> | 19 #include <algorithm> |
20 | 20 |
21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
| 22 #include "base/format_macros.h" |
22 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "gtest/gtest.h" | 25 #include "gtest/gtest.h" |
25 | 26 |
26 namespace crashpad { | 27 namespace crashpad { |
27 namespace test { | 28 namespace test { |
28 namespace { | 29 namespace { |
29 | 30 |
30 TEST(strlcpy, c16lcpy) { | 31 TEST(strlcpy, c16lcpy) { |
31 // Use a destination buffer that’s larger than the length passed to c16lcpy. | 32 // Use a destination buffer that’s larger than the length passed to c16lcpy. |
32 // The unused portion is a guard area that must not be written to. | 33 // The unused portion is a guard area that must not be written to. |
33 struct TestBuffer { | 34 struct TestBuffer { |
34 base::char16 lead_guard[64]; | 35 base::char16 lead_guard[64]; |
35 base::char16 data[128]; | 36 base::char16 data[128]; |
36 base::char16 trail_guard[64]; | 37 base::char16 trail_guard[64]; |
37 }; | 38 }; |
38 TestBuffer expected_untouched; | 39 TestBuffer expected_untouched; |
39 memset(&expected_untouched, 0xa5, sizeof(expected_untouched)); | 40 memset(&expected_untouched, 0xa5, sizeof(expected_untouched)); |
40 | 41 |
41 // Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and | 42 // Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and |
42 // nonzero low and high bytes. | 43 // nonzero low and high bytes. |
43 const base::char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; | 44 const base::char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; |
44 | 45 |
45 for (size_t index = 0; index < arraysize(test_characters); ++index) { | 46 for (size_t index = 0; index < arraysize(test_characters); ++index) { |
46 base::char16 test_character = test_characters[index]; | 47 base::char16 test_character = test_characters[index]; |
47 SCOPED_TRACE(base::StringPrintf( | 48 SCOPED_TRACE(base::StringPrintf( |
48 "character index %zu, character 0x%x", index, test_character)); | 49 "character index %" PRIuS ", character 0x%x", index, test_character)); |
49 for (size_t length = 0; length < 256; ++length) { | 50 for (size_t length = 0; length < 256; ++length) { |
50 SCOPED_TRACE(base::StringPrintf("index %zu", length)); | 51 SCOPED_TRACE( |
| 52 base::StringPrintf("index %" PRIuS, length)); |
51 base::string16 test_string(length, test_character); | 53 base::string16 test_string(length, test_character); |
52 | 54 |
53 TestBuffer destination; | 55 TestBuffer destination; |
54 memset(&destination, 0xa5, sizeof(destination)); | 56 memset(&destination, 0xa5, sizeof(destination)); |
55 | 57 |
56 EXPECT_EQ(length, | 58 EXPECT_EQ(length, |
57 c16lcpy(destination.data, | 59 c16lcpy(destination.data, |
58 test_string.c_str(), | 60 test_string.c_str(), |
59 arraysize(destination.data))); | 61 arraysize(destination.data))); |
60 | 62 |
(...skipping 23 matching lines...) Expand all Loading... |
84 EXPECT_TRUE(base::c16memcmp(expected_untouched.trail_guard, | 86 EXPECT_TRUE(base::c16memcmp(expected_untouched.trail_guard, |
85 destination.trail_guard, | 87 destination.trail_guard, |
86 arraysize(destination.trail_guard)) == 0); | 88 arraysize(destination.trail_guard)) == 0); |
87 } | 89 } |
88 } | 90 } |
89 } | 91 } |
90 | 92 |
91 } // namespace | 93 } // namespace |
92 } // namespace test | 94 } // namespace test |
93 } // namespace crashpad | 95 } // namespace crashpad |
OLD | NEW |