1//
2// MailStreamTest.cpp
3//
4// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "MailStreamTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Net/MailStream.h"
15#include "Poco/StreamCopier.h"
16#include <sstream>
17
18
19using Poco::Net::MailInputStream;
20using Poco::Net::MailOutputStream;
21using Poco::StreamCopier;
22
23
24MailStreamTest::MailStreamTest(const std::string& name): CppUnit::TestCase(name)
25{
26}
27
28
29MailStreamTest::~MailStreamTest()
30{
31}
32
33
34void MailStreamTest::testMailInputStream()
35{
36 std::istringstream istr(
37 "From: john.doe@no.domain\r\n"
38 "To: jane.doe@no.domain\r\n"
39 "Subject: test\r\n"
40 "\r\n"
41 "This is a test.\r\n"
42 "\rThis.is.\ngarbage\r.\r\n"
43 ".This line starts with a period.\r\n"
44 "..and this one too\r\n"
45 "..\r\n"
46 ".\r\n"
47 );
48
49 MailInputStream mis(istr);
50 std::ostringstream ostr;
51 StreamCopier::copyStream(mis, ostr);
52 std::string s(ostr.str());
53 assertTrue (s ==
54 "From: john.doe@no.domain\r\n"
55 "To: jane.doe@no.domain\r\n"
56 "Subject: test\r\n"
57 "\r\n"
58 "This is a test.\r\n"
59 "\rThis.is.\ngarbage\r.\r\n"
60 ".This line starts with a period.\r\n"
61 ".and this one too\r\n"
62 ".\r\n"
63 );
64}
65
66
67void MailStreamTest::testMailOutputStream()
68{
69 std::string msg(
70 "From: john.doe@no.domain\r\n"
71 "To: jane.doe@no.domain\r\n"
72 "Subject: test\r\n"
73 "\r\n"
74 "This is a test.\r\n"
75 "\rThis.is.\ngarbage\r.\r\n"
76 ".This line starts with a period.\r\n"
77 "\r\n"
78 ".and this one too\r\n"
79 ".\r\n"
80 );
81
82 std::ostringstream ostr;
83 MailOutputStream mos(ostr);
84 mos << msg;
85 mos.close();
86 std::string s(ostr.str());
87 assertTrue (s ==
88 "From: john.doe@no.domain\r\n"
89 "To: jane.doe@no.domain\r\n"
90 "Subject: test\r\n"
91 "\r\n"
92 "This is a test.\r\n"
93 "\rThis.is.\ngarbage\r.\r\n"
94 "..This line starts with a period.\r\n"
95 "\r\n"
96 "..and this one too\r\n"
97 "..\r\n"
98 ".\r\n"
99 );
100}
101
102
103void MailStreamTest::setUp()
104{
105}
106
107
108void MailStreamTest::tearDown()
109{
110}
111
112
113CppUnit::Test* MailStreamTest::suite()
114{
115 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailStreamTest");
116
117 CppUnit_addTest(pSuite, MailStreamTest, testMailInputStream);
118 CppUnit_addTest(pSuite, MailStreamTest, testMailOutputStream);
119
120 return pSuite;
121}
122