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

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

Issue 2932053002: Use C++11 alignment primitives (Closed)
Patch Set: Put back ALIGNAS 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 unified diff | Download patch
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 <stdint.h> 5 #include <stdint.h>
6 #include <type_traits>
6 7
7 #include "base/at_exit.h" 8 #include "base/at_exit.h"
8 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 namespace { 13 namespace {
13 14
14 static_assert(DefaultSingletonTraits<int>::kRegisterAtExit == true, 15 static_assert(DefaultSingletonTraits<int>::kRegisterAtExit == true,
15 "object must be deleted on process exit"); 16 "object must be deleted on process exit");
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 263 }
263 } 264 }
264 // The leaky singleton shouldn't leak since SingletonLeak has not been called. 265 // The leaky singleton shouldn't leak since SingletonLeak has not been called.
265 VerifiesCallbacksNotCalled(); 266 VerifiesCallbacksNotCalled();
266 } 267 }
267 268
268 #define EXPECT_ALIGNED(ptr, align) \ 269 #define EXPECT_ALIGNED(ptr, align) \
269 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) 270 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
270 271
271 TEST_F(SingletonTest, Alignment) { 272 TEST_F(SingletonTest, Alignment) {
272 using base::AlignedMemory;
273
274 // Create some static singletons with increasing sizes and alignment 273 // Create some static singletons with increasing sizes and alignment
275 // requirements. By ordering this way, the linker will need to do some work to 274 // requirements. By ordering this way, the linker will need to do some work to
276 // ensure proper alignment of the static data. 275 // ensure proper alignment of the static data.
277 AlignedTestSingleton<int32_t>* align4 = 276 AlignedTestSingleton<int32_t>* align4 =
278 AlignedTestSingleton<int32_t>::GetInstance(); 277 AlignedTestSingleton<int32_t>::GetInstance();
279 AlignedTestSingleton<AlignedMemory<32, 32> >* align32 = 278 AlignedTestSingleton<std::aligned_storage<32, 32>::type>* align32 =
280 AlignedTestSingleton<AlignedMemory<32, 32> >::GetInstance(); 279 AlignedTestSingleton<std::aligned_storage<32, 32>::type>::GetInstance();
281 AlignedTestSingleton<AlignedMemory<128, 128> >* align128 = 280 AlignedTestSingleton<std::aligned_storage<128, 128>::type>* align128 =
282 AlignedTestSingleton<AlignedMemory<128, 128> >::GetInstance(); 281 AlignedTestSingleton<std::aligned_storage<128, 128>::type>::GetInstance();
283 AlignedTestSingleton<AlignedMemory<4096, 4096> >* align4096 = 282 AlignedTestSingleton<std::aligned_storage<4096, 4096>::type>* align4096 =
284 AlignedTestSingleton<AlignedMemory<4096, 4096> >::GetInstance(); 283 AlignedTestSingleton<
284 std::aligned_storage<4096, 4096>::type>::GetInstance();
285 285
286 EXPECT_ALIGNED(align4, 4); 286 EXPECT_ALIGNED(align4, 4);
287 EXPECT_ALIGNED(align32, 32); 287 EXPECT_ALIGNED(align32, 32);
288 EXPECT_ALIGNED(align128, 128); 288 EXPECT_ALIGNED(align128, 128);
289 EXPECT_ALIGNED(align4096, 4096); 289 EXPECT_ALIGNED(align4096, 4096);
290 } 290 }
291 291
292 } // namespace 292 } // namespace
293 } // namespace base 293 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698