| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 }; | 393 }; |
| 394 | 394 |
| 395 static const wchar_t* const wchar_cases[] = { | 395 static const wchar_t* const wchar_cases[] = { |
| 396 L"Google Video", | 396 L"Google Video", |
| 397 L"Hello, world\n", | 397 L"Hello, world\n", |
| 398 L"0123ABCDwxyz \a\b\t\r\n!+,.~" | 398 L"0123ABCDwxyz \a\b\t\r\n!+,.~" |
| 399 }; | 399 }; |
| 400 | 400 |
| 401 for (size_t i = 0; i < arraysize(char_cases); ++i) { | 401 for (size_t i = 0; i < arraysize(char_cases); ++i) { |
| 402 EXPECT_TRUE(IsStringASCII(char_cases[i])); | 402 EXPECT_TRUE(IsStringASCII(char_cases[i])); |
| 403 std::wstring wide = ASCIIToWide(char_cases[i]); | 403 string16 utf16 = ASCIIToUTF16(char_cases[i]); |
| 404 EXPECT_EQ(wchar_cases[i], wide); | 404 EXPECT_EQ(WideToUTF16(wchar_cases[i]), utf16); |
| 405 | 405 |
| 406 std::string ascii = WideToASCII(wchar_cases[i]); | 406 std::string ascii = UTF16ToASCII(WideToUTF16(wchar_cases[i])); |
| 407 EXPECT_EQ(char_cases[i], ascii); | 407 EXPECT_EQ(char_cases[i], ascii); |
| 408 } | 408 } |
| 409 | 409 |
| 410 EXPECT_FALSE(IsStringASCII("Google \x80Video")); | 410 EXPECT_FALSE(IsStringASCII("Google \x80Video")); |
| 411 | 411 |
| 412 // Convert empty strings. | 412 // Convert empty strings. |
| 413 std::wstring wempty; | 413 string16 empty16; |
| 414 std::string empty; | 414 std::string empty; |
| 415 EXPECT_EQ(empty, WideToASCII(wempty)); | 415 EXPECT_EQ(empty, UTF16ToASCII(empty16)); |
| 416 EXPECT_EQ(wempty, ASCIIToWide(empty)); | 416 EXPECT_EQ(empty16, ASCIIToUTF16(empty)); |
| 417 | 417 |
| 418 // Convert strings with an embedded NUL character. | 418 // Convert strings with an embedded NUL character. |
| 419 const char chars_with_nul[] = "test\0string"; | 419 const char chars_with_nul[] = "test\0string"; |
| 420 const int length_with_nul = arraysize(chars_with_nul) - 1; | 420 const int length_with_nul = arraysize(chars_with_nul) - 1; |
| 421 std::string string_with_nul(chars_with_nul, length_with_nul); | 421 std::string string_with_nul(chars_with_nul, length_with_nul); |
| 422 std::wstring wide_with_nul = ASCIIToWide(string_with_nul); | 422 std::wstring wide_with_nul = ASCIIToWide(string_with_nul); |
| 423 EXPECT_EQ(static_cast<std::wstring::size_type>(length_with_nul), | 423 EXPECT_EQ(static_cast<std::wstring::size_type>(length_with_nul), |
| 424 wide_with_nul.length()); | 424 wide_with_nul.length()); |
| 425 std::string narrow_with_nul = WideToASCII(wide_with_nul); | 425 std::string narrow_with_nul = UTF16ToASCII(WideToUTF16(wide_with_nul)); |
| 426 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul), | 426 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul), |
| 427 narrow_with_nul.length()); | 427 narrow_with_nul.length()); |
| 428 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul)); | 428 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul)); |
| 429 } | 429 } |
| 430 | 430 |
| 431 TEST(StringUtilTest, ToUpperASCII) { | 431 TEST(StringUtilTest, ToUpperASCII) { |
| 432 EXPECT_EQ('C', ToUpperASCII('C')); | 432 EXPECT_EQ('C', ToUpperASCII('C')); |
| 433 EXPECT_EQ('C', ToUpperASCII('c')); | 433 EXPECT_EQ('C', ToUpperASCII('c')); |
| 434 EXPECT_EQ('2', ToUpperASCII('2')); | 434 EXPECT_EQ('2', ToUpperASCII('2')); |
| 435 | 435 |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 const std::string live = kLive; | 1189 const std::string live = kLive; |
| 1190 std::string dead = live; | 1190 std::string dead = live; |
| 1191 strncpy(WriteInto(&dead, 5), kDead, 4); | 1191 strncpy(WriteInto(&dead, 5), kDead, 4); |
| 1192 EXPECT_EQ(kDead, dead); | 1192 EXPECT_EQ(kDead, dead); |
| 1193 EXPECT_EQ(4u, dead.size()); | 1193 EXPECT_EQ(4u, dead.size()); |
| 1194 EXPECT_EQ(kLive, live); | 1194 EXPECT_EQ(kLive, live); |
| 1195 EXPECT_EQ(4u, live.size()); | 1195 EXPECT_EQ(4u, live.size()); |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 } // namespace base | 1198 } // namespace base |
| OLD | NEW |