1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/quic/blocked_list.h" 6 #include "net/quic/quic_connection.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 #if defined(COMPILER_GCC) 10 namespace BASE_HASH_NAMESPACE { 11 template<> 12 struct hash<const int*> { 13 std::size_t operator()(const int* ptr) const { 14 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 15 } 16 }; 17 } 18 #endif 19 20 namespace net { 21 namespace test { 22 namespace { 23 24 class BlockedListTest : public ::testing::Test { 25 protected: 26 BlockedListTest() : 27 item1_(0), 28 item2_(0), 29 item3_(0) { 30 } 31 32 BlockedList<const int*> list_; 33 const int item1_; 34 const int item2_; 35 const int item3_; 36 }; 37 38 TEST_F(BlockedListTest, BasicAdd) { 39 list_.AddBlockedObject(&item1_); 40 list_.AddBlockedObject(&item3_); 41 list_.AddBlockedObject(&item2_); 42 ASSERT_EQ(3, list_.NumObjects()); 43 ASSERT_FALSE(list_.IsEmpty()); 44 45 EXPECT_EQ(&item1_, list_.GetNextBlockedObject()); 46 EXPECT_EQ(&item3_, list_.GetNextBlockedObject()); 47 EXPECT_EQ(&item2_, list_.GetNextBlockedObject()); 48 } 49 50 TEST_F(BlockedListTest, AddAndRemove) { 51 list_.AddBlockedObject(&item1_); 52 list_.AddBlockedObject(&item3_); 53 list_.AddBlockedObject(&item2_); 54 ASSERT_EQ(3, list_.NumObjects()); 55 56 list_.RemoveBlockedObject(&item3_); 57 ASSERT_EQ(2, list_.NumObjects()); 58 59 EXPECT_EQ(&item1_, list_.GetNextBlockedObject()); 60 EXPECT_EQ(&item2_, list_.GetNextBlockedObject()); 61 } 62 63 TEST_F(BlockedListTest, DuplicateAdd) { 64 list_.AddBlockedObject(&item1_); 65 list_.AddBlockedObject(&item3_); 66 list_.AddBlockedObject(&item2_); 67 68 list_.AddBlockedObject(&item3_); 69 list_.AddBlockedObject(&item2_); 70 list_.AddBlockedObject(&item1_); 71 72 ASSERT_EQ(3, list_.NumObjects()); 73 ASSERT_FALSE(list_.IsEmpty()); 74 75 // Call in the original insert order. 76 EXPECT_EQ(&item1_, list_.GetNextBlockedObject()); 77 EXPECT_EQ(&item3_, list_.GetNextBlockedObject()); 78 EXPECT_EQ(&item2_, list_.GetNextBlockedObject()); 79 } 80 81 } // namespace 82 } // namespace test 83 } // namespace net 84