From feabba44702cf0720535b3af8e1d0ca89ae2b63d Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 12 Feb 2013 17:54:36 +0100 Subject: Unit tests for SMTPCommand and SMTPCommandSet. Fixed SMTPCommandSet::isFinished(). --- tests/net/smtp/SMTPCommandTest.cpp | 155 +++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/net/smtp/SMTPCommandTest.cpp (limited to 'tests/net/smtp/SMTPCommandTest.cpp') diff --git a/tests/net/smtp/SMTPCommandTest.cpp b/tests/net/smtp/SMTPCommandTest.cpp new file mode 100644 index 00000000..93cdf7ae --- /dev/null +++ b/tests/net/smtp/SMTPCommandTest.cpp @@ -0,0 +1,155 @@ +// +// 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/smtp/SMTPCommand.hpp" + + +using namespace vmime::net::smtp; + + +#define VMIME_TEST_SUITE SMTPCommandTest +#define VMIME_TEST_SUITE_MODULE "Net/SMTP" + + +VMIME_TEST_SUITE_BEGIN + + VMIME_TEST_LIST_BEGIN + VMIME_TEST(testCreateCommand) + VMIME_TEST(testCreateCommandParams) + VMIME_TEST(testHELO) + VMIME_TEST(testEHLO) + VMIME_TEST(testAUTH) + VMIME_TEST(testSTARTTLS) + VMIME_TEST(testMAIL) + VMIME_TEST(testRCPT) + VMIME_TEST(testDATA) + VMIME_TEST(testNOOP) + VMIME_TEST(testQUIT) + VMIME_TEST(testWriteToSocket) + VMIME_TEST_LIST_END + + + void testCreateCommand() + { + vmime::ref cmd = SMTPCommand::createCommand("MY_COMMAND"); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "MY_COMMAND", cmd->getText()); + } + + void testCreateCommandParams() + { + vmime::ref cmd = SMTPCommand::createCommand("MY_COMMAND param1 param2"); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "MY_COMMAND param1 param2", cmd->getText()); + } + + void testHELO() + { + vmime::ref cmd = SMTPCommand::HELO("hostname"); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "HELO hostname", cmd->getText()); + } + + void testEHLO() + { + vmime::ref cmd = SMTPCommand::EHLO("hostname"); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "EHLO hostname", cmd->getText()); + } + + void testAUTH() + { + vmime::ref cmd = SMTPCommand::AUTH("saslmechanism"); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "AUTH saslmechanism", cmd->getText()); + } + + void testSTARTTLS() + { + vmime::ref cmd = SMTPCommand::STARTTLS(); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "STARTTLS", cmd->getText()); + } + + void testMAIL() + { + vmime::ref cmd = SMTPCommand::MAIL(vmime::mailbox("me@vmime.org")); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "MAIL FROM:", cmd->getText()); + } + + void testRCPT() + { + vmime::ref cmd = SMTPCommand::RCPT(vmime::mailbox("someone@vmime.org")); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "RCPT TO:", cmd->getText()); + } + + void testDATA() + { + vmime::ref cmd = SMTPCommand::DATA(); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "DATA", cmd->getText()); + } + + void testNOOP() + { + vmime::ref cmd = SMTPCommand::NOOP(); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "NOOP", cmd->getText()); + } + + void testQUIT() + { + vmime::ref cmd = SMTPCommand::QUIT(); + + VASSERT_NOT_NULL("Not null", cmd); + VASSERT_EQ("Text", "QUIT", cmd->getText()); + } + + void testWriteToSocket() + { + vmime::ref cmd = SMTPCommand::createCommand("MY_COMMAND param1 param2"); + + vmime::ref sok = vmime::create (); + cmd->writeToSocket(sok); + + vmime::string response; + sok->localReceive(response); + + VASSERT_EQ("Sent buffer", "MY_COMMAND param1 param2\r\n", response); + } + +VMIME_TEST_SUITE_END -- cgit v1.2.3