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