]>
Commit | Line | Data |
---|---|---|
ec94e362 AJ |
1 | #define SQUID_UNIT_TEST 1 |
2 | ||
f7f3304a | 3 | #include "squid-old.h" |
c21ad0f5 | 4 | #include "Mem.h" |
5 | #include "testStore.h" | |
6 | #include "testStoreEntryStream.h" | |
a553a5a3 | 7 | #include "CapturingStoreEntry.h" |
c21ad0f5 | 8 | #include "Store.h" |
9 | #include "StoreEntryStream.h" | |
10 | ||
27e059d4 | 11 | #if HAVE_IOMANIP |
c21ad0f5 | 12 | #include <iomanip> |
27e059d4 | 13 | #endif |
c21ad0f5 | 14 | |
15 | #include <cppunit/TestAssert.h> | |
16 | ||
17 | CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream ); | |
18 | ||
c21ad0f5 | 19 | /* init memory pools */ |
20 | ||
16555581 | 21 | void testStoreEntryStream::setUp() |
c21ad0f5 | 22 | { |
16555581 | 23 | Mem::Init(); |
24 | } | |
c21ad0f5 | 25 | |
26 | void | |
27 | testStoreEntryStream::testGetStream() | |
28 | { | |
29 | /* Setup a store root so we can create a StoreEntry */ | |
30 | StorePointer aStore (new TestStore); | |
31 | Store::Root(aStore); | |
32 | ||
33 | CapturingStoreEntry * anEntry = new CapturingStoreEntry(); | |
34 | { | |
35 | StoreEntryStream stream(anEntry); | |
36 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); | |
37 | CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls); | |
b4f08306 | 38 | |
39 | stream.setf(std::ios::fixed); | |
40 | stream << 123456 << std::setprecision(1) << 77.7; | |
41 | stream << " some text" << std::setw(4) << "!" << '.'; | |
c21ad0f5 | 42 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); |
b4f08306 | 43 | |
44 | const int preFlushCount = anEntry->_flush_calls; | |
45 | // may have already flushed | |
26ac0430 | 46 | CPPUNIT_ASSERT(preFlushCount >= 0); |
c21ad0f5 | 47 | stream.flush(); |
b4f08306 | 48 | // flushed at least once more |
49 | CPPUNIT_ASSERT(anEntry->_flush_calls > preFlushCount); | |
50 | ||
c21ad0f5 | 51 | CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); |
b4f08306 | 52 | |
26ac0430 AJ |
53 | CPPUNIT_ASSERT_EQUAL(String("12345677.7 some text !."), |
54 | anEntry->_appended_text); | |
c21ad0f5 | 55 | } |
56 | ||
57 | delete anEntry; | |
58 | ||
59 | Store::Root(NULL); | |
60 | } |