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