]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStoreEntryStream.cc
1 #define SQUID_UNIT_TEST 1
4 #include "CapturingStoreEntry.h"
7 #include "StoreEntryStream.h"
9 #include "testStoreEntryStream.h"
12 #include <cppunit/TestAssert.h>
14 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream
);
16 /* init memory pools */
18 void testStoreEntryStream::setUp()
24 testStoreEntryStream::testGetStream()
26 /* Setup a store root so we can create a StoreEntry */
27 StorePointer
aStore (new TestStore
);
30 CapturingStoreEntry
* anEntry
= new CapturingStoreEntry();
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
);
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
);
41 const int preFlushCount
= anEntry
->_flush_calls
;
42 // may have already flushed
43 CPPUNIT_ASSERT(preFlushCount
>= 0);
45 // flushed at least once more
46 CPPUNIT_ASSERT(anEntry
->_flush_calls
> preFlushCount
);
48 CPPUNIT_ASSERT_EQUAL(1, anEntry
->_buffer_calls
);
50 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."),
51 anEntry
->_appended_text
);