ferencd@0: // ferencd@0: // VMime library (http://www.vmime.org) ferencd@0: // Copyright (C) 2002-2013 Vincent Richard ferencd@0: // ferencd@0: // This program is free software; you can redistribute it and/or ferencd@0: // modify it under the terms of the GNU General Public License as ferencd@0: // published by the Free Software Foundation; either version 3 of ferencd@0: // the License, or (at your option) any later version. ferencd@0: // ferencd@0: // This program is distributed in the hope that it will be useful, ferencd@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of ferencd@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ferencd@0: // General Public License for more details. ferencd@0: // ferencd@0: // You should have received a copy of the GNU General Public License along ferencd@0: // with this program; if not, write to the Free Software Foundation, Inc., ferencd@0: // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ferencd@0: // ferencd@0: // Linking this library statically or dynamically with other modules is making ferencd@0: // a combined work based on this library. Thus, the terms and conditions of ferencd@0: // the GNU General Public License cover the whole combination. ferencd@0: // ferencd@0: ferencd@0: #include "tests/testUtils.hpp" ferencd@0: ferencd@0: #include "vmime/net/smtp/SMTPTransport.hpp" ferencd@0: #include "vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp" ferencd@0: #include "vmime/net/smtp/SMTPExceptions.hpp" ferencd@0: ferencd@0: #include "SMTPTransportTestUtils.hpp" ferencd@0: ferencd@0: ferencd@0: VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) ferencd@0: ferencd@0: VMIME_TEST_LIST_BEGIN ferencd@0: VMIME_TEST(testConnectToInvalidServer) ferencd@0: VMIME_TEST(testGreetingError) ferencd@0: VMIME_TEST(testMAILandRCPT) ferencd@0: VMIME_TEST(testChunking) ferencd@0: VMIME_TEST(testSize_Chunking) ferencd@0: VMIME_TEST(testSize_NoChunking) ferencd@0: VMIME_TEST_LIST_END ferencd@0: ferencd@0: ferencd@0: void testConnectToInvalidServer() ferencd@0: { ferencd@0: vmime::shared_ptr sess ferencd@0: = vmime::make_shared (); ferencd@0: ferencd@0: vmime::utility::url url("smtp://invalid-smtp-server"); ferencd@0: vmime::shared_ptr store = sess->getTransport(url); ferencd@0: ferencd@0: VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error); ferencd@0: } ferencd@0: ferencd@0: void testGreetingError() ferencd@0: { ferencd@0: vmime::shared_ptr session = ferencd@0: vmime::make_shared (); ferencd@0: ferencd@0: vmime::shared_ptr tr = session->getTransport ferencd@0: (vmime::utility::url("smtp://localhost")); ferencd@0: ferencd@0: tr->setSocketFactory(vmime::make_shared >()); ferencd@0: tr->setTimeoutHandlerFactory(vmime::make_shared ()); ferencd@0: ferencd@0: VASSERT_THROW("Connection", tr->connect(), ferencd@0: vmime::exceptions::connection_greeting_error); ferencd@0: } ferencd@0: ferencd@0: void testMAILandRCPT() ferencd@0: { ferencd@0: vmime::shared_ptr session = ferencd@0: vmime::make_shared (); ferencd@0: ferencd@0: vmime::shared_ptr tr = session->getTransport ferencd@0: (vmime::utility::url("smtp://localhost")); ferencd@0: ferencd@0: tr->setSocketFactory(vmime::make_shared >()); ferencd@0: tr->setTimeoutHandlerFactory(vmime::make_shared ()); ferencd@0: ferencd@0: VASSERT_NO_THROW("Connection", tr->connect()); ferencd@0: ferencd@0: vmime::mailbox exp("expeditor@test.vmime.org"); ferencd@0: ferencd@0: vmime::mailboxList recips; ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient1@test.vmime.org")); ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient2@test.vmime.org")); ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient3@test.vmime.org")); ferencd@0: ferencd@0: vmime::string data("Message data"); ferencd@0: vmime::utility::inputStreamStringAdapter is(data); ferencd@0: ferencd@0: tr->send(exp, recips, is, 0); ferencd@0: } ferencd@0: ferencd@0: void testChunking() ferencd@0: { ferencd@0: vmime::shared_ptr session = ferencd@0: vmime::make_shared (); ferencd@0: ferencd@0: vmime::shared_ptr tr = session->getTransport ferencd@0: (vmime::utility::url("smtp://localhost")); ferencd@0: ferencd@0: tr->setSocketFactory(vmime::make_shared >()); ferencd@0: tr->setTimeoutHandlerFactory(vmime::make_shared ()); ferencd@0: ferencd@0: tr->connect(); ferencd@0: ferencd@0: VASSERT("Test server should report it supports the CHUNKING extension!", ferencd@0: vmime::dynamicCast (tr)->getConnection()->hasExtension("CHUNKING")); ferencd@0: ferencd@0: vmime::mailbox exp("expeditor@test.vmime.org"); ferencd@0: ferencd@0: vmime::mailboxList recips; ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient@test.vmime.org")); ferencd@0: ferencd@0: vmime::shared_ptr msg = vmime::make_shared (); ferencd@0: ferencd@0: tr->send(msg, exp, recips); ferencd@0: } ferencd@0: ferencd@0: void testSize_Chunking() ferencd@0: { ferencd@0: vmime::shared_ptr session = ferencd@0: vmime::make_shared (); ferencd@0: ferencd@0: vmime::shared_ptr tr = session->getTransport ferencd@0: (vmime::utility::url("smtp://localhost")); ferencd@0: ferencd@0: tr->setSocketFactory(vmime::make_shared > >()); ferencd@0: tr->setTimeoutHandlerFactory(vmime::make_shared ()); ferencd@0: ferencd@0: tr->connect(); ferencd@0: ferencd@0: VASSERT("Test server should report it supports the SIZE extension!", ferencd@0: vmime::dynamicCast (tr)->getConnection()->hasExtension("SIZE")); ferencd@0: ferencd@0: vmime::mailbox exp("expeditor@test.vmime.org"); ferencd@0: ferencd@0: vmime::mailboxList recips; ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient@test.vmime.org")); ferencd@0: ferencd@0: vmime::shared_ptr msg = vmime::make_shared (); ferencd@0: ferencd@0: VASSERT_THROW("Connection", tr->send(msg, exp, recips), ferencd@0: vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException); ferencd@0: } ferencd@0: ferencd@0: void testSize_NoChunking() ferencd@0: { ferencd@0: vmime::shared_ptr session = ferencd@0: vmime::make_shared (); ferencd@0: ferencd@0: vmime::shared_ptr tr = session->getTransport ferencd@0: (vmime::utility::url("smtp://localhost")); ferencd@0: ferencd@0: tr->setSocketFactory(vmime::make_shared > >()); ferencd@0: tr->setTimeoutHandlerFactory(vmime::make_shared ()); ferencd@0: ferencd@0: tr->connect(); ferencd@0: ferencd@0: VASSERT("Test server should report it supports the SIZE extension!", ferencd@0: vmime::dynamicCast (tr)->getConnection()->hasExtension("SIZE")); ferencd@0: ferencd@0: vmime::mailbox exp("expeditor@test.vmime.org"); ferencd@0: ferencd@0: vmime::mailboxList recips; ferencd@0: recips.appendMailbox(vmime::make_shared ("recipient@test.vmime.org")); ferencd@0: ferencd@0: vmime::shared_ptr msg = vmime::make_shared (); ferencd@0: ferencd@0: VASSERT_THROW("Connection", tr->send(msg, exp, recips), ferencd@0: vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException); ferencd@0: } ferencd@0: ferencd@0: VMIME_TEST_SUITE_END ferencd@0: