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

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

Issue 2478653002: Don't initialize ICU replacement character for UTF-32 encodings (Closed)
Patch Set: Don't use zero-length array initializer, to keep MSVC happy Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextEncoding.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/TextEncodingTest.cpp
diff --git a/third_party/WebKit/Source/wtf/text/TextEncodingTest.cpp b/third_party/WebKit/Source/wtf/text/TextEncodingTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9191eafb60a44f9cd6f3213d8279a2079bcf4046
--- /dev/null
+++ b/third_party/WebKit/Source/wtf/text/TextEncodingTest.cpp
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "wtf/text/TextEncoding.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace WTF {
+
+namespace {
+
+TEST(TextEncoding, NonByteBased) {
+ EXPECT_FALSE(TextEncoding("utf-8").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-16").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-16le").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-16be").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-32").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-32le").isNonByteBasedEncoding());
+ EXPECT_TRUE(TextEncoding("utf-32be").isNonByteBasedEncoding());
+ EXPECT_FALSE(TextEncoding("windows-1252").isNonByteBasedEncoding());
+ EXPECT_FALSE(TextEncoding("gbk").isNonByteBasedEncoding());
+ EXPECT_FALSE(TextEncoding("utf-7").isNonByteBasedEncoding());
+}
+
+TEST(TextEncoding, ClosestByteBased) {
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-8").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16le").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16be").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32le").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32be").closestByteBasedEquivalent().name());
+ EXPECT_STREQ(
+ "windows-1252",
+ TextEncoding("windows-1252").closestByteBasedEquivalent().name());
+ EXPECT_STREQ("GBK", TextEncoding("gbk").closestByteBasedEquivalent().name());
+ EXPECT_EQ(nullptr, TextEncoding("utf-7").closestByteBasedEquivalent().name());
+}
+
+TEST(TextEncoding, EncodingForFormSubmission) {
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-8").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16le").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-16be").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32le").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-32be").encodingForFormSubmission().name());
+ EXPECT_STREQ("windows-1252",
+ TextEncoding("windows-1252").encodingForFormSubmission().name());
+ EXPECT_STREQ("GBK", TextEncoding("gbk").encodingForFormSubmission().name());
+ EXPECT_STREQ("UTF-8",
+ TextEncoding("utf-7").encodingForFormSubmission().name());
+}
+}
+}
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextEncoding.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698