Squid Web Cache master
Loading...
Searching...
No Matches
testStore.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 "store/SwapMeta.h"
12#include "testStore.h"
13#include "unitTestMain.h"
14
15#include <limits>
16
18
19namespace Store {
20
22static void
24{
25 if (IgnoredSwapMetaType(rawType)) {
26 // an ignored raw type is either deprecated or reserved
27 CPPUNIT_ASSERT(DeprecatedSwapMetaType(rawType) || ReservedSwapMetaType(rawType));
28 CPPUNIT_ASSERT(!(DeprecatedSwapMetaType(rawType) && ReservedSwapMetaType(rawType)));
29 } else {
30 // all other raw types are neither deprecated nor reserved
31 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType) && !ReservedSwapMetaType(rawType));
32 }
33}
34
36static void
38{
39 // RawSwapMetaTypeBottom and smaller values are unrelated to any named
40 // SwapMetaDataType values, including past, current, and future ones
41 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType)); // current
42 CPPUNIT_ASSERT(!IgnoredSwapMetaType(rawType)); // past and future
43 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType)); // past
44 CPPUNIT_ASSERT(!ReservedSwapMetaType(rawType)); // future
45}
46
48static void
50{
51 // an in-range rawType other than STORE_META_VOID is either honored or ignored
52 CPPUNIT_ASSERT(HonoredSwapMetaType(rawType) || IgnoredSwapMetaType(rawType));
53 CPPUNIT_ASSERT(!(HonoredSwapMetaType(rawType) && IgnoredSwapMetaType(rawType)));
55}
56
58static void
60{
61 // values beyond RawSwapMetaTypeTop() cannot be honored but may be ignored
62 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType));
64}
65
67static void
69{
70 if (rawType <= RawSwapMetaTypeBottom)
72 else if (rawType > RawSwapMetaTypeTop())
74 else
76}
77
78} // namespace Store
79
80void
82{
83 using limits = std::numeric_limits<Store::RawSwapMetaType>;
84 for (auto rawType = limits::min(); true; ++rawType) {
85
87
88 if (rawType == limits::max())
89 break;
90 }
91
92 // Store::RawSwapMetaTypeTop() is documented as an honored type value
94}
95
97class MyTestProgram: public TestProgram
98{
99public:
100 /* TestProgram API */
101 void startup() override { Mem::Init(); }
102};
103
104int
105main(int argc, char *argv[])
106{
107 return MyTestProgram().run(argc, argv);
108}
109
customizes our test setup
void startup() override
Definition testStore.cc:101
implements test program's main() function while enabling customization
int run(int argc, char *argv[])
void testSwapMetaTypeClassification()
Definition testStore.cc:81
int main()
void Init()
Definition old_api.cc:281
const RawSwapMetaType RawSwapMetaTypeBottom
Definition SwapMeta.h:126
static void checkKnownSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type within SwapMetaType range, excluding STORE_META_VOID
Definition testStore.cc:49
char RawSwapMetaType
Definition SwapMeta.h:95
constexpr RawSwapMetaType RawSwapMetaTypeTop()
Definition SwapMeta.h:131
constexpr bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition SwapMeta.h:219
static void checkSwapMetaRawType(const RawSwapMetaType rawType)
check a given raw swap meta field type
Definition testStore.cc:68
constexpr bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition SwapMeta.h:197
constexpr bool ReservedSwapMetaType(const RawSwapMetaType type)
Definition SwapMeta.h:180
static void checkIgnorableSwapMetaRawType(const RawSwapMetaType rawType)
check rawType that may be ignored
Definition testStore.cc:23
static void checkTooSmallSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type below SwapMetaType range or STORE_META_VOID
Definition testStore.cc:37
constexpr bool DeprecatedSwapMetaType(const RawSwapMetaType type)
Definition SwapMeta.h:158
static void checkTooBigSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type exceeding RawSwapMetaTypeTop()
Definition testStore.cc:59
CPPUNIT_TEST_SUITE_REGISTRATION(TestStore)