blob: 074b6f52782c2950c3fb5ed9f7e6b29fe8772c58 [file] [log] [blame]
[email protected]5351cc4b2013-03-03 07:22:411// 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)
10namespace BASE_HASH_NAMESPACE {
11template<>
12struct 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
20namespace net {
21namespace test {
22namespace {
23
24class 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
38TEST_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
50TEST_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
63TEST_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