tests/testSBuf \
tests/testSBufList \
tests/testConfigParser \
- tests/testStatHist
+ tests/testStatHist \
+ tests/testLookupTable
if HAVE_FS_ROCK
check_PROGRAMS += tests/testRock
$(COMPAT_LIB)
tests_testStatHist_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
+tests_testLookupTable_SOURCES = \
+ tests/testLookupTable.h \
+ tests/testLookupTable.cc \
+ tests/stub_debug.cc \
+ tests/stub_libmem.cc \
+ tests/stub_SBufDetailedStats.cc \
+ base/LookupTable.h \
+ String.cc \
+ $(SBUF_SOURCE)
+nodist_tests_testLookupTable_SOURCES = $(TESTSOURCES)
+tests_testLookupTable_LDFLAGS = $(LIBADD_DL)
+tests_testLookupTable_LDADD = \
+ base/libbase.la \
+ $(SQUID_CPPUNIT_LIBS) \
+ $(COMPAT_LIB) \
+ $(XTRA_LIBS)
+tests_testLookupTable_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
+
TESTS += testHeaders
## Special Universal .h dependency test script
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
#ifndef SQUID_LOOKUPTABLE_H_
#define SQUID_LOOKUPTABLE_H_
--- /dev/null
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "base/LookupTable.h"
+#include "testLookupTable.h"
+#include "unitTestMain.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( testLookupTable );
+
+enum EnumData {
+ ENUM_1,
+ ENUM_2,
+ ENUM_3,
+ ENUM_4,
+ ENUM_5,
+ ENUM_6,
+ ENUM_7,
+ ENUM_INVALID
+};
+
+static const LookupTable<EnumData>::Record tableData[] = {
+ {"one", ENUM_1},
+ {"two", ENUM_2},
+ {"three", ENUM_3},
+ {"four", ENUM_4},
+ {"five", ENUM_5},
+ {"six", ENUM_6},
+ {"seven", ENUM_7},
+ {nullptr, ENUM_INVALID}
+};
+
+void
+testLookupTable::testLookupTableLookup()
+{
+ LookupTable<EnumData> lt(ENUM_INVALID, tableData);
+ // element found
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("one")), ENUM_1);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("two")), ENUM_2);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("three")), ENUM_3);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("four")), ENUM_4);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("five")), ENUM_5);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("six")), ENUM_6);
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("seven")), ENUM_7);
+
+ // element not found
+ CPPUNIT_ASSERT_EQUAL(lt.lookup(SBuf("eleventy")), ENUM_INVALID);
+}
--- /dev/null
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_TESTLOOKUPTABLE_H_
+#define SQUID_TESTLOOKUPTABLE_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class testLookupTable : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE( testLookupTable );
+ CPPUNIT_TEST( testLookupTableLookup );
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testLookupTableLookup();
+};
+
+#endif /* SQUID_TESTLOOKUPTABLE_H_ */