From: Amos Jeffries Date: Fri, 18 Jul 2014 11:02:16 +0000 (-0700) Subject: Fix unit test issue after rev.1498 X-Git-Tag: SQUID_3_5_0_1~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b505ba9bf9270634f5d414b54ee472fbc3d3ff8;p=thirdparty%2Fsquid.git Fix unit test issue after rev.1498 Moves service_name global definition to tools.h where it can be accessible to more unit tests, in particular tests outside of src/Makefile.am Adds stub_SBuf.cc for use by unit tests not actually needing SBuf. --- diff --git a/src/globals.h b/src/globals.h index e90bb92efb..568c0acf86 100644 --- a/src/globals.h +++ b/src/globals.h @@ -53,7 +53,6 @@ extern const char *null_string; /* "" */ extern const char *version_string; /* VERSION */ extern const char *appname_string; /* PACKAGE */ extern char const *visible_appname_string; /* NULL */ -extern SBuf service_name; /* SBuf(APP_SHORTNAME) */ extern const char *fdTypeStr[]; extern const char *hier_strings[]; extern const char *memStatusStr[]; diff --git a/src/ip/testAddress.cc b/src/ip/testAddress.cc index eb36a73c79..49d60d1d8c 100644 --- a/src/ip/testAddress.cc +++ b/src/ip/testAddress.cc @@ -19,6 +19,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( testIpAddress ); +#include "tests/stub_SBuf.cc" + /* so that we don't break POD dependency just for the test */ struct timeval current_time; double current_dtime; diff --git a/src/ipc/Port.cc b/src/ipc/Port.cc index 409b1d97f6..4970973c2c 100644 --- a/src/ipc/Port.cc +++ b/src/ipc/Port.cc @@ -8,8 +8,8 @@ #include "comm/Connection.h" #include "comm/Read.h" #include "CommCalls.h" -#include "globals.h" #include "ipc/Port.h" +#include "tools.h" static const char channelPathPfx[] = DEFAULT_STATEDIR "/"; static const char coordinatorAddrLabel[] = "-coordinator"; diff --git a/src/tests/Stub.list b/src/tests/Stub.list index a72341207e..3a266a96e6 100644 --- a/src/tests/Stub.list +++ b/src/tests/Stub.list @@ -13,6 +13,7 @@ STUB_SOURCE= tests/STUB.h \ tests/stub_MemObject.cc \ tests/stub_MemStore.cc \ tests/stub_Port.cc \ + tests/stub_SBuf.cc \ tests/stub_SBufDetailedStats.cc \ tests/stub_StatHist.cc \ tests/stub_StoreMeta.cc \ diff --git a/src/tests/stub_SBuf.cc b/src/tests/stub_SBuf.cc new file mode 100644 index 0000000000..66e8713fd6 --- /dev/null +++ b/src/tests/stub_SBuf.cc @@ -0,0 +1,60 @@ +#include "squid.h" + +#define STUB_API "SBuf.cc" +#include "tests/STUB.h" + +#include "SBuf.h" + +InstanceIdDefinitions(SBuf, "SBuf"); + +SBufStats SBuf::stats; +const SBuf::size_type SBuf::npos; +const SBuf::size_type SBuf::maxSize; + +SBufStats::SBufStats() {} +std::ostream& SBufStats::dump(std::ostream &os) const STUB_RETVAL(os) +SBufStats& SBufStats::operator +=(const SBufStats&) STUB_RETVAL(*this) + +SBuf::SBuf() {} +SBuf::SBuf(const SBuf &S) {} +SBuf::SBuf(const char *S, size_type n) {} +SBuf::SBuf(const String &S) {} +SBuf::SBuf(const std::string &s) {} +SBuf::~SBuf() {} +SBuf& SBuf::assign(const SBuf &S) STUB_RETVAL(*this) +SBuf& SBuf::assign(const char *S, size_type n) STUB_RETVAL(*this) +void clear() STUB +SBuf& SBuf::append(const SBuf & S) STUB_RETVAL(*this) +SBuf& SBuf::append(const char * S, size_type Ssize) STUB_RETVAL(*this) +SBuf& Printf(const char *fmt, ...); +SBuf& SBuf::appendf(const char *fmt, ...) STUB_RETVAL(*this) +SBuf& SBuf::vappendf(const char *fmt, va_list vargs) STUB_RETVAL(*this) +std::ostream& SBuf::print(std::ostream &os) const STUB_RETVAL(os) +std::ostream& SBuf::dump(std::ostream &os) const STUB_RETVAL(os) +void SBuf::setAt(size_type pos, char toset) STUB +int SBuf::compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const STUB_RETVAL(-1) +int SBuf::compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const STUB_RETVAL(-1) +bool SBuf::startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const STUB_RETVAL(false) +bool SBuf::operator ==(const SBuf & S) const STUB_RETVAL(false) +bool SBuf::operator !=(const SBuf & S) const STUB_RETVAL(false) +SBuf SBuf::consume(size_type n) STUB_RETVAL(*this) +const SBufStats& SBuf::GetStats() STUB_RETVAL(SBuf::stats) +SBuf::size_type SBuf::copy(char *dest, size_type n) const STUB_RETVAL(0) +const char* SBuf::rawContent() const STUB_RETVAL(NULL) +char *SBuf::rawSpace(size_type minSize) STUB_RETVAL(NULL) +void SBuf::forceSize(size_type newSize) STUB +const char* SBuf::c_str() STUB_RETVAL("") +void SBuf::reserveCapacity(size_type minCapacity) STUB +SBuf& SBuf::chop(size_type pos, size_type n) STUB_RETVAL(*this) +SBuf& SBuf::trim(const SBuf &toRemove, bool atBeginning, bool atEnd) STUB_RETVAL(*this) +SBuf SBuf::substr(size_type pos, size_type n) const STUB_RETVAL(*this) +SBuf::size_type SBuf::find(char c, size_type startPos) const STUB_RETVAL(SBuf::npos) +SBuf::size_type SBuf::find(const SBuf & str, size_type startPos) const STUB_RETVAL(SBuf::npos) +SBuf::size_type SBuf::rfind(char c, size_type endPos) const STUB_RETVAL(SBuf::npos) +SBuf::size_type SBuf::rfind(const SBuf &str, size_type endPos) const STUB_RETVAL(SBuf::npos) +SBuf::size_type SBuf::findFirstOf(const CharacterSet &set, size_type startPos) const STUB_RETVAL(SBuf::npos) +SBuf::size_type SBuf::findFirstNotOf(const CharacterSet &set, size_type startPos) const STUB_RETVAL(SBuf::npos) +int SBuf::scanf(const char *format, ...) STUB_RETVAL(-1) +SBuf SBuf::toLower() const STUB_RETVAL(*this) +SBuf SBuf::toUpper() const STUB_RETVAL(*this) +String SBuf::toString() const STUB_RETVAL(String("")) diff --git a/src/tests/stub_tools.cc b/src/tests/stub_tools.cc index fbc20a9797..c03a511352 100644 --- a/src/tests/stub_tools.cc +++ b/src/tests/stub_tools.cc @@ -1,10 +1,12 @@ #include "squid.h" -#include "tools.h" +// XXX: need src/ to avoid clashes with ip/tools.h in testIpAddress +#include "src/tools.h" #define STUB_API "tools.cc" #include "tests/STUB.h" int DebugSignal = -1; +SBuf service_name(APP_SHORTNAME); void releaseServerSockets(void) STUB char * dead_msg(void) STUB_RETVAL(NULL) void mail_warranty(void) STUB diff --git a/src/tools.cc b/src/tools.cc index 466e284f24..324bdaab0d 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -82,6 +82,7 @@ Thanks!\n" static void mail_warranty(void); static void restoreCapabilities(int keep); int DebugSignal = -1; +SBuf service_name(APP_SHORTNAME); #if _SQUID_LINUX_ /* Workaround for crappy glic header files */ diff --git a/src/tools.h b/src/tools.h index 8ee906e2da..49a49a3a41 100644 --- a/src/tools.h +++ b/src/tools.h @@ -34,6 +34,7 @@ #define SQUID_TOOLS_H_ #include "Packer.h" +#include "SBuf.h" #include "SquidString.h" #include "typedefs.h" @@ -41,6 +42,10 @@ class MemBuf; extern int DebugSignal; +/// The Squid -n parameter service name. +/// Default is APP_SHORTNAME ('squid'). +extern SBuf service_name; + void kb_incr(kb_t *, size_t); void parseEtcHosts(void); int getMyPort(void); diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6aeb5187d4..d9d39e0822 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -52,11 +52,14 @@ check_PROGRAMS += debug \ tcp_banger2_LDADD = $(top_builddir)/lib/libmiscutil.la -DEBUG_SOURCE = test_tools.cc stub_debug.cc stub_tools.cc stub_fatal.cc +DEBUG_SOURCE = test_tools.cc stub_debug.cc stub_SBuf.cc stub_tools.cc stub_fatal.cc stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc cp $(top_srcdir)/src/tests/stub_debug.cc . +stub_SBuf.cc: $(top_srcdir)/src/tests/stub_SBuf.cc + cp $(top_srcdir)/src/tests/stub_SBuf.cc . + stub_tools.cc: $(top_srcdir)/src/tests/stub_tools.cc cp $(top_srcdir)/src/tests/stub_tools.cc .