]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStoreEntryStream.cc
Cleanup: un-wrap C++ header includes
[thirdparty/squid.git] / src / tests / testStoreEntryStream.cc
1 #define SQUID_UNIT_TEST 1
2
3 #include "squid.h"
4 #include "CapturingStoreEntry.h"
5 #include "Mem.h"
6 #include "Store.h"
7 #include "StoreEntryStream.h"
8 #include "testStore.h"
9 #include "testStoreEntryStream.h"
10
11 #include <iomanip>
12 #include <cppunit/TestAssert.h>
13
14 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream );
15
16 /* init memory pools */
17
18 void testStoreEntryStream::setUp()
19 {
20 Mem::Init();
21 }
22
23 void
24 testStoreEntryStream::testGetStream()
25 {
26 /* Setup a store root so we can create a StoreEntry */
27 StorePointer aStore (new TestStore);
28 Store::Root(aStore);
29
30 CapturingStoreEntry * anEntry = new CapturingStoreEntry();
31 {
32 StoreEntryStream stream(anEntry); // locks and unlocks/deletes anEntry
33 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
34 CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls);
35
36 stream.setf(std::ios::fixed);
37 stream << 123456 << std::setprecision(1) << 77.7;
38 stream << " some text" << std::setw(4) << "!" << '.';
39 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
40
41 const int preFlushCount = anEntry->_flush_calls;
42 // may have already flushed
43 CPPUNIT_ASSERT(preFlushCount >= 0);
44 stream.flush();
45 // flushed at least once more
46 CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount);
47
48 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
49
50 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."),
51 anEntry->_appended_text);
52 }
53 Store::Root(NULL);
54 }