29 using NUnit.Framework;
31 using OpenSim.Tests.Common;
33 namespace OpenSim.Framework.Tests
42 double expectedDistance;
43 double expectedMagnitude;
44 double lowPrecisionTolerance = 0.001;
48 v1 =
new Vector3(0, 0, 0);
49 v2 =
new Vector3(5, 5, 5);
50 expectedDistance = 8.66;
51 Assert.That(Util.GetDistanceTo(v1, v2),
53 "Calculated distance between two vectors was not within tolerances.");
55 expectedMagnitude = 0;
56 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0),
"Magnitude of null vector was not zero.");
58 expectedMagnitude = 8.66;
59 Assert.That(Util.GetMagnitude(v2),
61 "Magnitude of vector was incorrect.");
68 Vector3 expectedNormalizedVector =
new Vector3(.577f, .577f, .577f);
69 double expectedNormalizedMagnitude = 1;
70 Vector3 normalizedVector = Util.GetNormalizedVector(v2);
71 Assert.That(normalizedVector,
73 "Normalized vector generated from vector was not what was expected.");
74 Assert.That(Util.GetMagnitude(normalizedVector),
76 "Normalized vector generated from vector does not have magnitude of 1.");
81 v1 =
new Vector3(0, 0, 0);
82 v2 =
new Vector3(0, 0, 0);
84 Assert.That(Util.GetDistanceTo(v1, v2),
86 "Calculated distance between two vectors was not within tolerances.");
88 expectedMagnitude = 0;
89 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0),
"Magnitude of null vector was not zero.");
91 expectedMagnitude = 0;
92 Assert.That(Util.GetMagnitude(v2),
94 "Magnitude of vector was incorrect.");
110 v1 =
new Vector3(0, 0, 0);
111 v2 =
new Vector3(-5, -5, -5);
112 expectedDistance = 8.66;
113 Assert.That(Util.GetDistanceTo(v1, v2),
115 "Calculated distance between two vectors was not within tolerances.");
117 expectedMagnitude = 0;
118 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0),
"Magnitude of null vector was not zero.");
120 expectedMagnitude = 8.66;
121 Assert.That(Util.GetMagnitude(v2),
123 "Magnitude of vector was incorrect.");
130 Vector3 expectedNormalizedVector =
new Vector3(-.577f, -.577f, -.577f);
131 double expectedNormalizedMagnitude = 1;
132 Vector3 normalizedVector = Util.GetNormalizedVector(v2);
133 Assert.That(normalizedVector,
135 "Normalized vector generated from vector was not what was expected.");
136 Assert.That(Util.GetMagnitude(normalizedVector),
138 "Normalized vector generated from vector does not have magnitude of 1.");
145 Assert.IsTrue(Util.isUUID(
"01234567-89ab-Cdef-0123-456789AbCdEf"),
146 "A correct UUID wasn't recognized.");
147 Assert.IsFalse(Util.isUUID(
"FOOBAR67-89ab-Cdef-0123-456789AbCdEf"),
148 "UUIDs with non-hex characters are recognized as correct UUIDs.");
149 Assert.IsFalse(Util.isUUID(
"01234567"),
150 "Too short UUIDs are recognized as correct UUIDs.");
151 Assert.IsFalse(Util.isUUID(
"01234567-89ab-Cdef-0123-456789AbCdEf0"),
152 "Too long UUIDs are recognized as correct UUIDs.");
153 Assert.IsFalse(Util.isUUID(
"01234567-89ab-Cdef-0123+456789AbCdEf"),
154 "UUIDs with wrong format are recognized as correct UUIDs.");
160 string string1 =
"This is one string";
161 string string2 =
"This is another";
164 Assert.AreEqual(Util.GetHashGuid(string1,
"secret1"), Util.GetHashGuid(string1,
"secret1"));
165 Assert.AreEqual(Util.GetHashGuid(string2,
"secret1"), Util.GetHashGuid(string2,
"secret1"));
168 Assert.AreNotEqual(Util.GetHashGuid(string1,
"secret1"), Util.GetHashGuid(string2,
"secret1"));
171 Assert.AreNotEqual(Util.GetHashGuid(string1,
"secret1"), Util.GetHashGuid(string1,
"secret2"));
177 int[] assettypes =
new int[]{-1,0,1,2,3,5,6,7,8,10,11,12,13,17,18,19,20,21,22
179 string[] contenttypes =
new string[]
181 "application/octet-stream",
184 "application/vnd.ll.callingcard",
185 "application/vnd.ll.landmark",
186 "application/vnd.ll.clothing",
187 "application/vnd.ll.primitive",
188 "application/vnd.ll.notecard",
189 "application/vnd.ll.folder",
190 "application/vnd.ll.lsltext",
191 "application/vnd.ll.lslbyte",
193 "application/vnd.ll.bodypart",
197 "application/vnd.ll.animation",
198 "application/vnd.ll.gesture",
199 "application/x-metaverse-simstate",
200 "application/vnd.ll.link",
201 "application/vnd.ll.linkfolder",
203 for (
int i=0;i<assettypes.Length;i++)
205 Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i],
"Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i]));
208 for (
int i = 0; i < contenttypes.Length; i++)
211 if (contenttypes[i] ==
"image/tga")
214 expected = assettypes[i];
215 Assert.AreEqual(expected, SLUtil.ContentTypeToSLAssetType(contenttypes[i]),
216 String.Format(
"Incorrect AssetType mapped from Content-Type {0}", contenttypes[i]));
219 int[] inventorytypes =
new int[] {-1,0,1,2,3,6,7,8,10,15,17,18,20};
220 string[] invcontenttypes =
new string[]
222 "application/octet-stream",
225 "application/vnd.ll.callingcard",
226 "application/vnd.ll.landmark",
227 "application/vnd.ll.primitive",
228 "application/vnd.ll.notecard",
229 "application/vnd.ll.rootfolder",
230 "application/vnd.ll.lsltext",
232 "application/vnd.ll.primitive",
233 "application/vnd.ll.clothing",
234 "application/vnd.ll.gesture"
237 for (
int i=0;i<inventorytypes.Length;i++)
239 Assert.AreEqual(invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i]),
240 String.Format(
"Incorrect Content-Type mapped from InventoryType {0}", inventorytypes[i]));
243 invcontenttypes =
new string[]
245 "image/x-j2c",
"image/jp2",
"image/tga",
246 "image/jpeg",
"application/ogg",
"audio/ogg",
247 "audio/x-wav",
"application/vnd.ll.callingcard",
248 "application/x-metaverse-callingcard",
249 "application/vnd.ll.landmark",
250 "application/x-metaverse-landmark",
251 "application/vnd.ll.clothing",
252 "application/x-metaverse-clothing",
"application/vnd.ll.bodypart",
253 "application/x-metaverse-bodypart",
"application/vnd.ll.primitive",
254 "application/x-metaverse-primitive",
"application/vnd.ll.notecard",
255 "application/x-metaverse-notecard",
"application/vnd.ll.folder",
256 "application/vnd.ll.rootfolder",
"application/vnd.ll.lsltext",
257 "application/x-metaverse-lsl",
"application/vnd.ll.lslbyte",
258 "application/x-metaverse-lso",
"application/vnd.ll.trashfolder",
259 "application/vnd.ll.snapshotfolder",
260 "application/vnd.ll.lostandfoundfolder",
"application/vnd.ll.animation",
261 "application/x-metaverse-animation",
"application/vnd.ll.gesture",
262 "application/x-metaverse-gesture",
"application/x-metaverse-simstate",
263 "application/octet-stream"
265 sbyte[] invtypes =
new sbyte[]
267 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, -1, 8, 10, 10, 10, 10
268 , 14, 15, 16, 19, 19, 20, 20, 15, -1
271 for (
int i = 0; i < invtypes.Length; i++)
273 Assert.AreEqual(invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i]),
274 String.Format(
"Incorrect InventoryType mapped from Content-Type {0}", invcontenttypes[i]));
281 byte[] hexBytes8 = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
282 byte[] hexBytes16 = {
283 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
284 0x77, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f };
285 UInt64 var64Bit = (UInt64)0xfedcba9876543210;
288 ulong regionHandle1 = 1095216660736000;
294 UUID fakeParcelID1, uuid;
296 ulong bigInt64 = Util.BytesToUInt64Big(hexBytes8);
297 Assert.AreEqual(var64Bit, bigInt64,
298 "BytesToUint64Bit conversion of 8 bytes to UInt64 failed.");
301 fakeParcelID1 = Util.BuildFakeParcelID(regionHandle1, x1, y1);
302 Util.ParseFakeParcelID(fakeParcelID1, out regionHandle2, out x2, out y2);
303 Assert.AreEqual(regionHandle1, regionHandle2,
304 "region handle decoded from FakeParcelID wth X/Y failed.");
305 Assert.AreEqual(x1, x2,
306 "X coordinate decoded from FakeParcelID wth X/Y failed.");
307 Assert.AreEqual(y1, y2,
308 "Y coordinate decoded from FakeParcelID wth X/Y failed.");
310 fakeParcelID1 = Util.BuildFakeParcelID(regionHandle1, x1, y1, z1);
311 Util.ParseFakeParcelID(fakeParcelID1, out regionHandle2, out x2, out y2, out z2);
312 Assert.AreEqual(regionHandle1, regionHandle2,
313 "region handle decoded from FakeParcelID with X/Y/Z failed.");
314 Assert.AreEqual(x1, x2,
315 "X coordinate decoded from FakeParcelID with X/Y/Z failed.");
316 Assert.AreEqual(y1, y2,
317 "Y coordinate decoded from FakeParcelID with X/Y/Z failed.");
318 Assert.AreEqual(z1, z2,
319 "Z coordinate decoded from FakeParcelID with X/Y/Z failed.");
326 fakeParcelID1 = Util.BuildFakeParcelID(var64Bit, x1, y1);
327 Util.ParseFakeParcelID(fakeParcelID1, out regionHandle2, out x2, out y2);
328 Assert.AreEqual(var64Bit, regionHandle2,
329 "region handle decoded from FakeParcelID with X/Y/Z failed.");
330 Assert.AreEqual(x1, x2,
331 "X coordinate decoded from FakeParcelID with X/Y/Z failed.");
332 Assert.AreEqual(y1, y2,
333 "Y coordinate decoded from FakeParcelID with X/Y/Z failed.");
335 fakeParcelID1 = Util.BuildFakeParcelID(var64Bit, x1, y1, z1);
336 Util.ParseFakeParcelID(fakeParcelID1, out regionHandle2, out x2, out y2, out z2);
337 Assert.AreEqual(var64Bit, regionHandle2,
338 "region handle decoded from FakeParcelID with X/Y/Z failed.");
339 Assert.AreEqual(x1, x2,
340 "X coordinate decoded from FakeParcelID with X/Y/Z failed.");
341 Assert.AreEqual(y1, y2,
342 "Y coordinate decoded from FakeParcelID with X/Y/Z failed.");
343 Assert.AreEqual(z1, z2,
344 "Z coordinate decoded from FakeParcelID with X/Y/Z failed.");
349 fakeParcelID1 = Util.BuildFakeParcelID(regionHandle1, x1, y1);
350 Util.FakeParcelIDToGlobalPosition(fakeParcelID1, out x2, out y2);
351 Assert.AreEqual(255000+x1, x2,
352 "Global X coordinate decoded from regionHandle failed.");
353 Assert.AreEqual(256000+y1, y2,
354 "Global Y coordinate decoded from regionHandle failed.");
356 uuid =
new UUID(
"00dd0700-00d1-0700-3800-000032000000");
357 Util.FakeParcelIDToGlobalPosition(uuid, out x2, out y2);
void VectorOperationTests()
void SLUtilTypeConvertTests()