From f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 21 Nov 2013 22:16:57 +0100 Subject: Boost/C++11 shared pointers. --- tests/net/pop3/POP3CommandTest.cpp | 47 +++++++++++----------- tests/net/pop3/POP3ResponseTest.cpp | 80 ++++++++++++++++++------------------- tests/net/pop3/POP3StoreTest.cpp | 14 +++---- tests/net/pop3/POP3TestUtils.hpp | 15 +++---- tests/net/pop3/POP3UtilsTest.cpp | 10 ++--- 5 files changed, 84 insertions(+), 82 deletions(-) (limited to 'tests/net/pop3') diff --git a/tests/net/pop3/POP3CommandTest.cpp b/tests/net/pop3/POP3CommandTest.cpp index 14c92be4..4733c96b 100644 --- a/tests/net/pop3/POP3CommandTest.cpp +++ b/tests/net/pop3/POP3CommandTest.cpp @@ -59,7 +59,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testCreateCommand() { - vmime::ref cmd = POP3Command::createCommand("MY_COMMAND"); + vmime::shared_ptr cmd = POP3Command::createCommand("MY_COMMAND"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "MY_COMMAND", cmd->getText()); @@ -67,7 +67,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testCreateCommandParams() { - vmime::ref cmd = POP3Command::createCommand("MY_COMMAND param1 param2"); + vmime::shared_ptr cmd = POP3Command::createCommand("MY_COMMAND param1 param2"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "MY_COMMAND param1 param2", cmd->getText()); @@ -75,7 +75,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testCAPA() { - vmime::ref cmd = POP3Command::CAPA(); + vmime::shared_ptr cmd = POP3Command::CAPA(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "CAPA", cmd->getText()); @@ -83,7 +83,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testNOOP() { - vmime::ref cmd = POP3Command::NOOP(); + vmime::shared_ptr cmd = POP3Command::NOOP(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "NOOP", cmd->getText()); @@ -91,7 +91,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testAUTH() { - vmime::ref cmd = POP3Command::AUTH("saslmechanism"); + vmime::shared_ptr cmd = POP3Command::AUTH("saslmechanism"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "AUTH saslmechanism", cmd->getText()); @@ -99,7 +99,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testSTLS() { - vmime::ref cmd = POP3Command::STLS(); + vmime::shared_ptr cmd = POP3Command::STLS(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "STLS", cmd->getText()); @@ -107,7 +107,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testAPOP() { - vmime::ref cmd = POP3Command::APOP("user", "digest"); + vmime::shared_ptr cmd = POP3Command::APOP("user", "digest"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "APOP user digest", cmd->getText()); @@ -115,7 +115,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testUSER() { - vmime::ref cmd = POP3Command::USER("user"); + vmime::shared_ptr cmd = POP3Command::USER("user"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "USER user", cmd->getText()); @@ -123,7 +123,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testPASS() { - vmime::ref cmd = POP3Command::PASS("pass"); + vmime::shared_ptr cmd = POP3Command::PASS("pass"); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "PASS pass", cmd->getText()); @@ -131,7 +131,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testSTAT() { - vmime::ref cmd = POP3Command::STAT(); + vmime::shared_ptr cmd = POP3Command::STAT(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "STAT", cmd->getText()); @@ -139,7 +139,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testLIST() { - vmime::ref cmd = POP3Command::LIST(); + vmime::shared_ptr cmd = POP3Command::LIST(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "LIST", cmd->getText()); @@ -147,7 +147,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testLISTMessage() { - vmime::ref cmd = POP3Command::LIST(42); + vmime::shared_ptr cmd = POP3Command::LIST(42); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "LIST 42", cmd->getText()); @@ -155,7 +155,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testUIDL() { - vmime::ref cmd = POP3Command::UIDL(); + vmime::shared_ptr cmd = POP3Command::UIDL(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "UIDL", cmd->getText()); @@ -163,7 +163,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testUIDLMessage() { - vmime::ref cmd = POP3Command::UIDL(42); + vmime::shared_ptr cmd = POP3Command::UIDL(42); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "UIDL 42", cmd->getText()); @@ -171,7 +171,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testDELE() { - vmime::ref cmd = POP3Command::DELE(42); + vmime::shared_ptr cmd = POP3Command::DELE(42); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "DELE 42", cmd->getText()); @@ -179,7 +179,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testRETR() { - vmime::ref cmd = POP3Command::RETR(42); + vmime::shared_ptr cmd = POP3Command::RETR(42); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "RETR 42", cmd->getText()); @@ -187,7 +187,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testTOP() { - vmime::ref cmd = POP3Command::TOP(42, 567); + vmime::shared_ptr cmd = POP3Command::TOP(42, 567); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "TOP 42 567", cmd->getText()); @@ -195,7 +195,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testRSET() { - vmime::ref cmd = POP3Command::RSET(); + vmime::shared_ptr cmd = POP3Command::RSET(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "RSET", cmd->getText()); @@ -203,7 +203,7 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testQUIT() { - vmime::ref cmd = POP3Command::QUIT(); + vmime::shared_ptr cmd = POP3Command::QUIT(); VASSERT_NOT_NULL("Not null", cmd); VASSERT_EQ("Text", "QUIT", cmd->getText()); @@ -211,11 +211,12 @@ VMIME_TEST_SUITE_BEGIN(POP3CommandTest) void testWriteToSocket() { - vmime::ref cmd = POP3Command::createCommand("MY_COMMAND param1 param2"); + vmime::shared_ptr cmd = POP3Command::createCommand("MY_COMMAND param1 param2"); - vmime::ref sok = vmime::create (); - vmime::ref conn = vmime::create - (sok.dynamicCast (), vmime::null); + vmime::shared_ptr sok = vmime::make_shared (); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (sok), + vmime::shared_ptr ()); cmd->send(conn); diff --git a/tests/net/pop3/POP3ResponseTest.cpp b/tests/net/pop3/POP3ResponseTest.cpp index f1fbcd54..2d3b3d32 100644 --- a/tests/net/pop3/POP3ResponseTest.cpp +++ b/tests/net/pop3/POP3ResponseTest.cpp @@ -47,15 +47,15 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testSingleLineResponseOK() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+OK Response Text\r\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); @@ -67,15 +67,15 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testSingleLineResponseERR() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("-ERR Response Text\r\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode()); @@ -87,15 +87,15 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testSingleLineResponseReady() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+ challenge_string\r\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_READY, resp->getCode()); @@ -107,15 +107,15 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testSingleLineResponseInvalid() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("Invalid Response Text\r\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode()); @@ -127,15 +127,15 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testSingleLineResponseLF() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+OK Response terminated by LF\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); @@ -147,18 +147,18 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testMultiLineResponse() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (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 resp = + vmime::shared_ptr resp = POP3Response::readMultilineResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); @@ -172,18 +172,18 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) void testMultiLineResponseLF() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+OK Response Text\n"); socket->localSend("Line 1\n"); socket->localSend("Line 2\n"); socket->localSend(".\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readMultilineResponse(conn); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); @@ -202,11 +202,11 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) for (unsigned int i = 0 ; i < 5000 ; ++i) data << "VMIME.VMIME\nVMIME\r\nVMIME_VMIME"; - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+OK Large Response Follows\n"); socket->localSend(data.str()); @@ -215,7 +215,7 @@ VMIME_TEST_SUITE_BEGIN(POP3ResponseTest) vmime::string receivedData; vmime::utility::outputStreamStringAdapter receivedDataStream(receivedData); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readLargeResponse(conn, receivedDataStream, NULL, 0); VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode()); diff --git a/tests/net/pop3/POP3StoreTest.cpp b/tests/net/pop3/POP3StoreTest.cpp index d938f472..5517f770 100644 --- a/tests/net/pop3/POP3StoreTest.cpp +++ b/tests/net/pop3/POP3StoreTest.cpp @@ -39,29 +39,29 @@ VMIME_TEST_SUITE_BEGIN(POP3StoreTest) void testCreateFromURL() { - vmime::ref sess - = vmime::create (); + vmime::shared_ptr sess + = vmime::make_shared (); // POP3 vmime::utility::url url("pop3://pop3.vmime.org"); - vmime::ref store = sess->getStore(url); + vmime::shared_ptr store = sess->getStore(url); VASSERT_TRUE("pop3", typeid(*store) == typeid(vmime::net::pop3::POP3Store)); // POP3S vmime::utility::url url2("pop3s://pop3s.vmime.org"); - vmime::ref store2 = sess->getStore(url2); + vmime::shared_ptr store2 = sess->getStore(url2); VASSERT_TRUE("pop3s", typeid(*store2) == typeid(vmime::net::pop3::POP3SStore)); } void testConnectToInvalidServer() { - vmime::ref sess - = vmime::create (); + vmime::shared_ptr sess + = vmime::make_shared (); vmime::utility::url url("pop3://invalid-pop3-server"); - vmime::ref store = sess->getStore(url); + vmime::shared_ptr store = sess->getStore(url); VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error); } diff --git a/tests/net/pop3/POP3TestUtils.hpp b/tests/net/pop3/POP3TestUtils.hpp index 26b6601a..1c6e8935 100644 --- a/tests/net/pop3/POP3TestUtils.hpp +++ b/tests/net/pop3/POP3TestUtils.hpp @@ -29,25 +29,26 @@ class POP3ConnectionTest : public vmime::net::pop3::POP3Connection { public: - POP3ConnectionTest(vmime::ref socket, - vmime::ref timeoutHandler) - : POP3Connection(NULL, NULL), + POP3ConnectionTest(vmime::shared_ptr socket, + vmime::shared_ptr timeoutHandler) + : POP3Connection(vmime::shared_ptr (), + vmime::shared_ptr ()), m_socket(socket), m_timeoutHandler(timeoutHandler) { } - vmime::ref getSocket() + vmime::shared_ptr getSocket() { return m_socket; } - vmime::ref getTimeoutHandler() + vmime::shared_ptr getTimeoutHandler() { return m_timeoutHandler; } private: - vmime::ref m_socket; - vmime::ref m_timeoutHandler; + vmime::shared_ptr m_socket; + vmime::shared_ptr m_timeoutHandler; }; diff --git a/tests/net/pop3/POP3UtilsTest.cpp b/tests/net/pop3/POP3UtilsTest.cpp index 9d443ddb..55a99806 100644 --- a/tests/net/pop3/POP3UtilsTest.cpp +++ b/tests/net/pop3/POP3UtilsTest.cpp @@ -41,11 +41,11 @@ VMIME_TEST_SUITE_BEGIN(POP3UtilsTest) void testParseMultiListOrUidlResponse() { - vmime::ref socket = vmime::create (); - vmime::ref toh = vmime::create (); + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); - vmime::ref conn = vmime::create - (socket.dynamicCast (), toh); + vmime::shared_ptr conn = vmime::make_shared + (vmime::dynamicCast (socket), toh); socket->localSend("+OK Response Text\r\n"); socket->localSend("1 abcdef\r\n"); @@ -55,7 +55,7 @@ VMIME_TEST_SUITE_BEGIN(POP3UtilsTest) socket->localSend("8 yz \r\n"); socket->localSend(".\r\n"); - vmime::ref resp = + vmime::shared_ptr resp = POP3Response::readMultilineResponse(conn); std::map result; -- cgit