Squid Web Cache
master
Loading...
Searching...
No Matches
testPackableStream.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3
*
4
* Squid software is distributed under GPLv2+ license and includes
5
* contributions from numerous individuals and organizations.
6
* Please see the COPYING and CONTRIBUTORS files for details.
7
*/
8
9
#include "
squid.h
"
10
#include "
base/PackableStream.h
"
11
#include "
CapturingStoreEntry.h
"
12
#include "
compat/cppunit.h
"
13
#include "
Store.h
"
14
#include "
testStore.h
"
15
16
#include <iomanip>
17
#include <cppunit/TestAssert.h>
18
19
class
TestPackableStream
:
public
CPPUNIT_NS::TestFixture
20
{
21
CPPUNIT_TEST_SUITE
(
TestPackableStream
);
22
CPPUNIT_TEST
(
testGetStream
);
23
CPPUNIT_TEST_SUITE_END
();
24
25
protected
:
26
void
testGetStream
();
27
};
28
29
CPPUNIT_TEST_SUITE_REGISTRATION
(
TestPackableStream
);
30
31
// TODO: test streaming to a MemBuf as well.
32
33
void
34
TestPackableStream::testGetStream
()
35
{
36
CapturingStoreEntry
* anEntry =
new
CapturingStoreEntry
();
37
{
38
anEntry->
lock
(
"test"
);
39
PackableStream
stream(*anEntry);
40
CPPUNIT_ASSERT_EQUAL(1, anEntry->
_buffer_calls
);
41
CPPUNIT_ASSERT_EQUAL(0, anEntry->
_flush_calls
);
42
43
stream.setf(std::ios::fixed);
44
stream << 123456 << std::setprecision(1) << 77.7;
45
stream <<
" some text"
<< std::setw(4) <<
"!"
<<
'.'
;
46
CPPUNIT_ASSERT_EQUAL(1, anEntry->
_buffer_calls
);
47
48
const
int
preFlushCount = anEntry->
_flush_calls
;
49
// may have already flushed
50
CPPUNIT_ASSERT(preFlushCount >= 0);
51
stream.flush();
52
// flushed at least once more
53
CPPUNIT_ASSERT(anEntry->
_flush_calls
> preFlushCount);
54
55
CPPUNIT_ASSERT_EQUAL(1, anEntry->
_buffer_calls
);
56
CPPUNIT_ASSERT_EQUAL(
String
(
"12345677.7 some text !."
), anEntry->
_appended_text
);
57
}
58
delete
anEntry;
// does the unlock()
59
}
60
61
// This test uses main() from ./testStore.cc.
62
CapturingStoreEntry.h
PackableStream.h
Store.h
CapturingStoreEntry
Definition
CapturingStoreEntry.h:17
CapturingStoreEntry::_flush_calls
int _flush_calls
Definition
CapturingStoreEntry.h:25
CapturingStoreEntry::_buffer_calls
int _buffer_calls
Definition
CapturingStoreEntry.h:24
CapturingStoreEntry::_appended_text
String _appended_text
Definition
CapturingStoreEntry.h:23
PackableStream
Definition
PackableStream.h:76
StoreEntry::lock
void lock(const char *context)
Definition
store.cc:445
String
Definition
SquidString.h:27
TestPackableStream
Definition
testPackableStream.cc:20
TestPackableStream::CPPUNIT_TEST_SUITE_END
CPPUNIT_TEST_SUITE_END()
TestPackableStream::CPPUNIT_TEST
CPPUNIT_TEST(testGetStream)
TestPackableStream::CPPUNIT_TEST_SUITE
CPPUNIT_TEST_SUITE(TestPackableStream)
TestPackableStream::testGetStream
void testGetStream()
Definition
testPackableStream.cc:34
cppunit.h
squid.h
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(TestPackableStream)
testStore.h
squid
src
tests
testPackableStream.cc
Generated by
1.9.8