From: Amos Jeffries Date: Mon, 3 Aug 2015 02:08:22 +0000 (-0700) Subject: Place unit tests in src/tests to make automake happy X-Git-Tag: merge-candidate-3-v1^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=37122e219139990f0911223cc25879e7af393e34;p=thirdparty%2Fsquid.git Place unit tests in src/tests to make automake happy The auto* toolchain warns that automake future versions will be enablign aubdir-objects mechanism by default. Some unit tests were moved into per-library subdirs with the plan of keeping all convenience library code together. However the current layout state of Squid means that most still require some objects in other libraries or at the top level. This does not build happily with the auto-tools subdir-objects feature. In particular the distclean target has a tendency to erase objects twice and die on the second attempt. Temporarily undo that SourceLayout shuffing in order to be more compatible with automake 1.1n versions. --- diff --git a/src/Makefile.am b/src/Makefile.am index 6ac92aff9a..48281d1579 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -903,14 +903,18 @@ TESTSOURCES= \ check_PROGRAMS+=\ tests/testBoilerplate \ tests/testCacheManager \ + tests/testCharacterSet \ tests/testDiskIO \ tests/testDns \ tests/testEvent \ tests/testEventLoop \ tests/test_http_range \ + tests/testTokenizer \ tests/testHttp1Parser \ tests/testHttpReply \ tests/testHttpRequest \ + tests/testIcmp \ + tests/testIpAddress \ tests/testStore \ tests/testString \ tests/testURL \ @@ -1219,6 +1223,24 @@ tests_testBoilerplate_LDFLAGS = $(LIBADD_DL) tests_testBoilerplate_DEPENDENCIES = \ $(SQUID_CPPUNIT_LA) +## Tests of base/libbase.la objects +tests_testCharacterSet_SOURCES = \ + tests/testCharacterSet.cc \ + tests/testCharacterSet.h +nodist_tests_testCharacterSet_SOURCES = \ + base/CharacterSet.h \ + $(TESTSOURCES) \ + tests/stub_cbdata.cc \ + tests/stub_debug.cc \ + tests/stub_MemBuf.cc +tests_testCharacterSet_LDFLAGS = $(LIBADD_DL) +tests_testCharacterSet_LDADD= \ + base/libbase.la \ + $(COMPAT_LIB) \ + $(SQUID_CPPUNIT_LA) \ + $(SQUID_CPPUNIT_LIBS) \ + $(XTRA_LIBS) + ## Tests of the CacheManager module. tests_testCacheManager_SOURCES = \ AccessLogEntry.cc \ @@ -2378,6 +2400,30 @@ tests_test_http_range_LDFLAGS = $(LIBADD_DL) tests_test_http_range_DEPENDENCIES = \ $(SQUID_CPPUNIT_LA) +## Tests of parser/* objects +tests_testTokenizer_SOURCES = \ + tests/testTokenizer.h \ + tests/testTokenizer.cc +nodist_tests_testTokenizer_SOURCES = \ + parser/Tokenizer.h \ + $(SBUF_SOURCE) \ + SquidString.h \ + String.cc \ + $(TESTSOURCES) \ + tests/stub_debug.cc \ + tests/stub_libmem.cc \ + tests/stub_time.cc \ + tests/stub_SBufDetailedStats.cc +tests_testTokenizer_LDFLAGS = $(LIBADD_DL) +tests_testTokenizer_LDADD = \ + parser/libsquid-parser.la \ + base/libbase.la \ + $(top_builddir)/lib/libmiscutil.la \ + $(COMPAT_LIB) \ + $(SQUID_CPPUNIT_LA) \ + $(SQUID_CPPUNIT_LIBS) \ + $(XTRA_LIBS) + tests_testHttp1Parser_SOURCES = \ Debug.h \ MemBuf.cc \ @@ -2667,6 +2713,44 @@ tests_testHttpRequest_DEPENDENCIES = \ $(REPL_OBJS) \ $(SQUID_CPPUNIT_LA) +## Tests for icmp/* objects +# icmp/libicmp-core.la is used by pinger so SHOULD NOT require more dependancies! :-( +tests_testIcmp_SOURCES = \ + tests/testIcmp.h \ + tests/testIcmp.cc +nodist_tests_testIcmp_SOURCES = \ + icmp/Icmp.h \ + SquidTime.h \ + tests/stub_debug.cc \ + time.cc \ + globals.cc +tests_testIcmp_LDFLAGS = $(LIBADD_DL) +tests_testIcmp_LDADD=\ + icmp/libicmp-core.la \ + ip/libip.la \ + base/libbase.la \ + $(COMPAT_LIB) \ + $(SQUID_CPPUNIT_LA) \ + $(SQUID_CPPUNIT_LIBS) \ + $(XTRA_LIBS) + +## Tests for ip/* objects +tests_testIpAddress_SOURCES= \ + tests/testAddress.cc \ + tests/testAddress.h +nodist_tests_testIpAddress_SOURCES= \ + ip/Address.h \ + tests/stub_debug.cc \ + tests/stub_tools.cc +tests_testIpAddress_LDADD= \ + ip/libip.la \ + base/libbase.la \ + $(COMPAT_LIB) \ + $(SQUID_CPPUNIT_LA) \ + $(SQUID_CPPUNIT_LIBS) \ + $(XTRA_LIBS) +tests_testIpAddress_LDFLAGS= $(LIBADD_DL) + ## why so many sources? well httpHeaderTools requites ACLChecklist & friends. ## first line - what we are testing. tests_testStore_SOURCES= \ diff --git a/src/base/Makefile.am b/src/base/Makefile.am index dc6811c0ca..cd03165a17 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -36,26 +36,3 @@ libbase_la_SOURCES = \ TextException.cc \ TextException.h \ TidyPointer.h - -EXTRA_PROGRAMS = \ - testCharacterSet - -check_PROGRAMS += testCharacterSet -TESTS += testCharacterSet - -testCharacterSet_SOURCES = \ - CharacterSet.h \ - testCharacterSet.h \ - testCharacterSet.cc -nodist_testCharacterSet_SOURCES = \ - $(top_srcdir)/src/tests/stub_debug.cc \ - $(top_srcdir)/src/tests/stub_MemBuf.cc \ - $(top_srcdir)/src/tests/stub_cbdata.cc -testCharacterSet_LDFLAGS = $(LIBADD_DL) -testCharacterSet_LDADD=\ - $(SQUID_CPPUNIT_LIBS) \ - $(SQUID_CPPUNIT_LA) \ - libbase.la \ - $(COMPAT_LIB) \ - $(XTRA_LIBS) -testCharacterSet_DEPENDENCIES= $(SQUID_CPPUNIT_LA) diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index 06fdd493d0..a83038e670 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -9,40 +9,20 @@ include $(top_srcdir)/src/Common.am include $(top_srcdir)/src/TestHeaders.am # TODO: get rid of this when config filename is no longer a global constant. -# its only here so the testIcmp will link . +# its only here so the pinger globals.cc will link. DEFS += -DDEFAULT_CONFIG_FILE=NULL # ICMP Specific Configurations if ENABLE_PINGER -PINGER = pinger +libexec_PROGRAMS = pinger else -PINGER = +EXTRA_PROGRAMS = pinger endif -EXTRA_PROGRAMS = \ - pinger \ - testIcmp - -libexec_PROGRAMS = $(PINGER) - noinst_LTLIBRARIES = libicmp-core.la libicmp.la -SBUF_SOURCE= \ - $(top_srcdir)/src/base/CharacterSet.h \ - $(top_srcdir)/src/SBuf.h \ - $(top_srcdir)/src/SBuf.cc \ - $(top_srcdir)/src/MemBlob.h \ - $(top_srcdir)/src/MemBlob.cc \ - $(top_srcdir)/src/OutOfBoundsException.h \ - $(top_srcdir)/src/SBufExceptions.h \ - $(top_srcdir)/src/SBufExceptions.cc \ - $(top_srcdir)/src/String.cc \ - $(top_srcdir)/src/SquidString.h \ - $(top_srcdir)/src/base/TextException.h \ - $(top_srcdir)/src/base/TextException.cc - # ICMP API definition ... libicmp_core_la_SOURCES = \ Icmp.h \ @@ -71,12 +51,12 @@ pinger_SOURCES = \ # depends on these but install/dist is done elsewhere. # TODO: remove when these are cleaned up in their own way. nodist_pinger_SOURCES = \ - $(top_srcdir)/src/debug.cc \ - $(top_builddir)/src/globals.cc \ - $(top_srcdir)/src/time.cc \ - $(top_srcdir)/src/SquidConfig.cc \ - $(top_srcdir)/src/SquidNew.cc \ - $(top_srcdir)/src/tests/stub_HelperChildConfig.cc + debug.cc \ + globals.cc \ + SquidConfig.cc \ + SquidNew.cc \ + stub_HelperChildConfig.cc \ + time.cc pinger_LDFLAGS = $(LIBADD_DL) pinger_LDADD=\ @@ -86,7 +66,6 @@ pinger_LDADD=\ $(COMPAT_LIB) \ $(XTRA_LIBS) - ##install-pinger: ## @f=$(PINGER_EXE); \ ## if test -f $(libexecdir)/$$f; then \ @@ -100,29 +79,22 @@ pinger_LDADD=\ ## $(RM) -f $(libexecdir)/-$$f; \ ## fi +## files we need to pull in from other locations +## copied like this to avoid subdir-objects collisions on 'make clean' +debug.cc: $(top_srcdir)/src/debug.cc + cp $(top_srcdir)/src/debug.cc . -check_PROGRAMS += testIcmp -TESTS += testIcmp +globals.cc: $(top_srcdir)/src/globals.h + cp $(top_builddir)/src/globals.cc . -## Tests of the ICMP base module. -# Its used by pinger so SHOULD NOT require more dependancies! :-( -testIcmp_SOURCES = \ - Icmp.h \ - testIcmp.h \ - testIcmp.cc -nodist_testIcmp_SOURCES = \ - $(top_srcdir)/src/SquidTime.h \ - $(top_srcdir)/src/tests/stub_debug.cc \ - $(top_srcdir)/src/time.cc \ - $(top_srcdir)/test-suite/test_tools.cc \ - $(top_builddir)/src/globals.cc -testIcmp_LDFLAGS = $(LIBADD_DL) -testIcmp_LDADD=\ - $(SQUID_CPPUNIT_LIBS) \ - $(SQUID_CPPUNIT_LA) \ - libicmp-core.la \ - ../ip/libip.la \ - ../base/libbase.la \ - $(COMPAT_LIB) \ - $(XTRA_LIBS) -testIcmp_DEPENDENCIES= $(SQUID_CPPUNIT_LA) +time.cc: $(top_srcdir)/src/time.cc + cp $(top_srcdir)/src/time.cc . + +SquidConfig.cc: $(top_srcdir)/src/SquidConfig.cc + cp $(top_srcdir)/src/SquidConfig.cc . + +SquidNew.cc: $(top_srcdir)/src/SquidNew.cc + cp $(top_srcdir)/src/SquidNew.cc . + +stub_HelperChildConfig.cc: $(top_srcdir)/src/tests/stub_HelperChildConfig.cc + cp $(top_srcdir)/src/tests/stub_HelperChildConfig.cc . diff --git a/src/ip/Makefile.am b/src/ip/Makefile.am index 4321f48055..b741b12b6b 100644 --- a/src/ip/Makefile.am +++ b/src/ip/Makefile.am @@ -21,22 +21,3 @@ libip_la_SOURCES = \ Qos.cci \ tools.cc \ tools.h - - -check_PROGRAMS += testIpAddress -TESTS += testIpAddress - -testIpAddress_SOURCES= \ - testAddress.cc \ - testAddress.h -nodist_testIpAddress_SOURCES= \ - $(top_srcdir)/src/tests/stub_debug.cc \ - $(top_srcdir)/src/tests/stub_tools.cc -testIpAddress_LDADD= \ - libip.la \ - ../base/libbase.la \ - $(XTRA_LIBS) \ - $(COMPAT_LIB) \ - $(SQUID_CPPUNIT_LA) \ - $(SQUID_CPPUNIT_LIBS) -testIpAddress_LDFLAGS= $(LIBADD_DL) diff --git a/src/parser/Makefile.am b/src/parser/Makefile.am index 9b1aca5bf8..a77ca1912a 100644 --- a/src/parser/Makefile.am +++ b/src/parser/Makefile.am @@ -8,12 +8,6 @@ include $(top_srcdir)/src/Common.am include $(top_srcdir)/src/TestHeaders.am -EXTRA_PROGRAMS = \ - testTokenizer - -check_PROGRAMS += testTokenizer -TESTS += testTokenizer - noinst_LTLIBRARIES = libsquid-parser.la libsquid_parser_la_SOURCES = \ @@ -34,22 +28,3 @@ SBUF_SOURCE= \ $(top_srcdir)/src/base/TextException.h \ $(top_srcdir)/src/base/TextException.cc -testTokenizer_SOURCES = \ - $(SBUF_SOURCE) \ - testTokenizer.h \ - testTokenizer.cc \ - Tokenizer.h -nodist_testTokenizer_SOURCES = \ - $(top_srcdir)/src/tests/stub_libmem.cc \ - $(top_srcdir)/src/tests/stub_debug.cc \ - $(top_srcdir)/src/tests/stub_time.cc \ - $(top_srcdir)/src/tests/stub_SBufDetailedStats.cc -testTokenizer_LDFLAGS = $(LIBADD_DL) -testTokenizer_LDADD = \ - libsquid-parser.la \ - $(top_builddir)/lib/libmiscutil.la \ - $(top_builddir)/src/base/libbase.la \ - $(SQUID_CPPUNIT_LIBS) \ - $(SQUID_CPPUNIT_LA) \ - $(COMPAT_LIB) -testTokenizer_DEPENDENCIES = $(SQUID_CPPUNIT_LA) diff --git a/src/ip/testAddress.cc b/src/tests/testAddress.cc similarity index 100% rename from src/ip/testAddress.cc rename to src/tests/testAddress.cc diff --git a/src/ip/testAddress.h b/src/tests/testAddress.h similarity index 100% rename from src/ip/testAddress.h rename to src/tests/testAddress.h diff --git a/src/base/testCharacterSet.cc b/src/tests/testCharacterSet.cc similarity index 100% rename from src/base/testCharacterSet.cc rename to src/tests/testCharacterSet.cc diff --git a/src/base/testCharacterSet.h b/src/tests/testCharacterSet.h similarity index 100% rename from src/base/testCharacterSet.h rename to src/tests/testCharacterSet.h diff --git a/src/icmp/testIcmp.cc b/src/tests/testIcmp.cc similarity index 98% rename from src/icmp/testIcmp.cc rename to src/tests/testIcmp.cc index 7f4ed627c2..43eac7612e 100644 --- a/src/icmp/testIcmp.cc +++ b/src/tests/testIcmp.cc @@ -9,19 +9,17 @@ #define SQUID_HELPER 1 #include "squid.h" +#include "tests/testIcmp.h" +#include "unitTestMain.h" #include -#include "testIcmp.h" -#include "unitTestMain.h" - CPPUNIT_TEST_SUITE_REGISTRATION( testIcmp ); -#if USE_ICMP - void testIcmp::testChecksum() { +#if USE_ICMP stubIcmp icmp; uint16_t buf[10], tmpval; for (tmpval=0; tmpval < 10; ++tmpval) @@ -70,11 +68,13 @@ testIcmp::testChecksum() CPPUNIT_ASSERT_EQUAL((int)htons(0xffc8), icmp.testChecksum(buf,20)); // 1+2...+10 // data with invalid length (overrun) ==> Garbage checksum... +#endif } void testIcmp::testHops() { +#if USE_ICMP stubIcmp icmp; /* test invalid -(under values) */ @@ -113,7 +113,6 @@ testIcmp::testHops() CPPUNIT_ASSERT_EQUAL(0, icmp.testHops(256)); // 257 - produces negative hops CPPUNIT_ASSERT_EQUAL(-1, icmp.testHops(257)); +#endif } -#endif /* USE_ICMP */ - diff --git a/src/icmp/testIcmp.h b/src/tests/testIcmp.h similarity index 87% rename from src/icmp/testIcmp.h rename to src/tests/testIcmp.h index 3904a23b7b..f935a27179 100644 --- a/src/icmp/testIcmp.h +++ b/src/tests/testIcmp.h @@ -6,14 +6,15 @@ * Please see the COPYING and CONTRIBUTORS files for details. */ -#ifndef SQUID_SRC_TEST_URL_H -#define SQUID_SRC_TEST_URL_H +#ifndef SQUID_SRC_TESTS_TESTICMP_H +#define SQUID_SRC_TESTS_TESTICMP_H -#include "Icmp.h" #include #if USE_ICMP +#include "icmp/Icmp.h" + class stubIcmp : public Icmp { public: @@ -32,8 +33,7 @@ public: int testChecksum(unsigned short *ptr, int size) { return CheckSum(ptr,size); }; int testHops(int ttl) { return ipHops(ttl); }; }; - -#endif /* USE_ICMP */ +#endif /** * test the ICMP base class. @@ -41,18 +41,14 @@ public: class testIcmp : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE( testIcmp ); -#if USE_ICMP CPPUNIT_TEST( testChecksum ); CPPUNIT_TEST( testHops ); -#endif /* USE_ICMP */ CPPUNIT_TEST_SUITE_END(); protected: -#if USE_ICMP void testChecksum(); void testHops(); -#endif /* USE_ICMP */ }; -#endif +#endif /* SQUID_SRC_TESTS_TESTICMP_H */ diff --git a/src/parser/testTokenizer.cc b/src/tests/testTokenizer.cc similarity index 99% rename from src/parser/testTokenizer.cc rename to src/tests/testTokenizer.cc index d0a96bf77e..682f0d01f8 100644 --- a/src/parser/testTokenizer.cc +++ b/src/tests/testTokenizer.cc @@ -9,7 +9,7 @@ #include "squid.h" #include "base/CharacterSet.h" #include "parser/Tokenizer.h" -#include "testTokenizer.h" +#include "tests/testTokenizer.h" #include "unitTestMain.h" CPPUNIT_TEST_SUITE_REGISTRATION( testTokenizer ); diff --git a/src/parser/testTokenizer.h b/src/tests/testTokenizer.h similarity index 100% rename from src/parser/testTokenizer.h rename to src/tests/testTokenizer.h