Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1217)

Unified Diff: third_party/WebKit/Source/wtf/text/WTFStringTest.cpp

Issue 1382583002: Add toStdString methods to CString and WTF::String (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add include Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
diff --git a/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp b/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
index 66cf6370575e91a79756585de2b5ad831776f677..9efa2e4641a9ef101f90d76df11db8b1537e6197 100644
--- a/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
+++ b/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
@@ -347,4 +347,23 @@ TEST(StringTest, Lower)
EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data());
}
+TEST(StringTest, ToStdString)
+{
+ // Empty string case.
+ EXPECT_TRUE(String("").toUTF8().empty());
+ EXPECT_EQ(std::string(), String("").toUTF8());
+
+ // ASCII string case.
+ char kAsciiChars[] = "1";
+ EXPECT_EQ(std::string(kAsciiChars), String(kAsciiChars).toUTF8());
+
+ // UTF-8 string case.
+ char kUTF8Chars[] = "r\xC3\xA9sum\xC3\xA9";
+ EXPECT_EQ(std::string(kUTF8Chars), String::fromUTF8(kUTF8Chars).toUTF8());
+
+ // UTF-16 -> UTF-8 string case.
+ UChar kUTF16Chars[] = {0x20AC, 0xD801, 0};
+ EXPECT_EQ(std::string("\xE2\x82\xAC\xED\xA0\x81"), String(kUTF16Chars).toUTF8());
+}
+
} // namespace WTF

Powered by Google App Engine
This is Rietveld 408576698