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

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

Issue 2315853002: Massively simplify WTF's StringConcatenate (Closed)
Patch Set: missing inlines. Created 4 years, 3 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) 2011 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 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() (++wtfStringCopyCount)
27
28 static int wtfStringCopyCount;
29
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "wtf/text/WTFString.h"
32
33 namespace WTF {
34
35 #define EXPECT_N_WTF_STRING_COPIES(count, expr) \
36 do { \
37 wtfStringCopyCount = 0; \
38 String __testString = expr; \
39 (void)__testString; \
40 EXPECT_EQ(count, wtfStringCopyCount) << #expr; \
41 } while (false)
42
43 TEST(StringOperatorsTest, DISABLED_StringOperators)
44 {
45 String string("String");
46 AtomicString atomicString("AtomicString");
47 const char* literal = "ASCIILiteral";
48
49 EXPECT_EQ(0, wtfStringCopyCount);
50
51 EXPECT_N_WTF_STRING_COPIES(2, string + string);
52 EXPECT_N_WTF_STRING_COPIES(2, string + atomicString);
53 EXPECT_N_WTF_STRING_COPIES(2, atomicString + string);
54 EXPECT_N_WTF_STRING_COPIES(2, atomicString + atomicString);
55
56 EXPECT_N_WTF_STRING_COPIES(1, "C string" + string);
57 EXPECT_N_WTF_STRING_COPIES(1, string + "C string");
58 EXPECT_N_WTF_STRING_COPIES(1, "C string" + atomicString);
59 EXPECT_N_WTF_STRING_COPIES(1, atomicString + "C string");
60
61 EXPECT_N_WTF_STRING_COPIES(1, literal + string);
62 EXPECT_N_WTF_STRING_COPIES(1, string + literal);
63 EXPECT_N_WTF_STRING_COPIES(1, literal + atomicString);
64 EXPECT_N_WTF_STRING_COPIES(1, atomicString + literal);
65
66 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + "C string" + string);
67 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + "C string" + string));
68 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + ("C string" + string)) ;
69 EXPECT_N_WTF_STRING_COPIES(2, string + "C string" + string + "C string");
70 EXPECT_N_WTF_STRING_COPIES(2, string + ("C string" + string + "C string"));
71 EXPECT_N_WTF_STRING_COPIES(2, (string + "C string") + (string + "C string")) ;
72
73 EXPECT_N_WTF_STRING_COPIES(2, literal + string + literal + string);
74 EXPECT_N_WTF_STRING_COPIES(2, literal + (string + literal + string));
75 EXPECT_N_WTF_STRING_COPIES(2, (literal + string) + (literal + string));
76 EXPECT_N_WTF_STRING_COPIES(2, string + literal + string + literal);
77 EXPECT_N_WTF_STRING_COPIES(2, string + (literal + string + literal));
78 EXPECT_N_WTF_STRING_COPIES(2, (string + literal) + (string + literal));
79
80 EXPECT_N_WTF_STRING_COPIES(2, literal + string + "C string" + string);
81 EXPECT_N_WTF_STRING_COPIES(2, literal + (string + "C string" + string));
82 EXPECT_N_WTF_STRING_COPIES(2, (literal + string) + ("C string" + string));
83 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + literal + string);
84 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + literal + string));
85 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + (literal + string));
86
87 EXPECT_N_WTF_STRING_COPIES(2, literal + atomicString + "C string" + atomicSt ring);
88 EXPECT_N_WTF_STRING_COPIES(2, literal + (atomicString + "C string" + atomicS tring));
89 EXPECT_N_WTF_STRING_COPIES(2, (literal + atomicString) + ("C string" + atomi cString));
90 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + literal + atomicSt ring);
91 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + literal + atomicS tring));
92 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + (literal + atomi cString));
93
94 EXPECT_N_WTF_STRING_COPIES(2, literal + atomicString + "C string" + string);
95 EXPECT_N_WTF_STRING_COPIES(2, literal + (atomicString + "C string" + string) );
96 EXPECT_N_WTF_STRING_COPIES(2, (literal + atomicString) + ("C string" + strin g));
97 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + literal + string);
98 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + literal + string) );
99 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + (literal + strin g));
100
101 EXPECT_N_WTF_STRING_COPIES(2, literal + string + "C string" + atomicString);
102 EXPECT_N_WTF_STRING_COPIES(2, literal + (string + "C string" + atomicString) );
103 EXPECT_N_WTF_STRING_COPIES(2, (literal + string) + ("C string" + atomicStrin g));
104 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + literal + atomicString);
105 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + literal + atomicString) );
106 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + (literal + atomicStrin g));
107
108 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + "C string" + atomi cString);
109 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + "C string" + atom icString));
110 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + ("C string" + at omicString));
111 EXPECT_N_WTF_STRING_COPIES(2, atomicString + "C string" + atomicString + "C string");
112 EXPECT_N_WTF_STRING_COPIES(2, atomicString + ("C string" + atomicString + "C string"));
113 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + "C string") + (atomicString + "C string"));
114
115 EXPECT_N_WTF_STRING_COPIES(2, literal + atomicString + literal + atomicStrin g);
116 EXPECT_N_WTF_STRING_COPIES(2, literal + (atomicString + literal + atomicStri ng));
117 EXPECT_N_WTF_STRING_COPIES(2, (literal + atomicString) + (literal + atomicSt ring));
118 EXPECT_N_WTF_STRING_COPIES(2, atomicString + literal + atomicString + litera l);
119 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (literal + atomicString + liter al));
120 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + literal) + (atomicString + lit eral));
121
122 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + "C string" + atomicStrin g);
123 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + "C string" + atomicStri ng));
124 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + ("C string" + atomicSt ring));
125 EXPECT_N_WTF_STRING_COPIES(2, string + "C string" + atomicString + "C string ");
126 EXPECT_N_WTF_STRING_COPIES(2, string + ("C string" + atomicString + "C strin g"));
127 EXPECT_N_WTF_STRING_COPIES(2, (string + "C string") + (atomicString + "C str ing"));
128
129 EXPECT_N_WTF_STRING_COPIES(2, literal + string + literal + atomicString);
130 EXPECT_N_WTF_STRING_COPIES(2, literal + (string + literal + atomicString));
131 EXPECT_N_WTF_STRING_COPIES(2, (literal + string) + (literal + atomicString)) ;
132 EXPECT_N_WTF_STRING_COPIES(2, string + literal + atomicString + literal);
133 EXPECT_N_WTF_STRING_COPIES(2, string + (literal + atomicString + literal));
134 EXPECT_N_WTF_STRING_COPIES(2, (string + literal) + (atomicString + literal)) ;
135
136 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + "C string" + strin g);
137 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + "C string" + stri ng));
138 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + ("C string" + st ring));
139 EXPECT_N_WTF_STRING_COPIES(2, atomicString + "C string" + string + "C string ");
140 EXPECT_N_WTF_STRING_COPIES(2, atomicString + ("C string" + string + "C strin g"));
141 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + "C string") + (string + "C str ing"));
142
143 EXPECT_N_WTF_STRING_COPIES(2, literal + atomicString + literal + string);
144 EXPECT_N_WTF_STRING_COPIES(2, literal + (atomicString + literal + string));
145 EXPECT_N_WTF_STRING_COPIES(2, (literal + atomicString) + (literal + string)) ;
146 EXPECT_N_WTF_STRING_COPIES(2, atomicString + literal + string + literal);
147 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (literal + string + literal));
148 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + literal) + (string + literal)) ;
149
150 #if COMPILER(MSVC)
151 EXPECT_N_WTF_STRING_COPIES(1, L"wide string" + string);
152 EXPECT_N_WTF_STRING_COPIES(1, string + L"wide string");
153 EXPECT_N_WTF_STRING_COPIES(1, L"wide string" + atomicString);
154 EXPECT_N_WTF_STRING_COPIES(1, atomicString + L"wide string");
155
156 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + string + L"wide string" + str ing);
157 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (string + L"wide string" + st ring));
158 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + string) + (L"wide string" + string));
159 EXPECT_N_WTF_STRING_COPIES(2, string + L"wide string" + string + L"wide stri ng");
160 EXPECT_N_WTF_STRING_COPIES(2, string + (L"wide string" + string + L"wide str ing"));
161 EXPECT_N_WTF_STRING_COPIES(2, (string + L"wide string") + (string + L"wide s tring"));
162
163 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + atomicString + L"wide string" + atomicString);
164 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (atomicString + L"wide string " + atomicString));
165 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + atomicString) + (L"wide stri ng" + atomicString));
166 EXPECT_N_WTF_STRING_COPIES(2, atomicString + L"wide string" + atomicString + L"wide string");
167 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (L"wide string" + atomicString + L"wide string"));
168 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + L"wide string") + (atomicStrin g + L"wide string"));
169
170 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + string + L"wide string" + ato micString);
171 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (string + L"wide string" + at omicString));
172 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + string) + (L"wide string" + atomicString));
173 EXPECT_N_WTF_STRING_COPIES(2, string + L"wide string" + atomicString + L"wid e string");
174 EXPECT_N_WTF_STRING_COPIES(2, string + (L"wide string" + atomicString + L"wi de string"));
175 EXPECT_N_WTF_STRING_COPIES(2, (string + L"wide string") + (atomicString + L" wide string"));
176
177 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + atomicString + L"wide string" + string);
178 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (atomicString + L"wide string " + string));
179 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + atomicString) + (L"wide stri ng" + string));
180 EXPECT_N_WTF_STRING_COPIES(2, atomicString + L"wide string" + string + L"wid e string");
181 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (L"wide string" + string + L"wi de string"));
182 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + L"wide string") + (string + L" wide string"));
183 #endif
184 }
185
186 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698