]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStoreEntryStream.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
10 #include "CapturingStoreEntry.h"
12 #include "StoreEntryStream.h"
13 #include "testStore.h"
14 #include "testStoreEntryStream.h"
17 #include <cppunit/TestAssert.h>
19 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream
);
21 /* init memory pools */
23 void testStoreEntryStream::setUp()
29 testStoreEntryStream::testGetStream()
31 /* Setup a store root so we can create a StoreEntry */
32 StorePointer
aStore (new TestStore
);
35 CapturingStoreEntry
* anEntry
= new CapturingStoreEntry();
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
);
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
);
46 const int preFlushCount
= anEntry
->_flush_calls
;
47 // may have already flushed
48 CPPUNIT_ASSERT(preFlushCount
>= 0);
50 // flushed at least once more
51 CPPUNIT_ASSERT(anEntry
->_flush_calls
> preFlushCount
);
53 CPPUNIT_ASSERT_EQUAL(1, anEntry
->_buffer_calls
);
55 CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."),
56 anEntry
->_appended_text
);