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

Side by Side Diff: Source/wtf/HashSetTest.cpp

Issue 835953003: Fix template angle bracket syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 | « Source/wtf/HashSet.h ('k') | Source/wtf/HashTraits.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 24 matching lines...) Expand all
35 35
36 template<int initialCapacity> 36 template<int initialCapacity>
37 struct InitialCapacityTestHashTraits : public WTF::UnsignedWithZeroKeyHashTr aits<int> { 37 struct InitialCapacityTestHashTraits : public WTF::UnsignedWithZeroKeyHashTr aits<int> {
38 static const int minimumTableSize = initialCapacity; 38 static const int minimumTableSize = initialCapacity;
39 }; 39 };
40 40
41 template<unsigned size> 41 template<unsigned size>
42 void testInitialCapacity() 42 void testInitialCapacity()
43 { 43 {
44 const unsigned initialCapacity = WTF::HashTableCapacityForSize<size>::value; 44 const unsigned initialCapacity = WTF::HashTableCapacityForSize<size>::value;
45 HashSet<int, DefaultHash<int>::Hash, InitialCapacityTestHashTraits<initialCa pacity> > testSet; 45 HashSet<int, DefaultHash<int>::Hash, InitialCapacityTestHashTraits<initialCa pacity>> testSet;
46 46
47 // Initial capacity is null. 47 // Initial capacity is null.
48 EXPECT_EQ(0UL, testSet.capacity()); 48 EXPECT_EQ(0UL, testSet.capacity());
49 49
50 // Adding items up to size should never change the capacity. 50 // Adding items up to size should never change the capacity.
51 for (size_t i = 0; i < size; ++i) { 51 for (size_t i = 0; i < size; ++i) {
52 testSet.add(i); 52 testSet.add(i);
53 EXPECT_EQ(initialCapacity, testSet.capacity()); 53 EXPECT_EQ(initialCapacity, testSet.capacity());
54 } 54 }
55 55
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 deleted = true; 88 deleted = true;
89 } 89 }
90 90
91 bool& deleted; 91 bool& deleted;
92 }; 92 };
93 93
94 TEST(HashSetTest, HashSetOwnPtr) 94 TEST(HashSetTest, HashSetOwnPtr)
95 { 95 {
96 bool deleted1 = false, deleted2 = false; 96 bool deleted1 = false, deleted2 = false;
97 97
98 typedef HashSet<OwnPtr<Dummy> > OwnPtrSet; 98 typedef HashSet<OwnPtr<Dummy>> OwnPtrSet;
99 OwnPtrSet set; 99 OwnPtrSet set;
100 100
101 Dummy* ptr1 = new Dummy(deleted1); 101 Dummy* ptr1 = new Dummy(deleted1);
102 { 102 {
103 // AddResult in a separate scope to avoid assertion hit, 103 // AddResult in a separate scope to avoid assertion hit,
104 // since we modify the container further. 104 // since we modify the container further.
105 HashSet<OwnPtr<Dummy> >::AddResult res1 = set.add(adoptPtr(ptr1)); 105 HashSet<OwnPtr<Dummy>>::AddResult res1 = set.add(adoptPtr(ptr1));
106 EXPECT_EQ(ptr1, res1.storedValue->get()); 106 EXPECT_EQ(ptr1, res1.storedValue->get());
107 } 107 }
108 108
109 EXPECT_FALSE(deleted1); 109 EXPECT_FALSE(deleted1);
110 EXPECT_EQ(1UL, set.size()); 110 EXPECT_EQ(1UL, set.size());
111 OwnPtrSet::iterator it1 = set.find(ptr1); 111 OwnPtrSet::iterator it1 = set.find(ptr1);
112 EXPECT_NE(set.end(), it1); 112 EXPECT_NE(set.end(), it1);
113 EXPECT_EQ(ptr1, (*it1)); 113 EXPECT_EQ(ptr1, (*it1));
114 114
115 Dummy* ptr2 = new Dummy(deleted2); 115 Dummy* ptr2 = new Dummy(deleted2);
116 { 116 {
117 HashSet<OwnPtr<Dummy> >::AddResult res2 = set.add(adoptPtr(ptr2)); 117 HashSet<OwnPtr<Dummy>>::AddResult res2 = set.add(adoptPtr(ptr2));
118 EXPECT_EQ(res2.storedValue->get(), ptr2); 118 EXPECT_EQ(res2.storedValue->get(), ptr2);
119 } 119 }
120 120
121 EXPECT_FALSE(deleted2); 121 EXPECT_FALSE(deleted2);
122 EXPECT_EQ(2UL, set.size()); 122 EXPECT_EQ(2UL, set.size());
123 OwnPtrSet::iterator it2 = set.find(ptr2); 123 OwnPtrSet::iterator it2 = set.find(ptr2);
124 EXPECT_NE(set.end(), it2); 124 EXPECT_NE(set.end(), it2);
125 EXPECT_EQ(ptr2, (*it2)); 125 EXPECT_EQ(ptr2, (*it2));
126 126
127 set.remove(ptr1); 127 set.remove(ptr1);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 bool& m_isDeleted; 180 bool& m_isDeleted;
181 }; 181 };
182 182
183 int DummyRefCounted::s_refInvokesCount = 0; 183 int DummyRefCounted::s_refInvokesCount = 0;
184 184
185 TEST(HashSetTest, HashSetRefPtr) 185 TEST(HashSetTest, HashSetRefPtr)
186 { 186 {
187 bool isDeleted = false; 187 bool isDeleted = false;
188 RefPtr<DummyRefCounted> ptr = adoptRef(new DummyRefCounted(isDeleted)); 188 RefPtr<DummyRefCounted> ptr = adoptRef(new DummyRefCounted(isDeleted));
189 EXPECT_EQ(0, DummyRefCounted::s_refInvokesCount); 189 EXPECT_EQ(0, DummyRefCounted::s_refInvokesCount);
190 HashSet<RefPtr<DummyRefCounted> > set; 190 HashSet<RefPtr<DummyRefCounted>> set;
191 set.add(ptr); 191 set.add(ptr);
192 // Referenced only once (to store a copy in the container). 192 // Referenced only once (to store a copy in the container).
193 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount); 193 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount);
194 194
195 DummyRefCounted* rawPtr = ptr.get(); 195 DummyRefCounted* rawPtr = ptr.get();
196 196
197 EXPECT_TRUE(set.contains(rawPtr)); 197 EXPECT_TRUE(set.contains(rawPtr));
198 EXPECT_NE(set.end(), set.find(rawPtr)); 198 EXPECT_NE(set.end(), set.find(rawPtr));
199 EXPECT_TRUE(set.contains(ptr)); 199 EXPECT_TRUE(set.contains(ptr));
200 EXPECT_NE(set.end(), set.find(ptr)); 200 EXPECT_NE(set.end(), set.find(ptr));
201 201
202 ptr.clear(); 202 ptr.clear();
203 EXPECT_FALSE(isDeleted); 203 EXPECT_FALSE(isDeleted);
204 204
205 set.remove(rawPtr); 205 set.remove(rawPtr);
206 EXPECT_TRUE(isDeleted); 206 EXPECT_TRUE(isDeleted);
207 EXPECT_TRUE(set.isEmpty()); 207 EXPECT_TRUE(set.isEmpty());
208 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount); 208 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount);
209 } 209 }
210 210
211 211
212 } // namespace 212 } // namespace
OLDNEW
« no previous file with comments | « Source/wtf/HashSet.h ('k') | Source/wtf/HashTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698