comparison 3rdparty/vmime/tests/net/smtp/SMTPCommandTest.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/SMTPCommand.hpp"
27
28
29 using namespace vmime::net::smtp;
30
31
32 VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
33
34 VMIME_TEST_LIST_BEGIN
35 VMIME_TEST(testCreateCommand)
36 VMIME_TEST(testCreateCommandParams)
37 VMIME_TEST(testHELO)
38 VMIME_TEST(testEHLO)
39 VMIME_TEST(testAUTH)
40 VMIME_TEST(testAUTH_InitialResponse)
41 VMIME_TEST(testSTARTTLS)
42 VMIME_TEST(testMAIL)
43 VMIME_TEST(testMAIL_Encoded)
44 VMIME_TEST(testMAIL_UTF8)
45 VMIME_TEST(testMAIL_SIZE)
46 VMIME_TEST(testMAIL_SIZE_UTF8)
47 VMIME_TEST(testRCPT)
48 VMIME_TEST(testRCPT_Encoded)
49 VMIME_TEST(testRCPT_UTF8)
50 VMIME_TEST(testRSET)
51 VMIME_TEST(testDATA)
52 VMIME_TEST(testBDAT)
53 VMIME_TEST(testNOOP)
54 VMIME_TEST(testQUIT)
55 VMIME_TEST(testWriteToSocket)
56 VMIME_TEST_LIST_END
57
58
59 void testCreateCommand()
60 {
61 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::createCommand("MY_COMMAND");
62
63 VASSERT_NOT_NULL("Not null", cmd);
64 VASSERT_EQ("Text", "MY_COMMAND", cmd->getText());
65 }
66
67 void testCreateCommandParams()
68 {
69 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::createCommand("MY_COMMAND param1 param2");
70
71 VASSERT_NOT_NULL("Not null", cmd);
72 VASSERT_EQ("Text", "MY_COMMAND param1 param2", cmd->getText());
73 }
74
75 void testHELO()
76 {
77 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::HELO("hostname");
78
79 VASSERT_NOT_NULL("Not null", cmd);
80 VASSERT_EQ("Text", "HELO hostname", cmd->getText());
81 }
82
83 void testEHLO()
84 {
85 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::EHLO("hostname");
86
87 VASSERT_NOT_NULL("Not null", cmd);
88 VASSERT_EQ("Text", "EHLO hostname", cmd->getText());
89 }
90
91 void testAUTH()
92 {
93 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::AUTH("saslmechanism");
94
95 VASSERT_NOT_NULL("Not null", cmd);
96 VASSERT_EQ("Text", "AUTH saslmechanism", cmd->getText());
97 }
98
99 void testAUTH_InitialResponse()
100 {
101 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::AUTH("saslmechanism", "initial-response");
102
103 VASSERT_NOT_NULL("Not null", cmd);
104 VASSERT_EQ("Text", "AUTH saslmechanism initial-response", cmd->getText());
105 }
106
107 void testSTARTTLS()
108 {
109 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::STARTTLS();
110
111 VASSERT_NOT_NULL("Not null", cmd);
112 VASSERT_EQ("Text", "STARTTLS", cmd->getText());
113 }
114
115 void testMAIL()
116 {
117 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(vmime::mailbox("me@vmime.org"), false);
118
119 VASSERT_NOT_NULL("Not null", cmd);
120 VASSERT_EQ("Text", "MAIL FROM:<me@vmime.org>", cmd->getText());
121 }
122
123 void testMAIL_Encoded()
124 {
125 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL
126 (vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false);
127
128 VASSERT_NOT_NULL("Not null", cmd);
129 VASSERT_EQ("Text", "MAIL FROM:<mailtest@xn--r8jz45g.xn--zckzah>", cmd->getText());
130 }
131
132 void testMAIL_UTF8()
133 {
134 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL
135 (vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true);
136
137 VASSERT_NOT_NULL("Not null", cmd);
138 VASSERT_EQ("Text", "MAIL FROM:<mailtest@例え.テスト> SMTPUTF8", cmd->getText());
139 }
140
141 void testMAIL_SIZE()
142 {
143 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL
144 (vmime::mailbox("me@vmime.org"), false, 123456789);
145
146 VASSERT_NOT_NULL("Not null", cmd);
147 VASSERT_EQ("Text", "MAIL FROM:<me@vmime.org> SIZE=123456789", cmd->getText());
148 }
149
150 void testMAIL_SIZE_UTF8()
151 {
152 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL
153 (vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, 123456789);
154
155 VASSERT_NOT_NULL("Not null", cmd);
156 VASSERT_EQ("Text", "MAIL FROM:<mailtest@例え.テスト> SMTPUTF8 SIZE=123456789", cmd->getText());
157 }
158
159 void testRCPT()
160 {
161 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RCPT(vmime::mailbox("someone@vmime.org"), false);
162
163 VASSERT_NOT_NULL("Not null", cmd);
164 VASSERT_EQ("Text", "RCPT TO:<someone@vmime.org>", cmd->getText());
165 }
166
167 void testRCPT_Encoded()
168 {
169 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RCPT
170 (vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false);
171
172 VASSERT_NOT_NULL("Not null", cmd);
173 VASSERT_EQ("Text", "RCPT TO:<mailtest@xn--r8jz45g.xn--zckzah>", cmd->getText());
174 }
175
176 void testRCPT_UTF8()
177 {
178 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RCPT
179 (vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true);
180
181 VASSERT_NOT_NULL("Not null", cmd);
182 VASSERT_EQ("Text", "RCPT TO:<mailtest@例え.テスト>", cmd->getText());
183 }
184
185 void testRSET()
186 {
187 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RSET();
188
189 VASSERT_NOT_NULL("Not null", cmd);
190 VASSERT_EQ("Text", "RSET", cmd->getText());
191 }
192
193 void testDATA()
194 {
195 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::DATA();
196
197 VASSERT_NOT_NULL("Not null", cmd);
198 VASSERT_EQ("Text", "DATA", cmd->getText());
199 }
200
201 void testBDAT()
202 {
203 vmime::shared_ptr <SMTPCommand> cmd1 = SMTPCommand::BDAT(12345, false);
204
205 VASSERT_NOT_NULL("Not null", cmd1);
206 VASSERT_EQ("Text", "BDAT 12345", cmd1->getText());
207
208 vmime::shared_ptr <SMTPCommand> cmd2 = SMTPCommand::BDAT(67890, true);
209
210 VASSERT_NOT_NULL("Not null", cmd2);
211 VASSERT_EQ("Text", "BDAT 67890 LAST", cmd2->getText());
212 }
213
214 void testNOOP()
215 {
216 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::NOOP();
217
218 VASSERT_NOT_NULL("Not null", cmd);
219 VASSERT_EQ("Text", "NOOP", cmd->getText());
220 }
221
222 void testQUIT()
223 {
224 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::QUIT();
225
226 VASSERT_NOT_NULL("Not null", cmd);
227 VASSERT_EQ("Text", "QUIT", cmd->getText());
228 }
229
230 void testWriteToSocket()
231 {
232 vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::createCommand("MY_COMMAND param1 param2");
233
234 vmime::shared_ptr <vmime::net::tracer> tracer;
235 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
236
237 cmd->writeToSocket(sok, tracer);
238
239 vmime::string response;
240 sok->localReceive(response);
241
242 VASSERT_EQ("Sent buffer", "MY_COMMAND param1 param2\r\n", response);
243 }
244
245 VMIME_TEST_SUITE_END