annotate 3rdparty/vmime/tests/net/smtp/SMTPCommandSetTest.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
rev   line source
ferencd@0 1 //
ferencd@0 2 // VMime library (http://www.vmime.org)
ferencd@0 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
ferencd@0 4 //
ferencd@0 5 // This program is free software; you can redistribute it and/or
ferencd@0 6 // modify it under the terms of the GNU General Public License as
ferencd@0 7 // published by the Free Software Foundation; either version 3 of
ferencd@0 8 // the License, or (at your option) any later version.
ferencd@0 9 //
ferencd@0 10 // This program is distributed in the hope that it will be useful,
ferencd@0 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ferencd@0 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ferencd@0 13 // General Public License for more details.
ferencd@0 14 //
ferencd@0 15 // You should have received a copy of the GNU General Public License along
ferencd@0 16 // with this program; if not, write to the Free Software Foundation, Inc.,
ferencd@0 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ferencd@0 18 //
ferencd@0 19 // Linking this library statically or dynamically with other modules is making
ferencd@0 20 // a combined work based on this library. Thus, the terms and conditions of
ferencd@0 21 // the GNU General Public License cover the whole combination.
ferencd@0 22 //
ferencd@0 23
ferencd@0 24 #include "tests/testUtils.hpp"
ferencd@0 25
ferencd@0 26 #include "vmime/net/smtp/SMTPCommandSet.hpp"
ferencd@0 27 #include "vmime/net/smtp/SMTPCommand.hpp"
ferencd@0 28
ferencd@0 29
ferencd@0 30 using namespace vmime::net::smtp;
ferencd@0 31
ferencd@0 32
ferencd@0 33 VMIME_TEST_SUITE_BEGIN(SMTPCommandSetTest)
ferencd@0 34
ferencd@0 35 VMIME_TEST_LIST_BEGIN
ferencd@0 36 VMIME_TEST(testCreate)
ferencd@0 37 VMIME_TEST(testCreatePipeline)
ferencd@0 38 VMIME_TEST(testAddCommand)
ferencd@0 39 VMIME_TEST(testAddCommandPipeline)
ferencd@0 40 VMIME_TEST(testWriteToSocket)
ferencd@0 41 VMIME_TEST(testWriteToSocketPipeline)
ferencd@0 42 VMIME_TEST(testGetLastCommandSent)
ferencd@0 43 VMIME_TEST(testGetLastCommandSentPipeline)
ferencd@0 44 VMIME_TEST_LIST_END
ferencd@0 45
ferencd@0 46
ferencd@0 47 void testCreate()
ferencd@0 48 {
ferencd@0 49 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ false);
ferencd@0 50
ferencd@0 51 VASSERT_NOT_NULL("Not null", cset);
ferencd@0 52 VASSERT_FALSE("Finished", cset->isFinished());
ferencd@0 53 }
ferencd@0 54
ferencd@0 55 void testCreatePipeline()
ferencd@0 56 {
ferencd@0 57 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ true);
ferencd@0 58
ferencd@0 59 VASSERT_NOT_NULL("Not null", cset);
ferencd@0 60 VASSERT_FALSE("Finished", cset->isFinished());
ferencd@0 61 }
ferencd@0 62
ferencd@0 63 void testAddCommand()
ferencd@0 64 {
ferencd@0 65 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ false);
ferencd@0 66
ferencd@0 67 VASSERT_NO_THROW("No throw 1", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1")));
ferencd@0 68 VASSERT_EQ("Text", "MY_COMMAND1\r\n", cset->getText());
ferencd@0 69 VASSERT_NO_THROW("No throw 2", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2")));
ferencd@0 70 VASSERT_EQ("Text", "MY_COMMAND1\r\nMY_COMMAND2\r\n", cset->getText());
ferencd@0 71
ferencd@0 72 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 73 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 74
ferencd@0 75 cset->writeToSocket(sok, tracer);
ferencd@0 76 VASSERT_FALSE("Finished", cset->isFinished());
ferencd@0 77
ferencd@0 78 // Can't add commands when writing to socket has started
ferencd@0 79 VASSERT_THROW("Throw", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND3")), std::runtime_error);
ferencd@0 80
ferencd@0 81 cset->writeToSocket(sok, tracer);
ferencd@0 82 VASSERT_TRUE("Finished", cset->isFinished());
ferencd@0 83 }
ferencd@0 84
ferencd@0 85 void testAddCommandPipeline()
ferencd@0 86 {
ferencd@0 87 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ true);
ferencd@0 88
ferencd@0 89 VASSERT_NO_THROW("No throw 1", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1")));
ferencd@0 90 VASSERT_EQ("Text", "MY_COMMAND1\r\n", cset->getText());
ferencd@0 91 VASSERT_NO_THROW("No throw 2", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2")));
ferencd@0 92 VASSERT_EQ("Text", "MY_COMMAND1\r\nMY_COMMAND2\r\n", cset->getText());
ferencd@0 93
ferencd@0 94 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 95 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 96 vmime::string response;
ferencd@0 97
ferencd@0 98 cset->writeToSocket(sok, tracer);
ferencd@0 99 VASSERT_TRUE("Finished", cset->isFinished());
ferencd@0 100
ferencd@0 101 sok->localReceive(response);
ferencd@0 102 VASSERT_EQ("Receive cmds", "MY_COMMAND1\r\nMY_COMMAND2\r\n", response);
ferencd@0 103
ferencd@0 104 // Can't add commands when writing to socket has started
ferencd@0 105 VASSERT_THROW("Throw", cset->addCommand(SMTPCommand::createCommand("MY_COMMAND3")), std::runtime_error);
ferencd@0 106 }
ferencd@0 107
ferencd@0 108 void testWriteToSocket()
ferencd@0 109 {
ferencd@0 110 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ false);
ferencd@0 111
ferencd@0 112 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1"));
ferencd@0 113 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2"));
ferencd@0 114
ferencd@0 115 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 116 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 117 vmime::string response;
ferencd@0 118
ferencd@0 119 cset->writeToSocket(sok, tracer);
ferencd@0 120
ferencd@0 121 sok->localReceive(response);
ferencd@0 122 VASSERT_EQ("Receive cmd 1", "MY_COMMAND1\r\n", response);
ferencd@0 123
ferencd@0 124 cset->writeToSocket(sok, tracer);
ferencd@0 125
ferencd@0 126 sok->localReceive(response);
ferencd@0 127 VASSERT_EQ("Receive cmd 2", "MY_COMMAND2\r\n", response);
ferencd@0 128 }
ferencd@0 129
ferencd@0 130 void testWriteToSocketPipeline()
ferencd@0 131 {
ferencd@0 132 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ true);
ferencd@0 133
ferencd@0 134 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1"));
ferencd@0 135 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2"));
ferencd@0 136
ferencd@0 137 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 138 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 139 vmime::string response;
ferencd@0 140
ferencd@0 141 cset->writeToSocket(sok, tracer);
ferencd@0 142
ferencd@0 143 sok->localReceive(response);
ferencd@0 144 VASSERT_EQ("Receive cmds", "MY_COMMAND1\r\nMY_COMMAND2\r\n", response);
ferencd@0 145 }
ferencd@0 146
ferencd@0 147 void testGetLastCommandSent()
ferencd@0 148 {
ferencd@0 149 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ false);
ferencd@0 150
ferencd@0 151 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1"));
ferencd@0 152 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2"));
ferencd@0 153
ferencd@0 154 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 155 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 156
ferencd@0 157 cset->writeToSocket(sok, tracer);
ferencd@0 158 VASSERT_EQ("Cmd 1", "MY_COMMAND1", cset->getLastCommandSent()->getText());
ferencd@0 159
ferencd@0 160 cset->writeToSocket(sok, tracer);
ferencd@0 161 VASSERT_EQ("Cmd 2", "MY_COMMAND2", cset->getLastCommandSent()->getText());
ferencd@0 162 }
ferencd@0 163
ferencd@0 164 void testGetLastCommandSentPipeline()
ferencd@0 165 {
ferencd@0 166 vmime::shared_ptr <SMTPCommandSet> cset = SMTPCommandSet::create(/* pipelining */ true);
ferencd@0 167
ferencd@0 168 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND1"));
ferencd@0 169 cset->addCommand(SMTPCommand::createCommand("MY_COMMAND2"));
ferencd@0 170
ferencd@0 171 vmime::shared_ptr <vmime::net::tracer> tracer;
ferencd@0 172 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
ferencd@0 173
ferencd@0 174 cset->writeToSocket(sok, tracer);
ferencd@0 175 VASSERT_EQ("Cmd 1", "MY_COMMAND1", cset->getLastCommandSent()->getText());
ferencd@0 176
ferencd@0 177 cset->writeToSocket(sok, tracer);
ferencd@0 178 VASSERT_EQ("Cmd 2", "MY_COMMAND2", cset->getLastCommandSent()->getText());
ferencd@0 179 }
ferencd@0 180
ferencd@0 181 VMIME_TEST_SUITE_END