Modified IMAP parser constructor to make testing easier.

This commit is contained in:
Vincent Richard 2014-03-16 09:57:36 +01:00
parent 9d73fc5382
commit cfe9c6b1e7
3 changed files with 46 additions and 8 deletions

View File

@ -72,6 +72,9 @@ IMAPConnection::IMAPConnection(shared_ptr <IMAPStore> store, shared_ptr <securit
m_secured(false), m_firstTag(true), m_capabilitiesFetched(false), m_noModSeq(false) m_secured(false), m_firstTag(true), m_capabilitiesFetched(false), m_noModSeq(false)
{ {
m_tag = make_shared <IMAPTag>(); m_tag = make_shared <IMAPTag>();
m_parser = make_shared <IMAPParser>();
m_parser->setTag(m_tag);
} }
@ -135,7 +138,8 @@ void IMAPConnection::connect()
m_socket->connect(address, port); m_socket->connect(address, port);
m_parser = make_shared <IMAPParser>(m_tag, m_socket, m_timeoutHandler); m_parser->setSocket(m_socket);
m_parser->setTimeoutHandler(m_timeoutHandler);
setState(STATE_NON_AUTHENTICATED); setState(STATE_NON_AUTHENTICATED);
@ -808,6 +812,7 @@ shared_ptr <const socket> IMAPConnection::getSocket() const
void IMAPConnection::setSocket(shared_ptr <socket> sok) void IMAPConnection::setSocket(shared_ptr <socket> sok)
{ {
m_socket = sok; m_socket = sok;
m_parser->setSocket(sok);
} }

View File

@ -237,23 +237,50 @@ class VMIME_EXPORT IMAPParser : public object
{ {
public: public:
IMAPParser(weak_ptr <IMAPTag> tag, weak_ptr <socket> sok, weak_ptr <timeoutHandler> _timeoutHandler) IMAPParser()
: m_tag(tag), m_socket(sok), m_progress(NULL), m_strict(false), : m_tag(), m_socket(), m_progress(NULL), m_strict(false),
m_literalHandler(NULL), m_timeoutHandler(_timeoutHandler) m_literalHandler(NULL), m_timeoutHandler()
{ {
} }
/** Set the tag currently used by this parser.
*
* @param tag IMAP command tag
*/
void setTag(shared_ptr <IMAPTag> tag)
{
m_tag = tag;
}
/** Return the tag currently used by this parser.
*
* @return IMAP command tag
*/
shared_ptr <const IMAPTag> getTag() const shared_ptr <const IMAPTag> getTag() const
{ {
return m_tag.lock(); return m_tag.lock();
} }
/** Set the socket currently used by this parser to receive data
* from server.
*
* @param sok socket
*/
void setSocket(shared_ptr <socket> sok) void setSocket(shared_ptr <socket> sok)
{ {
m_socket = sok; m_socket = sok;
} }
/** Set the timeout handler currently used by this parser.
*
* @param toh timeout handler
*/
void setTimeoutHandler(shared_ptr <timeoutHandler> toh)
{
m_timeoutHandler = toh;
}
/** Set whether we operate in strict mode (this may not work /** Set whether we operate in strict mode (this may not work
* with some servers which are not fully standard-compliant). * with some servers which are not fully standard-compliant).
* *

View File

@ -49,8 +49,11 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest)
"a001 OK Capability completed.\r\n"); "a001 OK Capability completed.\r\n");
vmime::shared_ptr <vmime::net::imap::IMAPParser> parser = vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
vmime::make_shared <vmime::net::imap::IMAPParser> vmime::make_shared <vmime::net::imap::IMAPParser>();
(tag, vmime::dynamicCast <vmime::net::socket>(socket), toh);
parser->setTag(tag);
parser->setSocket(socket);
parser->setTimeoutHandler(toh);
parser->setStrict(false); parser->setStrict(false);
VASSERT_NO_THROW("non-strict mode", parser->readResponse(/* literalHandler */ NULL)); VASSERT_NO_THROW("non-strict mode", parser->readResponse(/* literalHandler */ NULL));
@ -87,8 +90,11 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest)
socket->localSend("+\r\n"); socket->localSend("+\r\n");
vmime::shared_ptr <vmime::net::imap::IMAPParser> parser = vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
vmime::make_shared <vmime::net::imap::IMAPParser> vmime::make_shared <vmime::net::imap::IMAPParser>();
(tag, vmime::dynamicCast <vmime::net::socket>(socket), toh);
parser->setTag(tag);
parser->setSocket(socket);
parser->setTimeoutHandler(toh);
parser->setStrict(false); parser->setStrict(false);
VASSERT_NO_THROW("non-strict mode", parser->readResponse()); VASSERT_NO_THROW("non-strict mode", parser->readResponse());