testPackableStream.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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
9#include "squid.h"
10#include "base/PackableStream.h"
11#include "CapturingStoreEntry.h"
12#include "compat/cppunit.h"
13#include "Store.h"
14#include "testStore.h"
15
16#include <iomanip>
17#include <cppunit/TestAssert.h>
18
19class TestPackableStream : public CPPUNIT_NS::TestFixture
20{
24
25protected:
26 void testGetStream();
27};
28
30
31// TODO: test streaming to a MemBuf as well.
32
33void
35{
36 /* Setup a store root so we can create a StoreEntry */
38
40 {
41 anEntry->lock("test");
42 PackableStream stream(*anEntry);
43 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
44 CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls);
45
46 stream.setf(std::ios::fixed);
47 stream << 123456 << std::setprecision(1) << 77.7;
48 stream << " some text" << std::setw(4) << "!" << '.';
49 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
50
51 const int preFlushCount = anEntry->_flush_calls;
52 // may have already flushed
53 CPPUNIT_ASSERT(preFlushCount >= 0);
54 stream.flush();
55 // flushed at least once more
56 CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount);
57
58 CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls);
59 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."), anEntry->_appended_text);
60 }
61 delete anEntry; // does the unlock()
63}
64
65// This test uses main() from ./testStore.cc.
66
void lock(const char *context)
Definition: store.cc:431
CPPUNIT_TEST(testGetStream)
CPPUNIT_TEST_SUITE(TestPackableStream)
void FreeMemory()
undo Init()
Definition: Controller.cc:951
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:945
CPPUNIT_TEST_SUITE_REGISTRATION(TestPackableStream)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors