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

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

Issue 1184043002: Fix unit test style in Source/wtf/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: apply review comments Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/HashMapTest.cpp ('k') | Source/wtf/ListHashSetTest.cpp » ('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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
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 "config.h" 26 #include "config.h"
27 #include "wtf/HashSet.h"
27 28
28 #include "wtf/HashSet.h"
29 #include "wtf/OwnPtr.h" 29 #include "wtf/OwnPtr.h"
30 #include "wtf/PassOwnPtr.h" 30 #include "wtf/PassOwnPtr.h"
31 #include "wtf/RefCounted.h" 31 #include "wtf/RefCounted.h"
32 #include <gtest/gtest.h> 32 #include <gtest/gtest.h>
33 33
34 namespace { 34 namespace WTF {
35 35
36 template<int initialCapacity> 36 template<int initialCapacity>
37 struct InitialCapacityTestHashTraits : public WTF::UnsignedWithZeroKeyHashTr aits<int> { 37 struct InitialCapacityTestHashTraits : public UnsignedWithZeroKeyHashTraits<int> {
38 static const int minimumTableSize = initialCapacity; 38 static const int minimumTableSize = initialCapacity;
39 }; 39 };
40 40
41 namespace {
42
41 template<unsigned size> 43 template<unsigned size>
42 void testInitialCapacity() 44 void testInitialCapacity()
43 { 45 {
44 const unsigned initialCapacity = WTF::HashTableCapacityForSize<size>::value; 46 const unsigned initialCapacity = HashTableCapacityForSize<size>::value;
45 HashSet<int, DefaultHash<int>::Hash, InitialCapacityTestHashTraits<initialCa pacity>> testSet; 47 HashSet<int, DefaultHash<int>::Hash, InitialCapacityTestHashTraits<initialCa pacity>> testSet;
46 48
47 // Initial capacity is null. 49 // Initial capacity is null.
48 EXPECT_EQ(0UL, testSet.capacity()); 50 EXPECT_EQ(0UL, testSet.capacity());
49 51
50 // Adding items up to size should never change the capacity. 52 // Adding items up to size should never change the capacity.
51 for (size_t i = 0; i < size; ++i) { 53 for (size_t i = 0; i < size; ++i) {
52 testSet.add(i); 54 testSet.add(i);
53 EXPECT_EQ(initialCapacity, testSet.capacity()); 55 EXPECT_EQ(initialCapacity, testSet.capacity());
54 } 56 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ownPtr2 = set.takeAny(); 158 ownPtr2 = set.takeAny();
157 EXPECT_TRUE(set.isEmpty()); 159 EXPECT_TRUE(set.isEmpty());
158 } 160 }
159 EXPECT_FALSE(deleted1); 161 EXPECT_FALSE(deleted1);
160 EXPECT_FALSE(deleted2); 162 EXPECT_FALSE(deleted2);
161 163
162 EXPECT_EQ(ptr1, ownPtr1); 164 EXPECT_EQ(ptr1, ownPtr1);
163 EXPECT_EQ(ptr2, ownPtr2); 165 EXPECT_EQ(ptr2, ownPtr2);
164 } 166 }
165 167
166 class DummyRefCounted: public WTF::RefCounted<DummyRefCounted> { 168 class DummyRefCounted : public RefCounted<DummyRefCounted> {
167 public: 169 public:
168 DummyRefCounted(bool& isDeleted) : m_isDeleted(isDeleted) { m_isDeleted = fa lse; } 170 DummyRefCounted(bool& isDeleted) : m_isDeleted(isDeleted) { m_isDeleted = fa lse; }
169 ~DummyRefCounted() { m_isDeleted = true; } 171 ~DummyRefCounted() { m_isDeleted = true; }
170 172
171 void ref() 173 void ref()
172 { 174 {
173 WTF::RefCounted<DummyRefCounted>::ref(); 175 WTF::RefCounted<DummyRefCounted>::ref();
174 ++s_refInvokesCount; 176 ++s_refInvokesCount;
175 } 177 }
176 178
(...skipping 24 matching lines...) Expand all
201 203
202 ptr.clear(); 204 ptr.clear();
203 EXPECT_FALSE(isDeleted); 205 EXPECT_FALSE(isDeleted);
204 206
205 set.remove(rawPtr); 207 set.remove(rawPtr);
206 EXPECT_TRUE(isDeleted); 208 EXPECT_TRUE(isDeleted);
207 EXPECT_TRUE(set.isEmpty()); 209 EXPECT_TRUE(set.isEmpty());
208 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount); 210 EXPECT_EQ(1, DummyRefCounted::s_refInvokesCount);
209 } 211 }
210 212
213 } // anonymous namespace
211 214
212 } // namespace 215 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/HashMapTest.cpp ('k') | Source/wtf/ListHashSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698