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