]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStore.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testStore.cc
1 /*
2 * Copyright (C) 1996-2017 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 "Store.h"
11 #include "testStore.h"
12 #include "unitTestMain.h"
13
14 CPPUNIT_TEST_SUITE_REGISTRATION( testStore );
15
16 int
17 TestStore::callback()
18 {
19 return 1;
20 }
21
22 StoreEntry*
23 TestStore::get(const cache_key*)
24 {
25 return NULL;
26 }
27
28 void
29 TestStore::get(String, void (*)(StoreEntry*, void*), void*)
30 {}
31
32 void
33 TestStore::init()
34 {}
35
36 uint64_t
37 TestStore::maxSize() const
38 {
39 return 3;
40 }
41
42 uint64_t
43 TestStore::minSize() const
44 {
45 return 1;
46 }
47
48 uint64_t
49 TestStore::currentSize() const
50 {
51 return 2;
52 }
53
54 uint64_t
55 TestStore::currentCount() const
56 {
57 return 2;
58 }
59
60 int64_t
61 TestStore::maxObjectSize() const
62 {
63 return 1;
64 }
65
66 void
67 TestStore::getStats(StoreInfoStats &) const
68 {
69 }
70
71 void
72 TestStore::stat(StoreEntry &) const
73 {
74 const_cast<TestStore *>(this)->statsCalled = true;
75 }
76
77 StoreSearch *
78 TestStore::search()
79 {
80 return NULL;
81 }
82
83 void
84 testStore::testSetRoot()
85 {
86 Store::Controller *aStore(new TestStore);
87 Store::Init(aStore);
88
89 CPPUNIT_ASSERT_EQUAL(&Store::Root(), aStore);
90 Store::FreeMemory();
91 }
92
93 void
94 testStore::testUnsetRoot()
95 {
96 Store::Controller *aStore(new TestStore);
97 Store::Controller *aStore2(new TestStore);
98 Store::Init(aStore);
99 Store::FreeMemory();
100 Store::Init(aStore2);
101 CPPUNIT_ASSERT_EQUAL(&Store::Root(),aStore2);
102 Store::FreeMemory();
103 }
104
105 void
106 testStore::testStats()
107 {
108 TestStore *aStore(new TestStore);
109 Store::Init(aStore);
110 CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
111 Store::Stats(NullStoreEntry::getInstance());
112 CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
113 Store::FreeMemory();
114 }
115
116 void
117 testStore::testMaxSize()
118 {
119 Store::Controller *aStore(new TestStore);
120 Store::Init(aStore);
121 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(3), aStore->maxSize());
122 Store::FreeMemory();
123 }
124