| OLD | NEW |
| 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 |
| 7 #include <memory> |
| 8 |
| 7 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 11 |
| 10 #define EXPECT_ALIGNED(ptr, align) \ | 12 #define EXPECT_ALIGNED(ptr, align) \ |
| 11 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) | 13 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 using base::AlignedMemory; | 17 using base::AlignedMemory; |
| 16 | 18 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 EXPECT_ALIGNED(p, 256); | 87 EXPECT_ALIGNED(p, 256); |
| 86 base::AlignedFree(p); | 88 base::AlignedFree(p); |
| 87 | 89 |
| 88 p = base::AlignedAlloc(8, 4096); | 90 p = base::AlignedAlloc(8, 4096); |
| 89 EXPECT_TRUE(p); | 91 EXPECT_TRUE(p); |
| 90 EXPECT_ALIGNED(p, 4096); | 92 EXPECT_ALIGNED(p, 4096); |
| 91 base::AlignedFree(p); | 93 base::AlignedFree(p); |
| 92 } | 94 } |
| 93 | 95 |
| 94 TEST(AlignedMemoryTest, ScopedDynamicAllocation) { | 96 TEST(AlignedMemoryTest, ScopedDynamicAllocation) { |
| 95 scoped_ptr<float, base::AlignedFreeDeleter> p( | 97 std::unique_ptr<float, base::AlignedFreeDeleter> p( |
| 96 static_cast<float*>(base::AlignedAlloc(8, 8))); | 98 static_cast<float*>(base::AlignedAlloc(8, 8))); |
| 97 EXPECT_TRUE(p.get()); | 99 EXPECT_TRUE(p.get()); |
| 98 EXPECT_ALIGNED(p.get(), 8); | 100 EXPECT_ALIGNED(p.get(), 8); |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| OLD | NEW |