OLD | NEW |
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 "platform/graphics/ContiguousContainer.h" | 5 #include "platform/graphics/ContiguousContainer.h" |
6 | 6 |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "wtf/TypeTraits.h" | 9 #include "wtf/TypeTraits.h" |
10 | 10 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 list.allocateAndConstruct<Point2D>(); | 197 list.allocateAndConstruct<Point2D>(); |
198 EXPECT_FALSE(list.isEmpty()); | 198 EXPECT_FALSE(list.isEmpty()); |
199 EXPECT_EQ(1u, list.size()); | 199 EXPECT_EQ(1u, list.size()); |
200 } | 200 } |
201 | 201 |
202 TEST(ContiguousContainerTest, ElementAddressesAreStable) { | 202 TEST(ContiguousContainerTest, ElementAddressesAreStable) { |
203 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 203 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
204 Vector<Point2D*> pointers; | 204 Vector<Point2D*> pointers; |
205 for (int i = 0; i < (int)kNumElements; i++) | 205 for (int i = 0; i < (int)kNumElements; i++) |
206 pointers.append(&list.allocateAndConstruct<Point2D>()); | 206 pointers.push_back(&list.allocateAndConstruct<Point2D>()); |
207 EXPECT_EQ(kNumElements, list.size()); | 207 EXPECT_EQ(kNumElements, list.size()); |
208 EXPECT_EQ(kNumElements, pointers.size()); | 208 EXPECT_EQ(kNumElements, pointers.size()); |
209 | 209 |
210 auto listIt = list.begin(); | 210 auto listIt = list.begin(); |
211 auto vectorIt = pointers.begin(); | 211 auto vectorIt = pointers.begin(); |
212 for (; listIt != list.end(); ++listIt, ++vectorIt) | 212 for (; listIt != list.end(); ++listIt, ++vectorIt) |
213 EXPECT_EQ(&*listIt, *vectorIt); | 213 EXPECT_EQ(&*listIt, *vectorIt); |
214 } | 214 } |
215 | 215 |
216 TEST(ContiguousContainerTest, ForwardIteration) { | 216 TEST(ContiguousContainerTest, ForwardIteration) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 struct SmallStruct { | 276 struct SmallStruct { |
277 char dummy[16]; | 277 char dummy[16]; |
278 }; | 278 }; |
279 ContiguousContainer<SmallStruct> list(sizeof(SmallStruct), | 279 ContiguousContainer<SmallStruct> list(sizeof(SmallStruct), |
280 1 * sizeof(SmallStruct)); | 280 1 * sizeof(SmallStruct)); |
281 Vector<SmallStruct*> pointers; | 281 Vector<SmallStruct*> pointers; |
282 | 282 |
283 // Utilities which keep these two lists in sync and check that their | 283 // Utilities which keep these two lists in sync and check that their |
284 // iteration order matches. | 284 // iteration order matches. |
285 auto push = [&list, &pointers]() { | 285 auto push = [&list, &pointers]() { |
286 pointers.append(&list.allocateAndConstruct<SmallStruct>()); | 286 pointers.push_back(&list.allocateAndConstruct<SmallStruct>()); |
287 }; | 287 }; |
288 auto pop = [&list, &pointers]() { | 288 auto pop = [&list, &pointers]() { |
289 pointers.pop_back(); | 289 pointers.pop_back(); |
290 list.removeLast(); | 290 list.removeLast(); |
291 }; | 291 }; |
292 auto check_equal = [&list, &pointers]() { | 292 auto check_equal = [&list, &pointers]() { |
293 // They should be of the same size, and compare equal with all four | 293 // They should be of the same size, and compare equal with all four |
294 // kinds of iteration. | 294 // kinds of iteration. |
295 const auto& constList = list; | 295 const auto& constList = list; |
296 const auto& constPointers = pointers; | 296 const auto& constPointers = pointers; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 list.appendByMoving(list[2], sizeof(Point3D)); | 533 list.appendByMoving(list[2], sizeof(Point3D)); |
534 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); | 534 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
535 list.appendByMoving(list[3], sizeof(Point3D)); | 535 list.appendByMoving(list[3], sizeof(Point3D)); |
536 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); | 536 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
537 list.appendByMoving(list[4], sizeof(Point2D)); | 537 list.appendByMoving(list[4], sizeof(Point2D)); |
538 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); | 538 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (maxAlign - 1)); |
539 } | 539 } |
540 | 540 |
541 } // namespace | 541 } // namespace |
542 } // namespace blink | 542 } // namespace blink |
OLD | NEW |