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

Side by Side Diff: third_party/WebKit/Source/wtf/VectorTest.cpp

Issue 2470233009: WTF/std normalization: replace WTF::Vector::first() with ::front() (Closed)
Patch Set: rebase Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 typedef WTF::Vector<std::unique_ptr<DestructCounter>> OwnPtrVector; 158 typedef WTF::Vector<std::unique_ptr<DestructCounter>> OwnPtrVector;
159 159
160 TEST(VectorTest, OwnPtr) { 160 TEST(VectorTest, OwnPtr) {
161 int destructNumber = 0; 161 int destructNumber = 0;
162 OwnPtrVector vector; 162 OwnPtrVector vector;
163 vector.append(wrapUnique(new DestructCounter(0, &destructNumber))); 163 vector.append(wrapUnique(new DestructCounter(0, &destructNumber)));
164 vector.append(wrapUnique(new DestructCounter(1, &destructNumber))); 164 vector.append(wrapUnique(new DestructCounter(1, &destructNumber)));
165 EXPECT_EQ(2u, vector.size()); 165 EXPECT_EQ(2u, vector.size());
166 166
167 std::unique_ptr<DestructCounter>& counter0 = vector.first(); 167 std::unique_ptr<DestructCounter>& counter0 = vector.front();
168 ASSERT_EQ(0, counter0->get()); 168 ASSERT_EQ(0, counter0->get());
169 int counter1 = vector.back()->get(); 169 int counter1 = vector.back()->get();
170 ASSERT_EQ(1, counter1); 170 ASSERT_EQ(1, counter1);
171 ASSERT_EQ(0, destructNumber); 171 ASSERT_EQ(0, destructNumber);
172 172
173 size_t index = 0; 173 size_t index = 0;
174 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end(); 174 for (OwnPtrVector::iterator iter = vector.begin(); iter != vector.end();
175 ++iter) { 175 ++iter) {
176 std::unique_ptr<DestructCounter>* refCounter = iter; 176 std::unique_ptr<DestructCounter>* refCounter = iter;
177 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get())); 177 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()->get()));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 WTF_MAKE_NONCOPYABLE(MoveOnly); 241 WTF_MAKE_NONCOPYABLE(MoveOnly);
242 int m_i; 242 int m_i;
243 }; 243 };
244 244
245 TEST(VectorTest, MoveOnlyType) { 245 TEST(VectorTest, MoveOnlyType) {
246 WTF::Vector<MoveOnly> vector; 246 WTF::Vector<MoveOnly> vector;
247 vector.append(MoveOnly(1)); 247 vector.append(MoveOnly(1));
248 vector.append(MoveOnly(2)); 248 vector.append(MoveOnly(2));
249 EXPECT_EQ(2u, vector.size()); 249 EXPECT_EQ(2u, vector.size());
250 250
251 ASSERT_EQ(1, vector.first().value()); 251 ASSERT_EQ(1, vector.front().value());
252 ASSERT_EQ(2, vector.back().value()); 252 ASSERT_EQ(2, vector.back().value());
253 253
254 vector.remove(0); 254 vector.remove(0);
255 EXPECT_EQ(2, vector[0].value()); 255 EXPECT_EQ(2, vector[0].value());
256 EXPECT_EQ(1u, vector.size()); 256 EXPECT_EQ(1u, vector.size());
257 257
258 MoveOnly moveOnly(std::move(vector[0])); 258 MoveOnly moveOnly(std::move(vector[0]));
259 vector.remove(0); 259 vector.remove(0);
260 ASSERT_EQ(2, moveOnly.value()); 260 ASSERT_EQ(2, moveOnly.value());
261 ASSERT_EQ(0u, vector.size()); 261 ASSERT_EQ(0u, vector.size());
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 compare<WTF::String>(); 422 compare<WTF::String>();
423 } 423 }
424 424
425 TEST(VectorTest, AppendFirst) { 425 TEST(VectorTest, AppendFirst) {
426 Vector<WTF::String> vector; 426 Vector<WTF::String> vector;
427 vector.append("string"); 427 vector.append("string");
428 // Test passes if it does not crash (reallocation did not make 428 // Test passes if it does not crash (reallocation did not make
429 // the input reference stale). 429 // the input reference stale).
430 size_t limit = vector.capacity() + 1; 430 size_t limit = vector.capacity() + 1;
431 for (size_t i = 0; i < limit; i++) 431 for (size_t i = 0; i < limit; i++)
432 vector.append(vector.first()); 432 vector.append(vector.front());
433 433
434 limit = vector.capacity() + 1; 434 limit = vector.capacity() + 1;
435 for (size_t i = 0; i < limit; i++) 435 for (size_t i = 0; i < limit; i++)
436 vector.append(const_cast<const WTF::String&>(vector.first())); 436 vector.append(const_cast<const WTF::String&>(vector.front()));
437 } 437 }
438 438
439 // The test below is for the following issue: 439 // The test below is for the following issue:
440 // 440 //
441 // https://bugs.chromium.org/p/chromium/issues/detail?id=592767 441 // https://bugs.chromium.org/p/chromium/issues/detail?id=592767
442 // 442 //
443 // where deleted copy assignment operator made canMoveWithMemcpy true because 443 // where deleted copy assignment operator made canMoveWithMemcpy true because
444 // of the implementation of IsTriviallyMoveAssignable<T>. 444 // of the implementation of IsTriviallyMoveAssignable<T>.
445 445
446 class MojoMoveOnlyType final { 446 class MojoMoveOnlyType final {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, 699 static_assert(VectorTraits<UChar>::canCopyWithMemcpy,
700 "UChar should be copied with memcpy."); 700 "UChar should be copied with memcpy.");
701 701
702 class UnknownType; 702 class UnknownType;
703 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, 703 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy,
704 "Pointers should be copied with memcpy."); 704 "Pointers should be copied with memcpy.");
705 705
706 } // anonymous namespace 706 } // anonymous namespace
707 707
708 } // namespace WTF 708 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698