| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/ContiguousContainer.h" | 5 #include "platform/graphics/ContiguousContainer.h" |
| 6 | 6 |
| 7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "wtf/TypeTraits.h" | 9 #include "wtf/TypeTraits.h" |
| 10 | 10 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // Clearing should restore the capacity of the container to the same as a | 517 // Clearing should restore the capacity of the container to the same as a |
| 518 // newly allocated one (without reserved capacity requested). | 518 // newly allocated one (without reserved capacity requested). |
| 519 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 519 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
| 520 size_t emptyCapacity = list.capacityInBytes(); | 520 size_t emptyCapacity = list.capacityInBytes(); |
| 521 list.allocateAndConstruct<Point2D>(); | 521 list.allocateAndConstruct<Point2D>(); |
| 522 list.allocateAndConstruct<Point2D>(); | 522 list.allocateAndConstruct<Point2D>(); |
| 523 list.clear(); | 523 list.clear(); |
| 524 EXPECT_EQ(emptyCapacity, list.capacityInBytes()); | 524 EXPECT_EQ(emptyCapacity, list.capacityInBytes()); |
| 525 } | 525 } |
| 526 | 526 |
| 527 TEST(ContiguousContainerTest, Alignment) |
| 528 { |
| 529 const size_t maxAlign = WTF_ALIGN_OF(long double); |
| 530 ContiguousContainer<Point2D, maxAlign> list(kMaxPointSize); |
| 531 |
| 532 list.allocateAndConstruct<Point2D>(); |
| 533 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 534 list.allocateAndConstruct<Point2D>(); |
| 535 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 536 list.allocateAndConstruct<Point3D>(); |
| 537 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 538 list.allocateAndConstruct<Point3D>(); |
| 539 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 540 list.allocateAndConstruct<Point2D>(); |
| 541 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 542 |
| 543 list.appendByMoving(list[0], sizeof(Point2D)); |
| 544 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 545 list.appendByMoving(list[1], sizeof(Point2D)); |
| 546 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 547 list.appendByMoving(list[2], sizeof(Point3D)); |
| 548 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 549 list.appendByMoving(list[3], sizeof(Point3D)); |
| 550 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 551 list.appendByMoving(list[4], sizeof(Point2D)); |
| 552 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
| 553 } |
| 554 |
| 527 } // namespace | 555 } // namespace |
| 528 } // namespace blink | 556 } // namespace blink |
| OLD | NEW |