]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testPackableStream.cc
063b86a674d4c16eb75724c90d5684849324db5b
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
10 #include "base/PackableStream.h"
11 #include "CapturingStoreEntry.h"
13 #include "testPackableStream.h"
14 #include "testStore.h"
17 #include <cppunit/TestAssert.h>
19 CPPUNIT_TEST_SUITE_REGISTRATION( testPackableStream
);
21 /* init memory pools */
23 void testPackableStream::setUp()
28 // TODO: test streaming to a MemBuf as well.
31 testPackableStream::testGetStream()
33 /* Setup a store root so we can create a StoreEntry */
36 CapturingStoreEntry
* anEntry
= new CapturingStoreEntry();
38 anEntry
->lock("test");
39 PackableStream
stream(*anEntry
);
40 CPPUNIT_ASSERT_EQUAL(1, anEntry
->_buffer_calls
);
41 CPPUNIT_ASSERT_EQUAL(0, anEntry
->_flush_calls
);
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
);
48 const int preFlushCount
= anEntry
->_flush_calls
;
49 // may have already flushed
50 CPPUNIT_ASSERT(preFlushCount
>= 0);
52 // flushed at least once more
53 CPPUNIT_ASSERT(anEntry
->_flush_calls
> preFlushCount
);
55 CPPUNIT_ASSERT_EQUAL(1, anEntry
->_buffer_calls
);
56 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."), anEntry
->_appended_text
);
58 delete anEntry
; // does the unlock()