Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: base/stack_container_unittest.cc

Issue 9186057: Add ALIGNAS and ALIGNOF macros to ensure proper alignment of StaticMemorySingletonTraits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan feedback Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/stack_container.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/stack_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698