Chromium Code Reviews| Index: cc/base/contiguous_container_unittest.cc |
| diff --git a/cc/base/contiguous_container_unittest.cc b/cc/base/contiguous_container_unittest.cc |
| index 158b787d28dc4a584748e32b8861dc5e3decbc85..2a1d3d40bdc3b5c48ad70a9cf1d05892798d4f15 100644 |
| --- a/cc/base/contiguous_container_unittest.cc |
| +++ b/cc/base/contiguous_container_unittest.cc |
| @@ -511,6 +511,33 @@ TEST(ContiguousContainerTest, CapacityInBytesAfterClear) { |
| EXPECT_EQ(empty_capacity, list.GetCapacityInBytes()); |
| } |
|
danakj
2016/08/23 18:16:00
Can you add a test that verifies we can use begin(
Dmitry Skiba
2016/08/24 17:58:46
Done.
|
| +TEST(ContiguousContainerTest, MemoryUsageInBytes) { |
| + constexpr size_t initial_size1 = 10 * kMaxPointSize; |
| + ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize, |
| + initial_size1); |
| + |
| + constexpr size_t initial_size2 = 10000 * kMaxPointSize; |
| + ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize, |
| + initial_size2); |
| + |
| + // Memory is allocated lazily, so even though lists were created with |
| + // different initial_size values, they'll have the same memory size here. |
| + EXPECT_EQ(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes()); |
|
danakj
2016/08/23 18:16:00
You could check LT initial_size here?
Dmitry Skiba
2016/08/24 17:58:46
I think that checking that would make us depend on
|
| + |
| + // Trigger memory allocation. |
| + list1.AllocateAndConstruct<Point2D>(); |
| + list2.AllocateAndConstruct<Point2D>(); |
| + |
| + // Same object was created in both lists, but their memory sizes grew |
| + // differently, based on initial_size values lists were created with. |
| + EXPECT_NE(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes()); |
| + |
| + // Since memory size also includes other things, it should be greater |
| + // than initial_size value. |
| + EXPECT_GT(list1.MemoryUsageInBytes(), initial_size1); |
| + EXPECT_GT(list2.MemoryUsageInBytes(), initial_size2); |
| +} |
| + |
| TEST(ContiguousContainerTest, Alignment) { |
| const size_t max_align = ALIGNOF(long double); |
| ContiguousContainer<Point2D, max_align> list(kMaxPointSize); |