]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 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" |
a553a5a3 | 10 | #include "CapturingStoreEntry.h" |
c21ad0f5 | 11 | #include "Store.h" |
12 | #include "StoreEntryStream.h" | |
602d9612 A |
13 | #include "testStore.h" |
14 | #include "testStoreEntryStream.h" | |
c21ad0f5 | 15 | |
16 | #include <iomanip> | |
c21ad0f5 | 17 | #include <cppunit/TestAssert.h> |
18 | ||
19 | CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream ); | |
20 | ||
c21ad0f5 | 21 | /* init memory pools */ |
22 | ||
16555581 | 23 | void testStoreEntryStream::setUp() |
c21ad0f5 | 24 | { |
16555581 | 25 | Mem::Init(); |
26 | } | |
c21ad0f5 | 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 | { | |
cb868059 | 37 | StoreEntryStream stream(anEntry); // locks and unlocks/deletes anEntry |
c21ad0f5 | 38 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); |
39 | CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls); | |
b4f08306 | 40 | |
41 | stream.setf(std::ios::fixed); | |
42 | stream << 123456 << std::setprecision(1) << 77.7; | |
43 | stream << " some text" << std::setw(4) << "!" << '.'; | |
c21ad0f5 | 44 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); |
b4f08306 | 45 | |
46 | const int preFlushCount = anEntry->_flush_calls; | |
47 | // may have already flushed | |
26ac0430 | 48 | CPPUNIT_ASSERT(preFlushCount >= 0); |
c21ad0f5 | 49 | stream.flush(); |
b4f08306 | 50 | // flushed at least once more |
51 | CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount); | |
52 | ||
c21ad0f5 | 53 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); |
b4f08306 | 54 | |
26ac0430 AJ |
55 | CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."), |
56 | anEntry->_appended_text); | |
c21ad0f5 | 57 | } |
c21ad0f5 | 58 | Store::Root(NULL); |
59 | } | |
f53969cc | 60 |