2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() (++wtfStringCopyCount)
30 static int wtfStringCopyCount
;
32 #include "wtf/text/WTFString.h"
33 #include <gtest/gtest.h>
37 #define EXPECT_N_WTF_STRING_COPIES(count, expr) \
39 wtfStringCopyCount = 0; \
40 String __testString = expr; \
42 EXPECT_EQ(count, wtfStringCopyCount) << #expr; \
45 TEST(StringOperatorsTest
, DISABLED_StringOperators
)
47 String
string("String");
48 AtomicString
atomicString("AtomicString");
49 const char* literal
= "ASCIILiteral";
51 EXPECT_EQ(0, wtfStringCopyCount
);
53 EXPECT_N_WTF_STRING_COPIES(2, string
+ string
);
54 EXPECT_N_WTF_STRING_COPIES(2, string
+ atomicString
);
55 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ string
);
56 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ atomicString
);
58 EXPECT_N_WTF_STRING_COPIES(1, "C string" + string
);
59 EXPECT_N_WTF_STRING_COPIES(1, string
+ "C string");
60 EXPECT_N_WTF_STRING_COPIES(1, "C string" + atomicString
);
61 EXPECT_N_WTF_STRING_COPIES(1, atomicString
+ "C string");
63 EXPECT_N_WTF_STRING_COPIES(1, literal
+ string
);
64 EXPECT_N_WTF_STRING_COPIES(1, string
+ literal
);
65 EXPECT_N_WTF_STRING_COPIES(1, literal
+ atomicString
);
66 EXPECT_N_WTF_STRING_COPIES(1, atomicString
+ literal
);
68 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string
+ "C string" + string
);
69 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string
+ "C string" + string
));
70 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string
) + ("C string" + string
));
71 EXPECT_N_WTF_STRING_COPIES(2, string
+ "C string" + string
+ "C string");
72 EXPECT_N_WTF_STRING_COPIES(2, string
+ ("C string" + string
+ "C string"));
73 EXPECT_N_WTF_STRING_COPIES(2, (string
+ "C string") + (string
+ "C string"));
75 EXPECT_N_WTF_STRING_COPIES(2, literal
+ string
+ literal
+ string
);
76 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (string
+ literal
+ string
));
77 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ string
) + (literal
+ string
));
78 EXPECT_N_WTF_STRING_COPIES(2, string
+ literal
+ string
+ literal
);
79 EXPECT_N_WTF_STRING_COPIES(2, string
+ (literal
+ string
+ literal
));
80 EXPECT_N_WTF_STRING_COPIES(2, (string
+ literal
) + (string
+ literal
));
82 EXPECT_N_WTF_STRING_COPIES(2, literal
+ string
+ "C string" + string
);
83 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (string
+ "C string" + string
));
84 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ string
) + ("C string" + string
));
85 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string
+ literal
+ string
);
86 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string
+ literal
+ string
));
87 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string
) + (literal
+ string
));
89 EXPECT_N_WTF_STRING_COPIES(2, literal
+ atomicString
+ "C string" + atomicString
);
90 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (atomicString
+ "C string" + atomicString
));
91 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ atomicString
) + ("C string" + atomicString
));
92 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString
+ literal
+ atomicString
);
93 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString
+ literal
+ atomicString
));
94 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString
) + (literal
+ atomicString
));
96 EXPECT_N_WTF_STRING_COPIES(2, literal
+ atomicString
+ "C string" + string
);
97 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (atomicString
+ "C string" + string
));
98 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ atomicString
) + ("C string" + string
));
99 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString
+ literal
+ string
);
100 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString
+ literal
+ string
));
101 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString
) + (literal
+ string
));
103 EXPECT_N_WTF_STRING_COPIES(2, literal
+ string
+ "C string" + atomicString
);
104 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (string
+ "C string" + atomicString
));
105 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ string
) + ("C string" + atomicString
));
106 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string
+ literal
+ atomicString
);
107 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string
+ literal
+ atomicString
));
108 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string
) + (literal
+ atomicString
));
110 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString
+ "C string" + atomicString
);
111 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString
+ "C string" + atomicString
));
112 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString
) + ("C string" + atomicString
));
113 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ "C string" + atomicString
+ "C string");
114 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ ("C string" + atomicString
+ "C string"));
115 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ "C string") + (atomicString
+ "C string"));
117 EXPECT_N_WTF_STRING_COPIES(2, literal
+ atomicString
+ literal
+ atomicString
);
118 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (atomicString
+ literal
+ atomicString
));
119 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ atomicString
) + (literal
+ atomicString
));
120 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ literal
+ atomicString
+ literal
);
121 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ (literal
+ atomicString
+ literal
));
122 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ literal
) + (atomicString
+ literal
));
124 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string
+ "C string" + atomicString
);
125 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string
+ "C string" + atomicString
));
126 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string
) + ("C string" + atomicString
));
127 EXPECT_N_WTF_STRING_COPIES(2, string
+ "C string" + atomicString
+ "C string");
128 EXPECT_N_WTF_STRING_COPIES(2, string
+ ("C string" + atomicString
+ "C string"));
129 EXPECT_N_WTF_STRING_COPIES(2, (string
+ "C string") + (atomicString
+ "C string"));
131 EXPECT_N_WTF_STRING_COPIES(2, literal
+ string
+ literal
+ atomicString
);
132 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (string
+ literal
+ atomicString
));
133 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ string
) + (literal
+ atomicString
));
134 EXPECT_N_WTF_STRING_COPIES(2, string
+ literal
+ atomicString
+ literal
);
135 EXPECT_N_WTF_STRING_COPIES(2, string
+ (literal
+ atomicString
+ literal
));
136 EXPECT_N_WTF_STRING_COPIES(2, (string
+ literal
) + (atomicString
+ literal
));
138 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString
+ "C string" + string
);
139 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString
+ "C string" + string
));
140 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString
) + ("C string" + string
));
141 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ "C string" + string
+ "C string");
142 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ ("C string" + string
+ "C string"));
143 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ "C string") + (string
+ "C string"));
145 EXPECT_N_WTF_STRING_COPIES(2, literal
+ atomicString
+ literal
+ string
);
146 EXPECT_N_WTF_STRING_COPIES(2, literal
+ (atomicString
+ literal
+ string
));
147 EXPECT_N_WTF_STRING_COPIES(2, (literal
+ atomicString
) + (literal
+ string
));
148 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ literal
+ string
+ literal
);
149 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ (literal
+ string
+ literal
));
150 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ literal
) + (string
+ literal
));
153 EXPECT_N_WTF_STRING_COPIES(1, L
"wide string" + string
);
154 EXPECT_N_WTF_STRING_COPIES(1, string
+ L
"wide string");
155 EXPECT_N_WTF_STRING_COPIES(1, L
"wide string" + atomicString
);
156 EXPECT_N_WTF_STRING_COPIES(1, atomicString
+ L
"wide string");
158 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + string
+ L
"wide string" + string
);
159 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + (string
+ L
"wide string" + string
));
160 EXPECT_N_WTF_STRING_COPIES(2, (L
"wide string" + string
) + (L
"wide string" + string
));
161 EXPECT_N_WTF_STRING_COPIES(2, string
+ L
"wide string" + string
+ L
"wide string");
162 EXPECT_N_WTF_STRING_COPIES(2, string
+ (L
"wide string" + string
+ L
"wide string"));
163 EXPECT_N_WTF_STRING_COPIES(2, (string
+ L
"wide string") + (string
+ L
"wide string"));
165 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + atomicString
+ L
"wide string" + atomicString
);
166 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + (atomicString
+ L
"wide string" + atomicString
));
167 EXPECT_N_WTF_STRING_COPIES(2, (L
"wide string" + atomicString
) + (L
"wide string" + atomicString
));
168 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ L
"wide string" + atomicString
+ L
"wide string");
169 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ (L
"wide string" + atomicString
+ L
"wide string"));
170 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ L
"wide string") + (atomicString
+ L
"wide string"));
172 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + string
+ L
"wide string" + atomicString
);
173 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + (string
+ L
"wide string" + atomicString
));
174 EXPECT_N_WTF_STRING_COPIES(2, (L
"wide string" + string
) + (L
"wide string" + atomicString
));
175 EXPECT_N_WTF_STRING_COPIES(2, string
+ L
"wide string" + atomicString
+ L
"wide string");
176 EXPECT_N_WTF_STRING_COPIES(2, string
+ (L
"wide string" + atomicString
+ L
"wide string"));
177 EXPECT_N_WTF_STRING_COPIES(2, (string
+ L
"wide string") + (atomicString
+ L
"wide string"));
179 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + atomicString
+ L
"wide string" + string
);
180 EXPECT_N_WTF_STRING_COPIES(2, L
"wide string" + (atomicString
+ L
"wide string" + string
));
181 EXPECT_N_WTF_STRING_COPIES(2, (L
"wide string" + atomicString
) + (L
"wide string" + string
));
182 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ L
"wide string" + string
+ L
"wide string");
183 EXPECT_N_WTF_STRING_COPIES(2, atomicString
+ (L
"wide string" + string
+ L
"wide string"));
184 EXPECT_N_WTF_STRING_COPIES(2, (atomicString
+ L
"wide string") + (string
+ L
"wide string"));