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

Unified Diff: base/memory/aligned_memory_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/memory/aligned_memory.h ('k') | base/memory/singleton.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/aligned_memory_unittest.cc
diff --git a/base/memory/aligned_memory_unittest.cc b/base/memory/aligned_memory_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..065e9522a9853ba5bb42f68509214255f2d34211
--- /dev/null
+++ b/base/memory/aligned_memory_unittest.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/aligned_memory.h"
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#define EXPECT_ALIGNED(ptr, align) \
+ EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
+
+namespace {
+
+using base::AlignedMemory;
+
+TEST(AlignedMemoryTest, StaticAlignment) {
+ static AlignedMemory<8, 8> raw8;
+ static AlignedMemory<8, 16> raw16;
+ static AlignedMemory<8, 256> raw256;
+ static AlignedMemory<8, 4096> raw4096;
+
+ EXPECT_EQ(8u, ALIGNOF(raw8));
+ EXPECT_EQ(16u, ALIGNOF(raw16));
+ EXPECT_EQ(256u, ALIGNOF(raw256));
+ EXPECT_EQ(4096u, ALIGNOF(raw4096));
+
+ EXPECT_ALIGNED(raw8.void_data(), 8);
+ EXPECT_ALIGNED(raw16.void_data(), 16);
+ EXPECT_ALIGNED(raw256.void_data(), 256);
+ EXPECT_ALIGNED(raw4096.void_data(), 4096);
+}
+
+TEST(AlignedMemoryTest, StackAlignment) {
+ AlignedMemory<8, 8> raw8;
+ AlignedMemory<8, 16> raw16;
+ AlignedMemory<8, 256> raw256;
+ AlignedMemory<8, 4096> raw4096;
+
+ EXPECT_EQ(8u, ALIGNOF(raw8));
+ EXPECT_EQ(16u, ALIGNOF(raw16));
+ EXPECT_EQ(256u, ALIGNOF(raw256));
+ EXPECT_EQ(4096u, ALIGNOF(raw4096));
+
+ EXPECT_ALIGNED(raw8.void_data(), 8);
+ EXPECT_ALIGNED(raw16.void_data(), 16);
+ EXPECT_ALIGNED(raw256.void_data(), 256);
+ EXPECT_ALIGNED(raw4096.void_data(), 4096);
+}
+
+} // namespace
« no previous file with comments | « base/memory/aligned_memory.h ('k') | base/memory/singleton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698