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

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

Issue 2776203002: Migrate WTF::Vector::remove() to ::erase() (Closed)
Patch Set: rebase, repatch VectorTest Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/web/ChromeClientImpl.cpp ('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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 intVector.push_back(1); 72 intVector.push_back(1);
73 intVector.push_back(2); 73 intVector.push_back(2);
74 intVector.push_back(3); 74 intVector.push_back(3);
75 75
76 EXPECT_EQ(4u, intVector.size()); 76 EXPECT_EQ(4u, intVector.size());
77 EXPECT_EQ(0, intVector[0]); 77 EXPECT_EQ(0, intVector[0]);
78 EXPECT_EQ(1, intVector[1]); 78 EXPECT_EQ(1, intVector[1]);
79 EXPECT_EQ(2, intVector[2]); 79 EXPECT_EQ(2, intVector[2]);
80 EXPECT_EQ(3, intVector[3]); 80 EXPECT_EQ(3, intVector[3]);
81 81
82 intVector.remove(2, 0); 82 intVector.erase(2, 0);
83 EXPECT_EQ(4u, intVector.size()); 83 EXPECT_EQ(4u, intVector.size());
84 EXPECT_EQ(2, intVector[2]); 84 EXPECT_EQ(2, intVector[2]);
85 85
86 intVector.remove(2, 1); 86 intVector.erase(2, 1);
87 EXPECT_EQ(3u, intVector.size()); 87 EXPECT_EQ(3u, intVector.size());
88 EXPECT_EQ(3, intVector[2]); 88 EXPECT_EQ(3, intVector[2]);
89 89
90 intVector.remove(0, 0); 90 intVector.erase(0, 0);
91 EXPECT_EQ(3u, intVector.size()); 91 EXPECT_EQ(3u, intVector.size());
92 EXPECT_EQ(0, intVector[0]); 92 EXPECT_EQ(0, intVector[0]);
93 93
94 intVector.remove(0); 94 intVector.erase(0);
95 EXPECT_EQ(2u, intVector.size()); 95 EXPECT_EQ(2u, intVector.size());
96 EXPECT_EQ(1, intVector[0]); 96 EXPECT_EQ(1, intVector[0]);
97 } 97 }
98 98
99 TEST(VectorTest, Iterator) { 99 TEST(VectorTest, Iterator) {
100 Vector<int> intVector; 100 Vector<int> intVector;
101 intVector.push_back(10); 101 intVector.push_back(10);
102 intVector.push_back(11); 102 intVector.push_back(11);
103 intVector.push_back(12); 103 intVector.push_back(12);
104 intVector.push_back(13); 104 intVector.push_back(13);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 EXPECT_EQ(0, destructNumber); 181 EXPECT_EQ(0, destructNumber);
182 182
183 for (index = 0; index < vector.size(); index++) { 183 for (index = 0; index < vector.size(); index++) {
184 std::unique_ptr<DestructCounter>& refCounter = vector[index]; 184 std::unique_ptr<DestructCounter>& refCounter = vector[index];
185 EXPECT_EQ(index, static_cast<size_t>(refCounter->get())); 185 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()));
186 } 186 }
187 EXPECT_EQ(0, destructNumber); 187 EXPECT_EQ(0, destructNumber);
188 188
189 EXPECT_EQ(0, vector[0]->get()); 189 EXPECT_EQ(0, vector[0]->get());
190 EXPECT_EQ(1, vector[1]->get()); 190 EXPECT_EQ(1, vector[1]->get());
191 vector.remove(0); 191 vector.erase(0);
192 EXPECT_EQ(1, vector[0]->get()); 192 EXPECT_EQ(1, vector[0]->get());
193 EXPECT_EQ(1u, vector.size()); 193 EXPECT_EQ(1u, vector.size());
194 EXPECT_EQ(1, destructNumber); 194 EXPECT_EQ(1, destructNumber);
195 195
196 std::unique_ptr<DestructCounter> ownCounter1 = std::move(vector[0]); 196 std::unique_ptr<DestructCounter> ownCounter1 = std::move(vector[0]);
197 vector.remove(0); 197 vector.erase(0);
198 ASSERT_EQ(counter1, ownCounter1->get()); 198 ASSERT_EQ(counter1, ownCounter1->get());
199 ASSERT_EQ(0u, vector.size()); 199 ASSERT_EQ(0u, vector.size());
200 ASSERT_EQ(1, destructNumber); 200 ASSERT_EQ(1, destructNumber);
201 201
202 ownCounter1.reset(); 202 ownCounter1.reset();
203 EXPECT_EQ(2, destructNumber); 203 EXPECT_EQ(2, destructNumber);
204 204
205 size_t count = 1025; 205 size_t count = 1025;
206 destructNumber = 0; 206 destructNumber = 0;
207 for (size_t i = 0; i < count; i++) 207 for (size_t i = 0; i < count; i++)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 TEST(VectorTest, MoveOnlyType) { 245 TEST(VectorTest, MoveOnlyType) {
246 WTF::Vector<MoveOnly> vector; 246 WTF::Vector<MoveOnly> vector;
247 vector.push_back(MoveOnly(1)); 247 vector.push_back(MoveOnly(1));
248 vector.push_back(MoveOnly(2)); 248 vector.push_back(MoveOnly(2));
249 EXPECT_EQ(2u, vector.size()); 249 EXPECT_EQ(2u, vector.size());
250 250
251 ASSERT_EQ(1, vector.front().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.erase(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.erase(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());
262 262
263 size_t count = vector.capacity() + 1; 263 size_t count = vector.capacity() + 1;
264 for (size_t i = 0; i < count; i++) 264 for (size_t i = 0; i < count; i++)
265 vector.push_back( 265 vector.push_back(
266 MoveOnly(i + 1)); // +1 to distinguish from default-constructed. 266 MoveOnly(i + 1)); // +1 to distinguish from default-constructed.
267 267
268 // Reallocation did not affect the vector's content. 268 // Reallocation did not affect the vector's content.
269 EXPECT_EQ(count, vector.size()); 269 EXPECT_EQ(count, vector.size());
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 unsigned size2 = vector2.size(); 515 unsigned size2 = vector2.size();
516 516
517 for (unsigned k = 0; k < 5; k++) { 517 for (unsigned k = 0; k < 5; k++) {
518 vector.swap(vector2); 518 vector.swap(vector2);
519 std::swap(size, size2); 519 std::swap(size, size2);
520 EXPECT_EQ(i + j, LivenessCounter::s_live); 520 EXPECT_EQ(i + j, LivenessCounter::s_live);
521 EXPECT_EQ(size, vector.size()); 521 EXPECT_EQ(size, vector.size());
522 EXPECT_EQ(size2, vector2.size()); 522 EXPECT_EQ(size2, vector2.size());
523 523
524 vector2.push_back(&counter); 524 vector2.push_back(&counter);
525 vector2.remove(0); 525 vector2.erase(0);
526 } 526 }
527 } 527 }
528 } 528 }
529 } 529 }
530 530
531 TEST(VectorTest, SwapWithConstructorsAndDestructors) { 531 TEST(VectorTest, SwapWithConstructorsAndDestructors) {
532 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<0>(); 532 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<0>();
533 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<2>(); 533 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<2>();
534 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<10>(); 534 testDestructorAndConstructorCallsWhenSwappingWithInlineCapacity<10>();
535 } 535 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 EXPECT_EQ(0, *vector[0]); 577 EXPECT_EQ(0, *vector[0]);
578 EXPECT_EQ(1, *vector[1]); 578 EXPECT_EQ(1, *vector[1]);
579 EXPECT_EQ(2, *vector[2]); 579 EXPECT_EQ(2, *vector[2]);
580 EXPECT_EQ(3, *vector[3]); 580 EXPECT_EQ(3, *vector[3]);
581 581
582 vector.shrink(3); 582 vector.shrink(3);
583 EXPECT_EQ(3u, vector.size()); 583 EXPECT_EQ(3u, vector.size());
584 vector.grow(4); 584 vector.grow(4);
585 ASSERT_EQ(4u, vector.size()); 585 ASSERT_EQ(4u, vector.size());
586 EXPECT_TRUE(!vector[3]); 586 EXPECT_TRUE(!vector[3]);
587 vector.remove(3); 587 vector.erase(3);
588 vector[0] = Pointer(new int(-1)); 588 vector[0] = Pointer(new int(-1));
589 ASSERT_EQ(3u, vector.size()); 589 ASSERT_EQ(3u, vector.size());
590 EXPECT_EQ(-1, *vector[0]); 590 EXPECT_EQ(-1, *vector[0]);
591 } 591 }
592 592
593 bool isOneTwoThree(const Vector<int>& vector) { 593 bool isOneTwoThree(const Vector<int>& vector) {
594 return vector.size() == 3 && vector[0] == 1 && vector[1] == 2 && 594 return vector.size() == 3 && vector[0] == 1 && vector[1] == 2 &&
595 vector[2] == 3; 595 vector[2] == 3;
596 } 596 }
597 597
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, 716 static_assert(VectorTraits<UChar>::canCopyWithMemcpy,
717 "UChar should be copied with memcpy."); 717 "UChar should be copied with memcpy.");
718 718
719 class UnknownType; 719 class UnknownType;
720 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, 720 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy,
721 "Pointers should be copied with memcpy."); 721 "Pointers should be copied with memcpy.");
722 722
723 } // anonymous namespace 723 } // anonymous namespace
724 724
725 } // namespace WTF 725 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ChromeClientImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698