diff options
Diffstat (limited to 'linden/indra/test')
-rw-r--r-- | linden/indra/test/common.cpp | 2 | ||||
-rw-r--r-- | linden/indra/test/files.lst | 2 | ||||
-rw-r--r-- | linden/indra/test/llbitpack_tut.cpp | 119 | ||||
-rw-r--r-- | linden/indra/test/lldatapacker_tut.cpp | 571 | ||||
-rw-r--r-- | linden/indra/test/llhttpclient_tut.cpp | 9 | ||||
-rw-r--r-- | linden/indra/test/llinventoryparcel_tut.cpp | 70 | ||||
-rw-r--r-- | linden/indra/test/lliohttpserver_tut.cpp | 2 | ||||
-rw-r--r-- | linden/indra/test/llpartdata_tut.cpp | 217 | ||||
-rw-r--r--[-rwxr-xr-x] | linden/indra/test/llrandom_tut.cpp | 0 | ||||
-rw-r--r-- | linden/indra/test/llsdserialize_tut.cpp | 5 | ||||
-rw-r--r-- | linden/indra/test/llservicebuilder_tut.cpp | 152 | ||||
-rw-r--r-- | linden/indra/test/llstring_tut.cpp | 498 | ||||
-rw-r--r-- | linden/indra/test/lltut.h | 16 | ||||
-rw-r--r-- | linden/indra/test/llxfer_tut.cpp | 61 | ||||
-rw-r--r-- | linden/indra/test/m3math_tut.cpp | 320 | ||||
-rw-r--r-- | linden/indra/test/v2math_tut.cpp | 447 | ||||
-rw-r--r-- | linden/indra/test/v3dmath_tut.cpp | 402 | ||||
-rw-r--r-- | linden/indra/test/v3math_tut.cpp | 568 | ||||
-rw-r--r-- | linden/indra/test/xform_tut.cpp | 247 |
19 files changed, 3629 insertions, 79 deletions
diff --git a/linden/indra/test/common.cpp b/linden/indra/test/common.cpp index 2a88ba0..d32a4ca 100644 --- a/linden/indra/test/common.cpp +++ b/linden/indra/test/common.cpp | |||
@@ -305,7 +305,7 @@ namespace tut | |||
305 | template<> template<> | 305 | template<> template<> |
306 | void sd_object::test<13>() | 306 | void sd_object::test<13>() |
307 | { | 307 | { |
308 | for(S32 i = 0; i < 10000; ++i) | 308 | for(S32 i = 0; i < 1000; ++i) |
309 | { | 309 | { |
310 | // gen up a starting point | 310 | // gen up a starting point |
311 | std::string expected; | 311 | std::string expected; |
diff --git a/linden/indra/test/files.lst b/linden/indra/test/files.lst index b04b0ac..74f8879 100644 --- a/linden/indra/test/files.lst +++ b/linden/indra/test/files.lst | |||
@@ -7,6 +7,7 @@ test/llblowfish_tut.cpp | |||
7 | test/llerror_tut.cpp | 7 | test/llerror_tut.cpp |
8 | test/llhttpclient_tut.cpp | 8 | test/llhttpclient_tut.cpp |
9 | test/llhttpnode_tut.cpp | 9 | test/llhttpnode_tut.cpp |
10 | test/llinventoryparcel_tut.cpp | ||
10 | test/lliohttpserver_tut.cpp | 11 | test/lliohttpserver_tut.cpp |
11 | test/llmime_tut.cpp | 12 | test/llmime_tut.cpp |
12 | test/llmessageconfig_tut.cpp | 13 | test/llmessageconfig_tut.cpp |
@@ -20,6 +21,7 @@ test/llservicebuilder_tut.cpp | |||
20 | test/lltiming_tut.cpp | 21 | test/lltiming_tut.cpp |
21 | test/lltut.cpp | 22 | test/lltut.cpp |
22 | test/lluri_tut.cpp | 23 | test/lluri_tut.cpp |
24 | test/llxfer_tut.cpp | ||
23 | test/math.cpp | 25 | test/math.cpp |
24 | test/reflection_tut.cpp | 26 | test/reflection_tut.cpp |
25 | test/test.cpp | 27 | test/test.cpp |
diff --git a/linden/indra/test/llbitpack_tut.cpp b/linden/indra/test/llbitpack_tut.cpp new file mode 100644 index 0000000..1040a96 --- /dev/null +++ b/linden/indra/test/llbitpack_tut.cpp | |||
@@ -0,0 +1,119 @@ | |||
1 | /** | ||
2 | * @file llbitpack_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date February 2007 | ||
5 | * @brief llstreamtools test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "linden_common.h" | ||
32 | #include "bitpack.h" | ||
33 | #include "lltut.h" | ||
34 | |||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct bit_pack | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<bit_pack> bit_pack_t; | ||
42 | typedef bit_pack_t::object bit_pack_object_t; | ||
43 | tut::bit_pack_t tut_bit_pack("bitpack"); | ||
44 | |||
45 | // pack -> unpack | ||
46 | template<> template<> | ||
47 | void bit_pack_object_t::test<1>() | ||
48 | { | ||
49 | U8 packbuffer[255]; | ||
50 | U8 unpackbuffer[255]; | ||
51 | int pack_bufsize = 0; | ||
52 | int unpack_bufsize = 0; | ||
53 | |||
54 | LLBitPack bitpack(packbuffer, 255); | ||
55 | |||
56 | char str[] = "SecondLife is a 3D virtual world"; | ||
57 | int len = sizeof(str); | ||
58 | pack_bufsize = bitpack.bitPack((U8*) str, len*8); | ||
59 | pack_bufsize = bitpack.flushBitPack(); | ||
60 | |||
61 | LLBitPack bitunpack(packbuffer, pack_bufsize*8); | ||
62 | unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, len*8); | ||
63 | ensure("bitPack: unpack size should be same as string size prior to pack", len == unpack_bufsize); | ||
64 | ensure_memory_matches("str->bitPack->bitUnpack should be equal to string", str, len, unpackbuffer, unpack_bufsize); | ||
65 | } | ||
66 | |||
67 | // pack large, unpack in individual bytes | ||
68 | template<> template<> | ||
69 | void bit_pack_object_t::test<2>() | ||
70 | { | ||
71 | U8 packbuffer[255]; | ||
72 | U8 unpackbuffer[255]; | ||
73 | int pack_bufsize = 0; | ||
74 | int unpack_bufsize = 0; | ||
75 | |||
76 | LLBitPack bitpack(packbuffer, 255); | ||
77 | |||
78 | char str[] = "SecondLife"; | ||
79 | int len = sizeof(str); | ||
80 | pack_bufsize = bitpack.bitPack((U8*) str, len*8); | ||
81 | pack_bufsize = bitpack.flushBitPack(); | ||
82 | |||
83 | LLBitPack bitunpack(packbuffer, pack_bufsize*8); | ||
84 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
85 | ensure("bitPack: individual unpack: 0", unpackbuffer[0] == (U8) str[0]); | ||
86 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
87 | ensure("bitPack: individual unpack: 1", unpackbuffer[0] == (U8) str[1]); | ||
88 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
89 | ensure("bitPack: individual unpack: 2", unpackbuffer[0] == (U8) str[2]); | ||
90 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
91 | ensure("bitPack: individual unpack: 3", unpackbuffer[0] == (U8) str[3]); | ||
92 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
93 | ensure("bitPack: individual unpack: 4", unpackbuffer[0] == (U8) str[4]); | ||
94 | unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8); | ||
95 | ensure("bitPack: individual unpack: 5", unpackbuffer[0] == (U8) str[5]); | ||
96 | unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, 8*4); // Life | ||
97 | ensure_memory_matches("bitPack: 4 bytes unpack:", unpackbuffer, 4, str+6, 4); | ||
98 | } | ||
99 | |||
100 | // U32 packing | ||
101 | template<> template<> | ||
102 | void bit_pack_object_t::test<3>() | ||
103 | { | ||
104 | U8 packbuffer[255]; | ||
105 | int pack_bufsize = 0; | ||
106 | |||
107 | LLBitPack bitpack(packbuffer, 255); | ||
108 | U32 num = 0x41fab67a; | ||
109 | pack_bufsize = bitpack.bitPack((U8*)&num, 8*sizeof(U32)); | ||
110 | pack_bufsize = bitpack.flushBitPack(); | ||
111 | |||
112 | LLBitPack bitunpack(packbuffer, pack_bufsize*8); | ||
113 | U32 res = 0; | ||
114 | // since packing and unpacking is done on same machine in the unit test run, | ||
115 | // endianness should not matter | ||
116 | bitunpack.bitUnpack((U8*) &res, sizeof(res)*8); | ||
117 | ensure("U32->bitPack->bitUnpack->U32 should be equal", num == res); | ||
118 | } | ||
119 | } | ||
diff --git a/linden/indra/test/lldatapacker_tut.cpp b/linden/indra/test/lldatapacker_tut.cpp new file mode 100644 index 0000000..71def35 --- /dev/null +++ b/linden/indra/test/lldatapacker_tut.cpp | |||
@@ -0,0 +1,571 @@ | |||
1 | /** | ||
2 | * @file lldatapacker_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date February 2007 | ||
5 | * @brief LLDataPacker test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | #include "linden_common.h" | ||
33 | #include "lldatapacker.h" | ||
34 | #include "v4color.h" | ||
35 | #include "v4coloru.h" | ||
36 | #include "v2math.h" | ||
37 | #include "v3math.h" | ||
38 | #include "v4math.h" | ||
39 | #include "llsdserialize.h" | ||
40 | |||
41 | #define TEST_FILE_NAME "datapacker_test.txt" | ||
42 | namespace tut | ||
43 | { | ||
44 | struct datapacker_test | ||
45 | { | ||
46 | }; | ||
47 | typedef test_group<datapacker_test> datapacker_test_t; | ||
48 | typedef datapacker_test_t::object datapacker_test_object_t; | ||
49 | tut::datapacker_test_t tut_datapacker_test("datapacker_test"); | ||
50 | |||
51 | //*********LLDataPackerBinaryBuffer | ||
52 | template<> template<> | ||
53 | void datapacker_test_object_t::test<1>() | ||
54 | { | ||
55 | U8 packbuf[128]; | ||
56 | F32 f_val1 = 44.44f, f_unpkval1; | ||
57 | F32 f_val2 = 12344.443232f, f_unpkval2; | ||
58 | F32 f_val3 = 44.4456789f, f_unpkval3; | ||
59 | LLDataPackerBinaryBuffer lldp(packbuf,128); | ||
60 | lldp.packFixed( f_val1, "linden_lab", FALSE, 8, 8); | ||
61 | lldp.packFixed( f_val2, "linden_lab", FALSE, 14, 16); | ||
62 | lldp.packFixed( f_val3, "linden_lab", FALSE, 8, 23); | ||
63 | |||
64 | LLDataPackerBinaryBuffer lldp1(packbuf, lldp.getCurrentSize()); | ||
65 | lldp1.unpackFixed(f_unpkval1, "linden_lab", FALSE, 8, 8); | ||
66 | lldp1.unpackFixed(f_unpkval2, "linden_lab", FALSE, 14, 16); | ||
67 | lldp1.unpackFixed(f_unpkval3, "linden_lab", FALSE, 8, 23); | ||
68 | ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 8 failed", f_val1, f_unpkval1, 8); | ||
69 | ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 16 failed", f_val2, f_unpkval2, 16); | ||
70 | ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 23 failed", f_val3, f_unpkval3, 31); | ||
71 | } | ||
72 | |||
73 | template<> template<> | ||
74 | void datapacker_test_object_t::test<2>() | ||
75 | { | ||
76 | U8 packbuf[1024]; | ||
77 | |||
78 | char str[] = "SecondLife is virtual World\0"; | ||
79 | char strBinary[] = "SecondLife is virtual World"; | ||
80 | char strBinaryFixed[] = "Fixed Data"; | ||
81 | S32 sizeBinaryFixed = sizeof(strBinaryFixed); | ||
82 | U8 valU8 = 'C'; | ||
83 | U16 valU16 = 0xFFFF; | ||
84 | U32 valU32 = 0xFFFFFFFF; | ||
85 | S32 valS32 = -94967295; | ||
86 | F32 valF32 = 4354355.44f ; | ||
87 | LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f); | ||
88 | LLColor4U llcol4u(3, 128, 24, 33); | ||
89 | LLVector2 llvec2(333.33f, 444.44f); | ||
90 | LLVector3 llvec3(333.33f, 444.44f, 555.55f); | ||
91 | LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f); | ||
92 | LLUUID uuid; | ||
93 | |||
94 | std::string unpkstr; | ||
95 | char unpkstrBinary[256]; | ||
96 | char unpkstrBinaryFixed[256]; | ||
97 | S32 unpksizeBinary; | ||
98 | U8 unpkvalU8; | ||
99 | U16 unpkvalU16; | ||
100 | U32 unpkvalU32; | ||
101 | S32 unpkvalS32; | ||
102 | F32 unpkvalF32; | ||
103 | LLColor4 unpkllcol4; | ||
104 | LLColor4U unpkllcol4u; | ||
105 | LLVector2 unpkllvec2; | ||
106 | LLVector3 unpkllvec3; | ||
107 | LLVector4 unpkllvec4; | ||
108 | LLUUID unpkuuid; | ||
109 | |||
110 | LLDataPackerBinaryBuffer lldp(packbuf,1024); | ||
111 | lldp.packString(str , "linden_lab_str"); | ||
112 | lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd"); | ||
113 | lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
114 | lldp.packU8(valU8,"linden_lab_u8"); | ||
115 | lldp.packU16(valU16,"linden_lab_u16"); | ||
116 | lldp.packU32(valU32, "linden_lab_u32"); | ||
117 | lldp.packS32(valS32, "linden_lab_s32"); | ||
118 | lldp.packF32(valF32, "linden_lab_f32"); | ||
119 | lldp.packColor4(llcol4, "linden_lab_col4"); | ||
120 | lldp.packColor4U(llcol4u, "linden_lab_col4u"); | ||
121 | lldp.packVector2(llvec2, "linden_lab_vec2"); | ||
122 | lldp.packVector3(llvec3, "linden_lab_vec3"); | ||
123 | lldp.packVector4(llvec4, "linden_lab_vec4"); | ||
124 | uuid.generate(); | ||
125 | lldp.packUUID(uuid, "linden_lab_uuid"); | ||
126 | |||
127 | S32 cur_size = lldp.getCurrentSize(); | ||
128 | |||
129 | LLDataPackerBinaryBuffer lldp1(packbuf, cur_size); | ||
130 | lldp1.unpackString(unpkstr , "linden_lab_str"); | ||
131 | lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd"); | ||
132 | lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
133 | lldp1.unpackU8(unpkvalU8,"linden_lab_u8"); | ||
134 | lldp1.unpackU16(unpkvalU16,"linden_lab_u16"); | ||
135 | lldp1.unpackU32(unpkvalU32, "linden_lab_u32"); | ||
136 | lldp1.unpackS32(unpkvalS32, "linden_lab_s32"); | ||
137 | lldp1.unpackF32(unpkvalF32, "linden_lab_f32"); | ||
138 | lldp1.unpackColor4(unpkllcol4, "linden_lab_col4"); | ||
139 | lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u"); | ||
140 | lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2"); | ||
141 | lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3"); | ||
142 | lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4"); | ||
143 | lldp1.unpackUUID(unpkuuid, "linden_lab_uuid"); | ||
144 | |||
145 | ensure("LLDataPackerBinaryBuffer::packString failed", strcmp(str, unpkstr.c_str()) == 0); | ||
146 | ensure("LLDataPackerBinaryBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0); | ||
147 | ensure("LLDataPackerBinaryBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0); | ||
148 | ensure_equals("LLDataPackerBinaryBuffer::packU8 failed", valU8, unpkvalU8); | ||
149 | ensure_equals("LLDataPackerBinaryBuffer::packU16 failed", valU16, unpkvalU16); | ||
150 | ensure_equals("LLDataPackerBinaryBuffer::packU32 failed", valU32, unpkvalU32); | ||
151 | ensure_equals("LLDataPackerBinaryBuffer::packS32 failed", valS32, unpkvalS32); | ||
152 | ensure("LLDataPackerBinaryBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32)); | ||
153 | ensure_equals("LLDataPackerBinaryBuffer::packColor4 failed", llcol4, unpkllcol4); | ||
154 | ensure_equals("LLDataPackerBinaryBuffer::packColor4U failed", llcol4u, unpkllcol4u); | ||
155 | ensure_equals("LLDataPackerBinaryBuffer::packVector2 failed", llvec2, unpkllvec2); | ||
156 | ensure_equals("LLDataPackerBinaryBuffer::packVector3 failed", llvec3, unpkllvec3); | ||
157 | ensure_equals("LLDataPackerBinaryBuffer::packVector4 failed", llvec4, unpkllvec4); | ||
158 | ensure_equals("LLDataPackerBinaryBuffer::packUUID failed", uuid, unpkuuid); | ||
159 | } | ||
160 | |||
161 | template<> template<> | ||
162 | void datapacker_test_object_t::test<3>() | ||
163 | { | ||
164 | U8 packbuf[128]; | ||
165 | char str[] = "SecondLife is virtual World"; | ||
166 | S32 strSize = sizeof(str); // include '\0' | ||
167 | LLDataPackerBinaryBuffer lldp(packbuf, 128); | ||
168 | lldp.packString(str , "linden_lab"); | ||
169 | |||
170 | ensure("LLDataPackerBinaryBuffer: current size is wrong", strSize == lldp.getCurrentSize()); | ||
171 | ensure("LLDataPackerBinaryBuffer: buffer size is wrong", 128 == lldp.getBufferSize()); | ||
172 | |||
173 | lldp.reset(); | ||
174 | ensure("LLDataPackerBinaryBuffer::reset failed",0 == lldp.getCurrentSize()); | ||
175 | } | ||
176 | |||
177 | template<> template<> | ||
178 | void datapacker_test_object_t::test<4>() | ||
179 | { | ||
180 | U8* packbuf = new U8[128]; | ||
181 | char str[] = "SecondLife is virtual World"; | ||
182 | LLDataPackerBinaryBuffer lldp(packbuf, 128); | ||
183 | lldp.packString(str , "linden_lab"); | ||
184 | lldp.freeBuffer(); | ||
185 | ensure("LLDataPackerBinaryBuffer.freeBuffer failed" , 0 == lldp.getBufferSize()); | ||
186 | |||
187 | } | ||
188 | |||
189 | template<> template<> | ||
190 | void datapacker_test_object_t::test<5>() | ||
191 | { | ||
192 | U8 buf[] = "SecondLife is virtual World"; | ||
193 | S32 size = sizeof(buf); | ||
194 | LLDataPackerBinaryBuffer lldp(buf, size); | ||
195 | U8 new_buf[] = "Its Amazing"; | ||
196 | size = sizeof(new_buf); | ||
197 | lldp.assignBuffer(new_buf, size); | ||
198 | ensure("LLDataPackerBinaryBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (0 == lldp.getCurrentSize()))) ; | ||
199 | } | ||
200 | |||
201 | template<> template<> | ||
202 | void datapacker_test_object_t::test<6>() | ||
203 | { | ||
204 | U8 packbuf[128]; | ||
205 | char str[] = "SecondLife is virtual World"; | ||
206 | LLDataPackerBinaryBuffer lldp(packbuf, 128); | ||
207 | lldp.packString(str , "linden_lab"); | ||
208 | U8 new_buffer[128]; | ||
209 | std::string unpkbuf; | ||
210 | LLDataPackerBinaryBuffer lldp1(new_buffer,128); | ||
211 | lldp1 = lldp; | ||
212 | lldp1.unpackString(unpkbuf, "linden_lab"); | ||
213 | ensure("1. LLDataPackerBinaryBuffer::operator= failed" , lldp1.getBufferSize() == lldp.getBufferSize()); | ||
214 | ensure_equals("2.LLDataPackerBinaryBuffer::operator= failed", str,unpkbuf); | ||
215 | } | ||
216 | |||
217 | //*********LLDataPackerAsciiBuffer | ||
218 | |||
219 | template<> template<> | ||
220 | void datapacker_test_object_t::test<7>() | ||
221 | { | ||
222 | char packbuf[128]; | ||
223 | F32 f_val = 44.44f, f_unpkval; | ||
224 | LLDataPackerAsciiBuffer lldp(packbuf,128); | ||
225 | lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8); | ||
226 | |||
227 | LLDataPackerAsciiBuffer lldp1(packbuf, lldp.getCurrentSize()); | ||
228 | lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8); | ||
229 | ensure_approximately_equals("LLDataPackerAsciiBuffer::packFixed failed", f_val, f_unpkval, 8); | ||
230 | } | ||
231 | |||
232 | template<> template<> | ||
233 | void datapacker_test_object_t::test<8>() | ||
234 | { | ||
235 | char packbuf[1024]; | ||
236 | |||
237 | char str[] = "SecondLife is virtual World\0"; | ||
238 | char strBinary[] = "SecondLife is virtual World"; | ||
239 | char strBinaryFixed[] = "Fixed Data"; | ||
240 | S32 sizeBinaryFixed = sizeof(strBinaryFixed); | ||
241 | U8 valU8 = 'C'; | ||
242 | U16 valU16 = 0xFFFF; | ||
243 | U32 valU32 = 0xFFFFFFFF; | ||
244 | S32 valS32 = -94967295; | ||
245 | F32 valF32 = 4354355.44f ; | ||
246 | LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f); | ||
247 | LLColor4U llcol4u(3, 128, 24, 33); | ||
248 | LLVector2 llvec2(333.33f, 444.44f); | ||
249 | LLVector3 llvec3(333.33f, 444.44f, 555.55f); | ||
250 | LLVector4 llvec4(4354355.44f, 444.44f, 555.55f, 666.66f); | ||
251 | LLUUID uuid; | ||
252 | |||
253 | std::string unpkstr; | ||
254 | char unpkstrBinary[256]; | ||
255 | char unpkstrBinaryFixed[256]; | ||
256 | S32 unpksizeBinary; | ||
257 | U8 unpkvalU8; | ||
258 | U16 unpkvalU16; | ||
259 | U32 unpkvalU32; | ||
260 | S32 unpkvalS32; | ||
261 | F32 unpkvalF32; | ||
262 | LLColor4 unpkllcol4; | ||
263 | LLColor4U unpkllcol4u; | ||
264 | LLVector2 unpkllvec2; | ||
265 | LLVector3 unpkllvec3; | ||
266 | LLVector4 unpkllvec4; | ||
267 | LLUUID unpkuuid; | ||
268 | |||
269 | LLDataPackerAsciiBuffer lldp(packbuf,1024); | ||
270 | lldp.packString(str , "linden_lab_str"); | ||
271 | lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd"); | ||
272 | lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
273 | lldp.packU8(valU8,"linden_lab_u8"); | ||
274 | lldp.packU16(valU16,"linden_lab_u16"); | ||
275 | lldp.packU32(valU32, "linden_lab_u32"); | ||
276 | lldp.packS32(valS32, "linden_lab_s32"); | ||
277 | lldp.packF32(valF32, "linden_lab_f32"); | ||
278 | lldp.packColor4(llcol4, "linden_lab_col4"); | ||
279 | lldp.packColor4U(llcol4u, "linden_lab_col4u"); | ||
280 | lldp.packVector2(llvec2, "linden_lab_vec2"); | ||
281 | lldp.packVector3(llvec3, "linden_lab_vec3"); | ||
282 | lldp.packVector4(llvec4, "linden_lab_vec4"); | ||
283 | uuid.generate(); | ||
284 | lldp.packUUID(uuid, "linden_lab_uuid"); | ||
285 | |||
286 | S32 cur_size = lldp.getCurrentSize(); | ||
287 | |||
288 | LLDataPackerAsciiBuffer lldp1(packbuf, cur_size); | ||
289 | lldp1.unpackString(unpkstr , "linden_lab_str"); | ||
290 | lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd"); | ||
291 | lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
292 | lldp1.unpackU8(unpkvalU8,"linden_lab_u8"); | ||
293 | lldp1.unpackU16(unpkvalU16,"linden_lab_u16"); | ||
294 | lldp1.unpackU32(unpkvalU32, "linden_lab_u32"); | ||
295 | lldp1.unpackS32(unpkvalS32, "linden_lab_s32"); | ||
296 | lldp1.unpackF32(unpkvalF32, "linden_lab_f32"); | ||
297 | lldp1.unpackColor4(unpkllcol4, "linden_lab_col4"); | ||
298 | lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u"); | ||
299 | lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2"); | ||
300 | lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3"); | ||
301 | lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4"); | ||
302 | lldp1.unpackUUID(unpkuuid, "linden_lab_uuid"); | ||
303 | |||
304 | ensure("LLDataPackerAsciiBuffer::packString failed", strcmp(str, unpkstr.c_str()) == 0); | ||
305 | ensure("LLDataPackerAsciiBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0); | ||
306 | ensure("LLDataPackerAsciiBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0); | ||
307 | ensure_equals("LLDataPackerAsciiBuffer::packU8 failed", valU8, unpkvalU8); | ||
308 | ensure_equals("LLDataPackerAsciiBuffer::packU16 failed", valU16, unpkvalU16); | ||
309 | ensure_equals("LLDataPackerAsciiBuffer::packU32 failed", valU32, unpkvalU32); | ||
310 | ensure_equals("LLDataPackerAsciiBuffer::packS32 failed", valS32, unpkvalS32); | ||
311 | ensure("LLDataPackerAsciiBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32)); | ||
312 | ensure_equals("LLDataPackerAsciiBuffer::packColor4 failed", llcol4, unpkllcol4); | ||
313 | ensure_equals("LLDataPackerAsciiBuffer::packColor4U failed", llcol4u, unpkllcol4u); | ||
314 | ensure_equals("LLDataPackerAsciiBuffer::packVector2 failed", llvec2, unpkllvec2); | ||
315 | ensure_equals("LLDataPackerAsciiBuffer::packVector3 failed", llvec3, unpkllvec3); | ||
316 | ensure_equals("LLDataPackerAsciiBuffer::packVector4 failed", llvec4, unpkllvec4); | ||
317 | ensure_equals("LLDataPackerAsciiBuffer::packUUID failed", uuid, unpkuuid); | ||
318 | } | ||
319 | |||
320 | template<> template<> | ||
321 | void datapacker_test_object_t::test<9>() | ||
322 | { | ||
323 | char* packbuf = new char[128]; | ||
324 | char str[] = "SecondLife is virtual World"; | ||
325 | LLDataPackerAsciiBuffer lldp(packbuf, 128); | ||
326 | lldp.packString(str , "linden_lab"); | ||
327 | lldp.freeBuffer(); | ||
328 | ensure("LLDataPackerAsciiBuffer::freeBuffer failed" , 0 == lldp.getBufferSize()); | ||
329 | } | ||
330 | |||
331 | template<> template<> | ||
332 | void datapacker_test_object_t::test<10>() | ||
333 | { | ||
334 | char buf[] = "SecondLife is virtual World"; | ||
335 | S32 size = sizeof(buf); | ||
336 | LLDataPackerAsciiBuffer lldp(buf, size); | ||
337 | char new_buf[] = "Its Amazing"; | ||
338 | size = sizeof(new_buf); | ||
339 | lldp.assignBuffer(new_buf, size); | ||
340 | ensure("LLDataPackerAsciiBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (1 == lldp.getCurrentSize()))) ; | ||
341 | } | ||
342 | |||
343 | //*********LLDataPackerAsciiFile | ||
344 | |||
345 | template<> template<> | ||
346 | void datapacker_test_object_t::test<11>() | ||
347 | { | ||
348 | F32 f_val = 44.44f, f_unpkval; | ||
349 | |||
350 | FILE* fp = fopen(TEST_FILE_NAME, "w+"); | ||
351 | if(!fp) | ||
352 | { | ||
353 | llerrs << "File couldnt be open" <<llendl; | ||
354 | return; | ||
355 | } | ||
356 | |||
357 | LLDataPackerAsciiFile lldp(fp,2); | ||
358 | lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8); | ||
359 | |||
360 | fflush(fp); | ||
361 | fseek(fp,0,SEEK_SET); | ||
362 | LLDataPackerAsciiFile lldp1(fp,2); | ||
363 | |||
364 | lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8); | ||
365 | fclose(fp); | ||
366 | |||
367 | ensure_approximately_equals("LLDataPackerAsciiFile::packFixed failed", f_val, f_unpkval, 8); | ||
368 | } | ||
369 | |||
370 | template<> template<> | ||
371 | void datapacker_test_object_t::test<12>() | ||
372 | { | ||
373 | char str[] = "SecondLife is virtual World\0"; | ||
374 | char strBinary[] = "SecondLife is virtual World"; | ||
375 | char strBinaryFixed[] = "Fixed Data"; | ||
376 | S32 sizeBinaryFixed = sizeof(strBinaryFixed); | ||
377 | U8 valU8 = 'C'; | ||
378 | U16 valU16 = 0xFFFF; | ||
379 | U32 valU32 = 0xFFFFFFFF; | ||
380 | S32 valS32 = -94967295; | ||
381 | F32 valF32 = 4354355.44f ; | ||
382 | LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f); | ||
383 | LLColor4U llcol4u(3, 128, 24, 33); | ||
384 | LLVector2 llvec2(333.33f, 444.44f); | ||
385 | LLVector3 llvec3(333.33f, 444.44f, 555.55f); | ||
386 | LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f); | ||
387 | LLUUID uuid; | ||
388 | |||
389 | std::string unpkstr; | ||
390 | char unpkstrBinary[256]; | ||
391 | char unpkstrBinaryFixed[256]; | ||
392 | S32 unpksizeBinary; | ||
393 | U8 unpkvalU8; | ||
394 | U16 unpkvalU16; | ||
395 | U32 unpkvalU32; | ||
396 | S32 unpkvalS32; | ||
397 | F32 unpkvalF32; | ||
398 | LLColor4 unpkllcol4; | ||
399 | LLColor4U unpkllcol4u; | ||
400 | LLVector2 unpkllvec2; | ||
401 | LLVector3 unpkllvec3; | ||
402 | LLVector4 unpkllvec4; | ||
403 | LLUUID unpkuuid; | ||
404 | |||
405 | FILE* fp = fopen(TEST_FILE_NAME,"w+"); | ||
406 | if(!fp) | ||
407 | { | ||
408 | llerrs << "File couldnt be open" <<llendl; | ||
409 | return; | ||
410 | } | ||
411 | |||
412 | LLDataPackerAsciiFile lldp(fp,2); | ||
413 | |||
414 | lldp.packString(str , "linden_lab_str"); | ||
415 | lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd"); | ||
416 | lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
417 | lldp.packU8(valU8,"linden_lab_u8"); | ||
418 | lldp.packU16(valU16,"linden_lab_u16"); | ||
419 | lldp.packU32(valU32, "linden_lab_u32"); | ||
420 | lldp.packS32(valS32, "linden_lab_s32"); | ||
421 | lldp.packF32(valF32, "linden_lab_f32"); | ||
422 | lldp.packColor4(llcol4, "linden_lab_col4"); | ||
423 | lldp.packColor4U(llcol4u, "linden_lab_col4u"); | ||
424 | lldp.packVector2(llvec2, "linden_lab_vec2"); | ||
425 | lldp.packVector3(llvec3, "linden_lab_vec3"); | ||
426 | lldp.packVector4(llvec4, "linden_lab_vec4"); | ||
427 | uuid.generate(); | ||
428 | lldp.packUUID(uuid, "linden_lab_uuid"); | ||
429 | |||
430 | fflush(fp); | ||
431 | fseek(fp,0,SEEK_SET); | ||
432 | LLDataPackerAsciiFile lldp1(fp,2); | ||
433 | |||
434 | lldp1.unpackString(unpkstr , "linden_lab_str"); | ||
435 | lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd"); | ||
436 | lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
437 | lldp1.unpackU8(unpkvalU8,"linden_lab_u8"); | ||
438 | lldp1.unpackU16(unpkvalU16,"linden_lab_u16"); | ||
439 | lldp1.unpackU32(unpkvalU32, "linden_lab_u32"); | ||
440 | lldp1.unpackS32(unpkvalS32, "linden_lab_s32"); | ||
441 | lldp1.unpackF32(unpkvalF32, "linden_lab_f32"); | ||
442 | lldp1.unpackColor4(unpkllcol4, "linden_lab_col4"); | ||
443 | lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u"); | ||
444 | lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2"); | ||
445 | lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3"); | ||
446 | lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4"); | ||
447 | lldp1.unpackUUID(unpkuuid, "linden_lab_uuid"); | ||
448 | |||
449 | fclose(fp); | ||
450 | |||
451 | ensure("LLDataPackerAsciiFile::packString failed", strcmp(str, unpkstr.c_str()) == 0); | ||
452 | ensure("LLDataPackerAsciiFile::packBinaryData failed", strcmp(strBinary, unpkstrBinary) == 0); | ||
453 | ensure("LLDataPackerAsciiFile::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0); | ||
454 | ensure_equals("LLDataPackerAsciiFile::packU8 failed", valU8, unpkvalU8); | ||
455 | ensure_equals("LLDataPackerAsciiFile::packU16 failed", valU16, unpkvalU16); | ||
456 | ensure_equals("LLDataPackerAsciiFile::packU32 failed", valU32, unpkvalU32); | ||
457 | ensure_equals("LLDataPackerAsciiFile::packS32 failed", valS32, unpkvalS32); | ||
458 | ensure("LLDataPackerAsciiFile::packF32 failed", is_approx_equal(valF32, unpkvalF32)); | ||
459 | ensure_equals("LLDataPackerAsciiFile::packColor4 failed", llcol4, unpkllcol4); | ||
460 | ensure_equals("LLDataPackerAsciiFile::packColor4U failed", llcol4u, unpkllcol4u); | ||
461 | ensure_equals("LLDataPackerAsciiFile::packVector2 failed", llvec2, unpkllvec2); | ||
462 | ensure_equals("LLDataPackerAsciiFile::packVector3 failed", llvec3, unpkllvec3); | ||
463 | ensure_equals("LLDataPackerAsciiFile::packVector4 failed", llvec4, unpkllvec4); | ||
464 | ensure_equals("LLDataPackerAsciiFile::packUUID failed", uuid, unpkuuid); | ||
465 | } | ||
466 | |||
467 | template<> template<> | ||
468 | void datapacker_test_object_t::test<13>() | ||
469 | { | ||
470 | F32 f_val = 44.44f, f_unpkval; | ||
471 | |||
472 | std::ostringstream ostr; | ||
473 | LLDataPackerAsciiFile lldp(ostr,2); | ||
474 | lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8); | ||
475 | |||
476 | std::istringstream istr(ostr.str()); | ||
477 | LLDataPackerAsciiFile lldp1(istr,2); | ||
478 | |||
479 | lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8); | ||
480 | |||
481 | ensure_approximately_equals("LLDataPackerAsciiFile::packFixed (iostring) failed", f_val, f_unpkval, 8); | ||
482 | } | ||
483 | |||
484 | template<> template<> | ||
485 | void datapacker_test_object_t::test<14>() | ||
486 | { | ||
487 | char str[] = "SecondLife is virtual World\0"; | ||
488 | char strBinary[] = "SecondLife is virtual World"; | ||
489 | char strBinaryFixed[] = "Fixed Data"; | ||
490 | S32 sizeBinaryFixed = sizeof(strBinaryFixed); | ||
491 | U8 valU8 = 'C'; | ||
492 | U16 valU16 = 0xFFFF; | ||
493 | U32 valU32 = 0xFFFFFFFF; | ||
494 | S32 valS32 = -94967295; | ||
495 | F32 valF32 = 4354355.44f ; | ||
496 | LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f); | ||
497 | LLColor4U llcol4u(3, 128, 24, 33); | ||
498 | LLVector2 llvec2(3333333.33f, 444.333344f); | ||
499 | LLVector3 llvec3(3323233.33f, 444.4324f, 555.553232f); | ||
500 | LLVector4 llvec4(333.33233f, 444.4323234f, 55323225.55f, 6323236.66f); | ||
501 | LLUUID uuid; | ||
502 | |||
503 | std::string unpkstr; | ||
504 | char unpkstrBinary[256]; | ||
505 | char unpkstrBinaryFixed[256]; | ||
506 | S32 unpksizeBinary; | ||
507 | U8 unpkvalU8; | ||
508 | U16 unpkvalU16; | ||
509 | U32 unpkvalU32; | ||
510 | S32 unpkvalS32; | ||
511 | F32 unpkvalF32; | ||
512 | LLColor4 unpkllcol4; | ||
513 | LLColor4U unpkllcol4u; | ||
514 | LLVector2 unpkllvec2; | ||
515 | LLVector3 unpkllvec3; | ||
516 | LLVector4 unpkllvec4; | ||
517 | LLUUID unpkuuid; | ||
518 | |||
519 | std::ostringstream ostr; | ||
520 | LLDataPackerAsciiFile lldp(ostr,2); | ||
521 | |||
522 | lldp.packString(str , "linden_lab_str"); | ||
523 | lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd"); | ||
524 | lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
525 | lldp.packU8(valU8,"linden_lab_u8"); | ||
526 | lldp.packU16(valU16,"linden_lab_u16"); | ||
527 | lldp.packU32(valU32, "linden_lab_u32"); | ||
528 | lldp.packS32(valS32, "linden_lab_s32"); | ||
529 | lldp.packF32(valF32, "linden_lab_f32"); | ||
530 | lldp.packColor4(llcol4, "linden_lab_col4"); | ||
531 | lldp.packColor4U(llcol4u, "linden_lab_col4u"); | ||
532 | lldp.packVector2(llvec2, "linden_lab_vec2"); | ||
533 | lldp.packVector3(llvec3, "linden_lab_vec3"); | ||
534 | lldp.packVector4(llvec4, "linden_lab_vec4"); | ||
535 | uuid.generate(); | ||
536 | lldp.packUUID(uuid, "linden_lab_uuid"); | ||
537 | |||
538 | std::istringstream istr(ostr.str()); | ||
539 | LLDataPackerAsciiFile lldp1(istr,2); | ||
540 | |||
541 | lldp1.unpackString(unpkstr , "linden_lab_str"); | ||
542 | lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd"); | ||
543 | lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf"); | ||
544 | lldp1.unpackU8(unpkvalU8,"linden_lab_u8"); | ||
545 | lldp1.unpackU16(unpkvalU16,"linden_lab_u16"); | ||
546 | lldp1.unpackU32(unpkvalU32, "linden_lab_u32"); | ||
547 | lldp1.unpackS32(unpkvalS32, "linden_lab_s32"); | ||
548 | lldp1.unpackF32(unpkvalF32, "linden_lab_f32"); | ||
549 | lldp1.unpackColor4(unpkllcol4, "linden_lab_col4"); | ||
550 | lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u"); | ||
551 | lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2"); | ||
552 | lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3"); | ||
553 | lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4"); | ||
554 | lldp1.unpackUUID(unpkuuid, "linden_lab_uuid"); | ||
555 | |||
556 | ensure("LLDataPackerAsciiFile::packString (iostring) failed", strcmp(str, unpkstr.c_str()) == 0); | ||
557 | ensure("LLDataPackerAsciiFile::packBinaryData (iostring) failed", strcmp(strBinary, unpkstrBinary) == 0); | ||
558 | ensure("LLDataPackerAsciiFile::packBinaryDataFixed (iostring) failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0); | ||
559 | ensure_equals("LLDataPackerAsciiFile::packU8 (iostring) failed", valU8, unpkvalU8); | ||
560 | ensure_equals("LLDataPackerAsciiFile::packU16 (iostring) failed", valU16, unpkvalU16); | ||
561 | ensure_equals("LLDataPackerAsciiFile::packU32 (iostring) failed", valU32, unpkvalU32); | ||
562 | ensure_equals("LLDataPackerAsciiFile::packS32 (iostring) failed", valS32, unpkvalS32); | ||
563 | ensure("LLDataPackerAsciiFile::packF32 (iostring) failed", is_approx_equal(valF32, unpkvalF32)); | ||
564 | ensure_equals("LLDataPackerAsciiFile::packColor4 (iostring) failed", llcol4, unpkllcol4); | ||
565 | ensure_equals("LLDataPackerAsciiFile::packColor4U (iostring) failed", llcol4u, unpkllcol4u); | ||
566 | ensure_equals("LLDataPackerAsciiFile::packVector2 (iostring) failed", llvec2, unpkllvec2); | ||
567 | ensure_equals("LLDataPackerAsciiFile::packVector3 (iostring) failed", llvec3, unpkllvec3); | ||
568 | ensure_equals("LLDataPackerAsciiFile::packVector4 (iostring) failed", llvec4, unpkllvec4); | ||
569 | ensure_equals("LLDataPackerAsciiFile::packUUID (iostring) failed", uuid, unpkuuid); | ||
570 | } | ||
571 | } | ||
diff --git a/linden/indra/test/llhttpclient_tut.cpp b/linden/indra/test/llhttpclient_tut.cpp index 7918205..77f1e25 100644 --- a/linden/indra/test/llhttpclient_tut.cpp +++ b/linden/indra/test/llhttpclient_tut.cpp | |||
@@ -34,6 +34,10 @@ | |||
34 | 34 | ||
35 | #include <tut/tut.h> | 35 | #include <tut/tut.h> |
36 | #include "linden_common.h" | 36 | #include "linden_common.h" |
37 | |||
38 | // These are too slow on Windows to actually include in the build. JC | ||
39 | #if !LL_WINDOWS | ||
40 | |||
37 | #include "lltut.h" | 41 | #include "lltut.h" |
38 | #include "llhttpclient.h" | 42 | #include "llhttpclient.h" |
39 | #include "llformat.h" | 43 | #include "llformat.h" |
@@ -98,7 +102,7 @@ namespace tut | |||
98 | 102 | ||
99 | void setupTheServer() | 103 | void setupTheServer() |
100 | { | 104 | { |
101 | LLHTTPNode& root = LLCreateHTTPServer(mPool, *mServerPump, 8888); | 105 | LLHTTPNode& root = LLIOHTTPServer::create(mPool, *mServerPump, 8888); |
102 | 106 | ||
103 | LLHTTPStandardServices::useServices(); | 107 | LLHTTPStandardServices::useServices(); |
104 | LLHTTPRegistrar::buildAllServices(root); | 108 | LLHTTPRegistrar::buildAllServices(root); |
@@ -333,4 +337,7 @@ namespace tut | |||
333 | LLSD body = result["body"]; | 337 | LLSD body = result["body"]; |
334 | ensure_equals("echoed result matches", body.size(), expected.size()); | 338 | ensure_equals("echoed result matches", body.size(), expected.size()); |
335 | } | 339 | } |
340 | |||
336 | } | 341 | } |
342 | |||
343 | #endif // !LL_WINDOWS | ||
diff --git a/linden/indra/test/llinventoryparcel_tut.cpp b/linden/indra/test/llinventoryparcel_tut.cpp new file mode 100644 index 0000000..1a815ca --- /dev/null +++ b/linden/indra/test/llinventoryparcel_tut.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | /** | ||
2 | * @file llinventoryparcel_tut.cpp | ||
3 | * @author Moss | ||
4 | * @date 2007-04-17 | ||
5 | * | ||
6 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | #include "lltut.h" | ||
32 | |||
33 | #include "llparcel.h" | ||
34 | |||
35 | #include <string> | ||
36 | |||
37 | namespace tut | ||
38 | { | ||
39 | struct llinventoryparcel_data | ||
40 | { | ||
41 | }; | ||
42 | typedef test_group<llinventoryparcel_data> llinventoryparcel_test; | ||
43 | typedef llinventoryparcel_test::object llinventoryparcel_object; | ||
44 | tut::llinventoryparcel_test llinventoryparcel("llinventoryparcel"); | ||
45 | |||
46 | template<> template<> | ||
47 | void llinventoryparcel_object::test<1>() | ||
48 | { | ||
49 | for (S32 i=0; i<LLParcel::C_COUNT; ++i) | ||
50 | { | ||
51 | const char *catstring = LLParcel::getCategoryString(LLParcel::ECategory(i)); | ||
52 | ensure("LLParcel::getCategoryString(i)", | ||
53 | NULL != catstring); | ||
54 | |||
55 | const char *catuistring = LLParcel::getCategoryUIString(LLParcel::ECategory(i)); | ||
56 | ensure("LLParcel::getCategoryUIString(i)", | ||
57 | NULL != catuistring); | ||
58 | |||
59 | ensure_equals("LLParcel::ECategory mapping of string back to enum", LLParcel::getCategoryFromString(catstring), i); | ||
60 | ensure_equals("LLParcel::ECategory mapping of uistring back to enum", LLParcel::getCategoryFromUIString(catuistring), i); | ||
61 | } | ||
62 | |||
63 | // test the C_ANY case, which has to work for UI strings | ||
64 | const char *catuistring = LLParcel::getCategoryUIString(LLParcel::C_ANY); | ||
65 | ensure("LLParcel::getCategoryUIString(C_ANY)", | ||
66 | NULL != catuistring); | ||
67 | |||
68 | ensure_equals("LLParcel::ECategory mapping of uistring back to enum", LLParcel::getCategoryFromUIString(catuistring), LLParcel::C_ANY); | ||
69 | } | ||
70 | } | ||
diff --git a/linden/indra/test/lliohttpserver_tut.cpp b/linden/indra/test/lliohttpserver_tut.cpp index 0d914f2..a5693be 100644 --- a/linden/indra/test/lliohttpserver_tut.cpp +++ b/linden/indra/test/lliohttpserver_tut.cpp | |||
@@ -117,7 +117,7 @@ namespace tut | |||
117 | LLSD context; | 117 | LLSD context; |
118 | 118 | ||
119 | chain.push_back(LLIOPipe::ptr_t(injector)); | 119 | chain.push_back(LLIOPipe::ptr_t(injector)); |
120 | LLCreateHTTPPipe(chain, mRoot, LLSD()); | 120 | LLIOHTTPServer::createPipe(chain, mRoot, LLSD()); |
121 | chain.push_back(LLIOPipe::ptr_t(extractor)); | 121 | chain.push_back(LLIOPipe::ptr_t(extractor)); |
122 | 122 | ||
123 | pump->addChain(chain, DEFAULT_CHAIN_EXPIRY_SECS); | 123 | pump->addChain(chain, DEFAULT_CHAIN_EXPIRY_SECS); |
diff --git a/linden/indra/test/llpartdata_tut.cpp b/linden/indra/test/llpartdata_tut.cpp new file mode 100644 index 0000000..ce2cedc --- /dev/null +++ b/linden/indra/test/llpartdata_tut.cpp | |||
@@ -0,0 +1,217 @@ | |||
1 | /** | ||
2 | * @file llpartdata_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief LLPartData and LLPartSysData test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "lldatapacker.h" | ||
35 | #include "llpartdata.h" | ||
36 | #include "v3math.h" | ||
37 | #include "llsdserialize.h" | ||
38 | #include "message.h" | ||
39 | |||
40 | namespace tut | ||
41 | { | ||
42 | |||
43 | struct partdata_test | ||
44 | { | ||
45 | }; | ||
46 | typedef test_group<partdata_test> partdata_test_t; | ||
47 | typedef partdata_test_t::object partdata_test_object_t; | ||
48 | tut::partdata_test_t tut_partdata_test("partdata_test"); | ||
49 | |||
50 | template<> template<> | ||
51 | void partdata_test_object_t::test<1>() | ||
52 | { | ||
53 | LLPartData llpdata,llpdata1; | ||
54 | U8 pkbuf[128]; | ||
55 | |||
56 | llpdata.setFlags(LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK | | ||
57 | LLPartData::LL_PART_BOUNCE_MASK | LLPartData::LL_PART_WIND_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK | | ||
58 | LLPartData::LL_PART_FOLLOW_VELOCITY_MASK | LLPartData::LL_PART_TARGET_POS_MASK | LLPartData::LL_PART_TARGET_LINEAR_MASK | | ||
59 | LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_BEAM_MASK | LLPartData::LL_PART_DEAD_MASK); | ||
60 | |||
61 | llpdata.setMaxAge(29.3f); | ||
62 | |||
63 | LLVector3 llvec1(1.0f, .5f, .25f); | ||
64 | llpdata.setStartColor(llvec1); | ||
65 | llpdata.setStartAlpha(.7f); | ||
66 | |||
67 | LLVector3 llvec2(.2f, .3f, 1.0f); | ||
68 | llpdata.setEndColor(llvec2); | ||
69 | llpdata.setEndAlpha(1.0f); | ||
70 | |||
71 | llpdata.setStartScale(3.23f, 4.0f); | ||
72 | llpdata.setEndScale(2.4678f, 1.0f); | ||
73 | |||
74 | LLDataPackerBinaryBuffer dp((U8*)pkbuf, 128); | ||
75 | llpdata.pack(dp); | ||
76 | |||
77 | S32 cur_size = dp.getCurrentSize(); | ||
78 | |||
79 | LLDataPackerBinaryBuffer dp1((U8*)pkbuf, cur_size); | ||
80 | llpdata1.unpack(dp1); | ||
81 | |||
82 | ensure("1.mFlags values are different after unpacking", llpdata1.mFlags == llpdata.mFlags); | ||
83 | ensure_approximately_equals("2.mMaxAge values are different after unpacking", llpdata1.mMaxAge, llpdata.mMaxAge, 8); | ||
84 | |||
85 | ensure_approximately_equals("3.mStartColor[0] values are different after unpacking", llpdata1.mStartColor.mV[0], llpdata.mStartColor.mV[0], 8); | ||
86 | ensure_approximately_equals("4.mStartColor[1] values are different after unpacking", llpdata1.mStartColor.mV[1], llpdata.mStartColor.mV[1], 8); | ||
87 | ensure_approximately_equals("5.mStartColor[2] values are different after unpacking", llpdata1.mStartColor.mV[2], llpdata.mStartColor.mV[2], 8); | ||
88 | ensure_approximately_equals("6.mStartColor[3] values are different after unpacking", llpdata1.mStartColor.mV[3], llpdata.mStartColor.mV[3], 8); | ||
89 | |||
90 | ensure_approximately_equals("7.mEndColor[0] values are different after unpacking", llpdata1.mEndColor.mV[0], llpdata.mEndColor.mV[0], 8); | ||
91 | ensure_approximately_equals("8.mEndColor[1] values are different after unpacking", llpdata1.mEndColor.mV[1], llpdata.mEndColor.mV[1], 8); | ||
92 | ensure_approximately_equals("9.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[2], llpdata.mEndColor.mV[2], 8); | ||
93 | ensure_approximately_equals("10.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[3], llpdata.mEndColor.mV[3], 8); | ||
94 | |||
95 | ensure_approximately_equals("11.mStartScale[0] values are different after unpacking", llpdata1.mStartScale.mV[0], llpdata.mStartScale.mV[0], 5); | ||
96 | ensure_approximately_equals("12.mStartScale[1] values are different after unpacking", llpdata1.mStartScale.mV[1], llpdata.mStartScale.mV[1], 5); | ||
97 | |||
98 | ensure_approximately_equals("13.mEndScale[0] values are different after unpacking", llpdata1.mEndScale.mV[0], llpdata.mEndScale.mV[0], 5); | ||
99 | ensure_approximately_equals("14.mEndScale[1] values are different after unpacking", llpdata1.mEndScale.mV[1], llpdata.mEndScale.mV[1], 5); | ||
100 | } | ||
101 | |||
102 | |||
103 | template<> template<> | ||
104 | void partdata_test_object_t::test<2>() | ||
105 | { | ||
106 | LLPartData llpdata,llpdata1; | ||
107 | |||
108 | llpdata.setFlags(LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK | | ||
109 | LLPartData::LL_PART_BOUNCE_MASK | LLPartData::LL_PART_WIND_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK | | ||
110 | LLPartData::LL_PART_FOLLOW_VELOCITY_MASK | LLPartData::LL_PART_TARGET_POS_MASK | LLPartData::LL_PART_TARGET_LINEAR_MASK | | ||
111 | LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_BEAM_MASK | LLPartData::LL_PART_DEAD_MASK); | ||
112 | |||
113 | llpdata.setMaxAge(29.3f); | ||
114 | |||
115 | LLVector3 llvec1(1.0f, .5f, .25f); | ||
116 | llpdata.setStartColor(llvec1); | ||
117 | llpdata.setStartAlpha(.7f); | ||
118 | |||
119 | LLVector3 llvec2(.2f, .3f, 1.0f); | ||
120 | llpdata.setEndColor(llvec2); | ||
121 | llpdata.setEndAlpha(1.0f); | ||
122 | |||
123 | llpdata.setStartScale(3.23f, 4.0f); | ||
124 | llpdata.setEndScale(2.4678f, 1.0f); | ||
125 | |||
126 | LLSD llsd = llpdata.asLLSD(); | ||
127 | |||
128 | llpdata1.fromLLSD(llsd); | ||
129 | |||
130 | ensure("1.mFlags values are different after unpacking", llpdata1.mFlags == llpdata.mFlags); | ||
131 | ensure_approximately_equals("2.mMaxAge values are different after unpacking", llpdata1.mMaxAge, llpdata.mMaxAge, 8); | ||
132 | |||
133 | ensure_approximately_equals("3.mStartColor[0] values are different after unpacking", llpdata1.mStartColor.mV[0], llpdata.mStartColor.mV[0], 8); | ||
134 | ensure_approximately_equals("4.mStartColor[1] values are different after unpacking", llpdata1.mStartColor.mV[1], llpdata.mStartColor.mV[1], 8); | ||
135 | ensure_approximately_equals("5.mStartColor[2] values are different after unpacking", llpdata1.mStartColor.mV[2], llpdata.mStartColor.mV[2], 8); | ||
136 | ensure_approximately_equals("6.mStartColor[3] values are different after unpacking", llpdata1.mStartColor.mV[3], llpdata.mStartColor.mV[3], 8); | ||
137 | |||
138 | ensure_approximately_equals("7.mEndColor[0] values are different after unpacking", llpdata1.mEndColor.mV[0], llpdata.mEndColor.mV[0], 8); | ||
139 | ensure_approximately_equals("8.mEndColor[1] values are different after unpacking", llpdata1.mEndColor.mV[1], llpdata.mEndColor.mV[1], 8); | ||
140 | ensure_approximately_equals("9.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[2], llpdata.mEndColor.mV[2], 8); | ||
141 | ensure_approximately_equals("10.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[3], llpdata.mEndColor.mV[3], 8); | ||
142 | |||
143 | ensure_approximately_equals("11.mStartScale[0] values are different after unpacking", llpdata1.mStartScale.mV[0], llpdata.mStartScale.mV[0], 5); | ||
144 | ensure_approximately_equals("12.mStartScale[1] values are different after unpacking", llpdata1.mStartScale.mV[1], llpdata.mStartScale.mV[1], 5); | ||
145 | |||
146 | ensure_approximately_equals("13.mEndScale[0] values are different after unpacking", llpdata1.mEndScale.mV[0], llpdata.mEndScale.mV[0], 5); | ||
147 | ensure_approximately_equals("14.mEndScale[1] values are different after unpacking", llpdata1.mEndScale.mV[1], llpdata.mEndScale.mV[1], 5); | ||
148 | } | ||
149 | |||
150 | |||
151 | //*********llpartsysdata*********** | ||
152 | |||
153 | template<> template<> | ||
154 | void partdata_test_object_t::test<3>() | ||
155 | { | ||
156 | LLPartSysData llpsysdata, llpsysdata1; | ||
157 | U8 pkbuf[256]; | ||
158 | llpsysdata.setBurstSpeedMin(33.33f); | ||
159 | ensure("1.mBurstSpeedMin coudnt be set", 33.33f == llpsysdata.mBurstSpeedMin); | ||
160 | |||
161 | llpsysdata.setBurstSpeedMax(44.44f); | ||
162 | ensure("2.mBurstSpeedMax coudnt be set", 44.44f == llpsysdata.mBurstSpeedMax); | ||
163 | |||
164 | llpsysdata.setBurstRadius(45.55f); | ||
165 | ensure("3.mBurstRadius coudnt be set", 45.55f == llpsysdata.mBurstRadius); | ||
166 | |||
167 | LLVector3 llvec(44.44f, 111.11f, -40.4f); | ||
168 | llpsysdata.setPartAccel(llvec); | ||
169 | |||
170 | llpsysdata.mCRC = 0xFFFFFFFF; | ||
171 | llpsysdata.mFlags = 0x20; | ||
172 | |||
173 | llpsysdata.mPattern = LLPartSysData::LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY; | ||
174 | |||
175 | llpsysdata.mMaxAge = 99.99f; | ||
176 | llpsysdata.mStartAge = 18.5f; | ||
177 | llpsysdata.mInnerAngle = 4.234f; | ||
178 | llpsysdata.mOuterAngle = 7.123f; | ||
179 | llpsysdata.mBurstRate = 245.53f; | ||
180 | llpsysdata.mBurstPartCount = 0xFF; | ||
181 | llpsysdata.mAngularVelocity = llvec; | ||
182 | |||
183 | llpsysdata.mPartImageID.generate(); | ||
184 | llpsysdata.mTargetUUID.generate(); | ||
185 | |||
186 | LLDataPackerBinaryBuffer dp((U8*)pkbuf, 256); | ||
187 | llpsysdata.pack(dp); | ||
188 | S32 cur_size = dp.getCurrentSize(); | ||
189 | LLDataPackerBinaryBuffer dp1((U8*)pkbuf, cur_size); | ||
190 | llpsysdata1.unpack(dp1); | ||
191 | |||
192 | ensure("1.mCRC's not equal", llpsysdata.mCRC == llpsysdata1.mCRC); | ||
193 | ensure("2.mFlags's not equal", llpsysdata.mFlags == llpsysdata1.mFlags); | ||
194 | ensure("3.mPattern's not equal", llpsysdata.mPattern == llpsysdata1.mPattern); | ||
195 | ensure_approximately_equals("4.mMaxAge's not equal", llpsysdata.mMaxAge , llpsysdata1.mMaxAge, 8); | ||
196 | ensure_approximately_equals("5.mStartAge's not equal", llpsysdata.mStartAge, llpsysdata1.mStartAge, 8); | ||
197 | ensure_approximately_equals("6.mOuterAngle's not equal", llpsysdata.mOuterAngle, llpsysdata1.mOuterAngle, 5); | ||
198 | ensure_approximately_equals("7.mInnerAngles's not equal", llpsysdata.mInnerAngle, llpsysdata1.mInnerAngle, 5); | ||
199 | ensure_approximately_equals("8.mBurstRate's not equal", llpsysdata.mBurstRate, llpsysdata1.mBurstRate, 8); | ||
200 | ensure("9.mBurstPartCount's not equal", llpsysdata.mBurstPartCount == llpsysdata1.mBurstPartCount); | ||
201 | |||
202 | ensure_approximately_equals("10.mBurstSpeedMin's not equal", llpsysdata.mBurstSpeedMin, llpsysdata1.mBurstSpeedMin, 8); | ||
203 | ensure_approximately_equals("11.mBurstSpeedMax's not equal", llpsysdata.mBurstSpeedMax, llpsysdata1.mBurstSpeedMax, 8); | ||
204 | |||
205 | ensure_approximately_equals("12.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[0], llpsysdata1.mAngularVelocity.mV[0], 7); | ||
206 | ensure_approximately_equals("13.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[1], llpsysdata1.mAngularVelocity.mV[1], 7); | ||
207 | ensure_approximately_equals("14.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[2], llpsysdata1.mAngularVelocity.mV[2], 7); | ||
208 | |||
209 | ensure_approximately_equals("15.mPartAccel's not equal", llpsysdata.mPartAccel.mV[0], llpsysdata1.mPartAccel.mV[0], 7); | ||
210 | ensure_approximately_equals("16.mPartAccel's not equal", llpsysdata.mPartAccel.mV[1], llpsysdata1.mPartAccel.mV[1], 7); | ||
211 | ensure_approximately_equals("17.mPartAccel's not equal", llpsysdata.mPartAccel.mV[2], llpsysdata1.mPartAccel.mV[2], 7); | ||
212 | |||
213 | ensure("18.mPartImageID's not equal", llpsysdata.mPartImageID == llpsysdata1.mPartImageID); | ||
214 | ensure("19.mTargetUUID's not equal", llpsysdata.mTargetUUID == llpsysdata1.mTargetUUID); | ||
215 | ensure_approximately_equals("20.mBurstRadius's not equal", llpsysdata.mBurstRadius, llpsysdata1.mBurstRadius, 8); | ||
216 | } | ||
217 | } | ||
diff --git a/linden/indra/test/llrandom_tut.cpp b/linden/indra/test/llrandom_tut.cpp index c5b0488..c5b0488 100755..100644 --- a/linden/indra/test/llrandom_tut.cpp +++ b/linden/indra/test/llrandom_tut.cpp | |||
diff --git a/linden/indra/test/llsdserialize_tut.cpp b/linden/indra/test/llsdserialize_tut.cpp index 80a4336..497c529 100644 --- a/linden/indra/test/llsdserialize_tut.cpp +++ b/linden/indra/test/llsdserialize_tut.cpp | |||
@@ -36,6 +36,9 @@ | |||
36 | #include "lltut.h" | 36 | #include "lltut.h" |
37 | #include "llformat.h" | 37 | #include "llformat.h" |
38 | 38 | ||
39 | // These tests take too long to run on Windows. JC | ||
40 | #if !LL_WINDOWS | ||
41 | |||
39 | namespace tut | 42 | namespace tut |
40 | { | 43 | { |
41 | struct sd_xml_data | 44 | struct sd_xml_data |
@@ -577,3 +580,5 @@ namespace tut | |||
577 | multiple values inside an LLSD | 580 | multiple values inside an LLSD |
578 | */ | 581 | */ |
579 | } | 582 | } |
583 | |||
584 | #endif | ||
diff --git a/linden/indra/test/llservicebuilder_tut.cpp b/linden/indra/test/llservicebuilder_tut.cpp index fde0564..762aa46 100644 --- a/linden/indra/test/llservicebuilder_tut.cpp +++ b/linden/indra/test/llservicebuilder_tut.cpp | |||
@@ -1,9 +1,9 @@ | |||
1 | /** | 1 | /** |
2 | * @file llservicebuilder_tut.cpp | 2 | * @file llservicebuilder_tut.cpp |
3 | * @brief LLServiceBuilder unit tests | 3 | * @brief LLServiceBuilder unit tests |
4 | * @date March 2007 | 4 | * @date March 2007 |
5 | * | 5 | * |
6 | * Copyright (c) 2006-2007, Linden Research, Inc. | 6 | * Copyright (c) 2006-2007, Linden Research, Inc. |
7 | * | 7 | * |
8 | * Second Life Viewer Source Code | 8 | * Second Life Viewer Source Code |
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 9 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -24,73 +24,73 @@ | |||
24 | * | 24 | * |
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
27 | * COMPLETENESS OR PERFORMANCE. | 27 | * COMPLETENESS OR PERFORMANCE. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <tut/tut.h> | 30 | #include <tut/tut.h> |
31 | #include "lltut.h" | 31 | #include "lltut.h" |
32 | 32 | ||
33 | #include "llsd.h" | 33 | #include "llsd.h" |
34 | #include "llservicebuilder.h" | 34 | #include "llservicebuilder.h" |
35 | 35 | ||
36 | namespace tut | 36 | namespace tut |
37 | { | 37 | { |
38 | 38 | ||
39 | struct ServiceBuilderTestData { | 39 | struct ServiceBuilderTestData { |
40 | LLServiceBuilder mServiceBuilder; | 40 | LLServiceBuilder mServiceBuilder; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | typedef test_group<ServiceBuilderTestData> ServiceBuilderTestGroup; | 43 | typedef test_group<ServiceBuilderTestData> ServiceBuilderTestGroup; |
44 | typedef ServiceBuilderTestGroup::object ServiceBuilderTestObject; | 44 | typedef ServiceBuilderTestGroup::object ServiceBuilderTestObject; |
45 | 45 | ||
46 | ServiceBuilderTestGroup serviceBuilderTestGroup("ServiceBuilder"); | 46 | ServiceBuilderTestGroup serviceBuilderTestGroup("ServiceBuilder"); |
47 | 47 | ||
48 | template<> template<> | 48 | template<> template<> |
49 | void ServiceBuilderTestObject::test<1>() | 49 | void ServiceBuilderTestObject::test<1>() |
50 | { | 50 | { |
51 | //Simple service build and reply with no mapping | 51 | //Simple service build and reply with no mapping |
52 | LLSD test_block; | 52 | LLSD test_block; |
53 | test_block["service-builder"] = "/agent/name"; | 53 | test_block["service-builder"] = "/agent/name"; |
54 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); | 54 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); |
55 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest"); | 55 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest"); |
56 | ensure_equals("Basic URL Creation", test_url , "/agent/name"); | 56 | ensure_equals("Basic URL Creation", test_url , "/agent/name"); |
57 | } | 57 | } |
58 | 58 | ||
59 | template<> template<> | 59 | template<> template<> |
60 | void ServiceBuilderTestObject::test<2>() | 60 | void ServiceBuilderTestObject::test<2>() |
61 | { | 61 | { |
62 | //Simple replace test | 62 | //Simple replace test |
63 | LLSD test_block; | 63 | LLSD test_block; |
64 | test_block["service-builder"] = "/agent/{$agent-id}/name"; | 64 | test_block["service-builder"] = "/agent/{$agent-id}/name"; |
65 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); | 65 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); |
66 | LLSD data_map; | 66 | LLSD data_map; |
67 | data_map["agent-id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6"; | 67 | data_map["agent-id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6"; |
68 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map); | 68 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map); |
69 | ensure_equals("Replacement URL Creation", test_url , "/agent/257c631f-a0c5-4f29-8a9f-9031feaae6c6/name"); | 69 | ensure_equals("Replacement URL Creation", test_url , "/agent/257c631f-a0c5-4f29-8a9f-9031feaae6c6/name"); |
70 | } | 70 | } |
71 | 71 | ||
72 | template<> template<> | 72 | template<> template<> |
73 | void ServiceBuilderTestObject::test<3>() | 73 | void ServiceBuilderTestObject::test<3>() |
74 | { | 74 | { |
75 | //Incorrect service test | 75 | //Incorrect service test |
76 | LLSD test_block; | 76 | LLSD test_block; |
77 | test_block["service-builder"] = "/agent/{$agent-id}/name"; | 77 | test_block["service-builder"] = "/agent/{$agent-id}/name"; |
78 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); | 78 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); |
79 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilder"); | 79 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilder"); |
80 | ensure_equals("Replacement URL Creation for Non-existant Service", test_url , ""); | 80 | ensure_equals("Replacement URL Creation for Non-existant Service", test_url , ""); |
81 | } | 81 | } |
82 | 82 | ||
83 | template<> template<> | 83 | template<> template<> |
84 | void ServiceBuilderTestObject::test<4>() | 84 | void ServiceBuilderTestObject::test<4>() |
85 | { | 85 | { |
86 | //Incorrect service test | 86 | //Incorrect service test |
87 | LLSD test_block; | 87 | LLSD test_block; |
88 | test_block["service-builder"] = "/agent/{$agent-id}/name"; | 88 | test_block["service-builder"] = "/agent/{$agent-id}/name"; |
89 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); | 89 | mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]); |
90 | LLSD data_map; | 90 | LLSD data_map; |
91 | data_map["agent_id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6"; | 91 | data_map["agent_id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6"; |
92 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map); | 92 | std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map); |
93 | ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "/agent/{$agent-id}/name"); | 93 | ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "/agent/{$agent-id}/name"); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
diff --git a/linden/indra/test/llstring_tut.cpp b/linden/indra/test/llstring_tut.cpp new file mode 100644 index 0000000..040955b --- /dev/null +++ b/linden/indra/test/llstring_tut.cpp | |||
@@ -0,0 +1,498 @@ | |||
1 | /** | ||
2 | * @file llstring_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2006-12-24 | ||
5 | * @brief Test cases of llstring.cpp | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | #include "linden_common.h" | ||
33 | #include "llstring.h" | ||
34 | |||
35 | namespace tut | ||
36 | { | ||
37 | struct string_index | ||
38 | { | ||
39 | }; | ||
40 | typedef test_group<string_index> string_index_t; | ||
41 | typedef string_index_t::object string_index_object_t; | ||
42 | tut::string_index_t tut_string_index("string_test"); | ||
43 | |||
44 | template<> template<> | ||
45 | void string_index_object_t::test<1>() | ||
46 | { | ||
47 | LLString llstr1; | ||
48 | ensure("Empty LLString", (llstr1.size() == 0) && llstr1.empty()); | ||
49 | |||
50 | LLString llstr2("Hello"); | ||
51 | ensure("LLString = Hello", (!strcmp(llstr2.c_str(), "Hello")) && (llstr2.size() == 5) && !llstr2.empty()); | ||
52 | |||
53 | LLString llstr3(llstr2); | ||
54 | ensure("LLString = LLString(LLString)", (!strcmp(llstr3.c_str(), "Hello")) && (llstr3.size() == 5) && !llstr3.empty()); | ||
55 | |||
56 | std::string str("Hello World"); | ||
57 | LLString llstr4(str, 6); | ||
58 | ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (!strcmp(llstr4.c_str(), "World")) && (llstr4.size() == 5) && !llstr4.empty()); | ||
59 | |||
60 | LLString llstr5(str, str.size()); | ||
61 | ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (llstr5.size() == 0) && llstr5.empty()); | ||
62 | |||
63 | LLString llstr6(5, 'A'); | ||
64 | ensure("LLString = LLString(count, c)", (!strcmp(llstr6.c_str(), "AAAAA")) && (llstr6.size() == 5) && !llstr6.empty()); | ||
65 | |||
66 | LLString llstr7("Hello World", 5); | ||
67 | ensure("LLString(s, n)", (!strcmp(llstr7.c_str(), "Hello")) && (llstr7.size() == 5) && !llstr7.empty()); | ||
68 | |||
69 | LLString llstr8("Hello World", 6, 5); | ||
70 | ensure("LLString(s, n, count)", (!strcmp(llstr8.c_str(), "World")) && (llstr8.size() == 5) && !llstr8.empty()); | ||
71 | |||
72 | LLString llstr9("Hello World", sizeof("Hello World")-1, 5); // go past end | ||
73 | ensure("LLString(s, n, count) goes past end", (llstr9.size() == 0) && llstr9.empty()); | ||
74 | } | ||
75 | |||
76 | template<> template<> | ||
77 | void string_index_object_t::test<2>() | ||
78 | { | ||
79 | LLString str("Len=5"); | ||
80 | ensure("isValidIndex failed", LLString::isValidIndex(str, 0) == TRUE && | ||
81 | LLString::isValidIndex(str, 5) == TRUE && | ||
82 | LLString::isValidIndex(str, 6) == FALSE); | ||
83 | |||
84 | LLString str1; | ||
85 | ensure("isValidIndex failed fo rempty string", LLString::isValidIndex(str1, 0) == FALSE); | ||
86 | } | ||
87 | |||
88 | template<> template<> | ||
89 | void string_index_object_t::test<3>() | ||
90 | { | ||
91 | LLString str_val(" Testing the extra whitespaces "); | ||
92 | LLString::trimHead(str_val); | ||
93 | ensure_equals("1: trimHead failed", str_val, "Testing the extra whitespaces "); | ||
94 | |||
95 | LLString str_val1("\n\t\r\n Testing the extra whitespaces "); | ||
96 | LLString::trimHead(str_val1); | ||
97 | ensure_equals("2: trimHead failed", str_val1, "Testing the extra whitespaces "); | ||
98 | } | ||
99 | |||
100 | template<> template<> | ||
101 | void string_index_object_t::test<4>() | ||
102 | { | ||
103 | LLString str_val(" Testing the extra whitespaces "); | ||
104 | LLString::trimTail(str_val); | ||
105 | ensure_equals("1: trimTail failed", str_val, " Testing the extra whitespaces"); | ||
106 | |||
107 | LLString str_val1("\n Testing the extra whitespaces \n\t\r\n "); | ||
108 | LLString::trimTail(str_val1); | ||
109 | ensure_equals("2: trimTail failed", str_val1, "\n Testing the extra whitespaces"); | ||
110 | } | ||
111 | |||
112 | |||
113 | template<> template<> | ||
114 | void string_index_object_t::test<5>() | ||
115 | { | ||
116 | LLString str_val(" \t \r Testing the extra \r\n whitespaces \n \t "); | ||
117 | LLString::trim(str_val); | ||
118 | ensure_equals("1: trim failed", str_val, "Testing the extra \r\n whitespaces"); | ||
119 | } | ||
120 | |||
121 | template<> template<> | ||
122 | void string_index_object_t::test<6>() | ||
123 | { | ||
124 | LLString str("Second LindenLabs"); | ||
125 | LLString::truncate(str, 6); | ||
126 | ensure_equals("1: truncate", str, "Second"); | ||
127 | |||
128 | // further truncate more than the length | ||
129 | LLString::truncate(str, 0); | ||
130 | ensure_equals("2: truncate", str, ""); | ||
131 | } | ||
132 | |||
133 | template<> template<> | ||
134 | void string_index_object_t::test<7>() | ||
135 | { | ||
136 | LLString str_val("SecondLife Source"); | ||
137 | LLString::toUpper(str_val); | ||
138 | ensure_equals("toUpper failed", str_val, "SECONDLIFE SOURCE"); | ||
139 | } | ||
140 | |||
141 | template<> template<> | ||
142 | void string_index_object_t::test<8>() | ||
143 | { | ||
144 | LLString str_val("SecondLife Source"); | ||
145 | LLString::toLower(str_val); | ||
146 | ensure_equals("toLower failed", str_val, "secondlife source"); | ||
147 | } | ||
148 | |||
149 | template<> template<> | ||
150 | void string_index_object_t::test<9>() | ||
151 | { | ||
152 | LLString str_val("Second"); | ||
153 | ensure("1. isHead failed", LLString::isHead(str_val, "SecondLife Source") == TRUE); | ||
154 | ensure("2. isHead failed", LLString::isHead(str_val, " SecondLife Source") == FALSE); | ||
155 | LLString str_val2(""); | ||
156 | ensure("3. isHead failed", LLString::isHead(str_val2, "") == FALSE); | ||
157 | } | ||
158 | |||
159 | template<> template<> | ||
160 | void string_index_object_t::test<10>() | ||
161 | { | ||
162 | LLString str_val("Hello.\n\n Lindenlabs. \n This is \na simple test.\n"); | ||
163 | LLString orig_str_val(str_val); | ||
164 | LLString::addCRLF(str_val); | ||
165 | ensure_equals("addCRLF failed", str_val, "Hello.\r\n\r\n Lindenlabs. \r\n This is \r\na simple test.\r\n"); | ||
166 | LLString::removeCRLF(str_val); | ||
167 | ensure_equals("removeCRLF failed", str_val, orig_str_val); | ||
168 | } | ||
169 | |||
170 | template<> template<> | ||
171 | void string_index_object_t::test<11>() | ||
172 | { | ||
173 | LLString str_val("Hello.\n\n\t \t Lindenlabs. \t\t"); | ||
174 | LLString orig_str_val(str_val); | ||
175 | LLString::replaceTabsWithSpaces(str_val, 1); | ||
176 | ensure_equals("replaceTabsWithSpaces failed", str_val, "Hello.\n\n Lindenlabs. "); | ||
177 | LLString::replaceTabsWithSpaces(orig_str_val, 0); | ||
178 | ensure_equals("replaceTabsWithSpaces failed for 0", orig_str_val, "Hello.\n\n Lindenlabs. "); | ||
179 | |||
180 | str_val = "\t\t\t\t"; | ||
181 | LLString::replaceTabsWithSpaces(str_val, 0); | ||
182 | ensure_equals("replaceTabsWithSpaces failed for all tabs", str_val, ""); | ||
183 | } | ||
184 | |||
185 | template<> template<> | ||
186 | void string_index_object_t::test<12>() | ||
187 | { | ||
188 | LLString str_val("Hello.\n\n\t\t\r\nLindenlabsX."); | ||
189 | LLString::replaceNonstandardASCII(str_val, 'X'); | ||
190 | ensure_equals("replaceNonstandardASCII failed", str_val, "Hello.\n\nXXX\nLindenlabsX."); | ||
191 | } | ||
192 | |||
193 | template<> template<> | ||
194 | void string_index_object_t::test<13>() | ||
195 | { | ||
196 | LLString str_val("Hello.\n\t\r\nABCDEFGHIABABAB"); | ||
197 | LLString::replaceChar(str_val, 'A', 'X'); | ||
198 | ensure_equals("1: replaceChar failed", str_val, "Hello.\n\t\r\nXBCDEFGHIXBXBXB"); | ||
199 | LLString str_val1("Hello.\n\t\r\nABCDEFGHIABABAB"); | ||
200 | } | ||
201 | |||
202 | template<> template<> | ||
203 | void string_index_object_t::test<14>() | ||
204 | { | ||
205 | LLString str_val("Hello.\n\r\t"); | ||
206 | ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == TRUE); | ||
207 | |||
208 | str_val = "ABC "; | ||
209 | ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == FALSE); | ||
210 | } | ||
211 | |||
212 | template<> template<> | ||
213 | void string_index_object_t::test<15>() | ||
214 | { | ||
215 | LLString str_val("Hello.\n\r\t Again!"); | ||
216 | LLString::stripNonprintable(str_val); | ||
217 | ensure_equals("stripNonprintable failed", str_val, "Hello. Again!"); | ||
218 | |||
219 | str_val = "\r\n\t\t"; | ||
220 | LLString::stripNonprintable(str_val); | ||
221 | ensure_equals("stripNonprintable resulting in empty string failed", str_val, ""); | ||
222 | } | ||
223 | |||
224 | template<> template<> | ||
225 | void string_index_object_t::test<16>() | ||
226 | { | ||
227 | BOOL value; | ||
228 | LLString str_val("1"); | ||
229 | ensure("convertToBOOL 1 failed", LLString::convertToBOOL(str_val, value) && value); | ||
230 | str_val = "T"; | ||
231 | ensure("convertToBOOL T failed", LLString::convertToBOOL(str_val, value) && value); | ||
232 | str_val = "t"; | ||
233 | ensure("convertToBOOL t failed", LLString::convertToBOOL(str_val, value) && value); | ||
234 | str_val = "TRUE"; | ||
235 | ensure("convertToBOOL TRUE failed", LLString::convertToBOOL(str_val, value) && value); | ||
236 | str_val = "True"; | ||
237 | ensure("convertToBOOL True failed", LLString::convertToBOOL(str_val, value) && value); | ||
238 | str_val = "true"; | ||
239 | ensure("convertToBOOL true failed", LLString::convertToBOOL(str_val, value) && value); | ||
240 | |||
241 | str_val = "0"; | ||
242 | ensure("convertToBOOL 0 failed", LLString::convertToBOOL(str_val, value) && !value); | ||
243 | str_val = "F"; | ||
244 | ensure("convertToBOOL F failed", LLString::convertToBOOL(str_val, value) && !value); | ||
245 | str_val = "f"; | ||
246 | ensure("convertToBOOL f failed", LLString::convertToBOOL(str_val, value) && !value); | ||
247 | str_val = "FALSE"; | ||
248 | ensure("convertToBOOL FASLE failed", LLString::convertToBOOL(str_val, value) && !value); | ||
249 | str_val = "False"; | ||
250 | ensure("convertToBOOL False failed", LLString::convertToBOOL(str_val, value) && !value); | ||
251 | str_val = "false"; | ||
252 | ensure("convertToBOOL false failed", LLString::convertToBOOL(str_val, value) && !value); | ||
253 | |||
254 | str_val = "Tblah"; | ||
255 | ensure("convertToBOOL false failed", !LLString::convertToBOOL(str_val, value)); | ||
256 | } | ||
257 | |||
258 | template<> template<> | ||
259 | void string_index_object_t::test<17>() | ||
260 | { | ||
261 | U8 value; | ||
262 | LLString str_val("255"); | ||
263 | ensure("1: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 255); | ||
264 | |||
265 | str_val = "0"; | ||
266 | ensure("2: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 0); | ||
267 | |||
268 | str_val = "-1"; | ||
269 | ensure("3: convertToU8 failed", !LLString::convertToU8(str_val, value)); | ||
270 | |||
271 | str_val = "256"; // bigger than MAX_U8 | ||
272 | ensure("4: convertToU8 failed", !LLString::convertToU8(str_val, value)); | ||
273 | } | ||
274 | |||
275 | template<> template<> | ||
276 | void string_index_object_t::test<18>() | ||
277 | { | ||
278 | S8 value; | ||
279 | LLString str_val("127"); | ||
280 | ensure("1: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 127); | ||
281 | |||
282 | str_val = "0"; | ||
283 | ensure("2: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 0); | ||
284 | |||
285 | str_val = "-128"; | ||
286 | ensure("3: convertToS8 failed", LLString::convertToS8(str_val, value) && value == -128); | ||
287 | |||
288 | str_val = "128"; // bigger than MAX_S8 | ||
289 | ensure("4: convertToS8 failed", !LLString::convertToS8(str_val, value)); | ||
290 | |||
291 | str_val = "-129"; | ||
292 | ensure("5: convertToS8 failed", !LLString::convertToS8(str_val, value)); | ||
293 | } | ||
294 | |||
295 | template<> template<> | ||
296 | void string_index_object_t::test<19>() | ||
297 | { | ||
298 | S16 value; | ||
299 | LLString str_val("32767"); | ||
300 | ensure("1: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 32767); | ||
301 | |||
302 | str_val = "0"; | ||
303 | ensure("2: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 0); | ||
304 | |||
305 | str_val = "-32768"; | ||
306 | ensure("3: convertToS16 failed", LLString::convertToS16(str_val, value) && value == -32768); | ||
307 | |||
308 | str_val = "32768"; | ||
309 | ensure("4: convertToS16 failed", !LLString::convertToS16(str_val, value)); | ||
310 | |||
311 | str_val = "-32769"; | ||
312 | ensure("5: convertToS16 failed", !LLString::convertToS16(str_val, value)); | ||
313 | } | ||
314 | |||
315 | template<> template<> | ||
316 | void string_index_object_t::test<20>() | ||
317 | { | ||
318 | U16 value; | ||
319 | LLString str_val("65535"); //0xFFFF | ||
320 | ensure("1: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 65535); | ||
321 | |||
322 | str_val = "0"; | ||
323 | ensure("2: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 0); | ||
324 | |||
325 | str_val = "-1"; | ||
326 | ensure("3: convertToU16 failed", !LLString::convertToU16(str_val, value)); | ||
327 | |||
328 | str_val = "65536"; | ||
329 | ensure("4: convertToU16 failed", !LLString::convertToU16(str_val, value)); | ||
330 | } | ||
331 | |||
332 | template<> template<> | ||
333 | void string_index_object_t::test<21>() | ||
334 | { | ||
335 | U32 value; | ||
336 | LLString str_val("4294967295"); //0xFFFFFFFF | ||
337 | ensure("1: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295); | ||
338 | |||
339 | str_val = "0"; | ||
340 | ensure("2: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 0); | ||
341 | |||
342 | str_val = "-1"; | ||
343 | ensure("3: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295); | ||
344 | |||
345 | str_val = "4294967296"; | ||
346 | ensure("4: convertToU32 failed", !LLString::convertToU32(str_val, value)); | ||
347 | } | ||
348 | |||
349 | template<> template<> | ||
350 | void string_index_object_t::test<22>() | ||
351 | { | ||
352 | S32 value; | ||
353 | LLString str_val("2147483647"); //0x7FFFFFFF | ||
354 | ensure("1: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 2147483647); | ||
355 | |||
356 | str_val = "0"; | ||
357 | ensure("2: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 0); | ||
358 | |||
359 | str_val = "-2147483648"; | ||
360 | ensure("3: convertToS32 failed", LLString::convertToS32(str_val, value) && value == -2147483648); | ||
361 | |||
362 | str_val = "2147483648"; | ||
363 | ensure("4: convertToS32 failed", !LLString::convertToS32(str_val, value)); | ||
364 | |||
365 | str_val = "-2147483649"; | ||
366 | ensure("5: convertToS32 failed", !LLString::convertToS32(str_val, value)); | ||
367 | } | ||
368 | |||
369 | template<> template<> | ||
370 | void string_index_object_t::test<23>() | ||
371 | { | ||
372 | F32 value; | ||
373 | LLString str_val("2147483647"); //0x7FFFFFFF | ||
374 | ensure("1: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 2147483647); | ||
375 | |||
376 | str_val = "0"; | ||
377 | ensure("2: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 0); | ||
378 | |||
379 | /* Need to find max/min F32 values | ||
380 | str_val = "-2147483648"; | ||
381 | ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648); | ||
382 | |||
383 | str_val = "2147483648"; | ||
384 | ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value)); | ||
385 | |||
386 | str_val = "-2147483649"; | ||
387 | ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value)); | ||
388 | */ | ||
389 | } | ||
390 | |||
391 | template<> template<> | ||
392 | void string_index_object_t::test<24>() | ||
393 | { | ||
394 | F64 value; | ||
395 | LLString str_val("9223372036854775807"); //0x7FFFFFFFFFFFFFFF | ||
396 | ensure("1: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 9223372036854775807); | ||
397 | |||
398 | str_val = "0"; | ||
399 | ensure("2: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 0); | ||
400 | |||
401 | /* Need to find max/min F64 values | ||
402 | str_val = "-2147483648"; | ||
403 | ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648); | ||
404 | |||
405 | str_val = "2147483648"; | ||
406 | ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value)); | ||
407 | |||
408 | str_val = "-2147483649"; | ||
409 | ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value)); | ||
410 | */ | ||
411 | } | ||
412 | |||
413 | template<> template<> | ||
414 | void string_index_object_t::test<25>() | ||
415 | { | ||
416 | char* str1 = NULL; | ||
417 | char* str2 = NULL; | ||
418 | |||
419 | ensure("1: compareStrings failed", LLString::compareStrings(str1, str2) == 0); | ||
420 | str2 = "A"; | ||
421 | ensure("2: compareStrings failed", LLString::compareStrings(str1, str2) > 0); | ||
422 | ensure("3: compareStrings failed", LLString::compareStrings(str2, str1) < 0); | ||
423 | |||
424 | str1 = "A is smaller than B"; | ||
425 | str2 = "B is greater than A"; | ||
426 | ensure("4: compareStrings failed", LLString::compareStrings(str1, str2) < 0); | ||
427 | |||
428 | str2 = "A is smaller than B"; | ||
429 | ensure("5: compareStrings failed", LLString::compareStrings(str1, str2) == 0); | ||
430 | } | ||
431 | |||
432 | template<> template<> | ||
433 | void string_index_object_t::test<26>() | ||
434 | { | ||
435 | char* str1 = NULL; | ||
436 | char* str2 = NULL; | ||
437 | |||
438 | ensure("1: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0); | ||
439 | str2 = "A"; | ||
440 | ensure("2: compareInsensitive failed", LLString::compareInsensitive(str1, str2) > 0); | ||
441 | ensure("3: compareInsensitive failed", LLString::compareInsensitive(str2, str1) < 0); | ||
442 | |||
443 | str1 = "A is equal to a"; | ||
444 | str2 = "a is EQUAL to A"; | ||
445 | ensure("4: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0); | ||
446 | } | ||
447 | |||
448 | template<> template<> | ||
449 | void string_index_object_t::test<27>() | ||
450 | { | ||
451 | LLString lhs_str("PROgraM12files"); | ||
452 | LLString rhs_str("PROgram12Files"); | ||
453 | ensure("compareDict 1 failed", LLString::compareDict(lhs_str, rhs_str) < 0); | ||
454 | ensure("precedesDict 1 failed", LLString::precedesDict(lhs_str, rhs_str) == TRUE); | ||
455 | |||
456 | lhs_str = "PROgram12Files"; | ||
457 | rhs_str = "PROgram12Files"; | ||
458 | ensure("compareDict 2 failed", LLString::compareDict(lhs_str, rhs_str) == 0); | ||
459 | ensure("precedesDict 2 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE); | ||
460 | |||
461 | lhs_str = "PROgram12Files"; | ||
462 | rhs_str = "PROgRAM12FILES"; | ||
463 | ensure("compareDict 3 failed", LLString::compareDict(lhs_str, rhs_str) > 0); | ||
464 | ensure("precedesDict 3 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE); | ||
465 | } | ||
466 | |||
467 | template<> template<> | ||
468 | void string_index_object_t::test<28>() | ||
469 | { | ||
470 | char str1[] = "First String..."; | ||
471 | char str2[100]; | ||
472 | |||
473 | LLString::copy(str2, str1, 100); | ||
474 | ensure("LLString::copy with enough dest lenght failed", strcmp(str2, str1) == 0); | ||
475 | LLString::copy(str2, str1, sizeof("First")); | ||
476 | ensure("LLString::copy with less dest lenght failed", strcmp(str2, "First") == 0); | ||
477 | } | ||
478 | |||
479 | template<> template<> | ||
480 | void string_index_object_t::test<29>() | ||
481 | { | ||
482 | LLString str1 = "This is the sentence..."; | ||
483 | LLString str2 = "This is the "; | ||
484 | LLString str3 = "first "; | ||
485 | LLString str4 = "This is the first sentence..."; | ||
486 | LLString str5 = "This is the sentence...first "; | ||
487 | LLString dest; | ||
488 | |||
489 | dest = str1; | ||
490 | LLString::copyInto(dest, str3, str2.length()); | ||
491 | ensure("LLString::copyInto insert failed", dest == str4); | ||
492 | |||
493 | dest = str1; | ||
494 | LLString::copyInto(dest, str3, dest.length()); | ||
495 | ensure("LLString::copyInto append failed", dest == str5); | ||
496 | } | ||
497 | } | ||
498 | |||
diff --git a/linden/indra/test/lltut.h b/linden/indra/test/lltut.h index 3e43df8..626ff60 100644 --- a/linden/indra/test/lltut.h +++ b/linden/indra/test/lltut.h | |||
@@ -41,11 +41,27 @@ | |||
41 | 41 | ||
42 | #include "lldate.h" | 42 | #include "lldate.h" |
43 | #include "lluri.h" | 43 | #include "lluri.h" |
44 | #include "llmath.h" | ||
44 | 45 | ||
45 | class LLSD; | 46 | class LLSD; |
46 | 47 | ||
47 | namespace tut | 48 | namespace tut |
48 | { | 49 | { |
50 | inline void ensure_approximately_equals(const char* msg, F32 actual, F32 expected, U32 frac_bits) | ||
51 | { | ||
52 | if(!is_approx_equal_fraction(actual, expected, frac_bits)) | ||
53 | { | ||
54 | std::stringstream ss; | ||
55 | ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected; | ||
56 | throw tut::failure(ss.str().c_str()); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | inline void ensure_approximately_equals(F32 actual, F32 expected, U32 frac_bits) | ||
61 | { | ||
62 | ensure_approximately_equals(NULL, actual, expected, frac_bits); | ||
63 | } | ||
64 | |||
49 | inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len) | 65 | inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len) |
50 | { | 66 | { |
51 | if((expected_len != actual_len) || | 67 | if((expected_len != actual_len) || |
diff --git a/linden/indra/test/llxfer_tut.cpp b/linden/indra/test/llxfer_tut.cpp new file mode 100644 index 0000000..c4665c9 --- /dev/null +++ b/linden/indra/test/llxfer_tut.cpp | |||
@@ -0,0 +1,61 @@ | |||
1 | /** | ||
2 | * @file llxfer_tut.cpp | ||
3 | * @author Moss | ||
4 | * @date 2007-04-17 | ||
5 | * | ||
6 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | #include "lltut.h" | ||
32 | |||
33 | #include "llxfer_file.h" | ||
34 | |||
35 | #include <string> | ||
36 | |||
37 | namespace tut | ||
38 | { | ||
39 | struct llxfer_data | ||
40 | { | ||
41 | }; | ||
42 | typedef test_group<llxfer_data> llxfer_test; | ||
43 | typedef llxfer_test::object llxfer_object; | ||
44 | tut::llxfer_test llxfer("llxfer"); | ||
45 | |||
46 | template<> template<> | ||
47 | void llxfer_object::test<1>() | ||
48 | { | ||
49 | // test that he handle an oversized filename correctly. | ||
50 | LLString oversized_filename; | ||
51 | U32 i; | ||
52 | for (i=0; i<LL_MAX_PATH*2; ++i) // create oversized filename | ||
53 | { | ||
54 | oversized_filename += 'X'; | ||
55 | } | ||
56 | |||
57 | LLXfer_File xff(oversized_filename, FALSE, 1); | ||
58 | ensure("oversized local_filename nul-terminated", | ||
59 | strnlen(xff.getName(), LL_MAX_PATH) < LL_MAX_PATH); | ||
60 | } | ||
61 | } | ||
diff --git a/linden/indra/test/m3math_tut.cpp b/linden/indra/test/m3math_tut.cpp new file mode 100644 index 0000000..62ad365 --- /dev/null +++ b/linden/indra/test/m3math_tut.cpp | |||
@@ -0,0 +1,320 @@ | |||
1 | /** | ||
2 | * @file m3math_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief Test cases of m3math.h | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "m3math.h" | ||
35 | #include "v3math.h" | ||
36 | #include "v4math.h" | ||
37 | #include "m4math.h" | ||
38 | #include "llquaternion.h" | ||
39 | #include "v3dmath.h" | ||
40 | |||
41 | namespace tut | ||
42 | { | ||
43 | struct m3math_test | ||
44 | { | ||
45 | }; | ||
46 | typedef test_group<m3math_test> m3math_test_t; | ||
47 | typedef m3math_test_t::object m3math_test_object_t; | ||
48 | tut::m3math_test_t tut_m3math_test("m3math_test"); | ||
49 | |||
50 | //test case for identity() fn. | ||
51 | template<> template<> | ||
52 | void m3math_test_object_t::test<1>() | ||
53 | { | ||
54 | LLMatrix3 llmat3_obj; | ||
55 | llmat3_obj.identity(); | ||
56 | ensure("LLMatrix3::identity failed", 1.f == llmat3_obj.mMatrix[0][0] && | ||
57 | 0.f == llmat3_obj.mMatrix[0][1] && | ||
58 | 0.f == llmat3_obj.mMatrix[0][2] && | ||
59 | 0.f == llmat3_obj.mMatrix[1][0] && | ||
60 | 1.f == llmat3_obj.mMatrix[1][1] && | ||
61 | 0.f == llmat3_obj.mMatrix[1][2] && | ||
62 | 0.f == llmat3_obj.mMatrix[2][0] && | ||
63 | 0.f == llmat3_obj.mMatrix[2][1] && | ||
64 | 1.f == llmat3_obj.mMatrix[2][2]); | ||
65 | } | ||
66 | |||
67 | //test case for LLMatrix3& zero() fn. | ||
68 | template<> template<> | ||
69 | void m3math_test_object_t::test<2>() | ||
70 | { | ||
71 | LLMatrix3 llmat3_obj(30, 1, 2, 3); | ||
72 | llmat3_obj.zero(); | ||
73 | |||
74 | ensure("LLMatrix3::zero failed", 0.f == llmat3_obj.zero().mMatrix[0][0] && | ||
75 | 0.f == llmat3_obj.zero().mMatrix[0][1] && | ||
76 | 0.f == llmat3_obj.zero().mMatrix[0][2] && | ||
77 | 0.f == llmat3_obj.zero().mMatrix[1][0] && | ||
78 | 0.f == llmat3_obj.zero().mMatrix[1][1] && | ||
79 | 0.f == llmat3_obj.zero().mMatrix[1][2] && | ||
80 | 0.f == llmat3_obj.zero().mMatrix[2][0] && | ||
81 | 0.f == llmat3_obj.zero().mMatrix[2][1] && | ||
82 | 0.f == llmat3_obj.zero().mMatrix[2][2]); | ||
83 | } | ||
84 | |||
85 | //test case for setRows(const LLVector3 &x_axis, const LLVector3 &y_axis, const LLVector3 &z_axis) fns. | ||
86 | template<> template<> | ||
87 | void m3math_test_object_t::test<3>() | ||
88 | { | ||
89 | LLMatrix3 llmat3_obj; | ||
90 | LLVector3 vect1(2, 1, 4); | ||
91 | LLVector3 vect2(3, 5, 7); | ||
92 | LLVector3 vect3(6, 9, 7); | ||
93 | llmat3_obj.setRows(vect1, vect2, vect3); | ||
94 | ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] && | ||
95 | 1 == llmat3_obj.mMatrix[0][1] && | ||
96 | 4 == llmat3_obj.mMatrix[0][2] && | ||
97 | 3 == llmat3_obj.mMatrix[1][0] && | ||
98 | 5 == llmat3_obj.mMatrix[1][1] && | ||
99 | 7 == llmat3_obj.mMatrix[1][2] && | ||
100 | 6 == llmat3_obj.mMatrix[2][0] && | ||
101 | 9 == llmat3_obj.mMatrix[2][1] && | ||
102 | 7 == llmat3_obj.mMatrix[2][2]); | ||
103 | } | ||
104 | |||
105 | //test case for getFwdRow(), getLeftRow(), getUpRow() fns. | ||
106 | template<> template<> | ||
107 | void m3math_test_object_t::test<4>() | ||
108 | { | ||
109 | LLMatrix3 llmat3_obj; | ||
110 | LLVector3 vect1(2, 1, 4); | ||
111 | LLVector3 vect2(3, 5, 7); | ||
112 | LLVector3 vect3(6, 9, 7); | ||
113 | llmat3_obj.setRows(vect1, vect2, vect3); | ||
114 | |||
115 | ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow()); | ||
116 | ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow()); | ||
117 | ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow()); | ||
118 | } | ||
119 | |||
120 | //test case for operator*(const LLMatrix3 &a, const LLMatrix3 &b) | ||
121 | template<> template<> | ||
122 | void m3math_test_object_t::test<5>() | ||
123 | { | ||
124 | LLMatrix3 llmat_obj1; | ||
125 | LLMatrix3 llmat_obj2; | ||
126 | LLMatrix3 llmat_obj3; | ||
127 | |||
128 | LLVector3 llvec1(1, 3, 5); | ||
129 | LLVector3 llvec2(3, 6, 1); | ||
130 | LLVector3 llvec3(4, 6, 9); | ||
131 | |||
132 | LLVector3 llvec4(1, 1, 5); | ||
133 | LLVector3 llvec5(3, 6, 8); | ||
134 | LLVector3 llvec6(8, 6, 2); | ||
135 | |||
136 | LLVector3 llvec7(0, 0, 0); | ||
137 | LLVector3 llvec8(0, 0, 0); | ||
138 | LLVector3 llvec9(0, 0, 0); | ||
139 | |||
140 | llmat_obj1.setRows(llvec1, llvec2, llvec3); | ||
141 | llmat_obj2.setRows(llvec4, llvec5, llvec6); | ||
142 | llmat_obj3.setRows(llvec7, llvec8, llvec9); | ||
143 | llmat_obj3 = llmat_obj1 * llmat_obj2; | ||
144 | ensure("LLMatrix3::operator*(const LLMatrix3 &a, const LLMatrix3 &b) failed", | ||
145 | 50 == llmat_obj3.mMatrix[0][0] && | ||
146 | 49 == llmat_obj3.mMatrix[0][1] && | ||
147 | 39 == llmat_obj3.mMatrix[0][2] && | ||
148 | 29 == llmat_obj3.mMatrix[1][0] && | ||
149 | 45 == llmat_obj3.mMatrix[1][1] && | ||
150 | 65 == llmat_obj3.mMatrix[1][2] && | ||
151 | 94 == llmat_obj3.mMatrix[2][0] && | ||
152 | 94 == llmat_obj3.mMatrix[2][1] && | ||
153 | 86 == llmat_obj3.mMatrix[2][2]); | ||
154 | } | ||
155 | |||
156 | |||
157 | //test case for operator*(const LLVector3 &a, const LLMatrix3 &b) | ||
158 | template<> template<> | ||
159 | void m3math_test_object_t::test<6>() | ||
160 | { | ||
161 | |||
162 | LLMatrix3 llmat_obj1; | ||
163 | |||
164 | LLVector3 llvec(1, 3, 5); | ||
165 | LLVector3 res_vec(0, 0, 0); | ||
166 | LLVector3 llvec1(1, 3, 5); | ||
167 | LLVector3 llvec2(3, 6, 1); | ||
168 | LLVector3 llvec3(4, 6, 9); | ||
169 | |||
170 | llmat_obj1.setRows(llvec1, llvec2, llvec3); | ||
171 | res_vec = llvec * llmat_obj1; | ||
172 | |||
173 | LLVector3 expected_result(30, 51, 53); | ||
174 | |||
175 | ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", res_vec == expected_result); | ||
176 | } | ||
177 | |||
178 | //test case for operator*(const LLVector3d &a, const LLMatrix3 &b) | ||
179 | template<> template<> | ||
180 | void m3math_test_object_t::test<7>() | ||
181 | { | ||
182 | LLMatrix3 llmat_obj1; | ||
183 | LLVector3d llvec3d1; | ||
184 | LLVector3d llvec3d2(0, 3, 4); | ||
185 | |||
186 | LLVector3 llvec1(1, 3, 5); | ||
187 | LLVector3 llvec2(3, 2, 1); | ||
188 | LLVector3 llvec3(4, 6, 0); | ||
189 | |||
190 | llmat_obj1.setRows(llvec1, llvec2, llvec3); | ||
191 | llvec3d1 = llvec3d2 * llmat_obj1; | ||
192 | |||
193 | LLVector3d expected_result(25, 30, 3); | ||
194 | |||
195 | ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", llvec3d1 == expected_result); | ||
196 | } | ||
197 | |||
198 | // test case for operator==(const LLMatrix3 &a, const LLMatrix3 &b) | ||
199 | template<> template<> | ||
200 | void m3math_test_object_t::test<8>() | ||
201 | { | ||
202 | LLMatrix3 llmat_obj1; | ||
203 | LLMatrix3 llmat_obj2; | ||
204 | |||
205 | LLVector3 llvec1(1, 3, 5); | ||
206 | LLVector3 llvec2(3, 6, 1); | ||
207 | LLVector3 llvec3(4, 6, 9); | ||
208 | |||
209 | llmat_obj1.setRows(llvec1, llvec2, llvec3); | ||
210 | llmat_obj2.setRows(llvec1, llvec2, llvec3); | ||
211 | ensure("LLMatrix3::operator==(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 == llmat_obj2); | ||
212 | |||
213 | llmat_obj2.setRows(llvec2, llvec2, llvec3); | ||
214 | ensure("LLMatrix3::operator!=(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 != llmat_obj2); | ||
215 | } | ||
216 | |||
217 | //test case for quaternion() fn. | ||
218 | template<> template<> | ||
219 | void m3math_test_object_t::test<9>() | ||
220 | { | ||
221 | LLMatrix3 llmat_obj1; | ||
222 | LLQuaternion llmat_quat; | ||
223 | |||
224 | LLVector3 llmat1(2.0f, 1.0f, 6.0f); | ||
225 | LLVector3 llmat2(1.0f, 1.0f, 3.0f); | ||
226 | LLVector3 llmat3(1.0f, 7.0f, 5.0f); | ||
227 | |||
228 | llmat_obj1.setRows(llmat1, llmat2, llmat3); | ||
229 | llmat_quat = llmat_obj1.quaternion(); | ||
230 | ensure("LLMatrix3::quaternion failed ", is_approx_equal(-0.66666669f, llmat_quat.mQ[0]) && | ||
231 | is_approx_equal(-0.83333337f, llmat_quat.mQ[1]) && | ||
232 | is_approx_equal(0.0f, llmat_quat.mQ[2]) && | ||
233 | is_approx_equal(1.5f, llmat_quat.mQ[3])); | ||
234 | } | ||
235 | |||
236 | //test case for transpose() fn. | ||
237 | template<> template<> | ||
238 | void m3math_test_object_t::test<10>() | ||
239 | { | ||
240 | LLMatrix3 llmat_obj; | ||
241 | |||
242 | LLVector3 llvec1(1, 2, 3); | ||
243 | LLVector3 llvec2(3, 2, 1); | ||
244 | LLVector3 llvec3(2, 2, 2); | ||
245 | |||
246 | llmat_obj.setRows(llvec1, llvec2, llvec3); | ||
247 | llmat_obj.transpose(); | ||
248 | |||
249 | LLVector3 resllvec1(1, 3, 2); | ||
250 | LLVector3 resllvec2(2, 2, 2); | ||
251 | LLVector3 resllvec3(3, 1, 2); | ||
252 | LLMatrix3 expectedllmat_obj; | ||
253 | expectedllmat_obj.setRows(resllvec1, resllvec2, resllvec3); | ||
254 | |||
255 | ensure("LLMatrix3::transpose failed ", llmat_obj == expectedllmat_obj); | ||
256 | } | ||
257 | |||
258 | //test case for determinant() fn. | ||
259 | template<> template<> | ||
260 | void m3math_test_object_t::test<11>() | ||
261 | { | ||
262 | LLMatrix3 llmat_obj1; | ||
263 | |||
264 | LLVector3 llvec1(1, 2, 3); | ||
265 | LLVector3 llvec2(3, 2, 1); | ||
266 | LLVector3 llvec3(2, 2, 2); | ||
267 | llmat_obj1.setRows(llvec1, llvec2, llvec3); | ||
268 | ensure("LLMatrix3::determinant failed ", 0.0f == llmat_obj1.determinant()); | ||
269 | } | ||
270 | |||
271 | //test case for orthogonalize() fn. | ||
272 | template<> template<> | ||
273 | void m3math_test_object_t::test<12>() | ||
274 | { | ||
275 | LLMatrix3 llmat_obj; | ||
276 | |||
277 | LLVector3 llvec1(1, 4, 3); | ||
278 | LLVector3 llvec2(1, 2, 0); | ||
279 | LLVector3 llvec3(2, 4, 2); | ||
280 | |||
281 | llmat_obj.setRows(llvec1, llvec2, llvec3); | ||
282 | llmat_obj.orthogonalize(); | ||
283 | |||
284 | ensure("LLMatrix3::orthogonalize failed ", is_approx_equal(0.19611613f, llmat_obj.mMatrix[0][0]) && | ||
285 | is_approx_equal(0.78446454f, llmat_obj.mMatrix[0][1]) && | ||
286 | is_approx_equal(0.58834839f, llmat_obj.mMatrix[0][2]) && | ||
287 | is_approx_equal(0.47628206f, llmat_obj.mMatrix[1][0]) && | ||
288 | is_approx_equal(0.44826555f, llmat_obj.mMatrix[1][1]) && | ||
289 | is_approx_equal(-0.75644791f, llmat_obj.mMatrix[1][2]) && | ||
290 | is_approx_equal(-0.85714287f, llmat_obj.mMatrix[2][0]) && | ||
291 | is_approx_equal(0.42857143f, llmat_obj.mMatrix[2][1]) && | ||
292 | is_approx_equal(-0.28571427f, llmat_obj.mMatrix[2][2])); | ||
293 | } | ||
294 | |||
295 | //test case for adjointTranspose() fn. | ||
296 | template<> template<> | ||
297 | void m3math_test_object_t::test<13>() | ||
298 | { | ||
299 | LLMatrix3 llmat_obj; | ||
300 | |||
301 | LLVector3 llvec1(3, 2, 1); | ||
302 | LLVector3 llvec2(6, 2, 1); | ||
303 | LLVector3 llvec3(3, 6, 8); | ||
304 | |||
305 | llmat_obj.setRows(llvec1, llvec2, llvec3); | ||
306 | llmat_obj.adjointTranspose(); | ||
307 | |||
308 | ensure("LLMatrix3::adjointTranspose failed ", 10 == llmat_obj.mMatrix[0][0] && | ||
309 | -45 == llmat_obj.mMatrix[1][0] && | ||
310 | 30 == llmat_obj.mMatrix[2][0] && | ||
311 | -10 == llmat_obj.mMatrix[0][1] && | ||
312 | 21 == llmat_obj.mMatrix[1][1] && | ||
313 | -12 == llmat_obj.mMatrix[2][1] && | ||
314 | 0 == llmat_obj.mMatrix[0][2] && | ||
315 | 3 == llmat_obj.mMatrix[1][2] && | ||
316 | -6 == llmat_obj.mMatrix[2][2]); | ||
317 | } | ||
318 | |||
319 | /* TBD: Need to add test cases for getEulerAngles() and setRot() functions */ | ||
320 | } | ||
diff --git a/linden/indra/test/v2math_tut.cpp b/linden/indra/test/v2math_tut.cpp new file mode 100644 index 0000000..e94a19b --- /dev/null +++ b/linden/indra/test/v2math_tut.cpp | |||
@@ -0,0 +1,447 @@ | |||
1 | /** | ||
2 | * @file v2math_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date February 2007 | ||
5 | * @brief v2math test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | #include "linden_common.h" | ||
33 | #include "v2math.h" | ||
34 | |||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct v2math_data | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<v2math_data> v2math_test; | ||
42 | typedef v2math_test::object v2math_object; | ||
43 | tut::v2math_test v2math_testcase("v2math"); | ||
44 | |||
45 | template<> template<> | ||
46 | void v2math_object::test<1>() | ||
47 | { | ||
48 | LLVector2 vec2; | ||
49 | ensure("LLVector2:Fail to initialize ", (0.f == vec2.mV[VX] && 0.f == vec2.mV[VY])); | ||
50 | |||
51 | F32 x =2.0f, y = 3.2f ; | ||
52 | LLVector2 vec3(x,y); | ||
53 | ensure("LLVector2(F32 x, F32 y):Fail to initialize ", (x == vec3.mV[VX]) && (y == vec3.mV[VY])); | ||
54 | |||
55 | const F32 vec[2] = {3.2f, 4.5f}; | ||
56 | LLVector2 vec4(vec); | ||
57 | ensure("LLVector2(const F32 *vec):Fail to initialize ", (vec[0] == vec4.mV[VX]) && (vec[1] == vec4.mV[VY])); | ||
58 | |||
59 | vec4.clearVec(); | ||
60 | ensure("clearVec():Fail to clean the values ", (0.f == vec4.mV[VX] && 0.f == vec4.mV[VY])); | ||
61 | |||
62 | vec3.zeroVec(); | ||
63 | ensure("zeroVec():Fail to fill the zero ", (0.f == vec3.mV[VX] && 0.f == vec3.mV[VY])); | ||
64 | } | ||
65 | |||
66 | template<> template<> | ||
67 | void v2math_object::test<2>() | ||
68 | { | ||
69 | F32 x = 123.356f, y = 2387.453f; | ||
70 | LLVector2 vec2,vec3; | ||
71 | vec2.setVec(x, y); | ||
72 | ensure("1:setVec: Fail ", (x == vec2.mV[VX]) && (y == vec2.mV[VY])); | ||
73 | |||
74 | vec3.setVec(vec2); | ||
75 | ensure("2:setVec: Fail " ,(vec2 == vec3)); | ||
76 | |||
77 | vec3.zeroVec(); | ||
78 | const F32 vec[2] = {3.24653f, 457653.4f}; | ||
79 | vec3.setVec(vec); | ||
80 | ensure("3:setVec: Fail ", (vec[0] == vec3.mV[VX]) && (vec[1] == vec3.mV[VY])); | ||
81 | } | ||
82 | |||
83 | template<> template<> | ||
84 | void v2math_object::test<3>() | ||
85 | { | ||
86 | F32 x = 2.2345f, y = 3.5678f ; | ||
87 | LLVector2 vec2(x,y); | ||
88 | ensure("magVecSquared:Fail ", is_approx_equal(vec2.magVecSquared(), (x*x + y*y))); | ||
89 | ensure("magVec:Fail ", is_approx_equal(vec2.magVec(), fsqrtf(x*x + y*y))); | ||
90 | } | ||
91 | |||
92 | template<> template<> | ||
93 | void v2math_object::test<4>() | ||
94 | { | ||
95 | F32 x =-2.0f, y = -3.0f ; | ||
96 | LLVector2 vec2(x,y); | ||
97 | ensure("abs():Fail ", TRUE == vec2.abs() && is_approx_equal(x, 2.f) && is_approx_equal(y, 3.f)); | ||
98 | |||
99 | ensure("isNull():Fail ", FALSE == vec2.isNull()); //Returns TRUE if vector has a _very_small_ length | ||
100 | |||
101 | x =.00000001f, y = .000001001f; | ||
102 | vec2.setVec(x, y); | ||
103 | ensure("isNull(): Fail ", TRUE == vec2.isNull()); | ||
104 | } | ||
105 | |||
106 | template<> template<> | ||
107 | void v2math_object::test<5>() | ||
108 | { | ||
109 | F32 x =1.f, y = 2.f; | ||
110 | LLVector2 vec2(x, y), vec3; | ||
111 | vec3 = vec3.scaleVec(vec2); | ||
112 | ensure("scaleVec: Fail ", vec3.mV[VX] == 0. && vec3.mV[VY] == 0.); | ||
113 | ensure("isExactlyZero(): Fail", TRUE == vec3.isExactlyZero()); | ||
114 | |||
115 | vec3.setVec(2.f, 1.f); | ||
116 | vec3 = vec3.scaleVec(vec2); | ||
117 | ensure("scaleVec: Fail ", (2.f == vec3.mV[VX]) && (2.f == vec3.mV[VY])); | ||
118 | ensure("isExactlyZero():Fail", FALSE == vec3.isExactlyZero()); | ||
119 | } | ||
120 | |||
121 | template<> template<> | ||
122 | void v2math_object::test<6>() | ||
123 | { | ||
124 | F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f; | ||
125 | F32 val1, val2; | ||
126 | LLVector2 vec2(x1, y1), vec3(x2, y2), vec4; | ||
127 | vec4 = vec2 + vec3 ; | ||
128 | val1 = x1+x2; | ||
129 | val2 = y1+y2; | ||
130 | ensure("1:operator+ failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY]))); | ||
131 | |||
132 | vec2.clearVec(); | ||
133 | vec3.clearVec(); | ||
134 | x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f; | ||
135 | vec2.setVec(x1, y1); | ||
136 | vec3.setVec(x2, y2); | ||
137 | vec4 = vec2 + vec3; | ||
138 | val1 = x1+x2; | ||
139 | val2 = y1+y2; | ||
140 | ensure("2:operator+ failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY]))); | ||
141 | } | ||
142 | |||
143 | template<> template<> | ||
144 | void v2math_object::test<7>() | ||
145 | { | ||
146 | F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f; | ||
147 | F32 val1, val2; | ||
148 | LLVector2 vec2(x1, y1), vec3(x2, y2), vec4; | ||
149 | vec4 = vec2 - vec3 ; | ||
150 | val1 = x1-x2; | ||
151 | val2 = y1-y2; | ||
152 | ensure("1:operator- failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY]))); | ||
153 | |||
154 | vec2.clearVec(); | ||
155 | vec3.clearVec(); | ||
156 | vec4.clearVec(); | ||
157 | x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f; | ||
158 | vec2.setVec(x1, y1); | ||
159 | vec3.setVec(x2, y2); | ||
160 | vec4 = vec2 - vec3; | ||
161 | val1 = x1-x2; | ||
162 | val2 = y1-y2; | ||
163 | ensure("2:operator- failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY]))); | ||
164 | } | ||
165 | |||
166 | template<> template<> | ||
167 | void v2math_object::test<8>() | ||
168 | { | ||
169 | F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f; | ||
170 | F32 val1, val2; | ||
171 | LLVector2 vec2(x1, y1), vec3(x2, y2); | ||
172 | val1 = vec2 * vec3; | ||
173 | val2 = x1*x2 + y1*y2; | ||
174 | ensure("1:operator* failed",(val1 == val2)); | ||
175 | |||
176 | vec3.clearVec(); | ||
177 | F32 mulVal = 4.332f; | ||
178 | vec3 = vec2 * mulVal; | ||
179 | val1 = x1*mulVal; | ||
180 | val2 = y1*mulVal; | ||
181 | ensure("2:operator* failed",(val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY])); | ||
182 | |||
183 | vec3.clearVec(); | ||
184 | vec3 = mulVal * vec2; | ||
185 | ensure("3:operator* failed",(val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY])); | ||
186 | } | ||
187 | |||
188 | template<> template<> | ||
189 | void v2math_object::test<9>() | ||
190 | { | ||
191 | F32 x1 =1.f, y1 = 2.f, div = 3.2f; | ||
192 | F32 val1, val2; | ||
193 | LLVector2 vec2(x1, y1), vec3; | ||
194 | vec3 = vec2 / div; | ||
195 | val1 = x1 / div; | ||
196 | val2 = y1 / div; | ||
197 | ensure("1:operator/ failed", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY])); | ||
198 | |||
199 | vec3.clearVec(); | ||
200 | x1 = -.235f, y1 = -24.32f, div = -2.2f; | ||
201 | vec2.setVec(x1, y1); | ||
202 | vec3 = vec2 / div; | ||
203 | val1 = x1 / div; | ||
204 | val2 = y1 / div; | ||
205 | ensure("2:operator/ failed", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY])); | ||
206 | } | ||
207 | |||
208 | template<> template<> | ||
209 | void v2math_object::test<10>() | ||
210 | { | ||
211 | F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f; | ||
212 | F32 val1, val2; | ||
213 | LLVector2 vec2(x1, y1), vec3(x2, y2), vec4; | ||
214 | vec4 = vec2 % vec3; | ||
215 | val1 = x1*y2 - x2*y1; | ||
216 | val2 = y1*x2 - y2*x1; | ||
217 | ensure("1:operator% failed",(val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY])); | ||
218 | |||
219 | vec2.clearVec(); | ||
220 | vec3.clearVec(); | ||
221 | vec4.clearVec(); | ||
222 | x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f; | ||
223 | vec2.setVec(x1, y1); | ||
224 | vec3.setVec(x2, y2); | ||
225 | vec4 = vec2 % vec3; | ||
226 | val1 = x1*y2 - x2*y1; | ||
227 | val2 = y1*x2 - y2*x1; | ||
228 | ensure("2:operator% failed",(val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY])); | ||
229 | } | ||
230 | template<> template<> | ||
231 | void v2math_object::test<11>() | ||
232 | { | ||
233 | F32 x1 =1.f, y1 = 2.f; | ||
234 | LLVector2 vec2(x1, y1), vec3(x1, y1); | ||
235 | ensure("1:operator== failed",(vec2 == vec3)); | ||
236 | |||
237 | vec2.clearVec(); | ||
238 | vec3.clearVec(); | ||
239 | x1 = -.235f, y1 = -24.32f; | ||
240 | vec2.setVec(x1, y1); | ||
241 | vec3.setVec(vec2); | ||
242 | ensure("2:operator== failed",(vec2 == vec3)); | ||
243 | } | ||
244 | |||
245 | template<> template<> | ||
246 | void v2math_object::test<12>() | ||
247 | { | ||
248 | F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f; | ||
249 | LLVector2 vec2(x1, y1), vec3(x2, y2); | ||
250 | ensure("1:operator!= failed",(vec2 != vec3)); | ||
251 | |||
252 | vec2.clearVec(); | ||
253 | vec3.clearVec(); | ||
254 | vec2.setVec(x1, y1); | ||
255 | vec3.setVec(vec2); | ||
256 | ensure("2:operator!= failed", (FALSE == (vec2 != vec3))); | ||
257 | } | ||
258 | template<> template<> | ||
259 | void v2math_object::test<13>() | ||
260 | { | ||
261 | F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f; | ||
262 | F32 val1, val2; | ||
263 | LLVector2 vec2(x1, y1), vec3(x2, y2); | ||
264 | vec2 +=vec3; | ||
265 | val1 = x1+x2; | ||
266 | val2 = y1+y2; | ||
267 | ensure("1:operator+= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
268 | |||
269 | vec2.setVec(x1, y1); | ||
270 | vec2 -=vec3; | ||
271 | val1 = x1-x2; | ||
272 | val2 = y1-y2; | ||
273 | ensure("2:operator-= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
274 | |||
275 | vec2.clearVec(); | ||
276 | vec3.clearVec(); | ||
277 | x1 = -21.000466f, y1 = 2.98382f,x2 = 0.332f, y2 = -01.23f; | ||
278 | vec2.setVec(x1, y1); | ||
279 | vec3.setVec(x2, y2); | ||
280 | vec2 +=vec3; | ||
281 | val1 = x1+x2; | ||
282 | val2 = y1+y2; | ||
283 | ensure("3:operator+= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
284 | |||
285 | vec2.setVec(x1, y1); | ||
286 | vec2 -=vec3; | ||
287 | val1 = x1-x2; | ||
288 | val2 = y1-y2; | ||
289 | ensure("4:operator-= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
290 | } | ||
291 | |||
292 | template<> template<> | ||
293 | void v2math_object::test<14>() | ||
294 | { | ||
295 | F32 x1 =1.f, y1 = 2.f; | ||
296 | F32 val1, val2, mulVal = 4.332f; | ||
297 | LLVector2 vec2(x1, y1); | ||
298 | vec2 /=mulVal; | ||
299 | val1 = x1 / mulVal; | ||
300 | val2 = y1 / mulVal; | ||
301 | ensure("1:operator/= failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY])); | ||
302 | |||
303 | vec2.clearVec(); | ||
304 | x1 = .213f, y1 = -2.34f, mulVal = -.23f; | ||
305 | vec2.setVec(x1, y1); | ||
306 | vec2 /=mulVal; | ||
307 | val1 = x1 / mulVal; | ||
308 | val2 = y1 / mulVal; | ||
309 | ensure("2:operator/= failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY])); | ||
310 | } | ||
311 | |||
312 | template<> template<> | ||
313 | void v2math_object::test<15>() | ||
314 | { | ||
315 | F32 x1 =1.f, y1 = 2.f; | ||
316 | F32 val1, val2, mulVal = 4.332f; | ||
317 | LLVector2 vec2(x1, y1); | ||
318 | vec2 *=mulVal; | ||
319 | val1 = x1*mulVal; | ||
320 | val2 = y1*mulVal; | ||
321 | ensure("1:operator*= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
322 | |||
323 | vec2.clearVec(); | ||
324 | x1 = .213f, y1 = -2.34f, mulVal = -.23f; | ||
325 | vec2.setVec(x1, y1); | ||
326 | vec2 *=mulVal; | ||
327 | val1 = x1*mulVal; | ||
328 | val2 = y1*mulVal; | ||
329 | ensure("2:operator*= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
330 | } | ||
331 | |||
332 | template<> template<> | ||
333 | void v2math_object::test<16>() | ||
334 | { | ||
335 | F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f; | ||
336 | F32 val1, val2; | ||
337 | LLVector2 vec2(x1, y1), vec3(x2, y2); | ||
338 | vec2 %= vec3; | ||
339 | val1 = x1*y2 - x2*y1; | ||
340 | val2 = y1*x2 - y2*x1; | ||
341 | ensure("1:operator%= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY])); | ||
342 | } | ||
343 | |||
344 | template<> template<> | ||
345 | void v2math_object::test<17>() | ||
346 | { | ||
347 | F32 x1 =1.f, y1 = 2.f; | ||
348 | LLVector2 vec2(x1, y1),vec3; | ||
349 | vec3 = -vec2; | ||
350 | ensure("1:operator- failed",(-vec3 == vec2)); | ||
351 | } | ||
352 | |||
353 | template<> template<> | ||
354 | void v2math_object::test<18>() | ||
355 | { | ||
356 | F32 x1 =1.f, y1 = 2.f; | ||
357 | std::ostringstream stream1, stream2; | ||
358 | LLVector2 vec2(x1, y1),vec3; | ||
359 | stream1 << vec2; | ||
360 | vec3.setVec(x1, y1); | ||
361 | stream2 << vec3; | ||
362 | ensure("1:operator << failed",(stream1.str() == stream2.str())); | ||
363 | } | ||
364 | |||
365 | template<> template<> | ||
366 | void v2math_object::test<19>() | ||
367 | { | ||
368 | F32 x1 =1.0f, y1 = 2.0f, x2 = -.32f, y2 = .2234f; | ||
369 | LLVector2 vec2(x1, y1),vec3(x2, y2); | ||
370 | ensure("1:operator < failed",(vec3 < vec2)); | ||
371 | |||
372 | x1 = 1.0f, y1 = 2.0f, x2 = 1.0f, y2 = 3.2234f; | ||
373 | vec2.setVec(x1, y1); | ||
374 | vec3.setVec(x2, y2); | ||
375 | ensure("2:operator < failed", (FALSE == vec3 < vec2)); | ||
376 | } | ||
377 | |||
378 | template<> template<> | ||
379 | void v2math_object::test<20>() | ||
380 | { | ||
381 | F32 x1 =1.0f, y1 = 2.0f; | ||
382 | LLVector2 vec2(x1, y1); | ||
383 | ensure("1:operator [] failed",( x1 == vec2[0])); | ||
384 | ensure("2:operator [] failed",( y1 == vec2[1])); | ||
385 | |||
386 | vec2.clearVec(); | ||
387 | x1 = 23.0f, y1 = -.2361f; | ||
388 | vec2.setVec(x1, y1); | ||
389 | F32 ref1 = vec2[0]; | ||
390 | ensure("3:operator [] failed", ( ref1 == x1)); | ||
391 | F32 ref2 = vec2[1]; | ||
392 | ensure("4:operator [] failed", ( ref2 == y1)); | ||
393 | } | ||
394 | |||
395 | template<> template<> | ||
396 | void v2math_object::test<21>() | ||
397 | { | ||
398 | F32 x1 =1.f, y1 = 2.f, x2 = -.32f, y2 = .2234f; | ||
399 | F32 val1, val2; | ||
400 | LLVector2 vec2(x1, y1),vec3(x2, y2); | ||
401 | val1 = dist_vec_squared2D(vec2, vec3); | ||
402 | val2 = (x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2); | ||
403 | ensure_equals("dist_vec_squared2D values are not equal",val2, val1); | ||
404 | |||
405 | val1 = dist_vec_squared(vec2, vec3); | ||
406 | ensure_equals("dist_vec_squared values are not equal",val2, val1); | ||
407 | |||
408 | val1 = dist_vec(vec2, vec3); | ||
409 | val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2)); | ||
410 | ensure_equals("dist_vec values are not equal",val2, val1); | ||
411 | } | ||
412 | |||
413 | template<> template<> | ||
414 | void v2math_object::test<22>() | ||
415 | { | ||
416 | F32 x1 =1.f, y1 = 2.f, x2 = -.32f, y2 = .2234f,fVal = .0121f; | ||
417 | F32 val1, val2; | ||
418 | LLVector2 vec2(x1, y1),vec3(x2, y2); | ||
419 | LLVector2 vec4 = lerp(vec2, vec3, fVal); | ||
420 | val1 = x1 + (x2 - x1) * fVal; | ||
421 | val2 = y1 + (y2 - y1) * fVal; | ||
422 | ensure("lerp values are not equal", ((val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY]))); | ||
423 | } | ||
424 | |||
425 | template<> template<> | ||
426 | void v2math_object::test<23>() | ||
427 | { | ||
428 | F32 x1 =1.f, y1 = 2.f; | ||
429 | F32 val1, val2; | ||
430 | LLVector2 vec2(x1, y1); | ||
431 | |||
432 | F32 vecMag = vec2.normVec(); | ||
433 | F32 mag = fsqrtf(x1*x1 + y1*y1); | ||
434 | |||
435 | F32 oomag = 1.f / mag; | ||
436 | val1 = x1 * oomag; | ||
437 | val2 = y1 * oomag; | ||
438 | |||
439 | ensure("normVec failed", val1 == vec2.mV[VX] && val2 == vec2.mV[VY] && vecMag == mag); | ||
440 | |||
441 | x1 =.00000001f, y1 = 0.f; | ||
442 | |||
443 | vec2.setVec(x1, y1); | ||
444 | vecMag = vec2.normVec(); | ||
445 | ensure("normVec failed should be 0.", 0. == vec2.mV[VX] && 0. == vec2.mV[VY] && vecMag == 0.); | ||
446 | } | ||
447 | } | ||
diff --git a/linden/indra/test/v3dmath_tut.cpp b/linden/indra/test/v3dmath_tut.cpp new file mode 100644 index 0000000..88ade71 --- /dev/null +++ b/linden/indra/test/v3dmath_tut.cpp | |||
@@ -0,0 +1,402 @@ | |||
1 | /** | ||
2 | * @file v3dmath_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief v3dmath test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "llquaternion.h" | ||
34 | #include "m3math.h" | ||
35 | #include "v4math.h" | ||
36 | #include "llsd.h" | ||
37 | #include "v3dmath.h" | ||
38 | #include "v3dmath.h" | ||
39 | |||
40 | namespace tut | ||
41 | { | ||
42 | struct v3dmath_data | ||
43 | { | ||
44 | }; | ||
45 | typedef test_group<v3dmath_data> v3dmath_test; | ||
46 | typedef v3dmath_test::object v3dmath_object; | ||
47 | tut::v3dmath_test v3dmath_testcase("v3dmath"); | ||
48 | |||
49 | template<> template<> | ||
50 | void v3dmath_object::test<1>() | ||
51 | { | ||
52 | LLVector3d vec3D; | ||
53 | ensure("1:LLVector3d:Fail to initialize ", ((0 == vec3D.mdV[VX]) && (0 == vec3D.mdV[VY]) && (0 == vec3D.mdV[VZ]))); | ||
54 | F64 x = 2.32f, y = 1.212f, z = -.12f; | ||
55 | LLVector3d vec3Da(x,y,z); | ||
56 | ensure("2:LLVector3d:Fail to initialize ", ((2.32f == vec3Da.mdV[VX]) && (1.212f == vec3Da.mdV[VY]) && (-.12f == vec3Da.mdV[VZ]))); | ||
57 | const F64 vec[3] = {1.2f ,3.2f, -4.2f}; | ||
58 | LLVector3d vec3Db(vec); | ||
59 | ensure("3:LLVector3d:Fail to initialize ", ((1.2f == vec3Db.mdV[VX]) && (3.2f == vec3Db.mdV[VY]) && (-4.2f == vec3Db.mdV[VZ]))); | ||
60 | LLVector3 vec3((F32)x,(F32)y,(F32)z); | ||
61 | LLVector3d vec3Dc(vec3); | ||
62 | ensure_equals("4:LLVector3d Fail to initialize",vec3Da,vec3Dc); | ||
63 | } | ||
64 | |||
65 | template<> template<> | ||
66 | void v3dmath_object::test<2>() | ||
67 | { | ||
68 | S32 a = -235; | ||
69 | LLSD llsd(a); | ||
70 | LLVector3d vec3d(llsd); | ||
71 | LLSD sd = vec3d.getValue(); | ||
72 | LLVector3d vec3da(sd); | ||
73 | ensure("1:getValue:Fail ", (vec3d == vec3da)); | ||
74 | } | ||
75 | |||
76 | template<> template<> | ||
77 | void v3dmath_object::test<3>() | ||
78 | { | ||
79 | F64 a = 232345521.411132; | ||
80 | LLSD llsd(a); | ||
81 | LLVector3d vec3d; | ||
82 | vec3d.setValue(llsd); | ||
83 | LLSD sd = vec3d.getValue(); | ||
84 | LLVector3d vec3da(sd); | ||
85 | ensure("1:setValue:Fail to initialize ", (vec3d == vec3da)); | ||
86 | } | ||
87 | |||
88 | template<> template<> | ||
89 | void v3dmath_object::test<4>() | ||
90 | { | ||
91 | F64 a[3] = {222231.43222, 12345.2343, -434343.33222}; | ||
92 | LLSD llsd; | ||
93 | llsd[0] = a[0]; | ||
94 | llsd[1] = a[1]; | ||
95 | llsd[2] = a[2]; | ||
96 | LLVector3d vec3D; | ||
97 | vec3D = llsd; | ||
98 | ensure("1:operator=:Fail to initialize ", ((llsd[0].asReal()== vec3D.mdV[VX]) && (llsd[1].asReal() == vec3D.mdV[VY]) && (llsd[2].asReal() == vec3D.mdV[VZ]))); | ||
99 | } | ||
100 | |||
101 | template<> template<> | ||
102 | void v3dmath_object::test<5>() | ||
103 | { | ||
104 | F64 x = 2.32f, y = 1.212f, z = -.12f; | ||
105 | LLVector3d vec3D(x,y,z); | ||
106 | vec3D.clearVec(); | ||
107 | ensure("1:clearVec:Fail to initialize ", ((0 == vec3D.mdV[VX]) && (0 == vec3D.mdV[VY]) && (0 == vec3D.mdV[VZ]))); | ||
108 | vec3D.setVec(x,y,z); | ||
109 | ensure("2:setVec:Fail to initialize ", ((x == vec3D.mdV[VX]) && (y == vec3D.mdV[VY]) && (z == vec3D.mdV[VZ]))); | ||
110 | vec3D.zeroVec(); | ||
111 | ensure("3:zeroVec:Fail to initialize ", ((0 == vec3D.mdV[VX]) && (0 == vec3D.mdV[VY]) && (0 == vec3D.mdV[VZ]))); | ||
112 | vec3D.clearVec(); | ||
113 | LLVector3 vec3((F32)x,(F32)y,(F32)z); | ||
114 | vec3D.setVec(vec3); | ||
115 | ensure("4:setVec:Fail to initialize ", ((x == vec3D.mdV[VX]) && (y == vec3D.mdV[VY]) && (z == vec3D.mdV[VZ]))); | ||
116 | vec3D.clearVec(); | ||
117 | const F64 vec[3] = {x,y,z}; | ||
118 | vec3D.setVec(vec); | ||
119 | ensure("5:setVec:Fail to initialize ", ((x == vec3D.mdV[VX]) && (y == vec3D.mdV[VY]) && (z == vec3D.mdV[VZ]))); | ||
120 | LLVector3d vec3Da; | ||
121 | vec3Da.setVec(vec3D); | ||
122 | ensure_equals("6:setVec: Fail to initialize", vec3D, vec3Da); | ||
123 | } | ||
124 | |||
125 | template<> template<> | ||
126 | void v3dmath_object::test<6>() | ||
127 | { | ||
128 | F64 x = -2.32, y = 1.212, z = -.12; | ||
129 | LLVector3d vec3D(x,y,z); | ||
130 | vec3D.abs(); | ||
131 | ensure("1:abs:Fail ", ((-x == vec3D.mdV[VX]) && (y == vec3D.mdV[VY]) && (-z == vec3D.mdV[VZ]))); | ||
132 | ensure("2:isNull():Fail ", (FALSE == vec3D.isNull())); | ||
133 | vec3D.clearVec(); | ||
134 | x =.00000001, y = .000001001, z = .000001001; | ||
135 | vec3D.setVec(x,y,z); | ||
136 | ensure("3:isNull():Fail ", (TRUE == vec3D.isNull())); | ||
137 | ensure("4:isExactlyZero():Fail ", (FALSE == vec3D.isExactlyZero())); | ||
138 | x =.0000000, y = .00000000, z = .00000000; | ||
139 | vec3D.setVec(x,y,z); | ||
140 | ensure("5:isExactlyZero():Fail ", (TRUE == vec3D.isExactlyZero())); | ||
141 | } | ||
142 | |||
143 | template<> template<> | ||
144 | void v3dmath_object::test<7>() | ||
145 | { | ||
146 | F64 x = -2.32, y = 1.212, z = -.12; | ||
147 | LLVector3d vec3D(x,y,z); | ||
148 | |||
149 | ensure("1:operator [] failed",( x == vec3D[0])); | ||
150 | ensure("2:operator [] failed",( y == vec3D[1])); | ||
151 | ensure("3:operator [] failed",( z == vec3D[2])); | ||
152 | vec3D.clearVec(); | ||
153 | x = 23.23, y = -.2361, z = 3.25; | ||
154 | vec3D.setVec(x,y,z); | ||
155 | F64 &ref1 = vec3D[0]; | ||
156 | ensure("4:operator [] failed",( ref1 == vec3D[0])); | ||
157 | F64 &ref2 = vec3D[1]; | ||
158 | ensure("5:operator [] failed",( ref2 == vec3D[1])); | ||
159 | F64 &ref3 = vec3D[2]; | ||
160 | ensure("6:operator [] failed",( ref3 == vec3D[2])); | ||
161 | } | ||
162 | |||
163 | template<> template<> | ||
164 | void v3dmath_object::test<8>() | ||
165 | { | ||
166 | F32 x = 1.f, y = 2.f, z = -1.f; | ||
167 | LLVector4 vec4(x,y,z); | ||
168 | LLVector3d vec3D; | ||
169 | vec3D = vec4; | ||
170 | ensure("1:operator=:Fail to initialize ", ((vec4.mV[VX] == vec3D.mdV[VX]) && (vec4.mV[VY] == vec3D.mdV[VY]) && (vec4.mV[VZ] == vec3D.mdV[VZ]))); | ||
171 | } | ||
172 | |||
173 | template<> template<> | ||
174 | void v3dmath_object::test<9>() | ||
175 | { | ||
176 | F64 x1 = 1.78787878, y1 = 232322.2121, z1 = -12121.121212; | ||
177 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | ||
178 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2),vec3Db; | ||
179 | vec3Db = vec3Da+ vec3D; | ||
180 | ensure("1:operator+:Fail to initialize ", ((x1+x2 == vec3Db.mdV[VX]) && (y1+y2 == vec3Db.mdV[VY]) && (z1+z2 == vec3Db.mdV[VZ]))); | ||
181 | x1 = -2.45, y1 = 2.1, z1 = 3.0; | ||
182 | vec3D.clearVec(); | ||
183 | vec3Da.clearVec(); | ||
184 | vec3D.setVec(x1,y1,z1); | ||
185 | vec3Da += vec3D; | ||
186 | ensure_equals("2:operator+=: Fail to initialize", vec3Da,vec3D); | ||
187 | vec3Da += vec3D; | ||
188 | ensure("3:operator+=:Fail to initialize ", ((2*x1 == vec3Da.mdV[VX]) && (2*y1 == vec3Da.mdV[VY]) && (2*z1 == vec3Da.mdV[VZ]))); | ||
189 | } | ||
190 | |||
191 | template<> template<> | ||
192 | void v3dmath_object::test<10>() | ||
193 | { | ||
194 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
195 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | ||
196 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2),vec3Db; | ||
197 | vec3Db = vec3Da - vec3D; | ||
198 | ensure("1:operator-:Fail to initialize ", ((x2-x1 == vec3Db.mdV[VX]) && (y2-y1 == vec3Db.mdV[VY]) && (z2-z1 == vec3Db.mdV[VZ]))); | ||
199 | x1 = -2.45, y1 = 2.1, z1 = 3.0; | ||
200 | vec3D.clearVec(); | ||
201 | vec3Da.clearVec(); | ||
202 | vec3D.setVec(x1,y1,z1); | ||
203 | vec3Da -=vec3D; | ||
204 | ensure("2:operator-=:Fail to initialize ", ((2.45 == vec3Da.mdV[VX]) && (-2.1 == vec3Da.mdV[VY]) && (-3.0 == vec3Da.mdV[VZ]))); | ||
205 | vec3Da -= vec3D; | ||
206 | ensure("3:operator-=:Fail to initialize ", ((-2*x1 == vec3Da.mdV[VX]) && (-2*y1 == vec3Da.mdV[VY]) && (-2*z1 == vec3Da.mdV[VZ]))); | ||
207 | } | ||
208 | template<> template<> | ||
209 | void v3dmath_object::test<11>() | ||
210 | { | ||
211 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
212 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | ||
213 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2); | ||
214 | F64 res = vec3D * vec3Da; | ||
215 | ensure("1:operator* failed",(res == (x1*x2 + y1*y2 + z1*z2))); | ||
216 | vec3Da.clearVec(); | ||
217 | F64 mulVal = 4.2; | ||
218 | vec3Da = vec3D * mulVal; | ||
219 | ensure("2:operator* failed",(x1*mulVal == vec3Da.mdV[VX]) && (y1*mulVal == vec3Da.mdV[VY])&& (z1*mulVal == vec3Da.mdV[VZ])); | ||
220 | vec3Da.clearVec(); | ||
221 | vec3Da = mulVal * vec3D; | ||
222 | ensure("3:operator* failed",(x1*mulVal == vec3Da.mdV[VX]) && (y1*mulVal == vec3Da.mdV[VY])&& (z1*mulVal == vec3Da.mdV[VZ])); | ||
223 | vec3D *= mulVal; | ||
224 | ensure("4:operator*= failed",(x1*mulVal == vec3D.mdV[VX]) && (y1*mulVal == vec3D.mdV[VY])&& (z1*mulVal == vec3D.mdV[VZ])); | ||
225 | } | ||
226 | |||
227 | template<> template<> | ||
228 | void v3dmath_object::test<12>() | ||
229 | { | ||
230 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
231 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | ||
232 | F64 val1, val2, val3; | ||
233 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2), vec3Db; | ||
234 | vec3Db = vec3D % vec3Da; | ||
235 | val1 = y1*z2 - y2*z1; | ||
236 | val2 = z1*x2 -z2*x1; | ||
237 | val3 = x1*y2-x2*y1; | ||
238 | ensure("1:operator% failed",(val1 == vec3Db.mdV[VX]) && (val2 == vec3Db.mdV[VY]) && (val3 == vec3Db.mdV[VZ])); | ||
239 | vec3D %= vec3Da; | ||
240 | ensure_equals("2:operator%= failed",vec3D,vec3Db); | ||
241 | } | ||
242 | |||
243 | template<> template<> | ||
244 | void v3dmath_object::test<13>() | ||
245 | { | ||
246 | F64 x1 = 1., y1 = 2., z1 = -1.1,div = 4.2; | ||
247 | F64 t = 1.f / div; | ||
248 | LLVector3d vec3D(x1,y1,z1), vec3Da; | ||
249 | vec3Da = vec3D/div; | ||
250 | ensure("1:operator/ failed",(x1*t == vec3Da.mdV[VX]) && (y1*t == vec3Da.mdV[VY])&& (z1*t == vec3Da.mdV[VZ])); | ||
251 | x1 = 1.23, y1 = 4., z1 = -2.32; | ||
252 | vec3D.clearVec(); | ||
253 | vec3Da.clearVec(); | ||
254 | vec3D.setVec(x1,y1,z1); | ||
255 | vec3Da = vec3D/div; | ||
256 | ensure("2:operator/ failed",(x1*t == vec3Da.mdV[VX]) && (y1*t == vec3Da.mdV[VY])&& (z1*t == vec3Da.mdV[VZ])); | ||
257 | vec3D /= div; | ||
258 | ensure("3:operator/= failed",(x1*t == vec3D.mdV[VX]) && (y1*t == vec3D.mdV[VY])&& (z1*t == vec3D.mdV[VZ])); | ||
259 | } | ||
260 | |||
261 | template<> template<> | ||
262 | void v3dmath_object::test<14>() | ||
263 | { | ||
264 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
265 | LLVector3d vec3D(x1,y1,z1), vec3Da; | ||
266 | ensure("1:operator!= failed",(TRUE == (vec3D !=vec3Da))); | ||
267 | vec3Da = vec3D; | ||
268 | ensure("2:operator== failed",(vec3D ==vec3Da)); | ||
269 | vec3D.clearVec(); | ||
270 | vec3Da.clearVec(); | ||
271 | x1 = .211, y1 = 21.111, z1 = 23.22; | ||
272 | vec3D.setVec(x1,y1,z1); | ||
273 | vec3Da.setVec(x1,y1,z1); | ||
274 | ensure("3:operator== failed",(vec3D ==vec3Da)); | ||
275 | ensure("4:operator!= failed",(FALSE == (vec3D !=vec3Da))); | ||
276 | } | ||
277 | |||
278 | template<> template<> | ||
279 | void v3dmath_object::test<15>() | ||
280 | { | ||
281 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
282 | LLVector3d vec3D(x1,y1,z1), vec3Da; | ||
283 | std::ostringstream stream1, stream2; | ||
284 | stream1 << vec3D; | ||
285 | vec3Da.setVec(x1,y1,z1); | ||
286 | stream2 << vec3Da; | ||
287 | ensure("1:operator << failed",(stream1.str() == stream2.str())); | ||
288 | } | ||
289 | |||
290 | template<> template<> | ||
291 | void v3dmath_object::test<16>() | ||
292 | { | ||
293 | F64 x1 = 1.23, y1 = 2.0, z1 = 4.; | ||
294 | char buf[] = "1.23 2. 4"; | ||
295 | LLVector3d vec3D, vec3Da(x1,y1,z1); | ||
296 | LLVector3d::parseVector3d(buf, &vec3D); | ||
297 | ensure_equals("1:parseVector3d: failed " , vec3D, vec3Da); | ||
298 | } | ||
299 | |||
300 | template<> template<> | ||
301 | void v3dmath_object::test<17>() | ||
302 | { | ||
303 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
304 | LLVector3d vec3D(x1,y1,z1), vec3Da; | ||
305 | vec3Da = -vec3D; | ||
306 | ensure("1:operator- failed", (vec3D == - vec3Da)); | ||
307 | } | ||
308 | |||
309 | template<> template<> | ||
310 | void v3dmath_object::test<18>() | ||
311 | { | ||
312 | F64 x = 1., y = 2., z = -1.1; | ||
313 | LLVector3d vec3D(x,y,z); | ||
314 | F64 res = (x*x + y*y + z*z) - vec3D.magVecSquared(); | ||
315 | ensure("1:magVecSquared:Fail ", ((-F_APPROXIMATELY_ZERO <= res)&& (res <=F_APPROXIMATELY_ZERO))); | ||
316 | res = fsqrtf(x*x + y*y + z*z) - vec3D.magVec(); | ||
317 | ensure("2:magVec: Fail ", ((-F_APPROXIMATELY_ZERO <= res)&& (res <=F_APPROXIMATELY_ZERO))); | ||
318 | } | ||
319 | |||
320 | template<> template<> | ||
321 | void v3dmath_object::test<19>() | ||
322 | { | ||
323 | F64 x = 1., y = 2., z = -1.1; | ||
324 | LLVector3d vec3D(x,y,z); | ||
325 | F64 mag = vec3D.normVec(); | ||
326 | mag = 1.f/ mag; | ||
327 | ensure("1:normVec: Fail ", (x* mag == vec3D.mdV[VX]) && (y* mag == vec3D.mdV[VY])&& (z* mag == vec3D.mdV[VZ])); | ||
328 | x = 0.000000001, y = 0.000000001, z = 0.000000001; | ||
329 | vec3D.clearVec(); | ||
330 | vec3D.setVec(x,y,z); | ||
331 | mag = vec3D.normVec(); | ||
332 | ensure("2:normVec: Fail ", (x* mag == vec3D.mdV[VX]) && (y* mag == vec3D.mdV[VY])&& (z* mag == vec3D.mdV[VZ])); | ||
333 | } | ||
334 | |||
335 | template<> template<> | ||
336 | void v3dmath_object::test<20>() | ||
337 | { | ||
338 | F64 x1 = 1111.232222, y1 = 2222222222.22, z1 = 422222222222; | ||
339 | char buf[] = "1111.232222 2222222222.22 422222222222"; | ||
340 | LLVector3d vec3Da, vec3Db(x1,y1,z1); | ||
341 | LLVector3d::parseVector3d(buf, &vec3Da); | ||
342 | ensure_equals("1:parseVector3 failed", vec3Da, vec3Db); | ||
343 | } | ||
344 | |||
345 | template<> template<> | ||
346 | void v3dmath_object::test<21>() | ||
347 | { | ||
348 | F64 x1 = 1., y1 = 2., z1 = -1.1; | ||
349 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | ||
350 | F64 val = 2.3f,val1,val2,val3; | ||
351 | val1 = x1 + (x2 - x1)* val; | ||
352 | val2 = y1 + (y2 - y1)* val; | ||
353 | val3 = z1 + (z2 - z1)* val; | ||
354 | LLVector3d vec3Da(x1,y1,z1),vec3Db(x2,y2,z2); | ||
355 | LLVector3d vec3d = lerp(vec3Da,vec3Db,val); | ||
356 | ensure("1:lerp failed", ((val1 ==vec3d.mdV[VX])&& (val2 ==vec3d.mdV[VY]) && (val3 ==vec3d.mdV[VZ]))); | ||
357 | } | ||
358 | |||
359 | template<> template<> | ||
360 | void v3dmath_object::test<22>() | ||
361 | { | ||
362 | F64 x = 2.32, y = 1.212, z = -.12; | ||
363 | F64 min = 0.0001, max = 3.0; | ||
364 | LLVector3d vec3d(x,y,z); | ||
365 | ensure("1:clamp:Fail ", (TRUE == (vec3d.clamp(min, max)))); | ||
366 | x = 0.000001f, z = 5.3f; | ||
367 | vec3d.setVec(x,y,z); | ||
368 | ensure("2:clamp:Fail ", (TRUE == (vec3d.clamp(min, max)))); | ||
369 | } | ||
370 | |||
371 | template<> template<> | ||
372 | void v3dmath_object::test<23>() | ||
373 | { | ||
374 | F64 x = 10., y = 20., z = -15.; | ||
375 | F64 epsilon = .23425; | ||
376 | LLVector3d vec3Da(x,y,z), vec3Db(x,y,z); | ||
377 | ensure("1:are_parallel: Fail ", (TRUE == are_parallel(vec3Da,vec3Db,epsilon))); | ||
378 | F64 x1 = -12., y1 = -20., z1 = -100.; | ||
379 | vec3Db.clearVec(); | ||
380 | vec3Db.setVec(x1,y1,z1); | ||
381 | ensure("2:are_parallel: Fail ", (FALSE == are_parallel(vec3Da,vec3Db,epsilon))); | ||
382 | } | ||
383 | |||
384 | template<> template<> | ||
385 | void v3dmath_object::test<24>() | ||
386 | { | ||
387 | F64 x = 10., y = 20., z = -15.; | ||
388 | F64 angle1, angle2; | ||
389 | LLVector3d vec3Da(x,y,z), vec3Db(x,y,z); | ||
390 | angle1 = angle_between(vec3Da, vec3Db); | ||
391 | ensure("1:angle_between: Fail ", (0 == angle1)); | ||
392 | F64 x1 = -1., y1 = -20., z1 = -1.; | ||
393 | vec3Da.clearVec(); | ||
394 | vec3Da.setVec(x1,y1,z1); | ||
395 | angle2 = angle_between(vec3Da, vec3Db); | ||
396 | vec3Db.normVec(); | ||
397 | vec3Da.normVec(); | ||
398 | F64 angle = vec3Db*vec3Da; | ||
399 | angle = acos(angle); | ||
400 | ensure("2:angle_between: Fail ", (angle == angle2)); | ||
401 | } | ||
402 | } \ No newline at end of file | ||
diff --git a/linden/indra/test/v3math_tut.cpp b/linden/indra/test/v3math_tut.cpp new file mode 100644 index 0000000..36eaca9 --- /dev/null +++ b/linden/indra/test/v3math_tut.cpp | |||
@@ -0,0 +1,568 @@ | |||
1 | /** | ||
2 | * @file v3math_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date February 2007 | ||
5 | * @brief v3math test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | #include "llquaternion.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llquantize.h" | ||
35 | #include "v3dmath.h" | ||
36 | #include "m3math.h" | ||
37 | #include "v4math.h" | ||
38 | #include "llsd.h" | ||
39 | #include "v3math.h" | ||
40 | |||
41 | |||
42 | namespace tut | ||
43 | { | ||
44 | struct v3math_data | ||
45 | { | ||
46 | }; | ||
47 | typedef test_group<v3math_data> v3math_test; | ||
48 | typedef v3math_test::object v3math_object; | ||
49 | tut::v3math_test v3math_testcase("v3math"); | ||
50 | |||
51 | template<> template<> | ||
52 | void v3math_object::test<1>() | ||
53 | { | ||
54 | LLVector3 vec3; | ||
55 | ensure("1:LLVector3:Fail to initialize ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ]))); | ||
56 | F32 x = 2.32f, y = 1.212f, z = -.12f; | ||
57 | LLVector3 vec3a(x,y,z); | ||
58 | ensure("2:LLVector3:Fail to initialize ", ((2.32f == vec3a.mV[VX]) && (1.212f == vec3a.mV[VY]) && (-.12f == vec3a.mV[VZ]))); | ||
59 | const F32 vec[3] = {1.2f ,3.2f, -4.2f}; | ||
60 | LLVector3 vec3b(vec); | ||
61 | ensure("3:LLVector3:Fail to initialize ", ((1.2f == vec3b.mV[VX]) && (3.2f == vec3b.mV[VY]) && (-4.2f == vec3b.mV[VZ]))); | ||
62 | } | ||
63 | |||
64 | template<> template<> | ||
65 | void v3math_object::test<2>() | ||
66 | { | ||
67 | F32 x = 2.32f, y = 1.212f, z = -.12f; | ||
68 | LLVector3 vec3(x,y,z); | ||
69 | LLVector3d vector3d(vec3); | ||
70 | LLVector3 vec3a(vector3d); | ||
71 | ensure("1:LLVector3:Fail to initialize ", vec3 == vec3a); | ||
72 | LLVector4 vector4(vec3); | ||
73 | LLVector3 vec3b(vector4); | ||
74 | ensure("2:LLVector3:Fail to initialize ", vec3 == vec3b); | ||
75 | } | ||
76 | |||
77 | template<> template<> | ||
78 | void v3math_object::test<3>() | ||
79 | { | ||
80 | S32 a = 231; | ||
81 | LLSD llsd(a); | ||
82 | LLVector3 vec3(llsd); | ||
83 | LLSD sd = vec3.getValue(); | ||
84 | LLVector3 vec3a(sd); | ||
85 | ensure("1:LLVector3:Fail to initialize ", (vec3 == vec3a)); | ||
86 | } | ||
87 | |||
88 | template<> template<> | ||
89 | void v3math_object::test<4>() | ||
90 | { | ||
91 | S32 a = 231; | ||
92 | LLSD llsd(a); | ||
93 | LLVector3 vec3(llsd),vec3a; | ||
94 | vec3a = vec3; | ||
95 | ensure("1:Operator= Fail to initialize " ,(vec3 == vec3a)); | ||
96 | } | ||
97 | |||
98 | template<> template<> | ||
99 | void v3math_object::test<5>() | ||
100 | { | ||
101 | F32 x = 2.32f, y = 1.212f, z = -.12f; | ||
102 | LLVector3 vec3(x,y,z); | ||
103 | ensure("1:isFinite= Fail to initialize ", (TRUE == vec3.isFinite()));//need more test cases: | ||
104 | vec3.clearVec(); | ||
105 | ensure("2:clearVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ]))); | ||
106 | vec3.setVec(x,y,z); | ||
107 | ensure("3:setVec:Fail to set values ", ((2.32f == vec3.mV[VX]) && (1.212f == vec3.mV[VY]) && (-.12f == vec3.mV[VZ]))); | ||
108 | vec3.zeroVec(); | ||
109 | ensure("4:zeroVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ]))); | ||
110 | } | ||
111 | |||
112 | template<> template<> | ||
113 | void v3math_object::test<6>() | ||
114 | { | ||
115 | F32 x = 2.32f, y = 1.212f, z = -.12f; | ||
116 | LLVector3 vec3(x,y,z),vec3a; | ||
117 | vec3.abs(); | ||
118 | ensure("1:abs:Fail ", ((x == vec3.mV[VX]) && (y == vec3.mV[VY]) && (-z == vec3.mV[VZ]))); | ||
119 | vec3a.setVec(vec3); | ||
120 | ensure("2:setVec:Fail to initialize ", (vec3a == vec3)); | ||
121 | const F32 vec[3] = {1.2f ,3.2f, -4.2f}; | ||
122 | vec3.clearVec(); | ||
123 | vec3.setVec(vec); | ||
124 | ensure("3:setVec:Fail to initialize ", ((1.2f == vec3.mV[VX]) && (3.2f == vec3.mV[VY]) && (-4.2f == vec3.mV[VZ]))); | ||
125 | vec3a.clearVec(); | ||
126 | LLVector3d vector3d(vec3); | ||
127 | vec3a.setVec(vector3d); | ||
128 | ensure("4:setVec:Fail to initialize ", (vec3 == vec3a)); | ||
129 | LLVector4 vector4(vec3); | ||
130 | vec3a.clearVec(); | ||
131 | vec3a.setVec(vector4); | ||
132 | ensure("5:setVec:Fail to initialize ", (vec3 == vec3a)); | ||
133 | } | ||
134 | |||
135 | template<> template<> | ||
136 | void v3math_object::test<7>() | ||
137 | { | ||
138 | F32 x = 2.32f, y = 3.212f, z = -.12f; | ||
139 | F32 min = 0.0001f, max = 3.0f; | ||
140 | LLVector3 vec3(x,y,z); | ||
141 | ensure("1:clamp:Fail ", TRUE == vec3.clamp(min, max) && x == vec3.mV[VX] && max == vec3.mV[VY] && min == vec3.mV[VZ]); | ||
142 | x = 1.f, y = 2.2f, z = 2.8f; | ||
143 | vec3.setVec(x,y,z); | ||
144 | ensure("2:clamp:Fail ", FALSE == vec3.clamp(min, max)); | ||
145 | } | ||
146 | |||
147 | template<> template<> | ||
148 | void v3math_object::test<8>() | ||
149 | { | ||
150 | F32 x = 2.32f, y = 1.212f, z = -.12f; | ||
151 | LLVector3 vec3(x,y,z); | ||
152 | ensure("1:magVecSquared:Fail ", is_approx_equal(vec3.magVecSquared(), (x*x + y*y + z*z))); | ||
153 | ensure("2:magVec:Fail ", is_approx_equal(vec3.magVec(), fsqrtf(x*x + y*y + z*z))); | ||
154 | } | ||
155 | |||
156 | template<> template<> | ||
157 | void v3math_object::test<9>() | ||
158 | { | ||
159 | F32 x =-2.0f, y = -3.0f, z = 1.23f ; | ||
160 | LLVector3 vec3(x,y,z); | ||
161 | ensure("1:abs():Fail ", (TRUE == vec3.abs())); | ||
162 | ensure("2:isNull():Fail", (FALSE == vec3.isNull())); //Returns TRUE if vector has a _very_small_ length | ||
163 | x =.00000001f, y = .000001001f, z = .000001001f; | ||
164 | vec3.setVec(x,y,z); | ||
165 | ensure("3:isNull(): Fail ", (TRUE == vec3.isNull())); | ||
166 | } | ||
167 | |||
168 | template<> template<> | ||
169 | void v3math_object::test<10>() | ||
170 | { | ||
171 | F32 x =-2.0f, y = -3.0f, z = 1.f ; | ||
172 | LLVector3 vec3(x,y,z),vec3a; | ||
173 | ensure("1:isExactlyZero():Fail ", (TRUE == vec3a.isExactlyZero())); | ||
174 | vec3a = vec3a.scaleVec(vec3); | ||
175 | ensure("2:scaleVec: Fail ", vec3a.mV[VX] == 0.f && vec3a.mV[VY] == 0.f && vec3a.mV[VZ] == 0.f); | ||
176 | vec3a.setVec(x,y,z); | ||
177 | vec3a = vec3a.scaleVec(vec3); | ||
178 | ensure("3:scaleVec: Fail ", ((4 == vec3a.mV[VX]) && (9 == vec3a.mV[VY]) &&(1 == vec3a.mV[VZ]))); | ||
179 | ensure("4:isExactlyZero():Fail ", (FALSE == vec3.isExactlyZero())); | ||
180 | } | ||
181 | |||
182 | template<> template<> | ||
183 | void v3math_object::test<11>() | ||
184 | { | ||
185 | F32 x =20.0f, y = 30.0f, z = 15.f ; | ||
186 | F32 angle = 100.f; | ||
187 | LLVector3 vec3(x,y,z),vec3a(1.f,2.f,3.f); | ||
188 | vec3a = vec3a.rotVec(angle, vec3); | ||
189 | LLVector3 vec3b(1.f,2.f,3.f); | ||
190 | vec3b = vec3b.rotVec(angle, vec3); | ||
191 | ensure_equals("rotVec():Fail" ,vec3b,vec3a); | ||
192 | } | ||
193 | |||
194 | template<> template<> | ||
195 | void v3math_object::test<12>() | ||
196 | { | ||
197 | F32 x =-2.0f, y = -3.0f, z = 1.f ; | ||
198 | LLVector3 vec3(x,y,z); | ||
199 | ensure("1:operator [] failed",( x == vec3[0])); | ||
200 | ensure("2:operator [] failed",( y == vec3[1])); | ||
201 | ensure("3:operator [] failed",( z == vec3[2])); | ||
202 | |||
203 | vec3.clearVec(); | ||
204 | x = 23.f, y = -.2361f, z = 3.25; | ||
205 | vec3.setVec(x,y,z); | ||
206 | F32 &ref1 = vec3[0]; | ||
207 | ensure("4:operator [] failed",( ref1 == vec3[0])); | ||
208 | F32 &ref2 = vec3[1]; | ||
209 | ensure("5:operator [] failed",( ref2 == vec3[1])); | ||
210 | F32 &ref3 = vec3[2]; | ||
211 | ensure("6:operator [] failed",( ref3 == vec3[2])); | ||
212 | } | ||
213 | |||
214 | template<> template<> | ||
215 | void v3math_object::test<13>() | ||
216 | { | ||
217 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
218 | F32 val1, val2, val3; | ||
219 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b; | ||
220 | vec3b = vec3 + vec3a ; | ||
221 | val1 = x1+x2; | ||
222 | val2 = y1+y2; | ||
223 | val3 = z1+z2; | ||
224 | ensure("1:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
225 | |||
226 | vec3.clearVec(); | ||
227 | vec3a.clearVec(); | ||
228 | vec3b.clearVec(); | ||
229 | x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f; | ||
230 | vec3.setVec(x1,y1,z1); | ||
231 | vec3a.setVec(x2,y2,z2); | ||
232 | vec3b = vec3 + vec3a; | ||
233 | val1 = x1+x2; | ||
234 | val2 = y1+y2; | ||
235 | val3 = z1+z2; | ||
236 | ensure("2:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
237 | } | ||
238 | |||
239 | template<> template<> | ||
240 | void v3math_object::test<14>() | ||
241 | { | ||
242 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
243 | F32 val1, val2, val3; | ||
244 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b; | ||
245 | vec3b = vec3 - vec3a ; | ||
246 | val1 = x1-x2; | ||
247 | val2 = y1-y2; | ||
248 | val3 = z1-z2; | ||
249 | ensure("1:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
250 | |||
251 | vec3.clearVec(); | ||
252 | vec3a.clearVec(); | ||
253 | vec3b.clearVec(); | ||
254 | x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f; | ||
255 | vec3.setVec(x1,y1,z1); | ||
256 | vec3a.setVec(x2,y2,z2); | ||
257 | vec3b = vec3 - vec3a; | ||
258 | val1 = x1-x2; | ||
259 | val2 = y1-y2; | ||
260 | val3 = z1-z2; | ||
261 | ensure("2:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
262 | } | ||
263 | |||
264 | template<> template<> | ||
265 | void v3math_object::test<15>() | ||
266 | { | ||
267 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
268 | F32 val1, val2, val3; | ||
269 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
270 | val1 = vec3 * vec3a; | ||
271 | val2 = x1*x2 + y1*y2 + z1*z2; | ||
272 | ensure_equals("1:operator* failed",val1,val2); | ||
273 | |||
274 | vec3a.clearVec(); | ||
275 | F32 mulVal = 4.332f; | ||
276 | vec3a = vec3 * mulVal; | ||
277 | val1 = x1*mulVal; | ||
278 | val2 = y1*mulVal; | ||
279 | val3 = z1*mulVal; | ||
280 | ensure("2:operator* failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ])); | ||
281 | vec3a.clearVec(); | ||
282 | vec3a = mulVal * vec3; | ||
283 | ensure("3:operator* failed ", (val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ])); | ||
284 | } | ||
285 | |||
286 | template<> template<> | ||
287 | void v3math_object::test<16>() | ||
288 | { | ||
289 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
290 | F32 val1, val2, val3; | ||
291 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b; | ||
292 | vec3b = vec3 % vec3a ; | ||
293 | val1 = y1*z2 - y2*z1; | ||
294 | val2 = z1*x2 -z2*x1; | ||
295 | val3 = x1*y2-x2*y1; | ||
296 | ensure("1:operator% failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
297 | |||
298 | vec3.clearVec(); | ||
299 | vec3a.clearVec(); | ||
300 | vec3b.clearVec(); | ||
301 | x1 =112.f, y1 = 22.3f,z1 = 1.2f, x2 = -2.3f, y2 = 341.11f, z2 = 1234.234f; | ||
302 | vec3.setVec(x1,y1,z1); | ||
303 | vec3a.setVec(x2,y2,z2); | ||
304 | vec3b = vec3 % vec3a ; | ||
305 | val1 = y1*z2 - y2*z1; | ||
306 | val2 = z1*x2 -z2*x1; | ||
307 | val3 = x1*y2-x2*y1; | ||
308 | ensure("2:operator% failed ", (val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); | ||
309 | } | ||
310 | |||
311 | template<> template<> | ||
312 | void v3math_object::test<17>() | ||
313 | { | ||
314 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f; | ||
315 | F32 t = 1.f / div, val1, val2, val3; | ||
316 | LLVector3 vec3(x1,y1,z1), vec3a; | ||
317 | vec3a = vec3 / div; | ||
318 | val1 = x1 * t; | ||
319 | val2 = y1 * t; | ||
320 | val3 = z1 *t; | ||
321 | ensure("1:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ])); | ||
322 | |||
323 | vec3a.clearVec(); | ||
324 | x1 = -.235f, y1 = -24.32f, z1 = .342f, div = -2.2f; | ||
325 | t = 1.f / div; | ||
326 | vec3.setVec(x1,y1,z1); | ||
327 | vec3a = vec3 / div; | ||
328 | val1 = x1 * t; | ||
329 | val2 = y1 * t; | ||
330 | val3 = z1 *t; | ||
331 | ensure("2:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ])); | ||
332 | } | ||
333 | |||
334 | template<> template<> | ||
335 | void v3math_object::test<18>() | ||
336 | { | ||
337 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f; | ||
338 | LLVector3 vec3(x1,y1,z1), vec3a(x1,y1,z1); | ||
339 | ensure("1:operator== failed",(vec3 == vec3a)); | ||
340 | |||
341 | vec3a.clearVec(); | ||
342 | x1 = -.235f, y1 = -24.32f, z1 = .342f; | ||
343 | vec3.clearVec(); | ||
344 | vec3a.clearVec(); | ||
345 | vec3.setVec(x1,y1,z1); | ||
346 | vec3a.setVec(x1,y1,z1); | ||
347 | ensure("2:operator== failed ", (vec3 == vec3a)); | ||
348 | } | ||
349 | |||
350 | template<> template<> | ||
351 | void v3math_object::test<19>() | ||
352 | { | ||
353 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.234f,z2 = 11.2f;; | ||
354 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
355 | ensure("1:operator!= failed",(vec3a != vec3)); | ||
356 | |||
357 | vec3.clearVec(); | ||
358 | vec3.clearVec(); | ||
359 | vec3a.setVec(vec3); | ||
360 | ensure("2:operator!= failed", ( FALSE == (vec3a != vec3))); | ||
361 | } | ||
362 | |||
363 | template<> template<> | ||
364 | void v3math_object::test<20>() | ||
365 | { | ||
366 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;; | ||
367 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
368 | vec3a += vec3; | ||
369 | F32 val1, val2, val3; | ||
370 | val1 = x1+x2; | ||
371 | val2 = y1+y2; | ||
372 | val3 = z1+z2; | ||
373 | ensure("1:operator+= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ])); | ||
374 | } | ||
375 | |||
376 | template<> template<> | ||
377 | void v3math_object::test<21>() | ||
378 | { | ||
379 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;; | ||
380 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
381 | vec3a -= vec3; | ||
382 | F32 val1, val2, val3; | ||
383 | val1 = x2-x1; | ||
384 | val2 = y2-y1; | ||
385 | val3 = z2-z1; | ||
386 | ensure("1:operator-= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ])); | ||
387 | } | ||
388 | |||
389 | template<> template<> | ||
390 | void v3math_object::test<22>() | ||
391 | { | ||
392 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
393 | F32 val1,val2,val3; | ||
394 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
395 | vec3a *= vec3; | ||
396 | val1 = x1*x2; | ||
397 | val2 = y1*y2; | ||
398 | val3 = z1*z2; | ||
399 | ensure("1:operator*= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ])); | ||
400 | |||
401 | F32 mulVal = 4.332f; | ||
402 | vec3 *=mulVal; | ||
403 | val1 = x1*mulVal; | ||
404 | val2 = y1*mulVal; | ||
405 | val3 = z1*mulVal; | ||
406 | ensure("2:operator*= failed ", (val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY]) && (val3 == vec3.mV[VZ])); | ||
407 | } | ||
408 | |||
409 | template<> template<> | ||
410 | void v3math_object::test<23>() | ||
411 | { | ||
412 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | ||
413 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2),vec3b; | ||
414 | vec3b = vec3a % vec3; | ||
415 | vec3a %= vec3; | ||
416 | ensure_equals("1:operator%= failed",vec3a,vec3b); | ||
417 | } | ||
418 | |||
419 | template<> template<> | ||
420 | void v3math_object::test<24>() | ||
421 | { | ||
422 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f; | ||
423 | F32 t = 1.f / div, val1, val2, val3; | ||
424 | LLVector3 vec3a(x1,y1,z1); | ||
425 | vec3a /= div; | ||
426 | val1 = x1 * t; | ||
427 | val2 = y1 * t; | ||
428 | val3 = z1 *t; | ||
429 | ensure("1:operator/= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ])); | ||
430 | } | ||
431 | |||
432 | template<> template<> | ||
433 | void v3math_object::test<25>() | ||
434 | { | ||
435 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f; | ||
436 | LLVector3 vec3(x1,y1,z1), vec3a; | ||
437 | vec3a = -vec3; | ||
438 | ensure("1:operator- failed",(-vec3a == vec3)); | ||
439 | } | ||
440 | |||
441 | template<> template<> | ||
442 | void v3math_object::test<26>() | ||
443 | { | ||
444 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f; | ||
445 | std::ostringstream stream1, stream2; | ||
446 | LLVector3 vec3(x1,y1,z1), vec3a; | ||
447 | stream1 << vec3; | ||
448 | vec3a.setVec(x1,y1,z1); | ||
449 | stream2 << vec3a; | ||
450 | ensure("1:operator << failed",(stream1.str() == stream2.str())); | ||
451 | } | ||
452 | |||
453 | template<> template<> | ||
454 | void v3math_object::test<27>() | ||
455 | { | ||
456 | F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f; | ||
457 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | ||
458 | ensure("1:operator< failed", (TRUE == vec3 < vec3a)); | ||
459 | x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 2.f, z2 = 1234.234f; | ||
460 | vec3.setVec(x1,y1,z1); | ||
461 | vec3a.setVec(x2,y2,z2); | ||
462 | ensure("2:operator< failed ", (TRUE == vec3 < vec3a)); | ||
463 | x1 =2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, | ||
464 | vec3.setVec(x1,y1,z1); | ||
465 | vec3a.setVec(x2,y2,z2); | ||
466 | ensure("3:operator< failed ", (FALSE == vec3 < vec3a)); | ||
467 | } | ||
468 | |||
469 | template<> template<> | ||
470 | void v3math_object::test<28>() | ||
471 | { | ||
472 | F32 x1 =1.23f, y1 = 2.f,z1 = 4.f; | ||
473 | char buf[] = "1.23 2. 4"; | ||
474 | LLVector3 vec3, vec3a(x1,y1,z1); | ||
475 | LLVector3::parseVector3(buf, &vec3); | ||
476 | ensure_equals("1:parseVector3 failed", vec3, vec3a); | ||
477 | } | ||
478 | |||
479 | template<> template<> | ||
480 | void v3math_object::test<29>() | ||
481 | { | ||
482 | F32 x1 =1.f, y1 = 2.f,z1 = 4.f; | ||
483 | LLVector3 vec3(x1,y1,z1),vec3a,vec3b; | ||
484 | vec3a.setVec(1,1,1); | ||
485 | vec3a.scaleVec(vec3); | ||
486 | ensure_equals("1:scaleVec failed", vec3, vec3a); | ||
487 | vec3a.clearVec(); | ||
488 | vec3a.setVec(x1,y1,z1); | ||
489 | vec3a.scaleVec(vec3); | ||
490 | ensure("2:scaleVec failed", ((1.f ==vec3a.mV[VX])&& (4.f ==vec3a.mV[VY]) && (16.f ==vec3a.mV[VZ]))); | ||
491 | } | ||
492 | |||
493 | template<> template<> | ||
494 | void v3math_object::test<30>() | ||
495 | { | ||
496 | F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f; | ||
497 | F32 val = 2.3f,val1,val2,val3; | ||
498 | val1 = x1 + (x2 - x1)* val; | ||
499 | val2 = y1 + (y2 - y1)* val; | ||
500 | val3 = z1 + (z2 - z1)* val; | ||
501 | LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2); | ||
502 | LLVector3 vec3b = lerp(vec3,vec3a,val); | ||
503 | ensure("1:lerp failed", ((val1 ==vec3b.mV[VX])&& (val2 ==vec3b.mV[VY]) && (val3 ==vec3b.mV[VZ]))); | ||
504 | } | ||
505 | |||
506 | template<> template<> | ||
507 | void v3math_object::test<31>() | ||
508 | { | ||
509 | F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f; | ||
510 | F32 val1,val2; | ||
511 | LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2); | ||
512 | val1 = dist_vec(vec3,vec3a); | ||
513 | val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2)); | ||
514 | ensure_equals("1:dist_vec: Fail ",val2, val1); | ||
515 | val1 = dist_vec_squared(vec3,vec3a); | ||
516 | val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2)); | ||
517 | ensure_equals("2:dist_vec_squared: Fail ",val2, val1); | ||
518 | val1 = dist_vec_squared2D(vec3, vec3a); | ||
519 | val2 =(x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2); | ||
520 | ensure_equals("3:dist_vec_squared2D: Fail ",val2, val1); | ||
521 | } | ||
522 | |||
523 | template<> template<> | ||
524 | void v3math_object::test<32>() | ||
525 | { | ||
526 | F32 x =12.3524f, y = -342.f,z = 4.126341f; | ||
527 | LLVector3 vec3(x,y,z); | ||
528 | F32 mag = vec3.normVec(); | ||
529 | mag = 1.f/ mag; | ||
530 | F32 val1 = x* mag, val2 = y* mag, val3 = z* mag; | ||
531 | ensure("1:normVec: Fail ", (val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY])&& (val3 == vec3.mV[VZ])); | ||
532 | x = 0.000000001f, y = 0.f, z = 0.f; | ||
533 | vec3.clearVec(); | ||
534 | vec3.setVec(x,y,z); | ||
535 | mag = vec3.normVec(); | ||
536 | val1 = x* mag, val2 = y* mag, val3 = z* mag; | ||
537 | ensure("2:normVec: Fail ", (mag == 0.) && (0. == vec3.mV[VX]) && (0. == vec3.mV[VY])&& (0. == vec3.mV[VZ])); | ||
538 | } | ||
539 | |||
540 | template<> template<> | ||
541 | void v3math_object::test<33>() | ||
542 | { | ||
543 | F32 x = -202.23412f, y = 123.2312f, z = -89.f; | ||
544 | LLVector3 vec(x,y,z); | ||
545 | vec.snap(2); | ||
546 | ensure("1:snap: Fail ", is_approx_equal(-202.23f, vec.mV[VX]) && is_approx_equal(123.23f, vec.mV[VY]) && is_approx_equal(-89.f, vec.mV[VZ])); | ||
547 | } | ||
548 | |||
549 | template<> template<> | ||
550 | void v3math_object::test<34>() | ||
551 | { | ||
552 | F32 x = 10.f, y = 20.f, z = -15.f; | ||
553 | F32 x1, y1, z1; | ||
554 | F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f; | ||
555 | LLVector3 vec3(x,y,z); | ||
556 | vec3.quantize16(lowerxy,upperxy,lowerz,upperz); | ||
557 | x1 = U16_to_F32(F32_to_U16(x, lowerxy, upperxy), lowerxy, upperxy); | ||
558 | y1 = U16_to_F32(F32_to_U16(y, lowerxy, upperxy), lowerxy, upperxy); | ||
559 | z1 = U16_to_F32(F32_to_U16(z, lowerz, upperz), lowerz, upperz); | ||
560 | ensure("1:quantize16: Fail ", (x1 == vec3.mV[VX]) && (y1 == vec3.mV[VY])&& (z1 == vec3.mV[VZ])); | ||
561 | LLVector3 vec3a(x,y,z); | ||
562 | vec3a.quantize8(lowerxy,upperxy,lowerz,upperz); | ||
563 | x1 = U8_to_F32(F32_to_U8(x, lowerxy, upperxy), lowerxy, upperxy); | ||
564 | y1 = U8_to_F32(F32_to_U8(y, lowerxy, upperxy), lowerxy, upperxy); | ||
565 | z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz); | ||
566 | ensure("2:quantize8: Fail ", (x1 == vec3a.mV[VX]) && (y1 == vec3a.mV[VY])&& (z1 == vec3a.mV[VZ])); | ||
567 | } | ||
568 | } \ No newline at end of file | ||
diff --git a/linden/indra/test/xform_tut.cpp b/linden/indra/test/xform_tut.cpp new file mode 100644 index 0000000..b3bc347 --- /dev/null +++ b/linden/indra/test/xform_tut.cpp | |||
@@ -0,0 +1,247 @@ | |||
1 | /** | ||
2 | * @file xform_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief Test cases for LLXform | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "xform.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct xform_test | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<xform_test> xform_test_t; | ||
42 | typedef xform_test_t::object xform_test_object_t; | ||
43 | tut::xform_test_t tut_xform_test("xform_test"); | ||
44 | |||
45 | //test case for init(), getParent(), getRotation(), getPositionW(), getWorldRotation() fns. | ||
46 | template<> template<> | ||
47 | void xform_test_object_t::test<1>() | ||
48 | { | ||
49 | LLXform xform_obj; | ||
50 | LLVector3 emptyVec(0.f,0.f,0.f); | ||
51 | LLVector3 initialScaleVec(1.f,1.f,1.f); | ||
52 | |||
53 | ensure("LLXform empty constructor failed: ", !xform_obj.getParent() && !xform_obj.isChanged() && | ||
54 | xform_obj.getPosition() == emptyVec && | ||
55 | (xform_obj.getRotation()).isIdentity() && | ||
56 | xform_obj.getScale() == initialScaleVec && | ||
57 | xform_obj.getPositionW() == emptyVec && | ||
58 | (xform_obj.getWorldRotation()).isIdentity() && | ||
59 | !xform_obj.getScaleChildOffset()); | ||
60 | } | ||
61 | |||
62 | // test cases for | ||
63 | // setScale(const LLVector3& scale) | ||
64 | // setScale(const F32 x, const F32 y, const F32 z) | ||
65 | // setRotation(const F32 x, const F32 y, const F32 z) | ||
66 | // setPosition(const F32 x, const F32 y, const F32 z) | ||
67 | // getLocalMat4(LLMatrix4 &mat) | ||
68 | template<> template<> | ||
69 | void xform_test_object_t::test<2>() | ||
70 | { | ||
71 | LLMatrix4 llmat4; | ||
72 | LLXform xform_obj; | ||
73 | |||
74 | F32 x = 3.6f; | ||
75 | F32 y = 5.5f; | ||
76 | F32 z = 4.2f; | ||
77 | F32 w = 0.f; | ||
78 | F32 posz = z + 2.122f; | ||
79 | LLVector3 vec(x, y, z); | ||
80 | xform_obj.setScale(x, y, z); | ||
81 | xform_obj.setPosition(x, y, posz); | ||
82 | ensure("setScale failed: ", xform_obj.getScale() == vec); | ||
83 | |||
84 | vec.setVec(x, y, posz); | ||
85 | ensure("getPosition failed: ", xform_obj.getPosition() == vec); | ||
86 | |||
87 | x = x * 2.f; | ||
88 | y = y + 2.3f; | ||
89 | z = posz * 4.f; | ||
90 | vec.setVec(x, y, z); | ||
91 | xform_obj.setPositionX(x); | ||
92 | xform_obj.setPositionY(y); | ||
93 | xform_obj.setPositionZ(z); | ||
94 | ensure("setPositionX/Y/Z failed: ", xform_obj.getPosition() == vec); | ||
95 | |||
96 | xform_obj.setScaleChildOffset(TRUE); | ||
97 | ensure("setScaleChildOffset failed: ", xform_obj.getScaleChildOffset()); | ||
98 | |||
99 | vec.setVec(x, y, z); | ||
100 | |||
101 | xform_obj.addPosition(vec); | ||
102 | vec += vec; | ||
103 | ensure("addPosition failed: ", xform_obj.getPosition() == vec); | ||
104 | |||
105 | xform_obj.setScale(vec); | ||
106 | ensure("setScale vector failed: ", xform_obj.getScale() == vec); | ||
107 | |||
108 | LLQuaternion quat(x, y, z, w); | ||
109 | xform_obj.setRotation(quat); | ||
110 | ensure("setRotation quat failed: ", xform_obj.getRotation() == quat); | ||
111 | |||
112 | xform_obj.setRotation(x, y, z, w); | ||
113 | ensure("getRotation 2 failed: ", xform_obj.getRotation() == quat); | ||
114 | |||
115 | xform_obj.setRotation(x, y, z); | ||
116 | quat.setQuat(x,y,z); | ||
117 | ensure("setRotation xyz failed: ", xform_obj.getRotation() == quat); | ||
118 | |||
119 | // LLXform::setRotation(const F32 x, const F32 y, const F32 z) | ||
120 | // Does normalization | ||
121 | // LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s) | ||
122 | // Simply copies the individual values - does not do any normalization. | ||
123 | // Is that the expected behavior? | ||
124 | } | ||
125 | |||
126 | // test cases for inline BOOL setParent(LLXform *parent) and getParent() fn. | ||
127 | template<> template<> | ||
128 | void xform_test_object_t::test<3>() | ||
129 | { | ||
130 | LLXform xform_obj; | ||
131 | LLXform par; | ||
132 | LLXform grandpar; | ||
133 | xform_obj.setParent(&par); | ||
134 | par.setParent(&grandpar); | ||
135 | ensure("setParent/getParent failed: ", &par == xform_obj.getParent()); | ||
136 | ensure("getRoot failed: ", &grandpar == xform_obj.getRoot()); | ||
137 | ensure("isRoot failed: ", grandpar.isRoot() && !par.isRoot() && !xform_obj.isRoot()); | ||
138 | ensure("isRootEdit failed: ", grandpar.isRootEdit() && !par.isRootEdit() && !xform_obj.isRootEdit()); | ||
139 | } | ||
140 | |||
141 | template<> template<> | ||
142 | void xform_test_object_t::test<4>() | ||
143 | { | ||
144 | LLXform xform_obj; | ||
145 | xform_obj.setChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED); | ||
146 | ensure("setChanged/isChanged failed: ", xform_obj.isChanged()); | ||
147 | |||
148 | xform_obj.clearChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED); | ||
149 | ensure("clearChanged failed: ", !xform_obj.isChanged()); | ||
150 | |||
151 | LLVector3 llvect3(12.4f, -5.6f, 0.34f); | ||
152 | xform_obj.setScale(llvect3); | ||
153 | ensure("setScale did not set SCALED flag: ", xform_obj.isChanged(LLXform::SCALED)); | ||
154 | xform_obj.setPosition(1.2f, 2.3f, 3.4f); | ||
155 | ensure("setScale did not set TRANSLATED flag: ", xform_obj.isChanged(LLXform::TRANSLATED)); | ||
156 | ensure("TRANSLATED reset SCALED flag: ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::SCALED)); | ||
157 | xform_obj.clearChanged(LLXform::SCALED); | ||
158 | ensure("reset SCALED failed: ", !xform_obj.isChanged(LLXform::SCALED)); | ||
159 | xform_obj.setRotation(1, 2, 3, 4); | ||
160 | ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::ROTATED)); | ||
161 | xform_obj.setScale(llvect3); | ||
162 | ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::MOVED)); | ||
163 | } | ||
164 | |||
165 | //to test init() and getWorldMatrix() fns. | ||
166 | template<> template<> | ||
167 | void xform_test_object_t::test<5>() | ||
168 | { | ||
169 | LLXformMatrix formMatrix_obj; | ||
170 | formMatrix_obj.init(); | ||
171 | LLMatrix4 mat4_obj; | ||
172 | |||
173 | ensure("1. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[0][0]); | ||
174 | ensure("2. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][1]); | ||
175 | ensure("3. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][2]); | ||
176 | ensure("4. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][3]); | ||
177 | ensure("5. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][0]); | ||
178 | ensure("6. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[1][1]); | ||
179 | ensure("7. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][2]); | ||
180 | ensure("8. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][3]); | ||
181 | ensure("9. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][0]); | ||
182 | ensure("10. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][1]); | ||
183 | ensure("11. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[2][2]); | ||
184 | ensure("12. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][3]); | ||
185 | ensure("13. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][0]); | ||
186 | ensure("14. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][1]); | ||
187 | ensure("15. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][2]); | ||
188 | ensure("16. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[3][3]); | ||
189 | } | ||
190 | |||
191 | //to test mMin.clearVec() and mMax.clearVec() fns | ||
192 | template<> template<> | ||
193 | void xform_test_object_t::test<6>() | ||
194 | { | ||
195 | LLXformMatrix formMatrix_obj; | ||
196 | formMatrix_obj.init(); | ||
197 | LLVector3 llmin_vec3; | ||
198 | LLVector3 llmax_vec3; | ||
199 | formMatrix_obj.getMinMax(llmin_vec3, llmax_vec3); | ||
200 | ensure("1. The value is not NULL", 0.f == llmin_vec3.mV[0]); | ||
201 | ensure("2. The value is not NULL", 0.f == llmin_vec3.mV[1]); | ||
202 | ensure("3. The value is not NULL", 0.f == llmin_vec3.mV[2]); | ||
203 | ensure("4. The value is not NULL", 0.f == llmin_vec3.mV[0]); | ||
204 | ensure("5. The value is not NULL", 0.f == llmin_vec3.mV[1]); | ||
205 | ensure("6. The value is not NULL", 0.f == llmin_vec3.mV[2]); | ||
206 | } | ||
207 | |||
208 | //test case of update() fn. | ||
209 | template<> template<> | ||
210 | void xform_test_object_t::test<7>() | ||
211 | { | ||
212 | LLXformMatrix formMatrix_obj; | ||
213 | |||
214 | LLXformMatrix parent; | ||
215 | LLVector3 llvecpos(1.0, 2.0, 3.0); | ||
216 | LLVector3 llvecpospar(10.0, 20.0, 30.0); | ||
217 | formMatrix_obj.setPosition(llvecpos); | ||
218 | parent.setPosition(llvecpospar); | ||
219 | |||
220 | LLVector3 llvecparentscale(1.0, 2.0, 0); | ||
221 | parent.setScaleChildOffset(TRUE); | ||
222 | parent.setScale(llvecparentscale); | ||
223 | |||
224 | LLQuaternion quat(1, 2, 3, 4); | ||
225 | LLQuaternion quatparent(5, 6, 7, 8); | ||
226 | formMatrix_obj.setRotation(quat); | ||
227 | parent.setRotation(quatparent); | ||
228 | formMatrix_obj.setParent(&parent); | ||
229 | |||
230 | parent.update(); | ||
231 | formMatrix_obj.update(); | ||
232 | |||
233 | LLVector3 worldPos = llvecpos; | ||
234 | worldPos.scaleVec(llvecparentscale); | ||
235 | worldPos *= quatparent; | ||
236 | worldPos += llvecpospar; | ||
237 | |||
238 | LLQuaternion worldRot = quat * quatparent; | ||
239 | |||
240 | ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos); | ||
241 | ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot); | ||
242 | |||
243 | ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar); | ||
244 | ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent); | ||
245 | } | ||
246 | } | ||
247 | |||