| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 1004 |
| 1005 // Test dst_size == 0, nothing should be written to |dst| and we should | 1005 // Test dst_size == 0, nothing should be written to |dst| and we should |
| 1006 // have the equivalent of strlen(src). | 1006 // have the equivalent of strlen(src). |
| 1007 { | 1007 { |
| 1008 char dst[2] = {1, 2}; | 1008 char dst[2] = {1, 2}; |
| 1009 wchar_t wdst[2] = {1, 2}; | 1009 wchar_t wdst[2] = {1, 2}; |
| 1010 EXPECT_EQ(7U, base::strlcpy(dst, "abcdefg", 0)); | 1010 EXPECT_EQ(7U, base::strlcpy(dst, "abcdefg", 0)); |
| 1011 EXPECT_EQ(1, dst[0]); | 1011 EXPECT_EQ(1, dst[0]); |
| 1012 EXPECT_EQ(2, dst[1]); | 1012 EXPECT_EQ(2, dst[1]); |
| 1013 EXPECT_EQ(7U, base::wcslcpy(wdst, L"abcdefg", 0)); | 1013 EXPECT_EQ(7U, base::wcslcpy(wdst, L"abcdefg", 0)); |
| 1014 #if defined(WCHAR_T_IS_UNSIGNED) | 1014 EXPECT_EQ(static_cast<wchar_t>(1), wdst[0]); |
| 1015 EXPECT_EQ(1U, wdst[0]); | 1015 EXPECT_EQ(static_cast<wchar_t>(2), wdst[1]); |
| 1016 EXPECT_EQ(2U, wdst[1]); | |
| 1017 #else | |
| 1018 EXPECT_EQ(1, wdst[0]); | |
| 1019 EXPECT_EQ(2, wdst[1]); | |
| 1020 #endif | |
| 1021 } | 1016 } |
| 1022 | 1017 |
| 1023 // Test the case were we _just_ competely fit including the null. | 1018 // Test the case were we _just_ competely fit including the null. |
| 1024 { | 1019 { |
| 1025 char dst[8]; | 1020 char dst[8]; |
| 1026 wchar_t wdst[8]; | 1021 wchar_t wdst[8]; |
| 1027 EXPECT_EQ(7U, base::strlcpy(dst, "abcdefg", arraysize(dst))); | 1022 EXPECT_EQ(7U, base::strlcpy(dst, "abcdefg", arraysize(dst))); |
| 1028 EXPECT_EQ(0, memcmp(dst, "abcdefg", 8)); | 1023 EXPECT_EQ(0, memcmp(dst, "abcdefg", 8)); |
| 1029 EXPECT_EQ(7U, base::wcslcpy(wdst, L"abcdefg", arraysize(wdst))); | 1024 EXPECT_EQ(7U, base::wcslcpy(wdst, L"abcdefg", arraysize(wdst))); |
| 1030 EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8)); | 1025 EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 const std::string live = kLive; | 1184 const std::string live = kLive; |
| 1190 std::string dead = live; | 1185 std::string dead = live; |
| 1191 strncpy(WriteInto(&dead, 5), kDead, 4); | 1186 strncpy(WriteInto(&dead, 5), kDead, 4); |
| 1192 EXPECT_EQ(kDead, dead); | 1187 EXPECT_EQ(kDead, dead); |
| 1193 EXPECT_EQ(4u, dead.size()); | 1188 EXPECT_EQ(4u, dead.size()); |
| 1194 EXPECT_EQ(kLive, live); | 1189 EXPECT_EQ(kLive, live); |
| 1195 EXPECT_EQ(4u, live.size()); | 1190 EXPECT_EQ(4u, live.size()); |
| 1196 } | 1191 } |
| 1197 | 1192 |
| 1198 } // namespace base | 1193 } // namespace base |
| OLD | NEW |