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