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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/text/TextCodecReplacement.cpp ('k') | Source/wtf/text/TextCodecUTF8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "wtf/text/TextCodecReplacement.h"
8
9 #include "wtf/OwnPtr.h"
10 #include "wtf/text/CString.h"
11 #include "wtf/text/TextCodec.h"
12 #include "wtf/text/TextEncoding.h"
13 #include "wtf/text/TextEncodingRegistry.h"
14 #include "wtf/text/WTFString.h"
15 #include <gtest/gtest.h>
16
17 namespace WTF {
18
19 namespace {
20
21 // Just one example, others are listed in the codec implementation.
22 const char* replacementAlias = "iso-2022-kr";
23
24 TEST(TextCodecReplacement, Aliases)
25 {
26 // FIXME: The 'replacement' label itself should not be referenceable by
27 // resources or script - it's a specification convenience - but much of
28 // the wtf/text API asserts that an encoding name is a label for itself.
29 // crbug.com/277037
30
31 EXPECT_TRUE(TextEncoding(replacementAlias).isValid());
32 EXPECT_STREQ("replacement", TextEncoding(replacementAlias).name());
33 }
34
35 TEST(TextCodecReplacement, DecodesToFFFD)
36 {
37 TextEncoding encoding(replacementAlias);
38 OwnPtr<TextCodec> codec(newTextCodec(encoding));
39
40 bool sawError = false;
41 const char testCase[] = "hello world";
42 size_t testCaseSize = sizeof(testCase) - 1;
43
44 const String result = codec->decode(testCase, testCaseSize, DataEOF, false, sawError);
45 EXPECT_TRUE(sawError);
46 ASSERT_EQ(1u, result.length());
47 EXPECT_EQ(0xFFFDU, result[0]);
48 }
49
50 TEST(TextCodecReplacement, EncodesToUTF8)
51 {
52 TextEncoding encoding(replacementAlias);
53 OwnPtr<TextCodec> codec(newTextCodec(encoding));
54
55 // "Kanji" in Chinese characters.
56 const UChar testCase[] = { 0x6F22, 0x5B57 };
57 size_t testCaseSize = WTF_ARRAY_LENGTH(testCase);
58 CString result = codec->encode(testCase, testCaseSize, QuestionMarksForUnenc odables);
59
60 EXPECT_STREQ("\xE6\xBC\xA2\xE5\xAD\x97", result.data());
61 }
62
63 } // namespace
64
65 } // namespace WTF
OLDNEW
« 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