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

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

Issue 2771783003: Move wtf_unittests to platform/wtf/. (Closed)
Patch Set: Rebase. Created 3 years, 8 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
(Empty)
1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "wtf/text/StringImpl.h"
27
28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "wtf/text/WTFString.h"
30
31 namespace WTF {
32
33 TEST(StringImplTest, Create8Bit) {
34 RefPtr<StringImpl> testStringImpl = StringImpl::create("1224");
35 EXPECT_TRUE(testStringImpl->is8Bit());
36 }
37
38 TEST(StringImplTest, Latin1CaseFoldTable) {
39 LChar symbol = 0xff;
40 while (symbol--) {
41 EXPECT_EQ(Unicode::foldCase(symbol),
42 StringImpl::latin1CaseFoldTable[symbol]);
43 }
44 }
45
46 TEST(StringImplTest, LowerASCII) {
47 RefPtr<StringImpl> testStringImpl = StringImpl::create("link");
48 EXPECT_TRUE(testStringImpl->is8Bit());
49 EXPECT_TRUE(StringImpl::create("a\xE1")->is8Bit());
50
51 EXPECT_TRUE(equal(testStringImpl.get(),
52 StringImpl::create("link")->lowerASCII().get()));
53 EXPECT_TRUE(equal(testStringImpl.get(),
54 StringImpl::create("LINK")->lowerASCII().get()));
55 EXPECT_TRUE(equal(testStringImpl.get(),
56 StringImpl::create("lInk")->lowerASCII().get()));
57
58 EXPECT_TRUE(equal(StringImpl::create("LINK")->lower().get(),
59 StringImpl::create("LINK")->lowerASCII().get()));
60 EXPECT_TRUE(equal(StringImpl::create("lInk")->lower().get(),
61 StringImpl::create("lInk")->lowerASCII().get()));
62
63 EXPECT_TRUE(equal(StringImpl::create("a\xE1").get(),
64 StringImpl::create("A\xE1")->lowerASCII().get()));
65 EXPECT_TRUE(equal(StringImpl::create("a\xC1").get(),
66 StringImpl::create("A\xC1")->lowerASCII().get()));
67
68 EXPECT_FALSE(equal(StringImpl::create("a\xE1").get(),
69 StringImpl::create("a\xC1")->lowerASCII().get()));
70 EXPECT_FALSE(equal(StringImpl::create("A\xE1").get(),
71 StringImpl::create("A\xC1")->lowerASCII().get()));
72
73 static const UChar test[5] = {0x006c, 0x0069, 0x006e, 0x006b, 0}; // link
74 static const UChar testCapitalized[5] = {0x004c, 0x0049, 0x004e, 0x004b,
75 0}; // LINK
76
77 RefPtr<StringImpl> testStringImpl16 = StringImpl::create(test, 4);
78 EXPECT_FALSE(testStringImpl16->is8Bit());
79
80 EXPECT_TRUE(equal(testStringImpl16.get(),
81 StringImpl::create(test, 4)->lowerASCII().get()));
82 EXPECT_TRUE(
83 equal(testStringImpl16.get(),
84 StringImpl::create(testCapitalized, 4)->lowerASCII().get()));
85
86 static const UChar testWithNonASCII[3] = {0x0061, 0x00e1, 0}; // a\xE1
87 static const UChar testWithNonASCIIComparison[3] = {0x0061, 0x00c1,
88 0}; // a\xC1
89 static const UChar testWithNonASCIICapitalized[3] = {0x0041, 0x00e1,
90 0}; // A\xE1
91
92 // Make sure we support RefPtr<const StringImpl>.
93 RefPtr<const StringImpl> constRef = testStringImpl->isolatedCopy();
94 DCHECK(constRef->hasOneRef());
95 EXPECT_TRUE(equal(
96 StringImpl::create(testWithNonASCII, 2).get(),
97 StringImpl::create(testWithNonASCIICapitalized, 2)->lowerASCII().get()));
98 EXPECT_FALSE(equal(
99 StringImpl::create(testWithNonASCII, 2).get(),
100 StringImpl::create(testWithNonASCIIComparison, 2)->lowerASCII().get()));
101 }
102
103 TEST(StringImplTest, UpperASCII) {
104 RefPtr<StringImpl> testStringImpl = StringImpl::create("LINK");
105 EXPECT_TRUE(testStringImpl->is8Bit());
106 EXPECT_TRUE(StringImpl::create("a\xE1")->is8Bit());
107
108 EXPECT_TRUE(equal(testStringImpl.get(),
109 StringImpl::create("link")->upperASCII().get()));
110 EXPECT_TRUE(equal(testStringImpl.get(),
111 StringImpl::create("LINK")->upperASCII().get()));
112 EXPECT_TRUE(equal(testStringImpl.get(),
113 StringImpl::create("lInk")->upperASCII().get()));
114
115 EXPECT_TRUE(equal(StringImpl::create("LINK")->upper().get(),
116 StringImpl::create("LINK")->upperASCII().get()));
117 EXPECT_TRUE(equal(StringImpl::create("lInk")->upper().get(),
118 StringImpl::create("lInk")->upperASCII().get()));
119
120 EXPECT_TRUE(equal(StringImpl::create("A\xE1").get(),
121 StringImpl::create("a\xE1")->upperASCII().get()));
122 EXPECT_TRUE(equal(StringImpl::create("A\xC1").get(),
123 StringImpl::create("a\xC1")->upperASCII().get()));
124
125 EXPECT_FALSE(equal(StringImpl::create("A\xE1").get(),
126 StringImpl::create("a\xC1")->upperASCII().get()));
127 EXPECT_FALSE(equal(StringImpl::create("A\xE1").get(),
128 StringImpl::create("A\xC1")->upperASCII().get()));
129
130 static const UChar test[5] = {0x006c, 0x0069, 0x006e, 0x006b, 0}; // link
131 static const UChar testCapitalized[5] = {0x004c, 0x0049, 0x004e, 0x004b,
132 0}; // LINK
133
134 RefPtr<StringImpl> testStringImpl16 = StringImpl::create(testCapitalized, 4);
135 EXPECT_FALSE(testStringImpl16->is8Bit());
136
137 EXPECT_TRUE(equal(testStringImpl16.get(),
138 StringImpl::create(test, 4)->upperASCII().get()));
139 EXPECT_TRUE(
140 equal(testStringImpl16.get(),
141 StringImpl::create(testCapitalized, 4)->upperASCII().get()));
142
143 static const UChar testWithNonASCII[3] = {0x0061, 0x00e1, 0}; // a\xE1
144 static const UChar testWithNonASCIIComparison[3] = {0x0061, 0x00c1,
145 0}; // a\xC1
146 static const UChar testWithNonASCIICapitalized[3] = {0x0041, 0x00e1,
147 0}; // A\xE1
148
149 // Make sure we support RefPtr<const StringImpl>.
150 RefPtr<const StringImpl> constRef = testStringImpl->isolatedCopy();
151 DCHECK(constRef->hasOneRef());
152 EXPECT_TRUE(
153 equal(StringImpl::create(testWithNonASCIICapitalized, 2).get(),
154 StringImpl::create(testWithNonASCII, 2)->upperASCII().get()));
155 EXPECT_FALSE(equal(
156 StringImpl::create(testWithNonASCIICapitalized, 2).get(),
157 StringImpl::create(testWithNonASCIIComparison, 2)->upperASCII().get()));
158 }
159
160 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringBuilderTest.cpp ('k') | third_party/WebKit/Source/wtf/text/StringOperatorsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698