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

Side by Side Diff: base/memory/aligned_memory_unittest.cc

Issue 10796020: Upgrade AlignedMemory to support dynamic allocations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix headers. Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/aligned_memory.h" 5 #include "base/memory/aligned_memory.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 #define EXPECT_ALIGNED(ptr, align) \ 9 #define EXPECT_ALIGNED(ptr, align) \
10 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) 10 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 EXPECT_ALIGNED(raw256.void_data(), 256); 44 EXPECT_ALIGNED(raw256.void_data(), 256);
45 45
46 // TODO(ios): This test hits an armv7 bug in clang. crbug.com/138066 46 // TODO(ios): This test hits an armv7 bug in clang. crbug.com/138066
47 #if !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY)) 47 #if !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY))
48 AlignedMemory<8, 4096> raw4096; 48 AlignedMemory<8, 4096> raw4096;
49 EXPECT_EQ(4096u, ALIGNOF(raw4096)); 49 EXPECT_EQ(4096u, ALIGNOF(raw4096));
50 EXPECT_ALIGNED(raw4096.void_data(), 4096); 50 EXPECT_ALIGNED(raw4096.void_data(), 4096);
51 #endif // !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY)) 51 #endif // !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY))
52 } 52 }
53 53
54 TEST(AlignedMemoryTest, DynamicAllocation) {
55 void* p = base::AlignedAlloc(8, 8);
56 EXPECT_TRUE(p);
57 EXPECT_ALIGNED(p, 8);
58 base::AlignedFree(p);
59
60 p = base::AlignedAlloc(8, 16);
61 EXPECT_TRUE(p);
62 EXPECT_ALIGNED(p, 16);
63 base::AlignedFree(p);
64
65 p = base::AlignedAlloc(8, 256);
66 EXPECT_TRUE(p);
67 EXPECT_ALIGNED(p, 256);
68 base::AlignedFree(p);
69
70 p = base::AlignedAlloc(8, 4096);
71 EXPECT_TRUE(p);
72 EXPECT_ALIGNED(p, 4096);
73 base::AlignedFree(p);
74 }
75
76 TEST(AlignedMemoryTest, ScopedDynamicAllocation) {
77 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> p(
78 reinterpret_cast<float*>(base::AlignedAlloc(8, 8)));
Jeffrey Yasskin 2012/07/23 18:34:40 static_cast here too.
DaleCurtis 2012/07/23 19:04:27 Done.
79 EXPECT_TRUE(p.get());
80 EXPECT_ALIGNED(p.get(), 8);
81 }
82
54 } // namespace 83 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698