comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24 #include "tests/testUtils.hpp"
25
26 #include "vmime/utility/outputStreamAdapter.hpp"
27
28
29 VMIME_TEST_SUITE_BEGIN(fileContentHandlerTest)
30
31 VMIME_TEST_LIST_BEGIN
32 VMIME_TEST(testIsEmpty)
33 VMIME_TEST(testGetLength)
34 VMIME_TEST(testIsEncoded)
35 VMIME_TEST(testExtract)
36 VMIME_TEST(testExtractRaw)
37 VMIME_TEST(testGenerate)
38 VMIME_TEST_LIST_END
39
40
41 vmime::shared_ptr <vmime::utility::file> testFile;
42 vmime::string testDataEncoded, testDataDecoded;
43
44
45 void setUp()
46 {
47 testDataDecoded = "ABCDEFGHIJKLMNOPQRSTUVWXYZ \x12\x34\x56\x78\x90 abcdefghijklmnopqrstuvwxyz0123456789";
48 testDataEncoded = "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVogEjRWeJAgYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5";
49
50 std::ostringstream testFilePath;
51 testFilePath << "/tmp/vmime_test_" << (rand() % 999999999);
52
53 vmime::shared_ptr <vmime::utility::fileSystemFactory> fsf =
54 vmime::platform::getHandler()->getFileSystemFactory();
55
56 testFile = fsf->create(fsf->stringToPath(testFilePath.str()));
57 testFile->createFile();
58 testFile->getFileWriter()->getOutputStream()->write(testDataEncoded.data(), testDataEncoded.length());
59 }
60
61 void tearDown()
62 {
63 testFile->remove();
64 testFile = vmime::null;
65 }
66
67
68 void testIsEmpty()
69 {
70 vmime::fileContentHandler cth;
71
72 VASSERT_TRUE("empty", cth.isEmpty());
73 }
74
75 void testGetLength()
76 {
77 vmime::fileContentHandler cth(testFile);
78
79 VASSERT_FALSE("empty", cth.isEmpty());
80 VASSERT_EQ("length", testDataEncoded.length(), cth.getLength());
81 }
82
83 void testIsEncoded()
84 {
85 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
86
87 VASSERT_TRUE("encoded", cth.isEncoded());
88 VASSERT_EQ("encoding", "base64", cth.getEncoding().generate());
89 }
90
91 void testExtract()
92 {
93 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
94
95 std::ostringstream oss;
96 vmime::utility::outputStreamAdapter osa(oss);
97
98 cth.extract(osa);
99
100 // Data should be decoded from B64
101 VASSERT_EQ("extract", testDataDecoded, oss.str());
102 }
103
104 void testExtractRaw()
105 {
106 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
107
108 std::ostringstream oss;
109 vmime::utility::outputStreamAdapter osa(oss);
110
111 cth.extractRaw(osa);
112
113 // Data should not be decoded
114 VASSERT_EQ("extractRaw", testDataEncoded, oss.str());
115 }
116
117 void testGenerate()
118 {
119 vmime::fileContentHandler cth(testFile, vmime::encoding("base64"));
120
121 std::ostringstream oss;
122 vmime::utility::outputStreamAdapter osa(oss);
123
124 cth.generate(osa, vmime::encoding("quoted-printable"));
125
126 // Data should be reencoded from B64 to QP
127 VASSERT_EQ("generate",
128 "ABCDEFGHIJKLMNOPQRSTUVWXYZ =124Vx=90 abcdefghijklmnopqrstuvwxyz0123456789", oss.str());
129 }
130
131 VMIME_TEST_SUITE_END