testLookupTable.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 "base/LookupTable.h"
11 #include "compat/cppunit.h"
12 #include "unitTestMain.h"
13 
14 class TestLookupTable : public CPPUNIT_NS::TestFixture
15 {
19 
20 public:
21  void testLookupTableLookup();
22 };
24 
25 enum EnumData {
34 };
35 
37  {"one", ENUM_1},
38  {"two", ENUM_2},
39  {"three", ENUM_3},
40  {"four", ENUM_4},
41  {"five", ENUM_5},
42  {"six", ENUM_6},
43  {"seven", ENUM_7},
44  {nullptr, ENUM_INVALID}
45 };
46 
47 void
49 {
51  // element found
52  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("one")), ENUM_1);
53  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("two")), ENUM_2);
54  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("three")), ENUM_3);
55  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("four")), ENUM_4);
56  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("five")), ENUM_5);
57  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("six")), ENUM_6);
58  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("seven")), ENUM_7);
59 
60  // element found despite a different key spelling
61  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("One")), ENUM_1);
62  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("fOUr")), ENUM_4);
63  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("seveN")), ENUM_7);
64 
65  // element not found
66  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("eleventy")), ENUM_INVALID);
67 }
68 
69 int
70 main(int argc, char *argv[])
71 {
72  return TestProgram().run(argc, argv);
73 }
74 
@ ENUM_3
@ ENUM_2
@ ENUM_5
@ ENUM_7
implements test program's main() function while enabling customization
Definition: unitTestMain.h:25
Definition: SBuf.h:93
@ ENUM_6
CPPUNIT_TEST_SUITE_REGISTRATION(TestLookupTable)
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
EnumType lookup(const SBuf &key) const
Definition: LookupTable.h:65
@ ENUM_1
CPPUNIT_TEST(testLookupTableLookup)
EnumData
CPPUNIT_TEST_SUITE(TestLookupTable)
@ ENUM_INVALID
void testLookupTableLookup()
int main(int argc, char *argv[])
@ ENUM_4
static const LookupTable< EnumData >::Record tableData[]

 

Introduction

Documentation

Support

Miscellaneous