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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // Convert empty strings. | 487 // Convert empty strings. |
488 string16 empty16; | 488 string16 empty16; |
489 std::string empty; | 489 std::string empty; |
490 EXPECT_EQ(empty, UTF16ToASCII(empty16)); | 490 EXPECT_EQ(empty, UTF16ToASCII(empty16)); |
491 EXPECT_EQ(empty16, ASCIIToUTF16(empty)); | 491 EXPECT_EQ(empty16, ASCIIToUTF16(empty)); |
492 | 492 |
493 // Convert strings with an embedded NUL character. | 493 // Convert strings with an embedded NUL character. |
494 const char chars_with_nul[] = "test\0string"; | 494 const char chars_with_nul[] = "test\0string"; |
495 const int length_with_nul = arraysize(chars_with_nul) - 1; | 495 const int length_with_nul = arraysize(chars_with_nul) - 1; |
496 std::string string_with_nul(chars_with_nul, length_with_nul); | 496 std::string string_with_nul(chars_with_nul, length_with_nul); |
497 std::wstring wide_with_nul = ASCIIToWide(string_with_nul); | 497 base::string16 string16_with_nul = ASCIIToUTF16(string_with_nul); |
498 EXPECT_EQ(static_cast<std::wstring::size_type>(length_with_nul), | 498 EXPECT_EQ(static_cast<base::string16::size_type>(length_with_nul), |
499 wide_with_nul.length()); | 499 string16_with_nul.length()); |
500 std::string narrow_with_nul = UTF16ToASCII(WideToUTF16(wide_with_nul)); | 500 std::string narrow_with_nul = UTF16ToASCII(string16_with_nul); |
501 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul), | 501 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul), |
502 narrow_with_nul.length()); | 502 narrow_with_nul.length()); |
503 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul)); | 503 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul)); |
504 } | 504 } |
505 | 505 |
506 TEST(StringUtilTest, ToUpperASCII) { | 506 TEST(StringUtilTest, ToUpperASCII) { |
507 EXPECT_EQ('C', ToUpperASCII('C')); | 507 EXPECT_EQ('C', ToUpperASCII('C')); |
508 EXPECT_EQ('C', ToUpperASCII('c')); | 508 EXPECT_EQ('C', ToUpperASCII('c')); |
509 EXPECT_EQ('2', ToUpperASCII('2')); | 509 EXPECT_EQ('2', ToUpperASCII('2')); |
510 | 510 |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 const std::string live = kLive; | 1259 const std::string live = kLive; |
1260 std::string dead = live; | 1260 std::string dead = live; |
1261 strncpy(WriteInto(&dead, 5), kDead, 4); | 1261 strncpy(WriteInto(&dead, 5), kDead, 4); |
1262 EXPECT_EQ(kDead, dead); | 1262 EXPECT_EQ(kDead, dead); |
1263 EXPECT_EQ(4u, dead.size()); | 1263 EXPECT_EQ(4u, dead.size()); |
1264 EXPECT_EQ(kLive, live); | 1264 EXPECT_EQ(kLive, live); |
1265 EXPECT_EQ(4u, live.size()); | 1265 EXPECT_EQ(4u, live.size()); |
1266 } | 1266 } |
1267 | 1267 |
1268 } // namespace base | 1268 } // namespace base |
OLD | NEW |