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