testLookupTable.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "testLookupTable.h"
12 #include "unitTestMain.h"
13 
15 
16 enum EnumData {
25 };
26 
27 static const LookupTable<EnumData>::Record tableData[] = {
28  {"one", ENUM_1},
29  {"two", ENUM_2},
30  {"three", ENUM_3},
31  {"four", ENUM_4},
32  {"five", ENUM_5},
33  {"six", ENUM_6},
34  {"seven", ENUM_7},
35  {nullptr, ENUM_INVALID}
36 };
37 
38 void
40 {
41  LookupTable<EnumData> lt(ENUM_INVALID, tableData);
42  // element found
43  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("one")), ENUM_1);
44  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("two")), ENUM_2);
45  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("three")), ENUM_3);
46  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("four")), ENUM_4);
47  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("five")), ENUM_5);
48  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("six")), ENUM_6);
49  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("seven")), ENUM_7);
50 
51  // element not found
52  CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("eleventy")), ENUM_INVALID);
53 }
54 
CPPUNIT_TEST_SUITE_REGISTRATION(testLookupTable)
Definition: SBuf.h:87
EnumType lookup(const SBuf &key) const
Definition: LookupTable.h:72
void testLookupTableLookup()
EnumData

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors