| Index: base/stack_container_unittest.cc
|
| diff --git a/base/stack_container_unittest.cc b/base/stack_container_unittest.cc
|
| index 816ee07d7fbe9a0213d30ff1f295aa65f3727b39..175df36d3cdb9081b232f3b46d1ca09b0ca3a1d7 100644
|
| --- a/base/stack_container_unittest.cc
|
| +++ b/base/stack_container_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include <algorithm>
|
|
|
| +#include "base/memory/aligned_memory.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -96,19 +97,33 @@ TEST(StackContainer, VectorDoubleDelete) {
|
| // Shouldn't crash at exit.
|
| }
|
|
|
| +namespace {
|
| +
|
| +template <size_t alignment>
|
| +class AlignedData {
|
| + public:
|
| + AlignedData() { memset(data_.void_data(), 0, alignment); }
|
| + ~AlignedData() {}
|
| + base::AlignedMemory<alignment, alignment> data_;
|
| +};
|
| +
|
| +} // anonymous namespace
|
| +
|
| +#define EXPECT_ALIGNED(ptr, align) \
|
| + EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
|
| +
|
| TEST(StackContainer, BufferAlignment) {
|
| StackVector<wchar_t, 16> text;
|
| text->push_back(L'A');
|
| - text->push_back(L'B');
|
| - text->push_back(L'C');
|
| - text->push_back(L'D');
|
| - text->push_back(L'E');
|
| - text->push_back(L'F');
|
| - text->push_back(0);
|
| -
|
| - const wchar_t* buffer = &text[1];
|
| - bool even_aligned = (0 == (((size_t)buffer) & 0x1));
|
| - EXPECT_EQ(even_aligned, true);
|
| + EXPECT_ALIGNED(&text[0], ALIGNOF(wchar_t));
|
| +
|
| + StackVector<double, 1> doubles;
|
| + doubles->push_back(0.0);
|
| + EXPECT_ALIGNED(&doubles[0], ALIGNOF(double));
|
| +
|
| + StackVector<AlignedData<256>, 1> aligned256;
|
| + aligned256->push_back(AlignedData<256>());
|
| + EXPECT_ALIGNED(&aligned256[0], 256);
|
| }
|
|
|
| #ifdef COMPILER_MSVC
|
|
|