summaryrefslogtreecommitdiff
path: root/indra/test
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
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')
-rw-r--r--indra/test/llbuffer_tut.cpp250
-rw-r--r--indra/test/lldatapacker_tut.cpp25
-rw-r--r--indra/test/llmessageconfig_tut.cpp205
-rw-r--r--indra/test/llmessagetemplateparser_tut.cpp350
-rw-r--r--indra/test/llpermissions_tut.cpp533
-rw-r--r--indra/test/llsaleinfo_tut.cpp228
-rwxr-xr-xindra/test/llsdmessagebuilder_tut.cpp2
-rwxr-xr-xindra/test/llsdmessagereader_tut.cpp6
-rw-r--r--indra/test/llsdtraits.h8
-rw-r--r--indra/test/llsdutil_tut.cpp132
-rw-r--r--indra/test/llstreamtools_tut.cpp908
-rw-r--r--indra/test/lltemplatemessagebuilder_tut.cpp944
-rw-r--r--indra/test/lltut.h6
-rw-r--r--indra/test/lluuidhashmap_tut.cpp339
-rw-r--r--indra/test/llxorcipher_tut.cpp113
-rw-r--r--indra/test/message_tut.cpp77
-rw-r--r--indra/test/test.cpp32
17 files changed, 4001 insertions, 157 deletions
diff --git a/indra/test/llbuffer_tut.cpp b/indra/test/llbuffer_tut.cpp
new file mode 100644
index 0000000000..f403181efa
--- /dev/null
+++ b/indra/test/llbuffer_tut.cpp
@@ -0,0 +1,250 @@
+/**
+ * @file llbuffer_tut.cpp
+ * @author Adroit
+ * @date 2007-03
+ * @brief llbuffer test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "llbuffer.h"
+#include "llmemtype.h"
+
+namespace tut
+{
+ struct buffer
+ {
+ };
+
+ typedef test_group<buffer> buffer_t;
+ typedef buffer_t::object buffer_object_t;
+ tut::buffer_t tut_buffer("buffer");
+
+ template<> template<>
+ void buffer_object_t::test<1>()
+ {
+ LLChannelDescriptors channelDescriptors;
+ ensure("in() and out() functions Failed", (0 == channelDescriptors.in() && 1 == channelDescriptors.out()));
+
+ S32 val = 50;
+ LLChannelDescriptors channelDescriptors1(val);
+ ensure("LLChannelDescriptors in() and out() functions Failed", (50 == channelDescriptors1.in() && 51 == channelDescriptors1.out()));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<2>()
+ {
+ LLSegment segment;
+ ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size()));
+ segment.setChannel(50);
+ ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50);
+ ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50)));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<3>()
+ {
+ S32 channel = 30;
+ const char str[] = "SecondLife";
+ S32 len = sizeof(str);
+ LLSegment segment(channel, (U8*)str, len);
+ ensure("LLSegment get functions failed", (30 == segment.getChannel() && len == segment.size() && (U8*)str == segment.data()));
+ ensure_memory_matches("LLSegment::data() failed", segment.data(), segment.size(), (U8*)str, len);
+ ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(channel)));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<4>()
+ {
+ S32 channel = 50;
+ S32 bigSize = 16384*2;
+ char str[] = "SecondLife";
+ S32 smallSize = sizeof(str);
+
+ LLSegment segment;
+ LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384
+
+ S32 requestSize;
+
+ requestSize = 16384-1;
+ ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+ // second request for remainign 1 byte
+
+ requestSize = 1;
+ ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+
+ // it should fail now.
+ requestSize = 1;
+ ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment)));
+
+ LLHeapBuffer buf1(bigSize);
+
+ // requst for more than default size but less than total sizeit should fail now.
+ requestSize = 16384 + 1;
+ ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+
+ LLHeapBuffer buf2((U8*) str, smallSize);
+ requestSize = smallSize;
+ ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0);
+ requestSize = smallSize+1;
+ ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment)));
+ }
+
+ //makeChannelConsumer()
+ template<> template<>
+ void buffer_object_t::test<5>()
+ {
+ LLChannelDescriptors inchannelDescriptors(20);
+ LLChannelDescriptors outchannelDescriptors = LLBufferArray::makeChannelConsumer(inchannelDescriptors);
+ ensure("LLBufferArray::makeChannelConsumer() function Failed", (21 == outchannelDescriptors.in()));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<6>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ S32 count = bufferArray.countAfter(channelDescriptors.in(), NULL);
+ ensure_equals("Appended size is:", count, len);
+ }
+
+ //append() and prepend()
+ template<> template<>
+ void buffer_object_t::test<7>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ const char array1[] = "LindenLabs";
+ S32 len1 = strlen(array1);
+
+ std::string str(array1);
+ str.append(array);
+
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ bufferArray.prepend(channelDescriptors.in(), (U8*)array1, len1);
+ char buf[100];
+ S32 len2 = 20;
+ bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("readAfter length failed", len2, 20);
+
+ buf[len2] = '\0';
+ ensure_equals("readAfter/prepend/append failed", buf, str);
+ }
+
+ //append()
+ template<> template<>
+ void buffer_object_t::test<8>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ const char array1[] = "LindenLabs";
+ S32 len1 = strlen(array1);
+
+ std::string str(array);
+ str.append(array1);
+
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ bufferArray.append(channelDescriptors.in(), (U8*)array1, len1);
+ char buf[100];
+ S32 len2 = 20;
+ bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("readAfter length failed", len2, 20);
+
+ buf[len2] = '\0';
+ ensure_equals("readAfter/append/append failed", buf, str);
+ }
+
+ template<> template<>
+ void buffer_object_t::test<9>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array) + 1;
+ std::string str(array);
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ LLBufferArray bufferArray1;
+ ensure("Contents are not copied and the source buffer is not empty", (1 == bufferArray1.takeContents(bufferArray)));
+
+ char buf[100];
+ S32 len2 = len;
+ bufferArray1.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("takeContents failed to copy", buf, str);
+ }
+
+ //seek()
+ template<> template<>
+ void buffer_object_t::test<10>()
+ {
+ const char array[] = "SecondLife is a Virtual World";
+ S32 len = strlen(array);
+ LLBufferArray bufferArray;
+ bufferArray.append(0, (U8*)array, len);
+
+ char buf[255];
+ S32 len1 = 16;
+ U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
+ buf[len1] = '\0';
+ last = bufferArray.seek(0, last, -2);
+
+ len1 = 15;
+ last = bufferArray.readAfter(0, last, (U8*)buf, len1);
+ buf[len1] = '\0';
+ std::string str(buf);
+ ensure_equals("Seek does'nt worked", str, std::string("a Virtual World"));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<11>()
+ {
+ const char array[] = "SecondLife is a Virtual World";
+ S32 len = strlen(array);
+ LLBufferArray bufferArray;
+ bufferArray.append(0, (U8*)array, len);
+
+ char buf[255];
+ S32 len1 = 10;
+ U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
+ bufferArray.splitAfter(last);
+ LLBufferArray::segment_iterator_t iterator = bufferArray.beginSegment();
+ ++iterator;
+ std::string str(((char*)(*iterator).data()), (*iterator).size());
+ ensure_equals("Strings are not equal;splitAfter() operation failed", str, std::string(" is a Virtual World"));
+ }
+
+ //makeSegment()->eraseSegment()
+ template<> template<>
+ void buffer_object_t::test<12>()
+ {
+ LLBufferArray bufferArray;
+ LLChannelDescriptors channelDescriptors;
+ LLBufferArray::segment_iterator_t it;
+ S32 length = 1000;
+ it = bufferArray.makeSegment(channelDescriptors.out(), length);
+ ensure("makeSegment() function failed", (it != bufferArray.endSegment()));
+ ensure("eraseSegment() function failed", bufferArray.eraseSegment(it));
+ ensure("eraseSegment() begin/end should now be same", bufferArray.beginSegment() == bufferArray.endSegment());
+ }
+
+ // constructSegmentAfter()
+ template<> template<>
+ void buffer_object_t::test<13>()
+ {
+ LLBufferArray bufferArray;
+ LLBufferArray::segment_iterator_t it;
+ LLSegment segment;
+ LLBufferArray::segment_iterator_t end = bufferArray.endSegment();
+ it = bufferArray.constructSegmentAfter(NULL, segment);
+ ensure("constructSegmentAfter() function failed", (it == end));
+ }
+}
diff --git a/indra/test/lldatapacker_tut.cpp b/indra/test/lldatapacker_tut.cpp
index 71def354f9..5e81185f29 100644
--- a/indra/test/lldatapacker_tut.cpp
+++ b/indra/test/lldatapacker_tut.cpp
@@ -1,30 +1,11 @@
/**
* @file lldatapacker_tut.cpp
* @author Adroit
- * @date February 2007
+ * @date 2007-02
* @brief LLDataPacker test cases.
*
- * Copyright (c) 2007-2007, Linden Research, Inc.
- *
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
*/
#include <tut/tut.h>
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);
}
}
diff --git a/indra/test/llmessagetemplateparser_tut.cpp b/indra/test/llmessagetemplateparser_tut.cpp
new file mode 100644
index 0000000000..2f76d7fb20
--- /dev/null
+++ b/indra/test/llmessagetemplateparser_tut.cpp
@@ -0,0 +1,350 @@
+/**
+ * @file llmessagetemplateparser_tut.cpp
+ * @date April 2007
+ * @brief LLMessageTemplateParser unit tests
+ *
+ * Copyright (c) 2006-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "llmessagetemplateparser.h"
+
+namespace tut
+{
+ struct LLMessageTemplateParserTestData {
+ LLMessageTemplateParserTestData() : mMessage("unset message")
+ {
+ }
+
+ ~LLMessageTemplateParserTestData()
+ {
+ }
+
+ void ensure_next(LLTemplateTokenizer & tokens,
+ std::string value,
+ U32 line)
+ {
+ std::string next = tokens.next();
+ ensure_equals(mMessage + " token matches", next, value);
+ ensure_equals(mMessage + " line matches", tokens.line(), line);
+ }
+
+ char * prehash(const char * name)
+ {
+ return gMessageStringTable.getString(name);
+ }
+
+ void ensure_block_attributes(std::string identifier,
+ const LLMessageTemplate * message,
+ const char * name,
+ EMsgBlockType type,
+ S32 number,
+ S32 total_size)
+ {
+ const LLMessageBlock * block = message->getBlock(prehash(name));
+ identifier = identifier + ":" + message->mName + ":" + name + " block";
+ ensure(identifier + " exists", block != NULL);
+ ensure_equals(identifier + " name", block->mName, prehash(name));
+ ensure_equals(identifier + " type", block->mType, type);
+ ensure_equals(identifier + " number", block->mNumber, number);
+ ensure_equals(identifier + " total size", block->mTotalSize, total_size);
+ }
+
+ void ensure_variable_attributes(std::string identifier,
+ const LLMessageBlock * block,
+ const char * name,
+ EMsgVariableType type,
+ S32 size)
+ {
+ const LLMessageVariable * var = block->getVariable(prehash(name));
+ identifier = identifier + ":" + block->mName + ":" + name + " variable";
+ ensure(identifier + " exists", var != NULL);
+ ensure_equals(
+ identifier + " name", var->getName(), prehash(name));
+ ensure_equals(
+ identifier + " type", var->getType(), type);
+ ensure_equals(identifier + " size", var->getSize(), size);
+ }
+
+ std::string mMessage;
+
+ };
+
+ typedef test_group<LLMessageTemplateParserTestData> LLMessageTemplateParserTestGroup;
+ typedef LLMessageTemplateParserTestGroup::object LLMessageTemplateParserTestObject;
+ LLMessageTemplateParserTestGroup llMessageTemplateParserTestGroup("LLMessageTemplateParser");
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<1>()
+ // tests tokenizer constructor and next methods
+ {
+ mMessage = "test method 1 walkthrough";
+ LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth");
+ ensure_next(tokens, "first", 1);
+ ensure_next(tokens, "line", 1);
+ ensure_next(tokens, "next", 2);
+ ensure_next(tokens, "line", 2);
+ ensure_next(tokens, "fourth", 4);
+
+ tokens = LLTemplateTokenizer("\n\t{ \t Test1 Fixed \n 523 }\n\n");
+ ensure(tokens.want("{"));
+ ensure_next(tokens, "Test1", 2);
+ ensure_next(tokens, "Fixed", 2);
+ ensure_next(tokens, "523", 3);
+ ensure(tokens.want("}"));
+
+ tokens = LLTemplateTokenizer("first line\nnext\t line\n\nfourth");
+ ensure(tokens.want("first"));
+ ensure_next(tokens, "line", 1);
+ ensure_next(tokens, "next", 2);
+ ensure_next(tokens, "line", 2);
+ ensure(tokens.want("fourth"));
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<2>()
+ // tests tokenizer want method
+ {
+ // *NOTE: order matters
+ LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth");
+ ensure_equals("wants first token", tokens.want("first"), true);
+ ensure_equals("doesn't want blar token", tokens.want("blar"), false);
+ ensure_equals("wants line token", tokens.want("line"), true);
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<3>()
+ // tests tokenizer eof methods
+ {
+ LLTemplateTokenizer tokens("single\n\n");
+ ensure_equals("is not at eof at beginning", tokens.atEOF(), false);
+ ensure_equals("doesn't want eof", tokens.wantEOF(), false);
+ ensure_equals("wants the first token just to consume it",
+ tokens.want("single"), true);
+ ensure_equals("is not at eof in middle", tokens.atEOF(), false);
+ ensure_equals("wants eof", tokens.wantEOF(), true);
+ ensure_equals("is at eof at end", tokens.atEOF(), true);
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<4>()
+ // tests variable parsing method
+ {
+ LLTemplateTokenizer tokens(std::string("{ Test0 \n\t\n U32 \n\n }"));
+ LLMessageVariable * var = LLTemplateParser::parseVariable(tokens);
+
+ ensure("test0 var parsed", var != 0);
+ ensure_equals("name of variable", std::string(var->getName()), std::string("Test0"));
+ ensure_equals("type of variable is U32", var->getType(), MVT_U32);
+ ensure_equals("size of variable", var->getSize(), 4);
+
+ delete var;
+
+ std::string message_string("\n\t{ \t Test1 Fixed \n 523 }\n\n");
+ tokens = LLTemplateTokenizer(message_string);
+ var = LLTemplateParser::parseVariable(tokens);
+
+ ensure("test1 var parsed", var != 0);
+ ensure_equals("name of variable", std::string(var->getName()), std::string("Test1"));
+ ensure_equals("type of variable is Fixed", var->getType(), MVT_FIXED);
+ ensure_equals("size of variable", var->getSize(), 523);
+
+ delete var;
+
+ // *NOTE: the parsers call llerrs on invalid input, so we can't really
+ // test that :-(
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<5>()
+ // tests block parsing method
+ {
+ LLTemplateTokenizer tokens("{ BlockA Single { VarX F32 } }");
+ LLMessageBlock * block = LLTemplateParser::parseBlock(tokens);
+
+ ensure("blockA block parsed", block != 0);
+ ensure_equals("name of block", std::string(block->mName), std::string("BlockA"));
+ ensure_equals("type of block is Single", block->mType, MBT_SINGLE);
+ ensure_equals("total size of block", block->mTotalSize, 4);
+ ensure_equals("number of block defaults to 1", block->mNumber, 1);
+ ensure_equals("variable type of VarX is F32",
+ block->getVariableType(prehash("VarX")), MVT_F32);
+ ensure_equals("variable size of VarX",
+ block->getVariableSize(prehash("VarX")), 4);
+
+ delete block;
+
+ tokens = LLTemplateTokenizer("{ Stuff Variable { Id LLUUID } }");
+ block = LLTemplateParser::parseBlock(tokens);
+
+ ensure("stuff block parsed", block != 0);
+ ensure_equals("name of block", std::string(block->mName), std::string("Stuff"));
+ ensure_equals("type of block is Multiple", block->mType, MBT_VARIABLE);
+ ensure_equals("total size of block", block->mTotalSize, 16);
+ ensure_equals("number of block defaults to 1", block->mNumber, 1);
+ ensure_equals("variable type of Id is LLUUID",
+ block->getVariableType(prehash("Id")), MVT_LLUUID);
+ ensure_equals("variable size of Id",
+ block->getVariableSize(prehash("Id")), 16);
+
+ delete block;
+
+ tokens = LLTemplateTokenizer("{ Stuff2 Multiple 45 { Shid LLVector3d } }");
+ block = LLTemplateParser::parseBlock(tokens);
+
+ ensure("stuff2 block parsed", block != 0);
+ ensure_equals("name of block", std::string(block->mName), std::string("Stuff2"));
+ ensure_equals("type of block is Multiple", block->mType, MBT_MULTIPLE);
+ ensure_equals("total size of block", block->mTotalSize, 24);
+ ensure_equals("number of blocks", block->mNumber, 45);
+ ensure_equals("variable type of Shid is Vector3d",
+ block->getVariableType(prehash("Shid")), MVT_LLVector3d);
+ ensure_equals("variable size of Shid",
+ block->getVariableSize(prehash("Shid")), 24);
+
+ delete block;
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<6>()
+ // tests message parsing method on a simple message
+ {
+ std::string message_skel(
+ "{\n"
+ "TestMessage Low 1 NotTrusted Zerocoded\n"
+ "// comment \n"
+ " {\n"
+ "TestBlock1 Single\n"
+ " { Test1 U32 }\n"
+ " }\n"
+ " {\n"
+ " NeighborBlock Multiple 4\n"
+ " { Test0 U32 }\n"
+ " { Test1 U32 }\n"
+ " { Test2 U32 }\n"
+ " }\n"
+ "}");
+ LLTemplateTokenizer tokens(message_skel);
+ LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens);
+
+ ensure("simple message parsed", message != 0);
+ ensure_equals("name of message", std::string(message->mName), std::string("TestMessage"));
+ ensure_equals("frequency is Low", message->mFrequency, MFT_LOW);
+ ensure_equals("trust is untrusted", message->mTrust, MT_NOTRUST);
+ ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 1));
+ ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED);
+ ensure_equals("message deprecation is notdeprecated", message->mDeprecation, MD_NOTDEPRECATED);
+
+ LLMessageBlock * block = message->getBlock(prehash("NonexistantBlock"));
+ ensure("Nonexistant block does not exist", block == 0);
+
+ delete message;
+ }
+
+ template<> template<>
+ void LLMessageTemplateParserTestObject::test<7>()
+ // tests message parsing method on a deprecated message
+ {
+ std::string message_skel(
+ "{\n"
+ "TestMessageDeprecated High 34 Trusted Unencoded Deprecated\n"
+ " {\n"
+ "TestBlock2 Single\n"
+ " { Test2 S32 }\n"
+ " }\n"
+ "}");
+ LLTemplateTokenizer tokens(message_skel);
+ LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens);
+
+ ensure("deprecated message parsed", message != 0);
+ ensure_equals("name of message", std::string(message->mName), std::string("TestMessageDeprecated"));
+ ensure_equals("frequency is High", message->mFrequency, MFT_HIGH);
+ ensure_equals("trust is trusted", message->mTrust, MT_TRUST);
+ ensure_equals("message number", message->mMessageNumber, (U32)34);
+ ensure_equals("message encoding is unencoded", message->mEncoding, ME_UNENCODED);
+ ensure_equals("message deprecation is deprecated", message->mDeprecation, MD_DEPRECATED);
+
+ delete message;
+ }
+
+ void LLMessageTemplateParserTestObject::test<8>()
+ // tests message parsing on RezMultipleAttachmentsFromInv, a possibly-faulty message
+ {
+ std::string message_skel(
+ "{\n\
+ RezMultipleAttachmentsFromInv Low 452 NotTrusted Zerocoded\n\
+ {\n\
+ AgentData Single\n\
+ { AgentID LLUUID }\n\
+ { SessionID LLUUID }\n\
+ } \n\
+ {\n\
+ HeaderData Single\n\
+ { CompoundMsgID LLUUID } // All messages a single \"compound msg\" must have the same id\n\
+ { TotalObjects U8 }\n\
+ { FirstDetachAll BOOL }\n\
+ }\n\
+ {\n\
+ ObjectData Variable // 1 to 4 of these per packet\n\
+ { ItemID LLUUID }\n\
+ { OwnerID LLUUID }\n\
+ { AttachmentPt U8 } // 0 for default\n\
+ { ItemFlags U32 }\n\
+ { GroupMask U32 }\n\
+ { EveryoneMask U32 }\n\
+ { NextOwnerMask U32 }\n\
+ { Name Variable 1 }\n\
+ { Description Variable 1 }\n\
+ }\n\
+ }\n\
+ ");
+ LLTemplateTokenizer tokens(message_skel);
+ LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens);
+
+ ensure("RezMultipleAttachmentsFromInv message parsed", message != 0);
+ ensure_equals("name of message", message->mName, prehash("RezMultipleAttachmentsFromInv"));
+ ensure_equals("frequency is low", message->mFrequency, MFT_LOW);
+ ensure_equals("trust is not trusted", message->mTrust, MT_NOTRUST);
+ ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 452));
+ ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED);
+
+ ensure_block_attributes(
+ "RMAFI", message, "AgentData", MBT_SINGLE, 1, 16+16);
+ LLMessageBlock * block = message->getBlock(prehash("AgentData"));
+ ensure_variable_attributes("RMAFI",
+ block, "AgentID", MVT_LLUUID, 16);
+ ensure_variable_attributes("RMAFI",
+ block, "SessionID", MVT_LLUUID, 16);
+
+ ensure_block_attributes(
+ "RMAFI", message, "HeaderData", MBT_SINGLE, 1, 16+1+1);
+ block = message->getBlock(prehash("HeaderData"));
+ ensure_variable_attributes(
+ "RMAFI", block, "CompoundMsgID", MVT_LLUUID, 16);
+ ensure_variable_attributes(
+ "RMAFI", block, "TotalObjects", MVT_U8, 1);
+ ensure_variable_attributes(
+ "RMAFI", block, "FirstDetachAll", MVT_BOOL, 1);
+
+
+ ensure_block_attributes(
+ "RMAFI", message, "ObjectData", MBT_VARIABLE, 1, -1);
+ block = message->getBlock(prehash("ObjectData"));
+ ensure_variable_attributes("RMAFI", block, "ItemID", MVT_LLUUID, 16);
+ ensure_variable_attributes("RMAFI", block, "OwnerID", MVT_LLUUID, 16);
+ ensure_variable_attributes("RMAFI", block, "AttachmentPt", MVT_U8, 1);
+ ensure_variable_attributes("RMAFI", block, "ItemFlags", MVT_U32, 4);
+ ensure_variable_attributes("RMAFI", block, "GroupMask", MVT_U32, 4);
+ ensure_variable_attributes("RMAFI", block, "EveryoneMask", MVT_U32, 4);
+ ensure_variable_attributes("RMAFI", block, "NextOwnerMask", MVT_U32, 4);
+ ensure_variable_attributes("RMAFI", block, "Name", MVT_VARIABLE, 1);
+ ensure_variable_attributes("RMAFI", block, "Description", MVT_VARIABLE, 1);
+
+ delete message;
+ }
+
+
+
+}
diff --git a/indra/test/llpermissions_tut.cpp b/indra/test/llpermissions_tut.cpp
new file mode 100644
index 0000000000..1a1e392a65
--- /dev/null
+++ b/indra/test/llpermissions_tut.cpp
@@ -0,0 +1,533 @@
+/**
+ * @file llpermissions_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief llpermissions test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "message.h"
+#include "llpermissions.h"
+
+
+namespace tut
+{
+ struct permission
+ {
+ };
+ typedef test_group<permission> permission_t;
+ typedef permission_t::object permission_object_t;
+ tut::permission_t tut_permission("permission");
+
+ template<> template<>
+ void permission_object_t::test<1>()
+ {
+ LLPermissions permissions;
+ LLUUID uuid = permissions.getCreator();
+ LLUUID uuid1 = permissions.getOwner();
+ LLUUID uuid2 = permissions.getGroup();
+ LLUUID uuid3 = permissions.getLastOwner();
+
+ ensure("LLPermission Get Functions failed", (uuid == LLUUID::null && uuid1 == LLUUID::null &&
+ uuid2 == LLUUID::null && uuid3 == LLUUID::null));
+ ensure("LLPermission Get Functions failed", (permissions.getMaskBase() == PERM_ALL && permissions.getMaskOwner() == PERM_ALL &&
+ permissions.getMaskGroup() == PERM_ALL && permissions.getMaskEveryone() == PERM_ALL && permissions.getMaskNextOwner() == PERM_ALL));
+ ensure("Ownership functions failed", (permissions.isGroupOwned() == FALSE && permissions.isOwned() == FALSE));
+ }
+
+ template<> template<>
+ void permission_object_t::test<2>()
+ {
+ LLPermissions permissions;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ permissions.init(creator, owner, lastOwner, group);
+
+ ensure_equals("init/getCreator():failed to return the creator ", creator, permissions.getCreator());
+ ensure_equals("init/getOwner():failed to return the owner ", owner, permissions.getOwner());
+ ensure_equals("init/getLastOwner():failed to return the group ", lastOwner, permissions.getLastOwner());
+ ensure_equals("init/getGroup():failed to return the group ", group, permissions.getGroup());
+ }
+
+ template<> template<>
+ void permission_object_t::test<3>()
+ {
+ LLPermissions permissions;
+ U32 base = PERM_ALL;
+ U32 owner = PERM_ITEM_UNRESTRICTED; //PERM_ITEM_UNRESTRICTED = PERM_MODIFY | PERM_COPY | PERM_TRANSFER;
+ U32 group = PERM_TRANSFER | PERM_MOVE | PERM_COPY|PERM_MODIFY;
+ U32 everyone = PERM_TRANSFER | PERM_MOVE | PERM_MODIFY;
+ U32 next = PERM_NONE;
+
+ U32 fixedbase = base;
+ U32 fixedowner = PERM_ITEM_UNRESTRICTED; //owner & fixedbase
+ U32 fixedgroup = PERM_ITEM_UNRESTRICTED; // no PERM_MOVE as owner does not have that perm either
+ U32 fixedeveryone = PERM_TRANSFER; // no PERM_MOVE. Everyone can never modify.
+ U32 fixednext = PERM_NONE;
+
+ permissions.initMasks(base, owner, everyone, group, next); // will fix perms if not allowed.
+ ensure_equals("initMasks/getMaskBase():failed to return the MaskBase ", fixedbase, permissions.getMaskBase());
+ ensure_equals("initMasks/getMaskOwner():failed to return the MaskOwner ", fixedowner, permissions.getMaskOwner());
+ ensure_equals("initMasks/getMaskEveryone():failed to return the MaskGroup ", fixedgroup, permissions.getMaskGroup());
+ ensure_equals("initMasks/getMaskEveryone():failed to return the MaskEveryone ", fixedeveryone, permissions.getMaskEveryone());
+ ensure_equals("initMasks/getMaskNextOwner():failed to return the MaskNext ", fixednext, permissions.getMaskNextOwner());
+
+ // explictly set should maintain the values
+ permissions.setMaskBase(base); //no fixing
+ ensure_equals("setMaskBase/getMaskBase():failed to return the MaskBase ", base, permissions.getMaskBase());
+
+ permissions.setMaskOwner(owner);
+ ensure_equals("setMaskOwner/getMaskOwner():failed to return the MaskOwner ", owner, permissions.getMaskOwner());
+
+ permissions.setMaskEveryone(everyone);
+ ensure_equals("setMaskEveryone/getMaskEveryone():failed to return the MaskEveryone ", everyone, permissions.getMaskEveryone());
+
+ permissions.setMaskGroup(group);
+ ensure_equals("setMaskGroup/getMaskEveryone():failed to return the MaskGroup ", group, permissions.getMaskGroup());
+
+ permissions.setMaskNext(next);
+ ensure_equals("setMaskNext/getMaskNextOwner():failed to return the MaskNext ", next, permissions.getMaskNextOwner());
+
+ // further tests can be added to ensure perms for owner/group/everyone etc. get properly fixed.
+ // code however suggests that there is no explict check if the perms are correct and the user of this
+ // class is expected to know how to use them correctly. skipping further test cases for now for various
+ // perm combinations.
+ }
+
+ template<> template<>
+ void permission_object_t::test<4>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm1.init(creator,owner,lastOwner,group);
+ perm.set(perm1);
+ ensure("set():failed to set ", (creator == perm.getCreator()) && (owner == perm.getOwner())&&
+ (lastOwner == perm.getLastOwner())&& (group == perm.getGroup()));
+ }
+
+ template<> template<>
+ void permission_object_t::test<5>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm1.init(creator,owner,lastOwner,group);
+
+ U32 base = PERM_TRANSFER;
+ U32 ownerp = PERM_TRANSFER;
+ U32 groupp = PERM_TRANSFER;
+ U32 everyone = PERM_TRANSFER;
+ U32 next = PERM_NONE;
+
+ perm1.initMasks(base, ownerp, everyone, groupp, next);
+
+ base = PERM_ALL;
+ ownerp = PERM_ITEM_UNRESTRICTED; //PERM_ITEM_UNRESTRICTED = PERM_MODIFY | PERM_COPY | PERM_TRANSFER;
+ groupp = PERM_TRANSFER | PERM_COPY|PERM_MODIFY;
+ everyone = PERM_TRANSFER;
+ next = PERM_NONE;
+
+ perm.init(creator,owner,lastOwner,group);
+ perm.initMasks(base, ownerp, everyone, groupp, next);
+
+ // restrict permissions by accumulation
+ perm.accumulate(perm1);
+
+ U32 fixedbase = PERM_TRANSFER | PERM_MOVE;
+ U32 fixedowner = PERM_TRANSFER;
+ U32 fixedgroup = PERM_TRANSFER;
+ U32 fixedeveryone = PERM_TRANSFER;
+ U32 fixednext = PERM_NONE;
+
+ ensure_equals("accumulate failed ", fixedbase, perm.getMaskBase());
+ ensure_equals("accumulate failed ", fixedowner, perm.getMaskOwner());
+ ensure_equals("accumulate failed ", fixedgroup, perm.getMaskGroup());
+ ensure_equals("accumulate failed ", fixedeveryone, perm.getMaskEveryone());
+ ensure_equals("accumulate failed ", fixednext, perm.getMaskNextOwner());
+ }
+
+ template<> template<>
+ void permission_object_t::test<6>()
+ {
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ ensure_equals("getSafeOwner:failed ", owner,perm.getSafeOwner());
+
+ ///NULL Owner
+ perm.init(creator,LLUUID::null,lastOwner,group);
+ ensure_equals("getSafeOwner:failed ", group, perm.getSafeOwner());
+ }
+
+ template<> template<>
+ void permission_object_t::test<7>()
+ {
+ LLPermissions perm1;
+ LLUUID uuid;
+ BOOL is_group_owned = FALSE;
+ ensure("1:getOwnership:failed ", (FALSE == perm1.getOwnership(uuid,is_group_owned)));
+
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ perm.getOwnership(uuid,is_group_owned);
+ ensure("2:getOwnership:failed ", ((uuid == owner) && (FALSE == is_group_owned)));
+
+ perm.init(creator,LLUUID::null,lastOwner,group);
+ perm.getOwnership(uuid,is_group_owned);
+ ensure("3:getOwnership:failed ", ((uuid == group) && (TRUE == is_group_owned)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<8>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ perm1.init(creator,owner,lastOwner,group);
+ ensure_equals("getCRC32:failed ", perm.getCRC32(),perm1.getCRC32());
+ }
+
+ template<> template<>
+ void permission_object_t::test<9>()
+ {
+ LLPermissions perm;
+ LLUUID agent("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ bool is_atomic = TRUE;
+ ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(agent,owner,group,is_atomic)));
+
+ LLUUID owner2("68edcf47-ccd7-45b8-9f90-1649d7f12807");
+ LLUUID group2("9c8eca51-53d5-42a7-bb58-cef070395db9");
+
+ // cant change - agent need to be current owner
+ ensure("setOwnerAndGroup():failed ", (FALSE == perm.setOwnerAndGroup(agent,owner2,group2,is_atomic)));
+
+ // should be able to change - agent and owner same as current owner
+ ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(owner,owner,group2,is_atomic)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<10>()
+ {
+ LLPermissions perm;
+ LLUUID agent;
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ ensure("deedToGroup():failed ", (TRUE == perm.deedToGroup(agent,group)));
+ }
+ template<> template<>
+ void permission_object_t::test<11>()
+ {
+ LLPermissions perm;
+ LLUUID agent;
+ BOOL set = 1;
+ U32 bits = PERM_TRANSFER | PERM_MODIFY;
+ ensure("setBaseBits():failed ", (TRUE == perm.setBaseBits(agent, set, bits)));
+ ensure("setOwnerBits():failed ", (TRUE == perm.setOwnerBits(agent, set, bits)));
+
+ LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ ensure("setBaseBits():failed ", (FALSE == perm.setBaseBits(agent1, set, bits)));
+ ensure("setOwnerBits():failed ", (FALSE == perm.setOwnerBits(agent1, set, bits)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<12>()
+ {
+ LLPermissions perm;
+ LLUUID agent;
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ BOOL set = 1;
+ U32 bits = 10;
+ ensure("setGroupBits():failed ", (TRUE == perm.setGroupBits(agent,group, set, bits)));
+ ensure("setEveryoneBits():failed ", (TRUE == perm.setEveryoneBits(agent,group, set, bits)));
+ ensure("setNextOwnerBits():failed ", (TRUE == perm.setNextOwnerBits(agent,group, set, bits)));
+
+ LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ ensure("setGroupBits():failed ", (FALSE == perm.setGroupBits(agent1,group, set, bits)));
+ ensure("setEveryoneBits():failed ", (FALSE == perm.setEveryoneBits(agent1,group, set, bits)));
+ ensure("setNextOwnerBits():failed ", (FALSE == perm.setNextOwnerBits(agent1,group, set, bits)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<13>()
+ {
+ LLPermissions perm;
+ LLUUID agent;
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ U32 bits = 10;
+ ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent,group)));
+
+ LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ perm.init(creator,owner,lastOwner,group);
+ ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent1,group)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<14>()
+ {
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner;
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ LLUUID agent;
+ ensure("1:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent)));
+ ensure("2:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent,group)));
+
+ U32 val1 = 0x7FFFFFFF;
+ S32 sVal = 1 << 14;
+ sVal = val1 & sVal;
+ LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ ensure("3:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1)));
+ ensure("4:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1,group)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<15>()
+ {
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner;
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ LLUUID agent;
+ ensure("1:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent)));
+ ensure("2:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent,group)));
+
+ U32 val1 = 0x7FFFFFFF;
+ S32 sVal = 1 << 15;
+ sVal = val1 & sVal;
+ LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ ensure("3:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1)));
+ ensure("4:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1,group)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<16>()
+ {
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner;
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ LLUUID agent;
+ ensure("1:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent)));
+ ensure("2:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent,group)));
+
+ U32 val1 = 0x7FFFFFFF;
+ S32 sVal = 1 << 19;
+ sVal = val1 & sVal;
+ LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ ensure("3:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1)));
+ ensure("4:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1,group)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<17>()
+ {
+ LLPermissions perm;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner;
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ LLUUID agent;
+ ensure("1:allowMoveBy():failed ", (TRUE == perm.allowTransferTo(agent)));
+
+ perm.init(creator,owner,lastOwner,group);
+ U32 val1 = 0x7FFFFFFF;
+ S32 sVal = 1 << 13;
+ sVal = val1 & sVal;
+ ensure("2:allowMoveBy():failed ", (sVal == perm.allowTransferTo(agent)));
+ }
+
+ template<> template<>
+ void permission_object_t::test<18>()
+ {
+ LLPermissions perm,perm1;
+ ensure("1:Operator==:failed ", perm == perm1);
+
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ perm = perm1;
+ ensure("2:Operator==:failed ", perm == perm1);
+ }
+
+ template<> template<>
+ void permission_object_t::test<19>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ ensure("2:Operator==:failed ", perm != perm1);
+ }
+
+ template<> template<>
+ void permission_object_t::test<20>()
+ {
+ FILE* fp = fopen("linden_file.dat","w+");
+ if(!fp)
+ {
+ llerrs << "file coudnt be opened\n" << llendl;
+ return;
+ }
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+
+ U32 base = PERM_TRANSFER | PERM_COPY;
+ U32 ownerp = PERM_TRANSFER;
+ U32 groupp = PERM_TRANSFER;
+ U32 everyone = PERM_TRANSFER;
+ U32 next = PERM_NONE;
+
+ perm.initMasks(base, ownerp, everyone, groupp, next);
+
+ perm.exportFile(fp);
+ fclose(fp);
+ fp = fopen("linden_file.dat","r+");
+ if(!fp)
+ {
+ llerrs << "file coudnt be opened\n" << llendl;
+ return;
+ }
+ perm1.importFile(fp);
+ fclose(fp);
+ ensure("exportFile()/importFile():failed to export and import the data ", perm1 == perm);
+}
+
+ template<> template<>
+ void permission_object_t::test<21>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+
+ U32 base = PERM_TRANSFER | PERM_COPY;
+ U32 ownerp = PERM_TRANSFER;
+ U32 groupp = PERM_TRANSFER;
+ U32 everyone = PERM_TRANSFER;
+ U32 next = PERM_NONE;
+
+ perm.initMasks(base, ownerp, everyone, groupp, next);
+
+ std::ostringstream ostream;
+ perm.exportLegacyStream(ostream);
+ std::istringstream istream(ostream.str());
+ perm1.importLegacyStream(istream);
+
+ ensure("exportLegacyStream()/importLegacyStream():failed to export and import the data ", perm1 == perm);
+ }
+
+ template<> template<>
+ void permission_object_t::test<22>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ LLXMLNode* xml_node = perm.exportFileXML();
+ perm1.importXML(xml_node);
+ ensure("exportFileXML()/importXML():failed to export and import the data ", perm1 == perm);
+ }
+
+ template<> template<>
+ void permission_object_t::test<23>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+ std::ostringstream stream1, stream2;
+ stream1 << perm;
+ perm1.init(creator,owner,lastOwner,group);
+ stream2 << perm1;
+ ensure("1:operator << failed",(stream1.str() == stream2.str()));
+ }
+
+ template<> template<>
+ void permission_object_t::test<24>()
+ {
+ LLPermissions perm,perm1;
+ LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
+ LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806");
+ LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d");
+ LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8");
+ perm.init(creator,owner,lastOwner,group);
+
+ U32 base = PERM_TRANSFER | PERM_COPY;
+ U32 ownerp = PERM_TRANSFER;
+ U32 groupp = PERM_TRANSFER;
+ U32 everyone = PERM_TRANSFER;
+ U32 next = PERM_NONE;
+
+ perm.initMasks(base, ownerp, everyone, groupp, next);
+
+ LLSD sd = ll_create_sd_from_permissions(perm);
+ perm1 = ll_permissions_from_sd(sd);
+ ensure_equals("ll_permissions_from_sd() and ll_create_sd_from_permissions()functions failed", perm, perm1);
+ }
+
+ template<> template<>
+ void permission_object_t::test<25>()
+ {
+ LLAggregatePermissions AggrPermission;
+ LLAggregatePermissions AggrPermission1;
+ ensure("getU8() function failed", (AggrPermission.getU8() == 0));
+ ensure("isEmpty() function failed", (AggrPermission.isEmpty() == TRUE));
+ AggrPermission.getValue(PERM_TRANSFER);
+ ensure_equals("getValue() function failed", AggrPermission.getValue(PERM_TRANSFER), 0x00);
+
+ AggrPermission.aggregate(PERM_ITEM_UNRESTRICTED);
+ ensure("aggregate() function failed", (AggrPermission.isEmpty() == FALSE));
+
+ AggrPermission1.aggregate(AggrPermission);
+ ensure("aggregate() function failed", (AggrPermission1.isEmpty() == FALSE));
+
+ std::ostringstream stream1;
+ stream1 << AggrPermission;
+ ensure("operator<< failed", (stream1.str() == "{PI_COPY=All, PI_MODIFY=All, PI_TRANSFER=All}"));
+ }
+}
diff --git a/indra/test/llsaleinfo_tut.cpp b/indra/test/llsaleinfo_tut.cpp
new file mode 100644
index 0000000000..ef6e1cc94b
--- /dev/null
+++ b/indra/test/llsaleinfo_tut.cpp
@@ -0,0 +1,228 @@
+/**
+ * @file LLSaleInfo_tut.cpp
+ * @author Adroit
+ * @date 2007-03
+ * @brief Test cases of llsaleinfo.h
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "linden_common.h"
+#include "llsaleinfo.h"
+
+namespace tut
+{
+ struct llsaleinfo_tut
+ {
+ };
+ typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t;
+ typedef llsaleinfo_tut_t::object llsaleinfo_test_t;
+ tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo");
+
+ template<> template<>
+ void llsaleinfo_test_t::test<1>()
+ {
+ //test case for getSaleType(), getSalePrice(), getCRC32() fn.
+ //test case for setSaleType(), setSalePrice() fn.
+
+ S32 sale_price = 10000;
+ LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
+ char* sale= "copy";
+
+ LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
+ LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
+
+ ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType());
+ ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
+ ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice());
+ ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32());
+ ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale));
+ ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
+
+ llsaleinfo.setSalePrice(10000000);
+ llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL);
+ sale = "cntn";
+ llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
+ saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
+
+ ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType());
+ ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
+ ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice());
+ ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32());
+ ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale));
+ ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
+
+ llsaleinfo.setSalePrice(55000550);
+ llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS);
+ sale = "orig";
+ llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
+ saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
+
+ ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType());
+ ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
+ ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice());
+ ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32());
+ ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale));
+ ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
+
+ llsaleinfo.setSalePrice(-6432);
+ llsaleinfo.setSaleType(LLSaleInfo::FS_NOT);
+ sale = "not";
+ llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
+ saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
+
+ ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType());
+ ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale());
+ ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice());
+ ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32());
+ ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale));
+ ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
+ }
+
+ template<> template<>
+ void llsaleinfo_test_t::test<2>()
+ {
+
+ FILE* fp = fopen("linden_file.dat","w+");
+ if(!fp)
+ {
+ llerrs << "file could not be opened\n" << llendl;
+ return;
+ }
+
+ S32 sale_price = 43500;
+ LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
+
+ llsaleinfo.exportFile(fp);
+ fclose(fp);
+
+ LLSaleInfo llsaleinfo1;
+ U32 perm_mask;
+ BOOL has_perm_mask;
+ fp = fopen("linden_file.dat","r");
+
+ if(!fp)
+ {
+ llerrs << "file coudnt be opened\n" << llendl;
+ return;
+ }
+
+ llsaleinfo1.importFile(fp, has_perm_mask, perm_mask);
+ fclose(fp);
+
+ ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() &&
+ llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice());
+ }
+
+ template<> template<>
+ void llsaleinfo_test_t::test<3>()
+ {
+ S32 sale_price = 525452;
+ LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
+
+ std::ostringstream ostream;
+ llsaleinfo.exportLegacyStream(ostream);
+
+ std::istringstream istream(ostream.str());
+ LLSaleInfo llsaleinfo1;
+ U32 perm_mask = 0;
+ BOOL has_perm_mask = FALSE;
+ llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask);
+
+ ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() &&
+ llsaleinfo.getSaleType() == llsaleinfo1.getSaleType());
+ }
+
+ template<> template<>
+ void llsaleinfo_test_t::test<4>()
+ {
+// LLXMLNode is teh suck.
+#if 0
+ S32 sale_price = 23445;
+ LLSaleInfo saleinfo(LLSaleInfo::FS_CONTENTS, sale_price);
+
+ LLXMLNode* x_node = saleinfo.exportFileXML();
+
+ LLSaleInfo saleinfo1(LLSaleInfo::FS_NOT, 0);
+
+ saleinfo1.importXML(x_node);
+ ensure_equals("1.importXML() fn failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("2.importXML() fn failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
+#endif
+ }
+
+ template<> template<>
+ void llsaleinfo_test_t::test<5>()
+ {
+ S32 sale_price = 99000;
+ LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
+
+ LLSD sd_result = saleinfo.asLLSD();
+
+ U32 perm_mask = 0 ;
+ BOOL has_perm_mask = FALSE;
+
+ LLSaleInfo saleinfo1;
+ saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask);
+
+ ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
+ ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
+ }
+
+ //static EForSale lookup(const char* name) fn test
+ template<> template<>
+ void llsaleinfo_test_t::test<6>()
+ {
+ S32 sale_price = 233223;
+ LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig");
+
+ ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL);
+
+ LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
+ const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY);
+ ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result));
+ }
+
+ //void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test
+ template<> template<>
+ void llsaleinfo_test_t::test<7>()
+ {
+ S32 sale_price = 20;
+ LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
+ LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price);
+ saleinfo1.accumulate(saleinfo);
+ ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40);
+
+ }
+
+ // test cases of bool operator==(const LLSaleInfo &rhs) fn
+ // test case of bool operator!=(const LLSaleInfo &rhs) fn
+ template<> template<>
+ void llsaleinfo_test_t::test<8>()
+ {
+ S32 sale_price = 55000;
+ LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
+ LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price);
+ LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2);
+
+ ensure("operator == fn. failed", true == (saleinfo == saleinfoequal));
+ ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal));
+ }
+
+ template<> template<>
+ void llsaleinfo_test_t::test<9>()
+ {
+
+ //TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const
+ //TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block)
+ //TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num)
+ }
+
+}
diff --git a/indra/test/llsdmessagebuilder_tut.cpp b/indra/test/llsdmessagebuilder_tut.cpp
index b153292abc..900de1f2dd 100755
--- a/indra/test/llsdmessagebuilder_tut.cpp
+++ b/indra/test/llsdmessagebuilder_tut.cpp
@@ -114,7 +114,7 @@ namespace tut
void LLSDMessageBuilderTestObject::test<7>()
// F32
{
- F32 outValue, inValue = 121.44;
+ F32 outValue, inValue = 121.44f;
LLSDMessageBuilder builder = defaultBuilder();
builder.addF32("var", inValue);
LLSDMessageReader reader = setReader(builder);
diff --git a/indra/test/llsdmessagereader_tut.cpp b/indra/test/llsdmessagereader_tut.cpp
index 31810ae00e..60a4ea0f29 100755
--- a/indra/test/llsdmessagereader_tut.cpp
+++ b/indra/test/llsdmessagereader_tut.cpp
@@ -10,6 +10,7 @@
#include <tut/tut.h>
#include "lltut.h"
+#include "message.h"
#include "llsdmessagereader.h"
#include "llsdutil.h"
@@ -21,7 +22,7 @@ namespace tut
const std::string& expected_name)
{
LLSDMessageReader msg;
- msg.setMessage(msg_name, msg_data);
+ msg.setMessage(gMessageStringTable.getString(msg_name.c_str()), msg_data);
ensure_equals("Ensure name", std::string(msg.getMessageName()),
expected_name);
}
@@ -169,7 +170,7 @@ namespace tut
void LLSDMessageReaderTestObject::test<9>()
// F32
{
- F32 outValue, inValue = 121.44;
+ F32 outValue, inValue = 121.44f;
LLSDMessageReader msg = testType(inValue);
msg.getF32("block", "var", outValue);
ensure_equals("Ensure F32", outValue, inValue);
@@ -297,4 +298,3 @@ namespace tut
ensure_equals("Ensure Binary", outValue, inValue);
}
}
-
diff --git a/indra/test/llsdtraits.h b/indra/test/llsdtraits.h
index 2e6a96a425..955a5b2036 100644
--- a/indra/test/llsdtraits.h
+++ b/indra/test/llsdtraits.h
@@ -1,3 +1,11 @@
+/**
+ * @file llsdtraits.h
+ * @brief Unit test helpers
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
#ifndef LLSDTRAITS_H
#define LLSDTRAITS_H
diff --git a/indra/test/llsdutil_tut.cpp b/indra/test/llsdutil_tut.cpp
new file mode 100644
index 0000000000..db476840bf
--- /dev/null
+++ b/indra/test/llsdutil_tut.cpp
@@ -0,0 +1,132 @@
+/**
+ * @file llsdutil_tut.cpp
+ * @author Adroit
+ * @date 2007-02
+ * @brief LLSD conversion routines test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include "linden_common.h"
+#include "lltut.h"
+#include "v3color.h"
+#include "v4math.h"
+#include "m4math.h"
+#include "llsdutil.h"
+
+
+namespace tut
+{
+ struct llsdutil_data
+ {
+ };
+ typedef test_group<llsdutil_data> llsdutil_test;;
+ typedef llsdutil_test::object llsdutil_object;
+ tut::llsdutil_test tutil("llsdutil");
+
+ template<> template<>
+ void llsdutil_object::test<1>()
+ {
+ LLSD sd;
+ U64 valueIn , valueOut;
+ valueIn = U64L(0xFEDCBA9876543210);
+ sd = ll_sd_from_U64(valueIn);
+ valueOut = ll_U64_from_sd(sd);
+ ensure_equals("U64 valueIn->sd->valueOut", valueIn, valueOut);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<2>()
+ {
+ LLSD sd;
+ U32 valueIn, valueOut;
+ valueIn = 0x87654321;
+ sd = ll_sd_from_U32(valueIn);
+ valueOut = ll_U32_from_sd(sd);
+ ensure_equals("U32 valueIn->sd->valueOut", valueIn, valueOut);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<3>()
+ {
+ U32 valueIn, valueOut;
+ valueIn = 0x87654321;
+ LLSD sd;
+ sd = ll_sd_from_ipaddr(valueIn);
+ valueOut = ll_ipaddr_from_sd(sd);
+ ensure_equals("valueIn->sd->valueOut", valueIn, valueOut);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<4>()
+ {
+ LLSD sd;
+ LLVector3 vec1(-1.0, 2.0, -3.0);
+ sd = ll_sd_from_vector3(vec1);
+ LLVector3 vec2 = ll_vector3_from_sd(sd);
+ ensure_equals("vector3 -> sd -> vector3: 1", vec1, vec2);
+
+ LLVector3 vec3(sd);
+ ensure_equals("vector3 -> sd -> vector3: 2", vec1, vec3);
+
+ sd.clear();
+ vec1.setVec(0., 0., 0.);
+ sd = ll_sd_from_vector3(vec1);
+ vec2 = ll_vector3_from_sd(sd);
+ ensure_equals("vector3 -> sd -> vector3: 3", vec1, vec2);
+ sd.clear();
+ }
+
+ template<> template<>
+ void llsdutil_object::test<5>()
+ {
+ LLSD sd;
+ LLVector3d vec1((F64)(U64L(0xFEDCBA9876543210) << 2), -1., 0);
+ sd = ll_sd_from_vector3d(vec1);
+ LLVector3d vec2 = ll_vector3d_from_sd(sd);
+ ensure_equals("vector3d -> sd -> vector3d: 1", vec1, vec2);
+
+ LLVector3d vec3(sd);
+ ensure_equals("vector3d -> sd -> vector3d : 2", vec1, vec3);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<6>()
+ {
+ LLSD sd;
+ LLVector2 vec((F32) -3., (F32) 4.2);
+ sd = ll_sd_from_vector2(vec);
+ LLVector2 vec1 = ll_vector2_from_sd(sd);
+ ensure_equals("vector2 -> sd -> vector2", vec, vec1);
+
+ LLSD sd2 = ll_sd_from_vector2(vec1);
+ ensure_equals("sd -> vector2 -> sd: 2", sd, sd2);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<7>()
+ {
+ LLSD sd;
+ LLQuaternion quat((F32) 1., (F32) -0.98, (F32) 2.3, (F32) 0xffff);
+ sd = ll_sd_from_quaternion(quat);
+ LLQuaternion quat1 = ll_quaternion_from_sd(sd);
+ ensure_equals("LLQuaternion -> sd -> LLQuaternion", quat, quat1);
+
+ LLSD sd2 = ll_sd_from_quaternion(quat1);
+ ensure_equals("sd -> LLQuaternion -> sd ", sd, sd2);
+ }
+
+ template<> template<>
+ void llsdutil_object::test<8>()
+ {
+ LLSD sd;
+ LLColor4 c(1.0f, 2.2f, 4.0f, 7.f);
+ sd = ll_sd_from_color4(c);
+ LLColor4 c1 =ll_color4_from_sd(sd);
+ ensure_equals("LLColor4 -> sd -> LLColor4", c, c1);
+
+ LLSD sd1 = ll_sd_from_color4(c1);
+ ensure_equals("sd -> LLColor4 -> sd", sd, sd1);
+ }
+}
diff --git a/indra/test/llstreamtools_tut.cpp b/indra/test/llstreamtools_tut.cpp
new file mode 100644
index 0000000000..17e5c7cc2c
--- /dev/null
+++ b/indra/test/llstreamtools_tut.cpp
@@ -0,0 +1,908 @@
+/**
+ * @file llstreamtools_tut.cpp
+ * @author Adroit
+ * @date February 2007
+ * @brief llstreamtools test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include <fstream>
+#include "llstreamtools.h"
+#include "lltut.h"
+
+
+namespace tut
+{
+ struct streamtools_data
+ {
+ };
+ typedef test_group<streamtools_data> streamtools_test;
+ typedef streamtools_test::object streamtools_object;
+ tut::streamtools_test streamtools_testcase("streamtools");
+
+ //test cases for skip_whitespace()
+ template<> template<>
+ void streamtools_object::test<1>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+
+ is.str(str = "");
+ ensure("skip_whitespace: empty string", (false == skip_whitespace(is)));
+
+ is.clear();
+ is.str(str = " SecondLife is a 3D World");
+ skip_whitespace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World";
+ ensure_equals("skip_whitespace: space", arr, expected_result);
+
+ is.clear();
+ is.str(str = "\t \tSecondLife is a 3D World");
+ skip_whitespace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World";
+ ensure_equals("skip_whitespace: space and tabs", arr, expected_result);
+
+ is.clear();
+ is.str(str = "\t \tSecondLife is a 3D World ");
+ skip_whitespace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World ";
+ ensure_equals("skip_whitespace: space at end", arr, expected_result);
+
+ is.clear();
+ is.str(str = "\t \r\nSecondLife is a 3D World");
+ skip_whitespace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "\r\nSecondLife is a 3D World";
+ ensure_equals("skip_whitespace: space at end", arr, expected_result);
+ }
+
+ //testcases for skip_emptyspaces()
+ template<> template<>
+ void streamtools_object::test<2>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = " \tSecondLife is a 3D World.\n");
+ skip_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World.\n";
+ ensure_equals("skip_emptyspace: space and tabs", arr, expected_result);
+
+ is.clear();
+ is.str(str = " \t\r\n \r SecondLife is a 3D World.\n");
+ skip_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World.\n";
+ ensure_equals("skip_emptyspace: space, tabs, carriage return, newline", arr, expected_result);
+
+ is.clear();
+ is.str(str = "");
+ ret = skip_emptyspace(is);
+ is.get(arr, 255, '\0');
+ ensure("skip_emptyspace: empty string", ret == false);
+
+ is.clear();
+ is.str(str = " \r\n \t ");
+ ret = skip_emptyspace(is);
+ is.get(arr, 255, '\0');
+ ensure("skip_emptyspace: space newline empty", ret == false);
+ }
+
+ //testcases for skip_comments_and_emptyspace()
+ template<> template<>
+ void streamtools_object::test<3>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = " \t\r\n \r SecondLife is a 3D World.\n");
+ skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World.\n";
+ ensure_equals("skip_comments_and_emptyspace: space, tabs, carriage return, newline", arr, expected_result);
+
+ is.clear();
+ is.str(str = "# \r\n SecondLife is a 3D World.");
+ skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World.";
+ ensure_equals("skip_comments_and_emptyspace: skip comment - 1", arr, expected_result);
+
+ is.clear();
+ is.str(str = "# \r\n # SecondLife is a 3D World. ##");
+ skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "";
+ ensure_equals("skip_comments_and_emptyspace: skip comment - 2", arr, expected_result);
+
+ is.clear();
+ is.str(str = " \r\n SecondLife is a 3D World. ##");
+ skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ expected_result = "SecondLife is a 3D World. ##";
+ ensure_equals("skip_comments_and_emptyspace: skip comment - 3", arr, expected_result);
+
+ is.clear();
+ is.str(str = "");
+ ret = skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ ensure("skip_comments_and_emptyspace: empty string", ret == false);
+
+ is.clear();
+ is.str(str = " \r\n \t # SecondLife is a 3D World");
+ ret = skip_comments_and_emptyspace(is);
+ is.get(arr, 255, '\0');
+ ensure("skip_comments_and_emptyspace: space newline comment empty", ret == false);
+ }
+
+ //testcases for skip_line()
+ template<> template<>
+ void streamtools_object::test<4>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "SecondLife is a 3D World.\n\n It provides an opportunity to the site \nuser to perform real life activities in virtual world.");
+ skip_line(is);
+ is.get(arr, 255, '\0');
+ expected_result = "\n It provides an opportunity to the site \nuser to perform real life activities in virtual world.";
+ ensure_equals("skip_line: 1 newline", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ skip_line(is);
+ is.get(arr, 255, '\0');
+ expected_result = " It provides an opportunity to the site \nuser to perform real life activities in virtual world.";
+ ensure_equals("skip_line: 2 newline", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ skip_line(is);
+ is.get(arr, 255, '\0');
+ expected_result = "user to perform real life activities in virtual world.";
+ ensure_equals("skip_line: 3 newline", arr, expected_result);
+
+ is.clear();
+ is.str(str = "");
+ ret = skip_line(is);
+ ensure("skip_line: empty string", ret == false);
+ }
+
+
+ // testcases for skip_to_next_word()
+ template<> template<>
+ void streamtools_object::test<5>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "SecondLife is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world.");
+ skip_to_next_word(is); // get past SecondLife
+ is.get(arr, 255, '\0');
+ expected_result = "is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world.";
+ ensure_equals("skip_to_next_word: 1", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ skip_to_next_word(is); // get past is
+ skip_to_next_word(is); // get past a
+ skip_to_next_word(is); // get past 3D_World.\n\n
+ is.get(arr, 255, '\0');
+ expected_result = "It-provides an opportunity to the site \nuser to perform real life activities in virtual world.";
+ ensure_equals("skip_to_next_word: get past .\n\n 2", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ skip_to_next_word(is); // get past It-
+ expected_result = "provides an opportunity to the site \nuser to perform real life activities in virtual world.";
+ is.get(arr, 255, '\0');
+ ensure_equals("skip_to_next_word: get past -", arr, expected_result);
+
+ is.clear();
+ is.str(str = "");
+ ret = skip_to_next_word(is);
+ ensure("skip_line: empty string", ret == false);
+
+ is.clear();
+ is.str(str = " \r\n\r\n");
+ ret = skip_to_next_word(is);
+ ensure("skip_line: space new lines", ret == false);
+ }
+
+
+ //testcases for skip_to_end_of_next_keyword()
+ template<> template<>
+ void streamtools_object::test<6>()
+ {
+ char arr[255];
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "FIRSTKEY followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.");
+ ret = skip_to_end_of_next_keyword("FIRSTKEY", is);
+ is.get(arr, 255, '\0');
+ expected_result = " followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
+ ensure_equals("skip_to_end_of_next_keyword: 1", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ ret = skip_to_end_of_next_keyword("SECONDKEY", is);
+ is.get(arr, 255, '\0');
+ expected_result = "\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
+ ensure_equals("skip_to_end_of_next_keyword: 2", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ ret = skip_to_end_of_next_keyword("SECONDKEY", is);
+ is.get(arr, 255, '\0');
+ expected_result = "\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
+ ensure_equals("skip_to_end_of_next_keyword: 3", arr, expected_result);
+
+ is.clear();
+ is.str(expected_result);
+ ret = skip_to_end_of_next_keyword("FOURTHKEY", is);
+ is.get(arr, 255, '\0');
+ expected_result = " FOURTHVALUEis a 3DWorld.";
+ ensure_equals("skip_to_end_of_next_keyword: 4", arr, expected_result);
+
+ is.clear();
+ is.str(str = "{should be skipped as newline/space/tab does not follow but this one should be picked\n { Does it?\n");
+ ret = skip_to_end_of_next_keyword("{", is);
+ is.get(arr, 255, '\0');
+ expected_result = " Does it?\n";
+ ensure_equals("skip_to_end_of_next_keyword: multiple delim matches on same line", arr, expected_result);
+
+ is.clear();
+ is.str(str = "Delim { could not be found at start");
+ ret = skip_to_end_of_next_keyword("{", is);
+ ensure("skip_to_end_of_next_keyword: delim should not be present", ret == false);
+
+ is.clear();
+ is.str(str = "Empty Delim");
+ ret = skip_to_end_of_next_keyword("", is);
+ ensure("skip_to_end_of_next_keyword: empty delim should not be valid", ret == false);
+
+ is.clear();
+ is.str(str = "");
+ ret = skip_to_end_of_next_keyword("}", is);
+ ensure("skip_to_end_of_next_keyword: empty string", ret == false);
+ }
+
+ //testcases for get_word(std::string& output_string, std::istream& input_stream)
+ template<> template<>
+ void streamtools_object::test<7>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
+ actual_result = "";
+ ret = get_word(actual_result, is);
+ expected_result = "First";
+ ensure_equals("get_word: 1", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is);
+ expected_result = "Second";
+ ensure_equals("get_word: 2", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is);
+ expected_result = "Third";
+ ensure_equals("get_word: 3", actual_result, expected_result);
+
+ // the current implementation of get_word seems inconsistent with
+ // skip_to_next_word. skip_to_next_word treats any character other
+ // than alhpa-numeric and '_' as a delimter, while get_word()
+ // treats only isspace() (i.e. space, form-feed('\f'), newline ('\n'),
+ // carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v')
+ // as delimiters
+ actual_result = "";
+ ret = get_word(actual_result, is); // will copy Fourth-ShouldThisBePartOfFourth
+ expected_result = "Fourth-ShouldThisBePartOfFourth"; // as per current impl.
+ ensure_equals("get_word: 4", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is); // will copy Fifth
+ expected_result = "Fifth"; // as per current impl.
+ ensure_equals("get_word: 5", actual_result, expected_result);
+
+ is.clear();
+ is.str(str = " \t \r \n ");
+ actual_result = "";
+ ret = get_word(actual_result, is);
+ ensure("get_word: empty all spaces, newline tabs", ret == false);
+
+ is.clear();
+ is.str(str = "");
+ actual_result = "";
+ ret = get_word(actual_result, is);
+ ensure("get_word: empty string", ret == false);
+ }
+
+ // testcase for get_word and skip_to_next_word compatibility
+ template<> template<>
+ void streamtools_object::test<8>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
+ actual_result = "";
+ ret = get_word(actual_result, is); // First
+ actual_result = "";
+ ret = get_word(actual_result, is); // Second
+ actual_result = "";
+ ret = get_word(actual_result, is); // Third
+
+ // the current implementation of get_word seems inconsistent with
+ // skip_to_next_word. skip_to_next_word treats any character other
+ // than alhpa-numeric and '_' as a delimter, while get_word()
+ // treats only isspace() (i.e. space, form-feed('\f'), newline ('\n'),
+ // carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v')
+ // as delimiters
+ actual_result = "";
+ ret = get_word(actual_result, is); // will copy Fourth-ShouldThisBePartOfFourth
+
+ actual_result = "";
+ ret = get_word(actual_result, is); // will copy Fifth
+
+ is.clear();
+ is.str(str = " First Second \t \r \n Third Fourth_ShouldThisBePartOfFourth Fifth\n");
+ ret = skip_to_next_word(is); // should now point to First
+ ret = skip_to_next_word(is); // should now point to Second
+ ret = skip_to_next_word(is); // should now point to Third
+ ret = skip_to_next_word(is); // should now point to Fourth
+ ret = skip_to_next_word(is); // should now point to ShouldThisBePartOfFourth
+ expected_result = "";
+ // will copy ShouldThisBePartOfFourth, the fifth word,
+ // while using get_word above five times result in getting "Fifth"
+ ret = get_word(expected_result, is);
+ ensure_equals("get_word: skip_to_next_word compatibility", actual_result, expected_result);
+ }
+
+ //testcases for get_word(std::string& output_string, std::istream& input_stream, int n)
+ template<> template<>
+ void streamtools_object::test<9>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
+ actual_result = "";
+ ret = get_word(actual_result, is, 255);
+ expected_result = "First";
+ ensure_equals("get_word: 1", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is, 4);
+ expected_result = "Seco"; // should be cut short
+ ensure_equals("get_word: 2", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is, 255);
+ expected_result = "nd"; // get remainder of Second
+ ensure_equals("get_word: 3", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is, 0); // 0 size string
+ expected_result = ""; // get remainder of Second
+ ensure_equals("get_word: 0 sized output", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_word(actual_result, is, 255);
+ expected_result = "Third";
+ ensure_equals("get_word: 4", actual_result, expected_result);
+
+ is.clear();
+ is.str(str = " \t \r \n ");
+ actual_result = "";
+ ret = get_word(actual_result, is, 255);
+ ensure("get_word: empty all spaces, newline tabs", ret == false);
+
+ is.clear();
+ is.str(str = "");
+ actual_result = "";
+ ret = get_word(actual_result, is, 255);
+ ensure("get_word: empty string", ret == false);
+ }
+
+ //test cases for get_line(std::string& output_string, std::istream& input_stream)
+ template<> template<>
+ void streamtools_object::test<10>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "First Second \t \r\n Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n");
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "First Second \t \n";
+ ensure_equals("get_line: 1", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = " Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n";
+ ensure_equals("get_line: 2", actual_result, expected_result);
+
+ is.clear();
+ is.str(str = "\nFirst Line.\n\nSecond Line.\n");
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "\n";
+ ensure_equals("get_line: First char as newline", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "First Line.\n";
+ ensure_equals("get_line: 3", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "\n";
+ ensure_equals("get_line: 4", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "Second Line.\n";
+ ensure_equals("get_line: 5", actual_result, expected_result);
+ }
+
+ //test cases for get_line(std::string& output_string, std::istream& input_stream)
+ template<> template<>
+ void streamtools_object::test<11>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "One Line only with no newline");
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "One Line only with no newline";
+ ensure_equals("get_line: No newline", actual_result, expected_result);
+ ensure_equals("return value is good state of stream", ret, is.good());
+ }
+
+ //test cases for get_line(std::string& output_string, std::istream& input_stream)
+ template<> template<>
+ void streamtools_object::test<12>()
+ {
+ skip_fail("get_line() incorrectly handles lone carriage return.");
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ // need to be check if this test case is wrong or the implementation is wrong.
+ is.clear();
+ is.str(str = "Should not skip \r unless they are followed with newline .\r\n");
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "Should not skip \r unless they are followed with newline .\n";
+ ensure_equals("get_line: carriage return skipped even though not followed by newline", actual_result, expected_result);
+ }
+
+ //test cases for get_line(std::string& output_string, std::istream& input_stream)
+ template<> template<>
+ void streamtools_object::test<13>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "\n");
+ actual_result = "";
+ ret = get_line(actual_result, is);
+ expected_result = "\n";
+ ensure_equals("get_line: Just newline", actual_result, expected_result);
+ }
+
+
+ //testcases for get_line(std::string& output_string, std::istream& input_stream, int n)
+ template<> template<>
+ void streamtools_object::test<14>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "First Line.\nSecond Line.\n");
+ actual_result = "";
+ ret = get_line(actual_result, is, 255);
+ expected_result = "First Line.\n";
+ ensure_equals("get_line: Basic Operation", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is, sizeof("Second")-1);
+ expected_result = "Second\n";
+ ensure_equals("get_line: Insufficient length 1", actual_result, expected_result);
+
+ actual_result = "";
+ ret = get_line(actual_result, is, 255);
+ expected_result = " Line.\n";
+ ensure_equals("get_line: Remainder after earlier insufficient length", actual_result, expected_result);
+
+ is.clear();
+ is.str(str = "One Line only with no newline with limited length");
+ actual_result = "";
+ ret = get_line(actual_result, is, sizeof("One Line only with no newline with limited length")-1);
+ expected_result = "One Line only with no newline with limited length\n";
+ ensure_equals("get_line: No newline with limited length", actual_result, expected_result);
+
+ is.clear();
+ is.str(str = "One Line only with no newline");
+ actual_result = "";
+ ret = get_line(actual_result, is, 255);
+ expected_result = "One Line only with no newline";
+ ensure_equals("get_line: No newline", actual_result, expected_result);
+ }
+
+ //testcases for get_line(std::string& output_string, std::istream& input_stream, int n)
+ template<> template<>
+ void streamtools_object::test<15>()
+ {
+ std::string str;
+ std::string expected_result;
+ std::string actual_result;
+ std::istringstream is;
+ bool ret;
+
+ is.clear();
+ is.str(str = "One Line only with no newline");
+ actual_result = "";
+ ret = get_line(actual_result, is, 255);
+ expected_result = "One Line only with no newline";
+ ensure_equals("get_line: No newline", actual_result, expected_result);
+ ensure_equals("return value is good state of stream", ret, is.good());
+ }
+
+ //testcases for remove_last_char()
+ template<> template<>
+ void streamtools_object::test<16>()
+ {
+ std::string str;
+ std::string expected_result;
+ bool ret;
+
+ str = "SecondLife is a 3D World";
+
+ ret = remove_last_char('d',str);
+ expected_result = "SecondLife is a 3D Worl";
+ ensure_equals("remove_last_char: should remove last char", str, expected_result);
+
+ str = "SecondLife is a 3D World";
+ ret = remove_last_char('W',str);
+ expected_result = "SecondLife is a 3D World";
+ ensure_equals("remove_last_char: should not remove as it is not last char", str, expected_result);
+ ensure("remove_last_char: should return false", ret == false);
+
+ str = "SecondLife is a 3D World\n";
+ ret = remove_last_char('\n',str);
+ expected_result = "SecondLife is a 3D World";
+ ensure_equals("remove_last_char: should remove last newline", str, expected_result);
+ ensure("remove_last_char: should remove newline and return true", ret == true);
+ }
+
+
+ //testcases for unescaped_string()
+ template<> template<>
+ void streamtools_object::test<17>()
+ {
+ std::string str;
+ std::string expected_result;
+
+ str = "SecondLife is a 3D world \\n";
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \n";
+ ensure_equals("unescape_string: newline", str, expected_result);
+
+ str = "SecondLife is a 3D world \\\\t \\n";
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \\t \n";
+ ensure_equals("unescape_string: backslash and newline", str, expected_result);
+
+ str = "SecondLife is a 3D world \\ ";
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \\ ";
+ ensure_equals("unescape_string: insufficient to unescape", str, expected_result);
+
+ str = "SecondLife is a 3D world \\n \\n \\n \\\\\\n";
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \n \n \n \\\n";
+ ensure_equals("unescape_string: multipel newline and backslash", str, expected_result);
+
+ str = "SecondLife is a 3D world \\t";
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \\t";
+ ensure_equals("unescape_string: leaves tab as is", str, expected_result);
+
+ str = "\\n";
+ unescape_string(str);
+ expected_result = "\n";
+ ensure_equals("unescape_string: only a newline", str, expected_result);
+ }
+
+ //testcases for escape_string()
+ template<> template<>
+ void streamtools_object::test<18>()
+ {
+ std::string str;
+ std::string expected_result;
+
+ str = "SecondLife is a 3D world \n";
+ escape_string(str);
+ expected_result = "SecondLife is a 3D world \\n";
+ ensure_equals("escape_string: newline", str, expected_result);
+
+ str = "SecondLife is a 3D world \\t \n";
+ escape_string(str);
+ expected_result = "SecondLife is a 3D world \\\\t \\n";
+ ensure_equals("escape_string: backslash and newline", str, expected_result);
+
+ str = "SecondLife is a 3D world \n \n \n \\\n";
+ escape_string(str);
+ expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\\\n";
+ ensure_equals("escape_string: multipel newline and backslash", str, expected_result);
+
+ str = "SecondLife is a 3D world \t";
+ escape_string(str);
+ expected_result = "SecondLife is a 3D world \t";
+ ensure_equals("unescape_string: leaves tab as is", str, expected_result);
+
+ str = "\n";
+ escape_string(str);
+ expected_result = "\\n";
+ ensure_equals("unescape_string: only a newline", str, expected_result);
+
+ // serialization/deserialization escape->unescape
+ str = "SecondLife is a 3D world \n \n \n \\\n";
+ escape_string(str);
+ unescape_string(str);
+ expected_result = "SecondLife is a 3D world \n \n \n \\\n";
+ ensure_equals("escape_string: should preserve with escape/unescape", str, expected_result);
+
+ // serialization/deserialization unescape->escape
+ str = "SecondLife is a 3D world \\n \\n \\n \\\\";
+ unescape_string(str);
+ escape_string(str);
+ expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\";
+ ensure_equals("escape_string: should preserve with unescape/escape", str, expected_result);
+ }
+
+ // testcases for replace_newlines_with_whitespace()
+ template<> template<>
+ void streamtools_object::test<19>()
+ {
+ std::string str;
+ std::string expected_result;
+
+ str = "SecondLife is a 3D \n\nworld\n";
+ replace_newlines_with_whitespace(str);
+ expected_result = "SecondLife is a 3D world ";
+ ensure_equals("replace_newlines_with_whitespace: replace all newline", str, expected_result);
+
+ str = "\nSecondLife is a 3D world\n";
+ replace_newlines_with_whitespace(str);
+ expected_result = " SecondLife is a 3D world ";
+ ensure_equals("replace_newlines_with_whitespace: begin and newline", str, expected_result);
+
+ str = "SecondLife is a 3D world\r\t";
+ replace_newlines_with_whitespace(str);
+ expected_result = "SecondLife is a 3D world\r\t";
+ ensure_equals("replace_newlines_with_whitespace: should only replace newline", str, expected_result);
+
+ str = "";
+ replace_newlines_with_whitespace(str);
+ expected_result = "";
+ ensure_equals("replace_newlines_with_whitespace: empty string", str, expected_result);
+ }
+
+ //testcases for remove_double_quotes()
+ template<> template<>
+ void streamtools_object::test<20>()
+ {
+ std::string str;
+ std::string expected_result;
+
+ str = "SecondLife is a \"\"3D world";
+ remove_double_quotes(str);
+ expected_result = "SecondLife is a 3D world";
+ ensure_equals("remove_double_quotes: replace empty doube quotes", str, expected_result);
+
+ str = "SecondLife is a \"3D world";
+ remove_double_quotes(str);
+ expected_result = "SecondLife is a 3D world";
+ ensure_equals("remove_double_quotes: keep as is it matching quote not found", str, expected_result);
+ }
+
+ // testcases for get_brace_count()
+ template<> template<>
+ void streamtools_object::test<21>()
+ {
+ skip_fail("get_brace_count() has bugs.");
+
+ std::string str;
+ std::string expected_result;
+ int count;
+
+ str = " { ";
+ count = get_brace_count(str);
+ ensure("get_brace_count: 1 for {", count == 1);
+
+ str = "\t}\t\t \n";
+ count = get_brace_count(str);
+ ensure("get_brace_count: 1 for {", count == -1);
+
+ str = "\t\t\t \n";
+ count = get_brace_count(str);
+ ensure("get_brace_count: 0 for no braces", count == 0);
+
+ str = "{ Remaining line not empty\n";
+ count = get_brace_count(str);
+ ensure("get_brace_count: 0 for remainign line not empty", count == 0);
+
+ /* shouldn't this return 1? */
+ str = "{ /*Remaining line in comment*/\n";
+ count = get_brace_count(str);
+ ensure("get_brace_count: 1 for { with remaining line in comment", count == 1);
+
+ /* shouldn't this return -1? */
+ str = " } //Remaining line in comment \n";
+ count = get_brace_count(str);
+ ensure("get_brace_count: -1 for } with remaining line in comment", count == -1);
+ }
+
+ //testcases for get_keyword_and_value()
+ template<> template<>
+ void streamtools_object::test<22>()
+ {
+ std::string s = "SecondLife is a 3D World";
+ std::string keyword;
+ std::string value;
+ get_keyword_and_value(keyword, value, s);
+ ensure("get_keyword_and_value: Unable to get Keyword and Value", ((keyword == "SecondLife") && (value == "is a 3D World")));
+
+ s = "SecondLife";
+ get_keyword_and_value(keyword, value, s);
+ ensure("get_keyword_and_value: value should be empty", ((keyword == "SecondLife") && (value == "")));
+
+ s = "SecondLife \t is cool! \n";
+ get_keyword_and_value(keyword, value, s);
+ ensure("get_keyword_and_value: remove space before value but not after", ((keyword == "SecondLife") && (value == "is cool! ")));
+ }
+
+ //testcases for get_keyword_and_value()
+ template<> template<>
+ void streamtools_object::test<23>()
+ {
+ skip_fail("get_keyword_and_value() has bugs.");
+
+ std::string s;
+ std::string keyword = "SOME PRIOR KEYWORD";
+ std::string value = "SOME PRIOR VALUE";
+
+ s = "SecondLife\n";
+ get_keyword_and_value(keyword, value, s);
+ ensure("get_keyword_and_value: terminated with newline. value should be empty", ((keyword == "SecondLife") && (value == "")));
+ }
+
+ //testcases for get_keyword_and_value()
+ template<> template<>
+ void streamtools_object::test<24>()
+ {
+ skip_fail("get_keyword_and_value() has bugs.");
+
+ std::string s;
+ std::string keyword = "SOME PRIOR KEYWORD";
+ std::string value = "SOME PRIOR VALUE";
+
+ s = "";
+ get_keyword_and_value(keyword, value, s);
+ ensure("get_keyword_and_value: empty string. keyword value should empty", ((keyword == "") && (value == "")));
+ }
+
+ //testcase for fullread()
+ template<> template<>
+ void streamtools_object::test<25>()
+ {
+ std::string str = "First Line.\nSecond Line\n";
+ std::istringstream is(str);
+ char buf[255] = {0};
+
+ fullread(is, buf, 255);
+ ensure_memory_matches("fullread: read with newlines", (void*) buf, str.size()-1, (void*) str.c_str(), str.size()-1);
+
+ is.clear();
+ is.str(str = "First Line.\nSecond Line\n");
+ memset(buf, 0, 255);
+
+ char expected_string[] = "First Line.\nSecond";
+ int len = sizeof(expected_string)-1;
+ fullread(is, buf, len);
+ ensure_memory_matches("fullread: read with newlines", (void*) buf, len, (void*) &expected_string, len);
+ }
+
+
+// testcases for operator >>
+
+ template<> template<>
+ void streamtools_object::test<26>()
+ {
+ char arr[255];
+ std::string str;
+ std::string toCheck = "SecondLife" ;
+ std::string expected_result;
+ std::istringstream stream("SecondLife is a 3D World");
+ stream >> toCheck.c_str();
+ stream.get(arr, 255, '\0');
+ expected_result = " is a 3D World";
+ ensure_equals("istream << operator", arr, expected_result);
+
+ stream.clear();
+ stream.str(str = "SecondLife is a 3D World");
+ toCheck = "is";
+ stream >> toCheck.c_str();
+ ensure("istream << operator should have failed", stream.good() == false);
+ }
+}
diff --git a/indra/test/lltemplatemessagebuilder_tut.cpp b/indra/test/lltemplatemessagebuilder_tut.cpp
new file mode 100644
index 0000000000..67ca9320ba
--- /dev/null
+++ b/indra/test/lltemplatemessagebuilder_tut.cpp
@@ -0,0 +1,944 @@
+/**
+ * @file lltemplatemessagebuilder_tut.cpp
+ * @date 2007-04
+ * @brief Tests for building messages.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+
+#include "llapr.h"
+#include "llmessagetemplate.h"
+#include "llquaternion.h"
+#include "lltemplatemessagebuilder.h"
+#include "lltemplatemessagereader.h"
+#include "llversion.h"
+#include "message_prehash.h"
+#include "u64.h"
+#include "v3dmath.h"
+#include "v3math.h"
+#include "v4math.h"
+
+namespace tut
+{
+ static LLTemplateMessageBuilder::message_template_name_map_t nameMap;
+ static LLTemplateMessageReader::message_template_number_map_t numberMap;
+
+ struct LLTemplateMessageBuilderTestData
+ {
+ static LLMessageTemplate defaultTemplate()
+ {
+ static bool init = false;
+ if(! init)
+ {
+ ll_init_apr();
+ start_messaging_system("notafile", 13035,
+ LL_VERSION_MAJOR,
+ LL_VERSION_MINOR,
+ LL_VERSION_PATCH,
+ FALSE,
+ "notasharedsecret");
+ init_prehash_data();
+ init = true;
+ }
+ return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH);
+ }
+
+ static LLMessageBlock* defaultBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE)
+ {
+ return createBlock(_PREHASH_Test0, type, size, block);
+ }
+
+ static LLMessageBlock* createBlock(char* name, const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE)
+ {
+ LLMessageBlock* result = new LLMessageBlock(name, block);
+ if(type != MVT_NULL)
+ {
+ result->addVariable(_PREHASH_Test0, type, size);
+ }
+ return result;
+ }
+
+ static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = _PREHASH_Test0)
+ {
+ nameMap[_PREHASH_TestMessage] = &messageTemplate;
+ LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(nameMap);
+ builder->newMessage(_PREHASH_TestMessage);
+ builder->nextBlock(name);
+ return builder;
+ }
+
+ /** Takes ownership of builder */
+ static LLTemplateMessageReader* setReader(
+ LLMessageTemplate& messageTemplate,
+ LLTemplateMessageBuilder* builder,
+ U8 offset = 0)
+ {
+ numberMap[1] = &messageTemplate;
+ const U32 bufferSize = 1024;
+ U8 buffer[bufferSize];
+ // zero out the packet ID field
+ memset(buffer, 0, LL_PACKET_ID_SIZE);
+ U32 builtSize = builder->buildMessage(buffer, bufferSize, offset);
+ delete builder;
+ LLTemplateMessageReader* reader = new LLTemplateMessageReader(numberMap);
+ reader->validateMessage(buffer, builtSize, LLHost());
+ reader->readMessage(buffer, LLHost());
+ return reader;
+ }
+
+ };
+
+ typedef test_group<LLTemplateMessageBuilderTestData> LLTemplateMessageBuilderTestGroup;
+ typedef LLTemplateMessageBuilderTestGroup::object LLTemplateMessageBuilderTestObject;
+ LLTemplateMessageBuilderTestGroup templateMessageBuilderTestGroup("LLTemplateMessageBuilder");
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<1>()
+ // construction and test of undefined
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock());
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<2>()
+ // BOOL
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1));
+ BOOL outValue, inValue = TRUE;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addBOOL(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure BOOL", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<3>()
+ // U8
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U8, 1));
+ U8 outValue, inValue = 2;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU8(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U8", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<4>()
+ // S16
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_S16, 2));
+ S16 outValue, inValue = 90;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addS16(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure S16", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<5>()
+ // U16
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U16, 2));
+ U16 outValue, inValue = 3;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU16(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U16", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<6>()
+ // S32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_S32, 4));
+ S32 outValue, inValue = 44;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addS32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure S32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<7>()
+ // F32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_F32, 4));
+ F32 outValue, inValue = 121.44f;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addF32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure F32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<8>()
+ // U32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U32, 4));
+ U32 outValue, inValue = 88;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<9>()
+ // U64
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U64, 8));
+ U64 outValue, inValue = 121;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU64(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U64", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<10>()
+ // F64
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_F64, 8));
+ F64 outValue, inValue = 3232143.33;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addF64(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure F64", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<11>()
+ // Vector3
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12));
+ LLVector3 outValue, inValue = LLVector3(1,2,3);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector3(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector3", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<12>()
+ // Vector4
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16));
+ LLVector4 outValue, inValue = LLVector4(1,2,3,4);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector4(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector4", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<13>()
+ // Vector3d
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24));
+ LLVector3d outValue, inValue = LLVector3d(1,2,3);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector3d(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector3d", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<14>()
+ // Quaternion
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12));
+ LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addQuat(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLQuaternion", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<15>()
+ // UUID
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16));
+ LLUUID outValue, inValue;
+ inValue.generate();
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addUUID(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure UUID", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<16>()
+ // IPAddr
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4));
+ U32 outValue, inValue = 12344556;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addIPAddr(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure IPAddr", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<17>()
+ // IPPort
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2));
+ U16 outValue, inValue = 80;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addIPPort(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure IPPort", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<18>()
+ // String
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1));
+ std::string outValue, inValue = "testing";
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addString(_PREHASH_Test0, inValue.c_str());
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ char buffer[MAX_STRING];
+ reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer);
+ outValue = buffer;
+ ensure_equals("Ensure String", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<19>()
+ // block name !-> binary order
+ {
+ U8 buffer1[MAX_BUFFER_SIZE];
+ memset(buffer1, 0, MAX_BUFFER_SIZE);
+ U8 buffer2[MAX_BUFFER_SIZE];
+ memset(buffer2, 0, MAX_BUFFER_SIZE);
+ U32 bufferSize1, bufferSize2;
+
+ // build template: Test0 before Test1
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));
+
+ // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ builder->nextBlock(_PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, 0xbbbb);
+ bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ // build template: Test1 before Test0
+ messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+
+ // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
+ builder = defaultBuilder(messageTemplate, _PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ builder->nextBlock(_PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xbbbb);
+ bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2);
+ ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0);
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<20>()
+ // block build order !-> binary order
+ {
+ U8 buffer1[MAX_BUFFER_SIZE];
+ memset(buffer1, 0, MAX_BUFFER_SIZE);
+ U8 buffer2[MAX_BUFFER_SIZE];
+ memset(buffer2, 0, MAX_BUFFER_SIZE);
+ U32 bufferSize1, bufferSize2;
+
+ // build template: Test0 before Test1
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));
+
+ // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ builder->nextBlock(_PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, 0xbbbb);
+ bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
+ builder = defaultBuilder(messageTemplate, _PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, 0xbbbb);
+ builder->nextBlock(_PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2);
+ ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0);
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<21>()
+ // block appended in declaration -> data appended in binary
+ {
+ U8 buffer1[MAX_BUFFER_SIZE];
+ memset(buffer1, 0, MAX_BUFFER_SIZE);
+ U8 buffer2[MAX_BUFFER_SIZE];
+ memset(buffer2, 0, MAX_BUFFER_SIZE);
+ U32 bufferSize1, bufferSize2;
+
+ // Build template: Test0 only
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+
+ // Build message
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ // Build template: Test0 before Test1
+ messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));
+
+ // Build message
+ builder = defaultBuilder(messageTemplate, _PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, 0xaaaa);
+ builder->nextBlock(_PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, 0xbbbb);
+ bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0);
+ delete builder;
+
+ ensure_not_equals("Ensure Buffer Sizes Not Equal", bufferSize1, bufferSize2);
+ ensure_equals("Ensure Buffer Prefix Equal", memcmp(buffer1, buffer2, bufferSize1), 0);
+ ensure_not_equals("Ensure Buffer Contents Not Equal", memcmp(buffer1, buffer2, bufferSize2), 0);
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<22>()
+ // repeated penultimate block (crashes when data in LLDynamicArrayIndexed)
+ {
+ U32 inTest00 = 0, inTest01 = 1, inTest1 = 2;
+ U32 outTest00, outTest01, outTest1;
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4));
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inTest00);
+ builder->nextBlock(_PREHASH_Test0);
+ builder->addU32(_PREHASH_Test0, inTest01);
+ builder->nextBlock(_PREHASH_Test1);
+ builder->addU32(_PREHASH_Test0, inTest1);
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest00, 0);
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest01, 1);
+ reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outTest1);
+ ensure_equals("Ensure Test0[0]", inTest00, outTest00);
+ ensure_equals("Ensure Test0[1]", inTest01, outTest01);
+ ensure_equals("Ensure Test1", inTest1, outTest1);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<23>()
+ // variable repeated block name never accessed
+ {
+ U32 inTest = 1, outTest;
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(
+ createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE));
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4));
+
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inTest);
+
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest);
+ S32 blockCount = reader->getNumberOfBlocks(_PREHASH_Test1);
+ ensure_equals("Ensure block count", blockCount, 0);
+ ensure_equals("Ensure Test0", inTest, outTest);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<24>()
+ // forwarding message
+ {
+ // build template
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4));
+
+ // build message
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, 42);
+
+ // read message
+ LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
+
+ // forward message
+ builder = defaultBuilder(messageTemplate);
+ builder->newMessage(_PREHASH_TestMessage);
+ reader->copyToBuilder(*builder);
+ U8 buffer[MAX_BUFFER_SIZE];
+ builder->buildMessage(buffer, MAX_BUFFER_SIZE, 0);
+
+ delete builder;
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<25>()
+ // non-zero offset with undefined
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock());
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 10);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<26>()
+ // non-zero offset with BOOL
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1));
+ BOOL outValue, inValue = TRUE;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addBOOL(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 1);
+ reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure BOOL", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<27>()
+ // non-zero offset with U8
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U8, 1));
+ U8 outValue, inValue = 2;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU8(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 255);
+ reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U8", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<28>()
+ // non-zero offset with S16
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_S16, 2));
+ S16 outValue, inValue = 90;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addS16(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 2);
+ reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure S16", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<29>()
+ // non-zero offset with U16
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U16, 2));
+ U16 outValue, inValue = 3;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU16(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 4);
+ reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U16", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<30>()
+ // non-zero offset with S32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_S32, 4));
+ S32 outValue, inValue = 44;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addS32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 4);
+ reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure S32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<31>()
+ // non-zero offset with F32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_F32, 4));
+ F32 outValue, inValue = 121.44f;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addF32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 16);
+ reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure F32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<32>()
+ // non-zero offset with U32
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U32, 4));
+ U32 outValue, inValue = 88;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 127);
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U32", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<33>()
+ // non-zero offset with U64
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U64, 8));
+ U64 outValue, inValue = 121;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU64(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 32);
+ reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure U64", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<34>()
+ // non-zero offset with F64
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_F64, 8));
+ F64 outValue, inValue = 3232143.33;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addF64(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 128);
+ reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure F64", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<35>()
+ // non-zero offset with Vector3
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12));
+ LLVector3 outValue, inValue = LLVector3(1,2,3);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector3(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 63);
+ reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector3", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<36>()
+ // non-zero offset with Vector4
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16));
+ LLVector4 outValue, inValue = LLVector4(1,2,3,4);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector4(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 64);
+ reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector4", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<37>()
+ // non-zero offset with Vector3d
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24));
+ LLVector3d outValue, inValue = LLVector3d(1,2,3);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addVector3d(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 64);
+ reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLVector3d", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<38>()
+ // non-zero offset with Quaternion
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12));
+ LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0);
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addQuat(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 12);
+ reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure LLQuaternion", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<39>()
+ // non-zero offset with UUID
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16));
+ LLUUID outValue, inValue;
+ inValue.generate();
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addUUID(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 31);
+ reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure UUID", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<40>()
+ // non-zero offset with IPAddr
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4));
+ U32 outValue, inValue = 12344556;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addIPAddr(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 32);
+ reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure IPAddr", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<41>()
+ // non-zero offset with IPPort
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2));
+ U16 outValue, inValue = 80;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addIPPort(_PREHASH_Test0, inValue);
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 6);
+ reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ ensure_equals("Ensure IPPort", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<42>()
+ // non-zero offset with String
+ {
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1));
+ std::string outValue, inValue = "testing";
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addString(_PREHASH_Test0, inValue.c_str());
+ LLTemplateMessageReader* reader = setReader(
+ messageTemplate, builder, 255);
+ char buffer[MAX_STRING];
+ reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer);
+ outValue = buffer;
+ ensure_equals("Ensure String", inValue, outValue);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<43>()
+ // read past end of message -> default values (forward compatibility)
+ {
+ // build message with single block
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
+ U32 outValue, outValue2, inValue = 0xbbbbbbbb;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inValue);
+ const U32 bufferSize = 1024;
+ U8 buffer[bufferSize];
+ memset(buffer, 0xaa, bufferSize);
+ memset(buffer, 0, LL_PACKET_ID_SIZE);
+ U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
+ delete builder;
+
+ // add block to reader template
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));
+
+ // read message value and default value
+ numberMap[1] = &messageTemplate;
+ LLTemplateMessageReader* reader =
+ new LLTemplateMessageReader(numberMap);
+ reader->validateMessage(buffer, builtSize, LLHost());
+ reader->readMessage(buffer, LLHost());
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outValue2);
+ ensure_equals("Ensure present value ", outValue, inValue);
+ ensure_equals("Ensure default value ", outValue2, 0);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<44>()
+ // read variable block past end of message -> 0 repeats
+ {
+ // build message with single block
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
+ U32 outValue, outValue2, inValue = 0xbbbbbbbb;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inValue);
+ const U32 bufferSize = 1024;
+ U8 buffer[bufferSize];
+ memset(buffer, 0xaa, bufferSize);
+ memset(buffer, 0, LL_PACKET_ID_SIZE);
+ U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
+ delete builder;
+
+ // add variable block to reader template
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4));
+
+ // read message value and check block repeat count
+ numberMap[1] = &messageTemplate;
+ LLTemplateMessageReader* reader =
+ new LLTemplateMessageReader(numberMap);
+ reader->validateMessage(buffer, builtSize, LLHost());
+ reader->readMessage(buffer, LLHost());
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1);
+ ensure_equals("Ensure present value ", outValue, inValue);
+ ensure_equals("Ensure 0 repeats ", outValue2, 0);
+ delete reader;
+ }
+
+ template<> template<>
+ void LLTemplateMessageBuilderTestObject::test<45>()
+ // read variable length data past end of message -> 0 length
+ {
+ // build message with single block
+ LLMessageTemplate messageTemplate = defaultTemplate();
+ messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
+ U32 outValue, outValue2, inValue = 0xbbbbbbbb;
+ LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
+ builder->addU32(_PREHASH_Test0, inValue);
+ const U32 bufferSize = 1024;
+ U8 buffer[bufferSize];
+ memset(buffer, 0xaa, bufferSize);
+ memset(buffer, 0, LL_PACKET_ID_SIZE);
+ U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
+ delete builder;
+
+ // add variable block to reader template
+ messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_VARIABLE, 4,
+ MBT_SINGLE));
+
+ // read message value and default string
+ numberMap[1] = &messageTemplate;
+ LLTemplateMessageReader* reader =
+ new LLTemplateMessageReader(numberMap);
+ reader->validateMessage(buffer, builtSize, LLHost());
+ reader->readMessage(buffer, LLHost());
+ reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
+ char outBuffer[bufferSize];
+ memset(buffer, 0xcc, bufferSize);
+ reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize,
+ outBuffer);
+ outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1);
+ ensure_equals("Ensure present value ", outValue, inValue);
+ ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0);
+ delete reader;
+ }
+}
+
diff --git a/indra/test/lltut.h b/indra/test/lltut.h
index 6f1fee2b2f..58de355453 100644
--- a/indra/test/lltut.h
+++ b/indra/test/lltut.h
@@ -8,12 +8,6 @@
* $License$
*/
-/**
- *
- * THOROUGH_DESCRIPTION
- *
- */
-
#ifndef LL_LLTUT_H
#define LL_LLTUT_H
diff --git a/indra/test/lluuidhashmap_tut.cpp b/indra/test/lluuidhashmap_tut.cpp
new file mode 100644
index 0000000000..c9736d4d4b
--- /dev/null
+++ b/indra/test/lluuidhashmap_tut.cpp
@@ -0,0 +1,339 @@
+/**
+ * @file lluuidhashmap_tut.cpp
+ * @author Adroit
+ * @date 2007-02
+ * @brief Test cases for LLUUIDHashMap
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "linden_common.h"
+#include "lluuidhashmap.h"
+#include "llsdserialize.h"
+
+namespace tut
+{
+ class UUIDTableEntry
+ {
+ public:
+ UUIDTableEntry()
+ {
+ mID.setNull();
+ mValue = 0;
+ }
+
+ UUIDTableEntry(const LLUUID& id, U32 value)
+ {
+ mID = id;
+ mValue = value;
+ }
+
+ ~UUIDTableEntry(){};
+
+ static BOOL uuidEq(const LLUUID &uuid, const UUIDTableEntry &id_pair)
+ {
+ if (uuid == id_pair.mID)
+ {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ const LLUUID& getID() { return mID; }
+ const U32& getValue() { return mValue; }
+
+ protected:
+ LLUUID mID;
+ U32 mValue;
+ };
+
+ struct hashmap_test
+ {
+ };
+
+ typedef test_group<hashmap_test> hash_index_t;
+ typedef hash_index_t::object hash_index_object_t;
+ tut::hash_index_t tut_hash_index("hashmap_test");
+
+ // stress test
+ template<> template<>
+ void hash_index_object_t::test<1>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 32> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ const int numElementsToCheck = 32*256*32;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ UUIDTableEntry entryToCheck = hashTable.get(idToCheck);
+ ensure("set/get did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i);
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ if (i % 2 != 0)
+ {
+ hashTable.remove(idToCheck);
+ }
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ ensure("remove or check did not work", (i % 2 == 0 && hashTable.check(idToCheck)) || (i % 2 != 0 && !hashTable.check(idToCheck)));
+ }
+ }
+
+ // test removing all but one element.
+ template<> template<>
+ void hash_index_object_t::test<2>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ const int numElementsToCheck = 5;
+ std::vector<LLUUID> idList(numElementsToCheck*10);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ ensure("getLength failed", hashTable.getLength() == numElementsToCheck);
+
+ // remove all but the last element
+ for (i = 0; i < numElementsToCheck-1; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ hashTable.remove(idToCheck);
+ }
+
+ // there should only be one element left now.
+ ensure("getLength failed", hashTable.getLength() == 1);
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ if (i != numElementsToCheck - 1)
+ {
+ ensure("remove did not work", hashTable.check(idToCheck) == FALSE);
+ }
+ else
+ {
+ UUIDTableEntry entryToCheck = hashTable.get(idToCheck);
+ ensure("remove did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i);
+ }
+ }
+ }
+
+ // test overriding of value already set.
+ template<> template<>
+ void hash_index_object_t::test<3>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 5> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ const int numElementsToCheck = 10;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id = idList[i];
+ // set new entry with value = i+numElementsToCheck
+ UUIDTableEntry entry(id, i+numElementsToCheck);
+ hashTable.set(id, entry);
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ UUIDTableEntry entryToCheck = hashTable.get(idToCheck);
+ ensure("set/get did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)(i+numElementsToCheck));
+ }
+ }
+
+ // test removeAll()
+ template<> template<>
+ void hash_index_object_t::test<4>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 5> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ const int numElementsToCheck = 10;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ hashTable.removeAll();
+ ensure("removeAll failed", hashTable.getLength() == 0);
+ }
+
+
+ // test sparse map - force it by creating 256 entries that fall into 256 different nodes
+ template<> template<>
+ void hash_index_object_t::test<5>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ const int numElementsToCheck = 256;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ // LLUUIDHashMap uses mData[0] to pick the bucket
+ // overwrite mData[0] so that it ranges from 0 to 255
+ id.mData[0] = i;
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ UUIDTableEntry entryToCheck = hashTable.get(idToCheck);
+ ensure("set/get did not work for sparse map", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i);
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ if (i % 2 != 0)
+ {
+ hashTable.remove(idToCheck);
+ }
+ }
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID idToCheck = idList[i];
+ ensure("remove or check did not work for sparse map", (i % 2 == 0 && hashTable.check(idToCheck)) || (i % 2 != 0 && !hashTable.check(idToCheck)));
+ }
+ }
+
+ // iterator
+ template<> template<>
+ void hash_index_object_t::test<6>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ LLUUIDHashMapIter<UUIDTableEntry, 2> hashIter(&hashTable);
+ const int numElementsToCheck = 256;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ // LLUUIDHashMap uses mData[0] to pick the bucket
+ // overwrite mData[0] so that it ranges from 0 to 255
+ // to create a sparse map
+ id.mData[0] = i;
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+ }
+
+ hashIter.first();
+ int numElementsIterated = 0;
+ while(!hashIter.done())
+ {
+ numElementsIterated++;
+ UUIDTableEntry tableEntry = *hashIter;
+ LLUUID id = tableEntry.getID();
+ hashIter.next();
+ ensure("Iteration failed for sparse map", tableEntry.getValue() < (size_t)numElementsToCheck && idList[tableEntry.getValue()] == tableEntry.getID());
+ }
+
+ ensure("iteration count failed", numElementsIterated == numElementsToCheck);
+ }
+
+ // remove after middle of iteration
+ template<> template<>
+ void hash_index_object_t::test<7>()
+ {
+ LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry());
+ LLUUIDHashMapIter<UUIDTableEntry, 2> hashIter(&hashTable);
+ const int numElementsToCheck = 256;
+ std::vector<LLUUID> idList(numElementsToCheck);
+ int i;
+
+ LLUUID uuidtoSearch;
+ for (i = 0; i < numElementsToCheck; i++)
+ {
+ LLUUID id;
+ id.generate();
+ // LLUUIDHashMap uses mData[0] to pick the bucket
+ // overwrite mData[0] so that it ranges from 0 to 255
+ // to create a sparse map
+ id.mData[0] = i;
+ UUIDTableEntry entry(id, i);
+ hashTable.set(id, entry);
+ idList[i] = id;
+
+ // pick uuid somewhere in the middle
+ if (i == 5)
+ {
+ uuidtoSearch = id;
+ }
+ }
+
+ hashIter.first();
+ int numElementsIterated = 0;
+ while(!hashIter.done())
+ {
+ numElementsIterated++;
+ UUIDTableEntry tableEntry = *hashIter;
+ LLUUID id = tableEntry.getID();
+ if (uuidtoSearch == id)
+ {
+ break;
+ }
+ hashIter.next();
+ }
+
+ // current iterator implementation will not allow any remove operations
+ // until ALL elements have been iterated over. this seems to be
+ // an unnecessary restriction. Iterator should have a method to
+ // reset() its state so that further operations (inckuding remove)
+ // can be performed on the HashMap without having to iterate thru
+ // all the remaining nodes.
+
+// hashIter.reset();
+// hashTable.remove(uuidtoSearch);
+// ensure("remove after iteration reset failed", hashTable.check(uuidtoSearch) == FALSE);
+ }
+}
diff --git a/indra/test/llxorcipher_tut.cpp b/indra/test/llxorcipher_tut.cpp
new file mode 100644
index 0000000000..6fe5176cb0
--- /dev/null
+++ b/indra/test/llxorcipher_tut.cpp
@@ -0,0 +1,113 @@
+/**
+ * @file llxorcipher_tut.cpp
+ * @author Adroit
+ * @date 2007-03
+ * @brief llxorcipher, llnullcipher test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "llxorcipher.h"
+#include "llnullcipher.h"
+
+namespace tut
+{
+ struct cipher
+ {
+ };
+ typedef test_group<cipher> cipher_t;
+ typedef cipher_t::object cipher_object_t;
+ tut::cipher_t tut_cipher("cipher");
+
+ //encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<1>()
+ {
+ const U32 len = 3;
+ const U8 pad[] = "abc";
+ const char str[] = "SecondLife";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+ LLXORCipher xorCipher(pad, len);
+ LLXORCipher xorCipher1(pad, len);
+
+ U32 length = xorCipher.requiredEncryptionSpace(50);
+ ensure("requiredEncryptionSpace() function failed", (length == 50));
+
+ U32 lenEncrypted = xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ ensure("Encryption failed", (lenEncrypted == str_len));
+ U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure("Decryption failed", (lenDecrypted == str_len));
+ ensure_memory_matches("LLXORCipher Encrypt/Decrypt failed", str, str_len, decrypted, lenDecrypted);
+ }
+
+ // operator=
+ template<> template<>
+ void cipher_object_t::test<2>()
+ {
+ const U8 pad[] = "ABCDEFGHIJKLMNOPQ"; // pad len longer than data to be ciphered
+ const U32 pad_len = sizeof(pad);
+ const U8 pad1[] = "SecondLife";
+ const U32 pad_len1 = sizeof(pad1);
+ const char str[] = "To Be Ciphered";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+
+ LLXORCipher xorCipher(pad, pad_len);
+ LLXORCipher xorCipher1(pad1, pad_len1);
+
+ xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ // make xorCipher1 same as xorCipher..so that xorCipher1 can decrypt what was
+ // encrypted using xorCipher
+ xorCipher1 = xorCipher;
+ U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure_memory_matches("LLXORCipher operator= failed", str, str_len, decrypted, lenDecrypted);
+ }
+
+ //in place encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<3>()
+ {
+ U32 padNum = 0x12349087;
+ const U8* pad = (U8*) &padNum;
+ const U32 pad_len = sizeof(U32);
+ char str[] = "To Be Ciphered a long string.........!!!.";
+ char str1[] = "To Be Ciphered a long string.........!!!."; // same as str
+ const S32 str_len = sizeof(str);
+
+ LLXORCipher xorCipher(pad, pad_len);
+ LLXORCipher xorCipher1(pad, pad_len);
+ xorCipher.encrypt((U8 *) str, str_len);
+ // it should not be the same as original data!
+ ensure("LLXORCipher: In Place encrypt failed", memcmp(str, str1, str_len) != 0);
+ xorCipher1.decrypt((U8 *) str, str_len);
+ // it should not be the same as original data!
+ ensure_memory_matches("LLXORCipher: In Place decrypt failed", str, str_len, str1, str_len);
+ }
+
+ //LLNullCipher encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<4>()
+ {
+ const char str[] = "SecondLife";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+ LLNullCipher nullCipher;
+ LLNullCipher nullCipher1;
+
+ U32 length = nullCipher.requiredEncryptionSpace(50);
+ ensure("LLNullCipher::requiredEncryptionSpace() function failed", (length == 50));
+
+ U32 len1 = nullCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ ensure_memory_matches("LLNullCipher - Source transformed during encryption.", encrypted, len1, str, str_len);
+
+ U32 len2 = nullCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure_memory_matches("LLNullCipher - Decryption failed", decrypted, len2, str, str_len);
+ }
+}
diff --git a/indra/test/message_tut.cpp b/indra/test/message_tut.cpp
new file mode 100644
index 0000000000..a08c3130f1
--- /dev/null
+++ b/indra/test/message_tut.cpp
@@ -0,0 +1,77 @@
+/**
+ * @file lldatapacker_tut.cpp
+ * @date 2007-04
+ * @brief LLDataPacker test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+
+#include "llapr.h"
+#include "llversion.h"
+#include "message.h"
+#include "message_prehash.h"
+
+namespace
+{
+ struct Response : public LLHTTPNode::Response
+ {
+ virtual void result(const LLSD&) {}
+ virtual void status(S32 code, const std::string& message)
+ {
+ mStatus = code;
+ }
+ S32 mStatus;
+ };
+}
+
+namespace tut
+{
+ struct LLMessageSystemTestData
+ {
+ LLMessageSystemTestData()
+ {
+ static bool init = false;
+ if(! init)
+ {
+ ll_init_apr();
+ init_prehash_data();
+ init = true;
+ }
+
+ // currently test disconnected message system
+ start_messaging_system("notafile", 13035,
+ LL_VERSION_MAJOR,
+ LL_VERSION_MINOR,
+ LL_VERSION_PATCH,
+ FALSE,
+ "notasharedsecret");
+ }
+
+ ~LLMessageSystemTestData()
+ {
+ // not end_messaging_system()
+ delete gMessageSystem;
+ gMessageSystem = NULL;
+ }
+ };
+
+ typedef test_group<LLMessageSystemTestData> LLMessageSystemTestGroup;
+ typedef LLMessageSystemTestGroup::object LLMessageSystemTestObject;
+ LLMessageSystemTestGroup messageTestGroup("LLMessageSystem");
+
+ template<> template<>
+ void LLMessageSystemTestObject::test<1>()
+ // dispatch unknown message
+ {
+ const char* name = "notamessasge";
+ const LLSD message;
+ const LLPointer<Response> response = new Response();
+ gMessageSystem->dispatch(name, message, response);
+ ensure_equals(response->mStatus, 404);
+ }
+}
+
diff --git a/indra/test/test.cpp b/indra/test/test.cpp
index b60abdf587..24a0c27a5e 100644
--- a/indra/test/test.cpp
+++ b/indra/test/test.cpp
@@ -44,7 +44,8 @@ public:
mTotalTests(0),
mPassedTests(0),
mFailedTests(0),
- mSkippedTests(0)
+ mSkippedTests(0),
+ mSkipedFailTests(0)
{
}
@@ -66,7 +67,7 @@ public:
break;
case tut::test_result::fail:
++mFailedTests;
- out << "fail '" << tr.message << "'";
+ out << "fail";
break;
case tut::test_result::ex:
++mFailedTests;
@@ -84,12 +85,20 @@ public:
++mSkippedTests;
out << "skipped";
break;
+ case tut::test_result::skip_fail:
+ ++mSkipedFailTests;
+ out << "skipped known failure";
+ break;
default:
++mFailedTests;
out << "unknown";
}
if(mVerboseMode || (tr.result != tut::test_result::ok))
{
+ if(!tr.message.empty())
+ {
+ out << ": '" << tr.message << "'";
+ }
std::cout << out.str() << std::endl;
}
}
@@ -98,11 +107,17 @@ public:
{
std::cout << std::endl;
std::cout << "Total Tests: " << mTotalTests << std::endl;
- std::cout << "Passed Tests : " << mPassedTests << std::endl;
+ std::cout << "Passed Tests: " << mPassedTests << std::endl;
if (mSkippedTests > 0)
{
- std::cout << "Skipped Tests : " << mSkippedTests << std::endl;
+ std::cout << "Skipped Tests: " << mSkippedTests << std::endl;
+ }
+
+ if (mSkipedFailTests > 0)
+ {
+ std::cout << "Skipped known failures: " << mSkipedFailTests
+ << std::endl;
}
if(mFailedTests > 0)
@@ -117,10 +132,11 @@ public:
protected:
bool mVerboseMode;
- S32 mTotalTests;
- S32 mPassedTests;
- S32 mFailedTests;
- S32 mSkippedTests;
+ int mTotalTests;
+ int mPassedTests;
+ int mFailedTests;
+ int mSkippedTests;
+ int mSkipedFailTests;
};
static const apr_getopt_option_t TEST_CL_OPTIONS[] =