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