Mercurial > thymian
comparison 3rdparty/vmime/tests/net/smtp/SMTPResponseTest.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/SMTPResponse.hpp" | |
| 27 | |
| 28 | |
| 29 VMIME_TEST_SUITE_BEGIN(SMTPResponseTest) | |
| 30 | |
| 31 VMIME_TEST_LIST_BEGIN | |
| 32 VMIME_TEST(testSingleLineResponse) | |
| 33 VMIME_TEST(testSingleLineResponseLF) | |
| 34 VMIME_TEST(testMultiLineResponse) | |
| 35 VMIME_TEST(testMultiLineResponseDifferentCode) | |
| 36 VMIME_TEST(testIncompleteMultiLineResponse) | |
| 37 VMIME_TEST(testNoResponseText) | |
| 38 VMIME_TEST(testEnhancedStatusCode) | |
| 39 VMIME_TEST(testNoEnhancedStatusCode) | |
| 40 VMIME_TEST(testInvalidEnhancedStatusCode) | |
| 41 VMIME_TEST_LIST_END | |
| 42 | |
| 43 | |
| 44 void testSingleLineResponse() | |
| 45 { | |
| 46 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 47 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 48 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 49 vmime::make_shared <testTimeoutHandler>(); | |
| 50 | |
| 51 socket->localSend("123 Response Text\r\n"); | |
| 52 | |
| 53 vmime::net::smtp::SMTPResponse::state responseState; | |
| 54 | |
| 55 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 56 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 57 | |
| 58 VASSERT_EQ("Code", 123, resp->getCode()); | |
| 59 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 60 VASSERT_EQ("Text", "Response Text", resp->getText()); | |
| 61 } | |
| 62 | |
| 63 void testSingleLineResponseLF() | |
| 64 { | |
| 65 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 66 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 67 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 68 vmime::make_shared <testTimeoutHandler>(); | |
| 69 | |
| 70 socket->localSend("123 Response Text\n"); | |
| 71 | |
| 72 vmime::net::smtp::SMTPResponse::state responseState; | |
| 73 | |
| 74 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 75 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 76 | |
| 77 VASSERT_EQ("Code", 123, resp->getCode()); | |
| 78 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 79 VASSERT_EQ("Text", "Response Text", resp->getText()); | |
| 80 } | |
| 81 | |
| 82 void testMultiLineResponse() | |
| 83 { | |
| 84 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 85 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 86 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 87 vmime::make_shared <testTimeoutHandler>(); | |
| 88 | |
| 89 socket->localSend | |
| 90 ( | |
| 91 "123-Response\r\n" | |
| 92 "123 Text\r\n" | |
| 93 ); | |
| 94 | |
| 95 vmime::net::smtp::SMTPResponse::state responseState; | |
| 96 | |
| 97 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 98 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 99 | |
| 100 VASSERT_EQ("Code", 123, resp->getCode()); | |
| 101 VASSERT_EQ("Lines", 2, resp->getLineCount()); | |
| 102 VASSERT_EQ("Text", "Response\nText", resp->getText()); | |
| 103 | |
| 104 VASSERT_EQ("Code", 123, resp->getLineAt(0).getCode()); | |
| 105 VASSERT_EQ("Text", "Response", resp->getLineAt(0).getText()); | |
| 106 | |
| 107 VASSERT_EQ("Code", 123, resp->getLineAt(1).getCode()); | |
| 108 VASSERT_EQ("Text", "Text", resp->getLineAt(1).getText()); | |
| 109 } | |
| 110 | |
| 111 void testMultiLineResponseDifferentCode() | |
| 112 { | |
| 113 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 114 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 115 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 116 vmime::make_shared <testTimeoutHandler>(); | |
| 117 | |
| 118 socket->localSend | |
| 119 ( | |
| 120 "123-Response\r\n" | |
| 121 "456 Text\r\n" | |
| 122 ); | |
| 123 | |
| 124 vmime::net::smtp::SMTPResponse::state responseState; | |
| 125 | |
| 126 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 127 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 128 | |
| 129 VASSERT_EQ("Code", 0, resp->getCode()); | |
| 130 VASSERT_EQ("Lines", 2, resp->getLineCount()); | |
| 131 VASSERT_EQ("Text", "Response\nText", resp->getText()); | |
| 132 | |
| 133 VASSERT_EQ("Code", 123, resp->getLineAt(0).getCode()); | |
| 134 VASSERT_EQ("Text", "Response", resp->getLineAt(0).getText()); | |
| 135 | |
| 136 VASSERT_EQ("Code", 456, resp->getLineAt(1).getCode()); | |
| 137 VASSERT_EQ("Text", "Text", resp->getLineAt(1).getText()); | |
| 138 } | |
| 139 | |
| 140 void testIncompleteMultiLineResponse() | |
| 141 { | |
| 142 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 143 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 144 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 145 vmime::make_shared <testTimeoutHandler>(1); | |
| 146 | |
| 147 socket->localSend | |
| 148 ( | |
| 149 "123-Response\r\n" | |
| 150 "123-Text\r\n" | |
| 151 // Missing data | |
| 152 ); | |
| 153 | |
| 154 vmime::net::smtp::SMTPResponse::state responseState; | |
| 155 | |
| 156 VASSERT_THROW("Incomplete response", | |
| 157 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState), | |
| 158 vmime::exceptions::operation_timed_out); | |
| 159 } | |
| 160 | |
| 161 void testNoResponseText() | |
| 162 { | |
| 163 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 164 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 165 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 166 vmime::make_shared <testTimeoutHandler>(1); | |
| 167 | |
| 168 socket->localSend | |
| 169 ( | |
| 170 "250\r\n" | |
| 171 ); | |
| 172 | |
| 173 vmime::net::smtp::SMTPResponse::state responseState; | |
| 174 | |
| 175 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 176 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 177 | |
| 178 VASSERT_EQ("Code", 250, resp->getCode()); | |
| 179 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 180 VASSERT_EQ("Text", "", resp->getText()); | |
| 181 } | |
| 182 | |
| 183 void testEnhancedStatusCode() | |
| 184 { | |
| 185 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 186 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 187 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 188 vmime::make_shared <testTimeoutHandler>(); | |
| 189 | |
| 190 socket->localSend("250 2.1.5 OK fu13sm4720601wic.7 - gsmtp\r\n"); | |
| 191 | |
| 192 vmime::net::smtp::SMTPResponse::state responseState; | |
| 193 | |
| 194 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 195 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 196 | |
| 197 VASSERT_EQ("Code", 250, resp->getCode()); | |
| 198 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 199 VASSERT_EQ("Text", "2.1.5 OK fu13sm4720601wic.7 - gsmtp", resp->getText()); | |
| 200 VASSERT_EQ("Enh.class", 2, resp->getEnhancedCode().klass); | |
| 201 VASSERT_EQ("Enh.subject", 1, resp->getEnhancedCode().subject); | |
| 202 VASSERT_EQ("Enh.detail", 5, resp->getEnhancedCode().detail); | |
| 203 } | |
| 204 | |
| 205 void testNoEnhancedStatusCode() | |
| 206 { | |
| 207 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 208 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 209 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 210 vmime::make_shared <testTimeoutHandler>(); | |
| 211 | |
| 212 socket->localSend("354 Go ahead fu13sm4720601wic.7 - gsmtp\r\n"); | |
| 213 | |
| 214 vmime::net::smtp::SMTPResponse::state responseState; | |
| 215 | |
| 216 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 217 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 218 | |
| 219 VASSERT_EQ("Code", 354, resp->getCode()); | |
| 220 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 221 VASSERT_EQ("Text", "Go ahead fu13sm4720601wic.7 - gsmtp", resp->getText()); | |
| 222 VASSERT_EQ("Enh.class", 0, resp->getEnhancedCode().klass); | |
| 223 VASSERT_EQ("Enh.subject", 0, resp->getEnhancedCode().subject); | |
| 224 VASSERT_EQ("Enh.detail", 0, resp->getEnhancedCode().detail); | |
| 225 } | |
| 226 | |
| 227 void testInvalidEnhancedStatusCode() | |
| 228 { | |
| 229 vmime::shared_ptr <vmime::net::tracer> tracer; | |
| 230 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); | |
| 231 vmime::shared_ptr <vmime::net::timeoutHandler> toh = | |
| 232 vmime::make_shared <testTimeoutHandler>(); | |
| 233 | |
| 234 socket->localSend("250 4.2 xxx\r\n"); | |
| 235 | |
| 236 vmime::net::smtp::SMTPResponse::state responseState; | |
| 237 | |
| 238 vmime::shared_ptr <vmime::net::smtp::SMTPResponse> resp = | |
| 239 vmime::net::smtp::SMTPResponse::readResponse(tracer, socket, toh, responseState); | |
| 240 | |
| 241 VASSERT_EQ("Code", 250, resp->getCode()); | |
| 242 VASSERT_EQ("Lines", 1, resp->getLineCount()); | |
| 243 VASSERT_EQ("Text", "4.2 xxx", resp->getText()); | |
| 244 VASSERT_EQ("Enh.class", 0, resp->getEnhancedCode().klass); | |
| 245 VASSERT_EQ("Enh.subject", 0, resp->getEnhancedCode().subject); | |
| 246 VASSERT_EQ("Enh.detail", 0, resp->getEnhancedCode().detail); | |
| 247 } | |
| 248 | |
| 249 VMIME_TEST_SUITE_END | |
| 250 |
