From 248f1fe188fe2307b9dcf2c87a83b653eaa1920c Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sat, 26 Dec 2009 12:42:57 +0000 Subject: synchronized with trunk except for ruby dir git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid.rnr@893970 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/test_tools.h | 48 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'cpp/src/tests/test_tools.h') diff --git a/cpp/src/tests/test_tools.h b/cpp/src/tests/test_tools.h index 32127b0442..bb2509fd32 100644 --- a/cpp/src/tests/test_tools.h +++ b/cpp/src/tests/test_tools.h @@ -18,15 +18,18 @@ * limitations under the License. * */ +#include "qpid/log/Logger.h" #include // Include before boost/test headers. - #include #include #include #include #include +#include #include +#include +#include // Print a sequence template std::ostream& seqPrint(std::ostream& o, const T& seq) { @@ -34,7 +37,7 @@ template std::ostream& seqPrint(std::ostream& o, const T& seq) { return o; } -// Compare sequences +// Compare sequences template bool seqEqual(const T& a, const U& b) { typename T::const_iterator i = a.begin(); @@ -43,13 +46,16 @@ bool seqEqual(const T& a, const U& b) { return (i == a.end()) && (j == b.end()); } -// ostream and == operators so we can compare vectors and boost::assign::list_of -// with BOOST_CHECK_EQUALS +// ostream and == operators so we can compare vectors and sets with +// boost::assign::list_of with BOOST_CHECK_EQUALS namespace std { // In namespace std so boost can find them. template ostream& operator<<(ostream& o, const vector& v) { return seqPrint(o, v); } +template +ostream& operator<<(ostream& o, const set& v) { return seqPrint(o, v); } + template ostream& operator<<(ostream& o, const boost::assign_detail::generic_list& l) { return seqPrint(o, l); } @@ -58,8 +64,17 @@ bool operator == (const vector& a, const boost::assign_detail::generic_list bool operator == (const boost::assign_detail::generic_list& b, const vector& a) { return seqEqual(a, b); } + +template +bool operator == (const set& a, const boost::assign_detail::generic_list& b) { return seqEqual(a, b); } + +template +bool operator == (const boost::assign_detail::generic_list& b, const set& a) { return seqEqual(a, b); } } +namespace qpid { +namespace tests { + /** NB: order of parameters is regex first, in line with * CHECK(expected, actual) convention. */ @@ -78,5 +93,30 @@ inline bool regexPredicate(const std::string& re, const std::string& text) { /** Check if types of two objects (as given by typeinfo::name()) match. */ #define BOOST_CHECK_TYPEID_EQUAL(a,b) BOOST_CHECK_EQUAL(typeid(a).name(),typeid(b).name()) +/** + * Supress all logging in a scope, restore to previous configuration in destructor. + */ +struct ScopedSuppressLogging { + typedef qpid::log::Logger Logger; + ScopedSuppressLogging(Logger& l=Logger::instance()) : logger(l), opts(l.getOptions()) { l.clear(); } + ~ScopedSuppressLogging() { logger.configure(opts); } + Logger& logger; + qpid::log::Options opts; +}; + +inline std::string getLibPath(const char* envName, const char* defaultPath = 0) { + const char* p = std::getenv(envName); + if (p != 0) + return p; + if (defaultPath == 0) { + std::ostringstream msg; + msg << "Environment variable " << envName << " not set."; + throw std::runtime_error(msg.str()); + } + return defaultPath; +} + +}} // namespace qpid::tests + #endif /*!TEST_TOOLS_H*/ -- cgit v1.2.1