forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipartWriterTest.cpp
More file actions
executable file
·96 lines (74 loc) · 2.15 KB
/
MultipartWriterTest.cpp
File metadata and controls
executable file
·96 lines (74 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// MultipartWriterTest.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/MultipartWriterTest.cpp#1 $
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "MultipartWriterTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Net/MultipartWriter.h"
#include "Poco/Net/MessageHeader.h"
#include <sstream>
using Poco::Net::MultipartWriter;
using Poco::Net::MessageHeader;
MultipartWriterTest::MultipartWriterTest(const std::string& name): CppUnit::TestCase(name)
{
}
MultipartWriterTest::~MultipartWriterTest()
{
}
void MultipartWriterTest::testWriteOnePart()
{
std::ostringstream ostr;
MultipartWriter w(ostr, "MIME_boundary_01234567");
assert (w.boundary() == "MIME_boundary_01234567");
MessageHeader h;
h.set("name1", "value1");
w.nextPart(h);
ostr << "this is part 1";
w.close();
std::string s = ostr.str();
assert (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
}
void MultipartWriterTest::testWriteTwoParts()
{
std::ostringstream ostr;
MultipartWriter w(ostr, "MIME_boundary_01234567");
MessageHeader h;
h.set("name1", "value1");
w.nextPart(h);
ostr << "this is part 1";
h.clear();
w.nextPart(h);
ostr << "this is part 2";
w.close();
std::string s = ostr.str();
assert (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
}
void MultipartWriterTest::testBoundary()
{
std::ostringstream ostr;
MultipartWriter w(ostr);
std::string boundary = w.boundary();
assert (boundary.substr(0, 14) == "MIME_boundary_");
assert (boundary.length() == 14 + 16);
}
void MultipartWriterTest::setUp()
{
}
void MultipartWriterTest::tearDown()
{
}
CppUnit::Test* MultipartWriterTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MultipartWriterTest");
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteOnePart);
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteTwoParts);
CppUnit_addTest(pSuite, MultipartWriterTest, testBoundary);
return pSuite;
}