annotate 3rdparty/vmime/tests/utility/outputStreamStringAdapterTest.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/outputStreamStringAdapter.hpp"
ferencd@0 27
ferencd@0 28
ferencd@0 29 VMIME_TEST_SUITE_BEGIN(outputStreamStringAdapterTest)
ferencd@0 30
ferencd@0 31 VMIME_TEST_LIST_BEGIN
ferencd@0 32 VMIME_TEST(testWrite)
ferencd@0 33 VMIME_TEST(testWriteBinary)
ferencd@0 34 VMIME_TEST(testWriteCRLF)
ferencd@0 35 VMIME_TEST_LIST_END
ferencd@0 36
ferencd@0 37
ferencd@0 38 void testWrite()
ferencd@0 39 {
ferencd@0 40 vmime::string str("initial data");
ferencd@0 41
ferencd@0 42 vmime::utility::outputStreamStringAdapter stream(str);
ferencd@0 43 stream << "additional data";
ferencd@0 44 stream.flush();
ferencd@0 45
ferencd@0 46 VASSERT_EQ("Write 1 len", 27, str.length());
ferencd@0 47 VASSERT_EQ("Write 1 data", "initial dataadditional data", str);
ferencd@0 48
ferencd@0 49 stream.write("more data");
ferencd@0 50
ferencd@0 51 VASSERT_EQ("Write 2 len", 36, str.length());
ferencd@0 52 VASSERT_EQ("Write 2 data", "initial dataadditional datamore data", str);
ferencd@0 53 }
ferencd@0 54
ferencd@0 55 void testWriteBinary()
ferencd@0 56 {
ferencd@0 57 const vmime::byte_t binaryData[] =
ferencd@0 58 "\xc5\x9a\xc3\xb8\xc9\xb1\xc9\x9b\x20\xc9\x93\xc9\xa8\xc9\xb2\xc9"
ferencd@0 59 "\x91\xc5\x95\xc9\xa3\x20\xc9\x96\xc9\x90\xca\x88\xc9\x92";
ferencd@0 60
ferencd@0 61 vmime::string str;
ferencd@0 62
ferencd@0 63 vmime::utility::outputStreamStringAdapter stream(str);
ferencd@0 64 stream.write(binaryData, sizeof(binaryData));
ferencd@0 65 stream.flush();
ferencd@0 66
ferencd@0 67 VASSERT_EQ("Write", 0, memcmp(binaryData, str.data(), sizeof(binaryData)));
ferencd@0 68 }
ferencd@0 69
ferencd@0 70 void testWriteCRLF()
ferencd@0 71 {
ferencd@0 72 vmime::string str;
ferencd@0 73
ferencd@0 74 vmime::utility::outputStreamStringAdapter stream(str);
ferencd@0 75 stream << "some data";
ferencd@0 76 stream.flush();
ferencd@0 77
ferencd@0 78 stream << "\nmore\r\ndata\r";
ferencd@0 79 stream.flush();
ferencd@0 80
ferencd@0 81 VASSERT_EQ("Write", "some data\nmore\r\ndata\r", str);
ferencd@0 82 }
ferencd@0 83
ferencd@0 84 VMIME_TEST_SUITE_END
ferencd@0 85