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

Side by Side Diff: cc/base/contiguous_container_unittest.cc

Issue 2122573002: Correct alignment in ContiguousContainer::appendByMoving() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 0u Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/base/contiguous_container.h" 7 #include "cc/base/contiguous_container.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // Clearing should restore the capacity of the container to the same as a 504 // Clearing should restore the capacity of the container to the same as a
505 // newly allocated one (without reserved capacity requested). 505 // newly allocated one (without reserved capacity requested).
506 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 506 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
507 size_t empty_capacity = list.GetCapacityInBytes(); 507 size_t empty_capacity = list.GetCapacityInBytes();
508 list.AllocateAndConstruct<Point2D>(); 508 list.AllocateAndConstruct<Point2D>();
509 list.AllocateAndConstruct<Point2D>(); 509 list.AllocateAndConstruct<Point2D>();
510 list.Clear(); 510 list.Clear();
511 EXPECT_EQ(empty_capacity, list.GetCapacityInBytes()); 511 EXPECT_EQ(empty_capacity, list.GetCapacityInBytes());
512 } 512 }
513 513
514 TEST(ContiguousContainerTest, Alignment) {
515 const size_t max_align = ALIGNOF(long double);
516 ContiguousContainer<Point2D, max_align> list(kMaxPointSize);
517
518 list.AllocateAndConstruct<Point2D>();
519 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
520 list.AllocateAndConstruct<Point2D>();
521 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
522 list.AllocateAndConstruct<Point3D>();
523 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
524 list.AllocateAndConstruct<Point3D>();
525 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
526 list.AllocateAndConstruct<Point2D>();
527 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
528
529 list.AppendByMoving(&list[0], sizeof(Point2D));
530 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
531 list.AppendByMoving(&list[1], sizeof(Point2D));
532 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
533 list.AppendByMoving(&list[2], sizeof(Point3D));
534 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
535 list.AppendByMoving(&list[3], sizeof(Point3D));
536 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
537 list.AppendByMoving(&list[4], sizeof(Point2D));
538 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
539 }
540
514 } // namespace 541 } // namespace
515 } // namespace cc 542 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/contiguous_container.h ('k') | third_party/WebKit/Source/platform/graphics/ContiguousContainer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698