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