diff options
| author | Alan Conway <aconway@apache.org> | 2008-09-25 14:16:51 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-09-25 14:16:51 +0000 |
| commit | 3751fdb4d6cdf3600aa97b7ec802c37c6c2a6f01 (patch) | |
| tree | 7ade88dcd40745aca0bbba7025d785f793308812 /qpid/cpp/src/tests | |
| parent | f8eca1f86220e065a5d56eff484ef5726a226f8f (diff) | |
| download | qpid-python-3751fdb4d6cdf3600aa97b7ec802c37c6c2a6f01.tar.gz | |
Added ScopedSuppressLogging, used to suppress expected error messages in tests.
For examples see src/tests/exception_test.cpp
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@698981 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests')
| -rw-r--r-- | qpid/cpp/src/tests/QueuePolicyTest.cpp | 7 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/exception_test.cpp | 10 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/logging.cpp | 53 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/test_tools.h | 14 |
4 files changed, 37 insertions, 47 deletions
diff --git a/qpid/cpp/src/tests/QueuePolicyTest.cpp b/qpid/cpp/src/tests/QueuePolicyTest.cpp index d7f3fa5628..cf45f554df 100644 --- a/qpid/cpp/src/tests/QueuePolicyTest.cpp +++ b/qpid/cpp/src/tests/QueuePolicyTest.cpp @@ -18,9 +18,11 @@ * under the License. * */ +#include "unit_test.h" +#include "test_tools.h" + #include "qpid/broker/QueuePolicy.h" #include "qpid/sys/Time.h" -#include "unit_test.h" #include "MessageUtils.h" #include "BrokerFixture.h" @@ -174,8 +176,9 @@ QPID_AUTO_TEST_CASE(testStrictRingPolicy) BOOST_CHECK_EQUAL(incoming.pop().getData(), (boost::format("%1%_%2%") % "Message" % (i+1)).str()); } try { + ScopedSuppressLogging sl; // Suppress messages for expected errors. f.session.messageTransfer(arg::content=client::Message("Message_6", q)); - BOOST_FAIL("Transfer should have failed as "); + BOOST_FAIL("expecting ResourceLimitExceededException."); } catch (const ResourceLimitExceededException&) {} } diff --git a/qpid/cpp/src/tests/exception_test.cpp b/qpid/cpp/src/tests/exception_test.cpp index 339881fa9d..b42c1e58e0 100644 --- a/qpid/cpp/src/tests/exception_test.cpp +++ b/qpid/cpp/src/tests/exception_test.cpp @@ -20,6 +20,7 @@ */ #include "unit_test.h" +#include "test_tools.h" #include "BrokerFixture.h" #include "qpid/client/SubscriptionManager.h" #include "qpid/sys/Runnable.h" @@ -51,7 +52,10 @@ struct Catcher : public Runnable { ~Catcher() { join(); } void run() { - try { f(); } + try { + ScopedSuppressLogging sl; // Suppress messages for expected errors. + f(); + } catch(const Ex& e) { caught=true; BOOST_MESSAGE(string("Caught expected exception: ")+e.what()+"["+typeid(e).name()+"]"); @@ -76,6 +80,7 @@ struct Catcher : public Runnable { QPID_AUTO_TEST_CASE(TestSessionBusy) { SessionFixture f; try { + ScopedSuppressLogging sl; // Suppress messages for expected errors. f.connection.newSession(f.session.getId().getName()); BOOST_FAIL("Expected SessionBusyException for " << f.session.getId().getName()); } catch (const Exception&) {} // FIXME aconway 2008-09-22: client is not throwing correct exception. @@ -99,6 +104,8 @@ QPID_AUTO_TEST_CASE(DisconnectedListen) { ProxyConnection c(fix.broker->getPort()); fix.session.queueDeclare(arg::queue="q"); fix.subs.subscribe(l, "q"); + + ScopedSuppressLogging sl; // Suppress messages for expected errors. Thread t(fix.subs); fix.connection.proxy.close(); t.join(); @@ -107,6 +114,7 @@ QPID_AUTO_TEST_CASE(DisconnectedListen) { QPID_AUTO_TEST_CASE(NoSuchQueueTest) { ProxySessionFixture fix; + ScopedSuppressLogging sl; // Suppress messages for expected errors. BOOST_CHECK_THROW(fix.subs.subscribe(fix.lq, "no such queue"), NotFoundException); } diff --git a/qpid/cpp/src/tests/logging.cpp b/qpid/cpp/src/tests/logging.cpp index 97bfed2436..32163c0058 100644 --- a/qpid/cpp/src/tests/logging.cpp +++ b/qpid/cpp/src/tests/logging.cpp @@ -77,6 +77,7 @@ QPID_AUTO_TEST_CASE(testStatementEnabled) { // Verify that the singleton enables and disables static // log statements. Logger& l = Logger::instance(); + ScopedSuppressLogging ls(l); l.select(Selector(debug)); static Statement s=QPID_LOG_STATEMENT_INIT(debug); BOOST_CHECK(!s.enabled); @@ -110,7 +111,7 @@ struct TestOutput : public Logger::Output { using boost::assign::list_of; QPID_AUTO_TEST_CASE(testLoggerOutput) { - Logger l; + Logger l; l.clear(); l.select(Selector(debug)); Statement s=QPID_LOG_STATEMENT_INIT(debug); @@ -133,7 +134,7 @@ QPID_AUTO_TEST_CASE(testLoggerOutput) { QPID_AUTO_TEST_CASE(testMacro) { Logger& l=Logger::instance(); - l.clear(); + ScopedSuppressLogging ls(l); l.select(Selector(info)); TestOutput* out=new TestOutput(l); QPID_LOG(info, "foo"); @@ -152,6 +153,7 @@ QPID_AUTO_TEST_CASE(testMacro) { QPID_AUTO_TEST_CASE(testLoggerFormat) { Logger& l = Logger::instance(); + ScopedSuppressLogging ls(l); l.select(Selector(critical)); TestOutput* out=new TestOutput(l); @@ -165,20 +167,16 @@ QPID_AUTO_TEST_CASE(testLoggerFormat) { l.format(Logger::FUNCTION); QPID_LOG(critical, "foo"); + BOOST_CHECK_REGEX("void .*testLoggerFormat.*\\(\\): foo\n", out->last()); l.format(Logger::LEVEL); QPID_LOG(critical, "foo"); BOOST_CHECK_EQUAL("critical foo\n", out->last()); - - l.format(~0); // Everything - QPID_LOG(critical, "foo"); - string re=".* critical -?\\[[0-9a-f]*] "+string(__FILE__)+":\\d+:void .*testLoggerFormat.*\\(\\): foo\n"; - BOOST_CHECK_REGEX(re, out->last()); } QPID_AUTO_TEST_CASE(testOstreamOutput) { Logger& l=Logger::instance(); - l.clear(); + ScopedSuppressLogging ls(l); l.select(Selector(error)); ostringstream os; l.output(os); @@ -191,6 +189,7 @@ QPID_AUTO_TEST_CASE(testOstreamOutput) { #if 0 // This test requires manual intervention. Normally disabled. QPID_AUTO_TEST_CASE(testSyslogOutput) { Logger& l=Logger::instance(); + Logger::StateSaver ls(l); l.clear(); l.select(Selector(info)); l.syslog("qpid_test"); @@ -306,41 +305,9 @@ QPID_AUTO_TEST_CASE(testSelectorFromOptions) { BOOST_CHECK(s.isEnabled(critical, "foo")); } -QPID_AUTO_TEST_CASE(testOptionsFormat) { - Logger l; - { - Options opts(""); - BOOST_CHECK_EQUAL(Logger::TIME|Logger::LEVEL, l.format(opts)); - const char* argv[]={ - 0, - "--log-time", "no", - "--log-level", "no", - "--log-source", "1", - "--log-thread", "1" - }; - opts.parse(ARGC(argv), const_cast<char**>(argv)); - BOOST_CHECK_EQUAL( - Logger::FILE|Logger::LINE|Logger::THREAD, l.format(opts)); - } - { - Options opts(""); // Clear. - const char* argv[]={ - 0, - "--log-level", "no", - "--log-thread", "true", - "--log-function", "YES", - "--log-time", "YES" - }; - opts.parse(ARGC(argv), const_cast<char**>(argv)); - BOOST_CHECK_EQUAL( - Logger::THREAD|Logger::FUNCTION|Logger::TIME, - l.format(opts)); - } -} - -QPID_AUTO_TEST_CASE(testLoggerConfigure) { +QPID_AUTO_TEST_CASE(testLoggerStateure) { Logger& l=Logger::instance(); - l.clear(); + ScopedSuppressLogging ls(l); Options opts("test"); const char* argv[]={ 0, @@ -363,7 +330,7 @@ QPID_AUTO_TEST_CASE(testLoggerConfigure) { QPID_AUTO_TEST_CASE(testQuoteNonPrintable) { Logger& l=Logger::instance(); - l.clear(); + ScopedSuppressLogging ls(l); Options opts("test"); opts.outputs.clear(); opts.outputs.push_back("logging.tmp"); diff --git a/qpid/cpp/src/tests/test_tools.h b/qpid/cpp/src/tests/test_tools.h index 32127b0442..37a6594f8a 100644 --- a/qpid/cpp/src/tests/test_tools.h +++ b/qpid/cpp/src/tests/test_tools.h @@ -18,9 +18,9 @@ * limitations under the License. * */ +#include "qpid/log/Logger.h" #include <limits.h> // Include before boost/test headers. - #include <boost/test/test_tools.hpp> #include <boost/assign/list_of.hpp> #include <boost/regex.hpp> @@ -78,5 +78,17 @@ 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; +}; + + #endif /*!TEST_TOOLS_H*/ |
