63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
// ProxyTest.cpp
|
|
#include <gtest/gtest.h>
|
|
#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:<test@example.com>"));
|
|
EXPECT_CALL(mock_socket, writeLine("MAIL FROM:<test@example.com>"));
|
|
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:<test@example.com>"))
|
|
.WillOnce(testing::Return("RCPT TO:<receiver@example.com>"))
|
|
.WillOnce(testing::Return(""));
|
|
|
|
EXPECT_CALL(mock_socket, writeLine("MAIL FROM:<test@example.com>"));
|
|
EXPECT_CALL(mock_socket, writeLine("RCPT TO:<receiver@example.com>"));
|
|
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();
|
|
}
|