From 7b5f339fa350511457d84273dc2b122b161a8811 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 28 Apr 2012 18:18:59 +0000 Subject: Allow hiding specific exceptions to keep test output cleaner. --- lib/common/Box.h | 13 +++++++++---- lib/common/Logging.cpp | 18 ++++++++++++++++++ lib/common/Logging.h | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/common/Box.h b/lib/common/Box.h index 6ef797be..bbff2ccb 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -105,7 +105,9 @@ #define THROW_EXCEPTION(type, subtype) \ { \ - if(!HideExceptionMessageGuard::ExceptionsHidden() \ + if((!HideExceptionMessageGuard::ExceptionsHidden() \ + && !HideSpecificExceptionGuard::IsHidden( \ + type::ExceptionType, type::subtype)) \ || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ { \ std::auto_ptr guard; \ @@ -127,7 +129,9 @@ { \ std::ostringstream _box_throw_line; \ _box_throw_line << message; \ - if(!HideExceptionMessageGuard::ExceptionsHidden() \ + if((!HideExceptionMessageGuard::ExceptionsHidden() \ + && !HideSpecificExceptionGuard::IsHidden( \ + type::ExceptionType, type::subtype)) \ || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ { \ std::auto_ptr guard; \ @@ -139,8 +143,9 @@ \ OPTIONAL_DO_BACKTRACE \ BOX_WARNING("Exception thrown: " \ - #type "(" #subtype ") (" << message << \ - ") at " __FILE__ "(" << __LINE__ << ")") \ + #type "(" #subtype ") (" << \ + _box_throw_line.str() << \ + ") at " __FILE__ ":" << __LINE__) \ } \ throw type(type::subtype, _box_throw_line.str()); \ } diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index f0cf74b4..7674115e 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -46,6 +46,9 @@ Log::Level Logging::sGlobalLevel = Log::EVERYTHING; Logging Logging::sGlobalLogging; //automatic initialisation std::string Logging::sProgramName; +HideSpecificExceptionGuard::SuppressedExceptions_t + HideSpecificExceptionGuard::sSuppressedExceptions; + int Logging::Guard::sGuardCount = 0; Log::Level Logging::Guard::sOriginalLevel = Log::INVALID; @@ -538,3 +541,18 @@ std::string PrintEscapedBinaryData(const std::string& rInput) return output.str(); } + +bool HideSpecificExceptionGuard::IsHidden(int type, int subtype) +{ + for (SuppressedExceptions_t::iterator + i = sSuppressedExceptions.begin(); + i != sSuppressedExceptions.end(); i++) + { + if(i->first == type && i->second == subtype) + { + return true; + } + } + return false; +} + diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 1fcbe59e..2318e142 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -10,6 +10,8 @@ #ifndef LOGGING__H #define LOGGING__H +#include + #include #include #include @@ -389,6 +391,30 @@ class HideExceptionMessageGuard bool mOldHiddenState; }; +class HideSpecificExceptionGuard +{ + private: + std::pair mExceptionCode; + + public: + typedef std::vector > SuppressedExceptions_t; + static SuppressedExceptions_t sSuppressedExceptions; + + HideSpecificExceptionGuard(int type, int subtype) + : mExceptionCode(std::pair(type, subtype)) + { + sSuppressedExceptions.push_back(mExceptionCode); + } + ~HideSpecificExceptionGuard() + { + SuppressedExceptions_t::reverse_iterator i = + sSuppressedExceptions.rbegin(); + assert(*i == mExceptionCode); + sSuppressedExceptions.pop_back(); + } + static bool IsHidden(int type, int subtype); +}; + std::string PrintEscapedBinaryData(const std::string& rInput); #endif // LOGGING__H -- cgit v1.2.3