annotate 3rdparty/vmime/tests/parser/streamContentHandlerTest.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
rev   line source
ferencd@0 1 //
ferencd@0 2 // VMime library (http://www.vmime.org)
ferencd@0 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
ferencd@0 4 //
ferencd@0 5 // This program is free software; you can redistribute it and/or
ferencd@0 6 // modify it under the terms of the GNU General Public License as
ferencd@0 7 // published by the Free Software Foundation; either version 3 of
ferencd@0 8 // the License, or (at your option) any later version.
ferencd@0 9 //
ferencd@0 10 // This program is distributed in the hope that it will be useful,
ferencd@0 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ferencd@0 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ferencd@0 13 // General Public License for more details.
ferencd@0 14 //
ferencd@0 15 // You should have received a copy of the GNU General Public License along
ferencd@0 16 // with this program; if not, write to the Free Software Foundation, Inc.,
ferencd@0 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ferencd@0 18 //
ferencd@0 19 // Linking this library statically or dynamically with other modules is making
ferencd@0 20 // a combined work based on this library. Thus, the terms and conditions of
ferencd@0 21 // the GNU General Public License cover the whole combination.
ferencd@0 22 //
ferencd@0 23
ferencd@0 24 #include "tests/testUtils.hpp"
ferencd@0 25
ferencd@0 26 #include "vmime/utility/outputStreamAdapter.hpp"
ferencd@0 27
ferencd@0 28
ferencd@0 29 VMIME_TEST_SUITE_BEGIN(streamContentHandlerTest)
ferencd@0 30
ferencd@0 31 VMIME_TEST_LIST_BEGIN
ferencd@0 32 VMIME_TEST(testIsEmpty)
ferencd@0 33 VMIME_TEST(testGetLength)
ferencd@0 34 VMIME_TEST(testIsEncoded)
ferencd@0 35 VMIME_TEST(testGetLength_Encoded)
ferencd@0 36 VMIME_TEST(testExtract)
ferencd@0 37 VMIME_TEST(testExtract_Encoded)
ferencd@0 38 VMIME_TEST(testExtractRaw_Encoded)
ferencd@0 39 VMIME_TEST(testGenerate)
ferencd@0 40 VMIME_TEST(testGenerate_Encoded)
ferencd@0 41 VMIME_TEST_LIST_END
ferencd@0 42
ferencd@0 43
ferencd@0 44 void testIsEmpty()
ferencd@0 45 {
ferencd@0 46 vmime::streamContentHandler cth;
ferencd@0 47
ferencd@0 48 VASSERT_TRUE("empty", cth.isEmpty());
ferencd@0 49 }
ferencd@0 50
ferencd@0 51 void testGetLength()
ferencd@0 52 {
ferencd@0 53 vmime::string data("Test Data");
ferencd@0 54 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 55 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 56
ferencd@0 57 vmime::streamContentHandler cth(stream, data.length());
ferencd@0 58
ferencd@0 59 VASSERT_FALSE("empty", cth.isEmpty());
ferencd@0 60 VASSERT_EQ("length", 9, cth.getLength());
ferencd@0 61 }
ferencd@0 62
ferencd@0 63 void testIsEncoded()
ferencd@0 64 {
ferencd@0 65 vmime::string data("Test Data");
ferencd@0 66 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 67 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 68
ferencd@0 69 vmime::streamContentHandler cth(stream, data.length());
ferencd@0 70
ferencd@0 71 VASSERT_FALSE("encoded", cth.isEncoded());
ferencd@0 72 VASSERT_EQ("encoding", vmime::contentHandler::NO_ENCODING, cth.getEncoding());
ferencd@0 73
ferencd@0 74
ferencd@0 75 vmime::string data2("Zm9vEjRWYmFy=");
ferencd@0 76 vmime::shared_ptr <vmime::utility::inputStream> stream2 =
ferencd@0 77 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data2);
ferencd@0 78
ferencd@0 79 vmime::streamContentHandler cth2(stream2, data2.length(), vmime::encoding("base64"));
ferencd@0 80
ferencd@0 81 VASSERT_TRUE("encoded", cth2.isEncoded());
ferencd@0 82 VASSERT_EQ("encoding", "base64", cth2.getEncoding().generate());
ferencd@0 83 }
ferencd@0 84
ferencd@0 85 void testGetLength_Encoded()
ferencd@0 86 {
ferencd@0 87 vmime::string data("foo=12=34=56bar");
ferencd@0 88 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 89 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 90
ferencd@0 91 vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("quoted-printable"));
ferencd@0 92
ferencd@0 93 // Reported length should be the length of encoded data
ferencd@0 94 VASSERT_EQ("length", 15, cth.getLength());
ferencd@0 95 }
ferencd@0 96
ferencd@0 97 void testExtract()
ferencd@0 98 {
ferencd@0 99 vmime::string data("Test Data");
ferencd@0 100 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 101 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 102
ferencd@0 103 vmime::streamContentHandler cth(stream, data.length());
ferencd@0 104
ferencd@0 105 std::ostringstream oss;
ferencd@0 106 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 107
ferencd@0 108 cth.extract(osa);
ferencd@0 109
ferencd@0 110 VASSERT_EQ("extract", "Test Data", oss.str());
ferencd@0 111 }
ferencd@0 112
ferencd@0 113 void testExtract_Encoded()
ferencd@0 114 {
ferencd@0 115 vmime::string data
ferencd@0 116 ("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk=");
ferencd@0 117 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 118 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 119
ferencd@0 120 vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("base64"));
ferencd@0 121
ferencd@0 122 std::ostringstream oss;
ferencd@0 123 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 124
ferencd@0 125 cth.extract(osa);
ferencd@0 126
ferencd@0 127 // Data should be decoded from B64
ferencd@0 128 VASSERT_EQ("extract",
ferencd@0 129 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", oss.str());
ferencd@0 130 }
ferencd@0 131
ferencd@0 132 void testExtractRaw_Encoded()
ferencd@0 133 {
ferencd@0 134 vmime::string data
ferencd@0 135 ("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk=");
ferencd@0 136 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 137 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 138
ferencd@0 139 vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("base64"));
ferencd@0 140
ferencd@0 141 std::ostringstream oss;
ferencd@0 142 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 143
ferencd@0 144 cth.extractRaw(osa);
ferencd@0 145
ferencd@0 146 // Data should not be decoded
ferencd@0 147 VASSERT_EQ("extractRaw",
ferencd@0 148 "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk=", oss.str());
ferencd@0 149 }
ferencd@0 150
ferencd@0 151 void testGenerate()
ferencd@0 152 {
ferencd@0 153 vmime::string data("foo\x12\x34\x56 bar");
ferencd@0 154 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 155 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 156
ferencd@0 157 vmime::streamContentHandler cth(stream, data.length());
ferencd@0 158
ferencd@0 159 std::ostringstream oss;
ferencd@0 160 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 161
ferencd@0 162 cth.generate(osa, vmime::encoding("base64"));
ferencd@0 163
ferencd@0 164 // Data should be encoded to B64
ferencd@0 165 VASSERT_EQ("generate", "Zm9vEjRWIGJhcg==", oss.str());
ferencd@0 166 }
ferencd@0 167
ferencd@0 168 void testGenerate_Encoded()
ferencd@0 169 {
ferencd@0 170 vmime::string data("foo=12=34=56bar");
ferencd@0 171 vmime::shared_ptr <vmime::utility::inputStream> stream =
ferencd@0 172 vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data);
ferencd@0 173
ferencd@0 174 vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("quoted-printable"));
ferencd@0 175
ferencd@0 176 std::ostringstream oss;
ferencd@0 177 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 178
ferencd@0 179 cth.generate(osa, vmime::encoding("base64"));
ferencd@0 180
ferencd@0 181 // Data should be reencoded from QP to B64
ferencd@0 182 VASSERT_EQ("generate", "Zm9vEjRWYmFy", oss.str());
ferencd@0 183 }
ferencd@0 184
ferencd@0 185 VMIME_TEST_SUITE_END