summaryrefslogtreecommitdiff
path: root/indra/test/llmessageconfig_tut.cpp
diff options
context:
space:
mode:
authorTess Chu <tess@lindenlab.com>2007-07-11 21:29:02 +0000
committerTess Chu <tess@lindenlab.com>2007-07-11 21:29:02 +0000
commit57b8fef824b6d7f37c5be5812ebffa39ab2e8093 (patch)
treef89014544fc276b283a36eb2e0cb52e93806a44a /indra/test/llmessageconfig_tut.cpp
parenta6769f262ff910949a7e1c81cf98e52ddfc2d44a (diff)
svn merge --ignore-ancestry svn+ssh://svn/svn/linden/release@65088 svn+ssh://svn/svn/linden/branches/release-candidate@65078 -> release Paired by Tess and rdw.
Diffstat (limited to 'indra/test/llmessageconfig_tut.cpp')
-rw-r--r--indra/test/llmessageconfig_tut.cpp205
1 files changed, 88 insertions, 117 deletions
diff --git a/indra/test/llmessageconfig_tut.cpp b/indra/test/llmessageconfig_tut.cpp
index f7eede73a3..1e9f861b25 100644
--- a/indra/test/llmessageconfig_tut.cpp
+++ b/indra/test/llmessageconfig_tut.cpp
@@ -12,41 +12,46 @@
#include "llmessageconfig.h"
#include "llsdserialize.h"
#include "llfile.h"
+#include "lldir.h"
#include "lltimer.h"
#include "llframetimer.h"
namespace tut
{
- ///var/tmp/babbage/dev/message-liberation/etc
- static const char file_name[] = "/tmp/message.xml";
- static const long refreshRateMillis = 6000;
-
struct LLMessageConfigTestData {
+ std::string mTestConfigDir;
- LLSD getCurrentConfig()
+ LLMessageConfigTestData()
{
- LLSD data;
- // store aside the current config to overwrite the test ones
- // when the test finishes
- llifstream in_file(file_name);
- if (in_file.is_open())
- {
- LLSDSerialize::fromXML(data, in_file);
- }
- return data;
+ // generate temp dir
+ mTestConfigDir = "/tmp/llmessage-config-test";
+ LLFile::mkdir(mTestConfigDir.c_str());
+
+ LLMessageConfig::initClass("simulator", mTestConfigDir);
+ }
+
+ ~LLMessageConfigTestData()
+ {
+ // rm contents of temp dir
+ gDirUtilp->deleteFilesInDir(mTestConfigDir, "*");
+ // rm temp dir
+ LLFile::rmdir(mTestConfigDir.c_str());
}
+ void reloadConfig(const LLSD& config)
+ {
+ LLMessageConfig::useConfig(config);
+ }
+
void writeConfigFile(const LLSD& config)
{
- LLMessageConfig::initClass("simulator", "/tmp");
- llofstream file(file_name);
+ std::string configFile = mTestConfigDir + "/message.xml";
+ llofstream file(configFile.c_str());
if (file.is_open())
{
LLSDSerialize::toPrettyXML(config, file);
}
file.close();
- ms_sleep(refreshRateMillis);
- LLFrameTimer::updateFrameTime();
}
};
@@ -58,150 +63,116 @@ namespace tut
void LLMessageConfigTestObject::test<1>()
// tests server defaults
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
config["serverDefaults"]["simulator"] = "template";
- writeConfigFile(config);
- ensure_equals("Ensure server default is not llsd",
- LLMessageConfig::isServerDefaultBuilderLLSD(),
- false);
- ensure_equals("Ensure server default is template",
- LLMessageConfig::isServerDefaultBuilderTemplate(),
- true);
- writeConfigFile(config_backup);
+ reloadConfig(config);
+ ensure_equals("Ensure server default is not template",
+ LLMessageConfig::getServerDefaultFlavor(),
+ LLMessageConfig::TEMPLATE_FLAVOR);
}
template<> template<>
void LLMessageConfigTestObject::test<2>()
- // tests message builders
+ // tests message flavors
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
config["serverDefaults"]["simulator"] = "template";
- config["messages"]["msg1"]["builder"] = "template";
- config["messages"]["msg2"]["builder"] = "llsd";
- writeConfigFile(config);
- ensure_equals("Ensure msg template builder not llsd",
- LLMessageConfig::isMessageBuiltLLSD("msg1"),
- false);
- ensure_equals("Ensure msg template builder",
- LLMessageConfig::isMessageBuiltTemplate("msg1"),
- true);
- ensure_equals("Ensure msg llsd builder",
- LLMessageConfig::isMessageBuiltLLSD("msg2"),
- true);
- ensure_equals("Ensure msg llsd builder not template",
- LLMessageConfig::isMessageBuiltTemplate("msg2"),
- false);
- writeConfigFile(config_backup);
+ config["messages"]["msg1"]["flavor"] = "template";
+ config["messages"]["msg2"]["flavor"] = "llsd";
+ reloadConfig(config);
+ ensure_equals("Ensure msg template flavor",
+ LLMessageConfig::getMessageFlavor("msg1"),
+ LLMessageConfig::TEMPLATE_FLAVOR);
+ ensure_equals("Ensure msg llsd flavor",
+ LLMessageConfig::getMessageFlavor("msg2"),
+ LLMessageConfig::LLSD_FLAVOR);
}
template<> template<>
void LLMessageConfigTestObject::test<4>()
- // tests message builder defaults
+ // tests message flavor defaults
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
config["serverDefaults"]["simulator"] = "llsd";
config["messages"]["msg1"]["trusted-sender"] = true;
- writeConfigFile(config);
- ensure_equals("Ensure missing message defaults to server builder, not template",
- LLMessageConfig::isMessageBuiltTemplate("Test"),
- false);
- ensure_equals("Ensure missing message default to server builder llsd",
- LLMessageConfig::isMessageBuiltLLSD("Test"),
- true);
- ensure_equals("Ensure missing builder defaults to server builder, not template",
- LLMessageConfig::isMessageBuiltTemplate("msg1"),
- false);
- ensure_equals("Ensure missing builder default to server builder llsd",
- LLMessageConfig::isMessageBuiltLLSD("msg1"),
- true);
-
- ensure_equals("Ensure server default is not llsd",
- LLMessageConfig::isServerDefaultBuilderLLSD(),
- true);
- ensure_equals("Ensure server default is template",
- LLMessageConfig::isServerDefaultBuilderTemplate(),
- false);
-
- writeConfigFile(config_backup);
+ reloadConfig(config);
+ ensure_equals("Ensure missing message gives no flavor",
+ LLMessageConfig::getMessageFlavor("Test"),
+ LLMessageConfig::NO_FLAVOR);
+ ensure_equals("Ensure missing flavor is NO_FLAVOR even with sender trustedness set",
+ LLMessageConfig::getMessageFlavor("msg1"),
+ LLMessageConfig::NO_FLAVOR);
+ ensure_equals("Ensure server default is llsd",
+ LLMessageConfig::getServerDefaultFlavor(),
+ LLMessageConfig::LLSD_FLAVOR);
}
template<> template<>
void LLMessageConfigTestObject::test<3>()
// tests trusted/untrusted senders
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
config["serverDefaults"]["simulator"] = "template";
- config["messages"]["msg1"]["builder"] = "llsd";
+ config["messages"]["msg1"]["flavor"] = "llsd";
config["messages"]["msg1"]["trusted-sender"] = false;
- config["messages"]["msg2"]["builder"] = "llsd";
+ config["messages"]["msg2"]["flavor"] = "llsd";
config["messages"]["msg2"]["trusted-sender"] = true;
- writeConfigFile(config);
- ensure_equals("Ensure untrusted is not trusted",
- LLMessageConfig::isMessageTrusted("msg1"),
- false);
+ reloadConfig(config);
ensure_equals("Ensure untrusted is untrusted",
- LLMessageConfig::isValidUntrustedMessage("msg1"),
- true);
+ LLMessageConfig::getSenderTrustedness("msg1"),
+ LLMessageConfig::UNTRUSTED);
ensure_equals("Ensure trusted is trusted",
- LLMessageConfig::isMessageTrusted("msg2"),
- true);
- ensure_equals("Ensure trusted is not untrusted",
- LLMessageConfig::isValidUntrustedMessage("msg2"),
- false);
- writeConfigFile(config_backup);
+ LLMessageConfig::getSenderTrustedness("msg2"),
+ LLMessageConfig::TRUSTED);
+ ensure_equals("Ensure missing trustedness is NOT_SET",
+ LLMessageConfig::getSenderTrustedness("msg3"),
+ LLMessageConfig::NOT_SET);
}
template<> template<>
void LLMessageConfigTestObject::test<5>()
- // tests trusted/untrusted without flag, only builder
+ // tests trusted/untrusted without flag, only flavor
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
config["serverDefaults"]["simulator"] = "template";
- config["messages"]["msg1"]["builder"] = "llsd";
- writeConfigFile(config);
- ensure_equals("Ensure missing trusted is not trusted",
- LLMessageConfig::isMessageTrusted("msg1"),
- false);
- ensure_equals("Ensure missing trusted is not untrusted",
- LLMessageConfig::isValidUntrustedMessage("msg1"),
- false);
- writeConfigFile(config_backup);
+ config["messages"]["msg1"]["flavor"] = "llsd";
+ reloadConfig(config);
+ ensure_equals("Ensure msg1 exists, has llsd flavor",
+ LLMessageConfig::getMessageFlavor("msg1"),
+ LLMessageConfig::LLSD_FLAVOR);
+ ensure_equals("Ensure missing trusted is not set",
+ LLMessageConfig::getSenderTrustedness("msg1"),
+ LLMessageConfig::NOT_SET);
}
template<> template<>
void LLMessageConfigTestObject::test<6>()
- // tests message builder defaults
{
- LLSD config_backup = getCurrentConfig();
LLSD config;
- config["serverDefaults"]["simulator"] = "template";
- config["messages"]["msg1"]["trusted-sender"] = true;
- writeConfigFile(config);
- ensure_equals("Ensure missing message defaults to server builder, not template",
- LLMessageConfig::isMessageBuiltTemplate("Test"),
- true);
- ensure_equals("Ensure missing message default to server builder llsd",
- LLMessageConfig::isMessageBuiltLLSD("Test"),
- false);
- ensure_equals("Ensure missing builder defaults to server builder, not template",
- LLMessageConfig::isMessageBuiltTemplate("msg1"),
+ config["capBans"]["MapLayer"] = true;
+ config["capBans"]["MapLayerGod"] = false;
+ reloadConfig(config);
+ ensure_equals("Ensure cap ban true MapLayer",
+ LLMessageConfig::isCapBanned("MapLayer"),
true);
- ensure_equals("Ensure missing builder default to server builder llsd",
- LLMessageConfig::isMessageBuiltLLSD("msg1"),
+ ensure_equals("Ensure cap ban false",
+ LLMessageConfig::isCapBanned("MapLayerGod"),
false);
+ }
- ensure_equals("Ensure server default is not llsd",
- LLMessageConfig::isServerDefaultBuilderLLSD(),
- false);
- ensure_equals("Ensure server default is template",
- LLMessageConfig::isServerDefaultBuilderTemplate(),
- true);
+ template<> template<>
+ void LLMessageConfigTestObject::test<7>()
+ // tests that config changes are picked up/refreshed periodically
+ {
+ LLSD config;
+ config["serverDefaults"]["simulator"] = "llsd";
+ writeConfigFile(config);
- writeConfigFile(config_backup);
+ // wait for it to reload after N seconds
+ ms_sleep(6*1000);
+ LLFrameTimer::updateFrameTime();
+ ensure_equals("Ensure reload after 6 seconds",
+ LLMessageConfig::getServerDefaultFlavor(),
+ LLMessageConfig::LLSD_FLAVOR);
}
}