diff options
Diffstat (limited to 'icetray/unittests/testIceTrayMail.cpp')
-rw-r--r-- | icetray/unittests/testIceTrayMail.cpp | 144 |
1 files changed, 62 insertions, 82 deletions
diff --git a/icetray/unittests/testIceTrayMail.cpp b/icetray/unittests/testIceTrayMail.cpp index 24f240c..aea3b66 100644 --- a/icetray/unittests/testIceTrayMail.cpp +++ b/icetray/unittests/testIceTrayMail.cpp @@ -1,13 +1,13 @@ #define BOOST_TEST_MODULE TestIceTrayMail -#include <boost/test/unit_test.hpp> #include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> -#include <memstream.h> +#include <definedDirs.h> +#include <fileUtils.h> #include <mailServer.h> -#include <mockMailServer.h> +#include <memstream.h> #include <mimeImpl.h> -#include <fileUtils.h> -#include <definedDirs.h> +#include <mockMailServer.h> using namespace std::string_literals; using namespace IceTray::Mime; @@ -15,42 +15,43 @@ using namespace IceTray::Mail; using QPTD = std::tuple<std::string_view, std::string_view>; using B64TD = std::tuple<size_t, std::string_view>; -BOOST_DATA_TEST_CASE(quotedPrintable, boost::unit_test::data::make<QPTD>({ - { "", "" }, - { "Simple string", "Simple string" }, - { " \t Leading whitespace", " \t Leading whitespace" }, - { "Trailing whitespace \t \n", "Trailing whitespace \t=20\r\n" }, - { "High byte values £ © ±", "High byte values =C2=A3 =\r\n=C2=A9 =C2=B1" }, - { "<html lang=\"en\">", "<html lang=3D\"en\">" } -}), input, expected) +BOOST_DATA_TEST_CASE(quotedPrintable, + boost::unit_test::data::make<QPTD>( + {{"", ""}, {"Simple string", "Simple string"}, {" \t Leading whitespace", " \t Leading whitespace"}, + {"Trailing whitespace \t \n", "Trailing whitespace \t=20\r\n"}, + {"High byte values £ © ±", "High byte values =C2=A3 =\r\n=C2=A9 =C2=B1"}, + {"<html lang=\"en\">", "<html lang=3D\"en\">"}}), + input, expected) { AdHoc::MemStream ms; TextPart::quotedPrintable(input, ms, 25); BOOST_CHECK_EQUAL(expected, ms.sv()); } -BOOST_DATA_TEST_CASE(base64, boost::unit_test::data::make<B64TD>({ - { 0, "\r\n" }, - { 1, "iQ==\r\n" }, - { 2, "iVA=\r\n" }, - { 3, "iVBO\r\n" }, - { 4, "iVBORw==\r\n" }, - { 5, "iVBORw0=\r\n" }, - { 90, - "iVBORw0KGgoAAAANSUhEUgAA\r\n" - "AAsAAAALCAYAAACprHcmAAAA\r\n" - "BmJLR0QA/wD/AP+gvaeTAAAA\r\n" - "J0lEQVQYlWP8////fwbiwGom\r\n" - "IhUyMDAwMIwqpo9iFgYGhtVE\r\n" }, - { 113, - "iVBORw0KGgoAAAANSUhEUgAA\r\n" - "AAsAAAALCAYAAACprHcmAAAA\r\n" - "BmJLR0QA/wD/AP+gvaeTAAAA\r\n" - "J0lEQVQYlWP8////fwbiwGom\r\n" - "IhUyMDAwMIwqpo9iFgYGhtVE\r\n" - "qj0BAAvPBjJ63HJVAAAAAElF\r\n" - "TkSuQmA=\r\n" }, -}), input, expected) +BOOST_DATA_TEST_CASE(base64, + boost::unit_test::data::make<B64TD>({ + {0, "\r\n"}, + {1, "iQ==\r\n"}, + {2, "iVA=\r\n"}, + {3, "iVBO\r\n"}, + {4, "iVBORw==\r\n"}, + {5, "iVBORw0=\r\n"}, + {90, + "iVBORw0KGgoAAAANSUhEUgAA\r\n" + "AAsAAAALCAYAAACprHcmAAAA\r\n" + "BmJLR0QA/wD/AP+gvaeTAAAA\r\n" + "J0lEQVQYlWP8////fwbiwGom\r\n" + "IhUyMDAwMIwqpo9iFgYGhtVE\r\n"}, + {113, + "iVBORw0KGgoAAAANSUhEUgAA\r\n" + "AAsAAAALCAYAAACprHcmAAAA\r\n" + "BmJLR0QA/wD/AP+gvaeTAAAA\r\n" + "J0lEQVQYlWP8////fwbiwGom\r\n" + "IhUyMDAwMIwqpo9iFgYGhtVE\r\n" + "qj0BAAvPBjJ63HJVAAAAAElF\r\n" + "TkSuQmA=\r\n"}, + }), + input, expected) { AdHoc::MemStream ms; AdHoc::FileUtils::MemMap png(rootDir / "fixtures" / "mail" / "blank.png"); @@ -97,33 +98,26 @@ struct TestBase { const std::string text_content = "Simple text £\r\n"; const std::string html_content = "<html lang=\"en\">\r\n" -"<head>\r\n" -"<title>£</title>\r\n" -"</head>\r\n" -"<html>\r\n"; + "<head>\r\n" + "<title>£</title>\r\n" + "</head>\r\n" + "<html>\r\n"; BOOST_FIXTURE_TEST_SUITE(base, TestBase); BOOST_AUTO_TEST_CASE(single_part) { - e->content = std::make_shared<TextPart>(Headers { - { "X-Source", "single_part" } - }, "text/plain", text_content); + e->content = std::make_shared<TextPart>(Headers {{"X-Source", "single_part"}}, "text/plain", text_content); BasicMailServer::writeEmailContent(e, ms); BOOST_CHECK_EQUAL(ms, AdHoc::FileUtils::MemMap(fixtures / "simple.eml").sv()); } BOOST_AUTO_TEST_CASE(multipart_alt) { - auto text = std::make_shared<TextPart>(Headers { - { "X-Source", "multipart_plain" } - }, "text/plain", text_content); - auto html = std::make_shared<TextPart>(Headers { - { "X-Source", "multipart_html" } - }, "text/html", html_content); - e->content = std::make_shared<MultiPart>(Headers { - { "X-Source", "multipart_top" } - }, "alternative", Parts { text, html }); + auto text = std::make_shared<TextPart>(Headers {{"X-Source", "multipart_plain"}}, "text/plain", text_content); + auto html = std::make_shared<TextPart>(Headers {{"X-Source", "multipart_html"}}, "text/html", html_content); + e->content + = std::make_shared<MultiPart>(Headers {{"X-Source", "multipart_top"}}, "alternative", Parts {text, html}); BasicMailServer::writeEmailContent(e, ms); BOOST_CHECK_EQUAL(ms, AdHoc::FileUtils::MemMap(fixtures / "multipart-alt.eml").sv()); } @@ -131,33 +125,23 @@ BOOST_AUTO_TEST_CASE(multipart_alt) BOOST_AUTO_TEST_CASE(multipart_alt_imgs) { AdHoc::FileUtils::MemMap png(fixtures / "blank.png"); - auto text = std::make_shared<TextPart>(Headers { - { "X-Source", "multipart_plain" } - }, "text/plain", text_content); - auto img1 = std::make_shared<BinaryViewPart>(Headers { - { "X-Source", "multipart_html_img1" } - }, "image/png", png.sv<uint8_t>()); - auto img2 = std::make_shared<BinaryCopyPart>(Headers { - { "X-Source", "multipart_html_img2" } - }, "image/png", std::vector<uint8_t>{ png.sv<uint8_t>().begin(), png.sv<uint8_t>().end() }); - auto html = std::make_shared<TextPart>(Headers { - { "X-Source", "multipart_html_main" } - }, "text/html", html_content); - auto htmlrel = std::make_shared<MultiPart>(Headers { - { "X-Source", "multipart_html" } - }, "related", Parts { html, img1, img2 }); - e->content = std::make_shared<MultiPart>(Headers { - { "X-Source", "multipart_top" } - }, "alternative", Parts { text, htmlrel }); + auto text = std::make_shared<TextPart>(Headers {{"X-Source", "multipart_plain"}}, "text/plain", text_content); + auto img1 = std::make_shared<BinaryViewPart>( + Headers {{"X-Source", "multipart_html_img1"}}, "image/png", png.sv<uint8_t>()); + auto img2 = std::make_shared<BinaryCopyPart>(Headers {{"X-Source", "multipart_html_img2"}}, "image/png", + std::vector<uint8_t> {png.sv<uint8_t>().begin(), png.sv<uint8_t>().end()}); + auto html = std::make_shared<TextPart>(Headers {{"X-Source", "multipart_html_main"}}, "text/html", html_content); + auto htmlrel = std::make_shared<MultiPart>( + Headers {{"X-Source", "multipart_html"}}, "related", Parts {html, img1, img2}); + e->content = std::make_shared<MultiPart>( + Headers {{"X-Source", "multipart_top"}}, "alternative", Parts {text, htmlrel}); BasicMailServer::writeEmailContent(e, ms); BOOST_CHECK_EQUAL(ms, AdHoc::FileUtils::MemMap(fixtures / "multipart-alt-imgs.eml").sv()); } BOOST_AUTO_TEST_CASE(mock_mail_server) { - e->content = std::make_shared<TextPart>(Headers { - { "X-Source", "single_part" } - }, "text/plain", text_content); + e->content = std::make_shared<TextPart>(Headers {{"X-Source", "single_part"}}, "text/plain", text_content); MockMailServerImpl mms; mms.sendEmail(e); auto sent = mms.getSentEmails(); @@ -168,9 +152,7 @@ BOOST_AUTO_TEST_CASE(mock_mail_server) BOOST_AUTO_TEST_CASE(send_real_mail_fail) { e->subject = __PRETTY_FUNCTION__; - e->content = std::make_shared<TextPart>(Headers { - { "X-Source", "single_part" } - }, "text/plain", __PRETTY_FUNCTION__); + e->content = std::make_shared<TextPart>(Headers {{"X-Source", "single_part"}}, "text/plain", __PRETTY_FUNCTION__); LibesmtpMailServer ms("localhost:1"); BOOST_REQUIRE_THROW(ms.sendEmail(e), SendEmailFailed); try { @@ -187,18 +169,16 @@ BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE(send_real_mail #ifndef COVERAGE - , * boost::unit_test::disabled() + , + *boost::unit_test::disabled() #endif - ) +) { - auto e = std::make_shared<Email>(); + auto e = std::make_shared<Email>(); e->from = {__FUNCTION__, "dan@randomdan.homeip.net"}; e->to = {"Dan", "dan@randomdan.homeip.net"}; e->subject = __PRETTY_FUNCTION__; - e->content = std::make_shared<TextPart>(Headers { - { "X-Source", "single_part" } - }, "text/plain", __PRETTY_FUNCTION__); + e->content = std::make_shared<TextPart>(Headers {{"X-Source", "single_part"}}, "text/plain", __PRETTY_FUNCTION__); LibesmtpMailServer ms("smtp.random.lan:25"); ms.sendEmail(e); } - |