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

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 2250353002: Introduce copyToVector for HeapHashCountedSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-some-hash-counted-set-copy-to-vector
Patch Set: Created 4 years, 4 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 #include "platform/heap/ThreadState.h" 38 #include "platform/heap/ThreadState.h"
39 #include "platform/heap/Visitor.h" 39 #include "platform/heap/Visitor.h"
40 #include "platform/testing/UnitTestHelpers.h" 40 #include "platform/testing/UnitTestHelpers.h"
41 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
42 #include "public/platform/WebTaskRunner.h" 42 #include "public/platform/WebTaskRunner.h"
43 #include "public/platform/WebTraceLocation.h" 43 #include "public/platform/WebTraceLocation.h"
44 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
45 #include "wtf/HashTraits.h" 45 #include "wtf/HashTraits.h"
46 #include "wtf/LinkedHashSet.h" 46 #include "wtf/LinkedHashSet.h"
47 #include "wtf/PtrUtil.h" 47 #include "wtf/PtrUtil.h"
48 #include <algorithm>
48 #include <memory> 49 #include <memory>
49 50
50 namespace blink { 51 namespace blink {
51 52
52 static void preciselyCollectGarbage() 53 static void preciselyCollectGarbage()
53 { 54 {
54 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); 55 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC);
55 } 56 }
56 57
57 static void conservativelyCollectGarbage() 58 static void conservativelyCollectGarbage()
(...skipping 3788 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 preciselyCollectGarbage(); 3847 preciselyCollectGarbage();
3847 EXPECT_EQ(0u, weakStrong->size()); 3848 EXPECT_EQ(0u, weakStrong->size());
3848 EXPECT_EQ(0u, strongWeak->size()); 3849 EXPECT_EQ(0u, strongWeak->size());
3849 EXPECT_EQ(0u, weakWeak->size()); 3850 EXPECT_EQ(0u, weakWeak->size());
3850 EXPECT_EQ(0u, weakSet->size()); 3851 EXPECT_EQ(0u, weakSet->size());
3851 EXPECT_EQ(0u, weakOrderedSet->size()); 3852 EXPECT_EQ(0u, weakOrderedSet->size());
3852 } 3853 }
3853 } 3854 }
3854 } 3855 }
3855 3856
3857 TEST(HeapTest, HeapHashCountedSetToVector)
3858 {
3859 HeapHashCountedSet<Member<IntWrapper>> set;
3860 HeapVector<Member<IntWrapper>> vector;
3861 set.add(new IntWrapper(1));
3862 set.add(new IntWrapper(1));
3863 set.add(new IntWrapper(2));
3864
3865 copyToVector(set, vector);
3866 EXPECT_EQ(3u, vector.size());
3867
3868 Vector<int> intVector;
3869 for (const auto& i : vector)
3870 intVector.append(i->value());
3871 std::sort(intVector.begin(), intVector.end());
3872 ASSERT_EQ(3u, intVector.size());
3873 EXPECT_EQ(1, intVector[0]);
3874 EXPECT_EQ(1, intVector[1]);
3875 EXPECT_EQ(2, intVector[2]);
3876 }
3877
3878 TEST(HeapTest, WeakHeapHashCountedSetToVector)
3879 {
3880 HeapHashCountedSet<WeakMember<IntWrapper>> set;
3881 HeapVector<Member<IntWrapper>> vector;
3882 set.add(new IntWrapper(1));
3883 set.add(new IntWrapper(1));
3884 set.add(new IntWrapper(2));
3885
3886 copyToVector(set, vector);
3887 EXPECT_LE(3u, vector.size());
3888 for (const auto& i : vector)
3889 EXPECT_TRUE(i->value() == 1 || i->value() == 2);
3890 }
3891
3856 TEST(HeapTest, RefCountedGarbageCollected) 3892 TEST(HeapTest, RefCountedGarbageCollected)
3857 { 3893 {
3858 RefCountedAndGarbageCollected::s_destructorCalls = 0; 3894 RefCountedAndGarbageCollected::s_destructorCalls = 0;
3859 { 3895 {
3860 RefPtr<RefCountedAndGarbageCollected> refPtr3; 3896 RefPtr<RefCountedAndGarbageCollected> refPtr3;
3861 { 3897 {
3862 Persistent<RefCountedAndGarbageCollected> persistent; 3898 Persistent<RefCountedAndGarbageCollected> persistent;
3863 { 3899 {
3864 Persistent<RefCountedAndGarbageCollected> refPtr1 = RefCountedAn dGarbageCollected::create(); 3900 Persistent<RefCountedAndGarbageCollected> refPtr1 = RefCountedAn dGarbageCollected::create();
3865 Persistent<RefCountedAndGarbageCollected> refPtr2 = RefCountedAn dGarbageCollected::create(); 3901 Persistent<RefCountedAndGarbageCollected> refPtr2 = RefCountedAn dGarbageCollected::create();
(...skipping 3080 matching lines...) Expand 10 before | Expand all | Expand 10 after
6946 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet"); 6982 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet");
6947 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet"); 6983 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet");
6948 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet"); 6984 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet");
6949 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap"); 6985 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap");
6950 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector"); 6986 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector");
6951 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque"); 6987 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque");
6952 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray"); 6988 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray");
6953 } 6989 }
6954 6990
6955 } // namespace blink 6991 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/HeapAllocator.h ('k') | third_party/WebKit/Source/wtf/HashCountedSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698