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

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

Issue 2725063003: Migrate WTF::LinkedHashSet/ListHashSet/HashTable::remove() to ::erase() (Closed)
Patch Set: rebase Created 3 years, 9 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/wtf/ListHashSet.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) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 set.insertBefore(it, 1); 240 set.insertBefore(it, 1);
241 if (!canModifyWhileIterating) 241 if (!canModifyWhileIterating)
242 it = set.find(2); 242 it = set.find(2);
243 ++it; 243 ++it;
244 EXPECT_EQ(3, *it); 244 EXPECT_EQ(3, *it);
245 EXPECT_EQ(5u, set.size()); 245 EXPECT_EQ(5u, set.size());
246 --it; 246 --it;
247 --it; 247 --it;
248 EXPECT_EQ(1, *it); 248 EXPECT_EQ(1, *it);
249 if (canModifyWhileIterating) { 249 if (canModifyWhileIterating) {
250 set.remove(-1); 250 set.erase(-1);
251 set.remove(0); 251 set.erase(0);
252 set.remove(2); 252 set.erase(2);
253 set.remove(3); 253 set.erase(3);
254 EXPECT_EQ(1u, set.size()); 254 EXPECT_EQ(1u, set.size());
255 EXPECT_EQ(1, *it); 255 EXPECT_EQ(1, *it);
256 ++it; 256 ++it;
257 EXPECT_EQ(it, set.end()); 257 EXPECT_EQ(it, set.end());
258 --it; 258 --it;
259 EXPECT_EQ(1, *it); 259 EXPECT_EQ(1, *it);
260 set.insertBefore(it, -1); 260 set.insertBefore(it, -1);
261 set.insertBefore(it, 0); 261 set.insertBefore(it, 0);
262 set.insert(2); 262 set.insert(2);
263 set.insert(3); 263 set.insert(3);
(...skipping 21 matching lines...) Expand all
285 EXPECT_EQ(3, *it); 285 EXPECT_EQ(3, *it);
286 --it; 286 --it;
287 EXPECT_EQ(2, *it); 287 EXPECT_EQ(2, *it);
288 EXPECT_EQ(5u, set.size()); 288 EXPECT_EQ(5u, set.size());
289 --it; 289 --it;
290 EXPECT_EQ(1, *it); 290 EXPECT_EQ(1, *it);
291 --it; 291 --it;
292 EXPECT_EQ(0, *it); 292 EXPECT_EQ(0, *it);
293 it = set.addReturnIterator(4); 293 it = set.addReturnIterator(4);
294 if (canModifyWhileIterating) { 294 if (canModifyWhileIterating) {
295 set.remove(3); 295 set.erase(3);
296 set.remove(2); 296 set.erase(2);
297 set.remove(1); 297 set.erase(1);
298 set.remove(0); 298 set.erase(0);
299 set.remove(-1); 299 set.erase(-1);
300 EXPECT_EQ(1u, set.size()); 300 EXPECT_EQ(1u, set.size());
301 } 301 }
302 EXPECT_EQ(4, *it); 302 EXPECT_EQ(4, *it);
303 ++it; 303 ++it;
304 EXPECT_EQ(it, set.end()); 304 EXPECT_EQ(it, set.end());
305 --it; 305 --it;
306 EXPECT_EQ(4, *it); 306 EXPECT_EQ(4, *it);
307 if (canModifyWhileIterating) { 307 if (canModifyWhileIterating) {
308 set.insertBefore(it, -1); 308 set.insertBefore(it, -1);
309 set.insertBefore(it, 0); 309 set.insertBefore(it, 0);
310 set.insertBefore(it, 1); 310 set.insertBefore(it, 1);
311 set.insertBefore(it, 2); 311 set.insertBefore(it, 2);
312 set.insertBefore(it, 3); 312 set.insertBefore(it, 3);
313 } 313 }
314 EXPECT_EQ(6u, set.size()); 314 EXPECT_EQ(6u, set.size());
315 it = set.addReturnIterator(5); 315 it = set.addReturnIterator(5);
316 EXPECT_EQ(7u, set.size()); 316 EXPECT_EQ(7u, set.size());
317 set.remove(it); 317 set.erase(it);
318 EXPECT_EQ(6u, set.size()); 318 EXPECT_EQ(6u, set.size());
319 EXPECT_EQ(4, set.back()); 319 EXPECT_EQ(4, set.back());
320 } 320 }
321 321
322 TYPED_TEST(ListOrLinkedHashSetTest, Swap) { 322 TYPED_TEST(ListOrLinkedHashSetTest, Swap) {
323 using Set = TypeParam; 323 using Set = TypeParam;
324 int num = 10; 324 int num = 10;
325 Set set0; 325 Set set0;
326 Set set1; 326 Set set1;
327 Set set2; 327 Set set2;
(...skipping 20 matching lines...) Expand all
348 it2 = set1.begin(); 348 it2 = set1.begin();
349 for (int i = 0; i < num; ++i, ++it1, ++it2) { 349 for (int i = 0; i < num; ++i, ++it1, ++it2) {
350 EXPECT_EQ(*it1, i + 1); 350 EXPECT_EQ(*it1, i + 1);
351 EXPECT_EQ(*it2, num - i); 351 EXPECT_EQ(*it2, num - i);
352 } 352 }
353 EXPECT_EQ(it1, set0.end()); 353 EXPECT_EQ(it1, set0.end());
354 EXPECT_EQ(it2, set1.end()); 354 EXPECT_EQ(it2, set1.end());
355 EXPECT_EQ(set2.begin(), set2.end()); 355 EXPECT_EQ(set2.begin(), set2.end());
356 356
357 int removedIndex = num >> 1; 357 int removedIndex = num >> 1;
358 set0.remove(removedIndex + 1); 358 set0.erase(removedIndex + 1);
359 set1.remove(num - removedIndex); 359 set1.erase(num - removedIndex);
360 360
361 it1 = set0.begin(); 361 it1 = set0.begin();
362 it2 = set1.begin(); 362 it2 = set1.begin();
363 for (int i = 0; i < num; ++i, ++it1, ++it2) { 363 for (int i = 0; i < num; ++i, ++it1, ++it2) {
364 if (i == removedIndex) 364 if (i == removedIndex)
365 ++i; 365 ++i;
366 EXPECT_EQ(*it1, i + 1); 366 EXPECT_EQ(*it1, i + 1);
367 EXPECT_EQ(*it2, num - i); 367 EXPECT_EQ(*it2, num - i);
368 } 368 }
369 EXPECT_EQ(it1, set0.end()); 369 EXPECT_EQ(it1, set0.end());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 DummyRefCounted* rawPtr = ptr.get(); 414 DummyRefCounted* rawPtr = ptr.get();
415 415
416 EXPECT_TRUE(set.contains(ptr)); 416 EXPECT_TRUE(set.contains(ptr));
417 EXPECT_TRUE(set.contains(rawPtr)); 417 EXPECT_TRUE(set.contains(rawPtr));
418 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount); 418 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount);
419 419
420 ptr.clear(); 420 ptr.clear();
421 EXPECT_FALSE(isDeleted); 421 EXPECT_FALSE(isDeleted);
422 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount); 422 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount);
423 423
424 set.remove(rawPtr); 424 set.erase(rawPtr);
425 EXPECT_TRUE(isDeleted); 425 EXPECT_TRUE(isDeleted);
426 426
427 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount); 427 EXPECT_EQ(1, DummyRefCounted::m_refInvokesCount);
428 } 428 }
429 429
430 TYPED_TEST(ListOrLinkedHashSetRefPtrTest, ExerciseValuePeekInType) { 430 TYPED_TEST(ListOrLinkedHashSetRefPtrTest, ExerciseValuePeekInType) {
431 using Set = TypeParam; 431 using Set = TypeParam;
432 Set set; 432 Set set;
433 bool isDeleted = false; 433 bool isDeleted = false;
434 bool isDeleted2 = false; 434 bool isDeleted2 = false;
435 435
436 RefPtr<DummyRefCounted> ptr = adoptRef(new DummyRefCounted(isDeleted)); 436 RefPtr<DummyRefCounted> ptr = adoptRef(new DummyRefCounted(isDeleted));
437 RefPtr<DummyRefCounted> ptr2 = adoptRef(new DummyRefCounted(isDeleted2)); 437 RefPtr<DummyRefCounted> ptr2 = adoptRef(new DummyRefCounted(isDeleted2));
438 438
439 typename Set::AddResult addResult = set.insert(ptr); 439 typename Set::AddResult addResult = set.insert(ptr);
440 EXPECT_TRUE(addResult.isNewEntry); 440 EXPECT_TRUE(addResult.isNewEntry);
441 set.find(ptr); 441 set.find(ptr);
442 const Set& constSet(set); 442 const Set& constSet(set);
443 constSet.find(ptr); 443 constSet.find(ptr);
444 EXPECT_TRUE(set.contains(ptr)); 444 EXPECT_TRUE(set.contains(ptr));
445 typename Set::iterator it = set.addReturnIterator(ptr); 445 typename Set::iterator it = set.addReturnIterator(ptr);
446 set.appendOrMoveToLast(ptr); 446 set.appendOrMoveToLast(ptr);
447 set.prependOrMoveToFirst(ptr); 447 set.prependOrMoveToFirst(ptr);
448 set.insertBefore(ptr, ptr); 448 set.insertBefore(ptr, ptr);
449 set.insertBefore(it, ptr); 449 set.insertBefore(it, ptr);
450 EXPECT_EQ(1u, set.size()); 450 EXPECT_EQ(1u, set.size());
451 set.insert(ptr2); 451 set.insert(ptr2);
452 ptr2.clear(); 452 ptr2.clear();
453 set.remove(ptr); 453 set.erase(ptr);
454 454
455 EXPECT_FALSE(isDeleted); 455 EXPECT_FALSE(isDeleted);
456 ptr.clear(); 456 ptr.clear();
457 EXPECT_TRUE(isDeleted); 457 EXPECT_TRUE(isDeleted);
458 458
459 EXPECT_FALSE(isDeleted2); 459 EXPECT_FALSE(isDeleted2);
460 set.removeFirst(); 460 set.removeFirst();
461 EXPECT_TRUE(isDeleted2); 461 EXPECT_TRUE(isDeleted2);
462 462
463 EXPECT_EQ(0u, set.size()); 463 EXPECT_EQ(0u, set.size());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 OwnPtrSet::AddResult res2 = set.insert(WTF::wrapUnique(ptr2)); 566 OwnPtrSet::AddResult res2 = set.insert(WTF::wrapUnique(ptr2));
567 EXPECT_EQ(res2.storedValue->get(), ptr2); 567 EXPECT_EQ(res2.storedValue->get(), ptr2);
568 } 568 }
569 569
570 EXPECT_FALSE(deleted2); 570 EXPECT_FALSE(deleted2);
571 EXPECT_EQ(2UL, set.size()); 571 EXPECT_EQ(2UL, set.size());
572 OwnPtrSet::iterator it2 = set.find(ptr2); 572 OwnPtrSet::iterator it2 = set.find(ptr2);
573 EXPECT_NE(set.end(), it2); 573 EXPECT_NE(set.end(), it2);
574 EXPECT_EQ(ptr2, (*it2).get()); 574 EXPECT_EQ(ptr2, (*it2).get());
575 575
576 set.remove(ptr1); 576 set.erase(ptr1);
577 EXPECT_TRUE(deleted1); 577 EXPECT_TRUE(deleted1);
578 578
579 set.clear(); 579 set.clear();
580 EXPECT_TRUE(deleted2); 580 EXPECT_TRUE(deleted2);
581 EXPECT_TRUE(set.isEmpty()); 581 EXPECT_TRUE(set.isEmpty());
582 582
583 deleted1 = false; 583 deleted1 = false;
584 deleted2 = false; 584 deleted2 = false;
585 { 585 {
586 OwnPtrSet set; 586 OwnPtrSet set;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 iter = set.find(MoveOnly(5)); 806 iter = set.find(MoveOnly(5));
807 ASSERT_TRUE(iter != set.end()); 807 ASSERT_TRUE(iter != set.end());
808 AddResult addResult = set.insertBefore(iter, MoveOnly(6, 6)); 808 AddResult addResult = set.insertBefore(iter, MoveOnly(6, 6));
809 EXPECT_TRUE(addResult.isNewEntry); 809 EXPECT_TRUE(addResult.isNewEntry);
810 EXPECT_EQ(6, addResult.storedValue->value()); 810 EXPECT_EQ(6, addResult.storedValue->value());
811 EXPECT_EQ(6, addResult.storedValue->id()); 811 EXPECT_EQ(6, addResult.storedValue->id());
812 } 812 }
813 813
814 // ... but they don't have any pass-out (like take()) methods. 814 // ... but they don't have any pass-out (like take()) methods.
815 815
816 set.remove(MoveOnly(3)); 816 set.erase(MoveOnly(3));
817 set.clear(); 817 set.clear();
818 } 818 }
819 819
820 } // anonymous namespace 820 } // anonymous namespace
821 821
822 } // namespace WTF 822 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ListHashSet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698