1//
2// QuotedPrintableTest.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 "QuotedPrintableTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Net/QuotedPrintableEncoder.h"
15#include "Poco/Net/QuotedPrintableDecoder.h"
16#include <sstream>
17
18
19using Poco::Net::QuotedPrintableEncoder;
20using Poco::Net::QuotedPrintableDecoder;
21
22
23QuotedPrintableTest::QuotedPrintableTest(const std::string& name): CppUnit::TestCase(name)
24{
25}
26
27
28QuotedPrintableTest::~QuotedPrintableTest()
29{
30}
31
32
33void QuotedPrintableTest::testEncode()
34{
35 std::ostringstream ostr;
36 QuotedPrintableEncoder encoder(ostr);
37
38 encoder <<
39 "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
40 "Proin id odio sit amet metus dignissim porttitor. \r\n"
41 "Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
42 "\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
43 "\200\201\r\n";
44 encoder.close();
45 std::string txt = ostr.str();
46 assertTrue (txt == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
47 "Proin id odio sit amet metus dignissim porttitor.=20\r\n"
48 "Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
49 "odales molestie arcu.\r\n"
50 "\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
51 "=80=81\r\n");
52}
53
54
55void QuotedPrintableTest::testDecode()
56{
57 std::istringstream istr(
58 "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
59 "Proin id odio sit amet metus dignissim porttitor.=20\r\n"
60 "Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
61 "odales molestie arcu.\r\n"
62 "\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
63 "=80=81\r\n"
64 );
65 QuotedPrintableDecoder decoder(istr);
66 std::string str;
67 int c = decoder.get();
68 while (c != -1)
69 {
70 str += (char) c;
71 c = decoder.get();
72 }
73 assertTrue (str == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
74 "Proin id odio sit amet metus dignissim porttitor. \r\n"
75 "Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
76 "\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
77 "\200\201\r\n");
78
79}
80
81
82void QuotedPrintableTest::setUp()
83{
84}
85
86
87void QuotedPrintableTest::tearDown()
88{
89}
90
91
92CppUnit::Test* QuotedPrintableTest::suite()
93{
94 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("QuotedPrintableTest");
95
96 CppUnit_addTest(pSuite, QuotedPrintableTest, testEncode);
97 CppUnit_addTest(pSuite, QuotedPrintableTest, testDecode);
98
99 return pSuite;
100}
101