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

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: abandoned new/delete support 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
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..c52f02ebab48403eb8a4709c690124b41bc25941
--- /dev/null
+++ b/base/memory/aligned_memory_unittest.cc
@@ -0,0 +1,51 @@
+// 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(reinterpret_cast<intptr_t>(ptr) & (align - 1), 0)
+
+namespace {
+
+using base::RawAlignedMemory;
+using base::AlignedMemory;
+
+TEST(AlignedMemoryTest, StaticAlignment) {
+ static RawAlignedMemory<8, 8> raw8;
+ static RawAlignedMemory<8, 16> raw16;
+ static RawAlignedMemory<8, 256> raw256;
+ static RawAlignedMemory<8, 4096> raw4096;
+
+ EXPECT_EQ(ALIGNOF(raw8), 8u);
+ EXPECT_EQ(ALIGNOF(raw16), 16u);
+ EXPECT_EQ(ALIGNOF(raw256), 256u);
+ EXPECT_EQ(ALIGNOF(raw4096), 4096u);
+
+ EXPECT_ALIGNED(raw8.data_, 8);
+ EXPECT_ALIGNED(raw16.data_, 16);
+ EXPECT_ALIGNED(raw256.data_, 256);
+ EXPECT_ALIGNED(raw4096.data_, 4096);
+}
+
+TEST(AlignedMemoryTest, StackAlignment) {
+ RawAlignedMemory<8, 8> raw8;
Sigurður Ásgeirsson 2012/02/22 15:31:32 nice - do you know if is there a cost to this? I a
jbates 2012/02/22 19:37:15 I'm not sure. It must already happen to a certain
+ RawAlignedMemory<8, 16> raw16;
+ RawAlignedMemory<8, 256> raw256;
+ RawAlignedMemory<8, 4096> raw4096;
+
+ EXPECT_EQ(ALIGNOF(raw8), 8u);
+ EXPECT_EQ(ALIGNOF(raw16), 16u);
+ EXPECT_EQ(ALIGNOF(raw256), 256u);
+ EXPECT_EQ(ALIGNOF(raw4096), 4096u);
+
+ EXPECT_ALIGNED(raw8.data_, 8);
+ EXPECT_ALIGNED(raw16.data_, 16);
+ EXPECT_ALIGNED(raw256.data_, 256);
+ EXPECT_ALIGNED(raw4096.data_, 4096);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698