diff options
Diffstat (limited to 'indra/test')
-rw-r--r-- | indra/test/llbuffer_tut.cpp | 542 | ||||
-rw-r--r-- | indra/test/llpermissions_tut.cpp | 982 | ||||
-rw-r--r-- | indra/test/llsaleinfo_tut.cpp | 388 | ||||
-rw-r--r-- | indra/test/llsdmessagebuilder_tut.cpp | 1674 | ||||
-rw-r--r-- | indra/test/llsdmessagereader_tut.cpp | 648 | ||||
-rw-r--r-- | indra/test/lltemplatemessagebuilder_tut.cpp | 1942 | ||||
-rw-r--r-- | indra/test/message_tut.cpp | 294 |
7 files changed, 3235 insertions, 3235 deletions
diff --git a/indra/test/llbuffer_tut.cpp b/indra/test/llbuffer_tut.cpp index 0100a3e225..07cb4d5aed 100644 --- a/indra/test/llbuffer_tut.cpp +++ b/indra/test/llbuffer_tut.cpp @@ -1,271 +1,271 @@ -/**
- * @file llbuffer_tut.cpp
- * @author Adroit
- * @date 2007-03
- * @brief llbuffer test cases.
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-
-#include "linden_common.h"
-#include "lltut.h"
-#include "llbuffer.h"
-#include "llerror.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));
- }
-}
+/** + * @file llbuffer_tut.cpp + * @author Adroit + * @date 2007-03 + * @brief llbuffer test cases. + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> + +#include "linden_common.h" +#include "lltut.h" +#include "llbuffer.h" +#include "llerror.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/llpermissions_tut.cpp b/indra/test/llpermissions_tut.cpp index c79a0dae83..1328939004 100644 --- a/indra/test/llpermissions_tut.cpp +++ b/indra/test/llpermissions_tut.cpp @@ -1,491 +1,491 @@ -/**
- * @file llpermissions_tut.cpp
- * @author Adroit
- * @date March 2007
- * @brief llpermissions test cases.
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-#include "linden_common.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()) && (! permissions.isOwned())));
- }
-
- 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 ", ! 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) && (! is_group_owned)));
-
- perm.init(creator,LLUUID::null,lastOwner,group);
- perm.getOwnership(uuid,is_group_owned);
- ensure("3:getOwnership:failed ", ((uuid == group) && 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 ", 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 ", ! perm.setOwnerAndGroup(agent,owner2,group2,is_atomic));
-
- // should be able to change - agent and owner same as current owner
- ensure("setOwnerAndGroup():failed ", 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 ", perm.deedToGroup(agent,group));
- }
- template<> template<>
- void permission_object_t::test<11>()
- {
- LLPermissions perm;
- LLUUID agent;
- bool set = true;
- U32 bits = PERM_TRANSFER | PERM_MODIFY;
- ensure("setBaseBits():failed ", perm.setBaseBits(agent, set, bits));
- ensure("setOwnerBits():failed ", perm.setOwnerBits(agent, set, bits));
-
- LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
- ensure("setBaseBits():failed ", ! perm.setBaseBits(agent1, set, bits));
- ensure("setOwnerBits():failed ", ! 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 = true;
- U32 bits = 10;
- ensure("setGroupBits():failed ", perm.setGroupBits(agent,group, set, bits));
- ensure("setEveryoneBits():failed ", perm.setEveryoneBits(agent,group, set, bits));
- ensure("setNextOwnerBits():failed ", perm.setNextOwnerBits(agent,group, set, bits));
-
- LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e");
- ensure("setGroupBits():failed ", ! perm.setGroupBits(agent1,group, set, bits));
- ensure("setEveryoneBits():failed ", ! perm.setEveryoneBits(agent1,group, set, bits));
- ensure("setNextOwnerBits():failed ", ! 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 ", 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 ", 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 ", perm.allowModifyBy(agent));
- ensure("2:allowModifyBy():failed ", perm.allowModifyBy(agent,group));
-
- LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
- ensure("3:allowModifyBy():failed ", perm.allowModifyBy(agent1));
- ensure("4:allowModifyBy():failed ", 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 ", perm.allowModifyBy(agent));
- ensure("2:allowCopyBy():failed ", perm.allowModifyBy(agent,group));
-
- LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
- ensure("3:allowCopyBy():failed ", perm.allowCopyBy(agent1));
- ensure("4:allowCopyBy():failed ", 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 ", perm.allowMoveBy(agent));
- ensure("2:allowMoveBy():failed ", perm.allowMoveBy(agent,group));
-
- LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8");
- ensure("3:allowMoveBy():failed ", perm.allowMoveBy(agent1));
- ensure("4:allowMoveBy():failed ", 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 ", perm.allowTransferTo(agent));
-
- perm.init(creator,owner,lastOwner,group);
- ensure("2:allowMoveBy():failed ", perm.allowTransferTo(agent));
- }
-
- template<> template<>
- void permission_object_t::test<18>()
- {
- LLPermissions perm,perm1;
- ensure_equals("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_equals("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_not_equals("2:Operator==:failed ", perm, perm1);
- }
-
- template<> template<>
- void permission_object_t::test<20>()
- {
- 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_equals("exportStream()/importStream():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);
- std::ostringstream stream1, stream2;
- stream1 << perm;
- perm1.init(creator,owner,lastOwner,group);
- stream2 << perm1;
- ensure_equals("1:operator << failed", stream1.str(), stream2.str());
- }
-
- 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);
-
- 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<23>()
- {
- LLAggregatePermissions AggrPermission;
- LLAggregatePermissions AggrPermission1;
- ensure_equals("getU8() function failed", AggrPermission.getU8(), 0);
- ensure("isEmpty() function failed", AggrPermission.isEmpty());
- 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());
-
- AggrPermission1.aggregate(AggrPermission);
- ensure("aggregate() function failed", ! AggrPermission1.isEmpty());
-
- std::ostringstream stream1;
- stream1 << AggrPermission;
- ensure_equals("operator<< failed", stream1.str(), "{PI_COPY=All, PI_MODIFY=All, PI_TRANSFER=All}");
- }
-}
+/** + * @file llpermissions_tut.cpp + * @author Adroit + * @date March 2007 + * @brief llpermissions test cases. + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> +#include "linden_common.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()) && (! permissions.isOwned()))); + } + + 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 ", ! 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) && (! is_group_owned))); + + perm.init(creator,LLUUID::null,lastOwner,group); + perm.getOwnership(uuid,is_group_owned); + ensure("3:getOwnership:failed ", ((uuid == group) && 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 ", 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 ", ! perm.setOwnerAndGroup(agent,owner2,group2,is_atomic)); + + // should be able to change - agent and owner same as current owner + ensure("setOwnerAndGroup():failed ", 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 ", perm.deedToGroup(agent,group)); + } + template<> template<> + void permission_object_t::test<11>() + { + LLPermissions perm; + LLUUID agent; + bool set = true; + U32 bits = PERM_TRANSFER | PERM_MODIFY; + ensure("setBaseBits():failed ", perm.setBaseBits(agent, set, bits)); + ensure("setOwnerBits():failed ", perm.setOwnerBits(agent, set, bits)); + + LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); + ensure("setBaseBits():failed ", ! perm.setBaseBits(agent1, set, bits)); + ensure("setOwnerBits():failed ", ! 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 = true; + U32 bits = 10; + ensure("setGroupBits():failed ", perm.setGroupBits(agent,group, set, bits)); + ensure("setEveryoneBits():failed ", perm.setEveryoneBits(agent,group, set, bits)); + ensure("setNextOwnerBits():failed ", perm.setNextOwnerBits(agent,group, set, bits)); + + LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); + ensure("setGroupBits():failed ", ! perm.setGroupBits(agent1,group, set, bits)); + ensure("setEveryoneBits():failed ", ! perm.setEveryoneBits(agent1,group, set, bits)); + ensure("setNextOwnerBits():failed ", ! 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 ", 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 ", 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 ", perm.allowModifyBy(agent)); + ensure("2:allowModifyBy():failed ", perm.allowModifyBy(agent,group)); + + LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); + ensure("3:allowModifyBy():failed ", perm.allowModifyBy(agent1)); + ensure("4:allowModifyBy():failed ", 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 ", perm.allowModifyBy(agent)); + ensure("2:allowCopyBy():failed ", perm.allowModifyBy(agent,group)); + + LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); + ensure("3:allowCopyBy():failed ", perm.allowCopyBy(agent1)); + ensure("4:allowCopyBy():failed ", 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 ", perm.allowMoveBy(agent)); + ensure("2:allowMoveBy():failed ", perm.allowMoveBy(agent,group)); + + LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); + ensure("3:allowMoveBy():failed ", perm.allowMoveBy(agent1)); + ensure("4:allowMoveBy():failed ", 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 ", perm.allowTransferTo(agent)); + + perm.init(creator,owner,lastOwner,group); + ensure("2:allowMoveBy():failed ", perm.allowTransferTo(agent)); + } + + template<> template<> + void permission_object_t::test<18>() + { + LLPermissions perm,perm1; + ensure_equals("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_equals("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_not_equals("2:Operator==:failed ", perm, perm1); + } + + template<> template<> + void permission_object_t::test<20>() + { + 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_equals("exportStream()/importStream():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); + std::ostringstream stream1, stream2; + stream1 << perm; + perm1.init(creator,owner,lastOwner,group); + stream2 << perm1; + ensure_equals("1:operator << failed", stream1.str(), stream2.str()); + } + + 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); + + 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<23>() + { + LLAggregatePermissions AggrPermission; + LLAggregatePermissions AggrPermission1; + ensure_equals("getU8() function failed", AggrPermission.getU8(), 0); + ensure("isEmpty() function failed", AggrPermission.isEmpty()); + 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()); + + AggrPermission1.aggregate(AggrPermission); + ensure("aggregate() function failed", ! AggrPermission1.isEmpty()); + + std::ostringstream stream1; + stream1 << AggrPermission; + ensure_equals("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 index 469aca0b6e..1da7101aa3 100644 --- a/indra/test/llsaleinfo_tut.cpp +++ b/indra/test/llsaleinfo_tut.cpp @@ -1,194 +1,194 @@ -/**
- * @file LLSaleInfo_tut.cpp
- * @author Adroit
- * @date 2007-03
- * @brief Test cases of llsaleinfo.h
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-#include "linden_common.h"
-#include "lltut.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);
- const 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>()
- {
- 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("importStream() fn failed ",
- llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() &&
- llsaleinfo.getSaleType() == llsaleinfo1.getSaleType());
- }
-
- template<> template<>
- void llsaleinfo_test_t::test<3>()
- {
- 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<4>()
- {
- 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<5>()
- {
- 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<6>()
- {
- 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<7>()
- {
-
- //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)
- }
-
-}
+/** + * @file LLSaleInfo_tut.cpp + * @author Adroit + * @date 2007-03 + * @brief Test cases of llsaleinfo.h + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> +#include "linden_common.h" +#include "lltut.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); + const 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>() + { + 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("importStream() fn failed ", + llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() && + llsaleinfo.getSaleType() == llsaleinfo1.getSaleType()); + } + + template<> template<> + void llsaleinfo_test_t::test<3>() + { + 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<4>() + { + 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<5>() + { + 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<6>() + { + 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<7>() + { + + //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 0675dc6c80..6804c3e29e 100644 --- a/indra/test/llsdmessagebuilder_tut.cpp +++ b/indra/test/llsdmessagebuilder_tut.cpp @@ -1,837 +1,837 @@ -/**
- * @file llsdmessagebuilder_tut.cpp
- * @date February 2006
- * @brief LLSDMessageBuilder unit tests
- *
- * $LicenseInfo:firstyear=2006&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-
-#include "linden_common.h"
-#include "lltut.h"
-#include "llmessagetemplate.h"
-#include "llsdmessagebuilder.h"
-#include "llsdmessagereader.h"
-#include "llsdtraits.h"
-#include "llmath.h"
-#include "llquaternion.h"
-#include "u64.h"
-#include "v3dmath.h"
-#include "v3math.h"
-#include "v4math.h"
-#include "llsdutil.h"
-//#include "llsdutil.cpp"
-#include "llsdutil_math.cpp"
-#include "lltemplatemessagebuilder.h"
-
-namespace tut
-{
- static LLTemplateMessageBuilder::message_template_name_map_t templateNameMap;
-
- LLMsgData* messageData = NULL;
- LLMsgBlkData* messageBlockData = NULL;
-
- struct LLSDMessageBuilderTestData {
-
- LLSDMessageBuilderTestData()
- {
- messageData = new LLMsgData("testMessage");
- messageBlockData = new LLMsgBlkData("testBlock", 0);
- }
-
- static LLSDMessageBuilder defaultBuilder()
- {
- LLSDMessageBuilder builder;
- builder.newMessage("name");
- builder.nextBlock("block");
- return builder;
- }
-
- static LLSDMessageReader setReader(const LLSDMessageBuilder& builder)
- {
- LLSDMessageReader reader;
- reader.setMessage("name", builder.getMessage());
- return reader;
- }
-
- static void addValue(LLMsgBlkData* mbd, char* name, void* v, EMsgVariableType type, int size, int data_size = -1)
- {
- LLMsgVarData tmp(name, type);
- tmp.addData(v, size, type, data_size);
- mbd->mMemberVarData[name] = tmp;
- }
-
-
- static LLMessageBlock* defaultTemplateBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE)
- {
- return createTemplateBlock(_PREHASH_Test0, type, size, block);
- }
-
- static LLMessageBlock* createTemplateBlock(const 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(const_cast<char*>(_PREHASH_Test0), type, size);
- }
- return result;
- }
-
- static LLTemplateMessageBuilder* defaultTemplateBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_PREHASH_Test0))
- {
- templateNameMap[_PREHASH_TestMessage] = &messageTemplate;
- LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(templateNameMap);
- builder->newMessage(_PREHASH_TestMessage);
- builder->nextBlock(name);
- return builder;
- }
-
- static LLMessageTemplate defaultTemplate()
- {
- return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH);
- }
- };
-
- typedef test_group<LLSDMessageBuilderTestData> LLSDMessageBuilderTestGroup;
- typedef LLSDMessageBuilderTestGroup::object LLSDMessageBuilderTestObject;
- LLSDMessageBuilderTestGroup llsdMessageBuilderTestGroup("LLSDMessageBuilder");
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<1>()
- // construction and test of undefined
- {
- LLSDMessageBuilder builder = defaultBuilder();
- LLSDMessageReader reader = setReader(builder);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<2>()
- // bool
- {
- bool outValue, inValue = true;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addBOOL("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getBOOL("block", "var", outValue);
- ensure_equals("Ensure bool", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<3>()
- // U8
- {
- U8 outValue, inValue = 2;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addU8("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getU8("block", "var", outValue);
- ensure_equals("Ensure U8", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<4>()
- // S16
- {
- S16 outValue, inValue = 90;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addS16("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getS16("block", "var", outValue);
- ensure_equals("Ensure S16", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<5>()
- // U16
- {
- U16 outValue, inValue = 3;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addU16("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getU16("block", "var", outValue);
- ensure_equals("Ensure U16", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<6>()
- // S32
- {
- S32 outValue, inValue = 44;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addS32("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getS32("block", "var", outValue);
- ensure_equals("Ensure S32", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<7>()
- // F32
- {
- F32 outValue, inValue = 121.44f;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addF32("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getF32("block", "var", outValue);
- ensure_equals("Ensure F32", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<8>()
- // U32
- {
- U32 outValue, inValue = 88;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addU32("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getU32("block", "var", outValue);
- ensure_equals("Ensure U32", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<9>()
- // U64
- {
- U64 outValue, inValue = 121;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addU64("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getU64("block", "var", outValue);
- ensure_equals("Ensure U64", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<10>()
- // F64
- {
- F64 outValue, inValue = 3232143.33;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addF64("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getF64("block", "var", outValue);
- ensure_equals("Ensure F64", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<11>()
- // Vector3
- {
- LLVector3 outValue, inValue = LLVector3(1,2,3);
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addVector3("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getVector3("block", "var", outValue);
- ensure_equals("Ensure Vector3", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<12>()
- // Vector4
- {
- LLVector4 outValue, inValue = LLVector4(1,2,3,4);
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addVector4("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getVector4("block", "var", outValue);
- ensure_equals("Ensure Vector4", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<13>()
- // Vector3d
- {
- LLVector3d outValue, inValue = LLVector3d(1,2,3);
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addVector3d("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getVector3d("block", "var", outValue);
- ensure_equals("Ensure Vector3d", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<14>()
- // Quaternion
- {
- LLQuaternion outValue, inValue = LLQuaternion(1,LLVector3(2,3,4));
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addQuat("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getQuat("block", "var", outValue);
- ensure_equals("Ensure Quaternion", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<15>()
- // UUID
- {
- LLUUID outValue, inValue;
- inValue.generate();
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addUUID("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getUUID("block", "var", outValue);
- ensure_equals("Ensure UUID", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<16>()
- // IPAddr
- {
- U32 outValue, inValue = 12344556;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addIPAddr("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getIPAddr("block", "var", outValue);
- ensure_equals("Ensure IPAddr", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<17>()
- // IPPort
- {
- U16 outValue, inValue = 80;
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addIPPort("var", inValue);
- LLSDMessageReader reader = setReader(builder);
- reader.getIPPort("block", "var", outValue);
- ensure_equals("Ensure IPPort", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<18>()
- {
- std::string outValue, inValue = "testing";
- LLSDMessageBuilder builder = defaultBuilder();
- builder.addString("var", inValue.c_str());
- LLSDMessageReader reader = setReader(builder);
- char buffer[MAX_STRING];
- reader.getString("block", "var", MAX_STRING, buffer);
- outValue = buffer;
- ensure_equals("Ensure String", inValue, outValue);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<19>()
- {
- LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0);
- LLMsgData* md = new LLMsgData("testMessage");
- md->addBlock(mbd);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*md);
- LLSD output = builder.getMessage();
-
- ensure("Ensure message block created when copied from legacy message to llsd", output["testBlock"].isDefined());
- }
-
- // MVT_FIXED
- template<> template<>
- void LLSDMessageBuilderTestObject::test<20>()
- {
- char binData[] = "abcdefghijklmnop";
-
- addValue(messageBlockData, (char *)"testBinData", &binData, MVT_FIXED, sizeof(binData));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure fixed binary data works in a message copied from legacy to llsd",
- &v[0], sizeof(binData), binData, sizeof(binData));
- }
-
- // MVT_VARIABLE data_size 1 (U8's)
- template<> template<>
- void LLSDMessageBuilderTestObject::test<21>()
- {
- /* U8 binData[] = "abcdefghijklmnop";
-
- addValue(messageBlockData, "testBinData", &binData, MVT_VARIABLE, sizeof(binData), 1);
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_VARIABLE U8 binary data works in a message copied from legacy to llsd",
- &v[0], sizeof(binData), binData, sizeof(binData));*/
- }
-
- // MVT_VARIABLE data_size 2 (U16's)
- template<> template<>
- void LLSDMessageBuilderTestObject::test<22>()
- {
- U16 binData[] = {1,2,3,4,5,6,7,8,9}; //9 shorts
-
- addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 1, 2);
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_VARIABLE U16 binary data works in a message copied from legacy to llsd",
- &v[0], sizeof(binData) >> 1, binData, sizeof(binData) >> 1);
- }
-
- // MVT_VARIABLE data_size 4 (S32's)
- template<> template<>
- void LLSDMessageBuilderTestObject::test<23>()
- {
- U32 binData[] = {9,8,7,6,5,4,3,2,1};
-
- addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 2, 4);
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_VARIABLE S32 binary data works in a message copied from legacy to llsd",
- &v[0], sizeof(binData) >> 2, binData, sizeof(binData) >> 2);
- }
-
- // MVT_U8
- template<> template<>
- void LLSDMessageBuilderTestObject::test<24>()
- {
- U8 data = 0xa5;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U8, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_U8 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_U16
- template<> template<>
- void LLSDMessageBuilderTestObject::test<25>()
- {
- U16 data = 0xa55a;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_U16 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_U32
- template<> template<>
- void LLSDMessageBuilderTestObject::test<26>()
- {
- U32 data = 0xa55a7117;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U32, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_U32 data works in a message copied from legacy to llsd",
- ll_U32_from_sd(output["testBlock"][0]["testBinData"]), data);
- }
-
- // MVT_U64 - crush into an s32: LLSD does not support 64 bit values
- template<> template<>
- void LLSDMessageBuilderTestObject::test<27>()
- {
- U64 data = U64L(0xa55a711711223344);
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U64, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_U64 data works in a message copied from legacy to llsd",
- ll_U64_from_sd(output["testBlock"][0]["testBinData"]), data);
- }
-
- // MVT_S8
- template<> template<>
- void LLSDMessageBuilderTestObject::test<28>()
- {
- S8 data = -31;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_S8, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_S8 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_S16
- template<> template<>
- void LLSDMessageBuilderTestObject::test<29>()
- {
- S16 data = -31;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_S16 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_S32
- template<> template<>
- void LLSDMessageBuilderTestObject::test<30>()
- {
- S32 data = -3100;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_S32, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_S32 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_S64 - crush into an s32: LLSD does not support 64 bit values
- template<> template<>
- void LLSDMessageBuilderTestObject::test<31>()
- {
- S64 data = -31003100;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_S64, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_S64 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), (S32)data);
- }
-
- // MVT_F32
- template<> template<>
- void LLSDMessageBuilderTestObject::test<32>()
- {
- F32 data = 1234.1234f;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_F32, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_F32 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asReal(), data);
- }
-
- // MVT_F64
- template<> template<>
- void LLSDMessageBuilderTestObject::test<33>()
- {
- F64 data = 1234.1234;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_F64, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_F64 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asReal(), data);
- }
-
- // MVT_LLVector3
- template<> template<>
- void LLSDMessageBuilderTestObject::test<34>()
- {
- LLVector3 data(1,2,3);
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd",
- ll_vector3_from_sd(output["testBlock"][0]["testBinData"]), data);
- }
-
- // MVT_LLVector3d
- template<> template<>
- void LLSDMessageBuilderTestObject::test<35>()
- {
- LLVector3d data(1,2,3);
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3d, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd",
- ll_vector3d_from_sd(output["testBlock"][0]["testBinData"]), data);
- }
-
- // MVT_LLVector4
- template<> template<>
- void LLSDMessageBuilderTestObject::test<36>()
- {
- LLVector4 data(1,2,3,4);
- LLSD v = ll_sd_from_vector4(data);
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector4, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_LLVector4 data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"], v);
- }
-
- // MVT_LLQuaternion
- template<> template<>
- void LLSDMessageBuilderTestObject::test<37>()
- {
- LLQuaternion data(0.3713907f, 0.5570861f, 0.7427813f,0.0f);
-
- //we send a quaternion packed into a vec3 (w is infered) - so sizeof(vec) == 12 bytes not 16.
- LLVector3 vec = data.packToVector3();
-
- addValue(messageBlockData, (char *)"testBinData", &vec, MVT_LLQuaternion, sizeof(vec));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_LLQuaternion data works in a message copied from legacy to llsd",
- ll_quaternion_from_sd(output["testBlock"][0]["testBinData"]), data);
- }
-
- // MVT_LLUUID
- template<> template<>
- void LLSDMessageBuilderTestObject::test<38>()
- {
- LLUUID data("01234567-0123-0123-0123-234567abcdef");
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLUUID, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::string v = output["testBlock"][0]["testBinData"].asUUID().asString();
-
- ensure_equals("Ensure MVT_LLUUID data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asUUID(), data);
- }
-
- // MVT_BOOL
- template<> template<>
- void LLSDMessageBuilderTestObject::test<39>()
- {
- bool valueTrue = true;
- bool valueFalse = false;
-
- LLMsgData* md = new LLMsgData("testMessage");
- LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0);
- addValue(mbd, (char *)"testBoolFalse", &valueFalse, MVT_BOOL, sizeof(bool));
- addValue(mbd, (char *)"testBoolTrue", &valueTrue, MVT_BOOL, sizeof(bool));
- md->addBlock(mbd);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*md);
- LLSD output = builder.getMessage();
-
- ensure("Ensure bools work in a message copied from legacy to llsd",
- output["testBlock"][0]["testBoolTrue"].asBoolean() && !output["testBlock"][0]["testBoolFalse"].asBoolean());
- }
-
- // MVT_IP_ADDR
- template<> template<>
- void LLSDMessageBuilderTestObject::test<40>()
- {
- U32 data(0xff887766);
- LLSD v = ll_sd_from_ipaddr(data);
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_ADDR, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_IP_ADDR data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"], v);
- }
-
- // MVT_IP_PORT
- template<> template<>
- void LLSDMessageBuilderTestObject::test<41>()
- {
- U16 data = 0xff88;
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_PORT, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- ensure_equals("Ensure MVT_IP_PORT data works in a message copied from legacy to llsd",
- output["testBlock"][0]["testBinData"].asInteger(), data);
- }
-
- // MVT_U16Vec3
- template<> template<>
- void LLSDMessageBuilderTestObject::test<42>()
- {
- U16 data[3] = {0,1,2};
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Vec3, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_U16Vec3 data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_U16Vec3 data works in a message copied from legacy to llsd",
- (U16*)&v[0], 6, data, 6);
- }
-
- // MVT_U16Quat
- template<> template<>
- void LLSDMessageBuilderTestObject::test<43>()
- {
- U16 data[4] = {0,1,2,4};
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Quat, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_U16Quat data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_U16Quat data works in a message copied from legacy to llsd",
- (U16*)&v[0], 8, data, 8);
- }
-
- // MVT_S16Array
- template<> template<>
- void LLSDMessageBuilderTestObject::test<44>()
- {
- S16 data[19] = {0,-1,2,-4,5,-6,7,-8,9,-10,11,-12,13,-14,15,16,17,18};
-
- addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16Array, sizeof(data));
- messageData->addBlock(messageBlockData);
- LLSDMessageBuilder builder = defaultBuilder();
-
- builder.copyFromMessageData(*messageData);
- LLSD output = builder.getMessage();
-
- std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary();
- ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0);
-
- ensure_memory_matches("Ensure MVT_S16Array data works in a message copied from legacy to llsd",
- (U16*)&v[0], 19, data, 19);
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<45>()
- {
- LLMessageTemplate messageTemplate = defaultTemplate();
- messageTemplate.addBlock(defaultTemplateBlock(MVT_U8, 1));
- U8 inValue = 2;
- LLTemplateMessageBuilder* template_builder = defaultTemplateBuilder(messageTemplate);
- template_builder->addU8(_PREHASH_Test0, inValue);
-
- LLSDMessageBuilder builder;
- builder.copyFromMessageData(*template_builder->getCurrentMessage());
- LLSD output = builder.getMessage();
-
- ensure_equals(output["Test0"][0]["Test0"].asInteger(), 2);
-
- }
-
- template<> template<>
- void LLSDMessageBuilderTestObject::test<46>()
- {
- LLMessageTemplate messageTemplate = defaultTemplate();
- messageTemplate.addBlock(defaultTemplateBlock(MVT_VARIABLE, 1));
- std::string inValue = "testing";
- LLTemplateMessageBuilder* builder = defaultTemplateBuilder(messageTemplate);
- builder->addString(_PREHASH_Test0, inValue.c_str());
-
- LLSDMessageBuilder sd_builder;
- sd_builder.copyFromMessageData(*builder->getCurrentMessage());
- LLSD output = sd_builder.getMessage();
-
- ensure_equals(output["Test0"][0]["Test0"].asString(), std::string("testing"));
- }
-
-}
-
+/** + * @file llsdmessagebuilder_tut.cpp + * @date February 2006 + * @brief LLSDMessageBuilder unit tests + * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> + +#include "linden_common.h" +#include "lltut.h" +#include "llmessagetemplate.h" +#include "llsdmessagebuilder.h" +#include "llsdmessagereader.h" +#include "llsdtraits.h" +#include "llmath.h" +#include "llquaternion.h" +#include "u64.h" +#include "v3dmath.h" +#include "v3math.h" +#include "v4math.h" +#include "llsdutil.h" +//#include "llsdutil.cpp" +#include "llsdutil_math.cpp" +#include "lltemplatemessagebuilder.h" + +namespace tut +{ + static LLTemplateMessageBuilder::message_template_name_map_t templateNameMap; + + LLMsgData* messageData = NULL; + LLMsgBlkData* messageBlockData = NULL; + + struct LLSDMessageBuilderTestData { + + LLSDMessageBuilderTestData() + { + messageData = new LLMsgData("testMessage"); + messageBlockData = new LLMsgBlkData("testBlock", 0); + } + + static LLSDMessageBuilder defaultBuilder() + { + LLSDMessageBuilder builder; + builder.newMessage("name"); + builder.nextBlock("block"); + return builder; + } + + static LLSDMessageReader setReader(const LLSDMessageBuilder& builder) + { + LLSDMessageReader reader; + reader.setMessage("name", builder.getMessage()); + return reader; + } + + static void addValue(LLMsgBlkData* mbd, char* name, void* v, EMsgVariableType type, int size, int data_size = -1) + { + LLMsgVarData tmp(name, type); + tmp.addData(v, size, type, data_size); + mbd->mMemberVarData[name] = tmp; + } + + + static LLMessageBlock* defaultTemplateBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) + { + return createTemplateBlock(_PREHASH_Test0, type, size, block); + } + + static LLMessageBlock* createTemplateBlock(const 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(const_cast<char*>(_PREHASH_Test0), type, size); + } + return result; + } + + static LLTemplateMessageBuilder* defaultTemplateBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_PREHASH_Test0)) + { + templateNameMap[_PREHASH_TestMessage] = &messageTemplate; + LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(templateNameMap); + builder->newMessage(_PREHASH_TestMessage); + builder->nextBlock(name); + return builder; + } + + static LLMessageTemplate defaultTemplate() + { + return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH); + } + }; + + typedef test_group<LLSDMessageBuilderTestData> LLSDMessageBuilderTestGroup; + typedef LLSDMessageBuilderTestGroup::object LLSDMessageBuilderTestObject; + LLSDMessageBuilderTestGroup llsdMessageBuilderTestGroup("LLSDMessageBuilder"); + + template<> template<> + void LLSDMessageBuilderTestObject::test<1>() + // construction and test of undefined + { + LLSDMessageBuilder builder = defaultBuilder(); + LLSDMessageReader reader = setReader(builder); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<2>() + // bool + { + bool outValue, inValue = true; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addBOOL("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getBOOL("block", "var", outValue); + ensure_equals("Ensure bool", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<3>() + // U8 + { + U8 outValue, inValue = 2; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addU8("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getU8("block", "var", outValue); + ensure_equals("Ensure U8", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<4>() + // S16 + { + S16 outValue, inValue = 90; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addS16("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getS16("block", "var", outValue); + ensure_equals("Ensure S16", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<5>() + // U16 + { + U16 outValue, inValue = 3; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addU16("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getU16("block", "var", outValue); + ensure_equals("Ensure U16", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<6>() + // S32 + { + S32 outValue, inValue = 44; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addS32("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getS32("block", "var", outValue); + ensure_equals("Ensure S32", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<7>() + // F32 + { + F32 outValue, inValue = 121.44f; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addF32("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getF32("block", "var", outValue); + ensure_equals("Ensure F32", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<8>() + // U32 + { + U32 outValue, inValue = 88; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addU32("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getU32("block", "var", outValue); + ensure_equals("Ensure U32", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<9>() + // U64 + { + U64 outValue, inValue = 121; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addU64("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getU64("block", "var", outValue); + ensure_equals("Ensure U64", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<10>() + // F64 + { + F64 outValue, inValue = 3232143.33; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addF64("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getF64("block", "var", outValue); + ensure_equals("Ensure F64", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<11>() + // Vector3 + { + LLVector3 outValue, inValue = LLVector3(1,2,3); + LLSDMessageBuilder builder = defaultBuilder(); + builder.addVector3("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getVector3("block", "var", outValue); + ensure_equals("Ensure Vector3", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<12>() + // Vector4 + { + LLVector4 outValue, inValue = LLVector4(1,2,3,4); + LLSDMessageBuilder builder = defaultBuilder(); + builder.addVector4("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getVector4("block", "var", outValue); + ensure_equals("Ensure Vector4", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<13>() + // Vector3d + { + LLVector3d outValue, inValue = LLVector3d(1,2,3); + LLSDMessageBuilder builder = defaultBuilder(); + builder.addVector3d("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getVector3d("block", "var", outValue); + ensure_equals("Ensure Vector3d", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<14>() + // Quaternion + { + LLQuaternion outValue, inValue = LLQuaternion(1,LLVector3(2,3,4)); + LLSDMessageBuilder builder = defaultBuilder(); + builder.addQuat("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getQuat("block", "var", outValue); + ensure_equals("Ensure Quaternion", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<15>() + // UUID + { + LLUUID outValue, inValue; + inValue.generate(); + LLSDMessageBuilder builder = defaultBuilder(); + builder.addUUID("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getUUID("block", "var", outValue); + ensure_equals("Ensure UUID", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<16>() + // IPAddr + { + U32 outValue, inValue = 12344556; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addIPAddr("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getIPAddr("block", "var", outValue); + ensure_equals("Ensure IPAddr", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<17>() + // IPPort + { + U16 outValue, inValue = 80; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addIPPort("var", inValue); + LLSDMessageReader reader = setReader(builder); + reader.getIPPort("block", "var", outValue); + ensure_equals("Ensure IPPort", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<18>() + { + std::string outValue, inValue = "testing"; + LLSDMessageBuilder builder = defaultBuilder(); + builder.addString("var", inValue.c_str()); + LLSDMessageReader reader = setReader(builder); + char buffer[MAX_STRING]; + reader.getString("block", "var", MAX_STRING, buffer); + outValue = buffer; + ensure_equals("Ensure String", inValue, outValue); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<19>() + { + LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0); + LLMsgData* md = new LLMsgData("testMessage"); + md->addBlock(mbd); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*md); + LLSD output = builder.getMessage(); + + ensure("Ensure message block created when copied from legacy message to llsd", output["testBlock"].isDefined()); + } + + // MVT_FIXED + template<> template<> + void LLSDMessageBuilderTestObject::test<20>() + { + char binData[] = "abcdefghijklmnop"; + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_FIXED, sizeof(binData)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure fixed binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData), binData, sizeof(binData)); + } + + // MVT_VARIABLE data_size 1 (U8's) + template<> template<> + void LLSDMessageBuilderTestObject::test<21>() + { + /* U8 binData[] = "abcdefghijklmnop"; + + addValue(messageBlockData, "testBinData", &binData, MVT_VARIABLE, sizeof(binData), 1); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE U8 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData), binData, sizeof(binData));*/ + } + + // MVT_VARIABLE data_size 2 (U16's) + template<> template<> + void LLSDMessageBuilderTestObject::test<22>() + { + U16 binData[] = {1,2,3,4,5,6,7,8,9}; //9 shorts + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 1, 2); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE U16 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData) >> 1, binData, sizeof(binData) >> 1); + } + + // MVT_VARIABLE data_size 4 (S32's) + template<> template<> + void LLSDMessageBuilderTestObject::test<23>() + { + U32 binData[] = {9,8,7,6,5,4,3,2,1}; + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 2, 4); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE S32 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData) >> 2, binData, sizeof(binData) >> 2); + } + + // MVT_U8 + template<> template<> + void LLSDMessageBuilderTestObject::test<24>() + { + U8 data = 0xa5; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U8, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U8 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U16 + template<> template<> + void LLSDMessageBuilderTestObject::test<25>() + { + U16 data = 0xa55a; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U16 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U32 + template<> template<> + void LLSDMessageBuilderTestObject::test<26>() + { + U32 data = 0xa55a7117; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U32 data works in a message copied from legacy to llsd", + ll_U32_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_U64 - crush into an s32: LLSD does not support 64 bit values + template<> template<> + void LLSDMessageBuilderTestObject::test<27>() + { + U64 data = U64L(0xa55a711711223344); + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U64 data works in a message copied from legacy to llsd", + ll_U64_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_S8 + template<> template<> + void LLSDMessageBuilderTestObject::test<28>() + { + S8 data = -31; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S8, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S8 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S16 + template<> template<> + void LLSDMessageBuilderTestObject::test<29>() + { + S16 data = -31; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S16 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S32 + template<> template<> + void LLSDMessageBuilderTestObject::test<30>() + { + S32 data = -3100; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S32 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S64 - crush into an s32: LLSD does not support 64 bit values + template<> template<> + void LLSDMessageBuilderTestObject::test<31>() + { + S64 data = -31003100; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S64 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), (S32)data); + } + + // MVT_F32 + template<> template<> + void LLSDMessageBuilderTestObject::test<32>() + { + F32 data = 1234.1234f; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_F32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_F32 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asReal(), data); + } + + // MVT_F64 + template<> template<> + void LLSDMessageBuilderTestObject::test<33>() + { + F64 data = 1234.1234; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_F64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_F64 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asReal(), data); + } + + // MVT_LLVector3 + template<> template<> + void LLSDMessageBuilderTestObject::test<34>() + { + LLVector3 data(1,2,3); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd", + ll_vector3_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLVector3d + template<> template<> + void LLSDMessageBuilderTestObject::test<35>() + { + LLVector3d data(1,2,3); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3d, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd", + ll_vector3d_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLVector4 + template<> template<> + void LLSDMessageBuilderTestObject::test<36>() + { + LLVector4 data(1,2,3,4); + LLSD v = ll_sd_from_vector4(data); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector4, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector4 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"], v); + } + + // MVT_LLQuaternion + template<> template<> + void LLSDMessageBuilderTestObject::test<37>() + { + LLQuaternion data(0.3713907f, 0.5570861f, 0.7427813f,0.0f); + + //we send a quaternion packed into a vec3 (w is infered) - so sizeof(vec) == 12 bytes not 16. + LLVector3 vec = data.packToVector3(); + + addValue(messageBlockData, (char *)"testBinData", &vec, MVT_LLQuaternion, sizeof(vec)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLQuaternion data works in a message copied from legacy to llsd", + ll_quaternion_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLUUID + template<> template<> + void LLSDMessageBuilderTestObject::test<38>() + { + LLUUID data("01234567-0123-0123-0123-234567abcdef"); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLUUID, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::string v = output["testBlock"][0]["testBinData"].asUUID().asString(); + + ensure_equals("Ensure MVT_LLUUID data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asUUID(), data); + } + + // MVT_BOOL + template<> template<> + void LLSDMessageBuilderTestObject::test<39>() + { + bool valueTrue = true; + bool valueFalse = false; + + LLMsgData* md = new LLMsgData("testMessage"); + LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0); + addValue(mbd, (char *)"testBoolFalse", &valueFalse, MVT_BOOL, sizeof(bool)); + addValue(mbd, (char *)"testBoolTrue", &valueTrue, MVT_BOOL, sizeof(bool)); + md->addBlock(mbd); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*md); + LLSD output = builder.getMessage(); + + ensure("Ensure bools work in a message copied from legacy to llsd", + output["testBlock"][0]["testBoolTrue"].asBoolean() && !output["testBlock"][0]["testBoolFalse"].asBoolean()); + } + + // MVT_IP_ADDR + template<> template<> + void LLSDMessageBuilderTestObject::test<40>() + { + U32 data(0xff887766); + LLSD v = ll_sd_from_ipaddr(data); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_ADDR, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_IP_ADDR data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"], v); + } + + // MVT_IP_PORT + template<> template<> + void LLSDMessageBuilderTestObject::test<41>() + { + U16 data = 0xff88; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_PORT, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_IP_PORT data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U16Vec3 + template<> template<> + void LLSDMessageBuilderTestObject::test<42>() + { + U16 data[3] = {0,1,2}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Vec3, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_U16Vec3 data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_U16Vec3 data works in a message copied from legacy to llsd", + (U16*)&v[0], 6, data, 6); + } + + // MVT_U16Quat + template<> template<> + void LLSDMessageBuilderTestObject::test<43>() + { + U16 data[4] = {0,1,2,4}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Quat, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_U16Quat data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_U16Quat data works in a message copied from legacy to llsd", + (U16*)&v[0], 8, data, 8); + } + + // MVT_S16Array + template<> template<> + void LLSDMessageBuilderTestObject::test<44>() + { + S16 data[19] = {0,-1,2,-4,5,-6,7,-8,9,-10,11,-12,13,-14,15,16,17,18}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16Array, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_S16Array data works in a message copied from legacy to llsd", + (U16*)&v[0], 19, data, 19); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<45>() + { + LLMessageTemplate messageTemplate = defaultTemplate(); + messageTemplate.addBlock(defaultTemplateBlock(MVT_U8, 1)); + U8 inValue = 2; + LLTemplateMessageBuilder* template_builder = defaultTemplateBuilder(messageTemplate); + template_builder->addU8(_PREHASH_Test0, inValue); + + LLSDMessageBuilder builder; + builder.copyFromMessageData(*template_builder->getCurrentMessage()); + LLSD output = builder.getMessage(); + + ensure_equals(output["Test0"][0]["Test0"].asInteger(), 2); + + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<46>() + { + LLMessageTemplate messageTemplate = defaultTemplate(); + messageTemplate.addBlock(defaultTemplateBlock(MVT_VARIABLE, 1)); + std::string inValue = "testing"; + LLTemplateMessageBuilder* builder = defaultTemplateBuilder(messageTemplate); + builder->addString(_PREHASH_Test0, inValue.c_str()); + + LLSDMessageBuilder sd_builder; + sd_builder.copyFromMessageData(*builder->getCurrentMessage()); + LLSD output = sd_builder.getMessage(); + + ensure_equals(output["Test0"][0]["Test0"].asString(), std::string("testing")); + } + +} + diff --git a/indra/test/llsdmessagereader_tut.cpp b/indra/test/llsdmessagereader_tut.cpp index 98f92fd9f5..38c4d870cb 100644 --- a/indra/test/llsdmessagereader_tut.cpp +++ b/indra/test/llsdmessagereader_tut.cpp @@ -1,324 +1,324 @@ -/**
- * @file llsdmessagereader_tut.cpp
- * @date February 2006
- * @brief LLSDMessageReader unit tests
- *
- * $LicenseInfo:firstyear=2006&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-#include "linden_common.h"
-#include "lltut.h"
-#include "v3dmath.h"
-#include "v3math.h"
-#include "v4math.h"
-#include "llquaternion.h"
-
-#include "message.h"
-#include "llsdmessagereader.h"
-#include "llsdutil.h"
-#include "llsdutil_math.h"
-
-namespace tut
-{
- struct LLSDMessageReaderTestData {
- static void ensureMessageName(const std::string& msg_name,
- const LLSD& msg_data,
- const std::string& expected_name)
- {
- LLSDMessageReader msg;
- msg.setMessage(LLMessageStringTable::getInstance()->getString(msg_name.c_str()), msg_data);
- ensure_equals("Ensure name", std::string(msg.getMessageName()),
- expected_name);
- }
-
- static void ensureNumberOfBlocks(const LLSD& msg_data,
- const std::string& block,
- S32 expected_number)
- {
- LLSDMessageReader msg;
- msg.setMessage("fakename", msg_data);
- ensure_equals("Ensure number of blocks", msg.getNumberOfBlocks(block.c_str()),
- expected_number);
- }
-
- static void ensureMessageSize(const LLSD& msg_data,
- S32 expected_size)
- {
- LLSDMessageReader msg;
- msg.setMessage("fakename", msg_data);
- ensure_equals( "Ensure size", msg.getMessageSize(), expected_size);
- }
-
- static void ensureBool(const LLSD& msg_data,
- const std::string& block,
- const std::string& var,
- S32 blocknum,
- bool expected)
- {
- LLSDMessageReader msg;
- msg.setMessage("fakename", msg_data);
- bool test_data;
- msg.getBOOL(block.c_str(), var.c_str(), test_data, blocknum);
- ensure_equals( "Ensure bool field", test_data, expected);
- }
- };
-
- typedef test_group<LLSDMessageReaderTestData> LLSDMessageReaderTestGroup;
- typedef LLSDMessageReaderTestGroup::object LLSDMessageReaderTestObject;
- LLSDMessageReaderTestGroup llsdMessageReaderTestGroup("LLSDMessageReader");
-
- template<> template<>
- void LLSDMessageReaderTestObject::test<1>()
- // construction and test of empty LLSD
- {
- LLSD message = LLSD::emptyMap();
-
- ensureMessageName("", message, "");
- ensureNumberOfBlocks(message, "Fakeblock", 0);
- ensureMessageSize(message, 0);
- }
-
- template<> template<>
- void LLSDMessageReaderTestObject::test<2>()
- // construction and test of simple message with one block
- {
- LLSD message = LLSD::emptyMap();
- message["block1"] = LLSD::emptyArray();
- message["block1"][0] = LLSD::emptyMap();
- message["block1"][0]["Field1"] = 0;
-
- ensureMessageName("name2", message, "name2");
- ensureNumberOfBlocks(message, "block1", 1);
- ensureMessageSize(message, 0);
- }
-
- template<> template<>
- void LLSDMessageReaderTestObject::test<3>()
- // multiple blocks
- {
- LLSD message = LLSD::emptyMap();
- message["block1"] = LLSD::emptyArray();
- bool bool_true = true;
- bool bool_false = false;
- message["block1"][0] = LLSD::emptyMap();
- message["block1"][0]["BoolField1"] = bool_true;
- message["block1"][1] = LLSD::emptyMap();
- message["block1"][1]["BoolField1"] = bool_false;
- message["block1"][1]["BoolField2"] = bool_true;
-
- ensureMessageName("name3", message, "name3");
- ensureBool(message, "block1", "BoolField1", 0, true);
- ensureBool(message, "block1", "BoolField1", 1, false);
- ensureBool(message, "block1", "BoolField2", 1, true);
- ensureNumberOfBlocks(message, "block1", 2);
- ensureMessageSize(message, 0);
- }
-
- template<typename T>
- LLSDMessageReader testType(const T& value)
- {
- LLSD message = LLSD::emptyMap();
- message["block"][0]["var"] = value;
- LLSDMessageReader msg;
- msg.setMessage("fakename", message);
- return msg;
- }
-
- template<> template<>
- void LLSDMessageReaderTestObject::test<4>()
- // S8
- {
- S8 outValue, inValue = -3;
- LLSDMessageReader msg = testType(inValue);
- msg.getS8("block", "var", outValue);
- ensure_equals("Ensure S8", outValue, inValue);
- }
- template<> template<>
- void
- LLSDMessageReaderTestObject::test<5>()
- // U8
- {
- U8 outValue, inValue = 2;
- LLSDMessageReader msg = testType(inValue);
- msg.getU8("block", "var", outValue);
- ensure_equals("Ensure U8", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<6>()
- // S16
- {
- S16 outValue, inValue = 90;
- LLSDMessageReader msg = testType(inValue);
- msg.getS16("block", "var", outValue);
- ensure_equals("Ensure S16", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<7>()
- // U16
- {
- U16 outValue, inValue = 3;
- LLSDMessageReader msg = testType(inValue);
- msg.getU16("block", "var", outValue);
- ensure_equals("Ensure S16", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<8>()
- // S32
- {
- S32 outValue, inValue = 44;
- LLSDMessageReader msg = testType(inValue);
- msg.getS32("block", "var", outValue);
- ensure_equals("Ensure S32", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<9>()
- // F32
- {
- F32 outValue, inValue = 121.44f;
- LLSDMessageReader msg = testType(inValue);
- msg.getF32("block", "var", outValue);
- ensure_equals("Ensure F32", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<10>()
- // U32
- {
- U32 outValue, inValue = 88;
- LLSD sdValue = ll_sd_from_U32(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getU32("block", "var", outValue);
- ensure_equals("Ensure U32", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<11>()
- // U64
- {
- U64 outValue, inValue = 121;
- LLSD sdValue = ll_sd_from_U64(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getU64("block", "var", outValue);
- ensure_equals("Ensure U64", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<12>()
- // F64
- {
- F64 outValue, inValue = 3232143.33;
- LLSDMessageReader msg = testType(inValue);
- msg.getF64("block", "var", outValue);
- ensure_equals("Ensure F64", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<13>()
- // String
- {
- std::string outValue, inValue = "testing";
- LLSDMessageReader msg = testType<std::string>(inValue.c_str());
-
- char buffer[MAX_STRING];
- msg.getString("block", "var", MAX_STRING, buffer);
- outValue = buffer;
- ensure_equals("Ensure String", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<14>()
- // Vector3
- {
- LLVector3 outValue, inValue = LLVector3(1,2,3);
- LLSD sdValue = ll_sd_from_vector3(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getVector3("block", "var", outValue);
- ensure_equals("Ensure Vector3", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<15>()
- // Vector4
- {
- LLVector4 outValue, inValue = LLVector4(1,2,3,4);
- LLSD sdValue = ll_sd_from_vector4(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getVector4("block", "var", outValue);
- ensure_equals("Ensure Vector4", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<16>()
- // Vector3d
- {
- LLVector3d outValue, inValue = LLVector3d(1,2,3);
- LLSD sdValue = ll_sd_from_vector3d(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getVector3d("block", "var", outValue);
- ensure_equals("Ensure Vector3d", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<17>()
- // Quaternion
- {
- LLQuaternion outValue, inValue = LLQuaternion(1,LLVector3(2,3,4));
- LLSD sdValue = ll_sd_from_quaternion(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getQuat("block", "var", outValue);
- ensure_equals("Ensure Quaternion", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<18>()
- // UUID
- {
- LLUUID outValue, inValue;
- inValue.generate();
- LLSDMessageReader msg = testType(inValue);
- msg.getUUID("block", "var", outValue);
- ensure_equals("Ensure UUID", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<19>()
- // IPAddr
- {
- U32 outValue, inValue = 12344556;
- LLSD sdValue = ll_sd_from_ipaddr(inValue);
- LLSDMessageReader msg = testType(sdValue);
- msg.getIPAddr("block", "var", outValue);
- ensure_equals("Ensure IPAddr", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<20>()
- // IPPort
- {
- U16 outValue, inValue = 80;
- LLSDMessageReader msg = testType(inValue);
- msg.getIPPort("block", "var", outValue);
- ensure_equals("Ensure IPPort", outValue, inValue);
- }
- template<> template<>
- void LLSDMessageReaderTestObject::test<21>()
- // Binary
- {
- std::vector<U8> outValue(2), inValue(2);
- inValue[0] = 0;
- inValue[1] = 1;
-
- LLSDMessageReader msg = testType(inValue);
- msg.getBinaryData("block", "var", &(outValue[0]), inValue.size());
- ensure_equals("Ensure Binary", outValue, inValue);
- }
-}
+/** + * @file llsdmessagereader_tut.cpp + * @date February 2006 + * @brief LLSDMessageReader unit tests + * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> +#include "linden_common.h" +#include "lltut.h" +#include "v3dmath.h" +#include "v3math.h" +#include "v4math.h" +#include "llquaternion.h" + +#include "message.h" +#include "llsdmessagereader.h" +#include "llsdutil.h" +#include "llsdutil_math.h" + +namespace tut +{ + struct LLSDMessageReaderTestData { + static void ensureMessageName(const std::string& msg_name, + const LLSD& msg_data, + const std::string& expected_name) + { + LLSDMessageReader msg; + msg.setMessage(LLMessageStringTable::getInstance()->getString(msg_name.c_str()), msg_data); + ensure_equals("Ensure name", std::string(msg.getMessageName()), + expected_name); + } + + static void ensureNumberOfBlocks(const LLSD& msg_data, + const std::string& block, + S32 expected_number) + { + LLSDMessageReader msg; + msg.setMessage("fakename", msg_data); + ensure_equals("Ensure number of blocks", msg.getNumberOfBlocks(block.c_str()), + expected_number); + } + + static void ensureMessageSize(const LLSD& msg_data, + S32 expected_size) + { + LLSDMessageReader msg; + msg.setMessage("fakename", msg_data); + ensure_equals( "Ensure size", msg.getMessageSize(), expected_size); + } + + static void ensureBool(const LLSD& msg_data, + const std::string& block, + const std::string& var, + S32 blocknum, + bool expected) + { + LLSDMessageReader msg; + msg.setMessage("fakename", msg_data); + bool test_data; + msg.getBOOL(block.c_str(), var.c_str(), test_data, blocknum); + ensure_equals( "Ensure bool field", test_data, expected); + } + }; + + typedef test_group<LLSDMessageReaderTestData> LLSDMessageReaderTestGroup; + typedef LLSDMessageReaderTestGroup::object LLSDMessageReaderTestObject; + LLSDMessageReaderTestGroup llsdMessageReaderTestGroup("LLSDMessageReader"); + + template<> template<> + void LLSDMessageReaderTestObject::test<1>() + // construction and test of empty LLSD + { + LLSD message = LLSD::emptyMap(); + + ensureMessageName("", message, ""); + ensureNumberOfBlocks(message, "Fakeblock", 0); + ensureMessageSize(message, 0); + } + + template<> template<> + void LLSDMessageReaderTestObject::test<2>() + // construction and test of simple message with one block + { + LLSD message = LLSD::emptyMap(); + message["block1"] = LLSD::emptyArray(); + message["block1"][0] = LLSD::emptyMap(); + message["block1"][0]["Field1"] = 0; + + ensureMessageName("name2", message, "name2"); + ensureNumberOfBlocks(message, "block1", 1); + ensureMessageSize(message, 0); + } + + template<> template<> + void LLSDMessageReaderTestObject::test<3>() + // multiple blocks + { + LLSD message = LLSD::emptyMap(); + message["block1"] = LLSD::emptyArray(); + bool bool_true = true; + bool bool_false = false; + message["block1"][0] = LLSD::emptyMap(); + message["block1"][0]["BoolField1"] = bool_true; + message["block1"][1] = LLSD::emptyMap(); + message["block1"][1]["BoolField1"] = bool_false; + message["block1"][1]["BoolField2"] = bool_true; + + ensureMessageName("name3", message, "name3"); + ensureBool(message, "block1", "BoolField1", 0, true); + ensureBool(message, "block1", "BoolField1", 1, false); + ensureBool(message, "block1", "BoolField2", 1, true); + ensureNumberOfBlocks(message, "block1", 2); + ensureMessageSize(message, 0); + } + + template<typename T> + LLSDMessageReader testType(const T& value) + { + LLSD message = LLSD::emptyMap(); + message["block"][0]["var"] = value; + LLSDMessageReader msg; + msg.setMessage("fakename", message); + return msg; + } + + template<> template<> + void LLSDMessageReaderTestObject::test<4>() + // S8 + { + S8 outValue, inValue = -3; + LLSDMessageReader msg = testType(inValue); + msg.getS8("block", "var", outValue); + ensure_equals("Ensure S8", outValue, inValue); + } + template<> template<> + void + LLSDMessageReaderTestObject::test<5>() + // U8 + { + U8 outValue, inValue = 2; + LLSDMessageReader msg = testType(inValue); + msg.getU8("block", "var", outValue); + ensure_equals("Ensure U8", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<6>() + // S16 + { + S16 outValue, inValue = 90; + LLSDMessageReader msg = testType(inValue); + msg.getS16("block", "var", outValue); + ensure_equals("Ensure S16", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<7>() + // U16 + { + U16 outValue, inValue = 3; + LLSDMessageReader msg = testType(inValue); + msg.getU16("block", "var", outValue); + ensure_equals("Ensure S16", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<8>() + // S32 + { + S32 outValue, inValue = 44; + LLSDMessageReader msg = testType(inValue); + msg.getS32("block", "var", outValue); + ensure_equals("Ensure S32", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<9>() + // F32 + { + F32 outValue, inValue = 121.44f; + LLSDMessageReader msg = testType(inValue); + msg.getF32("block", "var", outValue); + ensure_equals("Ensure F32", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<10>() + // U32 + { + U32 outValue, inValue = 88; + LLSD sdValue = ll_sd_from_U32(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getU32("block", "var", outValue); + ensure_equals("Ensure U32", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<11>() + // U64 + { + U64 outValue, inValue = 121; + LLSD sdValue = ll_sd_from_U64(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getU64("block", "var", outValue); + ensure_equals("Ensure U64", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<12>() + // F64 + { + F64 outValue, inValue = 3232143.33; + LLSDMessageReader msg = testType(inValue); + msg.getF64("block", "var", outValue); + ensure_equals("Ensure F64", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<13>() + // String + { + std::string outValue, inValue = "testing"; + LLSDMessageReader msg = testType<std::string>(inValue.c_str()); + + char buffer[MAX_STRING]; + msg.getString("block", "var", MAX_STRING, buffer); + outValue = buffer; + ensure_equals("Ensure String", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<14>() + // Vector3 + { + LLVector3 outValue, inValue = LLVector3(1,2,3); + LLSD sdValue = ll_sd_from_vector3(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getVector3("block", "var", outValue); + ensure_equals("Ensure Vector3", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<15>() + // Vector4 + { + LLVector4 outValue, inValue = LLVector4(1,2,3,4); + LLSD sdValue = ll_sd_from_vector4(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getVector4("block", "var", outValue); + ensure_equals("Ensure Vector4", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<16>() + // Vector3d + { + LLVector3d outValue, inValue = LLVector3d(1,2,3); + LLSD sdValue = ll_sd_from_vector3d(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getVector3d("block", "var", outValue); + ensure_equals("Ensure Vector3d", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<17>() + // Quaternion + { + LLQuaternion outValue, inValue = LLQuaternion(1,LLVector3(2,3,4)); + LLSD sdValue = ll_sd_from_quaternion(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getQuat("block", "var", outValue); + ensure_equals("Ensure Quaternion", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<18>() + // UUID + { + LLUUID outValue, inValue; + inValue.generate(); + LLSDMessageReader msg = testType(inValue); + msg.getUUID("block", "var", outValue); + ensure_equals("Ensure UUID", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<19>() + // IPAddr + { + U32 outValue, inValue = 12344556; + LLSD sdValue = ll_sd_from_ipaddr(inValue); + LLSDMessageReader msg = testType(sdValue); + msg.getIPAddr("block", "var", outValue); + ensure_equals("Ensure IPAddr", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<20>() + // IPPort + { + U16 outValue, inValue = 80; + LLSDMessageReader msg = testType(inValue); + msg.getIPPort("block", "var", outValue); + ensure_equals("Ensure IPPort", outValue, inValue); + } + template<> template<> + void LLSDMessageReaderTestObject::test<21>() + // Binary + { + std::vector<U8> outValue(2), inValue(2); + inValue[0] = 0; + inValue[1] = 1; + + LLSDMessageReader msg = testType(inValue); + msg.getBinaryData("block", "var", &(outValue[0]), inValue.size()); + ensure_equals("Ensure Binary", outValue, inValue); + } +} diff --git a/indra/test/lltemplatemessagebuilder_tut.cpp b/indra/test/lltemplatemessagebuilder_tut.cpp index d4a59249cc..ddf1c3dbcc 100644 --- a/indra/test/lltemplatemessagebuilder_tut.cpp +++ b/indra/test/lltemplatemessagebuilder_tut.cpp @@ -1,971 +1,971 @@ -/**
- * @file lltemplatemessagebuilder_tut.cpp
- * @date 2007-04
- * @brief Tests for building messages.
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-#include "linden_common.h"
-#include "lltut.h"
-
-#include "llapr.h"
-#include "llmessagetemplate.h"
-#include "llmath.h"
-#include "llquaternion.h"
-#include "lltemplatemessagebuilder.h"
-#include "lltemplatemessagereader.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();
- const F32 circuit_heartbeat_interval=5;
- const F32 circuit_timeout=100;
-
- start_messaging_system("notafile", 13035,
- 1,
- 0,
- 0,
- false,
- "notasharedsecret",
- NULL,
- false,
- circuit_heartbeat_interval,
- circuit_timeout);
- //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(const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), type, size);
- }
- return result;
- }
-
- static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_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(0.0f, LLVector3(0.3713907f, 0.5570861f, 0.7427813f));
-
- 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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));
-
- // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
- LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
-
- // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
- builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));
-
- // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
- LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
-
- // Build message
- LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));
-
- // Build message
- builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
- messageTemplate.addBlock(createBlock(const_cast<char*>(_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(const_cast<char*>(_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(const_cast<char*>(_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(0.0f, LLVector3(0.3713907f, 0.5570861f, 0.7427813f));
- 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(const_cast<char*>(_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(const_cast<char*>(_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, 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(const_cast<char*>(_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);
- (void)outValue;
- char outBuffer[bufferSize];
- memset(buffer, 0xcc, bufferSize);
- reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize,
- outBuffer);
- ensure_equals("Ensure present value ", outValue, inValue);
- ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0);
- delete reader;
- }
-}
-
+/** + * @file lltemplatemessagebuilder_tut.cpp + * @date 2007-04 + * @brief Tests for building messages. + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> +#include "linden_common.h" +#include "lltut.h" + +#include "llapr.h" +#include "llmessagetemplate.h" +#include "llmath.h" +#include "llquaternion.h" +#include "lltemplatemessagebuilder.h" +#include "lltemplatemessagereader.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(); + const F32 circuit_heartbeat_interval=5; + const F32 circuit_timeout=100; + + start_messaging_system("notafile", 13035, + 1, + 0, + 0, + false, + "notasharedsecret", + NULL, + false, + circuit_heartbeat_interval, + circuit_timeout); + //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(const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), type, size); + } + return result; + } + + static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_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(0.0f, LLVector3(0.3713907f, 0.5570861f, 0.7427813f)); + + 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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE)); + + // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb + LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + + // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb + builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE)); + + // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb + LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + + // Build message + LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE)); + + // Build message + builder = defaultBuilder(messageTemplate, const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_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(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE)); + messageTemplate.addBlock(createBlock(const_cast<char*>(_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(const_cast<char*>(_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(const_cast<char*>(_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(0.0f, LLVector3(0.3713907f, 0.5570861f, 0.7427813f)); + 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(const_cast<char*>(_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(const_cast<char*>(_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, 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(const_cast<char*>(_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); + (void)outValue; + char outBuffer[bufferSize]; + memset(buffer, 0xcc, bufferSize); + reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize, + outBuffer); + ensure_equals("Ensure present value ", outValue, inValue); + ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0); + delete reader; + } +} + diff --git a/indra/test/message_tut.cpp b/indra/test/message_tut.cpp index 14ba5884a8..11cd710ef6 100644 --- a/indra/test/message_tut.cpp +++ b/indra/test/message_tut.cpp @@ -1,147 +1,147 @@ -/**
- * @file lldatapacker_tut.cpp
- * @date 2007-04
- * @brief LLDataPacker test cases.
- *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include <tut/tut.hpp>
-#include "linden_common.h"
-#include "lltut.h"
-#include "llhttpconstants.h"
-#include "llapr.h"
-#include "llmessageconfig.h"
-#include "llsdserialize.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;
- }
- virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { }
- virtual void extendedResult(S32 code, const LLSD& result, const LLSD& headers) { }
- S32 mStatus;
- };
-}
-
-namespace tut
-{
- struct LLMessageSystemTestData
- {
- std::string mTestConfigDir;
- std::string mSep;
-
- LLMessageSystemTestData()
- {
- static bool init = false;
- if(!init)
- {
- ll_init_apr();
- //init_prehash_data();
- init = true;
- }
- const F32 circuit_heartbeat_interval=5;
- const F32 circuit_timeout=100;
-
-
- // currently test disconnected message system
- start_messaging_system("notafile", 13035,
- 1,
- 0,
- 0,
- false,
- "notasharedsecret",
- NULL,
- false,
- circuit_heartbeat_interval,
- circuit_timeout
- );
- // generate temp dir
- std::ostringstream ostr;
-#if LL_WINDOWS
- mSep = "\\";
- ostr << "C:" << mSep;
-#else
- mSep = "/";
- ostr << mSep << "tmp" << mSep;
-#endif
- LLUUID random;
- random.generate();
- ostr << "message-test-" << random;
- mTestConfigDir = ostr.str();
- LLFile::mkdir(mTestConfigDir);
- writeConfigFile(LLSD());
- LLMessageConfig::initClass("simulator", ostr.str());
- }
-
- ~LLMessageSystemTestData()
- {
- // not end_messaging_system()
- delete static_cast<LLMessageSystem*>(gMessageSystem);
- gMessageSystem = NULL;
-
- // rm contents of temp dir
- std::ostringstream ostr;
- ostr << mTestConfigDir << mSep << "message.xml";
- int rmfile = LLFile::remove(ostr.str());
- ensure_equals("rmfile value", rmfile, 0);
-
- // rm temp dir
- int rmdir = LLFile::rmdir(mTestConfigDir);
- ensure_equals("rmdir value", rmdir, 0);
- }
-
- void writeConfigFile(const LLSD& config)
- {
- std::string ostr(mTestConfigDir + mSep + "message.xml");
- llofstream file(ostr.c_str());
- if (file.is_open())
- {
- LLSDSerialize::toPrettyXML(config, file);
- }
- file.close();
- }
- };
-
- 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, HTTP_NOT_FOUND);
- }
-}
-
+/** + * @file lldatapacker_tut.cpp + * @date 2007-04 + * @brief LLDataPacker test cases. + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> +#include "linden_common.h" +#include "lltut.h" +#include "llhttpconstants.h" +#include "llapr.h" +#include "llmessageconfig.h" +#include "llsdserialize.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; + } + virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { } + virtual void extendedResult(S32 code, const LLSD& result, const LLSD& headers) { } + S32 mStatus; + }; +} + +namespace tut +{ + struct LLMessageSystemTestData + { + std::string mTestConfigDir; + std::string mSep; + + LLMessageSystemTestData() + { + static bool init = false; + if(!init) + { + ll_init_apr(); + //init_prehash_data(); + init = true; + } + const F32 circuit_heartbeat_interval=5; + const F32 circuit_timeout=100; + + + // currently test disconnected message system + start_messaging_system("notafile", 13035, + 1, + 0, + 0, + false, + "notasharedsecret", + NULL, + false, + circuit_heartbeat_interval, + circuit_timeout + ); + // generate temp dir + std::ostringstream ostr; +#if LL_WINDOWS + mSep = "\\"; + ostr << "C:" << mSep; +#else + mSep = "/"; + ostr << mSep << "tmp" << mSep; +#endif + LLUUID random; + random.generate(); + ostr << "message-test-" << random; + mTestConfigDir = ostr.str(); + LLFile::mkdir(mTestConfigDir); + writeConfigFile(LLSD()); + LLMessageConfig::initClass("simulator", ostr.str()); + } + + ~LLMessageSystemTestData() + { + // not end_messaging_system() + delete static_cast<LLMessageSystem*>(gMessageSystem); + gMessageSystem = NULL; + + // rm contents of temp dir + std::ostringstream ostr; + ostr << mTestConfigDir << mSep << "message.xml"; + int rmfile = LLFile::remove(ostr.str()); + ensure_equals("rmfile value", rmfile, 0); + + // rm temp dir + int rmdir = LLFile::rmdir(mTestConfigDir); + ensure_equals("rmdir value", rmdir, 0); + } + + void writeConfigFile(const LLSD& config) + { + std::string ostr(mTestConfigDir + mSep + "message.xml"); + llofstream file(ostr.c_str()); + if (file.is_open()) + { + LLSDSerialize::toPrettyXML(config, file); + } + file.close(); + } + }; + + 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, HTTP_NOT_FOUND); + } +} + |