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