Chromium Code Reviews| Index: base/memory/singleton_unittest.cc |
| diff --git a/base/memory/singleton_unittest.cc b/base/memory/singleton_unittest.cc |
| index 068148ff76b75e5e25f9f02ff1ddc802e93591d8..30580483188b66799e5ba3e0350505f41f8fbdf0 100644 |
| --- a/base/memory/singleton_unittest.cc |
| +++ b/base/memory/singleton_unittest.cc |
| @@ -110,6 +110,19 @@ struct CallbackSingletonWithStaticTrait::Trait |
| } |
| }; |
| +template <class Type> |
| +class AlignedTestSingleton { |
| + public: |
| + AlignedTestSingleton() {} |
| + ~AlignedTestSingleton() {} |
| + static AlignedTestSingleton* GetInstance() { |
| + return Singleton<AlignedTestSingleton, |
| + StaticMemorySingletonTraits<AlignedTestSingleton> >::get(); |
| + } |
| + |
| + Type type_; |
| +}; |
| + |
| void SingletonNoLeak(CallbackFunc CallOnQuit) { |
| CallbackSingletonWithNoLeakTrait::GetInstance()->callback_ = CallOnQuit; |
| @@ -250,3 +263,27 @@ TEST_F(SingletonTest, Basic) { |
| // The leaky singleton shouldn't leak since SingletonLeak has not been called. |
| VerifiesCallbacksNotCalled(); |
| } |
| + |
| +#define EXPECT_ALIGNED(ptr, align) \ |
| + EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) |
| + |
| +TEST_F(SingletonTest, Alignment) { |
| + using base::RawAlignedMemory; |
| + |
| + // Create some static singletons with increasing sizes and alignment |
| + // requirements. By ordering this way, the linker will need to do some work to |
| + // ensure proper alignment of the static data. |
| + AlignedTestSingleton<int32>* align4 = |
| + AlignedTestSingleton<int32>::GetInstance(); |
| + AlignedTestSingleton<RawAlignedMemory<32, 32> >* align32 = |
| + AlignedTestSingleton<RawAlignedMemory<32, 32> >::GetInstance(); |
| + AlignedTestSingleton<RawAlignedMemory<128, 128> >* align128 = |
| + AlignedTestSingleton<RawAlignedMemory<128, 128> >::GetInstance(); |
| + AlignedTestSingleton<RawAlignedMemory<4096, 4096> >* align4096 = |
| + AlignedTestSingleton<RawAlignedMemory<4096, 4096> >::GetInstance(); |
| + |
| + EXPECT_ALIGNED(align4, 4); |
|
willchan no longer on Chromium
2012/02/23 01:18:41
Again it's reversed here.
jbates
2012/02/23 02:23:53
The macro is defined above to call EXPECT_EQ prope
|
| + EXPECT_ALIGNED(align32, 32); |
| + EXPECT_ALIGNED(align128, 128); |
| + EXPECT_ALIGNED(align4096, 4096); |
| +} |