]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStore.cc
2 * Copyright (C) 1996-2023 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.
11 #include "store/SwapMeta.h"
12 #include "testStore.h"
13 #include "unitTestMain.h"
17 CPPUNIT_TEST_SUITE_REGISTRATION( testStore
);
26 TestStore::get(const cache_key
*)
32 TestStore::get(String
, void (*)(StoreEntry
*, void*), void*)
40 TestStore::maxSize() const
46 TestStore::minSize() const
52 TestStore::currentSize() const
58 TestStore::currentCount() const
64 TestStore::maxObjectSize() const
70 TestStore::getStats(StoreInfoStats
&) const
75 TestStore::stat(StoreEntry
&) const
77 const_cast<TestStore
*>(this)->statsCalled
= true;
87 testStore::testSetRoot()
89 Store::Controller
*aStore(new TestStore
);
92 CPPUNIT_ASSERT_EQUAL(&Store::Root(), aStore
);
97 testStore::testUnsetRoot()
99 Store::Controller
*aStore(new TestStore
);
100 Store::Controller
*aStore2(new TestStore
);
103 Store::Init(aStore2
);
104 CPPUNIT_ASSERT_EQUAL(&Store::Root(),aStore2
);
109 testStore::testStats()
111 TestStore
*aStore(new TestStore
);
113 CPPUNIT_ASSERT_EQUAL(false, aStore
->statsCalled
);
115 Store::Stats(&entry
);
116 CPPUNIT_ASSERT_EQUAL(true, aStore
->statsCalled
);
121 testStore::testMaxSize()
123 Store::Controller
*aStore(new TestStore
);
125 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(3), aStore
->maxSize());
131 /// check rawType that may be ignored
133 checkIgnorableSwapMetaRawType(const RawSwapMetaType rawType
)
135 if (IgnoredSwapMetaType(rawType
)) {
136 // an ignored raw type is either deprecated or reserved
137 CPPUNIT_ASSERT(DeprecatedSwapMetaType(rawType
) || ReservedSwapMetaType(rawType
));
138 CPPUNIT_ASSERT(!(DeprecatedSwapMetaType(rawType
) && ReservedSwapMetaType(rawType
)));
140 // all other raw types are neither deprecated nor reserved
141 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType
) && !ReservedSwapMetaType(rawType
));
145 /// check a raw swap meta field type below SwapMetaType range or STORE_META_VOID
147 checkTooSmallSwapMetaRawType(const RawSwapMetaType rawType
)
149 // RawSwapMetaTypeBottom and smaller values are unrelated to any named
150 // SwapMetaDataType values, including past, current, and future ones
151 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType
)); // current
152 CPPUNIT_ASSERT(!IgnoredSwapMetaType(rawType
)); // past and future
153 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType
)); // past
154 CPPUNIT_ASSERT(!ReservedSwapMetaType(rawType
)); // future
157 /// check a raw swap meta field type within SwapMetaType range, excluding STORE_META_VOID
159 checkKnownSwapMetaRawType(const RawSwapMetaType rawType
)
161 // an in-range rawType other than STORE_META_VOID is either honored or ignored
162 CPPUNIT_ASSERT(HonoredSwapMetaType(rawType
) || IgnoredSwapMetaType(rawType
));
163 CPPUNIT_ASSERT(!(HonoredSwapMetaType(rawType
) && IgnoredSwapMetaType(rawType
)));
164 checkIgnorableSwapMetaRawType(rawType
);
167 /// check a raw swap meta field type exceeding RawSwapMetaTypeTop()
169 checkTooBigSwapMetaRawType(const RawSwapMetaType rawType
)
171 // values beyond RawSwapMetaTypeTop() cannot be honored but may be ignored
172 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType
));
173 checkIgnorableSwapMetaRawType(rawType
);
176 /// check a given raw swap meta field type
178 checkSwapMetaRawType(const RawSwapMetaType rawType
)
180 if (rawType
<= RawSwapMetaTypeBottom
)
181 checkTooSmallSwapMetaRawType(rawType
);
182 else if (rawType
> RawSwapMetaTypeTop())
183 checkTooBigSwapMetaRawType(rawType
);
185 checkKnownSwapMetaRawType(rawType
);
191 testStore::testSwapMetaTypeClassification()
193 using limits
= std::numeric_limits
<Store::RawSwapMetaType
>;
194 for (auto rawType
= limits::min(); true; ++rawType
) {
196 Store::checkSwapMetaRawType(rawType
);
198 if (rawType
== limits::max())
202 // Store::RawSwapMetaTypeTop() is documented as an honored type value
203 CPPUNIT_ASSERT(Store::HonoredSwapMetaType(Store::RawSwapMetaTypeTop()));