// ProxyTest.cpp #include #include "Proxy.h" #include "socket_mock.h" class ProxyTest : public ::testing::Test { protected: MockSocket mock_socket; Proxy* proxy; void SetUp() override { proxy = new Proxy(&mock_socket); } void TearDown() override { delete proxy; } }; TEST_F(ProxyTest, HandlesMailFromCommand) { std::string peer_address = "127.0.0.1"; EXPECT_CALL(mock_socket, connect("server-host", 25)); EXPECT_CALL(mock_socket, canRead(0.2)).WillOnce(testing::Return(true)); EXPECT_CALL(mock_socket, readLine()).WillOnce(testing::Return("MAIL FROM:")); EXPECT_CALL(mock_socket, writeLine("MAIL FROM:")); EXPECT_CALL(mock_socket, writeLine("250 OK")); proxy->run(peer_address); } TEST_F(ProxyTest, HandlesRcptToCommand) { std::string peer_address = "127.0.0.1"; EXPECT_CALL(mock_socket, connect("server-host", 25)); EXPECT_CALL(mock_socket, canRead(0.2)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(mock_socket, readLine()) .WillOnce(testing::Return("MAIL FROM:")) .WillOnce(testing::Return("RCPT TO:")) .WillOnce(testing::Return("")); EXPECT_CALL(mock_socket, writeLine("MAIL FROM:")); EXPECT_CALL(mock_socket, writeLine("RCPT TO:")); EXPECT_CALL(mock_socket, writeLine("250 OK")); proxy->run(peer_address); } TEST_F(ProxyTest, HandlesEmptyLine) { std::string peer_address = "127.0.0.1"; EXPECT_CALL(mock_socket, connect("server-host", 25)); EXPECT_CALL(mock_socket, canRead(0.2)).WillOnce(testing::Return(true)); EXPECT_CALL(mock_socket, readLine()).WillOnce(testing::Return("")); proxy->run(peer_address); // Expect no further actions to occur } int main(int argc, char** argv) { ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); }