38 #pragma clang diagnostic push 39 #pragma clang diagnostic ignored "-Wweak-vtables" 43 class InterfaceTestClass :
public Interface 46 InterfaceTestClass(std::shared_ptr<ConnectionPool> connection_pool)
47 : connection_pool_(
std::move(connection_pool))
51 ~InterfaceTestClass() =
default;
54 const std::chrono::nanoseconds &timeout =
55 std::chrono::nanoseconds(100000)) final
60 const std::chrono::nanoseconds &timeout =
61 std::chrono::nanoseconds(100000)) final
64 connection_pool_->send(
65 std::make_unique<packet_v2::Packet>(to_vector(PingV2())));
69 std::ostream &
print_(std::ostream &os)
const final 71 os <<
"interface test class";
76 std::shared_ptr<ConnectionPool> connection_pool_;
80 #pragma clang diagnostic pop 86 TEST_CASE(
"Interface's can be constructed.",
"[Interface]")
88 fakeit::Mock<ConnectionPool> mock_pool;
89 std::shared_ptr<ConnectionPool> pool =
mock_shared(mock_pool);
90 REQUIRE_NOTHROW(InterfaceTestClass(pool));
94 TEST_CASE(
"Interface's 'send_packet' method (included just for coverage)." 97 fakeit::Mock<ConnectionPool> mock_pool;
98 std::shared_ptr<ConnectionPool> pool =
mock_shared(mock_pool);
99 InterfaceTestClass interface(pool);
100 REQUIRE_NOTHROW(interface.send_packet());
104 TEST_CASE(
"Interface's 'receive_packet' method sends the packet using the " 105 "contained ConnectionPool.",
"[Interface]")
107 fakeit::Mock<ConnectionPool> mock_pool;
108 fakeit::Fake(Method(mock_pool, send));
109 std::shared_ptr<ConnectionPool> pool =
mock_shared(mock_pool);
110 InterfaceTestClass interface(pool);
111 interface.receive_packet();
112 fakeit::Verify(Method(mock_pool, send).Matching([](
auto &&a)
121 fakeit::Mock<ConnectionPool> mock_pool;
122 std::shared_ptr<ConnectionPool> pool =
mock_shared(mock_pool);
123 REQUIRE(
str(InterfaceTestClass(pool)) ==
"interface test class");
std::string str(const T &object)
virtual std::ostream & print_(std::ostream &os) const =0
virtual void receive_packet(const std::chrono::nanoseconds &timeout)=0
virtual void send_packet(const std::chrono::nanoseconds &timeout)=0
TEST_CASE("Interface's can be constructed.", "[Interface]")
std::shared_ptr< T > mock_shared(fakeit::Mock< T > &mock)