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
14class TestLookupTable : public CPPUNIT_NS::TestFixture
15{
19
20public:
22};
24
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
47void
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
69int
70main(int argc, char *argv[])
71{
72 return TestProgram().run(argc, argv);
73}
74
EnumType lookup(const SBuf &key) const
Definition: LookupTable.h:65
Definition: SBuf.h:94
void testLookupTableLookup()
CPPUNIT_TEST_SUITE(TestLookupTable)
CPPUNIT_TEST(testLookupTableLookup)
implements test program's main() function while enabling customization
Definition: unitTestMain.h:26
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
int main(int argc, char *argv[])
CPPUNIT_TEST_SUITE_REGISTRATION(TestLookupTable)
EnumData
@ ENUM_2
@ ENUM_7
@ ENUM_3
@ ENUM_5
@ ENUM_6
@ ENUM_INVALID
@ ENUM_1
@ ENUM_4
static const LookupTable< EnumData >::Record tableData[]

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors