|
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 "tests/net/pop3/POP3TestUtils.hpp"
|
|
ferencd@0
|
27
|
|
ferencd@0
|
28 #include "vmime/net/pop3/POP3Command.hpp"
|
|
ferencd@0
|
29
|
|
ferencd@0
|
30
|
|
ferencd@0
|
31 using namespace vmime::net::pop3;
|
|
ferencd@0
|
32
|
|
ferencd@0
|
33
|
|
ferencd@0
|
34 VMIME_TEST_SUITE_BEGIN(POP3CommandTest)
|
|
ferencd@0
|
35
|
|
ferencd@0
|
36 VMIME_TEST_LIST_BEGIN
|
|
ferencd@0
|
37 VMIME_TEST(testCreateCommand)
|
|
ferencd@0
|
38 VMIME_TEST(testCreateCommandParams)
|
|
ferencd@0
|
39 VMIME_TEST(testCAPA)
|
|
ferencd@0
|
40 VMIME_TEST(testNOOP)
|
|
ferencd@0
|
41 VMIME_TEST(testAUTH)
|
|
ferencd@0
|
42 VMIME_TEST(testAUTH_InitialResponse)
|
|
ferencd@0
|
43 VMIME_TEST(testSTLS)
|
|
ferencd@0
|
44 VMIME_TEST(testAPOP)
|
|
ferencd@0
|
45 VMIME_TEST(testUSER)
|
|
ferencd@0
|
46 VMIME_TEST(testPASS)
|
|
ferencd@0
|
47 VMIME_TEST(testSTAT)
|
|
ferencd@0
|
48 VMIME_TEST(testLIST)
|
|
ferencd@0
|
49 VMIME_TEST(testLISTMessage)
|
|
ferencd@0
|
50 VMIME_TEST(testUIDL)
|
|
ferencd@0
|
51 VMIME_TEST(testUIDLMessage)
|
|
ferencd@0
|
52 VMIME_TEST(testDELE)
|
|
ferencd@0
|
53 VMIME_TEST(testRETR)
|
|
ferencd@0
|
54 VMIME_TEST(testTOP)
|
|
ferencd@0
|
55 VMIME_TEST(testRSET)
|
|
ferencd@0
|
56 VMIME_TEST(testQUIT)
|
|
ferencd@0
|
57 VMIME_TEST(testWriteToSocket)
|
|
ferencd@0
|
58 VMIME_TEST_LIST_END
|
|
ferencd@0
|
59
|
|
ferencd@0
|
60
|
|
ferencd@0
|
61 void testCreateCommand()
|
|
ferencd@0
|
62 {
|
|
ferencd@0
|
63 vmime::shared_ptr <POP3Command> cmd = POP3Command::createCommand("MY_COMMAND");
|
|
ferencd@0
|
64
|
|
ferencd@0
|
65 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
66 VASSERT_EQ("Text", "MY_COMMAND", cmd->getText());
|
|
ferencd@0
|
67 }
|
|
ferencd@0
|
68
|
|
ferencd@0
|
69 void testCreateCommandParams()
|
|
ferencd@0
|
70 {
|
|
ferencd@0
|
71 vmime::shared_ptr <POP3Command> cmd = POP3Command::createCommand("MY_COMMAND param1 param2");
|
|
ferencd@0
|
72
|
|
ferencd@0
|
73 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
74 VASSERT_EQ("Text", "MY_COMMAND param1 param2", cmd->getText());
|
|
ferencd@0
|
75 }
|
|
ferencd@0
|
76
|
|
ferencd@0
|
77 void testCAPA()
|
|
ferencd@0
|
78 {
|
|
ferencd@0
|
79 vmime::shared_ptr <POP3Command> cmd = POP3Command::CAPA();
|
|
ferencd@0
|
80
|
|
ferencd@0
|
81 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
82 VASSERT_EQ("Text", "CAPA", cmd->getText());
|
|
ferencd@0
|
83 }
|
|
ferencd@0
|
84
|
|
ferencd@0
|
85 void testNOOP()
|
|
ferencd@0
|
86 {
|
|
ferencd@0
|
87 vmime::shared_ptr <POP3Command> cmd = POP3Command::NOOP();
|
|
ferencd@0
|
88
|
|
ferencd@0
|
89 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
90 VASSERT_EQ("Text", "NOOP", cmd->getText());
|
|
ferencd@0
|
91 }
|
|
ferencd@0
|
92
|
|
ferencd@0
|
93 void testAUTH()
|
|
ferencd@0
|
94 {
|
|
ferencd@0
|
95 vmime::shared_ptr <POP3Command> cmd = POP3Command::AUTH("saslmechanism");
|
|
ferencd@0
|
96
|
|
ferencd@0
|
97 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
98 VASSERT_EQ("Text", "AUTH saslmechanism", cmd->getText());
|
|
ferencd@0
|
99 }
|
|
ferencd@0
|
100
|
|
ferencd@0
|
101 void testAUTH_InitialResponse()
|
|
ferencd@0
|
102 {
|
|
ferencd@0
|
103 vmime::shared_ptr <POP3Command> cmd = POP3Command::AUTH("saslmechanism", "initial-response");
|
|
ferencd@0
|
104
|
|
ferencd@0
|
105 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
106 VASSERT_EQ("Text", "AUTH saslmechanism initial-response", cmd->getText());
|
|
ferencd@0
|
107 }
|
|
ferencd@0
|
108
|
|
ferencd@0
|
109 void testSTLS()
|
|
ferencd@0
|
110 {
|
|
ferencd@0
|
111 vmime::shared_ptr <POP3Command> cmd = POP3Command::STLS();
|
|
ferencd@0
|
112
|
|
ferencd@0
|
113 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
114 VASSERT_EQ("Text", "STLS", cmd->getText());
|
|
ferencd@0
|
115 }
|
|
ferencd@0
|
116
|
|
ferencd@0
|
117 void testAPOP()
|
|
ferencd@0
|
118 {
|
|
ferencd@0
|
119 vmime::shared_ptr <POP3Command> cmd = POP3Command::APOP("user", "digest");
|
|
ferencd@0
|
120
|
|
ferencd@0
|
121 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
122 VASSERT_EQ("Text", "APOP user digest", cmd->getText());
|
|
ferencd@0
|
123 }
|
|
ferencd@0
|
124
|
|
ferencd@0
|
125 void testUSER()
|
|
ferencd@0
|
126 {
|
|
ferencd@0
|
127 vmime::shared_ptr <POP3Command> cmd = POP3Command::USER("user");
|
|
ferencd@0
|
128
|
|
ferencd@0
|
129 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
130 VASSERT_EQ("Text", "USER user", cmd->getText());
|
|
ferencd@0
|
131 }
|
|
ferencd@0
|
132
|
|
ferencd@0
|
133 void testPASS()
|
|
ferencd@0
|
134 {
|
|
ferencd@0
|
135 vmime::shared_ptr <POP3Command> cmd = POP3Command::PASS("pass");
|
|
ferencd@0
|
136
|
|
ferencd@0
|
137 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
138 VASSERT_EQ("Text", "PASS pass", cmd->getText());
|
|
ferencd@0
|
139 }
|
|
ferencd@0
|
140
|
|
ferencd@0
|
141 void testSTAT()
|
|
ferencd@0
|
142 {
|
|
ferencd@0
|
143 vmime::shared_ptr <POP3Command> cmd = POP3Command::STAT();
|
|
ferencd@0
|
144
|
|
ferencd@0
|
145 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
146 VASSERT_EQ("Text", "STAT", cmd->getText());
|
|
ferencd@0
|
147 }
|
|
ferencd@0
|
148
|
|
ferencd@0
|
149 void testLIST()
|
|
ferencd@0
|
150 {
|
|
ferencd@0
|
151 vmime::shared_ptr <POP3Command> cmd = POP3Command::LIST();
|
|
ferencd@0
|
152
|
|
ferencd@0
|
153 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
154 VASSERT_EQ("Text", "LIST", cmd->getText());
|
|
ferencd@0
|
155 }
|
|
ferencd@0
|
156
|
|
ferencd@0
|
157 void testLISTMessage()
|
|
ferencd@0
|
158 {
|
|
ferencd@0
|
159 vmime::shared_ptr <POP3Command> cmd = POP3Command::LIST(42);
|
|
ferencd@0
|
160
|
|
ferencd@0
|
161 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
162 VASSERT_EQ("Text", "LIST 42", cmd->getText());
|
|
ferencd@0
|
163 }
|
|
ferencd@0
|
164
|
|
ferencd@0
|
165 void testUIDL()
|
|
ferencd@0
|
166 {
|
|
ferencd@0
|
167 vmime::shared_ptr <POP3Command> cmd = POP3Command::UIDL();
|
|
ferencd@0
|
168
|
|
ferencd@0
|
169 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
170 VASSERT_EQ("Text", "UIDL", cmd->getText());
|
|
ferencd@0
|
171 }
|
|
ferencd@0
|
172
|
|
ferencd@0
|
173 void testUIDLMessage()
|
|
ferencd@0
|
174 {
|
|
ferencd@0
|
175 vmime::shared_ptr <POP3Command> cmd = POP3Command::UIDL(42);
|
|
ferencd@0
|
176
|
|
ferencd@0
|
177 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
178 VASSERT_EQ("Text", "UIDL 42", cmd->getText());
|
|
ferencd@0
|
179 }
|
|
ferencd@0
|
180
|
|
ferencd@0
|
181 void testDELE()
|
|
ferencd@0
|
182 {
|
|
ferencd@0
|
183 vmime::shared_ptr <POP3Command> cmd = POP3Command::DELE(42);
|
|
ferencd@0
|
184
|
|
ferencd@0
|
185 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
186 VASSERT_EQ("Text", "DELE 42", cmd->getText());
|
|
ferencd@0
|
187 }
|
|
ferencd@0
|
188
|
|
ferencd@0
|
189 void testRETR()
|
|
ferencd@0
|
190 {
|
|
ferencd@0
|
191 vmime::shared_ptr <POP3Command> cmd = POP3Command::RETR(42);
|
|
ferencd@0
|
192
|
|
ferencd@0
|
193 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
194 VASSERT_EQ("Text", "RETR 42", cmd->getText());
|
|
ferencd@0
|
195 }
|
|
ferencd@0
|
196
|
|
ferencd@0
|
197 void testTOP()
|
|
ferencd@0
|
198 {
|
|
ferencd@0
|
199 vmime::shared_ptr <POP3Command> cmd = POP3Command::TOP(42, 567);
|
|
ferencd@0
|
200
|
|
ferencd@0
|
201 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
202 VASSERT_EQ("Text", "TOP 42 567", cmd->getText());
|
|
ferencd@0
|
203 }
|
|
ferencd@0
|
204
|
|
ferencd@0
|
205 void testRSET()
|
|
ferencd@0
|
206 {
|
|
ferencd@0
|
207 vmime::shared_ptr <POP3Command> cmd = POP3Command::RSET();
|
|
ferencd@0
|
208
|
|
ferencd@0
|
209 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
210 VASSERT_EQ("Text", "RSET", cmd->getText());
|
|
ferencd@0
|
211 }
|
|
ferencd@0
|
212
|
|
ferencd@0
|
213 void testQUIT()
|
|
ferencd@0
|
214 {
|
|
ferencd@0
|
215 vmime::shared_ptr <POP3Command> cmd = POP3Command::QUIT();
|
|
ferencd@0
|
216
|
|
ferencd@0
|
217 VASSERT_NOT_NULL("Not null", cmd);
|
|
ferencd@0
|
218 VASSERT_EQ("Text", "QUIT", cmd->getText());
|
|
ferencd@0
|
219 }
|
|
ferencd@0
|
220
|
|
ferencd@0
|
221 void testWriteToSocket()
|
|
ferencd@0
|
222 {
|
|
ferencd@0
|
223 vmime::shared_ptr <POP3Command> cmd = POP3Command::createCommand("MY_COMMAND param1 param2");
|
|
ferencd@0
|
224
|
|
ferencd@0
|
225 vmime::shared_ptr <testSocket> sok = vmime::make_shared <testSocket>();
|
|
ferencd@0
|
226 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
|
|
ferencd@0
|
227 (vmime::dynamicCast <vmime::net::socket>(sok),
|
|
ferencd@0
|
228 vmime::shared_ptr <vmime::net::timeoutHandler>());
|
|
ferencd@0
|
229
|
|
ferencd@0
|
230 cmd->send(conn);
|
|
ferencd@0
|
231
|
|
ferencd@0
|
232 vmime::string response;
|
|
ferencd@0
|
233 sok->localReceive(response);
|
|
ferencd@0
|
234
|
|
ferencd@0
|
235 VASSERT_EQ("Sent buffer", "MY_COMMAND param1 param2\r\n", response);
|
|
ferencd@0
|
236 }
|
|
ferencd@0
|
237
|
|
ferencd@0
|
238 VMIME_TEST_SUITE_END
|