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