diff --git a/SConstruct b/SConstruct index eed044f7..4986af77 100644 --- a/SConstruct +++ b/SConstruct @@ -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', diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp index 613b5328..066b5ab5 100644 --- a/src/net/imap/IMAPConnection.cpp +++ b/src/net/imap/IMAPConnection.cpp @@ -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); } diff --git a/src/net/imap/IMAPTag.cpp b/src/net/imap/IMAPTag.cpp index 6754a15d..14d12788 100644 --- a/src/net/imap/IMAPTag.cpp +++ b/src/net/imap/IMAPTag.cpp @@ -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); diff --git a/tests/net/imap/IMAPTagTest.cpp b/tests/net/imap/IMAPTagTest.cpp new file mode 100644 index 00000000..26ed87c5 --- /dev/null +++ b/tests/net/imap/IMAPTagTest.cpp @@ -0,0 +1,88 @@ +// +// 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 "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 tag = + vmime::create (); + + VASSERT_EQ("init", "a001", static_cast (*tag)); + } + + void testIncrement() + { + vmime::ref tag = + vmime::create (); + + (*tag)++; + VASSERT_EQ("init", "a002", static_cast (*tag)); + + (*tag)++; + VASSERT_EQ("init", "a003", static_cast (*tag)); + + (*tag)++; + VASSERT_EQ("init", "a004", static_cast (*tag)); + } + + void testReset() + { + vmime::ref tag = + vmime::create (); + + for (int i = tag->number() ; i < tag->maximumNumber() ; ++i) + (*tag)++; + + VASSERT_EQ("last", "Z999", static_cast (*tag)); + + (*tag)++; + + VASSERT_EQ("reset", "a001", static_cast (*tag)); + } + + void testNumber() + { + vmime::ref tag = + vmime::create (); + + for (int i = 0 ; i < 41 ; ++i) + (*tag)++; + + VASSERT_EQ("number", 42, tag->number()); + } + +VMIME_TEST_SUITE_END diff --git a/vmime/net/imap/IMAPTag.hpp b/vmime/net/imap/IMAPTag.hpp index 5ff8a649..31da23df 100644 --- a/vmime/net/imap/IMAPTag.hpp +++ b/vmime/net/imap/IMAPTag.hpp @@ -53,6 +53,7 @@ public: IMAPTag& operator++(); // ++IMAPTag const IMAPTag operator++(int); // IMAPTag++ + int maximumNumber() const; int number() const; operator string() const;