Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 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 = 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 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 ownPtr2 = set.takeAny(); | 156 ownPtr2 = set.takeAny(); |
| 157 EXPECT_TRUE(set.isEmpty()); | 157 EXPECT_TRUE(set.isEmpty()); |
| 158 } | 158 } |
| 159 EXPECT_FALSE(deleted1); | 159 EXPECT_FALSE(deleted1); |
| 160 EXPECT_FALSE(deleted2); | 160 EXPECT_FALSE(deleted2); |
| 161 | 161 |
| 162 EXPECT_EQ(ptr1, ownPtr1); | 162 EXPECT_EQ(ptr1, ownPtr1); |
| 163 EXPECT_EQ(ptr2, ownPtr2); | 163 EXPECT_EQ(ptr2, ownPtr2); |
| 164 } | 164 } |
| 165 | 165 |
| 166 class DummyRefCounted: public WTF::RefCounted<DummyRefCounted> { | 166 class DummyRefCounted: public WTF::RefCounted<DummyRefCounted> { |
|
kochi
2015/06/15 03:34:22
one space after DummyRefCounted.
WTF:: not necessa
tkent
2015/06/15 04:45:57
Done.
Added namespace {} to this file.
| |
| 167 public: | 167 public: |
| 168 DummyRefCounted(bool& isDeleted) : m_isDeleted(isDeleted) { m_isDeleted = fa lse; } | 168 DummyRefCounted(bool& isDeleted) : m_isDeleted(isDeleted) { m_isDeleted = fa lse; } |
| 169 ~DummyRefCounted() { m_isDeleted = true; } | 169 ~DummyRefCounted() { m_isDeleted = true; } |
| 170 | 170 |
| 171 void ref() | 171 void ref() |
| 172 { | 172 { |
| 173 WTF::RefCounted<DummyRefCounted>::ref(); | 173 WTF::RefCounted<DummyRefCounted>::ref(); |
| 174 ++s_refInvokesCount; | 174 ++s_refInvokesCount; |
| 175 } | 175 } |
| 176 | 176 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 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 } // namespace WTF |
| 212 } // namespace | |
| OLD | NEW |