]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/testPackableStream.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testPackableStream.cc
CommitLineData
4e0938ef 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4e0938ef
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
582c2af2 9#include "squid.h"
7e10ac87 10#include "base/PackableStream.h"
a553a5a3 11#include "CapturingStoreEntry.h"
c21ad0f5 12#include "Store.h"
7e10ac87 13#include "testPackableStream.h"
602d9612 14#include "testStore.h"
c21ad0f5 15
16#include <iomanip>
c21ad0f5 17#include <cppunit/TestAssert.h>
18
7e10ac87 19CPPUNIT_TEST_SUITE_REGISTRATION( testPackableStream );
c21ad0f5 20
c21ad0f5 21/* init memory pools */
22
7e10ac87 23void testPackableStream::setUp()
c21ad0f5 24{
16555581 25 Mem::Init();
26}
c21ad0f5 27
7e10ac87
AJ
28// TODO: test streaming to a MemBuf as well.
29
c21ad0f5 30void
7e10ac87 31testPackableStream::testGetStream()
c21ad0f5 32{
33 /* Setup a store root so we can create a StoreEntry */
2745fea5 34 Store::Init();
c21ad0f5 35
36 CapturingStoreEntry * anEntry = new CapturingStoreEntry();
37 {
7e10ac87
AJ
38 anEntry->lock("test");
39 PackableStream stream(*anEntry);
c21ad0f5 40 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
41 CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls);
b4f08306 42
43 stream.setf(std::ios::fixed);
44 stream << 123456 << std::setprecision(1) << 77.7;
45 stream << " some text" << std::setw(4) << "!" << '.';
c21ad0f5 46 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
b4f08306 47
48 const int preFlushCount = anEntry->_flush_calls;
49 // may have already flushed
26ac0430 50 CPPUNIT_ASSERT(preFlushCount >= 0);
c21ad0f5 51 stream.flush();
b4f08306 52 // flushed at least once more
53 CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount);
54
c21ad0f5 55 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
7e10ac87 56 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."), anEntry->_appended_text);
c21ad0f5 57 }
7e10ac87 58 delete anEntry; // does the unlock()
2745fea5 59 Store::FreeMemory();
c21ad0f5 60}
f53969cc 61