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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "cc/base/contiguous_container.h" | 9 #include "cc/base/contiguous_container.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 list2.AllocateAndConstruct<Point2D>(); | 542 list2.AllocateAndConstruct<Point2D>(); |
543 | 543 |
544 // Same object was created in both lists, but their memory usages grew | 544 // Same object was created in both lists, but their memory usages grew |
545 // differently, based on initial_size values lists were created with. | 545 // differently, based on initial_size values lists were created with. |
546 EXPECT_NE(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes()); | 546 EXPECT_NE(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes()); |
547 EXPECT_GE(list1.MemoryUsageInBytes(), memory_usage1 + initial_size1); | 547 EXPECT_GE(list1.MemoryUsageInBytes(), memory_usage1 + initial_size1); |
548 EXPECT_GE(list2.MemoryUsageInBytes(), memory_usage2 + initial_size2); | 548 EXPECT_GE(list2.MemoryUsageInBytes(), memory_usage2 + initial_size2); |
549 } | 549 } |
550 | 550 |
551 TEST(ContiguousContainerTest, Alignment) { | 551 TEST(ContiguousContainerTest, Alignment) { |
552 const size_t max_align = ALIGNOF(long double); | 552 const size_t max_align = alignof(long double); |
553 ContiguousContainer<Point2D, max_align> list(kMaxPointSize); | 553 ContiguousContainer<Point2D, max_align> list(kMaxPointSize); |
554 | 554 |
555 list.AllocateAndConstruct<Point2D>(); | 555 list.AllocateAndConstruct<Point2D>(); |
556 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 556 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
557 list.AllocateAndConstruct<Point2D>(); | 557 list.AllocateAndConstruct<Point2D>(); |
558 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 558 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
559 list.AllocateAndConstruct<Point3D>(); | 559 list.AllocateAndConstruct<Point3D>(); |
560 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 560 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
561 list.AllocateAndConstruct<Point3D>(); | 561 list.AllocateAndConstruct<Point3D>(); |
562 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 562 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
563 list.AllocateAndConstruct<Point2D>(); | 563 list.AllocateAndConstruct<Point2D>(); |
564 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 564 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
565 | 565 |
566 list.AppendByMoving(&list[0], sizeof(Point2D)); | 566 list.AppendByMoving(&list[0], sizeof(Point2D)); |
567 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 567 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
568 list.AppendByMoving(&list[1], sizeof(Point2D)); | 568 list.AppendByMoving(&list[1], sizeof(Point2D)); |
569 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 569 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
570 list.AppendByMoving(&list[2], sizeof(Point3D)); | 570 list.AppendByMoving(&list[2], sizeof(Point3D)); |
571 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 571 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
572 list.AppendByMoving(&list[3], sizeof(Point3D)); | 572 list.AppendByMoving(&list[3], sizeof(Point3D)); |
573 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 573 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
574 list.AppendByMoving(&list[4], sizeof(Point2D)); | 574 list.AppendByMoving(&list[4], sizeof(Point2D)); |
575 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 575 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
576 } | 576 } |
577 | 577 |
578 } // namespace | 578 } // namespace |
579 } // namespace cc | 579 } // namespace cc |
OLD | NEW |