[sldev] Unit Test Harness: Patch-4
Gaurav Sharma
gsharma at adroit-inc.com
Fri Mar 23 00:22:33 PDT 2007
Hi,
Please find attached Patch 4 for unit test additions. It contains:
1. Unit tests
Completed: llcipher, llxorcipher, llnullcipher, llbuffer,
llquaternion,v4math, lljoint(unit tests for a few math computation
functions have not been added)
In Progress: llevent.h.
2. Fixed llnamevalue.cpp
i) Added U64 support in all key functions. TODO: S64 and F64 datatypes
should also be added to ENameValueType to avoid truncation in some U64
operations (like U64 * F32 or U64 * S32 etc.)
ii) Removed a lot of duplicated code
iii) Fixed bugs reported by the unit test
iv) Rerun unit test to ensure all tests now pass
Next up:
Unit tests for the following:
i) llcommon - llevent
ii) llmath - v3color, v4color, v4coloru
iii) llinventory - inventory, permissions, and saleinfo usage and
serialization
Thanks
Gaurav Sharma
-------------- next part --------------
diff -uwN 2007-03-13-Patch1\linden\indra\test/llbuffer_tut.cpp 2007-03-13\linden\indra\test/llbuffer_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/llbuffer_tut.cpp Wed Dec 31 16:00:00 1969
+++ 2007-03-13\linden\indra\test/llbuffer_tut.cpp Wed Mar 21 15:35:34 2007
@@ -0,0 +1,250 @@
+/**
+ * @file llbuffer_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief llbuffer test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "llbuffer.h"
+#include "llmemtype.h"
+
+namespace tut
+{
+ struct buffer
+ {
+ };
+
+ typedef test_group<buffer> buffer_t;
+ typedef buffer_t::object buffer_object_t;
+ tut::buffer_t tut_buffer("buffer");
+
+ template<> template<>
+ void buffer_object_t::test<1>()
+ {
+ LLChannelDescriptors channelDescriptors;
+ ensure("in() and out() functions Failed", (0 == channelDescriptors.in() && 1 == channelDescriptors.out()));
+
+ S32 val = 50;
+ LLChannelDescriptors channelDescriptors1(val);
+ ensure("LLChannelDescriptors in() and out() functions Failed", (50 == channelDescriptors1.in() && 51 == channelDescriptors1.out()));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<2>()
+ {
+ LLSegment segment;
+ ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size()));
+ segment.setChannel(50);
+ ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50);
+ ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50)));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<3>()
+ {
+ S32 channel = 30;
+ const char str[] = "SecondLife";
+ S32 len = sizeof(str);
+ LLSegment segment(channel, (U8*)str, len);
+ ensure("LLSegment get functions failed", (30 == segment.getChannel() && len == segment.size() && (U8*)str == segment.data()));
+ ensure_memory_matches("LLSegment::data() failed", segment.data(), segment.size(), (U8*)str, len);
+ ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(channel)));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<4>()
+ {
+ S32 channel = 50;
+ S32 bigSize = 16384*2;
+ char str[] = "SecondLife";
+ S32 smallSize = sizeof(str);
+
+ LLSegment segment;
+ LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384
+
+ S32 requestSize;
+
+ requestSize = 16384-1;
+ ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+ // second request for remainign 1 byte
+
+ requestSize = 1;
+ ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+
+ // it should fail now.
+ requestSize = 1;
+ ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment)));
+
+ LLHeapBuffer buf1(bigSize);
+
+ // requst for more than default size but less than total sizeit should fail now.
+ requestSize = 16384 + 1;
+ ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize);
+
+ LLHeapBuffer buf2((U8*) str, smallSize);
+ requestSize = smallSize;
+ ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0);
+ requestSize = smallSize+1;
+ ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment)));
+ }
+
+ //makeChannelConsumer()
+ template<> template<>
+ void buffer_object_t::test<5>()
+ {
+ LLChannelDescriptors inchannelDescriptors(20);
+ LLChannelDescriptors outchannelDescriptors = LLBufferArray::makeChannelConsumer(inchannelDescriptors);
+ ensure("LLBufferArray::makeChannelConsumer() function Failed", (21 == outchannelDescriptors.in()));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<6>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ S32 count = bufferArray.countAfter(channelDescriptors.in(), NULL);
+ ensure_equals("Appended size is:", count, len);
+ }
+
+ //append() and prepend()
+ template<> template<>
+ void buffer_object_t::test<7>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ const char array1[] = "LindenLabs";
+ S32 len1 = strlen(array1);
+
+ std::string str(array1);
+ str.append(array);
+
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ bufferArray.prepend(channelDescriptors.in(), (U8*)array1, len1);
+ char buf[100];
+ S32 len2 = 20;
+ bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("readAfter length failed", len2, 20);
+
+ buf[len2] = '\0';
+ ensure_equals("readAfter/prepend/append failed", buf, str);
+ }
+
+ //append()
+ template<> template<>
+ void buffer_object_t::test<8>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array);
+ const char array1[] = "LindenLabs";
+ S32 len1 = strlen(array1);
+
+ std::string str(array);
+ str.append(array1);
+
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ bufferArray.append(channelDescriptors.in(), (U8*)array1, len1);
+ char buf[100];
+ S32 len2 = 20;
+ bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("readAfter length failed", len2, 20);
+
+ buf[len2] = '\0';
+ ensure_equals("readAfter/append/append failed", buf, str);
+ }
+
+ template<> template<>
+ void buffer_object_t::test<9>()
+ {
+ LLBufferArray bufferArray;
+ const char array[] = "SecondLife";
+ S32 len = strlen(array) + 1;
+ std::string str(array);
+ LLChannelDescriptors channelDescriptors = bufferArray.nextChannel();
+ bufferArray.append(channelDescriptors.in(), (U8*)array, len);
+ LLBufferArray bufferArray1;
+ ensure("Contents are not copied and the source buffer is not empty", (1 == bufferArray1.takeContents(bufferArray)));
+
+ char buf[100];
+ S32 len2 = len;
+ bufferArray1.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2);
+ ensure_equals("takeContents failed to copy", buf, str);
+ }
+
+ //seek()
+ template<> template<>
+ void buffer_object_t::test<10>()
+ {
+ const char array[] = "SecondLife is a Virtual World";
+ S32 len = strlen(array);
+ LLBufferArray bufferArray;
+ bufferArray.append(0, (U8*)array, len);
+
+ char buf[255];
+ S32 len1 = 16;
+ U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
+ buf[len1] = '\0';
+ last = bufferArray.seek(0, last, -2);
+
+ len1 = 15;
+ last = bufferArray.readAfter(0, last, (U8*)buf, len1);
+ buf[len1] = '\0';
+ std::string str(buf);
+ ensure_equals("Seek does'nt worked", str, std::string("a Virtual World"));
+ }
+
+ template<> template<>
+ void buffer_object_t::test<11>()
+ {
+ const char array[] = "SecondLife is a Virtual World";
+ S32 len = strlen(array);
+ LLBufferArray bufferArray;
+ bufferArray.append(0, (U8*)array, len);
+
+ char buf[255];
+ S32 len1 = 10;
+ U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1);
+ bufferArray.splitAfter(last);
+ LLBufferArray::segment_iterator_t iterator = bufferArray.beginSegment();
+ ++iterator;
+ std::string str(((char*)(*iterator).data()), (*iterator).size());
+ ensure_equals("Strings are not equal;splitAfter() operation failed", str, std::string(" is a Virtual World"));
+ }
+
+ //makeSegment()->eraseSegment()
+ template<> template<>
+ void buffer_object_t::test<12>()
+ {
+ LLBufferArray bufferArray;
+ LLChannelDescriptors channelDescriptors;
+ LLBufferArray::segment_iterator_t it;
+ S32 length = 1000;
+ it = bufferArray.makeSegment(channelDescriptors.out(), length);
+ ensure("makeSegment() function failed", (it != bufferArray.endSegment()));
+ ensure("eraseSegment() function failed", bufferArray.eraseSegment(it));
+ ensure("eraseSegment() begin/end should now be same", bufferArray.beginSegment() == bufferArray.endSegment());
+ }
+
+ // constructSegmentAfter()
+ template<> template<>
+ void buffer_object_t::test<13>()
+ {
+ LLBufferArray bufferArray;
+ LLBufferArray::segment_iterator_t it;
+ LLSegment segment;
+ LLBufferArray::segment_iterator_t end = bufferArray.endSegment();
+ it = bufferArray.constructSegmentAfter(NULL, segment);
+ ensure("constructSegmentAfter() function failed", (it == end));
+ }
+}
diff -uwN 2007-03-13-Patch1\linden\indra\test/lljoint_tut.cpp 2007-03-13\linden\indra\test/lljoint_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/lljoint_tut.cpp Wed Dec 31 16:00:00 1969
+++ 2007-03-13\linden\indra\test/lljoint_tut.cpp Wed Mar 21 18:59:24 2007
@@ -0,0 +1,220 @@
+/**
+ * @file lljoint_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief lljoint test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "linden_common.h"
+#include "m4math.h"
+#include "v3math.h"
+#include "lljoint.h"
+
+
+namespace tut
+{
+ struct lljoint_data
+ {
+ };
+ typedef test_group<lljoint_data> lljoint_test;
+ typedef lljoint_test::object lljoint_object;
+ tut::lljoint_test lljoint_testcase("lljoint");
+
+ template<> template<>
+ void lljoint_object::test<1>()
+ {
+ LLJoint lljoint;
+ LLJoint* jnt = lljoint.getParent();
+ ensure("getParent() failed ", (NULL == jnt));
+ ensure("getRoot() failed ", (&lljoint == lljoint.getRoot()));
+ }
+
+ template<> template<>
+ void lljoint_object::test<2>()
+ {
+ std::string str = "LLJoint";
+ LLJoint parent(str), child;
+ child.setup(str, &parent);
+ LLJoint* jnt = child.getParent();
+ ensure("setup() failed ", (&parent == jnt));
+ }
+
+ template<> template<>
+ void lljoint_object::test<3>()
+ {
+ LLJoint parent, child;
+ std::string str = "LLJoint";
+ child.setup(str, &parent);
+ LLJoint* jnt = parent.findJoint(str);
+ ensure("findJoint() failed ", (&child == jnt));
+ }
+
+ template<> template<>
+ void lljoint_object::test<4>()
+ {
+ LLJoint parent;
+ std::string str1 = "LLJoint", str2;
+ parent.setName(str1);
+ str2 = parent.getName();
+ ensure("setName() failed ", (str1 == str2));
+ }
+
+ template<> template<>
+ void lljoint_object::test<5>()
+ {
+ LLJoint lljoint;
+ LLVector3 vec3(2.3f,30.f,10.f);
+ lljoint.setPosition(vec3);
+ LLVector3 pos = lljoint.getPosition();
+ ensure("setPosition()/getPosition() failed ", (vec3 == pos));
+ }
+
+ template<> template<>
+ void lljoint_object::test<6>()
+ {
+ LLJoint lljoint;
+ LLVector3 vec3(2.3f,30.f,10.f);
+ lljoint.setWorldPosition(vec3);
+ LLVector3 pos = lljoint.getWorldPosition();
+ ensure("1:setWorldPosition()/getWorldPosition() failed ", (vec3 == pos));
+ LLVector3 lastPos = lljoint.getLastWorldPosition();
+ ensure("2:getLastWorldPosition failed ", (vec3 == lastPos));
+ }
+
+ template<> template<>
+ void lljoint_object::test<7>()
+ {
+ LLJoint lljoint("LLJoint");
+ LLQuaternion q(2.3f,30.f,10.f,1.f);
+ lljoint.setRotation(q);
+ LLQuaternion rot = lljoint.getRotation();
+ ensure("setRotation()/getRotation() failed ", (q == rot));
+ }
+ template<> template<>
+ void lljoint_object::test<8>()
+ {
+ LLJoint lljoint("LLJoint");
+ LLQuaternion q(2.3f,30.f,10.f,1.f);
+ lljoint.setWorldRotation(q);
+ LLQuaternion rot = lljoint.getWorldRotation();
+ ensure("1:setWorldRotation()/getWorldRotation() failed ", (q == rot));
+ LLQuaternion lastRot = lljoint.getLastWorldRotation();
+ ensure("2:getLastWorldRotation failed ", (q == lastRot));
+ }
+
+ template<> template<>
+ void lljoint_object::test<9>()
+ {
+ LLJoint lljoint;
+ LLVector3 vec3(2.3f,30.f,10.f);
+ lljoint.setScale(vec3);
+ LLVector3 scale = lljoint.getScale();
+ ensure("setScale()/getScale failed ", (vec3 == scale));
+ }
+
+ template<> template<>
+ void lljoint_object::test<10>()
+ {
+ LLJoint lljoint("LLJoint");
+ LLMatrix4 mat;
+ mat.identity();
+ lljoint.setWorldMatrix(mat);//giving warning setWorldMatrix not correctly implemented;
+ LLMatrix4 mat4 = lljoint.getWorldMatrix();
+ ensure("setWorldMatrix()/getWorldMatrix failed ", (mat4 == mat));
+ }
+
+ template<> template<>
+ void lljoint_object::test<11>()
+ {
+ LLJoint lljoint("parent");
+ S32 joint_num = 12;
+ lljoint.setJointNum(joint_num);
+ S32 jointNum = lljoint.getJointNum();
+ ensure("setJointNum()/getJointNum failed ", (jointNum == joint_num));
+ }
+
+ template<> template<>
+ void lljoint_object::test<12>()
+ {
+ LLJoint lljoint;
+ LLVector3 vec3(2.3f,30.f,10.f);
+ lljoint.setSkinOffset(vec3);
+ LLVector3 offset = lljoint.getSkinOffset();
+ ensure("1:setSkinOffset()/getSkinOffset() failed ", (vec3 == offset));
+ }
+
+ template<> template<>
+ void lljoint_object::test<13>()
+ {
+ LLJoint lljointgp("gparent");
+ LLJoint lljoint("parent");
+ LLJoint lljoint1("child1");
+ lljoint.addChild(&lljoint1);
+ LLJoint lljoint2("child2");
+ lljoint.addChild(&lljoint2);
+ LLJoint lljoint3("child3");
+ lljoint.addChild(&lljoint3);
+
+ LLJoint* jnt = NULL;
+ jnt = lljoint2.getParent();
+ ensure("addChild() failed ", (&lljoint == jnt));
+ LLJoint* jnt1 = lljoint.findJoint("child3");
+ ensure("findJoint() failed ", (&lljoint3 == jnt1));
+ lljoint.removeChild(&lljoint3);
+ LLJoint* jnt2 = lljoint.findJoint("child3");
+ ensure("removeChild() failed ", (NULL == jnt2));
+
+ lljointgp.addChild(&lljoint);
+ ensure("GetParent() failed ", (&lljoint== lljoint2.getParent()));
+ ensure("getRoot() failed ", (&lljointgp == lljoint2.getRoot()));
+
+ ensure("getRoot() failed ", &lljoint1 == lljoint.findJoint("child1"));
+
+ lljointgp.removeAllChildren();
+ // parent removed from grandparent - so should not be able to locate child
+ ensure("removeAllChildren() failed ", (NULL == lljointgp.findJoint("child1")));
+ // it should still exist in parent though
+ ensure("removeAllChildren() failed ", (&lljoint1 == lljoint.findJoint("child1")));
+ }
+
+ template<> template<>
+ void lljoint_object::test<14>()
+ {
+ LLJoint lljointgp("gparent");
+
+ LLJoint llparent1("parent1");
+ LLJoint llparent2("parent2");
+
+ LLJoint llchild("child1");
+ LLJoint lladoptedchild("child2");
+ llparent1.addChild(&llchild);
+ llparent1.addChild(&lladoptedchild);
+
+ llparent2.addChild(&lladoptedchild);
+ ensure("1. addChild failed to remove prior parent", lladoptedchild.getParent() == &llparent2);
+ ensure("2. addChild failed to remove prior parent", llparent1.findJoint("child2") == NULL);
+ }
+
+
+ /*
+ Test cases for the following not added. They perform operations
+ on underlying LLXformMatrix and LLVector3 elements which have
+ been unit tested separately.
+ Unit Testing these functions will basically require re-implementing
+ logic of these function in the test case itself
+
+ 1) void WorldMatrixChildren();
+ 2) void updateWorldMatrixParent();
+ 3) void updateWorldPRSParent();
+ 4) void updateWorldMatrix();
+ 5) LLXformMatrix *getXform() { return &mXform; }
+ 6) void setConstraintSilhouette(LLDynamicArray<LLVector3>& silhouette);
+ 7) void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot);
+
+ */
+}
diff -uwN 2007-03-13-Patch1\linden\indra\test/llnamevalue_tut.cpp 2007-03-13\linden\indra\test/llnamevalue_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/llnamevalue_tut.cpp Tue Mar 13 11:55:22 2007
+++ 2007-03-13\linden\indra\test/llnamevalue_tut.cpp Wed Mar 21 23:45:32 2007
@@ -378,11 +378,6 @@
setExpectedResult(NVT_ASSET, "New Value");
nValue.setAsset("New Value");
-
- ensure("Asset nonzero failed", nValue.nonzero() == TRUE);
- setExpectedResult(NVT_ASSET, "");
- nValue.setAsset("");
- ensure("Asset nonzero failed", nValue.nonzero() == FALSE);
}
template<> template<>
diff -uwN 2007-03-13-Patch1\linden\indra\test/llquaternion_tut.cpp 2007-03-13\linden\indra\test/llquaternion_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/llquaternion_tut.cpp Wed Dec 31 16:00:00 1969
+++ 2007-03-13\linden\indra\test/llquaternion_tut.cpp Wed Mar 21 18:06:00 2007
@@ -0,0 +1,612 @@
+/**
+ * @file llquaternion_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief Test cases of llquaternion.h
+ *
+**/
+
+#include <tut/tut.h>
+#include "llmath.h"
+#include "lltut.h"
+#include "linden_common.h"
+#include "llquaternion.h"
+#include "v4math.h"
+#include "v3math.h"
+#include "v3dmath.h"
+#include "m4math.h"
+#include "m3math.h"
+#include "math.h"
+
+namespace tut
+{
+ struct llquat_test
+ {
+ };
+ typedef test_group<llquat_test> llquat_test_t;
+ typedef llquat_test_t::object llquat_test_object_t;
+ tut::llquat_test_t tut_llquat_test("llquat");
+
+ //test case for LLQuaternion::LLQuaternion(void) fn.
+ template<> template<>
+ void llquat_test_object_t::test<1>()
+ {
+ LLQuaternion llquat;
+ ensure("LLQuaternion::LLQuaternion() failed", 0.f == llquat.mQ[0] &&
+ 0.f == llquat.mQ[1] &&
+ 0.f == llquat.mQ[2] &&
+ 1.f == llquat.mQ[3]);
+ }
+
+ //test case for explicit LLQuaternion(const LLMatrix4 &mat) fn.
+ template<> template<>
+ void llquat_test_object_t::test<2>()
+ {
+ LLMatrix4 llmat;
+ LLVector4 vector1(2.0f, 1.0f, 3.0f, 6.0f);
+ LLVector4 vector2(5.0f, 6.0f, 0.0f, 1.0f);
+ LLVector4 vector3(2.0f, 1.0f, 2.0f, 9.0f);
+ LLVector4 vector4(3.0f, 8.0f, 1.0f, 5.0f);
+
+ llmat.initRows(vector1, vector2, vector3, vector4);
+ ensure("explicit LLQuaternion(const LLMatrix4 &mat) failed", 2.0f == llmat.mMatrix[0][0] &&
+ 1.0f == llmat.mMatrix[0][1] &&
+ 3.0f == llmat.mMatrix[0][2] &&
+ 6.0f == llmat.mMatrix[0][3] &&
+ 5.0f == llmat.mMatrix[1][0] &&
+ 6.0f == llmat.mMatrix[1][1] &&
+ 0.0f == llmat.mMatrix[1][2] &&
+ 1.0f == llmat.mMatrix[1][3] &&
+ 2.0f == llmat.mMatrix[2][0] &&
+ 1.0f == llmat.mMatrix[2][1] &&
+ 2.0f == llmat.mMatrix[2][2] &&
+ 9.0f == llmat.mMatrix[2][3] &&
+ 3.0f == llmat.mMatrix[3][0] &&
+ 8.0f == llmat.mMatrix[3][1] &&
+ 1.0f == llmat.mMatrix[3][2] &&
+ 5.0f == llmat.mMatrix[3][3]);
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<3>()
+ {
+ LLMatrix3 llmat;
+
+ LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f);
+ LLVector3 vect2(741.434f, 23.00034f, 6567.223423f);
+ LLVector3 vect3(566.003034f, 12.98705f, 234.764423f);
+ llmat.setRows(vect1, vect2, vect3);
+
+ ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] &&
+ 234.56f == llmat.mMatrix[0][1] &&
+ 4234.442234f == llmat.mMatrix[0][2] &&
+ 741.434f == llmat.mMatrix[1][0] &&
+ 23.00034f == llmat.mMatrix[1][1] &&
+ 6567.223423f == llmat.mMatrix[1][2] &&
+ 566.003034f == llmat.mMatrix[2][0] &&
+ 12.98705f == llmat.mMatrix[2][1] &&
+ 234.764423f == llmat.mMatrix[2][2]);
+ }
+
+ //test case for LLQuaternion(F32 x, F32 y, F32 z, F32 w), setQuatInit() and normQuat() fns.
+ template<> template<>
+ void llquat_test_object_t::test<4>()
+ {
+ F32 x_val = 3.0f;
+ F32 y_val = 2.0f;
+ F32 z_val = 6.0f;
+ F32 w_val = 1.0f;
+
+ LLQuaternion res_quat;
+ res_quat.setQuatInit(x_val, y_val, z_val, w_val);
+ res_quat.normQuat();
+
+ ensure("LLQuaternion::normQuat() fn failed",
+ is_approx_equal(0.42426407f, res_quat.mQ[0]) &&
+ is_approx_equal(0.28284273f, res_quat.mQ[1]) &&
+ is_approx_equal(0.84852815f, res_quat.mQ[2]) &&
+ is_approx_equal(0.14142136f, res_quat.mQ[3]));
+
+ x_val = 0.0f;
+ y_val = 0.0f;
+ z_val = 0.0f;
+ w_val = 0.0f;
+
+ res_quat;
+ res_quat.setQuatInit(x_val, y_val, z_val, w_val);
+ res_quat.normQuat();
+
+ ensure("LLQuaternion::normQuat() fn. failed.",
+ is_approx_equal(0.0f, res_quat.mQ[0]) &&
+ is_approx_equal(0.0f, res_quat.mQ[1]) &&
+ is_approx_equal(0.0f, res_quat.mQ[2]) &&
+ is_approx_equal(1.0f, res_quat.mQ[3]));
+
+
+ ensure("LLQuaternion::normQuat() fn. failed.",
+ is_approx_equal(0.0f, res_quat.mQ[0]) &&
+ is_approx_equal(0.0f, res_quat.mQ[1]) &&
+ is_approx_equal(0.0f, res_quat.mQ[2]) &&
+ is_approx_equal(1.0f, res_quat.mQ[3]));
+ }
+
+ //test case for conjQuat() and transQuat() fns.
+ template<> template<>
+ void llquat_test_object_t::test<5>()
+ {
+ F32 x_val = 3.0f;
+ F32 y_val = 2.0f;
+ F32 z_val = 6.0f;
+ F32 w_val = 1.0f;
+
+ LLQuaternion res_quat;
+ LLQuaternion result, result1;
+ result1 = result = res_quat.setQuatInit(x_val, y_val, z_val, w_val);
+
+ result.conjQuat();
+ result1.transQuat();
+
+ ensure("LLQuaternion::conjQuat and LLQuaternion::transQuat failed ",
+ is_approx_equal(result1.mQ[0], result.mQ[0]) &&
+ is_approx_equal(result1.mQ[1], result.mQ[1]) &&
+ is_approx_equal(result1.mQ[2], result.mQ[2]));
+
+ }
+
+ //test case for dot(const LLQuaternion &a, const LLQuaternion &b) fn.
+ template<> template<>
+ void llquat_test_object_t::test<6>()
+ {
+ LLQuaternion quat1(3.0f, 2.0f, 6.0f, 0.0f), quat2(1.0f, 1.0f, 1.0f, 1.0f);
+ ensure("1. The two values are different", llround(12.000000f, 2) == llround(dot(quat1, quat2), 2));
+
+ LLQuaternion quat0(3.0f, 9.334f, 34.5f, 23.0f), quat(34.5f, 23.23f, 2.0f, 45.5f);
+ ensure("2. The two values are different", llround(1435.828807f, 2) == llround(dot(quat0, quat), 2));
+ }
+
+ //test case for LLQuaternion &LLQuaternion::constrain(F32 radians) fn.
+ template<> template<>
+ void llquat_test_object_t::test<7>()
+ {
+ F32 radian = 60.0f;
+ LLQuaternion quat(3.0f, 2.0f, 6.0f, 0.0f);
+ LLQuaternion quat1;
+ quat1 = quat.constrain(radian);
+ ensure("1. LLQuaternion::constrain(F32 radians) failed",
+ is_approx_equal_fraction(-0.423442f, quat1.mQ[0], 8) &&
+ is_approx_equal_fraction(-0.282295f, quat1.mQ[1], 8) &&
+ is_approx_equal_fraction(-0.846884f, quat1.mQ[2], 8) &&
+ is_approx_equal_fraction(0.154251f, quat1.mQ[3], 8));
+
+
+ radian = 30.0f;
+ LLQuaternion quat0(37.50f, 12.0f, 86.023f, 40.32f);
+ quat1 = quat0.constrain(radian);
+
+ ensure("2. LLQuaternion::constrain(F32 radians) failed",
+ is_approx_equal_fraction(37.500000f, quat1.mQ[0], 8) &&
+ is_approx_equal_fraction(12.0000f, quat1.mQ[1], 8) &&
+ is_approx_equal_fraction(86.0230f, quat1.mQ[2], 8) &&
+ is_approx_equal_fraction(40.320000f, quat1.mQ[3], 8));
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<8>()
+ {
+ F32 value1 = 15.0f;
+ LLQuaternion quat1(1.0f, 2.0f, 4.0f, 1.0f);
+ LLQuaternion quat2(4.0f, 3.0f, 6.5f, 9.7f);
+ LLQuaternion res_lerp, res_slerp, res_nlerp;
+
+ //test case for lerp(F32 t, const LLQuaternion &q) fn.
+ res_lerp = lerp(value1, quat1);
+ ensure("1. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed",
+ is_approx_equal_fraction(0.181355f, res_lerp.mQ[0], 16) &&
+ is_approx_equal_fraction(0.362711f, res_lerp.mQ[1], 16) &&
+ is_approx_equal_fraction(0.725423f, res_lerp.mQ[2], 16) &&
+ is_approx_equal_fraction(0.556158f, res_lerp.mQ[3], 16));
+
+ //test case for lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) fn.
+ res_lerp = lerp(value1, quat1, quat2);
+ ensure("2. LLQuaternion lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) failed",
+ is_approx_equal_fraction(0.314306f, res_lerp.mQ[0], 16) &&
+ is_approx_equal_fraction(0.116156f, res_lerp.mQ[1], 16) &&
+ is_approx_equal_fraction(0.283559f, res_lerp.mQ[2], 16) &&
+ is_approx_equal_fraction(0.898506f, res_lerp.mQ[3], 16));
+
+ //test case for slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b ) fn.
+ res_slerp = slerp(value1, quat1, quat2);
+ ensure("3. LLQuaternion slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b) failed",
+ is_approx_equal_fraction(46.000f, res_slerp.mQ[0], 16) &&
+ is_approx_equal_fraction(17.00f, res_slerp.mQ[1], 16) &&
+ is_approx_equal_fraction(41.5f, res_slerp.mQ[2], 16) &&
+ is_approx_equal_fraction(131.5f, res_slerp.mQ[3], 16));
+
+ //test case for nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) fn.
+ res_nlerp = nlerp(value1, quat1, quat2);
+ ensure("4. LLQuaternion nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) failed",
+ is_approx_equal_fraction(0.314306f, res_nlerp.mQ[0], 16) &&
+ is_approx_equal_fraction(0.116157f, res_nlerp.mQ[1], 16) &&
+ is_approx_equal_fraction(0.283559f, res_nlerp.mQ[2], 16) &&
+ is_approx_equal_fraction(0.898506f, res_nlerp.mQ[3], 16));
+
+ //test case for nlerp(F32 t, const LLQuaternion &q) fn.
+ res_slerp = slerp(value1, quat1);
+ ensure("5. LLQuaternion slerp(F32 t, const LLQuaternion &q) failed",
+ is_approx_equal_fraction(1.0f, res_slerp.mQ[0], 16) &&
+ is_approx_equal_fraction(2.0f, res_slerp.mQ[1], 16) &&
+ is_approx_equal_fraction(4.0000f, res_slerp.mQ[2], 16) &&
+ is_approx_equal_fraction(1.000f, res_slerp.mQ[3], 16));
+
+ LLQuaternion quat3(2.0f, 1.0f, 5.5f, 10.5f);
+ LLQuaternion res_nlerp1;
+ value1 = 100.0f;
+ res_nlerp1 = nlerp(value1, quat3);
+ ensure("6. LLQuaternion nlerp(F32 t, const LLQuaternion &q) failed",
+ is_approx_equal_fraction(0.268245f, res_nlerp1.mQ[0], 16) && is_approx_equal_fraction(0.134122f, res_nlerp1.mQ[1], 2) &&
+ is_approx_equal_fraction(0.737673f, res_nlerp1.mQ[2], 16) &&
+ is_approx_equal_fraction(0.604892f, res_nlerp1.mQ[3], 16));
+
+ //test case for lerp(F32 t, const LLQuaternion &q) fn.
+ res_lerp = lerp(value1, quat2);
+ ensure("7. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed",
+ is_approx_equal_fraction(0.404867f, res_lerp.mQ[0], 16) &&
+ is_approx_equal_fraction(0.303650f, res_lerp.mQ[1], 16) &&
+ is_approx_equal_fraction(0.657909f, res_lerp.mQ[2], 16) &&
+ is_approx_equal_fraction(0.557704f, res_lerp.mQ[3], 16));
+
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<9>()
+ {
+ //test case for LLQuaternion operator*(const LLQuaternion &a, const LLQuaternion &b) fn
+ LLQuaternion quat1(1.0f, 2.5f, 3.5f, 5.5f);
+ LLQuaternion quat2(4.0f, 3.0f, 5.0f, 1.0f);
+ LLQuaternion result = quat1 * quat2;
+ ensure("1. LLQuaternion Operator* failed", (21.0f == result.mQ[0]) &&
+ (10.0f == result.mQ[1]) &&
+ (38.0f == result.mQ[2]) &&
+ (-23.5f == result.mQ[3]));
+
+ LLQuaternion quat3(2341.340f, 2352.345f, 233.25f, 7645.5f);
+ LLQuaternion quat4(674.067f, 893.0897f, 578.0f, 231.0f);
+ result = quat3 * quat4;
+ ensure("2. LLQuaternion Operator* failed", (4543086.5f == result.mQ[0]) &&
+ (8567578.0f == result.mQ[1]) &&
+ (3967591.25f == result.mQ[2]) &&
+ (-2047783.25f == result.mQ[3]));
+
+ //inline LLQuaternion operator+(const LLQuaternion &a, const LLQuaternion &b)fn.
+ result = quat1 + quat2;
+ ensure("3. LLQuaternion operator+ failed", (5.0f == result.mQ[0]) &&
+ (5.5f == result.mQ[1]) &&
+ (8.5f == result.mQ[2]) &&
+ (6.5f == result.mQ[3]));
+
+ result = quat3 + quat4;
+ ensure("4. LLQuaternion operator+ failed", is_approx_equal(3015.407227f, result.mQ[0]) &&
+ is_approx_equal(3245.434570f, result.mQ[1]) &&
+ (11.25f, result.mQ[2]) &&
+ (7876.5f, result.mQ[3]));
+
+ //inline LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) fn
+ result = quat1 - quat2;
+ ensure("5. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed",
+ (-3.0f == result.mQ[0]) &&
+ (-0.5f == result.mQ[1]) &&
+ (-1.5f == result.mQ[2]) &&
+ (4.5f == result.mQ[3]));
+
+ result = quat3 - quat4;
+ ensure("6. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed",
+ is_approx_equal(1667.273071f, result.mQ[0]) &&
+ is_approx_equal(1459.255249f, result.mQ[1]) &&
+ (-344.75f == result.mQ[2]) &&
+ (7414.50f == result.mQ[3]));
+ }
+
+ //test case for LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) fn.
+ template<> template<>
+ void llquat_test_object_t::test<10>()
+ {
+ LLVector4 vect(12.0f, 5.0f, 60.0f, 75.1f);
+ LLQuaternion quat(2323.034f, 23.5f, 673.23f, 57667.5f);
+ LLVector4 result = vect * quat;
+ ensure("1. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed",
+ (39928406016.0f == result.mV[0]) &&
+ (1457801728.0f == result.mV[1]) &&
+ (200580612096.0f == result.mV[2]) &&
+ (75.099998f == result.mV[3]));
+
+ LLVector4 vect1(22.0f, 45.0f, 40.0f, 78.1f);
+ LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f);
+ result = vect1 * quat1;
+ ensure("2. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed",
+ is_approx_equal(-58153.5390f, result.mV[0]) &&
+ (183787.8125f == result.mV[1]) &&
+ (116864.164063f == result.mV[2]) &&
+ (78.099998f == result.mV[3]));
+ }
+
+ //test case for LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) fn.
+ template<> template<>
+ void llquat_test_object_t::test<11>()
+ {
+ LLVector3 vect(12.0f, 5.0f, 60.0f);
+ LLQuaternion quat(23.5f, 6.5f, 3.23f, 56.5f);
+ LLVector3 result = vect * quat;
+ ensure("1. LLVEctor3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed",
+ is_approx_equal(97182.953125f,result.mV[0]) &&
+ is_approx_equal(-135405.640625f, result.mV[1]) &&
+ is_approx_equal(162986.140f, result.mV[2]));
+
+ LLVector3 vect1(5.0f, 40.0f, 78.1f);
+ LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f);
+ result = vect1 * quat1;
+ ensure("2. LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed",
+ is_approx_equal(33217.703f, result.mV[0]) &&
+ is_approx_equal(295383.8125f, result.mV[1]) &&
+ is_approx_equal(84718.140f, result.mV[2]));
+ }
+
+ //test case for LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) fn.
+ template<> template<>
+ void llquat_test_object_t::test<12>()
+ {
+ LLVector3d vect(-2.0f, 5.0f, -6.0f);
+ LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f);
+ LLVector3d result = vect * quat;
+ ensure("1. LLVEctor3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ",
+ (-633.0f == result.mdV[0]) &&
+ (-300.0f == result.mdV[1]) &&
+ (-36.0f == result.mdV[2]));
+
+ LLVector3d vect1(5.0f, -4.5f, 8.21f);
+ LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f);
+ result = vect1 * quat1;
+ ensure("2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed",
+ is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) &&
+ is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) &&
+ is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8));
+
+ LLVector3d vect2(2.0f, 3.5f, 1.1f);
+ LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f);
+ result = vect2 * quat2;
+ ensure("3. LLvector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed",
+ is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) &&
+ is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) &&
+ is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8));
+ }
+
+ //test case for inline LLQuaternion operator-(const LLQuaternion &a) fn.
+ template<> template<>
+ void llquat_test_object_t::test<13>()
+ {
+ LLQuaternion quat(23.5f, 34.5f, 16723.4f, 324.7f);
+ LLQuaternion result = -quat;
+ ensure("1. LLQuaternion operator-(const LLQuaternion &a) failed",
+ (-23.5f == result.mQ[0]) &&
+ (-34.5f == result.mQ[1]) &&
+ (-16723.4f == result.mQ[2]) &&
+ (-324.7f == result.mQ[3]));
+
+ LLQuaternion quat1(-3.5f, -34.5f, -16.4f, -154.7f);
+ result = -quat1;
+ ensure("2. LLQuaternion operator-(const LLQuaternion &a) failed.",
+ (3.5f == result.mQ[0]) &&
+ (34.5f == result.mQ[1]) &&
+ (16.4f == result.mQ[2]) &&
+ (154.7f == result.mQ[3]));
+ }
+
+ //test case for inline LLQuaternion operator*(F32 a, const LLQuaternion &q) and
+ //inline LLQuaternion operator*(F32 a, const LLQuaternion &q) fns.
+ template<> template<>
+ void llquat_test_object_t::test<14>()
+ {
+ LLQuaternion quat_value(9.0f, 8.0f, 7.0f, 6.0f);
+ F32 a =3.5f;
+ LLQuaternion result = a * quat_value;
+ LLQuaternion result1 = quat_value * a;
+
+ ensure("1. LLQuaternion operator* failed", (result.mQ[0] == result1.mQ[0]) &&
+ (result.mQ[1] == result1.mQ[1]) &&
+ (result.mQ[2] == result1.mQ[2]) &&
+ (result.mQ[3] == result1.mQ[3]));
+
+
+ LLQuaternion quat_val(9454.0f, 43568.3450f, 456343247.0343f, 2346.03434f);
+ a =-3324.3445f;
+ result = a * quat_val;
+ result1 = quat_val * a;
+
+ ensure("2. LLQuaternion operator* failed", (result.mQ[0] == result1.mQ[0]) &&
+ (result.mQ[1] == result1.mQ[1]) &&
+ (result.mQ[2] == result1.mQ[2]) &&
+ (result.mQ[3] == result1.mQ[3]));
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<15>()
+ {
+ // test cases for inline LLQuaternion operator~(const LLQuaternion &a)
+ LLQuaternion quat_val(2323.634f, -43535.4f, 3455.88f, -32232.45f);
+ LLQuaternion result = ~quat_val;
+ ensure("1. LLQuaternion operator~(const LLQuaternion &a) failed ",
+ (-2323.634f == result.mQ[0]) &&
+ (43535.4f == result.mQ[1]) &&
+ (-3455.88f == result.mQ[2]) &&
+ (-32232.45f == result.mQ[3]));
+
+ //test case for inline bool LLQuaternion::operator==(const LLQuaternion &b) const
+ LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f);
+ LLQuaternion quat_val2(2323.634f, -43535.4f, 3455.88f, -32232.45f);
+ ensure("2. LLQuaternion::operator==(const LLQuaternion &b) failed", quat_val1 == quat_val2);
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<16>()
+ {
+ //test case for inline bool LLQuaternion::operator!=(const LLQuaternion &b) const
+ LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f);
+ LLQuaternion quat_val2(0, -43535.4f, 3455.88f, -32232.45f);
+ ensure("LLQuaternion::operator!=(const LLQuaternion &b) failed", quat_val1 != quat_val2);
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<17>()
+ {
+ //test case for LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order)
+ F32 x = 2.0f;
+ F32 y = 1.0f;
+ F32 z = 3.0f;
+
+ LLQuaternion result = mayaQ(x, y, z, LLQuaternion::XYZ);
+ ensure("1. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
+ is_approx_equal_fraction(0.0172174f, result.mQ[0], 16) &&
+ is_approx_equal_fraction(0.009179f, result.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026020f, result.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999471f, result.mQ[3], 16));
+
+ LLQuaternion result1 = mayaQ(x, y, z, LLQuaternion::YZX);
+ ensure("2. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
+ is_approx_equal_fraction(0.017217f, result1.mQ[0], 16) &&
+ is_approx_equal_fraction(0.008265f, result1.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026324f, result1.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999471f, result1.mQ[3], 16));
+
+ LLQuaternion result2 = mayaQ(x, y, z, LLQuaternion::ZXY);
+ ensure("3. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZXY",
+ is_approx_equal_fraction(0.017674f, result2.mQ[0], 16) &&
+ is_approx_equal_fraction(0.008265f, result2.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026020f, result2.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999471f, result2.mQ[3], 16));
+
+ LLQuaternion result3 = mayaQ(x, y, z, LLQuaternion::XZY);
+ ensure("4. TLLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XZY",
+ is_approx_equal_fraction(0.017674f, result3.mQ[0], 16) &&
+ is_approx_equal_fraction(0.009179f, result3.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026020f, result3.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999463f, result3.mQ[3], 16));
+
+ LLQuaternion result4 = mayaQ(x, y, z, LLQuaternion::YXZ);
+ ensure("5. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for YXZ",
+ is_approx_equal_fraction(0.017217f, result4.mQ[0], 16) &&
+ is_approx_equal_fraction(0.009179f, result4.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026324f, result4.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999463f, result4.mQ[3], 16));
+
+ LLQuaternion result5 = mayaQ(x, y, z, LLQuaternion::ZYX);
+ ensure("6. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZYX",
+ is_approx_equal_fraction(0.017674f, result5.mQ[0], 16) &&
+ is_approx_equal_fraction(0.008265f, result5.mQ[1], 16) &&
+ is_approx_equal_fraction(0.026324f, result5.mQ[2], 16) &&
+ is_approx_equal_fraction(0.999463f, result5.mQ[3], 16));
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<18>()
+ {
+ // test case for friend std::ostream& operator<<(std::ostream &s, const LLQuaternion &a) fn
+ LLQuaternion a(1.0f, 1.0f, 1.0f, 1.0f);
+ std::ostringstream result_value;
+ result_value << a;
+ ensure_equals("1. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }");
+
+ LLQuaternion b(-31.034f, 231.2340f, 3451.344320f, -341.0f);
+ std::ostringstream result_value1;
+ result_value1 << b;
+ ensure_equals("2. Operator << failed", result_value1.str(), "{ -31.034, 231.234, 3451.34, -341 }");
+
+ LLQuaternion c(1.0f, 2.2f, 3.3f, 4.4f);
+ result_value << c;
+ ensure_equals("3. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }{ 1, 2.2, 3.3, 4.4 }");
+
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<19>()
+ {
+ //test case for const char *OrderToString( const LLQuaternion::Order order ) fn
+ const char* result = OrderToString(LLQuaternion::XYZ);
+ ensure("1. OrderToString failed for XYZ", (0 == strcmp("XYZ", result)));
+
+ result = OrderToString(LLQuaternion::YZX);
+ ensure("2. OrderToString failed for YZX", (0 == strcmp("YZX", result)));
+
+ result = OrderToString(LLQuaternion::ZXY);
+ ensure("3. OrderToString failed for ZXY", (0 == strcmp("ZXY", result)) &&
+ (0 != strcmp("XYZ", result)) &&
+ (0 != strcmp("YXZ", result)) &&
+ (0 != strcmp("ZYX", result)) &&
+ (0 != strcmp("XYZ", result)));
+
+ result = OrderToString(LLQuaternion::XZY);
+ ensure("4. OrderToString failed for XZY", (0 == strcmp("XZY", result)));
+
+ result = OrderToString(LLQuaternion::ZYX);
+ ensure("5. OrderToString failed for ZYX", (0 == strcmp("ZYX", result)));
+
+ result = OrderToString(LLQuaternion::YXZ);
+ ensure("6.OrderToString failed for YXZ", (0 == strcmp("YXZ", result)));
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<20>()
+ {
+ //test case for LLQuaternion::Order StringToOrder( const char *str ) fn
+ int result = StringToOrder("XYZ");
+ ensure("1. LLQuaternion::Order StringToOrder(const char *str ) failed for XYZ", 0 == result);
+
+ result = StringToOrder("YZX");
+ ensure("2. LLQuaternion::Order StringToOrder(const char *str) failed for YZX", 1 == result);
+
+ result = StringToOrder("ZXY");
+ ensure("3. LLQuaternion::Order StringToOrder(const char *str) failed for ZXY", 2 == result);
+
+ result = StringToOrder("XZY");
+ ensure("4. LLQuaternion::Order StringToOrder(const char *str) failed for XZY", 3 == result);
+
+ result = StringToOrder("YXZ");
+ ensure("5. LLQuaternion::Order StringToOrder(const char *str) failed for YXZ", 4 == result);
+
+ result = StringToOrder("ZYX");
+ ensure("6. LLQuaternion::Order StringToOrder(const char *str) failed for ZYX", 5 == result);
+
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<21>()
+ {
+ //void LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) const fn
+ F32 angle_value = 90.0f;
+ LLVector3 vect(12.0f, 4.0f, 1.0f);
+ LLQuaternion llquat(angle_value, vect);
+ llquat.getAngleAxis(&angle_value, vect);
+ ensure("LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) failed",
+ is_approx_equal_fraction(2.035406f, angle_value, 16) &&
+ is_approx_equal_fraction(0.315244f, vect.mV[1], 16) &&
+ is_approx_equal_fraction(0.078811f, vect.mV[2], 16) &&
+ is_approx_equal_fraction(0.945733f, vect.mV[0], 16));
+ }
+
+ template<> template<>
+ void llquat_test_object_t::test<22>()
+ {
+ //test case for void LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const fn
+ F32 roll = -12.0f;
+ F32 pitch = -22.43f;
+ F32 yaw = 11.0f;
+
+ LLQuaternion llquat;
+ llquat.getEulerAngles(&roll, &pitch, &yaw);
+ ensure("LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) failed",
+ is_approx_equal(0.000f, llquat.mQ[0]) &&
+ is_approx_equal(0.000f, llquat.mQ[1]) &&
+ is_approx_equal(0.000f, llquat.mQ[2]) &&
+ is_approx_equal(1.000f, llquat.mQ[3]));
+
+ }
+
+}
diff -uwN 2007-03-13-Patch1\linden\indra\test/llxorcipher_tut.cpp 2007-03-13\linden\indra\test/llxorcipher_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/llxorcipher_tut.cpp Wed Dec 31 16:00:00 1969
+++ 2007-03-13\linden\indra\test/llxorcipher_tut.cpp Wed Mar 21 01:55:12 2007
@@ -0,0 +1,113 @@
+/**
+ * @file llxorcipher_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief llxorcipher, llnullcipher test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "llxorcipher.h"
+#include "llnullcipher.h"
+
+namespace tut
+{
+ struct cipher
+ {
+ };
+ typedef test_group<cipher> cipher_t;
+ typedef cipher_t::object cipher_object_t;
+ tut::cipher_t tut_cipher("cipher");
+
+ //encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<1>()
+ {
+ const U32 len = 3;
+ const U8 pad[] = "abc";
+ const char str[] = "SecondLife";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+ LLXORCipher xorCipher(pad, len);
+ LLXORCipher xorCipher1(pad, len);
+
+ U32 length = xorCipher.requiredEncryptionSpace(50);
+ ensure("requiredEncryptionSpace() function failed", (length == 50));
+
+ U32 lenEncrypted = xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ ensure("Encryption failed", (lenEncrypted == str_len));
+ U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure("Decryption failed", (lenDecrypted == str_len));
+ ensure_memory_matches("LLXORCipher Encrypt/Decrypt failed", str, str_len, decrypted, lenDecrypted);
+ }
+
+ // operator=
+ template<> template<>
+ void cipher_object_t::test<2>()
+ {
+ const U8 pad[] = "ABCDEFGHIJKLMNOPQ"; // pad len longer than data to be ciphered
+ const U32 pad_len = sizeof(pad);
+ const U8 pad1[] = "SecondLife";
+ const U32 pad_len1 = sizeof(pad1);
+ const char str[] = "To Be Ciphered";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+
+ LLXORCipher xorCipher(pad, pad_len);
+ LLXORCipher xorCipher1(pad1, pad_len1);
+
+ xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ // make xorCipher1 same as xorCipher..so that xorCipher1 can decrypt what was
+ // encrypted using xorCipher
+ xorCipher1 = xorCipher;
+ U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure_memory_matches("LLXORCipher operator= failed", str, str_len, decrypted, lenDecrypted);
+ }
+
+ //in place encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<3>()
+ {
+ U32 padNum = 0x12349087;
+ const U8* pad = (U8*) &padNum;
+ const U32 pad_len = sizeof(U32);
+ char str[] = "To Be Ciphered a long string.........!!!.";
+ char str1[] = "To Be Ciphered a long string.........!!!."; // same as str
+ const S32 str_len = sizeof(str);
+
+ LLXORCipher xorCipher(pad, pad_len);
+ LLXORCipher xorCipher1(pad, pad_len);
+ xorCipher.encrypt((U8 *) str, str_len);
+ // it should not be the same as original data!
+ ensure("LLXORCipher: In Place encrypt failed", memcmp(str, str1, str_len) != 0);
+ xorCipher1.decrypt((U8 *) str, str_len);
+ // it should not be the same as original data!
+ ensure_memory_matches("LLXORCipher: In Place decrypt failed", str, str_len, str1, str_len);
+ }
+
+ //LLNullCipher encrypt->decrypt
+ template<> template<>
+ void cipher_object_t::test<4>()
+ {
+ const char str[] = "SecondLife";
+ const S32 str_len = sizeof(str);
+ U8 encrypted[str_len];
+ U8 decrypted[str_len];
+ LLNullCipher nullCipher;
+ LLNullCipher nullCipher1;
+
+ U32 length = nullCipher.requiredEncryptionSpace(50);
+ ensure("LLNullCipher::requiredEncryptionSpace() function failed", (length == 50));
+
+ U32 len1 = nullCipher.encrypt((U8 *) str, str_len, encrypted, str_len);
+ ensure_memory_matches("LLNullCipher - Source transformed during encryption.", encrypted, len1, str, str_len);
+
+ U32 len2 = nullCipher1.decrypt(encrypted, str_len, decrypted, str_len);
+ ensure_memory_matches("LLNullCipher - Decryption failed", decrypted, len2, str, str_len);
+ }
+}
diff -uwN 2007-03-13-Patch1\linden\indra\test/v4math_tut.cpp 2007-03-13\linden\indra\test/v4math_tut.cpp
--- 2007-03-13-Patch1\linden\indra\test/v4math_tut.cpp Wed Dec 31 16:00:00 1969
+++ 2007-03-13\linden\indra\test/v4math_tut.cpp Wed Mar 21 18:40:20 2007
@@ -0,0 +1,359 @@
+/**
+ * @file v4math_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief v4math test cases.
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include <tut/tut.h>
+#include "lltut.h"
+#include "linden_common.h"
+#include "LLQuaternion.h"
+#include "llsd.h"
+#include "m4math.h"
+#include "v4math.h"
+
+namespace tut
+{
+ struct v4math_data
+ {
+ };
+ typedef test_group<v4math_data> v4math_test;
+ typedef v4math_test::object v4math_object;
+ tut::v4math_test v4math_testcase("v4math");
+
+ template<> template<>
+ void v4math_object::test<1>()
+ {
+ LLVector4 vec4;
+ ensure("1:LLVector4:Fail to initialize " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (1.0f == vec4.mV[VW])));
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4a(x,y,z);
+ ensure("2:LLVector4:Fail to initialize " ,((x == vec4a.mV[VX]) && (y == vec4a.mV[VY]) && (z == vec4a.mV[VZ])&& (1.0f == vec4a.mV[VW])));
+ LLVector4 vec4b(x,y,z,w);
+ ensure("3:LLVector4:Fail to initialize " ,((x == vec4b.mV[VX]) && (y == vec4b.mV[VY]) && (z == vec4b.mV[VZ])&& (w == vec4b.mV[VW])));
+ const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f};
+ LLVector4 vec4c(vec);
+ ensure("4:LLVector4:Fail to initialize " ,((vec[0] == vec4c.mV[VX]) && (vec[1] == vec4c.mV[VY]) && (vec[2] == vec4c.mV[VZ])&& (vec[3] == vec4c.mV[VW])));
+ LLVector3 vec3(-2.23f,1.01f,42.3f);
+ LLVector4 vec4d(vec3);
+ ensure("5:LLVector4:Fail to initialize " ,((vec3.mV[VX] == vec4d.mV[VX]) && (vec3.mV[VY] == vec4d.mV[VY]) && (vec3.mV[VZ] == vec4d.mV[VZ])&& (1.f == vec4d.mV[VW])));
+ F32 w1 = -.234f;
+ LLVector4 vec4e(vec3,w1);
+ ensure("6:LLVector4:Fail to initialize " ,((vec3.mV[VX] == vec4e.mV[VX]) && (vec3.mV[VY] == vec4e.mV[VY]) && (vec3.mV[VZ] == vec4e.mV[VZ])&& (w1 == vec4e.mV[VW])));
+ }
+
+ template<> template<>
+ void v4math_object::test<2>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4;
+ vec4.setVec(x,y,z);
+ ensure("1:setVec:Fail to initialize " ,((x == vec4.mV[VX]) && (y == vec4.mV[VY]) && (z == vec4.mV[VZ])&& (1.0f == vec4.mV[VW])));
+ vec4.clearVec();
+ ensure("2:clearVec:Fail " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (1.0f == vec4.mV[VW])));
+ vec4.setVec(x,y,z,w);
+ ensure("3:setVec:Fail to initialize " ,((x == vec4.mV[VX]) && (y == vec4.mV[VY]) && (z == vec4.mV[VZ])&& (w == vec4.mV[VW])));
+ vec4.zeroVec();
+ ensure("4:zeroVec:Fail " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (0 == vec4.mV[VW])));
+ LLVector3 vec3(-2.23f,1.01f,42.3f);
+ vec4.clearVec();
+ vec4.setVec(vec3);
+ ensure("5:setVec:Fail to initialize " ,((vec3.mV[VX] == vec4.mV[VX]) && (vec3.mV[VY] == vec4.mV[VY]) && (vec3.mV[VZ] == vec4.mV[VZ])&& (1.f == vec4.mV[VW])));
+ F32 w1 = -.234f;
+ vec4.zeroVec();
+ vec4.setVec(vec3,w1);
+ ensure("6:setVec:Fail to initialize " ,((vec3.mV[VX] == vec4.mV[VX]) && (vec3.mV[VY] == vec4.mV[VY]) && (vec3.mV[VZ] == vec4.mV[VZ])&& (w1 == vec4.mV[VW])));
+ const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f};
+ LLVector4 vec4a;
+ vec4a.setVec(vec);
+ ensure("7:setVec:Fail to initialize " ,((vec[0] == vec4a.mV[VX]) && (vec[1] == vec4a.mV[VY]) && (vec[2] == vec4a.mV[VZ])&& (vec[3] == vec4a.mV[VW])));
+ }
+
+ template<> template<>
+ void v4math_object::test<3>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f;
+ LLVector4 vec4(x,y,z);
+ ensure("magVec:Fail ", is_approx_equal(vec4.magVec(), fsqrtf(x*x + y*y + z*z)));
+ ensure("magVecSquared:Fail ", is_approx_equal(vec4.magVecSquared(), (x*x + y*y + z*z)));
+ }
+
+ template<> template<>
+ void v4math_object::test<4>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f;
+ LLVector4 vec4(x,y,z);
+ F32 mag = vec4.normVec();
+ mag = 1.f/ mag;
+ ensure("1:normVec: Fail " ,is_approx_equal(mag*x,vec4.mV[VX]) && is_approx_equal(mag*y, vec4.mV[VY])&& is_approx_equal(mag*z, vec4.mV[VZ]));
+ x = 0.000000001f, y = 0.000000001f, z = 0.000000001f;
+ vec4.clearVec();
+ vec4.setVec(x,y,z);
+ mag = vec4.normVec();
+ ensure("2:normVec: Fail " ,is_approx_equal(mag*x,vec4.mV[VX]) && is_approx_equal(mag*y, vec4.mV[VY])&& is_approx_equal(mag*z, vec4.mV[VZ]));
+ }
+
+ template<> template<>
+ void v4math_object::test<5>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4(x,y,z,w);
+ vec4.abs();
+ ensure("abs:Fail " ,((x == vec4.mV[VX]) && (-y == vec4.mV[VY]) && (-z == vec4.mV[VZ])&& (-w == vec4.mV[VW])));
+ vec4.clearVec();
+ ensure("isExactlyClear:Fail " ,(TRUE == vec4.isExactlyClear()));
+ vec4.zeroVec();
+ ensure("isExactlyZero:Fail " ,(TRUE == vec4.isExactlyZero()));
+ }
+
+ template<> template<>
+ void v4math_object::test<6>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4(x,y,z,w),vec4a;
+ vec4a = vec4.scaleVec(vec4);
+ ensure("scaleVec:Fail " ,(is_approx_equal(x*x, vec4a.mV[VX]) && is_approx_equal(y*y, vec4a.mV[VY]) && is_approx_equal(z*z, vec4a.mV[VZ])&& is_approx_equal(w*w, vec4a.mV[VW])));
+ }
+
+ template<> template<>
+ void v4math_object::test<7>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4(x,y,z,w);
+ ensure("1:operator [] failed " ,( x == vec4[0]));
+ ensure("2:operator [] failed " ,( y == vec4[1]));
+ ensure("3:operator [] failed " ,( z == vec4[2]));
+ ensure("4:operator [] failed " ,( w == vec4[3]));
+ x = 23.f, y = -.2361f, z = 3.25;
+ vec4.setVec(x,y,z);
+ F32 &ref1 = vec4[0];
+ ensure("5:operator [] failed " ,( ref1 == vec4[0]));
+ F32 &ref2 = vec4[1];
+ ensure("6:operator [] failed " ,( ref2 == vec4[1]));
+ F32 &ref3 = vec4[2];
+ ensure("7:operator [] failed " ,( ref3 == vec4[2]));
+ F32 &ref4 = vec4[3];
+ ensure("8:operator [] failed " ,( ref4 == vec4[3]));
+ }
+
+ template<> template<>
+ void v4math_object::test<8>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ const F32 val[10] = {1.f,2.f,3.f,.34f,.1f,-.5f,2.f,1.23f,1.234f,.89f};
+ LLMatrix4 mat(val);
+ LLVector4 vec4(x,y,z,w),vec4a;
+ vec4.rotVec(mat);
+ vec4a.setVec(x,y,z,w);
+ vec4a.rotVec(mat);
+ ensure_equals("1:rotVec: Fail " ,vec4a, vec4);
+ F32 a = 2.32f, b = -23.2f, c = -34.1112f, d = 1.010112f;
+ LLQuaternion q(a,b,c,d);
+ LLVector4 vec4b(a,b,c,d),vec4c;
+ vec4b.rotVec(q);
+ vec4c.setVec(a, b, c, d);
+ vec4c.rotVec(q);
+ ensure_equals("2:rotVec: Fail " ,vec4b, vec4c);
+ }
+
+ template<> template<>
+ void v4math_object::test<9>()
+ {
+ F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f;
+ LLVector4 vec4(x,y,z,w),vec4a;;
+ std::ostringstream stream1, stream2;
+ stream1 << vec4;
+ vec4a.setVec(x,y,z,w);
+ stream2 << vec4a;
+ ensure("operator << failed",(stream1.str() == stream2.str()));
+ }
+
+ template<> template<>
+ void v4math_object::test<10>()
+ {
+ F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f, w1 = .23f;
+ F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f, w2 = 1.3f;
+ LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2),vec4b;
+ vec4b = vec4a + vec4;
+ ensure("1:operator+:Fail to initialize " ,(is_approx_equal(x1+x2,vec4b.mV[VX]) && is_approx_equal(y1+y2,vec4b.mV[VY]) && is_approx_equal(z1+z2,vec4b.mV[VZ])));
+ x1 = -2.45f, y1 = 2.1f, z1 = 3.0f;
+ vec4.clearVec();
+ vec4a.clearVec();
+ vec4.setVec(x1,y1,z1);
+ vec4a +=vec4;
+ ensure_equals("2:operator+=: Fail to initialize", vec4a,vec4);
+ vec4a += vec4;
+ ensure("3:operator+=:Fail to initialize " ,(is_approx_equal(2*x1,vec4a.mV[VX]) && is_approx_equal(2*y1,vec4a.mV[VY]) && is_approx_equal(2*z1,vec4a.mV[VZ])));
+ }
+ template<> template<>
+ void v4math_object::test<11>()
+ {
+ F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f, w1 = .23f;
+ F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f, w2 = 1.3f;
+ LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2),vec4b;
+ vec4b = vec4a - vec4;
+ ensure("1:operator-:Fail to initialize " ,(is_approx_equal(x2-x1,vec4b.mV[VX]) && is_approx_equal(y2-y1,vec4b.mV[VY]) && is_approx_equal(z2-z1,vec4b.mV[VZ])));
+ x1 = -2.45f, y1 = 2.1f, z1 = 3.0f;
+ vec4.clearVec();
+ vec4a.clearVec();
+ vec4.setVec(x1,y1,z1);
+ vec4a -=vec4;
+ ensure_equals("2:operator-=: Fail to initialize" , vec4a,-vec4);
+ vec4a -=vec4;
+ ensure("3:operator-=:Fail to initialize " ,(is_approx_equal(-2*x1,vec4a.mV[VX]) && is_approx_equal(-2*y1,vec4a.mV[VY]) && is_approx_equal(-2*z1,vec4a.mV[VZ])));
+ }
+
+ template<> template<>
+ void v4math_object::test<12>()
+ {
+ F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f;
+ F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f;
+ LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2);
+ F32 res = vec4 * vec4a;
+ ensure("1:operator* failed " ,is_approx_equal(res, x1*x2 + y1*y2 + z1*z2));
+ vec4a.clearVec();
+ F32 mulVal = 4.2f;
+ vec4a = vec4 * mulVal;
+ ensure("2:operator* failed " ,is_approx_equal(x1*mulVal,vec4a.mV[VX]) && is_approx_equal(y1*mulVal, vec4a.mV[VY])&& is_approx_equal(z1*mulVal, vec4a.mV[VZ]));
+ vec4a.clearVec();
+ vec4a = mulVal * vec4 ;
+ ensure("3:operator* failed " ,is_approx_equal(x1*mulVal, vec4a.mV[VX]) && is_approx_equal(y1*mulVal, vec4a.mV[VY])&& is_approx_equal(z1*mulVal, vec4a.mV[VZ]));
+ vec4 *= mulVal;
+ ensure("4:operator*= failed " ,is_approx_equal(x1*mulVal, vec4.mV[VX]) && is_approx_equal(y1*mulVal, vec4.mV[VY])&& is_approx_equal(z1*mulVal, vec4.mV[VZ]));
+ }
+
+ template<> template<>
+ void v4math_object::test<13>()
+ {
+ F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f;
+ F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f;
+ LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2),vec4b;
+ vec4b = vec4 % vec4a;
+ ensure("1:operator% failed " ,is_approx_equal(y1*z2 - y2*z1, vec4b.mV[VX]) && is_approx_equal(z1*x2 -z2*x1, vec4b.mV[VY]) && is_approx_equal(x1*y2-x2*y1, vec4b.mV[VZ]));
+ vec4 %= vec4a;
+ ensure_equals("operator%= failed " ,vec4,vec4b);
+ }
+
+ template<> template<>
+ void v4math_object::test<14>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f,div = 4.2f;
+ F32 t = 1.f / div;
+ LLVector4 vec4(x,y,z), vec4a;
+ vec4a = vec4/div;
+ ensure("1:operator/ failed " ,is_approx_equal(x*t, vec4a.mV[VX]) && is_approx_equal(y*t, vec4a.mV[VY])&& is_approx_equal(z*t, vec4a.mV[VZ]));
+ x = 1.23f, y = 4.f, z = -2.32f;
+ vec4.clearVec();
+ vec4a.clearVec();
+ vec4.setVec(x,y,z);
+ vec4a = vec4/div;
+ ensure("2:operator/ failed " ,is_approx_equal(x*t, vec4a.mV[VX]) && is_approx_equal(y*t, vec4a.mV[VY])&& is_approx_equal(z*t, vec4a.mV[VZ]));
+ vec4 /= div;
+ ensure("3:operator/ failed " ,is_approx_equal(x*t, vec4.mV[VX]) && is_approx_equal(y*t, vec4.mV[VY])&& is_approx_equal(z*t, vec4.mV[VZ]));
+ }
+
+ template<> template<>
+ void v4math_object::test<15>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f;
+ LLVector4 vec4(x,y,z), vec4a;
+ ensure("operator!= failed " ,(vec4 != vec4a));
+ vec4a = vec4;
+ ensure("operator== failed " ,(vec4 ==vec4a));
+ }
+
+ template<> template<>
+ void v4math_object::test<16>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f;
+ LLVector4 vec4(x,y,z), vec4a;
+ vec4a = - vec4;
+ ensure("operator- failed " , (vec4 == - vec4a));
+ }
+
+ template<> template<>
+ void v4math_object::test<17>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f,epsilon = .23425f;
+ LLVector4 vec4(x,y,z), vec4a(x,y,z);
+ ensure("1:are_parallel: Fail " ,(TRUE == are_parallel(vec4a,vec4,epsilon)));
+ x = 21.f, y = 12.f, z = -123.1f;
+ vec4a.clearVec();
+ vec4a.setVec(x,y,z);
+ ensure("2:are_parallel: Fail " ,(FALSE == are_parallel(vec4a,vec4,epsilon)));
+ }
+
+ template<> template<>
+ void v4math_object::test<18>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f;
+ F32 angle1, angle2;
+ LLVector4 vec4(x,y,z), vec4a(x,y,z);
+ angle1 = angle_between(vec4, vec4a);
+ vec4.normVec();
+ vec4a.normVec();
+ angle2 = acos(vec4 * vec4a);
+ ensure_equals("1:angle_between: Fail " ,angle1,angle2);
+ F32 x1 = 21.f, y1 = 2.23f, z1 = -1.1f;
+ LLVector4 vec4b(x,y,z), vec4c(x1,y1,z1);
+ angle1 = angle_between(vec4b, vec4c);
+ vec4b.normVec();
+ vec4c.normVec();
+ angle2 = acos(vec4b * vec4c);
+ ensure_equals("2:angle_between: Fail " ,angle1,angle2);
+ }
+
+ template<> template<>
+ void v4math_object::test<19>()
+ {
+ F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f;
+ F32 val1,val2;
+ LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2);
+ val1 = dist_vec(vec4,vec4a);
+ val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
+ ensure_equals("dist_vec: Fail ",val2, val1);
+ val1 = dist_vec_squared(vec4,vec4a);
+ val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
+ ensure_equals("dist_vec_squared: Fail ",val2, val1);
+ }
+
+ template<> template<>
+ void v4math_object::test<20>()
+ {
+ F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, w1 = -.23f, x2 = 1.3f, y2 = 1.f, z2 = 1.f,w2 = .12f;
+ F32 val = 2.3f,val1,val2,val3,val4;
+ LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2);
+ val1 = x1 + (x2 - x1)* val;
+ val2 = y1 + (y2 - y1)* val;
+ val3 = z1 + (z2 - z1)* val;
+ val4 = w1 + (w2 - w1)* val;
+ LLVector4 vec4b = lerp(vec4,vec4a,val);
+ ensure("lerp failed", ((val1 ==vec4b.mV[VX])&& (val2 ==vec4b.mV[VY]) && (val3 ==vec4b.mV[VZ])&& (val4 ==vec4b.mV[VW])));
+ }
+
+ template<> template<>
+ void v4math_object::test<21>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f;
+ LLVector4 vec4(x,y,z);
+ LLVector3 vec3 = vec4to3(vec4);
+ ensure("vec4to3 failed", ((x == vec3.mV[VX])&& (y == vec3.mV[VY]) && (z == vec3.mV[VZ])));
+ LLVector4 vec4a = vec3to4(vec3);
+ ensure_equals("vec3to4 failed",vec4a,vec4);
+ }
+
+ template<> template<>
+ void v4math_object::test<22>()
+ {
+ F32 x = 1.f, y = 2.f, z = -1.1f;
+ LLVector4 vec4(x,y,z);
+ LLSD llsd = vec4.getValue();
+ LLVector3 vec3(llsd);
+ LLVector4 vec4a = vec3to4(vec3);
+ ensure_equals("getValue failed",vec4a,vec4);
+ }
+}
--- 2007-03-13-Patch1\linden\indra\llmessage\llnamevalue.cpp Tue Mar 13 12:57:42 2007
+++ 2007-03-13\linden\indra\llmessage\llnamevalue.cpp Thu Mar 22 03:18:36 2007
@@ -133,10 +133,13 @@
mStringType = mNVNameTable->addString(type);
if (!strcmp(mStringType, "STRING"))
{
- S32 string_length = (S32)strlen(data); /*Flawfinder: Ignore*/
mType = NVT_STRING;
-
delete[] mNameValueReference.string;
+ mNameValueReference.string = NULL;
+
+ if (data)
+ {
+ S32 string_length = (S32)strlen(data); /*Flawfinder: Ignore*/
// two options here. . . data can either look like foo or "foo"
// WRONG! - this is a poorly implemented and incomplete escape
@@ -156,24 +159,45 @@
//}
mNameValueReference.string[string_length] = 0;
}
+ }
else if (!strcmp(mStringType, "F32"))
{
mType = NVT_F32;
+ delete mNameValueReference.f32;
+ mNameValueReference.f32 = NULL;
+ if (data)
+ {
mNameValueReference.f32 = new F32((F32)atof(data));
}
+ }
else if (!strcmp(mStringType, "S32"))
{
mType = NVT_S32;
+ delete mNameValueReference.s32;
+ mNameValueReference.s32 = NULL;
+ if (data)
+ {
mNameValueReference.s32 = new S32(atoi(data));
}
+ }
else if (!strcmp(mStringType, "U64"))
{
mType = NVT_U64;
+ delete mNameValueReference.u64;
+ mNameValueReference.u64 = NULL;
+ if (data)
+ {
mNameValueReference.u64 = new U64(str_to_U64(data));
}
+ }
else if (!strcmp(mStringType, "VEC3"))
{
+ delete mNameValueReference.vec3;
+ mNameValueReference.vec3 = NULL;
mType = NVT_VEC3;
+
+ if (data)
+ {
F32 t1, t2, t3;
// two options here. . . data can either look like 0, 1, 2 or <0, 1, 2>
@@ -197,17 +221,28 @@
mNameValueReference.vec3 = new LLVector3(t1, t2, t3);
}
+ }
else if (!strcmp(mStringType, "U32"))
{
mType = NVT_U32;
+ delete mNameValueReference.u32;
+ mNameValueReference.u32 = NULL;
+ if (data)
+ {
mNameValueReference.u32 = new U32(atoi(data));
}
+ }
else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
{
+ mType = NVT_ASSET;
+ delete [] mNameValueReference.string;
+ mNameValueReference.string = NULL;
+
+ if (data)
+ {
// assets are treated like strings, except that the name has
// meaning to an LLAssetInfo object
S32 string_length = (S32)strlen(data); /*Flawfinder: Ignore*/
- mType = NVT_ASSET;
// two options here. . . data can either look like foo or "foo"
// WRONG! - this is a poorly implemented and incomplete escape
@@ -227,6 +262,7 @@
//}
mNameValueReference.string[string_length] = 0;
}
+ }
else
{
llwarns << "Unknown name value type string " << mStringType << " for " << mName << llendl;
@@ -339,71 +375,7 @@
LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass, TNameValueCallback nvcb, void **user_data)
{
baseInit();
- mName = mNVNameTable->addString(name);
-
- // Nota Bene: Whatever global structure manages this should have these in the name table already!
- mStringType = mNVNameTable->addString(type);
- if (!strcmp(mStringType, "STRING"))
- {
- mType = NVT_STRING;
- mNameValueReference.string = NULL;
- }
- else if (!strcmp(mStringType, "F32"))
- {
- mType = NVT_F32;
- mNameValueReference.f32 = NULL;
- }
- else if (!strcmp(mStringType, "S32"))
- {
- mType = NVT_S32;
- mNameValueReference.s32 = NULL;
- }
- else if (!strcmp(mStringType, "VEC3"))
- {
- mType = NVT_VEC3;
- mNameValueReference.vec3 = NULL;
- }
- else if (!strcmp(mStringType, "U32"))
- {
- mType = NVT_U32;
- mNameValueReference.u32 = NULL;
- }
- else if (!strcmp(mStringType, "U64"))
- {
- mType = NVT_U64;
- mNameValueReference.u64 = NULL;
- }
- else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
- {
- mType = NVT_ASSET;
- mNameValueReference.string = NULL;
- }
- else
- {
- mType = NVT_NULL;
- llinfos << "Unknown name-value type " << mStringType << llendl;
- }
-
- // Nota Bene: Whatever global structure manages this should have these in the name table already!
- mStringClass = mNVNameTable->addString(nvclass);
- if (!strcmp(mStringClass, "READ_ONLY"))
- {
- mClass = NVC_READ_ONLY;
- }
- else if (!strcmp(mStringClass, "READ_WRITE"))
- {
- mClass = NVC_READ_WRITE;
- }
- else if (!strcmp(mStringClass, "CALLBACK"))
- {
- mClass = NVC_READ_WRITE;
- mNameValueCB = nvcb;
- mUserData = user_data;
- }
-
- // Initialize the sendto variable
- mStringSendto = mNVNameTable->addString("SIM");
- mSendto = NVS_SIM;
+ init(name, NULL, type, nvclass, "SIM", nvcb, user_data);
}
@@ -746,6 +718,9 @@
case NVT_U32:
return (F32)(*mNameValueReference.u32);
break;
+ case NVT_U64:
+ return (F32)(*mNameValueReference.u64); // can be trunction of data
+ break;
default:
llerrs << "No magnitude operation for NV type " << mStringType << llendl;
break;
@@ -863,11 +838,6 @@
{
strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */
}
-
- if (b_changed)
- {
- callCallback();
- }
}
else
{
@@ -917,11 +887,6 @@
{
strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */
}
-
- if (b_changed)
- {
- callCallback();
- }
}
else
{
@@ -935,6 +900,7 @@
default:
break;
}
+
if (b_changed)
{
callCallback();
@@ -957,14 +923,11 @@
b_changed = TRUE;
}
*mNameValueReference.f32 = a;
- if (b_changed)
- {
- callCallback();
- }
break;
default:
break;
}
+
if (b_changed)
{
callCallback();
@@ -989,10 +952,6 @@
b_changed = TRUE;
}
*mNameValueReference.s32 = a;
- if (b_changed)
- {
- callCallback();
- }
break;
case NVT_U32:
if ( (mClass == NVC_CALLBACK)
@@ -1001,10 +960,14 @@
b_changed = TRUE;
}
*mNameValueReference.u32 = a;
- if (b_changed)
+ break;
+ case NVT_U64:
+ if ( (mClass == NVC_CALLBACK)
+ && ((S32) (*this->mNameValueReference.u64) != a))
{
- callCallback();
+ b_changed = TRUE;
}
+ *mNameValueReference.u64 = a;
break;
case NVT_F32:
if ( (mClass == NVC_CALLBACK)
@@ -1013,14 +976,11 @@
b_changed = TRUE;
}
*mNameValueReference.f32 = (F32)a;
- if (b_changed)
- {
- callCallback();
- }
break;
default:
break;
}
+
if (b_changed)
{
callCallback();
@@ -1045,10 +1005,6 @@
b_changed = TRUE;
}
*mNameValueReference.s32 = a;
- if (b_changed)
- {
- callCallback();
- }
break;
case NVT_U32:
if ( (mClass == NVC_CALLBACK)
@@ -1057,10 +1013,14 @@
b_changed = TRUE;
}
*mNameValueReference.u32 = a;
- if (b_changed)
+ break;
+ case NVT_U64:
+ if ( (mClass == NVC_CALLBACK)
+ &&(*this->mNameValueReference.u64 != a))
{
- callCallback();
+ b_changed = TRUE;
}
+ *mNameValueReference.u64 = a;
break;
case NVT_F32:
if ( (mClass == NVC_CALLBACK)
@@ -1069,15 +1029,17 @@
b_changed = TRUE;
}
*mNameValueReference.f32 = (F32)a;
- if (b_changed)
- {
- callCallback();
- }
break;
default:
llerrs << "NameValue: Trying to set U32 into a " << mStringType << ", unknown conversion" << llendl;
break;
}
+
+ if (b_changed)
+ {
+ callCallback();
+ }
+
return;
}
@@ -1097,15 +1059,17 @@
b_changed = TRUE;
}
*mNameValueReference.vec3 = a;
- if (b_changed)
- {
- callCallback();
- }
break;
default:
llerrs << "NameValue: Trying to set LLVector3 into a " << mStringType << ", unknown conversion" << llendl;
break;
}
+
+ if (b_changed)
+ {
+ callCallback();
+ }
+
return;
}
@@ -1124,6 +1088,8 @@
return (*mNameValueReference.s32 != 0);
case NVT_U32:
return (*mNameValueReference.u32 != 0);
+ case NVT_U64:
+ return (*mNameValueReference.u64 != 0);
case NVT_VEC3:
return (mNameValueReference.vec3->magVecSquared() != 0.f);
default:
@@ -1200,6 +1166,7 @@
U64_to_str(*a.mNameValueReference.u64, u64_string, sizeof(u64_string));
s << u64_string;
}
+ break;
case NVT_VEC3:
s << *(a.mNameValueReference.vec3);
break;
@@ -1258,6 +1225,13 @@
delete retval.mNameValueReference.f32;
retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 + *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 + *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1281,6 +1255,13 @@
delete retval.mNameValueReference.s32;
retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 + *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 + (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1304,6 +1285,43 @@
delete retval.mNameValueReference.u32;
retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 + *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u32 + *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_F32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 + (U64) *b.mNameValueReference.f32);
+ }
+ else if (b.mType == NVT_S32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 + *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 + *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 + *b.mNameValueReference.u64);
+ }
break;
case NVT_VEC3:
if ( (a.mType == b.mType)
@@ -1352,6 +1370,13 @@
delete retval.mNameValueReference.f32;
retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 - *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 - (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1375,6 +1400,13 @@
delete retval.mNameValueReference.s32;
retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 - *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 - (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1393,10 +1425,47 @@
}
else if (b.mType == NVT_U32)
{
- retval.mType = NVT_U32;
- retval.mStringType = NameValueTypeStrings[NVT_U32];
- delete retval.mNameValueReference.u32;
- retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 - *b.mNameValueReference.u32);
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 - *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 - (U32) *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_F32)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u64 - *b.mNameValueReference.f32);
+ }
+ else if (b.mType == NVT_S32)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) *a.mNameValueReference.u64 - *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) *a.mNameValueReference.u64 - *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) (*a.mNameValueReference.u64 - *b.mNameValueReference.u64));
}
break;
case NVT_VEC3:
@@ -1446,6 +1515,13 @@
delete retval.mNameValueReference.f32;
retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1469,6 +1545,13 @@
delete retval.mNameValueReference.s32;
retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 * *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32; // should add S64 support.
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 * (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1492,20 +1575,57 @@
delete retval.mNameValueReference.u32;
retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 * *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u32 * *b.mNameValueReference.u64);
+ }
break;
- case NVT_VEC3:
- if ( (a.mType == b.mType)
- &&(a.mType == NVT_VEC3))
+ case NVT_U64:
+ if (b.mType == NVT_F32)
{
retval.mType = NVT_F32;
- retval.mStringType = NameValueTypeStrings[a.mType];
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
delete retval.mNameValueReference.f32;
- retval.mNameValueReference.f32 = new F32((*a.mNameValueReference.vec3) * (*b.mNameValueReference.vec3));
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u64 * *b.mNameValueReference.f32);
}
- break;
- default:
- llerrs << "Unknown multiply of NV type " << a.mStringType << " to " << b.mStringType << llendl;
- break;
+ else if (b.mType == NVT_S32)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) *a.mNameValueReference.u64 * *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 * *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 * *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_VEC3:
+ if ( (a.mType == b.mType)
+ &&(a.mType == NVT_VEC3))
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[a.mType];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32((*a.mNameValueReference.vec3) * (*b.mNameValueReference.vec3));
+ }
+ break;
+ default:
+ llerrs << "Unknown multiply of NV type " << a.mStringType << " to " << b.mStringType << llendl;
+ break;
}
return retval;
}
@@ -1540,6 +1660,13 @@
delete retval.mNameValueReference.f32;
retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 / *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 / (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1563,6 +1690,13 @@
delete retval.mNameValueReference.s32;
retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 / *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 / (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1586,6 +1720,43 @@
delete retval.mNameValueReference.u32;
retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 / *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U32;
+ retval.mStringType = NameValueTypeStrings[NVT_U32];
+ delete retval.mNameValueReference.u32;
+ retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 / (U32) *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_F32)
+ {
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u64 / *b.mNameValueReference.f32);
+ }
+ else if (b.mType == NVT_S32)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) *a.mNameValueReference.u64 / *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 / *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 / *b.mNameValueReference.u64);
+ }
break;
default:
llerrs << "Unknown divide of NV type " << a.mStringType << " to " << b.mStringType << llendl;
@@ -1619,6 +1790,13 @@
delete retval.mNameValueReference.s32;
retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 % *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 % (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_S32)
@@ -1635,6 +1813,36 @@
delete retval.mNameValueReference.u32;
retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 % *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U32;
+ retval.mStringType = NameValueTypeStrings[NVT_U32];
+ delete retval.mNameValueReference.u32;
+ retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 % (U32) *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_S32)
+ {
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ retval.mNameValueReference.s32 = new S32((S32) *a.mNameValueReference.u64 % *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 % *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ retval.mType = NVT_U64;
+ retval.mStringType = NameValueTypeStrings[NVT_U64];
+ delete retval.mNameValueReference.u64;
+ retval.mNameValueReference.u64 = new U64(*a.mNameValueReference.u64 % *b.mNameValueReference.u64);
+ }
break;
case NVT_VEC3:
if ( (a.mType == b.mType)
@@ -1681,6 +1889,12 @@
delete retval.mNameValueReference.f32;
retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 * k);
break;
+ case NVT_U64:
+ retval.mType = NVT_F32;
+ retval.mStringType = NameValueTypeStrings[NVT_F32];
+ delete retval.mNameValueReference.f32;
+ retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u64 * k);
+ break;
case NVT_VEC3:
retval.mType = a.mType;
retval.mStringType = NameValueTypeStrings[a.mType];
@@ -1697,41 +1911,7 @@
LLNameValue &operator*(F32 k, const LLNameValue &a)
{
- static LLNameValue retval;
-
- switch(a.mType)
- {
- case NVT_STRING:
- break;
- case NVT_F32:
- retval.mType = NVT_F32;
- retval.mStringType = NameValueTypeStrings[NVT_F32];
- delete retval.mNameValueReference.f32;
- retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * k);
- break;
- case NVT_S32:
- retval.mType = NVT_F32;
- retval.mStringType = NameValueTypeStrings[NVT_F32];
- delete retval.mNameValueReference.f32;
- retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 * k);
- break;
- case NVT_U32:
- retval.mType = NVT_F32;
- retval.mStringType = NameValueTypeStrings[NVT_F32];
- delete retval.mNameValueReference.f32;
- retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 * k);
- break;
- case NVT_VEC3:
- retval.mType = a.mType;
- retval.mStringType = NameValueTypeStrings[a.mType];
- delete retval.mNameValueReference.vec3;
- retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 * k);
- break;
- default:
- llerrs << "Unknown multiply of NV type " << a.mStringType << " with F32" << llendl;
- break;
- }
- return retval;
+ return a * k;
}
@@ -1762,6 +1942,10 @@
{
return (*a.mNameValueReference.f32 == *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.f32 == (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1776,6 +1960,10 @@
{
return (*a.mNameValueReference.s32 == (S32) *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.s32 == (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1790,6 +1978,28 @@
{
return (*a.mNameValueReference.u32 == *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.u32 == (U32) *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_F32)
+ {
+ return (*a.mNameValueReference.u64 == *b.mNameValueReference.f32);
+ }
+ else if (b.mType == NVT_S32)
+ {
+ return ((S32) *a.mNameValueReference.u64 == *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ return (*a.mNameValueReference.u64 == *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.u64 == *b.mNameValueReference.u64);
+ }
break;
case NVT_VEC3:
if ( (a.mType == b.mType)
@@ -1829,6 +2039,10 @@
{
return (*a.mNameValueReference.f32 <= *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.f32 <= (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1843,6 +2057,10 @@
{
return (*a.mNameValueReference.s32 <= (S32) *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.s32 <= (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1857,6 +2075,28 @@
{
return (*a.mNameValueReference.u32 <= *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.u32 <= (U32) *b.mNameValueReference.u64);
+ }
+ break;
+ case NVT_U64:
+ if (b.mType == NVT_F32)
+ {
+ return (*a.mNameValueReference.u64 <= *b.mNameValueReference.f32);
+ }
+ else if (b.mType == NVT_S32)
+ {
+ return ((S32) *a.mNameValueReference.u64 <= *b.mNameValueReference.s32);
+ }
+ else if (b.mType == NVT_U32)
+ {
+ return (*a.mNameValueReference.u64 <= *b.mNameValueReference.u32);
+ }
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.u64 <= *b.mNameValueReference.u64);
+ }
break;
default:
llerrs << "Unknown <= NV type " << a.mStringType << " with " << b.mStringType << llendl;
@@ -1891,6 +2131,10 @@
{
return (*a.mNameValueReference.f32 >= *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.f32 >= (F32) *b.mNameValueReference.u64);
+ }
break;
case NVT_S32:
if (b.mType == NVT_F32)
@@ -1905,6 +2149,10 @@
{
return (*a.mNameValueReference.s32 >= (S32) *b.mNameValueReference.u32);
}
+ else if (b.mType == NVT_U64)
+ {
+ return (*a.mNameValueReference.s32 >= (S32) *b.mNameValueReference.u64);
+ }
break;
case NVT_U32:
if (b.mType == NVT_F32)
@@ -1919,202 +2167,75 @@
{
return (*a.mNameValueReference.u32 >= *b.mNameValueReference.u32);
}
- break;
- default:
- llerrs << "Unknown >= NV type " << a.mStringType << " with " << b.mStringType << llendl;
- break;
- }
- return FALSE;
-}
-
-
-bool operator<(const LLNameValue &a, const LLNameValue &b)
-{
- switch(a.mType)
- {
- case NVT_STRING:
- if ( (a.mType == b.mType)
- &&(a.mType == NVT_STRING))
- {
- S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string);
- return (retval < 0);
- }
- break;
- case NVT_F32:
- if (b.mType == NVT_F32)
+ else if (b.mType == NVT_U64)
{
- return (*a.mNameValueReference.f32 < *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
- {
- return (*a.mNameValueReference.f32 < *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.f32 < *b.mNameValueReference.u32);
+ return (*a.mNameValueReference.u32 >= (U32) *b.mNameValueReference.u64);
}
break;
- case NVT_S32:
+ case NVT_U64:
if (b.mType == NVT_F32)
{
- return (*a.mNameValueReference.s32 < *b.mNameValueReference.f32);
+ return (*a.mNameValueReference.u64 >= *b.mNameValueReference.f32);
}
else if (b.mType == NVT_S32)
{
- return (*a.mNameValueReference.s32 < *b.mNameValueReference.s32);
+ return ((S32) *a.mNameValueReference.u64 >= *b.mNameValueReference.s32);
}
else if (b.mType == NVT_U32)
{
- return (*a.mNameValueReference.s32 < (S32) *b.mNameValueReference.u32);
+ return (*a.mNameValueReference.u64 >= *b.mNameValueReference.u32);
}
- break;
- case NVT_U32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.u32 < *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
+ else if (b.mType == NVT_U64)
{
- return ((S32) *a.mNameValueReference.u32 < *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.u32 < *b.mNameValueReference.u32);
+ return (*a.mNameValueReference.u64 >= (U32) *b.mNameValueReference.u64);
}
break;
default:
- llerrs << "Unknown < NV type " << a.mStringType << " with " << b.mStringType << llendl;
+ llerrs << "Unknown >= NV type " << a.mStringType << " with " << b.mStringType << llendl;
break;
}
return FALSE;
}
-bool operator>(const LLNameValue &a, const LLNameValue &b)
-{
- switch(a.mType)
- {
- case NVT_STRING:
- if ( (a.mType == b.mType)
- &&(a.mType == NVT_STRING))
- {
- S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string);
- return (retval > 0);
- }
- break;
- case NVT_F32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.f32 > *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
- {
- return (*a.mNameValueReference.f32 > *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.f32 > *b.mNameValueReference.u32);
- }
- break;
- case NVT_S32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.s32 > *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
+bool operator<(const LLNameValue &a, const LLNameValue &b)
{
- return (*a.mNameValueReference.s32 > *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
+ if ((a.mType == NVT_STRING && b.mType == NVT_STRING) ||
+ ((a.mType == NVT_F32 || a.mType == NVT_S32 || a.mType == NVT_U32 || a.mType == NVT_U64) &&
+ (b.mType == NVT_F32 || b.mType == NVT_S32 || b.mType == NVT_U32 || b.mType == NVT_U64)))
{
- return (*a.mNameValueReference.s32 > (S32) *b.mNameValueReference.u32);
+ return !(a >= b);
}
- break;
- case NVT_U32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.u32 > *b.mNameValueReference.f32);
+
+ llerrs << "Unknown < NV type " << a.mStringType << " with " << b.mStringType << llendl;
+ return FALSE;
}
- else if (b.mType == NVT_S32)
+
+
+bool operator>(const LLNameValue &a, const LLNameValue &b)
{
- return ((S32) *a.mNameValueReference.u32 > *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
+ if ((a.mType == NVT_STRING && b.mType == NVT_STRING) ||
+ ((a.mType == NVT_F32 || a.mType == NVT_S32 || a.mType == NVT_U32 || a.mType == NVT_U64) &&
+ (b.mType == NVT_F32 || b.mType == NVT_S32 || b.mType == NVT_U32 || b.mType == NVT_U64)))
{
- return (*a.mNameValueReference.u32 > *b.mNameValueReference.u32);
+ return !(a <= b);
}
- break;
- default:
+
llerrs << "Unknown > NV type " << a.mStringType << " with " << b.mStringType << llendl;
- break;
- }
return FALSE;
}
bool operator!=(const LLNameValue &a, const LLNameValue &b)
{
- switch(a.mType)
- {
- case NVT_STRING:
- if ( (a.mType == b.mType)
- &&(a.mType == NVT_STRING))
+ if ((a.mType == NVT_STRING && b.mType == NVT_STRING) ||
+ (a.mType == NVT_VEC3 && b.mType == NVT_VEC3) ||
+ ((a.mType == NVT_F32 || a.mType == NVT_S32 || a.mType == NVT_U32 || a.mType == NVT_U64) &&
+ (b.mType == NVT_F32 || b.mType == NVT_S32 || b.mType == NVT_U32 || b.mType == NVT_U64)))
{
- return (strcmp(a.mNameValueReference.string, b.mNameValueReference.string)) ? true : false;
+ return !(a == b);
}
- break;
- case NVT_F32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.f32 != *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
- {
- return (*a.mNameValueReference.f32 != *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.f32 != *b.mNameValueReference.u32);
- }
- break;
- case NVT_S32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.s32 != *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
- {
- return (*a.mNameValueReference.s32 != *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.s32 != (S32) *b.mNameValueReference.u32);
- }
- break;
- case NVT_U32:
- if (b.mType == NVT_F32)
- {
- return (*a.mNameValueReference.u32 != *b.mNameValueReference.f32);
- }
- else if (b.mType == NVT_S32)
- {
- return ((S32) *a.mNameValueReference.u32 != *b.mNameValueReference.s32);
- }
- else if (b.mType == NVT_U32)
- {
- return (*a.mNameValueReference.u32 != *b.mNameValueReference.u32);
- }
- break;
- case NVT_VEC3:
- if ( (a.mType == b.mType)
- &&(a.mType == NVT_VEC3))
- {
- return (*a.mNameValueReference.vec3 != *b.mNameValueReference.vec3);
- }
- break;
- default:
+
llerrs << "Unknown != NV type " << a.mStringType << " with " << b.mStringType << llendl;
- break;
- }
return FALSE;
}
@@ -2145,6 +2266,13 @@
delete retval.mNameValueReference.s32;
// Can't do unary minus on U32, doesn't work.
retval.mNameValueReference.s32 = new S32(-S32(*a.mNameValueReference.u32));
+ break;
+ case NVT_U64:
+ retval.mType = NVT_S32;
+ retval.mStringType = NameValueTypeStrings[NVT_S32];
+ delete retval.mNameValueReference.s32;
+ // Can't do unary minus on U64, doesn't work.
+ retval.mNameValueReference.s32 = new S32(-S32(*a.mNameValueReference.u64));
break;
case NVT_VEC3:
retval.mType = a.mType;
More information about the SLDev
mailing list