| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/ContiguousContainer.h" | 6 #include "platform/graphics/ContiguousContainer.h" |
| 7 | 7 |
| 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 #include "wtf/TypeTraits.h" | 10 #include "wtf/TypeTraits.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 227 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
| 228 for (int i = 0; i < (int)kNumElements; i++) | 228 for (int i = 0; i < (int)kNumElements; i++) |
| 229 list.allocateAndConstruct<Point2D>(i, i); | 229 list.allocateAndConstruct<Point2D>(i, i); |
| 230 unsigned count = 0; | 230 unsigned count = 0; |
| 231 for (Point2D& point : list) { | 231 for (Point2D& point : list) { |
| 232 EXPECT_EQ((int)count, point.x); | 232 EXPECT_EQ((int)count, point.x); |
| 233 count++; | 233 count++; |
| 234 } | 234 } |
| 235 EXPECT_EQ(kNumElements, count); | 235 EXPECT_EQ(kNumElements, count); |
| 236 | 236 |
| 237 static_assert(WTF::IsSameType<decltype(*list.begin()), Point2D&>::value, | 237 static_assert(std::is_same<decltype(*list.begin()), Point2D&>::value, |
| 238 "Non-const iteration should produce non-const references."); | 238 "Non-const iteration should produce non-const references."); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST(ContiguousContainerTest, ConstForwardIteration) | 241 TEST(ContiguousContainerTest, ConstForwardIteration) |
| 242 { | 242 { |
| 243 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 243 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
| 244 for (int i = 0; i < (int)kNumElements; i++) | 244 for (int i = 0; i < (int)kNumElements; i++) |
| 245 list.allocateAndConstruct<Point2D>(i, i); | 245 list.allocateAndConstruct<Point2D>(i, i); |
| 246 | 246 |
| 247 const auto& constList = list; | 247 const auto& constList = list; |
| 248 unsigned count = 0; | 248 unsigned count = 0; |
| 249 for (const Point2D& point : constList) { | 249 for (const Point2D& point : constList) { |
| 250 EXPECT_EQ((int)count, point.x); | 250 EXPECT_EQ((int)count, point.x); |
| 251 count++; | 251 count++; |
| 252 } | 252 } |
| 253 EXPECT_EQ(kNumElements, count); | 253 EXPECT_EQ(kNumElements, count); |
| 254 | 254 |
| 255 static_assert(WTF::IsSameType<decltype(*constList.begin()), const Point2D&>:
:value, | 255 static_assert(std::is_same<decltype(*constList.begin()), const Point2D&>::va
lue, |
| 256 "Const iteration should produce const references."); | 256 "Const iteration should produce const references."); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST(ContiguousContainerTest, ReverseIteration) | 259 TEST(ContiguousContainerTest, ReverseIteration) |
| 260 { | 260 { |
| 261 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 261 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
| 262 for (int i = 0; i < (int)kNumElements; i++) | 262 for (int i = 0; i < (int)kNumElements; i++) |
| 263 list.allocateAndConstruct<Point2D>(i, i); | 263 list.allocateAndConstruct<Point2D>(i, i); |
| 264 | 264 |
| 265 unsigned count = 0; | 265 unsigned count = 0; |
| 266 for (auto it = list.rbegin(); it != list.rend(); ++it) { | 266 for (auto it = list.rbegin(); it != list.rend(); ++it) { |
| 267 EXPECT_EQ((int)(kNumElements - 1 - count), it->x); | 267 EXPECT_EQ((int)(kNumElements - 1 - count), it->x); |
| 268 count++; | 268 count++; |
| 269 } | 269 } |
| 270 EXPECT_EQ(kNumElements, count); | 270 EXPECT_EQ(kNumElements, count); |
| 271 | 271 |
| 272 static_assert(WTF::IsSameType<decltype(*list.rbegin()), Point2D&>::value, | 272 static_assert(std::is_same<decltype(*list.rbegin()), Point2D&>::value, |
| 273 "Non-const iteration should produce non-const references."); | 273 "Non-const iteration should produce non-const references."); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Checks that the latter list has pointers to the elements of the former. | 276 // Checks that the latter list has pointers to the elements of the former. |
| 277 template <typename It1, typename It2> | 277 template <typename It1, typename It2> |
| 278 bool EqualPointers(It1 it1, const It1& end1, It2 it2) | 278 bool EqualPointers(It1 it1, const It1& end1, It2 it2) |
| 279 { | 279 { |
| 280 for (; it1 != end1; ++it1, ++it2) { | 280 for (; it1 != end1; ++it1, ++it2) { |
| 281 if (&*it1 != *it2) | 281 if (&*it1 != *it2) |
| 282 return false; | 282 return false; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); | 520 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); |
| 521 size_t emptyCapacity = list.capacityInBytes(); | 521 size_t emptyCapacity = list.capacityInBytes(); |
| 522 list.allocateAndConstruct<Point2D>(); | 522 list.allocateAndConstruct<Point2D>(); |
| 523 list.allocateAndConstruct<Point2D>(); | 523 list.allocateAndConstruct<Point2D>(); |
| 524 list.clear(); | 524 list.clear(); |
| 525 EXPECT_EQ(emptyCapacity, list.capacityInBytes()); | 525 EXPECT_EQ(emptyCapacity, list.capacityInBytes()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 } // namespace | 528 } // namespace |
| 529 } // namespace blink | 529 } // namespace blink |
| OLD | NEW |