aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-06-12 12:02:40 +0000
committerVincent Richard <[email protected]>2013-06-12 12:02:40 +0000
commit7ab35173bce99c6c9a5f189cdd83f93fcb3e9086 (patch)
tree3fb077645ba770932adaa1f629b7c2f0931a6cf0 /tests
parentMoved POP3 client command related things to POP3Command class. (diff)
downloadvmime-7ab35173bce99c6c9a5f189cdd83f93fcb3e9086.tar.gz
vmime-7ab35173bce99c6c9a5f189cdd83f93fcb3e9086.zip
Moved POP3 connection-related things to POP3Connection object.
Diffstat (limited to 'tests')
-rw-r--r--tests/net/pop3/POP3CommandTest.cpp7
-rw-r--r--tests/net/pop3/POP3ResponseTest.cpp42
-rw-r--r--tests/net/pop3/POP3TestUtils.hpp53
-rw-r--r--tests/net/pop3/POP3UtilsTest.cpp7
4 files changed, 99 insertions, 10 deletions
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 <POP3Command> cmd = POP3Command::createCommand("MY_COMMAND param1 param2");
vmime::ref <testSocket> sok = vmime::create <testSocket>();
- cmd->writeToSocket(sok);
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (sok.dynamicCast <vmime::net::socket>(), 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("+OK Response Text\r\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("-ERR Response Text\r\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("+ challenge_string\r\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("Invalid Response Text\r\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("+OK Response terminated by LF\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), 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 <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), toh);
+
socket->localSend("+OK Response Text\n");
socket->localSend("Line 1\n");
socket->localSend("Line 2\n");
socket->localSend(".\n");
vmime::ref <POP3Response> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), 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 <POP3Response> 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 <[email protected]>
+//
+// 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 <vmime::net::socket> socket,
+ vmime::ref <vmime::net::timeoutHandler> timeoutHandler)
+ : POP3Connection(NULL, NULL),
+ m_socket(socket), m_timeoutHandler(timeoutHandler)
+ {
+ }
+
+ vmime::ref <vmime::net::socket> getSocket()
+ {
+ return m_socket;
+ }
+
+ vmime::ref <vmime::net::timeoutHandler> getTimeoutHandler()
+ {
+ return m_timeoutHandler;
+ }
+
+private:
+
+ vmime::ref <vmime::net::socket> m_socket;
+ vmime::ref <vmime::net::timeoutHandler> 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 <testSocket> socket = vmime::create <testSocket>();
vmime::ref <vmime::net::timeoutHandler> toh = vmime::create <testTimeoutHandler>();
+ vmime::ref <POP3ConnectionTest> conn = vmime::create <POP3ConnectionTest>
+ (socket.dynamicCast <vmime::net::socket>(), 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 <POP3Response> resp =
- POP3Response::readMultilineResponse(socket, toh);
+ POP3Response::readMultilineResponse(conn);
std::map <int, vmime::string> result;
POP3Utils::parseMultiListOrUidlResponse(resp, result);