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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ContiguousContainerTest.cpp

Issue 1477213003: More switching to standard type traits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Excluded WTF::IsSubclass from the patch Created 4 years, 11 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 "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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 226 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
227 for (int i = 0; i < (int)kNumElements; i++) 227 for (int i = 0; i < (int)kNumElements; i++)
228 list.allocateAndConstruct<Point2D>(i, i); 228 list.allocateAndConstruct<Point2D>(i, i);
229 unsigned count = 0; 229 unsigned count = 0;
230 for (Point2D& point : list) { 230 for (Point2D& point : list) {
231 EXPECT_EQ((int)count, point.x); 231 EXPECT_EQ((int)count, point.x);
232 count++; 232 count++;
233 } 233 }
234 EXPECT_EQ(kNumElements, count); 234 EXPECT_EQ(kNumElements, count);
235 235
236 static_assert(WTF::IsSameType<decltype(*list.begin()), Point2D&>::value, 236 static_assert(std::is_same<decltype(*list.begin()), Point2D&>::value,
237 "Non-const iteration should produce non-const references."); 237 "Non-const iteration should produce non-const references.");
238 } 238 }
239 239
240 TEST(ContiguousContainerTest, ConstForwardIteration) 240 TEST(ContiguousContainerTest, ConstForwardIteration)
241 { 241 {
242 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 242 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
243 for (int i = 0; i < (int)kNumElements; i++) 243 for (int i = 0; i < (int)kNumElements; i++)
244 list.allocateAndConstruct<Point2D>(i, i); 244 list.allocateAndConstruct<Point2D>(i, i);
245 245
246 const auto& constList = list; 246 const auto& constList = list;
247 unsigned count = 0; 247 unsigned count = 0;
248 for (const Point2D& point : constList) { 248 for (const Point2D& point : constList) {
249 EXPECT_EQ((int)count, point.x); 249 EXPECT_EQ((int)count, point.x);
250 count++; 250 count++;
251 } 251 }
252 EXPECT_EQ(kNumElements, count); 252 EXPECT_EQ(kNumElements, count);
253 253
254 static_assert(WTF::IsSameType<decltype(*constList.begin()), const Point2D&>: :value, 254 static_assert(std::is_same<decltype(*constList.begin()), const Point2D&>::va lue,
255 "Const iteration should produce const references."); 255 "Const iteration should produce const references.");
256 } 256 }
257 257
258 TEST(ContiguousContainerTest, ReverseIteration) 258 TEST(ContiguousContainerTest, ReverseIteration)
259 { 259 {
260 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 260 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
261 for (int i = 0; i < (int)kNumElements; i++) 261 for (int i = 0; i < (int)kNumElements; i++)
262 list.allocateAndConstruct<Point2D>(i, i); 262 list.allocateAndConstruct<Point2D>(i, i);
263 263
264 unsigned count = 0; 264 unsigned count = 0;
265 for (auto it = list.rbegin(); it != list.rend(); ++it) { 265 for (auto it = list.rbegin(); it != list.rend(); ++it) {
266 EXPECT_EQ((int)(kNumElements - 1 - count), it->x); 266 EXPECT_EQ((int)(kNumElements - 1 - count), it->x);
267 count++; 267 count++;
268 } 268 }
269 EXPECT_EQ(kNumElements, count); 269 EXPECT_EQ(kNumElements, count);
270 270
271 static_assert(WTF::IsSameType<decltype(*list.rbegin()), Point2D&>::value, 271 static_assert(std::is_same<decltype(*list.rbegin()), Point2D&>::value,
272 "Non-const iteration should produce non-const references."); 272 "Non-const iteration should produce non-const references.");
273 } 273 }
274 274
275 // Checks that the latter list has pointers to the elements of the former. 275 // Checks that the latter list has pointers to the elements of the former.
276 template <typename It1, typename It2> 276 template <typename It1, typename It2>
277 bool EqualPointers(It1 it1, const It1& end1, It2 it2) 277 bool EqualPointers(It1 it1, const It1& end1, It2 it2)
278 { 278 {
279 for (; it1 != end1; ++it1, ++it2) { 279 for (; it1 != end1; ++it1, ++it2) {
280 if (&*it1 != *it2) 280 if (&*it1 != *it2)
281 return false; 281 return false;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 519 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
520 size_t emptyCapacity = list.capacityInBytes(); 520 size_t emptyCapacity = list.capacityInBytes();
521 list.allocateAndConstruct<Point2D>(); 521 list.allocateAndConstruct<Point2D>();
522 list.allocateAndConstruct<Point2D>(); 522 list.allocateAndConstruct<Point2D>();
523 list.clear(); 523 list.clear();
524 EXPECT_EQ(emptyCapacity, list.capacityInBytes()); 524 EXPECT_EQ(emptyCapacity, list.capacityInBytes());
525 } 525 }
526 526
527 } // namespace 527 } // namespace
528 } // namespace blink 528 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/TraceEvent.h ('k') | third_party/WebKit/Source/platform/heap/GCInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698