]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implement LookupTable unit tests, documentation, copyright blurb
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 27 Jul 2015 16:25:09 +0000 (18:25 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 27 Jul 2015 16:25:09 +0000 (18:25 +0200)
src/Makefile.am
src/base/LookupTable.h
src/tests/testLookupTable.cc [new file with mode: 0644]
src/tests/testLookupTable.h [new file with mode: 0644]

index c1c9668cdadd418f728ed2632b88a91de6093400..6ba5d5e57b4dd99c923eb07d3a7676e98ab07704 100644 (file)
@@ -917,7 +917,8 @@ check_PROGRAMS+=\
        tests/testSBuf \
        tests/testSBufList \
        tests/testConfigParser \
-       tests/testStatHist
+       tests/testStatHist \
+       tests/testLookupTable
 
 if HAVE_FS_ROCK
 check_PROGRAMS += tests/testRock
@@ -3655,6 +3656,24 @@ tests_testStatHist_LDADD = \
        $(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
index 8c5c608ca24709c79325417b87873db6b6777dc7..e50130ee6fad6b76befcf930cdc7ba6172357171 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * 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_
 
diff --git a/src/tests/testLookupTable.cc b/src/tests/testLookupTable.cc
new file mode 100644 (file)
index 0000000..268f839
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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);
+}
diff --git a/src/tests/testLookupTable.h b/src/tests/testLookupTable.h
new file mode 100644 (file)
index 0000000..545db6e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_ */