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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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') | third_party/WebKit/Source/wtf/OwnPtr.h » ('j') | 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 10 matching lines...) Expand all
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "wtf/ListHashSet.h" 26 #include "wtf/ListHashSet.h"
27 27
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "wtf/LinkedHashSet.h" 29 #include "wtf/LinkedHashSet.h"
30 #include "wtf/PassRefPtr.h" 30 #include "wtf/PassRefPtr.h"
31 #include "wtf/PtrUtil.h"
32 #include "wtf/RefCounted.h" 31 #include "wtf/RefCounted.h"
33 #include "wtf/RefPtr.h" 32 #include "wtf/RefPtr.h"
34 #include <memory>
35 #include <type_traits> 33 #include <type_traits>
36 34
37 namespace WTF { 35 namespace WTF {
38 36
39 namespace { 37 namespace {
40 38
41 template <typename Set> 39 template <typename Set>
42 class ListOrLinkedHashSetTest : public ::testing::Test { }; 40 class ListOrLinkedHashSetTest : public ::testing::Test { };
43 41
44 using SetTypes = ::testing::Types<ListHashSet<int>, ListHashSet<int, 1>, LinkedH ashSet<int>>; 42 using SetTypes = ::testing::Types<ListHashSet<int>, ListHashSet<int, 1>, LinkedH ashSet<int>>;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 deleted = true; 545 deleted = true;
548 } 546 }
549 547
550 bool& deleted; 548 bool& deleted;
551 }; 549 };
552 550
553 TEST(ListHashSetTest, WithOwnPtr) 551 TEST(ListHashSetTest, WithOwnPtr)
554 { 552 {
555 bool deleted1 = false, deleted2 = false; 553 bool deleted1 = false, deleted2 = false;
556 554
557 typedef ListHashSet<std::unique_ptr<Dummy>> OwnPtrSet; 555 typedef ListHashSet<OwnPtr<Dummy>> OwnPtrSet;
558 OwnPtrSet set; 556 OwnPtrSet set;
559 557
560 Dummy* ptr1 = new Dummy(deleted1); 558 Dummy* ptr1 = new Dummy(deleted1);
561 { 559 {
562 // AddResult in a separate scope to avoid assertion hit, 560 // AddResult in a separate scope to avoid assertion hit,
563 // since we modify the container further. 561 // since we modify the container further.
564 OwnPtrSet::AddResult res1 = set.add(wrapUnique(ptr1)); 562 OwnPtrSet::AddResult res1 = set.add(adoptPtr(ptr1));
565 EXPECT_EQ(res1.storedValue->get(), ptr1); 563 EXPECT_EQ(res1.storedValue->get(), ptr1);
566 } 564 }
567 565
568 EXPECT_FALSE(deleted1); 566 EXPECT_FALSE(deleted1);
569 EXPECT_EQ(1UL, set.size()); 567 EXPECT_EQ(1UL, set.size());
570 OwnPtrSet::iterator it1 = set.find(ptr1); 568 OwnPtrSet::iterator it1 = set.find(ptr1);
571 EXPECT_NE(set.end(), it1); 569 EXPECT_NE(set.end(), it1);
572 EXPECT_EQ(ptr1, (*it1).get()); 570 EXPECT_EQ(ptr1, (*it1));
573 571
574 Dummy* ptr2 = new Dummy(deleted2); 572 Dummy* ptr2 = new Dummy(deleted2);
575 { 573 {
576 OwnPtrSet::AddResult res2 = set.add(wrapUnique(ptr2)); 574 OwnPtrSet::AddResult res2 = set.add(adoptPtr(ptr2));
577 EXPECT_EQ(res2.storedValue->get(), ptr2); 575 EXPECT_EQ(res2.storedValue->get(), ptr2);
578 } 576 }
579 577
580 EXPECT_FALSE(deleted2); 578 EXPECT_FALSE(deleted2);
581 EXPECT_EQ(2UL, set.size()); 579 EXPECT_EQ(2UL, set.size());
582 OwnPtrSet::iterator it2 = set.find(ptr2); 580 OwnPtrSet::iterator it2 = set.find(ptr2);
583 EXPECT_NE(set.end(), it2); 581 EXPECT_NE(set.end(), it2);
584 EXPECT_EQ(ptr2, (*it2).get()); 582 EXPECT_EQ(ptr2, (*it2));
585 583
586 set.remove(ptr1); 584 set.remove(ptr1);
587 EXPECT_TRUE(deleted1); 585 EXPECT_TRUE(deleted1);
588 586
589 set.clear(); 587 set.clear();
590 EXPECT_TRUE(deleted2); 588 EXPECT_TRUE(deleted2);
591 EXPECT_TRUE(set.isEmpty()); 589 EXPECT_TRUE(set.isEmpty());
592 590
593 deleted1 = false; 591 deleted1 = false;
594 deleted2 = false; 592 deleted2 = false;
595 { 593 {
596 OwnPtrSet set; 594 OwnPtrSet set;
597 set.add(wrapUnique(new Dummy(deleted1))); 595 set.add(adoptPtr(new Dummy(deleted1)));
598 set.add(wrapUnique(new Dummy(deleted2))); 596 set.add(adoptPtr(new Dummy(deleted2)));
599 } 597 }
600 EXPECT_TRUE(deleted1); 598 EXPECT_TRUE(deleted1);
601 EXPECT_TRUE(deleted2); 599 EXPECT_TRUE(deleted2);
602 600
603 601
604 deleted1 = false; 602 deleted1 = false;
605 deleted2 = false; 603 deleted2 = false;
606 std::unique_ptr<Dummy> ownPtr1; 604 OwnPtr<Dummy> ownPtr1;
607 std::unique_ptr<Dummy> ownPtr2; 605 OwnPtr<Dummy> ownPtr2;
608 ptr1 = new Dummy(deleted1); 606 ptr1 = new Dummy(deleted1);
609 ptr2 = new Dummy(deleted2); 607 ptr2 = new Dummy(deleted2);
610 { 608 {
611 OwnPtrSet set; 609 OwnPtrSet set;
612 set.add(wrapUnique(ptr1)); 610 set.add(adoptPtr(ptr1));
613 set.add(wrapUnique(ptr2)); 611 set.add(adoptPtr(ptr2));
614 ownPtr1 = set.takeFirst(); 612 ownPtr1 = set.takeFirst();
615 EXPECT_EQ(1UL, set.size()); 613 EXPECT_EQ(1UL, set.size());
616 ownPtr2 = set.take(ptr2); 614 ownPtr2 = set.take(ptr2);
617 EXPECT_TRUE(set.isEmpty()); 615 EXPECT_TRUE(set.isEmpty());
618 } 616 }
619 EXPECT_FALSE(deleted1); 617 EXPECT_FALSE(deleted1);
620 EXPECT_FALSE(deleted2); 618 EXPECT_FALSE(deleted2);
621 619
622 EXPECT_EQ(ptr1, ownPtr1.get()); 620 EXPECT_EQ(ptr1, ownPtr1);
623 EXPECT_EQ(ptr2, ownPtr2.get()); 621 EXPECT_EQ(ptr2, ownPtr2);
624 } 622 }
625 623
626 class CountCopy final { 624 class CountCopy final {
627 public: 625 public:
628 static int* const kDeletedValue; 626 static int* const kDeletedValue;
629 627
630 explicit CountCopy(int* counter = nullptr) : m_counter(counter) { } 628 explicit CountCopy(int* counter = nullptr) : m_counter(counter) { }
631 CountCopy(const CountCopy& other) : m_counter(other.m_counter) 629 CountCopy(const CountCopy& other) : m_counter(other.m_counter)
632 { 630 {
633 if (m_counter && m_counter != kDeletedValue) 631 if (m_counter && m_counter != kDeletedValue)
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 // ... but they don't have any pass-out (like take()) methods. 821 // ... but they don't have any pass-out (like take()) methods.
824 822
825 set.remove(MoveOnly(3)); 823 set.remove(MoveOnly(3));
826 set.clear(); 824 set.clear();
827 } 825 }
828 826
829 827
830 } // anonymous namespace 828 } // anonymous namespace
831 829
832 } // namespace WTF 830 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ListHashSet.h ('k') | third_party/WebKit/Source/wtf/OwnPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698