Mercurial > thymian
comparison 3rdparty/vmime/tests/net/smtp/SMTPTransportTest.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/SMTPTransport.hpp" | |
| 27 #include "vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp" | |
| 28 #include "vmime/net/smtp/SMTPExceptions.hpp" | |
| 29 | |
| 30 #include "SMTPTransportTestUtils.hpp" | |
| 31 | |
| 32 | |
| 33 VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) | |
| 34 | |
| 35 VMIME_TEST_LIST_BEGIN | |
| 36 VMIME_TEST(testConnectToInvalidServer) | |
| 37 VMIME_TEST(testGreetingError) | |
| 38 VMIME_TEST(testMAILandRCPT) | |
| 39 VMIME_TEST(testChunking) | |
| 40 VMIME_TEST(testSize_Chunking) | |
| 41 VMIME_TEST(testSize_NoChunking) | |
| 42 VMIME_TEST_LIST_END | |
| 43 | |
| 44 | |
| 45 void testConnectToInvalidServer() | |
| 46 { | |
| 47 vmime::shared_ptr <vmime::net::session> sess | |
| 48 = vmime::make_shared <vmime::net::session>(); | |
| 49 | |
| 50 vmime::utility::url url("smtp://invalid-smtp-server"); | |
| 51 vmime::shared_ptr <vmime::net::transport> store = sess->getTransport(url); | |
| 52 | |
| 53 VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error); | |
| 54 } | |
| 55 | |
| 56 void testGreetingError() | |
| 57 { | |
| 58 vmime::shared_ptr <vmime::net::session> session = | |
| 59 vmime::make_shared <vmime::net::session>(); | |
| 60 | |
| 61 vmime::shared_ptr <vmime::net::transport> tr = session->getTransport | |
| 62 (vmime::utility::url("smtp://localhost")); | |
| 63 | |
| 64 tr->setSocketFactory(vmime::make_shared <testSocketFactory <greetingErrorSMTPTestSocket> >()); | |
| 65 tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>()); | |
| 66 | |
| 67 VASSERT_THROW("Connection", tr->connect(), | |
| 68 vmime::exceptions::connection_greeting_error); | |
| 69 } | |
| 70 | |
| 71 void testMAILandRCPT() | |
| 72 { | |
| 73 vmime::shared_ptr <vmime::net::session> session = | |
| 74 vmime::make_shared <vmime::net::session>(); | |
| 75 | |
| 76 vmime::shared_ptr <vmime::net::transport> tr = session->getTransport | |
| 77 (vmime::utility::url("smtp://localhost")); | |
| 78 | |
| 79 tr->setSocketFactory(vmime::make_shared <testSocketFactory <MAILandRCPTSMTPTestSocket> >()); | |
| 80 tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>()); | |
| 81 | |
| 82 VASSERT_NO_THROW("Connection", tr->connect()); | |
| 83 | |
| 84 vmime::mailbox exp("expeditor@test.vmime.org"); | |
| 85 | |
| 86 vmime::mailboxList recips; | |
| 87 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient1@test.vmime.org")); | |
| 88 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient2@test.vmime.org")); | |
| 89 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient3@test.vmime.org")); | |
| 90 | |
| 91 vmime::string data("Message data"); | |
| 92 vmime::utility::inputStreamStringAdapter is(data); | |
| 93 | |
| 94 tr->send(exp, recips, is, 0); | |
| 95 } | |
| 96 | |
| 97 void testChunking() | |
| 98 { | |
| 99 vmime::shared_ptr <vmime::net::session> session = | |
| 100 vmime::make_shared <vmime::net::session>(); | |
| 101 | |
| 102 vmime::shared_ptr <vmime::net::transport> tr = session->getTransport | |
| 103 (vmime::utility::url("smtp://localhost")); | |
| 104 | |
| 105 tr->setSocketFactory(vmime::make_shared <testSocketFactory <chunkingSMTPTestSocket> >()); | |
| 106 tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>()); | |
| 107 | |
| 108 tr->connect(); | |
| 109 | |
| 110 VASSERT("Test server should report it supports the CHUNKING extension!", | |
| 111 vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("CHUNKING")); | |
| 112 | |
| 113 vmime::mailbox exp("expeditor@test.vmime.org"); | |
| 114 | |
| 115 vmime::mailboxList recips; | |
| 116 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org")); | |
| 117 | |
| 118 vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPTestMessage>(); | |
| 119 | |
| 120 tr->send(msg, exp, recips); | |
| 121 } | |
| 122 | |
| 123 void testSize_Chunking() | |
| 124 { | |
| 125 vmime::shared_ptr <vmime::net::session> session = | |
| 126 vmime::make_shared <vmime::net::session>(); | |
| 127 | |
| 128 vmime::shared_ptr <vmime::net::transport> tr = session->getTransport | |
| 129 (vmime::utility::url("smtp://localhost")); | |
| 130 | |
| 131 tr->setSocketFactory(vmime::make_shared <testSocketFactory <bigMessageSMTPTestSocket <true> > >()); | |
| 132 tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>()); | |
| 133 | |
| 134 tr->connect(); | |
| 135 | |
| 136 VASSERT("Test server should report it supports the SIZE extension!", | |
| 137 vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("SIZE")); | |
| 138 | |
| 139 vmime::mailbox exp("expeditor@test.vmime.org"); | |
| 140 | |
| 141 vmime::mailboxList recips; | |
| 142 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org")); | |
| 143 | |
| 144 vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPBigTestMessage4MB>(); | |
| 145 | |
| 146 VASSERT_THROW("Connection", tr->send(msg, exp, recips), | |
| 147 vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException); | |
| 148 } | |
| 149 | |
| 150 void testSize_NoChunking() | |
| 151 { | |
| 152 vmime::shared_ptr <vmime::net::session> session = | |
| 153 vmime::make_shared <vmime::net::session>(); | |
| 154 | |
| 155 vmime::shared_ptr <vmime::net::transport> tr = session->getTransport | |
| 156 (vmime::utility::url("smtp://localhost")); | |
| 157 | |
| 158 tr->setSocketFactory(vmime::make_shared <testSocketFactory <bigMessageSMTPTestSocket <false> > >()); | |
| 159 tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>()); | |
| 160 | |
| 161 tr->connect(); | |
| 162 | |
| 163 VASSERT("Test server should report it supports the SIZE extension!", | |
| 164 vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("SIZE")); | |
| 165 | |
| 166 vmime::mailbox exp("expeditor@test.vmime.org"); | |
| 167 | |
| 168 vmime::mailboxList recips; | |
| 169 recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org")); | |
| 170 | |
| 171 vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPBigTestMessage4MB>(); | |
| 172 | |
| 173 VASSERT_THROW("Connection", tr->send(msg, exp, recips), | |
| 174 vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException); | |
| 175 } | |
| 176 | |
| 177 VMIME_TEST_SUITE_END | |
| 178 |
