Added unit tests for IMAPTag. Initialize sequence number at 1.

This commit is contained in:
Vincent Richard 2013-04-26 22:47:51 +02:00
parent 3f1c507555
commit 5a3d88855b
5 changed files with 103 additions and 5 deletions

View File

@ -396,6 +396,7 @@ libvmimetest_sources = [
# =============================== Net ================================
'tests/net/pop3/POP3ResponseTest.cpp',
'tests/net/pop3/POP3UtilsTest.cpp',
'tests/net/imap/IMAPTagTest.cpp',
'tests/net/smtp/SMTPTransportTest.cpp',
'tests/net/smtp/SMTPCommandTest.cpp',
'tests/net/smtp/SMTPCommandSetTest.cpp',

View File

@ -633,8 +633,6 @@ void IMAPConnection::send(bool tag, const string& what, bool end)
if (tag)
{
++(*m_tag);
oss << string(*m_tag);
oss << " ";
}
@ -648,8 +646,6 @@ void IMAPConnection::send(bool tag, const string& what, bool end)
#else
if (tag)
{
++(*m_tag);
m_socket->send(*m_tag);
m_socket->send(" ");
}
@ -661,6 +657,9 @@ void IMAPConnection::send(bool tag, const string& what, bool end)
m_socket->send("\r\n");
}
#endif
if (tag)
++(*m_tag);
}

View File

@ -42,6 +42,7 @@ IMAPTag::IMAPTag(const int number)
: m_number(number)
{
m_tag.resize(4);
generate();
}
@ -49,13 +50,15 @@ IMAPTag::IMAPTag(const IMAPTag& tag)
: object(), m_number(tag.m_number)
{
m_tag.resize(4);
generate();
}
IMAPTag::IMAPTag()
: m_number(0)
: m_number(1)
{
m_tag.resize(4);
generate();
}
@ -80,6 +83,12 @@ const IMAPTag IMAPTag::operator++(int)
}
int IMAPTag::maximumNumber() const
{
return sm_maxNumber - 1;
}
int IMAPTag::number() const
{
return (m_number);

View File

@ -0,0 +1,88 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
//
// 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 "tests/testUtils.hpp"
#include "vmime/net/imap/IMAPTag.hpp"
VMIME_TEST_SUITE_BEGIN(imapTagTest)
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testConstruct)
VMIME_TEST(testIncrement)
VMIME_TEST(testReset)
VMIME_TEST(testNumber)
VMIME_TEST_LIST_END
void testConstruct()
{
vmime::ref <vmime::net::imap::IMAPTag> tag =
vmime::create <vmime::net::imap::IMAPTag>();
VASSERT_EQ("init", "a001", static_cast <vmime::string>(*tag));
}
void testIncrement()
{
vmime::ref <vmime::net::imap::IMAPTag> tag =
vmime::create <vmime::net::imap::IMAPTag>();
(*tag)++;
VASSERT_EQ("init", "a002", static_cast <vmime::string>(*tag));
(*tag)++;
VASSERT_EQ("init", "a003", static_cast <vmime::string>(*tag));
(*tag)++;
VASSERT_EQ("init", "a004", static_cast <vmime::string>(*tag));
}
void testReset()
{
vmime::ref <vmime::net::imap::IMAPTag> tag =
vmime::create <vmime::net::imap::IMAPTag>();
for (int i = tag->number() ; i < tag->maximumNumber() ; ++i)
(*tag)++;
VASSERT_EQ("last", "Z999", static_cast <vmime::string>(*tag));
(*tag)++;
VASSERT_EQ("reset", "a001", static_cast <vmime::string>(*tag));
}
void testNumber()
{
vmime::ref <vmime::net::imap::IMAPTag> tag =
vmime::create <vmime::net::imap::IMAPTag>();
for (int i = 0 ; i < 41 ; ++i)
(*tag)++;
VASSERT_EQ("number", 42, tag->number());
}
VMIME_TEST_SUITE_END

View File

@ -53,6 +53,7 @@ public:
IMAPTag& operator++(); // ++IMAPTag
const IMAPTag operator++(int); // IMAPTag++
int maximumNumber() const;
int number() const;
operator string() const;