annotate 3rdparty/vmime/tests/net/pop3/POP3ResponseTest.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 "tests/net/pop3/POP3TestUtils.hpp"
ferencd@0 27
ferencd@0 28 #include "vmime/net/pop3/POP3Response.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(POP3ResponseTest)
ferencd@0 35
ferencd@0 36 VMIME_TEST_LIST_BEGIN
ferencd@0 37 VMIME_TEST(testSingleLineResponseOK)
ferencd@0 38 VMIME_TEST(testSingleLineResponseERR)
ferencd@0 39 VMIME_TEST(testSingleLineResponseReady)
ferencd@0 40 VMIME_TEST(testSingleLineResponseInvalid)
ferencd@0 41 VMIME_TEST(testSingleLineResponseLF)
ferencd@0 42 VMIME_TEST(testMultiLineResponse)
ferencd@0 43 VMIME_TEST(testMultiLineResponseLF)
ferencd@0 44 VMIME_TEST(testLargeResponse)
ferencd@0 45 VMIME_TEST_LIST_END
ferencd@0 46
ferencd@0 47
ferencd@0 48 void testSingleLineResponseOK()
ferencd@0 49 {
ferencd@0 50 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 51 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 52
ferencd@0 53 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 54 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 55
ferencd@0 56 socket->localSend("+OK Response Text\r\n");
ferencd@0 57
ferencd@0 58 vmime::shared_ptr <POP3Response> resp =
ferencd@0 59 POP3Response::readResponse(conn);
ferencd@0 60
ferencd@0 61 VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode());
ferencd@0 62 VASSERT_TRUE("Success", resp->isSuccess());
ferencd@0 63 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 64 VASSERT_EQ("Text", "Response Text", resp->getText());
ferencd@0 65 VASSERT_EQ("First Line", "+OK Response Text", resp->getFirstLine());
ferencd@0 66 }
ferencd@0 67
ferencd@0 68 void testSingleLineResponseERR()
ferencd@0 69 {
ferencd@0 70 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 71 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 72
ferencd@0 73 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 74 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 75
ferencd@0 76 socket->localSend("-ERR Response Text\r\n");
ferencd@0 77
ferencd@0 78 vmime::shared_ptr <POP3Response> resp =
ferencd@0 79 POP3Response::readResponse(conn);
ferencd@0 80
ferencd@0 81 VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode());
ferencd@0 82 VASSERT_FALSE("Success", resp->isSuccess());
ferencd@0 83 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 84 VASSERT_EQ("Text", "Response Text", resp->getText());
ferencd@0 85 VASSERT_EQ("First Line", "-ERR Response Text", resp->getFirstLine());
ferencd@0 86 }
ferencd@0 87
ferencd@0 88 void testSingleLineResponseReady()
ferencd@0 89 {
ferencd@0 90 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 91 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 92
ferencd@0 93 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 94 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 95
ferencd@0 96 socket->localSend("+ challenge_string\r\n");
ferencd@0 97
ferencd@0 98 vmime::shared_ptr <POP3Response> resp =
ferencd@0 99 POP3Response::readResponse(conn);
ferencd@0 100
ferencd@0 101 VASSERT_EQ("Code", POP3Response::CODE_READY, resp->getCode());
ferencd@0 102 VASSERT_FALSE("Success", resp->isSuccess());
ferencd@0 103 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 104 VASSERT_EQ("Text", "challenge_string", resp->getText());
ferencd@0 105 VASSERT_EQ("First Line", "+ challenge_string", resp->getFirstLine());
ferencd@0 106 }
ferencd@0 107
ferencd@0 108 void testSingleLineResponseInvalid()
ferencd@0 109 {
ferencd@0 110 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 111 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 112
ferencd@0 113 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 114 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 115
ferencd@0 116 socket->localSend("Invalid Response Text\r\n");
ferencd@0 117
ferencd@0 118 vmime::shared_ptr <POP3Response> resp =
ferencd@0 119 POP3Response::readResponse(conn);
ferencd@0 120
ferencd@0 121 VASSERT_EQ("Code", POP3Response::CODE_ERR, resp->getCode());
ferencd@0 122 VASSERT_FALSE("Success", resp->isSuccess());
ferencd@0 123 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 124 VASSERT_EQ("Text", "Response Text", resp->getText());
ferencd@0 125 VASSERT_EQ("First Line", "Invalid Response Text", resp->getFirstLine());
ferencd@0 126 }
ferencd@0 127
ferencd@0 128 void testSingleLineResponseLF()
ferencd@0 129 {
ferencd@0 130 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 131 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 132
ferencd@0 133 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 134 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 135
ferencd@0 136 socket->localSend("+OK Response terminated by LF\n");
ferencd@0 137
ferencd@0 138 vmime::shared_ptr <POP3Response> resp =
ferencd@0 139 POP3Response::readResponse(conn);
ferencd@0 140
ferencd@0 141 VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode());
ferencd@0 142 VASSERT_TRUE("Success", resp->isSuccess());
ferencd@0 143 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 144 VASSERT_EQ("Text", "Response terminated by LF", resp->getText());
ferencd@0 145 VASSERT_EQ("First Line", "+OK Response terminated by LF", resp->getFirstLine());
ferencd@0 146 }
ferencd@0 147
ferencd@0 148 void testMultiLineResponse()
ferencd@0 149 {
ferencd@0 150 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 151 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 152
ferencd@0 153 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 154 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 155
ferencd@0 156 socket->localSend("+OK Response Text\r\n");
ferencd@0 157 socket->localSend("Line 1\r\n");
ferencd@0 158 socket->localSend("Line 2\r\n");
ferencd@0 159 socket->localSend(".\r\n");
ferencd@0 160
ferencd@0 161 vmime::shared_ptr <POP3Response> resp =
ferencd@0 162 POP3Response::readMultilineResponse(conn);
ferencd@0 163
ferencd@0 164 VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode());
ferencd@0 165 VASSERT_TRUE("Success", resp->isSuccess());
ferencd@0 166 VASSERT_EQ("Lines", 2, resp->getLineCount());
ferencd@0 167 VASSERT_EQ("Text", "Response Text", resp->getText());
ferencd@0 168 VASSERT_EQ("First Line", "+OK Response Text", resp->getFirstLine());
ferencd@0 169 VASSERT_EQ("Line 1", "Line 1", resp->getLineAt(0));
ferencd@0 170 VASSERT_EQ("Line 2", "Line 2", resp->getLineAt(1));
ferencd@0 171 }
ferencd@0 172
ferencd@0 173 void testMultiLineResponseLF()
ferencd@0 174 {
ferencd@0 175 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 176 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 177
ferencd@0 178 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 179 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 180
ferencd@0 181 socket->localSend("+OK Response Text\n");
ferencd@0 182 socket->localSend("Line 1\n");
ferencd@0 183 socket->localSend("Line 2\n");
ferencd@0 184 socket->localSend(".\n");
ferencd@0 185
ferencd@0 186 vmime::shared_ptr <POP3Response> resp =
ferencd@0 187 POP3Response::readMultilineResponse(conn);
ferencd@0 188
ferencd@0 189 VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode());
ferencd@0 190 VASSERT_TRUE("Success", resp->isSuccess());
ferencd@0 191 VASSERT_EQ("Lines", 2, resp->getLineCount());
ferencd@0 192 VASSERT_EQ("Text", "Response Text", resp->getText());
ferencd@0 193 VASSERT_EQ("First Line", "+OK Response Text", resp->getFirstLine());
ferencd@0 194 VASSERT_EQ("Line 1", "Line 1", resp->getLineAt(0));
ferencd@0 195 VASSERT_EQ("Line 2", "Line 2", resp->getLineAt(1));
ferencd@0 196 }
ferencd@0 197
ferencd@0 198 void testLargeResponse()
ferencd@0 199 {
ferencd@0 200 std::ostringstream data;
ferencd@0 201
ferencd@0 202 for (unsigned int i = 0 ; i < 5000 ; ++i)
ferencd@0 203 data << "VMIME.VMIME\nVMIME\r\nVMIME_VMIME";
ferencd@0 204
ferencd@0 205 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
ferencd@0 206 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
ferencd@0 207
ferencd@0 208 vmime::shared_ptr <POP3ConnectionTest> conn = vmime::make_shared <POP3ConnectionTest>
ferencd@0 209 (vmime::dynamicCast <vmime::net::socket>(socket), toh);
ferencd@0 210
ferencd@0 211 socket->localSend("+OK Large Response Follows\n");
ferencd@0 212 socket->localSend(data.str());
ferencd@0 213 socket->localSend("\r\n.\r\n");
ferencd@0 214
ferencd@0 215 vmime::string receivedData;
ferencd@0 216 vmime::utility::outputStreamStringAdapter receivedDataStream(receivedData);
ferencd@0 217
ferencd@0 218 vmime::shared_ptr <POP3Response> resp =
ferencd@0 219 POP3Response::readLargeResponse(conn, receivedDataStream, NULL, 0);
ferencd@0 220
ferencd@0 221 VASSERT_EQ("Code", POP3Response::CODE_OK, resp->getCode());
ferencd@0 222 VASSERT_TRUE("Success", resp->isSuccess());
ferencd@0 223 VASSERT_EQ("Lines", 0, resp->getLineCount());
ferencd@0 224 VASSERT_EQ("Text", "Large Response Follows", resp->getText());
ferencd@0 225 VASSERT_EQ("Data Length", data.str().length(), receivedData.length());
ferencd@0 226 VASSERT_EQ("Data Bytes", data.str(), receivedData);
ferencd@0 227 }
ferencd@0 228
ferencd@0 229 VMIME_TEST_SUITE_END
ferencd@0 230