testStore.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 
19 namespace Store {
20 
22 static 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 
36 static 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 
48 static 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 
58 static void
60 {
61  // values beyond RawSwapMetaTypeTop() cannot be honored but may be ignored
62  CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType));
64 }
65 
67 static void
69 {
70  if (rawType <= RawSwapMetaTypeBottom)
72  else if (rawType > RawSwapMetaTypeTop())
74  else
76 }
77 
78 } // namespace Store
79 
80 void
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 
97 class MyTestProgram: public TestProgram
98 {
99 public:
100  /* TestProgram API */
101  void startup() override { Mem::Init(); }
102 };
103 
104 int
105 main(int argc, char *argv[])
106 {
107  return MyTestProgram().run(argc, argv);
108 }
109 
constexpr RawSwapMetaType RawSwapMetaTypeTop()
Definition: SwapMeta.h:131
CPPUNIT_TEST_SUITE_REGISTRATION(TestStore)
static void checkKnownSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type within SwapMetaType range, excluding STORE_META_VOID
Definition: testStore.cc:49
static void checkSwapMetaRawType(const RawSwapMetaType rawType)
check a given raw swap meta field type
Definition: testStore.cc:68
implements test program's main() function while enabling customization
Definition: unitTestMain.h:25
constexpr bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:219
const A & max(A const &lhs, A const &rhs)
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
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
char RawSwapMetaType
Definition: SwapMeta.h:95
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
void Init()
Definition: old_api.cc:281
void testSwapMetaTypeClassification()
Definition: testStore.cc:81
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
static void checkTooBigSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type exceeding RawSwapMetaTypeTop()
Definition: testStore.cc:59
customizes our test setup
const A & min(A const &lhs, A const &rhs)
int main(int argc, char *argv[])
Definition: testStore.cc:105
constexpr bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:197
void startup() override
Definition: testStore.cc:101

 

Introduction

Documentation

Support

Miscellaneous