]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/testStoreEntryStream.cc
Merged from trunk.
[thirdparty/squid.git] / src / tests / testStoreEntryStream.cc
CommitLineData
ec94e362
AJ
1#define SQUID_UNIT_TEST 1
2
c21ad0f5 3#include "squid.h"
4#include "Mem.h"
5#include "testStore.h"
6#include "testStoreEntryStream.h"
a553a5a3 7#include "CapturingStoreEntry.h"
c21ad0f5 8#include "Store.h"
9#include "StoreEntryStream.h"
10
11#include <iomanip>
12
13#include <cppunit/TestAssert.h>
14
15CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream );
16
c21ad0f5 17/* init memory pools */
18
16555581 19void testStoreEntryStream::setUp()
c21ad0f5 20{
16555581 21 Mem::Init();
22}
c21ad0f5 23
24void
25testStoreEntryStream::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);
b4f08306 36
37 stream.setf(std::ios::fixed);
38 stream << 123456 << std::setprecision(1) << 77.7;
39 stream << " some text" << std::setw(4) << "!" << '.';
c21ad0f5 40 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
b4f08306 41
42 const int preFlushCount = anEntry->_flush_calls;
43 // may have already flushed
44 CPPUNIT_ASSERT(preFlushCount >= 0);
c21ad0f5 45 stream.flush();
b4f08306 46 // flushed at least once more
47 CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount);
48
c21ad0f5 49 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
b4f08306 50
51 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."),
52anEntry->_appended_text);
c21ad0f5 53 }
54
55 delete anEntry;
56
57 Store::Root(NULL);
58}