33 TEST_CASE(
"ConnectionPool's can be constructed.",
"[ConnectionPool]")
39 TEST_CASE(
"ConnectionPool's can store at least one connection and send a " 40 "packet over it.",
"[ConnectionPool]")
43 auto packet = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
44 fakeit::Mock<Connection> mock;
45 fakeit::Fake(Method(mock, send));
46 std::shared_ptr<Connection> connection =
mock_shared(mock);
47 fakeit::Mock<Filter> mock_filter;
49 auto source_connection = std::make_shared<Connection>(
"SOURCE", filter);
50 auto ping = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
51 ping->connection(source_connection);
53 SECTION(
"with logging")
59 fakeit::Verify(Method(mock, send).Matching([&](
auto a)
64 mock_cout.
buffer().substr(21) ==
65 "received PING (#4) from 192.168 to 127.1 (v2.0) " 68 SECTION(
"without logging")
73 fakeit::Verify(Method(mock, send).Matching([&](
auto a)
77 REQUIRE(mock_cout.
buffer().empty());
83 TEST_CASE(
"ConnectionPool's can store more than one connection and send a " 84 "packet over them.",
"[ConnectionPool]")
87 auto packet = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
88 fakeit::Mock<Connection> mock1;
89 fakeit::Mock<Connection> mock2;
90 fakeit::Fake(Method(mock1, send));
91 fakeit::Fake(Method(mock2, send));
92 std::shared_ptr<Connection> connection1 =
mock_shared(mock1);
93 std::shared_ptr<Connection> connection2 =
mock_shared(mock2);
94 fakeit::Mock<Filter> mock_filter;
96 auto source_connection = std::make_shared<Connection>(
"SOURCE", filter);
97 auto ping = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
98 ping->connection(source_connection);
100 SECTION(
"with logging")
104 pool.
add(connection1);
105 pool.
add(connection2);
107 fakeit::Verify(Method(mock1, send).Matching([&](
auto a)
109 return *a == *packet;
111 fakeit::Verify(Method(mock2, send).Matching([&](
auto a)
113 return *a == *packet;
116 mock_cout.
buffer().substr(21) ==
117 "received PING (#4) from 192.168 to 127.1 (v2.0) " 120 SECTION(
"without logging")
123 pool.
add(connection1);
124 pool.
add(connection2);
126 fakeit::Verify(Method(mock1, send).Matching([&](
auto a)
128 return *a == *packet;
130 fakeit::Verify(Method(mock2, send).Matching([&](
auto a)
132 return *a == *packet;
134 REQUIRE(mock_cout.
buffer().empty());
140 TEST_CASE(
"ConnectionPool's 'remove' method removes a connection.",
143 auto packet = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
144 fakeit::Mock<Connection> mock1;
145 fakeit::Mock<Connection> mock2;
146 fakeit::Fake(Method(mock1, send));
147 fakeit::Fake(Method(mock2, send));
148 std::shared_ptr<Connection> connection1 =
mock_shared(mock1);
149 std::shared_ptr<Connection> connection2 =
mock_shared(mock2);
151 pool.
add(connection1);
152 pool.
add(connection2);
153 pool.
send(std::make_unique<packet_v2::Packet>(to_vector(PingV2())));
155 pool.
send(std::make_unique<packet_v2::Packet>(to_vector(PingV2())));
156 fakeit::Verify(Method(mock1, send).Matching([&](
auto a)
158 return *a == *packet;
160 fakeit::Verify(Method(mock2, send).Matching([&](
auto a)
162 return *a == *packet;
167 TEST_CASE(
"ConnectionPool's 'send' method removes connections that have " 168 "expired.",
"[ConnectionPool]")
170 auto packet = std::make_unique<packet_v2::Packet>(to_vector(PingV2()));
171 fakeit::Mock<Connection> mock1;
172 fakeit::Mock<Connection> mock2;
173 fakeit::Fake(Method(mock1, send));
174 fakeit::Fake(Method(mock2, send));
175 std::shared_ptr<Connection> connection1 =
mock_shared(mock1);
176 std::shared_ptr<Connection> connection2 =
mock_shared(mock2);
178 pool.
add(connection1);
179 pool.
add(connection2);
180 pool.
send(std::make_unique<packet_v2::Packet>(to_vector(PingV2())));
182 pool.
send(std::make_unique<packet_v2::Packet>(to_vector(PingV2())));
183 fakeit::Verify(Method(mock1, send).Matching([&](
auto a)
185 return *a == *packet;
187 fakeit::Verify(Method(mock2, send).Matching([&](
auto a)
189 return *a == *packet;
TEST_VIRTUAL void send(std::unique_ptr< const Packet > packet)
TEST_CASE("ConnectionPool's can be constructed.", "[ConnectionPool]")
static unsigned int level()
TEST_VIRTUAL void remove(const std::weak_ptr< Connection > &connection)
std::shared_ptr< T > mock_shared(fakeit::Mock< T > &mock)
TEST_VIRTUAL void add(std::weak_ptr< Connection > connection)