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

Unified Diff: base/memory/aligned_memory_unittest.cc

Issue 2932053002: Use C++11 alignment primitives (Closed)
Patch Set: Fix merge Created 3 years, 6 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/manual_constructor.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
index 892c50ef70b03915e6841734538c787115ecf883..e354f38b75ca72bc6592a69188e11169fb5deb84 100644
--- a/base/memory/aligned_memory_unittest.cc
+++ b/base/memory/aligned_memory_unittest.cc
@@ -12,84 +12,35 @@
#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, 128> raw128;
-
- EXPECT_EQ(8u, ALIGNOF(raw8));
- EXPECT_EQ(16u, ALIGNOF(raw16));
- EXPECT_EQ(128u, ALIGNOF(raw128));
-
- EXPECT_ALIGNED(raw8.void_data(), 8);
- EXPECT_ALIGNED(raw16.void_data(), 16);
- EXPECT_ALIGNED(raw128.void_data(), 128);
-
- // NaCl x86-64 compiler emits non-validating instructions for >128
- // bytes alignment.
- // http://www.chromium.org/nativeclient/design-documents/nacl-sfi-model-on-x86-64-systems
- // TODO(hamaji): Ideally, NaCl compiler for x86-64 should workaround
- // this limitation and this #if should be removed.
- // https://code.google.com/p/nativeclient/issues/detail?id=3463
-#if !(defined(OS_NACL) && defined(ARCH_CPU_X86_64))
- AlignedMemory<8, 256> raw256;
- EXPECT_EQ(256u, ALIGNOF(raw256));
- EXPECT_ALIGNED(raw256.void_data(), 256);
-
- AlignedMemory<8, 4096> raw4096;
- EXPECT_EQ(4096u, ALIGNOF(raw4096));
- EXPECT_ALIGNED(raw4096.void_data(), 4096);
-#endif // !(defined(OS_NACL) && defined(ARCH_CPU_X86_64))
-}
+namespace base {
TEST(AlignedMemoryTest, DynamicAllocation) {
- void* p = base::AlignedAlloc(8, 8);
+ void* p = AlignedAlloc(8, 8);
EXPECT_TRUE(p);
EXPECT_ALIGNED(p, 8);
- base::AlignedFree(p);
+ AlignedFree(p);
- p = base::AlignedAlloc(8, 16);
+ p = AlignedAlloc(8, 16);
EXPECT_TRUE(p);
EXPECT_ALIGNED(p, 16);
- base::AlignedFree(p);
+ AlignedFree(p);
- p = base::AlignedAlloc(8, 256);
+ p = AlignedAlloc(8, 256);
EXPECT_TRUE(p);
EXPECT_ALIGNED(p, 256);
- base::AlignedFree(p);
+ AlignedFree(p);
- p = base::AlignedAlloc(8, 4096);
+ p = AlignedAlloc(8, 4096);
EXPECT_TRUE(p);
EXPECT_ALIGNED(p, 4096);
- base::AlignedFree(p);
+ AlignedFree(p);
}
TEST(AlignedMemoryTest, ScopedDynamicAllocation) {
- std::unique_ptr<float, base::AlignedFreeDeleter> p(
- static_cast<float*>(base::AlignedAlloc(8, 8)));
+ std::unique_ptr<float, AlignedFreeDeleter> p(
+ static_cast<float*>(AlignedAlloc(8, 8)));
EXPECT_TRUE(p.get());
EXPECT_ALIGNED(p.get(), 8);
}
-} // namespace
+} // namespace base
« no previous file with comments | « base/memory/aligned_memory.h ('k') | base/memory/manual_constructor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698