From 7a71e758b1967305c9c1aa4b9c05407ef8f26ccf Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 20 Sep 2017 14:25:23 -0500 Subject: [PATCH] pvUnitTest.h multi-line prints --- src/misc/Makefile | 1 + src/misc/pv/pvUnitTest.h | 60 ++++++++++++++++++++++++++++------------ src/misc/pvUnitTest.cpp | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 src/misc/pvUnitTest.cpp diff --git a/src/misc/Makefile b/src/misc/Makefile index 06d0dd5..0f717d8 100644 --- a/src/misc/Makefile +++ b/src/misc/Makefile @@ -38,5 +38,6 @@ LIBSRCS += status.cpp LIBSRCS += localStaticLock.cpp LIBSRCS += typeCast.cpp LIBSRCS += parseToPOD.cpp +LIBSRCS += pvUnitTest.cpp LIBSRCS += debugPtr.cpp LIBSRCS += reftrack.cpp diff --git a/src/misc/pv/pvUnitTest.h b/src/misc/pv/pvUnitTest.h index 6f413a7..dce5061 100644 --- a/src/misc/pv/pvUnitTest.h +++ b/src/misc/pv/pvUnitTest.h @@ -29,24 +29,24 @@ void test_method(const char *kname, const char *mname) } } -class testPassx +class epicsShareClass testPassx { std::ostringstream strm; - bool pass, alive; + const bool dotest, pass; + bool alive; public: - explicit testPassx(bool r) :pass(r), alive(true) {} - ~testPassx() { - if(alive) - testOk(pass, "%s", strm.str().c_str()); - } + testPassx() :dotest(false), pass(false), alive(true) {} + explicit testPassx(bool r) :dotest(true), pass(r), alive(true) {} + ~testPassx(); template inline testPassx& operator<<(T v) { strm< +inline testPassx testNotEqualx(const char *nLHS, const char *nRHS, LHS l, RHS r) +{ + return testPassx(l!=r)< +#include + +#include + +#define epicsExportSharedSymbols +#include + +namespace detail { + +testPassx::~testPassx() { + if(!alive) return; + std::string msg(strm.str()); + size_t nl = msg.find_first_of('\n'); + if(nl==msg.npos) { + // single-line output + if(dotest) + testOk(pass, "%s", msg.c_str()); + else + testDiag("%s", msg.c_str()); + + } else { + // multi-line output + std::istringstream lines(msg); + std::string line; + bool first = true; + while(std::getline(lines ,line)) { + if(dotest && first) { + first = false; + testOk(pass, "%s", line.c_str()); + } else { + testDiag("%s", line.c_str()); + } + } + } +} + +testPassx::testPassx(testPassx& o) + :strm(o.strm.str()) + ,dotest(o.dotest) + ,pass(o.pass) + ,alive(o.alive) +{ + strm.seekp(0, std::ios_base::end); + o.alive = false; +} + +} // namespace detail