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