From 7ab35173bce99c6c9a5f189cdd83f93fcb3e9086 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 12 Jun 2013 14:02:40 +0200 Subject: Moved POP3 connection-related things to POP3Connection object. --- tests/net/pop3/POP3CommandTest.cpp | 7 ++++- tests/net/pop3/POP3ResponseTest.cpp | 42 +++++++++++++++++++++++------ tests/net/pop3/POP3TestUtils.hpp | 53 +++++++++++++++++++++++++++++++++++++ tests/net/pop3/POP3UtilsTest.cpp | 7 ++++- 4 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 tests/net/pop3/POP3TestUtils.hpp (limited to 'tests') diff --git a/tests/net/pop3/POP3CommandTest.cpp b/tests/net/pop3/POP3CommandTest.cpp index 35a3629d..14c92be4 100644 --- a/tests/net/pop3/POP3CommandTest.cpp +++ b/tests/net/pop3/POP3CommandTest.cpp @@ -23,6 +23,8 @@ #include "tests/testUtils.hpp" +#include "tests/net/pop3/POP3TestUtils.hpp" + #include "vmime/net/pop3/POP3Command.hpp" @@ -212,7 +214,10 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) vmime::ref cmd = POP3Command::createCommand("MY_COMMAND param1 param2"); vmime::ref sok = vmime::create (); - cmd->writeToSocket(sok); + vmime::ref conn = vmime::create + (sok.dynamicCast (), vmime::null); + + cmd->send(conn); vmime::string response; sok->localReceive(response); diff --git a/tests/net/pop3/POP3ResponseTest.cpp b/tests/net/pop3/POP3ResponseTest.cpp index 1541ce8b..f1fbcd54 100644 --- a/tests/net/pop3/POP3ResponseTest.cpp +++ b/tests/net/pop3/POP3ResponseTest.cpp @@ -23,6 +23,8 @@ #include "tests/testUtils.hpp" +#include "tests/net/pop3/POP3TestUtils.hpp" + #include "vmime/net/pop3/POP3Response.hpp" @@ -48,10 +50,13 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Response Text\r\n"); vmime::ref resp = - POP3Response::readResponse(socket, toh); + POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); VASSERT_TRUE("Success", resp->isSuccess()); @@ -65,10 +70,13 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("-ERR Response Text\r\n"); vmime::ref resp = - POP3Response::readResponse(socket, toh); + POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode()); VASSERT_FALSE("Success", resp->isSuccess()); @@ -82,10 +90,13 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+ challenge_string\r\n"); vmime::ref resp = - POP3Response::readResponse(socket, toh); + POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_READY, resp->getCode()); VASSERT_FALSE("Success", resp->isSuccess()); @@ -99,10 +110,13 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("Invalid Response Text\r\n"); vmime::ref resp = - POP3Response::readResponse(socket, toh); + POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode()); VASSERT_FALSE("Success", resp->isSuccess()); @@ -116,10 +130,13 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Response terminated by LF\n"); vmime::ref resp = - POP3Response::readResponse(socket, toh); + POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); VASSERT_TRUE("Success", resp->isSuccess()); @@ -133,13 +150,16 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Response Text\r\n"); socket->localSend("Line 1\r\n"); socket->localSend("Line 2\r\n"); socket->localSend(".\r\n"); vmime::ref resp = - POP3Response::readMultilineResponse(socket, toh); + POP3Response::readMultilineResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); VASSERT_TRUE("Success", resp->isSuccess()); @@ -155,13 +175,16 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Response Text\n"); socket->localSend("Line 1\n"); socket->localSend("Line 2\n"); socket->localSend(".\n"); vmime::ref resp = - POP3Response::readMultilineResponse(socket, toh); + POP3Response::readMultilineResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); VASSERT_TRUE("Success", resp->isSuccess()); @@ -182,6 +205,9 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Large Response Follows\n"); socket->localSend(data.str()); socket->localSend("\r\n.\r\n"); @@ -190,7 +216,7 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::utility::outputStreamStringAdapter receivedDataStream(receivedData); vmime::ref resp = - POP3Response::readLargeResponse(socket, toh, receivedDataStream, NULL, 0); + POP3Response::readLargeResponse(conn, receivedDataStream, NULL, 0); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); VASSERT_TRUE("Success", resp->isSuccess()); diff --git a/tests/net/pop3/POP3TestUtils.hpp b/tests/net/pop3/POP3TestUtils.hpp new file mode 100644 index 00000000..26b6601a --- /dev/null +++ b/tests/net/pop3/POP3TestUtils.hpp @@ -0,0 +1,53 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2013 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 3 of +// the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#include "vmime/net/pop3/POP3Connection.hpp" +#include "vmime/net/pop3/POP3Store.hpp" + + +class POP3ConnectionTest : public vmime::net::pop3::POP3Connection +{ +public: + + POP3ConnectionTest(vmime::ref socket, + vmime::ref timeoutHandler) + : POP3Connection(NULL, NULL), + m_socket(socket), m_timeoutHandler(timeoutHandler) + { + } + + vmime::ref getSocket() + { + return m_socket; + } + + vmime::ref getTimeoutHandler() + { + return m_timeoutHandler; + } + +private: + + vmime::ref m_socket; + vmime::ref m_timeoutHandler; +}; diff --git a/tests/net/pop3/POP3UtilsTest.cpp b/tests/net/pop3/POP3UtilsTest.cpp index ac92056a..9d443ddb 100644 --- a/tests/net/pop3/POP3UtilsTest.cpp +++ b/tests/net/pop3/POP3UtilsTest.cpp @@ -23,6 +23,8 @@ #include "tests/testUtils.hpp" +#include "tests/net/pop3/POP3TestUtils.hpp" + #include "vmime/net/pop3/POP3Utils.hpp" #include "vmime/net/pop3/POP3Response.hpp" @@ -42,6 +44,9 @@ VMIME_TEST_SUITE_BEGIN(POP3UtilsTest) vmime::ref socket = vmime::create (); vmime::ref toh = vmime::create (); + vmime::ref conn = vmime::create + (socket.dynamicCast (), toh); + socket->localSend("+OK Response Text\r\n"); socket->localSend("1 abcdef\r\n"); socket->localSend("23 ghijkl\r\n"); @@ -51,7 +56,7 @@ VMIME_TEST_SUITE_BEGIN(POP3UtilsTest) socket->localSend(".\r\n"); vmime::ref resp = - POP3Response::readMultilineResponse(socket, toh); + POP3Response::readMultilineResponse(conn); std::map result; POP3Utils::parseMultiListOrUidlResponse(resp, result); -- cgit v1.2.3