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>
34 namespace TestWebKitAPI {
36 #define EXPECT_N_WTF_STRING_COPIES(count, expr) \
38 wtfStringCopyCount = 0; \
39 String __testString = expr; \
41 EXPECT_EQ(count, wtfStringCopyCount) << #expr; \
44 TEST(WTF, StringOperators)
46 String string("String");
47 AtomicString atomicString("AtomicString");
49 EXPECT_EQ(0, wtfStringCopyCount);
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);
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");
61 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + "C string" + string);
62 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + "C string" + string));
63 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + ("C string" + string));
64 EXPECT_N_WTF_STRING_COPIES(2, string + "C string" + string + "C string");
65 EXPECT_N_WTF_STRING_COPIES(2, string + ("C string" + string + "C string"));
66 EXPECT_N_WTF_STRING_COPIES(2, (string + "C string") + (string + "C string"));
68 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + "C string" + atomicString);
69 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + "C string" + atomicString));
70 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + ("C string" + atomicString));
71 EXPECT_N_WTF_STRING_COPIES(2, atomicString + "C string" + atomicString + "C string");
72 EXPECT_N_WTF_STRING_COPIES(2, atomicString + ("C string" + atomicString + "C string"));
73 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + "C string") + (atomicString + "C string"));
75 EXPECT_N_WTF_STRING_COPIES(2, "C string" + string + "C string" + atomicString);
76 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (string + "C string" + atomicString));
77 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + string) + ("C string" + atomicString));
78 EXPECT_N_WTF_STRING_COPIES(2, string + "C string" + atomicString + "C string");
79 EXPECT_N_WTF_STRING_COPIES(2, string + ("C string" + atomicString + "C string"));
80 EXPECT_N_WTF_STRING_COPIES(2, (string + "C string") + (atomicString + "C string"));
82 EXPECT_N_WTF_STRING_COPIES(2, "C string" + atomicString + "C string" + string);
83 EXPECT_N_WTF_STRING_COPIES(2, "C string" + (atomicString + "C string" + string));
84 EXPECT_N_WTF_STRING_COPIES(2, ("C string" + atomicString) + ("C string" + string));
85 EXPECT_N_WTF_STRING_COPIES(2, atomicString + "C string" + string + "C string");
86 EXPECT_N_WTF_STRING_COPIES(2, atomicString + ("C string" + string + "C string"));
87 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + "C string") + (string + "C string"));
90 EXPECT_N_WTF_STRING_COPIES(1, L"wide string" + string);
91 EXPECT_N_WTF_STRING_COPIES(1, string + L"wide string");
92 EXPECT_N_WTF_STRING_COPIES(1, L"wide string" + atomicString);
93 EXPECT_N_WTF_STRING_COPIES(1, atomicString + L"wide string");
95 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + string + L"wide string" + string);
96 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (string + L"wide string" + string));
97 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + string) + (L"wide string" + string));
98 EXPECT_N_WTF_STRING_COPIES(2, string + L"wide string" + string + L"wide string");
99 EXPECT_N_WTF_STRING_COPIES(2, string + (L"wide string" + string + L"wide string"));
100 EXPECT_N_WTF_STRING_COPIES(2, (string + L"wide string") + (string + L"wide string"));
102 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + atomicString + L"wide string" + atomicString);
103 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (atomicString + L"wide string" + atomicString));
104 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + atomicString) + (L"wide string" + atomicString));
105 EXPECT_N_WTF_STRING_COPIES(2, atomicString + L"wide string" + atomicString + L"wide string");
106 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (L"wide string" + atomicString + L"wide string"));
107 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + L"wide string") + (atomicString + L"wide string"));
109 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + string + L"wide string" + atomicString);
110 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (string + L"wide string" + atomicString));
111 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + string) + (L"wide string" + atomicString));
112 EXPECT_N_WTF_STRING_COPIES(2, string + L"wide string" + atomicString + L"wide string");
113 EXPECT_N_WTF_STRING_COPIES(2, string + (L"wide string" + atomicString + L"wide string"));
114 EXPECT_N_WTF_STRING_COPIES(2, (string + L"wide string") + (atomicString + L"wide string"));
116 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + atomicString + L"wide string" + string);
117 EXPECT_N_WTF_STRING_COPIES(2, L"wide string" + (atomicString + L"wide string" + string));
118 EXPECT_N_WTF_STRING_COPIES(2, (L"wide string" + atomicString) + (L"wide string" + string));
119 EXPECT_N_WTF_STRING_COPIES(2, atomicString + L"wide string" + string + L"wide string");
120 EXPECT_N_WTF_STRING_COPIES(2, atomicString + (L"wide string" + string + L"wide string"));
121 EXPECT_N_WTF_STRING_COPIES(2, (atomicString + L"wide string") + (string + L"wide string"));
125 } // namespace TestWebKitAPI