OLD | NEW |
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 EXPECT_EQ(1u, vectorA.size()); | 279 EXPECT_EQ(1u, vectorA.size()); |
280 EXPECT_EQ(1, vectorA.at(0).get()); | 280 EXPECT_EQ(1, vectorA.at(0).get()); |
281 EXPECT_EQ(3u, vectorB.size()); | 281 EXPECT_EQ(3u, vectorB.size()); |
282 EXPECT_EQ(2, vectorB.at(0).get()); | 282 EXPECT_EQ(2, vectorB.at(0).get()); |
283 EXPECT_EQ(3, vectorB.at(1).get()); | 283 EXPECT_EQ(3, vectorB.at(1).get()); |
284 EXPECT_EQ(4, vectorB.at(2).get()); | 284 EXPECT_EQ(4, vectorB.at(2).get()); |
285 | 285 |
286 vectorB.swap(vectorA); | 286 vectorB.swap(vectorA); |
287 } | 287 } |
288 | 288 |
289 #if defined(ADDRESS_SANITIZER) | 289 #if defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
290 TEST(VectorTest, ContainerAnnotations) | 290 TEST(VectorTest, ContainerAnnotations) |
291 { | 291 { |
292 Vector<int> vectorA; | 292 Vector<int> vectorA; |
293 vectorA.append(10); | 293 vectorA.append(10); |
294 vectorA.reserveCapacity(32); | 294 vectorA.reserveCapacity(32); |
295 | 295 |
296 volatile int* intPointerA = vectorA.data(); | 296 volatile int* intPointerA = vectorA.data(); |
297 EXPECT_DEATH(intPointerA[1] = 11, "container-overflow"); | 297 EXPECT_DEATH(intPointerA[1] = 11, "container-overflow"); |
298 vectorA.append(11); | 298 vectorA.append(11); |
299 intPointerA[1] = 11; | 299 intPointerA[1] = 11; |
(...skipping 18 matching lines...) Expand all Loading... |
318 volatile int* intPointerB2 = vectorB.data(); | 318 volatile int* intPointerB2 = vectorB.data(); |
319 volatile int* intPointerC2 = vectorC.data(); | 319 volatile int* intPointerC2 = vectorC.data(); |
320 intPointerB2[2] = 13; | 320 intPointerB2[2] = 13; |
321 EXPECT_DEATH((void)intPointerB2[3], "container-overflow"); | 321 EXPECT_DEATH((void)intPointerB2[3], "container-overflow"); |
322 EXPECT_DEATH((void)intPointerC2[2], "container-overflow"); | 322 EXPECT_DEATH((void)intPointerC2[2], "container-overflow"); |
323 | 323 |
324 vectorB = vectorC; | 324 vectorB = vectorC; |
325 volatile int* intPointerB3 = vectorB.data(); | 325 volatile int* intPointerB3 = vectorB.data(); |
326 EXPECT_DEATH((void)intPointerB3[2], "container-overflow"); | 326 EXPECT_DEATH((void)intPointerB3[2], "container-overflow"); |
327 } | 327 } |
328 | 328 #endif // defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
329 TEST(VectorTest, ContainerAnnotationsInline) | |
330 { | |
331 Vector<int> vectorA; | |
332 Vector<int, 4> vectorB; | |
333 | |
334 vectorB.append(1); | |
335 vectorB.append(2); | |
336 volatile int* intPointerB = vectorB.data(); | |
337 EXPECT_DEATH((void)intPointerB[2], "container-overflow"); | |
338 | |
339 vectorB.append(3); | |
340 vectorB.append(4); | |
341 vectorB.append(5); | |
342 vectorB.reserveCapacity(16); | |
343 intPointerB = vectorB.data(); | |
344 EXPECT_DEATH((void)intPointerB[5], "container-overflow"); | |
345 | |
346 vectorB.clear(); | |
347 vectorB.shrinkToFit(); | |
348 vectorB.append(1); | |
349 intPointerB = vectorB.data(); | |
350 EXPECT_DEATH((void)intPointerB[1], "container-overflow"); | |
351 | |
352 vectorB.shrinkToFit(); | |
353 intPointerB = vectorB.data(); | |
354 EXPECT_DEATH((void)intPointerB[1], "container-overflow"); | |
355 | |
356 vectorA = vectorB; | |
357 vectorA.reserveCapacity(8); | |
358 volatile int* intPointerA = vectorA.data(); | |
359 EXPECT_DEATH((void)intPointerA[1], "container-overflow"); | |
360 | |
361 Vector<int, 4> vectorC; | |
362 vectorC.append(3); | |
363 vectorC.append(4); | |
364 vectorB.swap(vectorC); | |
365 intPointerB = vectorB.data(); | |
366 vectorC.reserveCapacity(8); | |
367 volatile int* intPointerC = vectorC.data(); | |
368 vectorC[0] = 2; | |
369 vectorB[1] = 1337; | |
370 EXPECT_DEATH((void)intPointerC[1], "container-overflow"); | |
371 EXPECT_DEATH((void)intPointerB[2], "container-overflow"); | |
372 } | |
373 #endif // defined(ADDRESS_SANITIZER) | |
374 | 329 |
375 class Comparable { | 330 class Comparable { |
376 }; | 331 }; |
377 bool operator==(const Comparable& a, const Comparable& b) { return true; } | 332 bool operator==(const Comparable& a, const Comparable& b) { return true; } |
378 | 333 |
379 template<typename T> void compare() | 334 template<typename T> void compare() |
380 { | 335 { |
381 EXPECT_TRUE(Vector<T>() == Vector<T>()); | 336 EXPECT_TRUE(Vector<T>() == Vector<T>()); |
382 EXPECT_FALSE(Vector<T>(1) == Vector<T>(0)); | 337 EXPECT_FALSE(Vector<T>(1) == Vector<T>(0)); |
383 EXPECT_FALSE(Vector<T>() == Vector<T>(1)); | 338 EXPECT_FALSE(Vector<T>() == Vector<T>(1)); |
384 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1)); | 339 EXPECT_TRUE(Vector<T>(1) == Vector<T>(1)); |
385 | 340 |
386 Vector<T, 1> vectorWithInlineCapacity; | 341 Vector<T, 1> vectorWithInlineCapacity; |
387 EXPECT_TRUE(vectorWithInlineCapacity == Vector<T>()); | 342 EXPECT_TRUE(vectorWithInlineCapacity == Vector<T>()); |
388 EXPECT_FALSE(vectorWithInlineCapacity == Vector<T>(1)); | 343 EXPECT_FALSE(vectorWithInlineCapacity == Vector<T>(1)); |
389 } | 344 } |
390 | 345 |
391 TEST(VectorTest, Compare) | 346 TEST(VectorTest, Compare) |
392 { | 347 { |
393 compare<int>(); | 348 compare<int>(); |
394 compare<Comparable>(); | 349 compare<Comparable>(); |
395 compare<WTF::String>(); | 350 compare<WTF::String>(); |
396 } | 351 } |
397 | 352 |
398 } // anonymous namespace | 353 } // anonymous namespace |
399 | 354 |
400 } // namespace WTF | 355 } // namespace WTF |
OLD | NEW |