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/VectorTest.cpp

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | third_party/WebKit/Source/wtf/VectorTraits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 18 matching lines...) Expand all
29 #include "wtf/HashSet.h" 29 #include "wtf/HashSet.h"
30 #include "wtf/OwnPtr.h" 30 #include "wtf/OwnPtr.h"
31 #include "wtf/PassOwnPtr.h" 31 #include "wtf/PassOwnPtr.h"
32 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
33 #include <gtest/gtest.h> 33 #include <gtest/gtest.h>
34 34
35 namespace WTF { 35 namespace WTF {
36 36
37 namespace { 37 namespace {
38 38
39 TEST(VectorTest, Basic) 39 TEST(VectorTest, Basic) {
40 { 40 Vector<int> intVector;
41 Vector<int> intVector; 41 EXPECT_TRUE(intVector.isEmpty());
42 EXPECT_TRUE(intVector.isEmpty()); 42 EXPECT_EQ(0ul, intVector.size());
43 EXPECT_EQ(0ul, intVector.size()); 43 EXPECT_EQ(0ul, intVector.capacity());
44 EXPECT_EQ(0ul, intVector.capacity()); 44 }
45 } 45
46 46 TEST(VectorTest, Reverse) {
47 TEST(VectorTest, Reverse) 47 Vector<int> intVector;
48 { 48 intVector.append(10);
49 Vector<int> intVector; 49 intVector.append(11);
50 intVector.append(10); 50 intVector.append(12);
51 intVector.append(11); 51 intVector.append(13);
52 intVector.append(12); 52 intVector.reverse();
53 intVector.append(13); 53
54 intVector.reverse(); 54 EXPECT_EQ(13, intVector[0]);
55 55 EXPECT_EQ(12, intVector[1]);
56 EXPECT_EQ(13, intVector[0]); 56 EXPECT_EQ(11, intVector[2]);
57 EXPECT_EQ(12, intVector[1]); 57 EXPECT_EQ(10, intVector[3]);
58 EXPECT_EQ(11, intVector[2]); 58
59 EXPECT_EQ(10, intVector[3]); 59 intVector.append(9);
60 60 intVector.reverse();
61 intVector.append(9); 61
62 intVector.reverse(); 62 EXPECT_EQ(9, intVector[0]);
63 63 EXPECT_EQ(10, intVector[1]);
64 EXPECT_EQ(9, intVector[0]); 64 EXPECT_EQ(11, intVector[2]);
65 EXPECT_EQ(10, intVector[1]); 65 EXPECT_EQ(12, intVector[3]);
66 EXPECT_EQ(11, intVector[2]); 66 EXPECT_EQ(13, intVector[4]);
67 EXPECT_EQ(12, intVector[3]); 67 }
68 EXPECT_EQ(13, intVector[4]); 68
69 } 69 TEST(VectorTest, Remove) {
70 70 Vector<int> intVector;
71 TEST(VectorTest, Remove) 71 intVector.append(0);
72 { 72 intVector.append(1);
73 Vector<int> intVector; 73 intVector.append(2);
74 intVector.append(0); 74 intVector.append(3);
75 intVector.append(1); 75
76 intVector.append(2); 76 EXPECT_EQ(4u, intVector.size());
77 intVector.append(3); 77 EXPECT_EQ(0, intVector[0]);
78 78 EXPECT_EQ(1, intVector[1]);
79 EXPECT_EQ(4u, intVector.size()); 79 EXPECT_EQ(2, intVector[2]);
80 EXPECT_EQ(0, intVector[0]); 80 EXPECT_EQ(3, intVector[3]);
81 EXPECT_EQ(1, intVector[1]); 81
82 EXPECT_EQ(2, intVector[2]); 82 intVector.remove(2, 0);
83 EXPECT_EQ(3, intVector[3]); 83 EXPECT_EQ(4u, intVector.size());
84 84 EXPECT_EQ(2, intVector[2]);
85 intVector.remove(2, 0); 85
86 EXPECT_EQ(4u, intVector.size()); 86 intVector.remove(2, 1);
87 EXPECT_EQ(2, intVector[2]); 87 EXPECT_EQ(3u, intVector.size());
88 88 EXPECT_EQ(3, intVector[2]);
89 intVector.remove(2, 1); 89
90 EXPECT_EQ(3u, intVector.size()); 90 intVector.remove(0, 0);
91 EXPECT_EQ(3, intVector[2]); 91 EXPECT_EQ(3u, intVector.size());
92 92 EXPECT_EQ(0, intVector[0]);
93 intVector.remove(0, 0); 93
94 EXPECT_EQ(3u, intVector.size()); 94 intVector.remove(0);
95 EXPECT_EQ(0, intVector[0]); 95 EXPECT_EQ(2u, intVector.size());
96 96 EXPECT_EQ(1, intVector[0]);
97 intVector.remove(0); 97 }
98 EXPECT_EQ(2u, intVector.size()); 98
99 EXPECT_EQ(1, intVector[0]); 99 TEST(VectorTest, Iterator) {
100 } 100 Vector<int> intVector;
101 101 intVector.append(10);
102 TEST(VectorTest, Iterator) 102 intVector.append(11);
103 { 103 intVector.append(12);
104 Vector<int> intVector; 104 intVector.append(13);
105 intVector.append(10); 105
106 intVector.append(11); 106 Vector<int>::iterator it = intVector.begin();
107 intVector.append(12); 107 Vector<int>::iterator end = intVector.end();
108 intVector.append(13); 108 EXPECT_TRUE(end != it);
109 109
110 Vector<int>::iterator it = intVector.begin(); 110 EXPECT_EQ(10, *it);
111 Vector<int>::iterator end = intVector.end(); 111 ++it;
112 EXPECT_TRUE(end != it); 112 EXPECT_EQ(11, *it);
113 113 ++it;
114 EXPECT_EQ(10, *it); 114 EXPECT_EQ(12, *it);
115 ++it; 115 ++it;
116 EXPECT_EQ(11, *it); 116 EXPECT_EQ(13, *it);
117 ++it; 117 ++it;
118 EXPECT_EQ(12, *it); 118
119 ++it; 119 EXPECT_TRUE(end == it);
120 EXPECT_EQ(13, *it); 120 }
121 ++it; 121
122 122 TEST(VectorTest, ReverseIterator) {
123 EXPECT_TRUE(end == it); 123 Vector<int> intVector;
124 } 124 intVector.append(10);
125 125 intVector.append(11);
126 TEST(VectorTest, ReverseIterator) 126 intVector.append(12);
127 { 127 intVector.append(13);
128 Vector<int> intVector; 128
129 intVector.append(10); 129 Vector<int>::reverse_iterator it = intVector.rbegin();
130 intVector.append(11); 130 Vector<int>::reverse_iterator end = intVector.rend();
131 intVector.append(12); 131 EXPECT_TRUE(end != it);
132 intVector.append(13); 132
133 133 EXPECT_EQ(13, *it);
134 Vector<int>::reverse_iterator it = intVector.rbegin(); 134 ++it;
135 Vector<int>::reverse_iterator end = intVector.rend(); 135 EXPECT_EQ(12, *it);
136 EXPECT_TRUE(end != it); 136 ++it;
137 137 EXPECT_EQ(11, *it);
138 EXPECT_EQ(13, *it); 138 ++it;
139 ++it; 139 EXPECT_EQ(10, *it);
140 EXPECT_EQ(12, *it); 140 ++it;
141 ++it; 141
142 EXPECT_EQ(11, *it); 142 EXPECT_TRUE(end == it);
143 ++it;
144 EXPECT_EQ(10, *it);
145 ++it;
146
147 EXPECT_TRUE(end == it);
148 } 143 }
149 144
150 class DestructCounter { 145 class DestructCounter {
151 public: 146 public:
152 explicit DestructCounter(int i, int* destructNumber) 147 explicit DestructCounter(int i, int* destructNumber)
153 : m_i(i) 148 : m_i(i), m_destructNumber(destructNumber) {}
154 , m_destructNumber(destructNumber) 149
155 { } 150 ~DestructCounter() { ++(*m_destructNumber); }
156 151 int get() const { return m_i; }
157 ~DestructCounter() { ++(*m_destructNumber); } 152
158 int get() const { return m_i; } 153 private:
159 154 int m_i;
160 private: 155 int* m_destructNumber;
161 int m_i;
162 int* m_destructNumber;
163 }; 156 };
164 157
165 typedef WTF::Vector<OwnPtr<DestructCounter>> OwnPtrVector; 158 typedef WTF::Vector<OwnPtr<DestructCounter>> OwnPtrVector;
166 159
167 TEST(VectorTest, OwnPtr) 160 TEST(VectorTest, OwnPtr) {
168 { 161 int destructNumber = 0;
169 int destructNumber = 0; 162 OwnPtrVector vector;
170 OwnPtrVector vector; 163 vector.append(adoptPtr(new DestructCounter(0, &destructNumber)));
171 vector.append(adoptPtr(new DestructCounter(0, &destructNumber))); 164 vector.append(adoptPtr(new DestructCounter(1, &destructNumber)));
172 vector.append(adoptPtr(new DestructCounter(1, &destructNumber))); 165 EXPECT_EQ(2u, vector.size());
173 EXPECT_EQ(2u, vector.size()); 166
174 167 OwnPtr<DestructCounter>& counter0 = vector.first();
175 OwnPtr<DestructCounter>& counter0 = vector.first(); 168 ASSERT_EQ(0, counter0->get());
176 ASSERT_EQ(0, counter0->get()); 169 int counter1 = vector.last()->get();
177 int counter1 = vector.last()->get(); 170 ASSERT_EQ(1, counter1);
178 ASSERT_EQ(1, counter1); 171 ASSERT_EQ(0, destructNumber);
179 ASSERT_EQ(0, destructNumber); 172
180 173 size_t index = 0;
181 size_t index = 0; 174 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end(); ++ite r) {
182 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end(); ++i ter) { 175 OwnPtr<DestructCounter>* refCounter = iter;
183 OwnPtr<DestructCounter>* refCounter = iter; 176 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get()));
184 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get())); 177 EXPECT_EQ(index, static_cast<size_t>((*refCounter)->get()));
185 EXPECT_EQ(index, static_cast<size_t>((*refCounter)->get())); 178 index++;
186 index++; 179 }
187 } 180 EXPECT_EQ(0, destructNumber);
188 EXPECT_EQ(0, destructNumber); 181
189 182 for (index = 0; index < vector.size(); index++) {
190 for (index = 0; index < vector.size(); index++) { 183 OwnPtr<DestructCounter>& refCounter = vector[index];
191 OwnPtr<DestructCounter>& refCounter = vector[index]; 184 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()));
192 EXPECT_EQ(index, static_cast<size_t>(refCounter->get())); 185 index++;
193 index++; 186 }
194 } 187 EXPECT_EQ(0, destructNumber);
195 EXPECT_EQ(0, destructNumber); 188
196 189 EXPECT_EQ(0, vector[0]->get());
197 EXPECT_EQ(0, vector[0]->get()); 190 EXPECT_EQ(1, vector[1]->get());
198 EXPECT_EQ(1, vector[1]->get()); 191 vector.remove(0);
199 vector.remove(0); 192 EXPECT_EQ(1, vector[0]->get());
200 EXPECT_EQ(1, vector[0]->get()); 193 EXPECT_EQ(1u, vector.size());
201 EXPECT_EQ(1u, vector.size()); 194 EXPECT_EQ(1, destructNumber);
202 EXPECT_EQ(1, destructNumber); 195
203 196 OwnPtr<DestructCounter> ownCounter1 = vector[0].release();
204 OwnPtr<DestructCounter> ownCounter1 = vector[0].release(); 197 vector.remove(0);
205 vector.remove(0); 198 ASSERT_EQ(counter1, ownCounter1->get());
206 ASSERT_EQ(counter1, ownCounter1->get()); 199 ASSERT_EQ(0u, vector.size());
207 ASSERT_EQ(0u, vector.size()); 200 ASSERT_EQ(1, destructNumber);
208 ASSERT_EQ(1, destructNumber); 201
209 202 ownCounter1.clear();
210 ownCounter1.clear(); 203 EXPECT_EQ(2, destructNumber);
211 EXPECT_EQ(2, destructNumber); 204
212 205 size_t count = 1025;
213 size_t count = 1025; 206 destructNumber = 0;
214 destructNumber = 0; 207 for (size_t i = 0; i < count; i++)
215 for (size_t i = 0; i < count; i++) 208 vector.prepend(adoptPtr(new DestructCounter(i, &destructNumber)));
216 vector.prepend(adoptPtr(new DestructCounter(i, &destructNumber))); 209
217 210 // Vector relocation must not destruct OwnPtr element.
218 // Vector relocation must not destruct OwnPtr element. 211 EXPECT_EQ(0, destructNumber);
219 EXPECT_EQ(0, destructNumber); 212 EXPECT_EQ(count, vector.size());
220 EXPECT_EQ(count, vector.size()); 213
221 214 OwnPtrVector copyVector;
222 OwnPtrVector copyVector; 215 vector.swap(copyVector);
223 vector.swap(copyVector); 216 EXPECT_EQ(0, destructNumber);
224 EXPECT_EQ(0, destructNumber); 217 EXPECT_EQ(count, copyVector.size());
225 EXPECT_EQ(count, copyVector.size()); 218 EXPECT_EQ(0u, vector.size());
226 EXPECT_EQ(0u, vector.size()); 219
227 220 copyVector.clear();
228 copyVector.clear(); 221 EXPECT_EQ(count, static_cast<size_t>(destructNumber));
229 EXPECT_EQ(count, static_cast<size_t>(destructNumber));
230 } 222 }
231 223
232 // WrappedInt class will fail if it was memmoved or memcpyed. 224 // WrappedInt class will fail if it was memmoved or memcpyed.
233 static HashSet<void*> constructedWrappedInts; 225 static HashSet<void*> constructedWrappedInts;
234 class WrappedInt { 226 class WrappedInt {
235 public: 227 public:
236 WrappedInt(int i = 0) 228 WrappedInt(int i = 0)
237 : m_originalThisPtr(this) 229 : m_originalThisPtr(this), m_i(i) {
238 , m_i(i) 230 constructedWrappedInts.add(this);
239 { 231 }
240 constructedWrappedInts.add(this); 232
241 } 233 WrappedInt(const WrappedInt& other)
242 234 : m_originalThisPtr(this), m_i(other.m_i) {
243 WrappedInt(const WrappedInt& other) 235 constructedWrappedInts.add(this);
244 : m_originalThisPtr(this) 236 }
245 , m_i(other.m_i) 237
246 { 238 WrappedInt& operator=(const WrappedInt& other) {
247 constructedWrappedInts.add(this); 239 m_i = other.m_i;
248 } 240 return *this;
249 241 }
250 WrappedInt& operator=(const WrappedInt& other) 242
251 { 243 ~WrappedInt() {
252 m_i = other.m_i; 244 EXPECT_EQ(m_originalThisPtr, this);
253 return *this; 245 EXPECT_TRUE(constructedWrappedInts.contains(this));
254 } 246 constructedWrappedInts.remove(this);
255 247 }
256 ~WrappedInt() 248
257 { 249 int get() const { return m_i; }
258 EXPECT_EQ(m_originalThisPtr, this); 250
259 EXPECT_TRUE(constructedWrappedInts.contains(this)); 251 private:
260 constructedWrappedInts.remove(this); 252 void* m_originalThisPtr;
261 } 253 int m_i;
262
263 int get() const { return m_i; }
264
265 private:
266 void* m_originalThisPtr;
267 int m_i;
268 }; 254 };
269 255
270 TEST(VectorTest, SwapWithInlineCapacity) 256 TEST(VectorTest, SwapWithInlineCapacity) {
271 { 257 const size_t inlineCapacity = 2;
272 const size_t inlineCapacity = 2; 258 Vector<WrappedInt, inlineCapacity> vectorA;
273 Vector<WrappedInt, inlineCapacity> vectorA; 259 vectorA.append(WrappedInt(1));
274 vectorA.append(WrappedInt(1)); 260 Vector<WrappedInt, inlineCapacity> vectorB;
275 Vector<WrappedInt, inlineCapacity> vectorB; 261 vectorB.append(WrappedInt(2));
276 vectorB.append(WrappedInt(2)); 262
277 263 EXPECT_EQ(vectorA.size(), vectorB.size());
278 EXPECT_EQ(vectorA.size(), vectorB.size()); 264 vectorA.swap(vectorB);
279 vectorA.swap(vectorB); 265
280 266 EXPECT_EQ(1u, vectorA.size());
281 EXPECT_EQ(1u, vectorA.size()); 267 EXPECT_EQ(2, vectorA.at(0).get());
282 EXPECT_EQ(2, vectorA.at(0).get()); 268 EXPECT_EQ(1u, vectorB.size());
283 EXPECT_EQ(1u, vectorB.size()); 269 EXPECT_EQ(1, vectorB.at(0).get());
284 EXPECT_EQ(1, vectorB.at(0).get()); 270
285 271 vectorA.append(WrappedInt(3));
286 vectorA.append(WrappedInt(3)); 272
287 273 EXPECT_GT(vectorA.size(), vectorB.size());
288 EXPECT_GT(vectorA.size(), vectorB.size()); 274 vectorA.swap(vectorB);
289 vectorA.swap(vectorB); 275
290 276 EXPECT_EQ(1u, vectorA.size());
291 EXPECT_EQ(1u, vectorA.size()); 277 EXPECT_EQ(1, vectorA.at(0).get());
292 EXPECT_EQ(1, vectorA.at(0).get()); 278 EXPECT_EQ(2u, vectorB.size());
293 EXPECT_EQ(2u, vectorB.size()); 279 EXPECT_EQ(2, vectorB.at(0).get());
294 EXPECT_EQ(2, vectorB.at(0).get()); 280 EXPECT_EQ(3, vectorB.at(1).get());
295 EXPECT_EQ(3, vectorB.at(1).get()); 281
296 282 EXPECT_LT(vectorA.size(), vectorB.size());
297 EXPECT_LT(vectorA.size(), vectorB.size()); 283 vectorA.swap(vectorB);
298 vectorA.swap(vectorB); 284
299 285 EXPECT_EQ(2u, vectorA.size());
300 EXPECT_EQ(2u, vectorA.size()); 286 EXPECT_EQ(2, vectorA.at(0).get());
301 EXPECT_EQ(2, vectorA.at(0).get()); 287 EXPECT_EQ(3, vectorA.at(1).get());
302 EXPECT_EQ(3, vectorA.at(1).get()); 288 EXPECT_EQ(1u, vectorB.size());
303 EXPECT_EQ(1u, vectorB.size()); 289 EXPECT_EQ(1, vectorB.at(0).get());
304 EXPECT_EQ(1, vectorB.at(0).get()); 290
305 291 vectorA.append(WrappedInt(4));
306 vectorA.append(WrappedInt(4)); 292 EXPECT_GT(vectorA.size(), inlineCapacity);
307 EXPECT_GT(vectorA.size(), inlineCapacity); 293 vectorA.swap(vectorB);
308 vectorA.swap(vectorB); 294
309 295 EXPECT_EQ(1u, vectorA.size());
310 EXPECT_EQ(1u, vectorA.size()); 296 EXPECT_EQ(1, vectorA.at(0).get());
311 EXPECT_EQ(1, vectorA.at(0).get()); 297 EXPECT_EQ(3u, vectorB.size());
312 EXPECT_EQ(3u, vectorB.size()); 298 EXPECT_EQ(2, vectorB.at(0).get());
313 EXPECT_EQ(2, vectorB.at(0).get()); 299 EXPECT_EQ(3, vectorB.at(1).get());
314 EXPECT_EQ(3, vectorB.at(1).get()); 300 EXPECT_EQ(4, vectorB.at(2).get());
315 EXPECT_EQ(4, vectorB.at(2).get()); 301
316 302 vectorB.swap(vectorA);
317 vectorB.swap(vectorA);
318 } 303 }
319 304
320 #if defined(ANNOTATE_CONTIGUOUS_CONTAINER) 305 #if defined(ANNOTATE_CONTIGUOUS_CONTAINER)
321 TEST(VectorTest, ContainerAnnotations) 306 TEST(VectorTest, ContainerAnnotations) {
322 { 307 Vector<int> vectorA;
323 Vector<int> vectorA; 308 vectorA.append(10);
324 vectorA.append(10); 309 vectorA.reserveCapacity(32);
325 vectorA.reserveCapacity(32); 310
326 311 volatile int* intPointerA = vectorA.data();
327 volatile int* intPointerA = vectorA.data(); 312 EXPECT_DEATH(intPointerA[1] = 11, "container-overflow");
328 EXPECT_DEATH(intPointerA[1] = 11, "container-overflow"); 313 vectorA.append(11);
329 vectorA.append(11); 314 intPointerA[1] = 11;
330 intPointerA[1] = 11; 315 EXPECT_DEATH(intPointerA[2] = 12, "container-overflow");
331 EXPECT_DEATH(intPointerA[2] = 12, "container-overflow"); 316 EXPECT_DEATH((void)intPointerA[2], "container-overflow");
332 EXPECT_DEATH((void)intPointerA[2], "container-overflow"); 317 vectorA.shrinkToFit();
333 vectorA.shrinkToFit(); 318 vectorA.reserveCapacity(16);
334 vectorA.reserveCapacity(16); 319 intPointerA = vectorA.data();
335 intPointerA = vectorA.data(); 320 EXPECT_DEATH((void)intPointerA[2], "container-overflow");
336 EXPECT_DEATH((void)intPointerA[2], "container-overflow"); 321
337 322 Vector<int> vectorB(vectorA);
338 Vector<int> vectorB(vectorA); 323 vectorB.reserveCapacity(16);
339 vectorB.reserveCapacity(16); 324 volatile int* intPointerB = vectorB.data();
340 volatile int* intPointerB = vectorB.data(); 325 EXPECT_DEATH((void)intPointerB[2], "container-overflow");
341 EXPECT_DEATH((void)intPointerB[2], "container-overflow"); 326
342 327 Vector<int> vectorC((Vector<int>(vectorA)));
343 Vector<int> vectorC((Vector<int>(vectorA))); 328 volatile int* intPointerC = vectorC.data();
344 volatile int* intPointerC = vectorC.data(); 329 EXPECT_DEATH((void)intPointerC[2], "container-overflow");
345 EXPECT_DEATH((void)intPointerC[2], "container-overflow"); 330 vectorC.append(13);
346 vectorC.append(13); 331 vectorC.swap(vectorB);
347 vectorC.swap(vectorB); 332
348 333 volatile int* intPointerB2 = vectorB.data();
349 volatile int* intPointerB2 = vectorB.data(); 334 volatile int* intPointerC2 = vectorC.data();
350 volatile int* intPointerC2 = vectorC.data(); 335 intPointerB2[2] = 13;
351 intPointerB2[2] = 13; 336 EXPECT_DEATH((void)intPointerB2[3], "container-overflow");
352 EXPECT_DEATH((void)intPointerB2[3], "container-overflow"); 337 EXPECT_DEATH((void)intPointerC2[2], "container-overflow");
353 EXPECT_DEATH((void)intPointerC2[2], "container-overflow"); 338
354 339 vectorB = vectorC;
355 vectorB = vectorC; 340 volatile int* intPointerB3 = vectorB.data();
356 volatile int* intPointerB3 = vectorB.data(); 341 EXPECT_DEATH((void)intPointerB3[2], "container-overflow");
357 EXPECT_DEATH((void)intPointerB3[2], "container-overflow"); 342 }
358 } 343 #endif // defined(ANNOTATE_CONTIGUOUS_CONTAINER)
359 #endif // defined(ANNOTATE_CONTIGUOUS_CONTAINER)
360 344
361 class Comparable { 345 class Comparable {
362 }; 346 };
363 bool operator==(const Comparable& a, const Comparable& b) { return true; } 347 bool operator==(const Comparable& a, const Comparable& b) {
364 348 return true;
365 template<typename T> void compare() 349 }
366 { 350
367 EXPECT_TRUE(Vector<T>() == Vector<T>()); 351 template <typename T>
368 EXPECT_FALSE(Vector<T>(1) == Vector<T>(0)); 352 void compare() {
369 EXPECT_FALSE(Vector<T>() == Vector<T>(1)); 353 EXPECT_TRUE(Vector<T>() == Vector<T>());
370 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1)); 354 EXPECT_FALSE(Vector<T>(1) == Vector<T>(0));
371 355 EXPECT_FALSE(Vector<T>() == Vector<T>(1));
372 Vector<T, 1> vectorWithInlineCapacity; 356 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1));
373 EXPECT_TRUE(vectorWithInlineCapacity == Vector<T>()); 357
374 EXPECT_FALSE(vectorWithInlineCapacity == Vector<T>(1)); 358 Vector<T, 1> vectorWithInlineCapacity;
375 } 359 EXPECT_TRUE(vectorWithInlineCapacity == Vector<T>());
376 360 EXPECT_FALSE(vectorWithInlineCapacity == Vector<T>(1));
377 TEST(VectorTest, Compare) 361 }
378 { 362
379 compare<int>(); 363 TEST(VectorTest, Compare) {
380 compare<Comparable>(); 364 compare<int>();
381 compare<WTF::String>(); 365 compare<Comparable>();
382 } 366 compare<WTF::String>();
383 367 }
384 } // anonymous namespace 368
385 369 } // anonymous namespace
386 } // namespace WTF 370
371 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | third_party/WebKit/Source/wtf/VectorTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698