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

Unified Diff: Source/wtf/text/TextCodecReplacementTest.cpp

Issue 265973003: Implement "replacement" text encoding. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Request rebaseline the temporary chaset-replacement output Created 6 years, 7 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
« no previous file with comments | « Source/wtf/text/TextCodecReplacement.cpp ('k') | Source/wtf/text/TextCodecUTF8.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/TextCodecReplacementTest.cpp
diff --git a/Source/wtf/text/TextCodecReplacementTest.cpp b/Source/wtf/text/TextCodecReplacementTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b95eec8b75249af91136ecaf821e74a59eb3db60
--- /dev/null
+++ b/Source/wtf/text/TextCodecReplacementTest.cpp
@@ -0,0 +1,65 @@
+// Copyright 2014 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 "config.h"
+
+#include "wtf/text/TextCodecReplacement.h"
+
+#include "wtf/OwnPtr.h"
+#include "wtf/text/CString.h"
+#include "wtf/text/TextCodec.h"
+#include "wtf/text/TextEncoding.h"
+#include "wtf/text/TextEncodingRegistry.h"
+#include "wtf/text/WTFString.h"
+#include <gtest/gtest.h>
+
+namespace WTF {
+
+namespace {
+
+// Just one example, others are listed in the codec implementation.
+const char* replacementAlias = "iso-2022-kr";
+
+TEST(TextCodecReplacement, Aliases)
+{
+ // FIXME: The 'replacement' label itself should not be referenceable by
+ // resources or script - it's a specification convenience - but much of
+ // the wtf/text API asserts that an encoding name is a label for itself.
+ // crbug.com/277037
+
+ EXPECT_TRUE(TextEncoding(replacementAlias).isValid());
+ EXPECT_STREQ("replacement", TextEncoding(replacementAlias).name());
+}
+
+TEST(TextCodecReplacement, DecodesToFFFD)
+{
+ TextEncoding encoding(replacementAlias);
+ OwnPtr<TextCodec> codec(newTextCodec(encoding));
+
+ bool sawError = false;
+ const char testCase[] = "hello world";
+ size_t testCaseSize = sizeof(testCase) - 1;
+
+ const String result = codec->decode(testCase, testCaseSize, DataEOF, false, sawError);
+ EXPECT_TRUE(sawError);
+ ASSERT_EQ(1u, result.length());
+ EXPECT_EQ(0xFFFDU, result[0]);
+}
+
+TEST(TextCodecReplacement, EncodesToUTF8)
+{
+ TextEncoding encoding(replacementAlias);
+ OwnPtr<TextCodec> codec(newTextCodec(encoding));
+
+ // "Kanji" in Chinese characters.
+ const UChar testCase[] = { 0x6F22, 0x5B57 };
+ size_t testCaseSize = WTF_ARRAY_LENGTH(testCase);
+ CString result = codec->encode(testCase, testCaseSize, QuestionMarksForUnencodables);
+
+ EXPECT_STREQ("\xE6\xBC\xA2\xE5\xAD\x97", result.data());
+}
+
+} // namespace
+
+} // namespace WTF
« no previous file with comments | « Source/wtf/text/TextCodecReplacement.cpp ('k') | Source/wtf/text/TextCodecUTF8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698