[Box Backup-commit] COMMIT r3101 - box/trunk/lib/common
subversion at boxbackup.org
subversion at boxbackup.org
Sat Apr 28 19:18:59 BST 2012
Author: chris
Date: 2012-04-28 19:18:59 +0100 (Sat, 28 Apr 2012)
New Revision: 3101
Modified:
box/trunk/lib/common/Box.h
box/trunk/lib/common/Logging.cpp
box/trunk/lib/common/Logging.h
Log:
Allow hiding specific exceptions to keep test output cleaner.
Modified: box/trunk/lib/common/Box.h
===================================================================
--- box/trunk/lib/common/Box.h 2012-04-28 18:18:15 UTC (rev 3100)
+++ box/trunk/lib/common/Box.h 2012-04-28 18:18:59 UTC (rev 3101)
@@ -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<Logging::Guard> 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<Logging::Guard> 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()); \
}
Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp 2012-04-28 18:18:15 UTC (rev 3100)
+++ box/trunk/lib/common/Logging.cpp 2012-04-28 18:18:59 UTC (rev 3101)
@@ -46,6 +46,9 @@
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 @@
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;
+}
+
Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h 2012-04-28 18:18:15 UTC (rev 3100)
+++ box/trunk/lib/common/Logging.h 2012-04-28 18:18:59 UTC (rev 3101)
@@ -10,6 +10,8 @@
#ifndef LOGGING__H
#define LOGGING__H
+#include <assert.h>
+
#include <cerrno>
#include <cstring>
#include <iomanip>
@@ -389,6 +391,30 @@
bool mOldHiddenState;
};
+class HideSpecificExceptionGuard
+{
+ private:
+ std::pair<int, int> mExceptionCode;
+
+ public:
+ typedef std::vector<std::pair<int, int> > SuppressedExceptions_t;
+ static SuppressedExceptions_t sSuppressedExceptions;
+
+ HideSpecificExceptionGuard(int type, int subtype)
+ : mExceptionCode(std::pair<int, int>(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
More information about the Boxbackup-commit
mailing list