summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/llerror_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/tests/llerror_test.cpp')
-rw-r--r--indra/llcommon/tests/llerror_test.cpp79
1 files changed, 45 insertions, 34 deletions
diff --git a/indra/llcommon/tests/llerror_test.cpp b/indra/llcommon/tests/llerror_test.cpp
index cdc2bf8c87..148c18aabe 100644
--- a/indra/llcommon/tests/llerror_test.cpp
+++ b/indra/llcommon/tests/llerror_test.cpp
@@ -26,6 +26,7 @@
*/
#include <vector>
+#include <stdexcept>
#include "linden_common.h"
@@ -69,25 +70,41 @@ namespace
namespace
{
- static bool fatalWasCalled;
- LLError::ErrFatalHookResult fatalHook(const std::string&)
+ static bool fatalWasCalled = false;
+ struct FatalWasCalled: public std::runtime_error
{
- fatalWasCalled = true;
- return LLError::ERR_DO_NOT_CRASH;
- }
+ FatalWasCalled(const std::string& what): std::runtime_error(what) {}
+ };
+ void fatalCall(const std::string& msg) { throw FatalWasCalled(msg); }
}
+// Because we use LLError::setFatalFunction(fatalCall), any LL_ERRS call we
+// issue will throw FatalWasCalled. But we want the test program to continue.
+// So instead of writing:
+// LL_ERRS("tag") << "some message" << LL_ENDL;
+// write:
+// CATCH(LL_ERRS("tag"), "some message");
+#define CATCH(logcall, expr) \
+ try \
+ { \
+ logcall << expr << LL_ENDL; \
+ } \
+ catch (const FatalWasCalled&) \
+ { \
+ fatalWasCalled = true; \
+ }
+
namespace tut
{
class TestRecorder : public LLError::Recorder
{
public:
TestRecorder()
- {
- showTime(false);
- }
+ {
+ showTime(false);
+ }
virtual ~TestRecorder()
- {}
+ {}
virtual void recordMessage(LLError::ELevel level,
const std::string& message)
@@ -124,7 +141,7 @@ namespace tut
mPriorErrorSettings = LLError::saveAndResetSettings();
LLError::setDefaultLevel(LLError::LEVEL_DEBUG);
- LLError::setFatalHook(fatalHook);
+ LLError::setFatalFunction(fatalCall);
LLError::addRecorder(mRecorder);
}
@@ -256,7 +273,7 @@ namespace
LL_DEBUGS("WriteTag","AnotherTag") << "one" << LL_ENDL;
LL_INFOS("WriteTag") << "two" << LL_ENDL;
LL_WARNS("WriteTag") << "three" << LL_ENDL;
- LL_ERRS("WriteTag") << "four" << LL_ENDL;
+ CATCH(LL_ERRS("WriteTag"), "four");
}
};
@@ -384,7 +401,7 @@ namespace
std::string errorReturningLocation()
{
- LL_ERRS() << "die" << LL_ENDL; int this_line = __LINE__;
+ int this_line = __LINE__; CATCH(LL_ERRS(), "die");
return locationString(this_line);
}
}
@@ -705,7 +722,7 @@ public:
static void doDebug() { LL_DEBUGS() << "add dice" << LL_ENDL; }
static void doInfo() { LL_INFOS() << "any idea" << LL_ENDL; }
static void doWarn() { LL_WARNS() << "aim west" << LL_ENDL; }
- static void doError() { LL_ERRS() << "ate eels" << LL_ENDL; }
+ static void doError() { CATCH(LL_ERRS(), "ate eels"); }
static void doAll() { doDebug(); doInfo(); doWarn(); doError(); }
};
@@ -716,7 +733,7 @@ public:
static void doDebug() { LL_DEBUGS() << "bed down" << LL_ENDL; }
static void doInfo() { LL_INFOS() << "buy iron" << LL_ENDL; }
static void doWarn() { LL_WARNS() << "bad word" << LL_ENDL; }
- static void doError() { LL_ERRS() << "big easy" << LL_ENDL; }
+ static void doError() { CATCH(LL_ERRS(), "big easy"); }
static void doAll() { doDebug(); doInfo(); doWarn(); doError(); }
};
@@ -781,33 +798,30 @@ namespace tut
// proper cached, efficient lookup of filtering
void ErrorTestObject::test<15>()
{
- LLError::setDefaultLevel(LLError::LEVEL_NONE);
-
- // Note that the setFatalHook in the ErrorTestData constructor
- // increments the shouldLogCallCount
+ LLError::setDefaultLevel(LLError::LEVEL_NONE);
TestAlpha::doInfo();
ensure_message_count(0);
- ensure_equals("first check", LLError::shouldLogCallCount(), 2);
+ ensure_equals("first check", LLError::shouldLogCallCount(), 1);
TestAlpha::doInfo();
ensure_message_count(0);
- ensure_equals("second check", LLError::shouldLogCallCount(), 2);
+ ensure_equals("second check", LLError::shouldLogCallCount(), 1);
LLError::setClassLevel("TestAlpha", LLError::LEVEL_DEBUG);
TestAlpha::doInfo();
ensure_message_count(1);
- ensure_equals("third check", LLError::shouldLogCallCount(), 3);
+ ensure_equals("third check", LLError::shouldLogCallCount(), 2);
TestAlpha::doInfo();
ensure_message_count(2);
- ensure_equals("fourth check", LLError::shouldLogCallCount(), 3);
+ ensure_equals("fourth check", LLError::shouldLogCallCount(), 2);
LLError::setClassLevel("TestAlpha", LLError::LEVEL_WARN);
TestAlpha::doInfo();
ensure_message_count(2);
- ensure_equals("fifth check", LLError::shouldLogCallCount(), 4);
+ ensure_equals("fifth check", LLError::shouldLogCallCount(), 3);
TestAlpha::doInfo();
ensure_message_count(2);
- ensure_equals("sixth check", LLError::shouldLogCallCount(), 4);
+ ensure_equals("sixth check", LLError::shouldLogCallCount(), 3);
}
template<> template<>
@@ -881,13 +895,10 @@ namespace tut
namespace
{
std::string writeTagWithSpaceReturningLocation()
- {
- LL_DEBUGS("Write Tag") << "not allowed" << LL_ENDL; int this_line = __LINE__;
-
- std::ostringstream location;
- location << LLError::abbreviateFile(__FILE__).c_str() << "(" << this_line << ")";
- return location.str();
- }
+ {
+ int this_line = __LINE__; CATCH(LL_DEBUGS("Write Tag"), "not allowed");
+ return locationString(this_line);
+ }
};
namespace tut
@@ -901,9 +912,9 @@ namespace tut
std::string location = writeTagWithSpaceReturningLocation();
std::string expected = "Space is not allowed in a log tag at " + location;
- ensure_message_field_equals(0, LEVEL_FIELD, "ERROR");
- ensure_message_field_equals(0, MSG_FIELD, expected);
- ensure("fatal callback called", fatalWasCalled);
+ ensure_message_field_equals(0, LEVEL_FIELD, "ERROR");
+ ensure_message_field_equals(0, MSG_FIELD, expected);
+ ensure("fatal callback called", fatalWasCalled);
}
}