annotate 3rdparty/vmime/tests/parser/fileContentHandlerTest.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(fileContentHandlerTest)
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(testExtract)
ferencd@0 36 VMIME_TEST(testExtractRaw)
ferencd@0 37 VMIME_TEST(testGenerate)
ferencd@0 38 VMIME_TEST_LIST_END
ferencd@0 39
ferencd@0 40
ferencd@0 41 vmime::shared_ptr <vmime::utility::file> testFile;
ferencd@0 42 vmime::string testDataEncoded, testDataDecoded;
ferencd@0 43
ferencd@0 44
ferencd@0 45 void setUp()
ferencd@0 46 {
ferencd@0 47 testDataDecoded = "ABCDEFGHIJKLMNOPQRSTUVWXYZ \x12\x34\x56\x78\x90 abcdefghijklmnopqrstuvwxyz0123456789";
ferencd@0 48 testDataEncoded = "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVogEjRWeJAgYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5";
ferencd@0 49
ferencd@0 50 std::ostringstream testFilePath;
ferencd@0 51 testFilePath << "/tmp/vmime_test_" << (rand() % 999999999);
ferencd@0 52
ferencd@0 53 vmime::shared_ptr <vmime::utility::fileSystemFactory> fsf =
ferencd@0 54 vmime::platform::getHandler()->getFileSystemFactory();
ferencd@0 55
ferencd@0 56 testFile = fsf->create(fsf->stringToPath(testFilePath.str()));
ferencd@0 57 testFile->createFile();
ferencd@0 58 testFile->getFileWriter()->getOutputStream()->write(testDataEncoded.data(), testDataEncoded.length());
ferencd@0 59 }
ferencd@0 60
ferencd@0 61 void tearDown()
ferencd@0 62 {
ferencd@0 63 testFile->remove();
ferencd@0 64 testFile = vmime::null;
ferencd@0 65 }
ferencd@0 66
ferencd@0 67
ferencd@0 68 void testIsEmpty()
ferencd@0 69 {
ferencd@0 70 vmime::fileContentHandler cth;
ferencd@0 71
ferencd@0 72 VASSERT_TRUE("empty", cth.isEmpty());
ferencd@0 73 }
ferencd@0 74
ferencd@0 75 void testGetLength()
ferencd@0 76 {
ferencd@0 77 vmime::fileContentHandler cth(testFile);
ferencd@0 78
ferencd@0 79 VASSERT_FALSE("empty", cth.isEmpty());
ferencd@0 80 VASSERT_EQ("length", testDataEncoded.length(), cth.getLength());
ferencd@0 81 }
ferencd@0 82
ferencd@0 83 void testIsEncoded()
ferencd@0 84 {
ferencd@0 85 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
ferencd@0 86
ferencd@0 87 VASSERT_TRUE("encoded", cth.isEncoded());
ferencd@0 88 VASSERT_EQ("encoding", "base64", cth.getEncoding().generate());
ferencd@0 89 }
ferencd@0 90
ferencd@0 91 void testExtract()
ferencd@0 92 {
ferencd@0 93 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
ferencd@0 94
ferencd@0 95 std::ostringstream oss;
ferencd@0 96 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 97
ferencd@0 98 cth.extract(osa);
ferencd@0 99
ferencd@0 100 // Data should be decoded from B64
ferencd@0 101 VASSERT_EQ("extract", testDataDecoded, oss.str());
ferencd@0 102 }
ferencd@0 103
ferencd@0 104 void testExtractRaw()
ferencd@0 105 {
ferencd@0 106 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
ferencd@0 107
ferencd@0 108 std::ostringstream oss;
ferencd@0 109 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 110
ferencd@0 111 cth.extractRaw(osa);
ferencd@0 112
ferencd@0 113 // Data should not be decoded
ferencd@0 114 VASSERT_EQ("extractRaw", testDataEncoded, oss.str());
ferencd@0 115 }
ferencd@0 116
ferencd@0 117 void testGenerate()
ferencd@0 118 {
ferencd@0 119 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
ferencd@0 120
ferencd@0 121 std::ostringstream oss;
ferencd@0 122 vmime::utility::outputStreamAdapter osa(oss);
ferencd@0 123
ferencd@0 124 cth.generate(osa, vmime::encoding("quoted-printable"));
ferencd@0 125
ferencd@0 126 // Data should be reencoded from B64 to QP
ferencd@0 127 VASSERT_EQ("generate",
ferencd@0 128 "ABCDEFGHIJKLMNOPQRSTUVWXYZ =124Vx=90 abcdefghijklmnopqrstuvwxyz0123456789", oss.str());
ferencd@0 129 }
ferencd@0 130
ferencd@0 131 VMIME_TEST_SUITE_END