forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartialStreamTest.cpp
More file actions
119 lines (95 loc) · 2.85 KB
/
PartialStreamTest.cpp
File metadata and controls
119 lines (95 loc) · 2.85 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// PartialStreamTest.cpp
//
// $Id: //poco/1.4/Zip/testsuite/src/PartialStreamTest.cpp#1 $
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "PartialStreamTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Zip/PartialStream.h"
#include <sstream>
using namespace Poco::Zip;
PartialStreamTest::PartialStreamTest(const std::string& name): CppUnit::TestCase(name)
{
}
PartialStreamTest::~PartialStreamTest()
{
}
void PartialStreamTest::testReading()
{
std::string message("some dummy message !");
std::string prefix("pre ");
std::string postfix(" post");
std::string result(prefix+message+postfix);
std::istringstream istr(message);
PartialInputStream in(istr, 0, static_cast<std::streamoff>(message.length()), true, prefix, postfix);
char buf[124];
in.read(buf, 124);
std::string res(buf, static_cast<std::string::size_type>(in.gcount()));
assert (res == result);
}
void PartialStreamTest::testWriting()
{
std::string prefix("X");
std::string message("some test message");
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
assert (out.good());
out.close();
std::string res (ostr.str());
assert (out.bytesWritten() == message.size());
assert (message == res);
}
void PartialStreamTest::testWritingZero()
{
std::string prefix("X");
std::string message;
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
assert (out.good());
out.close();
std::string res (ostr.str());
assert (out.bytesWritten() == message.size());
assert (message == res);
}
void PartialStreamTest::testWritingOne()
{
std::string prefix("X");
std::string message("a");
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
assert (out.good());
out.close();
std::string res (ostr.str());
assert (out.bytesWritten() == message.size());
assert (message == res);
}
void PartialStreamTest::setUp()
{
}
void PartialStreamTest::tearDown()
{
}
CppUnit::Test* PartialStreamTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PartialStreamTest");
CppUnit_addTest(pSuite, PartialStreamTest, testReading);
CppUnit_addTest(pSuite, PartialStreamTest, testWriting);
CppUnit_addTest(pSuite, PartialStreamTest, testWritingZero);
CppUnit_addTest(pSuite, PartialStreamTest, testWritingOne);
return pSuite;
}