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

Side by Side Diff: third_party/WebKit/Source/wtf/text/TextCodecReplacementTest.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "wtf/text/TextCodecReplacement.h" 5 #include "wtf/text/TextCodecReplacement.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "wtf/OwnPtr.h" 8 #include "wtf/OwnPtr.h"
9 #include "wtf/text/CString.h" 9 #include "wtf/text/CString.h"
10 #include "wtf/text/TextCodec.h" 10 #include "wtf/text/TextCodec.h"
11 #include "wtf/text/TextEncoding.h" 11 #include "wtf/text/TextEncoding.h"
12 #include "wtf/text/TextEncodingRegistry.h" 12 #include "wtf/text/TextEncodingRegistry.h"
13 #include "wtf/text/WTFString.h" 13 #include "wtf/text/WTFString.h"
14 14
15 namespace WTF { 15 namespace WTF {
16 16
17 namespace { 17 namespace {
18 18
19 // Just one example, others are listed in the codec implementation. 19 // Just one example, others are listed in the codec implementation.
20 const char* replacementAlias = "iso-2022-kr"; 20 const char* replacementAlias = "iso-2022-kr";
21 21
22 TEST(TextCodecReplacement, Aliases) 22 TEST(TextCodecReplacement, Aliases) {
23 { 23 // "replacement" is not a valid alias for itself
24 // "replacement" is not a valid alias for itself 24 EXPECT_FALSE(TextEncoding("replacement").isValid());
25 EXPECT_FALSE(TextEncoding("replacement").isValid()); 25 EXPECT_FALSE(TextEncoding("rEpLaCeMeNt").isValid());
26 EXPECT_FALSE(TextEncoding("rEpLaCeMeNt").isValid());
27 26
28 EXPECT_TRUE(TextEncoding(replacementAlias).isValid()); 27 EXPECT_TRUE(TextEncoding(replacementAlias).isValid());
29 EXPECT_STREQ("replacement", TextEncoding(replacementAlias).name()); 28 EXPECT_STREQ("replacement", TextEncoding(replacementAlias).name());
30 } 29 }
31 30
32 TEST(TextCodecReplacement, DecodesToFFFD) 31 TEST(TextCodecReplacement, DecodesToFFFD) {
33 { 32 TextEncoding encoding(replacementAlias);
34 TextEncoding encoding(replacementAlias); 33 OwnPtr<TextCodec> codec(newTextCodec(encoding));
35 OwnPtr<TextCodec> codec(newTextCodec(encoding));
36 34
37 bool sawError = false; 35 bool sawError = false;
38 const char testCase[] = "hello world"; 36 const char testCase[] = "hello world";
39 size_t testCaseSize = sizeof(testCase) - 1; 37 size_t testCaseSize = sizeof(testCase) - 1;
40 38
41 const String result = codec->decode(testCase, testCaseSize, DataEOF, false, sawError); 39 const String result =
42 EXPECT_TRUE(sawError); 40 codec->decode(testCase, testCaseSize, DataEOF, false, sawError);
43 ASSERT_EQ(1u, result.length()); 41 EXPECT_TRUE(sawError);
44 EXPECT_EQ(0xFFFDU, result[0]); 42 ASSERT_EQ(1u, result.length());
43 EXPECT_EQ(0xFFFDU, result[0]);
45 } 44 }
46 45
47 TEST(TextCodecReplacement, EncodesToUTF8) 46 TEST(TextCodecReplacement, EncodesToUTF8) {
48 { 47 TextEncoding encoding(replacementAlias);
49 TextEncoding encoding(replacementAlias); 48 OwnPtr<TextCodec> codec(newTextCodec(encoding));
50 OwnPtr<TextCodec> codec(newTextCodec(encoding));
51 49
52 // "Kanji" in Chinese characters. 50 // "Kanji" in Chinese characters.
53 const UChar testCase[] = { 0x6F22, 0x5B57 }; 51 const UChar testCase[] = {0x6F22, 0x5B57};
54 size_t testCaseSize = WTF_ARRAY_LENGTH(testCase); 52 size_t testCaseSize = WTF_ARRAY_LENGTH(testCase);
55 CString result = codec->encode(testCase, testCaseSize, QuestionMarksForUnenc odables); 53 CString result =
54 codec->encode(testCase, testCaseSize, QuestionMarksForUnencodables);
56 55
57 EXPECT_STREQ("\xE6\xBC\xA2\xE5\xAD\x97", result.data()); 56 EXPECT_STREQ("\xE6\xBC\xA2\xE5\xAD\x97", result.data());
58 } 57 }
59 58
60 } // namespace 59 } // namespace
61 60
62 } // namespace WTF 61 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodecReplacement.cpp ('k') | third_party/WebKit/Source/wtf/text/TextCodecUTF16.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698