summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/tests')
-rwxr-xr-xindra/llcommon/tests/llerror_test.cpp78
-rwxr-xr-xindra/llcommon/tests/stringize_test.cpp2
-rwxr-xr-xindra/llcommon/tests/wrapllerrs.h117
3 files changed, 111 insertions, 86 deletions
diff --git a/indra/llcommon/tests/llerror_test.cpp b/indra/llcommon/tests/llerror_test.cpp
index b28c5ba4b3..a5aaff10c5 100755
--- a/indra/llcommon/tests/llerror_test.cpp
+++ b/indra/llcommon/tests/llerror_test.cpp
@@ -56,9 +56,9 @@ namespace tut
{
public:
TestRecorder() { mWantsTime = false; }
- ~TestRecorder() { LLError::removeRecorder(this); }
+ virtual ~TestRecorder() { }
- void recordMessage(LLError::ELevel level,
+ virtual void recordMessage(LLError::ELevel level,
const std::string& message)
{
mMessages.push_back(message);
@@ -85,15 +85,11 @@ namespace tut
struct ErrorTestData
{
- // addRecorder() expects to be able to later delete the passed
- // Recorder*. Even though removeRecorder() reclaims ownership, passing
- // a pointer to a data member rather than a heap Recorder subclass
- // instance would just be Wrong.
- TestRecorder* mRecorder;
- LLError::Settings* mPriorErrorSettings;
+ LLError::RecorderPtr mRecorder;
+ LLError::SettingsStoragePtr mPriorErrorSettings;
ErrorTestData():
- mRecorder(new TestRecorder)
+ mRecorder(new TestRecorder())
{
fatalWasCalled = false;
@@ -106,13 +102,32 @@ namespace tut
~ErrorTestData()
{
LLError::removeRecorder(mRecorder);
- delete mRecorder;
LLError::restoreSettings(mPriorErrorSettings);
}
+ int countMessages()
+ {
+ return boost::dynamic_pointer_cast<TestRecorder>(mRecorder)->countMessages();
+ }
+
+ void clearMessages()
+ {
+ boost::dynamic_pointer_cast<TestRecorder>(mRecorder)->clearMessages();
+ }
+
+ void setWantsTime(bool t)
+ {
+ boost::dynamic_pointer_cast<TestRecorder>(mRecorder)->setWantsTime(t);
+ }
+
+ std::string message(int n)
+ {
+ return boost::dynamic_pointer_cast<TestRecorder>(mRecorder)->message(n);
+ }
+
void ensure_message_count(int expectedCount)
{
- ensure_equals("message count", mRecorder->countMessages(), expectedCount);
+ ensure_equals("message count", countMessages(), expectedCount);
}
void ensure_message_contains(int n, const std::string& expectedText)
@@ -120,7 +135,7 @@ namespace tut
std::ostringstream test_name;
test_name << "testing message " << n;
- ensure_contains(test_name.str(), mRecorder->message(n), expectedText);
+ ensure_contains(test_name.str(), message(n), expectedText);
}
void ensure_message_does_not_contain(int n, const std::string& expectedText)
@@ -128,7 +143,7 @@ namespace tut
std::ostringstream test_name;
test_name << "testing message " << n;
- ensure_does_not_contain(test_name.str(), mRecorder->message(n), expectedText);
+ ensure_does_not_contain(test_name.str(), message(n), expectedText);
}
};
@@ -385,15 +400,15 @@ namespace
}
typedef std::string (*LogFromFunction)(bool);
- void testLogName(tut::TestRecorder* recorder, LogFromFunction f,
+ void testLogName(LLError::RecorderPtr recorder, LogFromFunction f,
const std::string& class_name = "")
{
- recorder->clearMessages();
+ boost::dynamic_pointer_cast<tut::TestRecorder>(recorder)->clearMessages();
std::string name = f(false);
f(true);
- std::string messageWithoutName = recorder->message(0);
- std::string messageWithName = recorder->message(1);
+ std::string messageWithoutName = boost::dynamic_pointer_cast<tut::TestRecorder>(recorder)->message(0);
+ std::string messageWithName = boost::dynamic_pointer_cast<tut::TestRecorder>(recorder)->message(1);
ensure_has(name + " logged without name",
messageWithoutName, name);
@@ -528,12 +543,12 @@ namespace tut
{
LLError::setTimeFunction(roswell);
- mRecorder->setWantsTime(false);
+ setWantsTime(false);
ufoSighting();
ensure_message_contains(0, "ufo");
ensure_message_does_not_contain(0, roswell());
- mRecorder->setWantsTime(true);
+ setWantsTime(true);
ufoSighting();
ensure_message_contains(1, "ufo");
ensure_message_contains(1, roswell());
@@ -545,13 +560,13 @@ namespace tut
{
LLError::setPrintLocation(true);
LLError::setTimeFunction(roswell);
- mRecorder->setWantsTime(true);
+ setWantsTime(true);
std::string location,
function;
writeReturningLocationAndFunction(location, function);
ensure_equals("order is location time type function message",
- mRecorder->message(0),
+ message(0),
location + roswell() + " INFO: " + function + ": apple");
}
@@ -559,19 +574,19 @@ namespace tut
// multiple recorders
void ErrorTestObject::test<11>()
{
- TestRecorder* altRecorder(new TestRecorder);
+ LLError::RecorderPtr altRecorder(new TestRecorder());
LLError::addRecorder(altRecorder);
LL_INFOS() << "boo" << LL_ENDL;
ensure_message_contains(0, "boo");
- ensure_equals("alt recorder count", altRecorder->countMessages(), 1);
- ensure_contains("alt recorder message 0", altRecorder->message(0), "boo");
+ ensure_equals("alt recorder count", boost::dynamic_pointer_cast<TestRecorder>(altRecorder)->countMessages(), 1);
+ ensure_contains("alt recorder message 0", boost::dynamic_pointer_cast<TestRecorder>(altRecorder)->message(0), "boo");
LLError::setTimeFunction(roswell);
- TestRecorder* anotherRecorder(new TestRecorder);
- anotherRecorder->setWantsTime(true);
+ LLError::RecorderPtr anotherRecorder(new TestRecorder());
+ boost::dynamic_pointer_cast<TestRecorder>(anotherRecorder)->setWantsTime(true);
LLError::addRecorder(anotherRecorder);
LL_INFOS() << "baz" << LL_ENDL;
@@ -579,10 +594,13 @@ namespace tut
std::string when = roswell();
ensure_message_does_not_contain(1, when);
- ensure_equals("alt recorder count", altRecorder->countMessages(), 2);
- ensure_does_not_contain("alt recorder message 1", altRecorder->message(1), when);
- ensure_equals("another recorder count", anotherRecorder->countMessages(), 1);
- ensure_contains("another recorder message 0", anotherRecorder->message(0), when);
+ ensure_equals("alt recorder count", boost::dynamic_pointer_cast<TestRecorder>(altRecorder)->countMessages(), 2);
+ ensure_does_not_contain("alt recorder message 1", boost::dynamic_pointer_cast<TestRecorder>(altRecorder)->message(1), when);
+ ensure_equals("another recorder count", boost::dynamic_pointer_cast<TestRecorder>(anotherRecorder)->countMessages(), 1);
+ ensure_contains("another recorder message 0", boost::dynamic_pointer_cast<TestRecorder>(anotherRecorder)->message(0), when);
+
+ LLError::removeRecorder(altRecorder);
+ LLError::removeRecorder(anotherRecorder);
}
}
diff --git a/indra/llcommon/tests/stringize_test.cpp b/indra/llcommon/tests/stringize_test.cpp
index 3e4ca548e5..2a4ed44a67 100755
--- a/indra/llcommon/tests/stringize_test.cpp
+++ b/indra/llcommon/tests/stringize_test.cpp
@@ -95,7 +95,7 @@ namespace tut
ensure_equals(stringize(f), "3.14159");
ensure_equals(stringize(d), "3.14159");
ensure_equals(stringize(abc), "abc def");
- ensure_equals(stringize(def), "def ghi"); //Will generate llwarns due to narrowing.
+ ensure_equals(stringize(def), "def ghi"); //Will generate LL_WARNS() due to narrowing.
ensure_equals(stringize(llsd), "{'abc':'abc def','d':r3.14159,'i':i34}");
}
diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h
index 3137bd8fea..785197ba11 100755
--- a/indra/llcommon/tests/wrapllerrs.h
+++ b/indra/llcommon/tests/wrapllerrs.h
@@ -38,6 +38,7 @@
#include "stringize.h"
#include <boost/bind.hpp>
#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
#include <list>
#include <string>
#include <stdexcept>
@@ -81,72 +82,29 @@ struct WrapLLErrs
}
std::string error;
- LLError::Settings* mPriorErrorSettings;
+ LLError::SettingsStoragePtr mPriorErrorSettings;
LLError::FatalFunction mPriorFatal;
};
/**
- * LLError::addRecorder() accepts ownership of the passed Recorder* -- it
- * expects to be able to delete it later. CaptureLog isa Recorder whose
- * pointer we want to be able to pass without any ownership implications.
- * For such cases, instantiate a new RecorderProxy(yourRecorder) and pass
- * that. Your heap RecorderProxy might later be deleted, but not yourRecorder.
- */
-class RecorderProxy: public LLError::Recorder
-{
-public:
- RecorderProxy(LLError::Recorder* recorder):
- mRecorder(recorder)
- {}
-
- virtual void recordMessage(LLError::ELevel level, const std::string& message)
- {
- mRecorder->recordMessage(level, message);
- }
-
- virtual bool wantsTime()
- {
- return mRecorder->wantsTime();
- }
-
-private:
- LLError::Recorder* mRecorder;
-};
-
-/**
* Capture log messages. This is adapted (simplified) from the one in
* llerror_test.cpp.
*/
-class CaptureLog : public LLError::Recorder, public boost::noncopyable
+class CaptureLogRecorder : public LLError::Recorder, public boost::noncopyable
{
public:
- CaptureLog(LLError::ELevel level=LLError::LEVEL_DEBUG):
- // Mostly what we're trying to accomplish by saving and resetting
- // LLError::Settings is to bypass the default RecordToStderr and
- // RecordToWinDebug Recorders. As these are visible only inside
- // llerror.cpp, we can't just call LLError::removeRecorder() with
- // each. For certain tests we need to produce, capture and examine
- // DEBUG log messages -- but we don't want to spam the user's console
- // with that output. If it turns out that saveAndResetSettings() has
- // some bad effect, give up and just let the DEBUG level log messages
- // display.
- mOldSettings(LLError::saveAndResetSettings()),
- mProxy(new RecorderProxy(this))
+ CaptureLogRecorder()
+ : LLError::Recorder(),
+ boost::noncopyable(),
+ mMessages()
{
- LLError::setFatalFunction(wouldHaveCrashed);
- LLError::setDefaultLevel(level);
- LLError::addRecorder(mProxy);
}
- ~CaptureLog()
+ virtual ~CaptureLogRecorder()
{
- LLError::removeRecorder(mProxy);
- delete mProxy;
- LLError::restoreSettings(mOldSettings);
}
- void recordMessage(LLError::ELevel level,
- const std::string& message)
+ virtual void recordMessage(LLError::ELevel level, const std::string& message)
{
mMessages.push_back(message);
}
@@ -154,7 +112,7 @@ public:
/// Don't assume the message we want is necessarily the LAST log message
/// emitted by the underlying code; search backwards through all messages
/// for the sought string.
- std::string messageWith(const std::string& search, bool required=true)
+ std::string messageWith(const std::string& search, bool required)
{
for (MessageList::const_reverse_iterator rmi(mMessages.rbegin()), rmend(mMessages.rend());
rmi != rmend; ++rmi)
@@ -187,14 +145,63 @@ public:
return out;
}
+private:
typedef std::list<std::string> MessageList;
MessageList mMessages;
- LLError::Settings* mOldSettings;
- LLError::Recorder* mProxy;
+};
+
+/**
+ * Capture log messages. This is adapted (simplified) from the one in
+ * llerror_test.cpp.
+ */
+class CaptureLog : public boost::noncopyable
+{
+public:
+ CaptureLog(LLError::ELevel level=LLError::LEVEL_DEBUG)
+ // Mostly what we're trying to accomplish by saving and resetting
+ // LLError::Settings is to bypass the default RecordToStderr and
+ // RecordToWinDebug Recorders. As these are visible only inside
+ // llerror.cpp, we can't just call LLError::removeRecorder() with
+ // each. For certain tests we need to produce, capture and examine
+ // DEBUG log messages -- but we don't want to spam the user's console
+ // with that output. If it turns out that saveAndResetSettings() has
+ // some bad effect, give up and just let the DEBUG level log messages
+ // display.
+ : boost::noncopyable(),
+ mOldSettings(LLError::saveAndResetSettings()),
+ mRecorder(new CaptureLogRecorder())
+ {
+ LLError::setFatalFunction(wouldHaveCrashed);
+ LLError::setDefaultLevel(level);
+ LLError::addRecorder(mRecorder);
+ }
+
+ ~CaptureLog()
+ {
+ LLError::removeRecorder(mRecorder);
+ LLError::restoreSettings(mOldSettings);
+ }
+
+ /// Don't assume the message we want is necessarily the LAST log message
+ /// emitted by the underlying code; search backwards through all messages
+ /// for the sought string.
+ std::string messageWith(const std::string& search, bool required=true)
+ {
+ return boost::dynamic_pointer_cast<CaptureLogRecorder>(mRecorder)->messageWith(search, required);
+ }
+
+ std::ostream& streamto(std::ostream& out) const
+ {
+ return boost::dynamic_pointer_cast<CaptureLogRecorder>(mRecorder)->streamto(out);
+ }
+
+private:
+ LLError::SettingsStoragePtr mOldSettings;
+ LLError::RecorderPtr mRecorder;
};
inline
-std::ostream& operator<<(std::ostream& out, const CaptureLog& log)
+std::ostream& operator<<(std::ostream& out, const CaptureLogRecorder& log)
{
return log.streamto(out);
}