diff options
author | Sean Dague | 2008-09-04 22:11:13 +0000 |
---|---|---|
committer | Sean Dague | 2008-09-04 22:11:13 +0000 |
commit | d363661a7e65e2bd83d6da99230d27cb593436ed (patch) | |
tree | 324d3925a74675b9e784ac27cde7a7894ece257f /OpenSim/Tests/Region/ScriptEngine | |
parent | normalize naming for OpenSim.Tests.Framework.dll (diff) | |
download | opensim-SC_OLD-d363661a7e65e2bd83d6da99230d27cb593436ed.zip opensim-SC_OLD-d363661a7e65e2bd83d6da99230d27cb593436ed.tar.gz opensim-SC_OLD-d363661a7e65e2bd83d6da99230d27cb593436ed.tar.bz2 opensim-SC_OLD-d363661a7e65e2bd83d6da99230d27cb593436ed.tar.xz |
complete rationalization of unit tests that we currently run
Diffstat (limited to 'OpenSim/Tests/Region/ScriptEngine')
12 files changed, 3915 insertions, 0 deletions
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs new file mode 100644 index 0000000..d89bb87 --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs | |||
@@ -0,0 +1,583 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Common; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Common.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLFloat | ||
37 | { | ||
38 | // Used for testing equality of two floats. | ||
39 | private double _lowPrecisionTolerance = 0.000001; | ||
40 | |||
41 | private Dictionary<int, double> m_intDoubleSet; | ||
42 | private Dictionary<double, double> m_doubleDoubleSet; | ||
43 | private Dictionary<double, int> m_doubleIntSet; | ||
44 | private Dictionary<double, int> m_doubleUintSet; | ||
45 | private Dictionary<string, double> m_stringDoubleSet; | ||
46 | private Dictionary<double, string> m_doubleStringSet; | ||
47 | private List<int> m_intList; | ||
48 | private List<double> m_doubleList; | ||
49 | |||
50 | /// <summary> | ||
51 | /// Sets up dictionaries and arrays used in the tests. | ||
52 | /// </summary> | ||
53 | [TestFixtureSetUp] | ||
54 | public void SetUpDataSets() | ||
55 | { | ||
56 | m_intDoubleSet = new Dictionary<int, double>(); | ||
57 | m_intDoubleSet.Add(2, 2.0); | ||
58 | m_intDoubleSet.Add(-2, -2.0); | ||
59 | m_intDoubleSet.Add(0, 0.0); | ||
60 | m_intDoubleSet.Add(1, 1.0); | ||
61 | m_intDoubleSet.Add(-1, -1.0); | ||
62 | m_intDoubleSet.Add(999999999, 999999999.0); | ||
63 | m_intDoubleSet.Add(-99999999, -99999999.0); | ||
64 | |||
65 | m_doubleDoubleSet = new Dictionary<double, double>(); | ||
66 | m_doubleDoubleSet.Add(2.0, 2.0); | ||
67 | m_doubleDoubleSet.Add(-2.0, -2.0); | ||
68 | m_doubleDoubleSet.Add(0.0, 0.0); | ||
69 | m_doubleDoubleSet.Add(1.0, 1.0); | ||
70 | m_doubleDoubleSet.Add(-1.0, -1.0); | ||
71 | m_doubleDoubleSet.Add(999999999.0, 999999999.0); | ||
72 | m_doubleDoubleSet.Add(-99999999.0, -99999999.0); | ||
73 | m_doubleDoubleSet.Add(0.5, 0.5); | ||
74 | m_doubleDoubleSet.Add(0.0005, 0.0005); | ||
75 | m_doubleDoubleSet.Add(0.6805, 0.6805); | ||
76 | m_doubleDoubleSet.Add(-0.5, -0.5); | ||
77 | m_doubleDoubleSet.Add(-0.0005, -0.0005); | ||
78 | m_doubleDoubleSet.Add(-0.6805, -0.6805); | ||
79 | m_doubleDoubleSet.Add(548.5, 548.5); | ||
80 | m_doubleDoubleSet.Add(2.0005, 2.0005); | ||
81 | m_doubleDoubleSet.Add(349485435.6805, 349485435.6805); | ||
82 | m_doubleDoubleSet.Add(-548.5, -548.5); | ||
83 | m_doubleDoubleSet.Add(-2.0005, -2.0005); | ||
84 | m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805); | ||
85 | |||
86 | m_doubleIntSet = new Dictionary<double, int>(); | ||
87 | m_doubleIntSet.Add(2.0, 2); | ||
88 | m_doubleIntSet.Add(-2.0, -2); | ||
89 | m_doubleIntSet.Add(0.0, 0); | ||
90 | m_doubleIntSet.Add(1.0, 1); | ||
91 | m_doubleIntSet.Add(-1.0, -1); | ||
92 | m_doubleIntSet.Add(999999999.0, 999999999); | ||
93 | m_doubleIntSet.Add(-99999999.0, -99999999); | ||
94 | m_doubleIntSet.Add(0.5, 0); | ||
95 | m_doubleIntSet.Add(0.0005, 0); | ||
96 | m_doubleIntSet.Add(0.6805, 0); | ||
97 | m_doubleIntSet.Add(-0.5, 0); | ||
98 | m_doubleIntSet.Add(-0.0005, 0); | ||
99 | m_doubleIntSet.Add(-0.6805, 0); | ||
100 | m_doubleIntSet.Add(548.5, 548); | ||
101 | m_doubleIntSet.Add(2.0005, 2); | ||
102 | m_doubleIntSet.Add(349485435.6805, 349485435); | ||
103 | m_doubleIntSet.Add(-548.5, -548); | ||
104 | m_doubleIntSet.Add(-2.0005, -2); | ||
105 | m_doubleIntSet.Add(-349485435.6805, -349485435); | ||
106 | |||
107 | m_doubleUintSet = new Dictionary<double, int>(); | ||
108 | m_doubleUintSet.Add(2.0, 2); | ||
109 | m_doubleUintSet.Add(-2.0, 2); | ||
110 | m_doubleUintSet.Add(0.0, 0); | ||
111 | m_doubleUintSet.Add(1.0, 1); | ||
112 | m_doubleUintSet.Add(-1.0, 1); | ||
113 | m_doubleUintSet.Add(999999999.0, 999999999); | ||
114 | m_doubleUintSet.Add(-99999999.0, 99999999); | ||
115 | m_doubleUintSet.Add(0.5, 0); | ||
116 | m_doubleUintSet.Add(0.0005, 0); | ||
117 | m_doubleUintSet.Add(0.6805, 0); | ||
118 | m_doubleUintSet.Add(-0.5, 0); | ||
119 | m_doubleUintSet.Add(-0.0005, 0); | ||
120 | m_doubleUintSet.Add(-0.6805, 0); | ||
121 | m_doubleUintSet.Add(548.5, 548); | ||
122 | m_doubleUintSet.Add(2.0005, 2); | ||
123 | m_doubleUintSet.Add(349485435.6805, 349485435); | ||
124 | m_doubleUintSet.Add(-548.5, 548); | ||
125 | m_doubleUintSet.Add(-2.0005, 2); | ||
126 | m_doubleUintSet.Add(-349485435.6805, 349485435); | ||
127 | |||
128 | m_stringDoubleSet = new Dictionary<string, double>(); | ||
129 | m_stringDoubleSet.Add("2", 2.0); | ||
130 | m_stringDoubleSet.Add("-2", -2.0); | ||
131 | m_stringDoubleSet.Add("1", 1.0); | ||
132 | m_stringDoubleSet.Add("-1", -1.0); | ||
133 | m_stringDoubleSet.Add("0", 0.0); | ||
134 | m_stringDoubleSet.Add("999999999.0", 999999999.0); | ||
135 | m_stringDoubleSet.Add("-99999999.0", -99999999.0); | ||
136 | m_stringDoubleSet.Add("0.5", 0.5); | ||
137 | m_stringDoubleSet.Add("0.0005", 0.0005); | ||
138 | m_stringDoubleSet.Add("0.6805", 0.6805); | ||
139 | m_stringDoubleSet.Add("-0.5", -0.5); | ||
140 | m_stringDoubleSet.Add("-0.0005", -0.0005); | ||
141 | m_stringDoubleSet.Add("-0.6805", -0.6805); | ||
142 | m_stringDoubleSet.Add("548.5", 548.5); | ||
143 | m_stringDoubleSet.Add("2.0005", 2.0005); | ||
144 | m_stringDoubleSet.Add("349485435.6805", 349485435.6805); | ||
145 | m_stringDoubleSet.Add("-548.5", -548.5); | ||
146 | m_stringDoubleSet.Add("-2.0005", -2.0005); | ||
147 | m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); | ||
148 | |||
149 | m_doubleStringSet = new Dictionary<double, string>(); | ||
150 | m_doubleStringSet.Add(2.0, "2.000000"); | ||
151 | m_doubleStringSet.Add(-2.0, "-2.000000"); | ||
152 | m_doubleStringSet.Add(1.0, "1.000000"); | ||
153 | m_doubleStringSet.Add(-1.0, "-1.000000"); | ||
154 | m_doubleStringSet.Add(0.0, "0.000000"); | ||
155 | m_doubleStringSet.Add(999999999.0, "999999999.000000"); | ||
156 | m_doubleStringSet.Add(-99999999.0, "-99999999.000000"); | ||
157 | m_doubleStringSet.Add(0.5, "0.500000"); | ||
158 | m_doubleStringSet.Add(0.0005, "0.000500"); | ||
159 | m_doubleStringSet.Add(0.6805, "0.680500"); | ||
160 | m_doubleStringSet.Add(-0.5, "-0.500000"); | ||
161 | m_doubleStringSet.Add(-0.0005, "-0.000500"); | ||
162 | m_doubleStringSet.Add(-0.6805, "-0.680500"); | ||
163 | m_doubleStringSet.Add(548.5, "548.500000"); | ||
164 | m_doubleStringSet.Add(2.0005, "2.000500"); | ||
165 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); | ||
166 | m_doubleStringSet.Add(-548.5, "-548.500000"); | ||
167 | m_doubleStringSet.Add(-2.0005, "-2.000500"); | ||
168 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); | ||
169 | |||
170 | m_doubleList = new List<double>(); | ||
171 | m_doubleList.Add(2.0); | ||
172 | m_doubleList.Add(-2.0); | ||
173 | m_doubleList.Add(1.0); | ||
174 | m_doubleList.Add(-1.0); | ||
175 | m_doubleList.Add(999999999.0); | ||
176 | m_doubleList.Add(-99999999.0); | ||
177 | m_doubleList.Add(0.5); | ||
178 | m_doubleList.Add(0.0005); | ||
179 | m_doubleList.Add(0.6805); | ||
180 | m_doubleList.Add(-0.5); | ||
181 | m_doubleList.Add(-0.0005); | ||
182 | m_doubleList.Add(-0.6805); | ||
183 | m_doubleList.Add(548.5); | ||
184 | m_doubleList.Add(2.0005); | ||
185 | m_doubleList.Add(349485435.6805); | ||
186 | m_doubleList.Add(-548.5); | ||
187 | m_doubleList.Add(-2.0005); | ||
188 | m_doubleList.Add(-349485435.6805); | ||
189 | |||
190 | m_intList = new List<int>(); | ||
191 | m_intList.Add(2); | ||
192 | m_intList.Add(-2); | ||
193 | m_intList.Add(0); | ||
194 | m_intList.Add(1); | ||
195 | m_intList.Add(-1); | ||
196 | m_intList.Add(999999999); | ||
197 | m_intList.Add(-99999999); | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Tests constructing a LSLFloat from an integer. | ||
202 | /// </summary> | ||
203 | [Test] | ||
204 | public void TestConstructFromInt() | ||
205 | { | ||
206 | LSL_Types.LSLFloat testFloat; | ||
207 | |||
208 | foreach (KeyValuePair<int, double> number in m_intDoubleSet) | ||
209 | { | ||
210 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
211 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Tests constructing a LSLFloat from a double. | ||
217 | /// </summary> | ||
218 | [Test] | ||
219 | public void TestConstructFromDouble() | ||
220 | { | ||
221 | LSL_Types.LSLFloat testFloat; | ||
222 | |||
223 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
224 | { | ||
225 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
226 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /// <summary> | ||
231 | /// Tests LSLFloat is correctly cast explicitly to integer. | ||
232 | /// </summary> | ||
233 | [Test] | ||
234 | public void TestExplicitCastLSLFloatToInt() | ||
235 | { | ||
236 | int testNumber; | ||
237 | |||
238 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) | ||
239 | { | ||
240 | testNumber = (int) new LSL_Types.LSLFloat(number.Key); | ||
241 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | /// <summary> | ||
246 | /// Tests LSLFloat is correctly cast explicitly to unsigned integer. | ||
247 | /// </summary> | ||
248 | [Test] | ||
249 | public void TestExplicitCastLSLFloatToUint() | ||
250 | { | ||
251 | uint testNumber; | ||
252 | |||
253 | foreach (KeyValuePair<double, int> number in m_doubleUintSet) | ||
254 | { | ||
255 | testNumber = (uint) new LSL_Types.LSLFloat(number.Key); | ||
256 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /// <summary> | ||
261 | /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero. | ||
262 | /// </summary> | ||
263 | [Test] | ||
264 | public void TestImplicitCastLSLFloatToBooleanTrue() | ||
265 | { | ||
266 | LSL_Types.LSLFloat testFloat; | ||
267 | bool testBool; | ||
268 | |||
269 | foreach (double number in m_doubleList) | ||
270 | { | ||
271 | testFloat = new LSL_Types.LSLFloat(number); | ||
272 | testBool = testFloat; | ||
273 | |||
274 | Assert.IsTrue(testBool); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /// <summary> | ||
279 | /// Tests LSLFloat is correctly cast implicitly to Boolean if zero. | ||
280 | /// </summary> | ||
281 | [Test] | ||
282 | public void TestImplicitCastLSLFloatToBooleanFalse() | ||
283 | { | ||
284 | LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); | ||
285 | bool testBool = testFloat; | ||
286 | |||
287 | Assert.IsFalse(testBool); | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Tests integer is correctly cast implicitly to LSLFloat. | ||
292 | /// </summary> | ||
293 | [Test] | ||
294 | public void TestImplicitCastIntToLSLFloat() | ||
295 | { | ||
296 | LSL_Types.LSLFloat testFloat; | ||
297 | |||
298 | foreach (int number in m_intList) | ||
299 | { | ||
300 | testFloat = number; | ||
301 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | /// <summary> | ||
306 | /// Tests LSLInteger is correctly cast implicitly to LSLFloat. | ||
307 | /// </summary> | ||
308 | [Test] | ||
309 | public void TestImplicitCastLSLIntegerToLSLFloat() | ||
310 | { | ||
311 | LSL_Types.LSLFloat testFloat; | ||
312 | |||
313 | foreach (int number in m_intList) | ||
314 | { | ||
315 | testFloat = new LSL_Types.LSLInteger(number); | ||
316 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Tests LSLInteger is correctly cast explicitly to LSLFloat. | ||
322 | /// </summary> | ||
323 | [Test] | ||
324 | public void TestExplicitCastLSLIntegerToLSLFloat() | ||
325 | { | ||
326 | LSL_Types.LSLFloat testFloat; | ||
327 | |||
328 | foreach (int number in m_intList) | ||
329 | { | ||
330 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number); | ||
331 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | /// <summary> | ||
336 | /// Tests string is correctly cast explicitly to LSLFloat. | ||
337 | /// </summary> | ||
338 | [Test] | ||
339 | public void TestExplicitCastStringToLSLFloat() | ||
340 | { | ||
341 | LSL_Types.LSLFloat testFloat; | ||
342 | |||
343 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
344 | { | ||
345 | testFloat = (LSL_Types.LSLFloat) number.Key; | ||
346 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | /// <summary> | ||
351 | /// Tests LSLString is correctly cast implicitly to LSLFloat. | ||
352 | /// </summary> | ||
353 | [Test] | ||
354 | public void TestExplicitCastLSLStringToLSLFloat() | ||
355 | { | ||
356 | LSL_Types.LSLFloat testFloat; | ||
357 | |||
358 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
359 | { | ||
360 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key); | ||
361 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /// <summary> | ||
366 | /// Tests double is correctly cast implicitly to LSLFloat. | ||
367 | /// </summary> | ||
368 | [Test] | ||
369 | public void TestImplicitCastDoubleToLSLFloat() | ||
370 | { | ||
371 | LSL_Types.LSLFloat testFloat; | ||
372 | |||
373 | foreach (double number in m_doubleList) | ||
374 | { | ||
375 | testFloat = number; | ||
376 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /// <summary> | ||
381 | /// Tests LSLFloat is correctly cast implicitly to double. | ||
382 | /// </summary> | ||
383 | [Test] | ||
384 | public void TestImplicitCastLSLFloatToDouble() | ||
385 | { | ||
386 | double testNumber; | ||
387 | LSL_Types.LSLFloat testFloat; | ||
388 | |||
389 | foreach (double number in m_doubleList) | ||
390 | { | ||
391 | testFloat = new LSL_Types.LSLFloat(number); | ||
392 | testNumber = testFloat; | ||
393 | |||
394 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
395 | } | ||
396 | } | ||
397 | |||
398 | /// <summary> | ||
399 | /// Tests the equality (==) operator. | ||
400 | /// </summary> | ||
401 | [Test] | ||
402 | public void TestEqualsOperator() | ||
403 | { | ||
404 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
405 | |||
406 | foreach (double number in m_doubleList) | ||
407 | { | ||
408 | testFloatA = new LSL_Types.LSLFloat(number); | ||
409 | testFloatB = new LSL_Types.LSLFloat(number); | ||
410 | Assert.IsTrue(testFloatA == testFloatB); | ||
411 | |||
412 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
413 | Assert.IsFalse(testFloatA == testFloatB); | ||
414 | } | ||
415 | } | ||
416 | |||
417 | /// <summary> | ||
418 | /// Tests the inequality (!=) operator. | ||
419 | /// </summary> | ||
420 | [Test] | ||
421 | public void TestNotEqualOperator() | ||
422 | { | ||
423 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
424 | |||
425 | foreach (double number in m_doubleList) | ||
426 | { | ||
427 | testFloatA = new LSL_Types.LSLFloat(number); | ||
428 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
429 | Assert.IsTrue(testFloatA != testFloatB); | ||
430 | |||
431 | testFloatB = new LSL_Types.LSLFloat(number); | ||
432 | Assert.IsFalse(testFloatA != testFloatB); | ||
433 | } | ||
434 | } | ||
435 | |||
436 | /// <summary> | ||
437 | /// Tests the increment operator. | ||
438 | /// </summary> | ||
439 | [Test] | ||
440 | public void TestIncrementOperator() | ||
441 | { | ||
442 | LSL_Types.LSLFloat testFloat; | ||
443 | double testNumber; | ||
444 | |||
445 | foreach (double number in m_doubleList) | ||
446 | { | ||
447 | testFloat = new LSL_Types.LSLFloat(number); | ||
448 | |||
449 | testNumber = testFloat++; | ||
450 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
451 | |||
452 | testNumber = testFloat; | ||
453 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance)); | ||
454 | |||
455 | testNumber = ++testFloat; | ||
456 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance)); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | /// <summary> | ||
461 | /// Tests the decrement operator. | ||
462 | /// </summary> | ||
463 | [Test] | ||
464 | public void TestDecrementOperator() | ||
465 | { | ||
466 | LSL_Types.LSLFloat testFloat; | ||
467 | double testNumber; | ||
468 | |||
469 | foreach (double number in m_doubleList) | ||
470 | { | ||
471 | testFloat = new LSL_Types.LSLFloat(number); | ||
472 | |||
473 | testNumber = testFloat--; | ||
474 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
475 | |||
476 | testNumber = testFloat; | ||
477 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance)); | ||
478 | |||
479 | testNumber = --testFloat; | ||
480 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance)); | ||
481 | } | ||
482 | } | ||
483 | |||
484 | /// <summary> | ||
485 | /// Tests LSLFloat.ToString(). | ||
486 | /// </summary> | ||
487 | [Test] | ||
488 | public void TestToString() | ||
489 | { | ||
490 | LSL_Types.LSLFloat testFloat; | ||
491 | |||
492 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
493 | { | ||
494 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
495 | Assert.AreEqual(number.Value, testFloat.ToString()); | ||
496 | } | ||
497 | } | ||
498 | |||
499 | /// <summary> | ||
500 | /// Tests addition of two LSLFloats. | ||
501 | /// </summary> | ||
502 | [Test] | ||
503 | public void TestAddTwoLSLFloats() | ||
504 | { | ||
505 | LSL_Types.LSLFloat testResult; | ||
506 | |||
507 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
508 | { | ||
509 | testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); | ||
510 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | /// <summary> | ||
515 | /// Tests subtraction of two LSLFloats. | ||
516 | /// </summary> | ||
517 | [Test] | ||
518 | public void TestSubtractTwoLSLFloats() | ||
519 | { | ||
520 | LSL_Types.LSLFloat testResult; | ||
521 | |||
522 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
523 | { | ||
524 | testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); | ||
525 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); | ||
526 | } | ||
527 | } | ||
528 | |||
529 | /// <summary> | ||
530 | /// Tests multiplication of two LSLFloats. | ||
531 | /// </summary> | ||
532 | [Test] | ||
533 | public void TestMultiplyTwoLSLFloats() | ||
534 | { | ||
535 | LSL_Types.LSLFloat testResult; | ||
536 | |||
537 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
538 | { | ||
539 | testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); | ||
540 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); | ||
541 | } | ||
542 | } | ||
543 | |||
544 | /// <summary> | ||
545 | /// Tests division of two LSLFloats. | ||
546 | /// </summary> | ||
547 | [Test] | ||
548 | public void TestDivideTwoLSLFloats() | ||
549 | { | ||
550 | LSL_Types.LSLFloat testResult; | ||
551 | |||
552 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
553 | { | ||
554 | if (number.Value != 0.0) // Let's avoid divide by zero. | ||
555 | { | ||
556 | testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); | ||
557 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | |||
562 | /// <summary> | ||
563 | /// Tests boolean correctly cast implicitly to LSLFloat. | ||
564 | /// </summary> | ||
565 | [Test] | ||
566 | public void TestImplicitCastBooleanToLSLFloat() | ||
567 | { | ||
568 | LSL_Types.LSLFloat testFloat; | ||
569 | |||
570 | testFloat = (1 == 0); | ||
571 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
572 | |||
573 | testFloat = (1 == 1); | ||
574 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
575 | |||
576 | testFloat = false; | ||
577 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
578 | |||
579 | testFloat = true; | ||
580 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
581 | } | ||
582 | } | ||
583 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs new file mode 100644 index 0000000..d2839db --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Common; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Common.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLInteger | ||
37 | { | ||
38 | private Dictionary<double, int> m_doubleIntSet; | ||
39 | private Dictionary<string, int> m_stringIntSet; | ||
40 | |||
41 | /// <summary> | ||
42 | /// Sets up dictionaries and arrays used in the tests. | ||
43 | /// </summary> | ||
44 | [TestFixtureSetUp] | ||
45 | public void SetUpDataSets() | ||
46 | { | ||
47 | m_doubleIntSet = new Dictionary<double, int>(); | ||
48 | m_doubleIntSet.Add(2.0, 2); | ||
49 | m_doubleIntSet.Add(-2.0, -2); | ||
50 | m_doubleIntSet.Add(0.0, 0); | ||
51 | m_doubleIntSet.Add(1.0, 1); | ||
52 | m_doubleIntSet.Add(-1.0, -1); | ||
53 | m_doubleIntSet.Add(999999999.0, 999999999); | ||
54 | m_doubleIntSet.Add(-99999999.0, -99999999); | ||
55 | |||
56 | m_stringIntSet = new Dictionary<string, int>(); | ||
57 | m_stringIntSet.Add("2", 2); | ||
58 | m_stringIntSet.Add("-2", -2); | ||
59 | m_stringIntSet.Add("0", 0); | ||
60 | m_stringIntSet.Add("1", 1); | ||
61 | m_stringIntSet.Add("-1", -1); | ||
62 | m_stringIntSet.Add("123.9", 123); | ||
63 | m_stringIntSet.Add("999999999", 999999999); | ||
64 | m_stringIntSet.Add("-99999999", -99999999); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Tests LSLFloat is correctly cast explicitly to LSLInteger. | ||
69 | /// </summary> | ||
70 | [Test] | ||
71 | public void TestExplicitCastLSLFloatToLSLInteger() | ||
72 | { | ||
73 | LSL_Types.LSLInteger testInteger; | ||
74 | |||
75 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) | ||
76 | { | ||
77 | testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key); | ||
78 | Assert.AreEqual(testInteger.value, number.Value); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// Tests string is correctly cast explicitly to LSLInteger. | ||
84 | /// </summary> | ||
85 | [Test] | ||
86 | public void TestExplicitCastStringToLSLInteger() | ||
87 | { | ||
88 | LSL_Types.LSLInteger testInteger; | ||
89 | |||
90 | foreach (KeyValuePair<string, int> number in m_stringIntSet) | ||
91 | { | ||
92 | testInteger = (LSL_Types.LSLInteger) number.Key; | ||
93 | Assert.AreEqual(testInteger.value, number.Value); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Tests LSLString is correctly cast explicitly to LSLInteger. | ||
99 | /// </summary> | ||
100 | [Test] | ||
101 | public void TestExplicitCastLSLStringToLSLInteger() | ||
102 | { | ||
103 | LSL_Types.LSLInteger testInteger; | ||
104 | |||
105 | foreach (KeyValuePair<string, int> number in m_stringIntSet) | ||
106 | { | ||
107 | testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key); | ||
108 | Assert.AreEqual(testInteger.value, number.Value); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Tests boolean correctly cast implicitly to LSLInteger. | ||
114 | /// </summary> | ||
115 | [Test] | ||
116 | public void TestImplicitCastBooleanToLSLInteger() | ||
117 | { | ||
118 | LSL_Types.LSLInteger testInteger; | ||
119 | |||
120 | testInteger = (1 == 0); | ||
121 | Assert.AreEqual(0, testInteger.value); | ||
122 | |||
123 | testInteger = (1 == 1); | ||
124 | Assert.AreEqual(1, testInteger.value); | ||
125 | |||
126 | testInteger = false; | ||
127 | Assert.AreEqual(0, testInteger.value); | ||
128 | |||
129 | testInteger = true; | ||
130 | Assert.AreEqual(1, testInteger.value); | ||
131 | } | ||
132 | } | ||
133 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs new file mode 100644 index 0000000..3aa52cb --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Common; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Common.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLString | ||
37 | { | ||
38 | private Dictionary<double, string> m_doubleStringSet; | ||
39 | |||
40 | /// <summary> | ||
41 | /// Sets up dictionaries and arrays used in the tests. | ||
42 | /// </summary> | ||
43 | [TestFixtureSetUp] | ||
44 | public void SetUpDataSets() | ||
45 | { | ||
46 | m_doubleStringSet = new Dictionary<double, string>(); | ||
47 | m_doubleStringSet.Add(2, "2.000000"); | ||
48 | m_doubleStringSet.Add(-2, "-2.000000"); | ||
49 | m_doubleStringSet.Add(0, "0.000000"); | ||
50 | m_doubleStringSet.Add(1, "1.000000"); | ||
51 | m_doubleStringSet.Add(-1, "-1.000000"); | ||
52 | m_doubleStringSet.Add(999999999, "999999999.000000"); | ||
53 | m_doubleStringSet.Add(-99999999, "-99999999.000000"); | ||
54 | m_doubleStringSet.Add(0.5, "0.500000"); | ||
55 | m_doubleStringSet.Add(0.0005, "0.000500"); | ||
56 | m_doubleStringSet.Add(0.6805, "0.680500"); | ||
57 | m_doubleStringSet.Add(-0.5, "-0.500000"); | ||
58 | m_doubleStringSet.Add(-0.0005, "-0.000500"); | ||
59 | m_doubleStringSet.Add(-0.6805, "-0.680500"); | ||
60 | m_doubleStringSet.Add(548.5, "548.500000"); | ||
61 | m_doubleStringSet.Add(2.0005, "2.000500"); | ||
62 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); | ||
63 | m_doubleStringSet.Add(-548.5, "-548.500000"); | ||
64 | m_doubleStringSet.Add(-2.0005, "-2.000500"); | ||
65 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Tests constructing a LSLString from an LSLFloat. | ||
70 | /// </summary> | ||
71 | [Test] | ||
72 | public void TestConstructFromLSLFloat() | ||
73 | { | ||
74 | LSL_Types.LSLString testString; | ||
75 | |||
76 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
77 | { | ||
78 | testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key)); | ||
79 | Assert.AreEqual(number.Value, testString.m_string); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Tests constructing a LSLString from an LSLFloat. | ||
85 | /// </summary> | ||
86 | [Test] | ||
87 | public void TestExplicitCastLSLFloatToLSLString() | ||
88 | { | ||
89 | LSL_Types.LSLString testString; | ||
90 | |||
91 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
92 | { | ||
93 | testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key); | ||
94 | Assert.AreEqual(number.Value, testString.m_string); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /// <summary> | ||
99 | /// Test constructing a Quaternion from a string. | ||
100 | /// </summary> | ||
101 | [Test] | ||
102 | public void TestExplicitCastLSLStringToQuaternion() | ||
103 | { | ||
104 | string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>"; | ||
105 | LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString); | ||
106 | |||
107 | LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711); | ||
108 | LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString; | ||
109 | LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString; | ||
110 | |||
111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); | ||
112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); | ||
113 | } | ||
114 | |||
115 | /// <summary> | ||
116 | /// Tests boolean correctly cast explicitly to LSLString. | ||
117 | /// </summary> | ||
118 | [Test] | ||
119 | public void TestImplicitCastBooleanToLSLFloat() | ||
120 | { | ||
121 | LSL_Types.LSLString testString; | ||
122 | |||
123 | testString = (LSL_Types.LSLString) (1 == 0); | ||
124 | Assert.AreEqual("0", testString.m_string); | ||
125 | |||
126 | testString = (LSL_Types.LSLString) (1 == 1); | ||
127 | Assert.AreEqual("1", testString.m_string); | ||
128 | |||
129 | testString = (LSL_Types.LSLString) false; | ||
130 | Assert.AreEqual("0", testString.m_string); | ||
131 | |||
132 | testString = (LSL_Types.LSLString) true; | ||
133 | Assert.AreEqual("1", testString.m_string); | ||
134 | } | ||
135 | } | ||
136 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestList.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestList.cs new file mode 100644 index 0000000..e63200e --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestList.cs | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Common; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Common.Tests | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Tests the LSL_Types.list class. | ||
37 | /// </summary> | ||
38 | [TestFixture] | ||
39 | public class LSL_TypesTestList | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Tests concatenating a string to a list. | ||
43 | /// </summary> | ||
44 | [Test] | ||
45 | public void TestConcatenateString() | ||
46 | { | ||
47 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
48 | testList += "addition"; | ||
49 | |||
50 | Assert.AreEqual(4, testList.Length); | ||
51 | Assert.AreEqual("addition", testList.Data[3]); | ||
52 | Assert.AreEqual(typeof(System.String), testList.Data[3].GetType()); | ||
53 | |||
54 | LSL_Types.list secondTestList = testList + "more"; | ||
55 | |||
56 | Assert.AreEqual(5, secondTestList.Length); | ||
57 | Assert.AreEqual("more", secondTestList.Data[4]); | ||
58 | Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType()); | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Tests concatenating an integer to a list. | ||
63 | /// </summary> | ||
64 | [Test] | ||
65 | public void TestConcatenateInteger() | ||
66 | { | ||
67 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
68 | testList += 20; | ||
69 | |||
70 | Assert.AreEqual(4, testList.Length); | ||
71 | Assert.AreEqual(20, testList.Data[3]); | ||
72 | Assert.AreEqual(typeof(int), testList.Data[3].GetType()); | ||
73 | |||
74 | LSL_Types.list secondTestList = testList + 2; | ||
75 | |||
76 | Assert.AreEqual(5, secondTestList.Length); | ||
77 | Assert.AreEqual(2, secondTestList.Data[4]); | ||
78 | Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType()); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Tests concatenating a double to a list. | ||
83 | /// </summary> | ||
84 | [Test] | ||
85 | public void TestConcatenateDouble() | ||
86 | { | ||
87 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
88 | testList += 2.0; | ||
89 | |||
90 | Assert.AreEqual(4, testList.Length); | ||
91 | Assert.AreEqual(2.0, testList.Data[3]); | ||
92 | Assert.AreEqual(typeof(double), testList.Data[3].GetType()); | ||
93 | |||
94 | LSL_Types.list secondTestList = testList + 0.04; | ||
95 | |||
96 | Assert.AreEqual(5, secondTestList.Length); | ||
97 | Assert.AreEqual(0.04, secondTestList.Data[4]); | ||
98 | Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); | ||
99 | } | ||
100 | } | ||
101 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs new file mode 100644 index 0000000..0a41f92 --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Common; | ||
32 | using vector = OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Common.Tests | ||
35 | { | ||
36 | [TestFixture] | ||
37 | public class LSL_TypesTestVector3 | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Tests for Vector3 | ||
41 | /// </summary> | ||
42 | [Test] | ||
43 | public void TestDotProduct() | ||
44 | { | ||
45 | // The numbers we test for. | ||
46 | Dictionary<string, double> expectsSet = new Dictionary<string, double>(); | ||
47 | expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0); | ||
48 | expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0); | ||
49 | |||
50 | double result; | ||
51 | string[] parts; | ||
52 | string[] delim = { "*" }; | ||
53 | |||
54 | foreach (KeyValuePair<string, double> ex in expectsSet) | ||
55 | { | ||
56 | parts = ex.Key.Split(delim, System.StringSplitOptions.None); | ||
57 | result = new vector(parts[0]) * new vector(parts[1]); | ||
58 | Assert.AreEqual(ex.Value, result); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | [Test] | ||
63 | public void TestUnaryMinusOperator() | ||
64 | { | ||
65 | Assert.AreEqual(new vector(-1, -1, -1), - (new vector(1, 1, 1))); | ||
66 | Assert.AreEqual(new vector(0, 0, 0), - (new vector(0, 0, 0))); | ||
67 | } | ||
68 | } | ||
69 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs new file mode 100644 index 0000000..10dd3fe --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs | |||
@@ -0,0 +1,1644 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Text.RegularExpressions; | ||
30 | using NUnit.Framework; | ||
31 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Tests the LSL compiler, both the code generation and transformation. | ||
37 | /// Each test has some LSL code as input and C# code as expected output. | ||
38 | /// The generated C# code is compared against the expected C# code. | ||
39 | /// </summary> | ||
40 | [TestFixture] | ||
41 | public class CSCodeGeneratorTest | ||
42 | { | ||
43 | [Test] | ||
44 | public void TestDefaultState() | ||
45 | { | ||
46 | string input = @"default | ||
47 | { | ||
48 | state_entry() | ||
49 | { | ||
50 | } | ||
51 | } | ||
52 | "; | ||
53 | string expected = @" | ||
54 | public void default_event_state_entry() | ||
55 | { | ||
56 | } | ||
57 | "; | ||
58 | |||
59 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
60 | string output = cg.Convert(input); | ||
61 | Assert.AreEqual(expected, output); | ||
62 | } | ||
63 | |||
64 | [Test] | ||
65 | public void TestCustomState() | ||
66 | { | ||
67 | string input = @"default | ||
68 | { | ||
69 | state_entry() | ||
70 | { | ||
71 | } | ||
72 | } | ||
73 | |||
74 | state another_state | ||
75 | { | ||
76 | no_sensor() | ||
77 | { | ||
78 | } | ||
79 | } | ||
80 | "; | ||
81 | string expected = @" | ||
82 | public void default_event_state_entry() | ||
83 | { | ||
84 | } | ||
85 | public void another_state_event_no_sensor() | ||
86 | { | ||
87 | } | ||
88 | "; | ||
89 | |||
90 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
91 | string output = cg.Convert(input); | ||
92 | Assert.AreEqual(expected, output); | ||
93 | } | ||
94 | |||
95 | [Test] | ||
96 | public void TestEventWithArguments() | ||
97 | { | ||
98 | string input = @"default | ||
99 | { | ||
100 | at_rot_target(integer tnum, rotation targetrot, rotation ourrot) | ||
101 | { | ||
102 | } | ||
103 | } | ||
104 | "; | ||
105 | string expected = @" | ||
106 | public void default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot) | ||
107 | { | ||
108 | } | ||
109 | "; | ||
110 | |||
111 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
112 | string output = cg.Convert(input); | ||
113 | Assert.AreEqual(expected, output); | ||
114 | } | ||
115 | |||
116 | [Test] | ||
117 | public void TestIntegerDeclaration() | ||
118 | { | ||
119 | string input = @"default | ||
120 | { | ||
121 | touch_start(integer num_detected) | ||
122 | { | ||
123 | integer x; | ||
124 | } | ||
125 | } | ||
126 | "; | ||
127 | string expected = @" | ||
128 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
129 | { | ||
130 | LSL_Types.LSLInteger x = 0; | ||
131 | } | ||
132 | "; | ||
133 | |||
134 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
135 | string output = cg.Convert(input); | ||
136 | Assert.AreEqual(expected, output); | ||
137 | } | ||
138 | |||
139 | [Test] | ||
140 | public void TestAssignments() | ||
141 | { | ||
142 | string input = @"default | ||
143 | { | ||
144 | touch_start(integer num_detected) | ||
145 | { | ||
146 | string y; | ||
147 | integer x = 14; | ||
148 | y = ""Hello""; | ||
149 | } | ||
150 | } | ||
151 | "; | ||
152 | string expected = @" | ||
153 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
154 | { | ||
155 | LSL_Types.LSLString y = """"; | ||
156 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14); | ||
157 | y = new LSL_Types.LSLString(""Hello""); | ||
158 | } | ||
159 | "; | ||
160 | |||
161 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
162 | string output = cg.Convert(input); | ||
163 | Assert.AreEqual(expected, output); | ||
164 | } | ||
165 | |||
166 | [Test] | ||
167 | public void TestAdditionSubtractionOperator() | ||
168 | { | ||
169 | string input = @"default | ||
170 | { | ||
171 | touch_start(integer num_detected) | ||
172 | { | ||
173 | integer y = -3; | ||
174 | integer x = 14 + 6; | ||
175 | y = 12 +45+20+x + 23 + 1 + x + y; | ||
176 | y = 12 + -45 + - 20 + x + 23 + -1 + x + y; | ||
177 | } | ||
178 | } | ||
179 | "; | ||
180 | string expected = @" | ||
181 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
182 | { | ||
183 | LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3); | ||
184 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6); | ||
185 | y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1) + x + y; | ||
186 | y = new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + -new LSL_Types.LSLInteger(1) + x + y; | ||
187 | } | ||
188 | "; | ||
189 | |||
190 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
191 | string output = cg.Convert(input); | ||
192 | Assert.AreEqual(expected, output); | ||
193 | } | ||
194 | |||
195 | [Test] | ||
196 | public void TestStrings() | ||
197 | { | ||
198 | string input = @"default | ||
199 | { | ||
200 | touch_start(integer num_detected) | ||
201 | { | ||
202 | llOwnerSay(""Testing, 1, 2, 3""); | ||
203 | llSay(0, ""I can hear you!""); | ||
204 | some_custom_function(1, 2, 3 + x, 4, ""five"", ""arguments""); | ||
205 | } | ||
206 | } | ||
207 | "; | ||
208 | string expected = @" | ||
209 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
210 | { | ||
211 | llOwnerSay(new LSL_Types.LSLString(""Testing, 1, 2, 3"")); | ||
212 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""I can hear you!"")); | ||
213 | some_custom_function(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3) + x, new LSL_Types.LSLInteger(4), new LSL_Types.LSLString(""five""), new LSL_Types.LSLString(""arguments"")); | ||
214 | } | ||
215 | "; | ||
216 | |||
217 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
218 | string output = cg.Convert(input); | ||
219 | Assert.AreEqual(expected, output); | ||
220 | } | ||
221 | |||
222 | [Test] | ||
223 | public void TestBinaryExpression() | ||
224 | { | ||
225 | string input = @"default | ||
226 | { | ||
227 | touch_start(integer num_detected) | ||
228 | { | ||
229 | integer y; | ||
230 | integer x = 14 + 6; | ||
231 | y = 12 - 3; | ||
232 | y = 12 * 3; | ||
233 | y = 12 / 3; | ||
234 | y = 12 | 3; | ||
235 | y = 12 & 3; | ||
236 | y = 12 % 3; | ||
237 | y = 12 + 45 - 20 * x / 23 | 1 & x + y; | ||
238 | } | ||
239 | } | ||
240 | "; | ||
241 | string expected = @" | ||
242 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
243 | { | ||
244 | LSL_Types.LSLInteger y = 0; | ||
245 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6); | ||
246 | y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3); | ||
247 | y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3); | ||
248 | y = new LSL_Types.LSLInteger(12) / new LSL_Types.LSLInteger(3); | ||
249 | y = new LSL_Types.LSLInteger(12) | new LSL_Types.LSLInteger(3); | ||
250 | y = new LSL_Types.LSLInteger(12) & new LSL_Types.LSLInteger(3); | ||
251 | y = new LSL_Types.LSLInteger(12) % new LSL_Types.LSLInteger(3); | ||
252 | y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) - new LSL_Types.LSLInteger(20) * x / new LSL_Types.LSLInteger(23) | new LSL_Types.LSLInteger(1) & x + y; | ||
253 | } | ||
254 | "; | ||
255 | |||
256 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
257 | string output = cg.Convert(input); | ||
258 | Assert.AreEqual(expected, output); | ||
259 | } | ||
260 | |||
261 | [Test] | ||
262 | public void TestFloatConstants() | ||
263 | { | ||
264 | string input = @"default | ||
265 | { | ||
266 | touch_start(integer num_detected) | ||
267 | { | ||
268 | float y = 1.1; | ||
269 | y = 1.123E3; | ||
270 | y = 1.123e3; | ||
271 | y = 1.123E+3; | ||
272 | y = 1.123e+3; | ||
273 | y = 1.123E-3; | ||
274 | y = 1.123e-3; | ||
275 | y = .4; | ||
276 | y = -1.123E3; | ||
277 | y = -1.123e3; | ||
278 | y = -1.123E+3; | ||
279 | y = -1.123e+3; | ||
280 | y = -1.123E-3; | ||
281 | y = -1.123e-3; | ||
282 | y = -.4; | ||
283 | y = 12.3 + -1.45E3 - 1.20e-2; | ||
284 | } | ||
285 | } | ||
286 | "; | ||
287 | string expected = @" | ||
288 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
289 | { | ||
290 | LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.1); | ||
291 | y = new LSL_Types.LSLFloat(1.123E3); | ||
292 | y = new LSL_Types.LSLFloat(1.123e3); | ||
293 | y = new LSL_Types.LSLFloat(1.123E+3); | ||
294 | y = new LSL_Types.LSLFloat(1.123e+3); | ||
295 | y = new LSL_Types.LSLFloat(1.123E-3); | ||
296 | y = new LSL_Types.LSLFloat(1.123e-3); | ||
297 | y = new LSL_Types.LSLFloat(.4); | ||
298 | y = -new LSL_Types.LSLFloat(1.123E3); | ||
299 | y = -new LSL_Types.LSLFloat(1.123e3); | ||
300 | y = -new LSL_Types.LSLFloat(1.123E+3); | ||
301 | y = -new LSL_Types.LSLFloat(1.123e+3); | ||
302 | y = -new LSL_Types.LSLFloat(1.123E-3); | ||
303 | y = -new LSL_Types.LSLFloat(1.123e-3); | ||
304 | y = -new LSL_Types.LSLFloat(.4); | ||
305 | y = new LSL_Types.LSLFloat(12.3) + -new LSL_Types.LSLFloat(1.45E3) - new LSL_Types.LSLFloat(1.20e-2); | ||
306 | } | ||
307 | "; | ||
308 | |||
309 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
310 | string output = cg.Convert(input); | ||
311 | Assert.AreEqual(expected, output); | ||
312 | } | ||
313 | |||
314 | [Test] | ||
315 | public void TestComments() | ||
316 | { | ||
317 | string input = @"// this test tests comments | ||
318 | default | ||
319 | { | ||
320 | touch_start(integer num_detected) // this should be stripped | ||
321 | { | ||
322 | // fill in code here... | ||
323 | } | ||
324 | } | ||
325 | "; | ||
326 | string expected = @" | ||
327 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
328 | { | ||
329 | } | ||
330 | "; | ||
331 | |||
332 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
333 | string output = cg.Convert(input); | ||
334 | Assert.AreEqual(expected, output); | ||
335 | } | ||
336 | |||
337 | [Test] | ||
338 | public void TestStringsWithEscapedQuotesAndComments() | ||
339 | { | ||
340 | string input = @"// this test tests strings, with escaped quotes and comments in strings | ||
341 | default | ||
342 | { | ||
343 | touch_start(integer num_detected) | ||
344 | { | ||
345 | string s1 = ""this is a string.""; | ||
346 | string s2 = ""this is a string ""+""with an escaped \"" inside it.""; | ||
347 | s1 = s2+"" and this ""+""is a string with // comments.""; | ||
348 | |||
349 | string onemore = ""[\^@]""; | ||
350 | |||
351 | string multiline = ""Good evening Sir, | ||
352 | my name is Steve. | ||
353 | I come from a rough area. | ||
354 | I used to be addicted to crack | ||
355 | but now I am off it and trying to stay clean. | ||
356 | That is why I am selling magazine subscriptions.""; // http://www.imdb.com/title/tt0151804/quotes | ||
357 | } | ||
358 | } | ||
359 | "; | ||
360 | string expected = @" | ||
361 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
362 | { | ||
363 | LSL_Types.LSLString s1 = new LSL_Types.LSLString(""this is a string.""); | ||
364 | LSL_Types.LSLString s2 = new LSL_Types.LSLString(""this is a string "") + new LSL_Types.LSLString(""with an escaped \"" inside it.""); | ||
365 | s1 = s2 + new LSL_Types.LSLString("" and this "") + new LSL_Types.LSLString(""is a string with // comments.""); | ||
366 | LSL_Types.LSLString onemore = new LSL_Types.LSLString(""[\^@]""); | ||
367 | LSL_Types.LSLString multiline = new LSL_Types.LSLString(""Good evening Sir,\n my name is Steve.\n I come from a rough area.\n I used to be addicted to crack\n but now I am off it and trying to stay clean.\n That is why I am selling magazine subscriptions.""); | ||
368 | } | ||
369 | "; | ||
370 | |||
371 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
372 | string output = cg.Convert(input); | ||
373 | Assert.AreEqual(expected, output); | ||
374 | } | ||
375 | |||
376 | [Test] | ||
377 | public void TestGlobalDefinedFunctions() | ||
378 | { | ||
379 | string input = @"// this test tests custom defined functions | ||
380 | |||
381 | string onefunc() | ||
382 | { | ||
383 | return ""Hi from onefunc()!""; | ||
384 | } | ||
385 | |||
386 | twofunc(string s) | ||
387 | { | ||
388 | llSay(1000, s); | ||
389 | } | ||
390 | |||
391 | default | ||
392 | { | ||
393 | touch_start(integer num_detected) | ||
394 | { | ||
395 | llSay(2000, onefunc()); | ||
396 | twofunc(); | ||
397 | } | ||
398 | } | ||
399 | "; | ||
400 | string expected = @" | ||
401 | LSL_Types.LSLString onefunc() | ||
402 | { | ||
403 | return new LSL_Types.LSLString(""Hi from onefunc()!""); | ||
404 | } | ||
405 | void twofunc(LSL_Types.LSLString s) | ||
406 | { | ||
407 | llSay(new LSL_Types.LSLInteger(1000), s); | ||
408 | } | ||
409 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
410 | { | ||
411 | llSay(new LSL_Types.LSLInteger(2000), onefunc()); | ||
412 | twofunc(); | ||
413 | } | ||
414 | "; | ||
415 | |||
416 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
417 | string output = cg.Convert(input); | ||
418 | Assert.AreEqual(expected, output); | ||
419 | } | ||
420 | |||
421 | [Test] | ||
422 | public void TestGlobalDeclaredVariables() | ||
423 | { | ||
424 | string input = @"// this test tests custom defined functions and global variables | ||
425 | |||
426 | string globalString; | ||
427 | integer globalInt = 14; | ||
428 | integer anotherGlobal = 20 * globalInt; | ||
429 | |||
430 | string onefunc() | ||
431 | { | ||
432 | globalString = "" ...and the global!""; | ||
433 | return ""Hi "" + | ||
434 | ""from "" + | ||
435 | ""onefunc()!"" + globalString; | ||
436 | } | ||
437 | |||
438 | twofunc(string s) | ||
439 | { | ||
440 | llSay(1000, s); | ||
441 | } | ||
442 | |||
443 | default | ||
444 | { | ||
445 | touch_start(integer num_detected) | ||
446 | { | ||
447 | llSay(2000, onefunc()); | ||
448 | twofunc(); | ||
449 | } | ||
450 | } | ||
451 | "; | ||
452 | string expected = @" | ||
453 | LSL_Types.LSLString globalString = """"; | ||
454 | LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14); | ||
455 | LSL_Types.LSLInteger anotherGlobal = new LSL_Types.LSLInteger(20) * globalInt; | ||
456 | LSL_Types.LSLString onefunc() | ||
457 | { | ||
458 | globalString = new LSL_Types.LSLString("" ...and the global!""); | ||
459 | return new LSL_Types.LSLString(""Hi "") + new LSL_Types.LSLString(""from "") + new LSL_Types.LSLString(""onefunc()!"") + globalString; | ||
460 | } | ||
461 | void twofunc(LSL_Types.LSLString s) | ||
462 | { | ||
463 | llSay(new LSL_Types.LSLInteger(1000), s); | ||
464 | } | ||
465 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
466 | { | ||
467 | llSay(new LSL_Types.LSLInteger(2000), onefunc()); | ||
468 | twofunc(); | ||
469 | } | ||
470 | "; | ||
471 | |||
472 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
473 | string output = cg.Convert(input); | ||
474 | Assert.AreEqual(expected, output); | ||
475 | } | ||
476 | |||
477 | [Test] | ||
478 | public void TestMoreAssignments() | ||
479 | { | ||
480 | string input = @"// this test tests +=, -=, *=, /=, %= | ||
481 | |||
482 | string globalString; | ||
483 | integer globalInt = 14; | ||
484 | |||
485 | string onefunc(string addition) | ||
486 | { | ||
487 | globalInt -= 2; | ||
488 | |||
489 | globalString += addition; | ||
490 | return ""Hi "" + | ||
491 | ""from "" + | ||
492 | ""onefunc()! "" + globalString; | ||
493 | } | ||
494 | |||
495 | default | ||
496 | { | ||
497 | touch_start(integer num_detected) | ||
498 | { | ||
499 | llSay(2000, onefunc()); | ||
500 | |||
501 | integer x = 2; | ||
502 | x *= 3; | ||
503 | x /= 14 + -2; | ||
504 | x %= 10; | ||
505 | } | ||
506 | } | ||
507 | "; | ||
508 | string expected = @" | ||
509 | LSL_Types.LSLString globalString = """"; | ||
510 | LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14); | ||
511 | LSL_Types.LSLString onefunc(LSL_Types.LSLString addition) | ||
512 | { | ||
513 | globalInt -= new LSL_Types.LSLInteger(2); | ||
514 | globalString += addition; | ||
515 | return new LSL_Types.LSLString(""Hi "") + new LSL_Types.LSLString(""from "") + new LSL_Types.LSLString(""onefunc()! "") + globalString; | ||
516 | } | ||
517 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
518 | { | ||
519 | llSay(new LSL_Types.LSLInteger(2000), onefunc()); | ||
520 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2); | ||
521 | x *= new LSL_Types.LSLInteger(3); | ||
522 | x /= new LSL_Types.LSLInteger(14) + -new LSL_Types.LSLInteger(2); | ||
523 | x %= new LSL_Types.LSLInteger(10); | ||
524 | } | ||
525 | "; | ||
526 | |||
527 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
528 | string output = cg.Convert(input); | ||
529 | Assert.AreEqual(expected, output); | ||
530 | } | ||
531 | |||
532 | [Test] | ||
533 | public void TestVectorConstantNotation() | ||
534 | { | ||
535 | string input = @"default | ||
536 | { | ||
537 | touch_start(integer num_detected) | ||
538 | { | ||
539 | vector y = <1.2, llGetMeAFloat(), 4.4>; | ||
540 | rotation x = <0.1, 0.1, one + 2, 0.9>; | ||
541 | |||
542 | y = <0.1, 0.1, 1.1 - three - two+eight*8>; | ||
543 | } | ||
544 | } | ||
545 | "; | ||
546 | string expected = @" | ||
547 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
548 | { | ||
549 | LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4)); | ||
550 | LSL_Types.Quaternion x = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), one + new LSL_Types.LSLInteger(2), new LSL_Types.LSLFloat(0.9)); | ||
551 | y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(1.1) - three - two + eight * new LSL_Types.LSLInteger(8)); | ||
552 | } | ||
553 | "; | ||
554 | |||
555 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
556 | string output = cg.Convert(input); | ||
557 | Assert.AreEqual(expected, output); | ||
558 | } | ||
559 | |||
560 | [Test] | ||
561 | public void TestVectorMemberAccess() | ||
562 | { | ||
563 | string input = @"default | ||
564 | { | ||
565 | touch_start(integer num_detected) | ||
566 | { | ||
567 | vector y = <1.2, llGetMeAFloat(), 4.4>; | ||
568 | x = y.x + 1.1; | ||
569 | y.x = 1.1; | ||
570 | } | ||
571 | } | ||
572 | "; | ||
573 | string expected = @" | ||
574 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
575 | { | ||
576 | LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4)); | ||
577 | x = y.x + new LSL_Types.LSLFloat(1.1); | ||
578 | y.x = new LSL_Types.LSLFloat(1.1); | ||
579 | } | ||
580 | "; | ||
581 | |||
582 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
583 | string output = cg.Convert(input); | ||
584 | Assert.AreEqual(expected, output); | ||
585 | } | ||
586 | |||
587 | [Test] | ||
588 | public void TestExpressionInParentheses() | ||
589 | { | ||
590 | string input = @"default | ||
591 | { | ||
592 | touch_start(integer num_detected) | ||
593 | { | ||
594 | integer y = -3; | ||
595 | integer x = 14 + 6; | ||
596 | y = 12 +45+20+x + (23 + 1) + x + y; | ||
597 | y = (12 + -45 + -20 + x + 23 )+ -1 + x + y; | ||
598 | } | ||
599 | } | ||
600 | "; | ||
601 | string expected = @" | ||
602 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
603 | { | ||
604 | LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3); | ||
605 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6); | ||
606 | y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + x + y; | ||
607 | y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x + y; | ||
608 | } | ||
609 | "; | ||
610 | |||
611 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
612 | string output = cg.Convert(input); | ||
613 | Assert.AreEqual(expected, output); | ||
614 | } | ||
615 | |||
616 | [Test] | ||
617 | public void TestIncrementDecrementOperator() | ||
618 | { | ||
619 | string input = @"// here we'll test the ++ and -- operators | ||
620 | |||
621 | default | ||
622 | { | ||
623 | touch_start(integer num_detected) | ||
624 | { | ||
625 | integer y = -3; | ||
626 | integer x = 14 + 6; | ||
627 | y = 12 +45+20+x++ + (23 + 1) + ++x + -- y; | ||
628 | y = (12 + -45 + -20 + x-- + 23 )+ -1 + x -- + ++y; | ||
629 | } | ||
630 | } | ||
631 | "; | ||
632 | string expected = @" | ||
633 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
634 | { | ||
635 | LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3); | ||
636 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6); | ||
637 | y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x++ + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + ++x + --y; | ||
638 | y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x-- + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x-- + ++y; | ||
639 | } | ||
640 | "; | ||
641 | |||
642 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
643 | string output = cg.Convert(input); | ||
644 | Assert.AreEqual(expected, output); | ||
645 | } | ||
646 | |||
647 | [Test] | ||
648 | public void TestLists() | ||
649 | { | ||
650 | string input = @"// testing lists | ||
651 | |||
652 | default | ||
653 | { | ||
654 | touch_start(integer num_detected) | ||
655 | { | ||
656 | list l = []; | ||
657 | list m = [1, two, ""three"", <4.0, 4.0, 4.0>, 5 + 5]; | ||
658 | llCallSomeFunc(1, llAnotherFunc(), [1, 2, 3]); | ||
659 | } | ||
660 | } | ||
661 | "; | ||
662 | string expected = @" | ||
663 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
664 | { | ||
665 | LSL_Types.list l = new LSL_Types.list(); | ||
666 | LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), two, new LSL_Types.LSLString(""three""), new LSL_Types.Vector3(new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0)), new LSL_Types.LSLInteger(5) + new LSL_Types.LSLInteger(5)); | ||
667 | llCallSomeFunc(new LSL_Types.LSLInteger(1), llAnotherFunc(), new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3))); | ||
668 | } | ||
669 | "; | ||
670 | |||
671 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
672 | string output = cg.Convert(input); | ||
673 | Assert.AreEqual(expected, output); | ||
674 | } | ||
675 | |||
676 | [Test] | ||
677 | public void TestIfStatement() | ||
678 | { | ||
679 | string input = @"// let's test if statements | ||
680 | |||
681 | default | ||
682 | { | ||
683 | touch_start(integer num_detected) | ||
684 | { | ||
685 | integer x = 1; | ||
686 | |||
687 | if (x) llSay(0, ""Hello""); | ||
688 | if (1) | ||
689 | { | ||
690 | llSay(0, ""Hi""); | ||
691 | integer r = 3; | ||
692 | return; | ||
693 | } | ||
694 | |||
695 | if (f(x)) llSay(0, ""f(x) is true""); | ||
696 | else llSay(0, ""f(x) is false""); | ||
697 | |||
698 | if (x + y) llSay(0, ""x + y is true""); | ||
699 | else if (y - x) llSay(0, ""y - x is true""); | ||
700 | else llSay(0, ""Who needs x and y anyway?""); | ||
701 | |||
702 | if (x * y) llSay(0, ""x * y is true""); | ||
703 | else if (y / x) | ||
704 | { | ||
705 | llSay(0, ""uh-oh, y / x is true, exiting""); | ||
706 | return; | ||
707 | } | ||
708 | else llSay(0, ""Who needs x and y anyway?""); | ||
709 | |||
710 | // and now for my last trick | ||
711 | if (x % y) llSay(0, ""x is true""); | ||
712 | else if (y & x) llSay(0, ""y is true""); | ||
713 | else if (z | x) llSay(0, ""z is true""); | ||
714 | else if (a * (b + x)) llSay(0, ""a is true""); | ||
715 | else if (b) llSay(0, ""b is true""); | ||
716 | else if (v) llSay(0, ""v is true""); | ||
717 | else llSay(0, ""Everything is lies!""); | ||
718 | } | ||
719 | } | ||
720 | "; | ||
721 | string expected = @" | ||
722 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
723 | { | ||
724 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
725 | if (x) | ||
726 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Hello"")); | ||
727 | if (new LSL_Types.LSLInteger(1)) | ||
728 | { | ||
729 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Hi"")); | ||
730 | LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3); | ||
731 | return ; | ||
732 | } | ||
733 | if (f(x)) | ||
734 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""f(x) is true"")); | ||
735 | else | ||
736 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""f(x) is false"")); | ||
737 | if (x + y) | ||
738 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x + y is true"")); | ||
739 | else | ||
740 | if (y - x) | ||
741 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""y - x is true"")); | ||
742 | else | ||
743 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Who needs x and y anyway?"")); | ||
744 | if (x * y) | ||
745 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x * y is true"")); | ||
746 | else | ||
747 | if (y / x) | ||
748 | { | ||
749 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""uh-oh, y / x is true, exiting"")); | ||
750 | return ; | ||
751 | } | ||
752 | else | ||
753 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Who needs x and y anyway?"")); | ||
754 | if (x % y) | ||
755 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is true"")); | ||
756 | else | ||
757 | if (y & x) | ||
758 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""y is true"")); | ||
759 | else | ||
760 | if (z | x) | ||
761 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""z is true"")); | ||
762 | else | ||
763 | if (a * (b + x)) | ||
764 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""a is true"")); | ||
765 | else | ||
766 | if (b) | ||
767 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""b is true"")); | ||
768 | else | ||
769 | if (v) | ||
770 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""v is true"")); | ||
771 | else | ||
772 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Everything is lies!"")); | ||
773 | } | ||
774 | "; | ||
775 | |||
776 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
777 | string output = cg.Convert(input); | ||
778 | Assert.AreEqual(expected, output); | ||
779 | } | ||
780 | |||
781 | [Test] | ||
782 | public void TestIfElseStatement() | ||
783 | { | ||
784 | string input = @"// let's test complex logical expressions | ||
785 | |||
786 | default | ||
787 | { | ||
788 | touch_start(integer num_detected) | ||
789 | { | ||
790 | integer x = 1; | ||
791 | integer y = 0; | ||
792 | |||
793 | if (x && y) llSay(0, ""Hello""); | ||
794 | if (x || y) | ||
795 | { | ||
796 | llSay(0, ""Hi""); | ||
797 | integer r = 3; | ||
798 | return; | ||
799 | } | ||
800 | |||
801 | if (x && y || z) llSay(0, ""x is true""); | ||
802 | else llSay(0, ""x is false""); | ||
803 | |||
804 | if (x == y) llSay(0, ""x is true""); | ||
805 | else if (y < x) llSay(0, ""y is true""); | ||
806 | else llSay(0, ""Who needs x and y anyway?""); | ||
807 | |||
808 | if (x > y) llSay(0, ""x is true""); | ||
809 | else if (y <= x) | ||
810 | { | ||
811 | llSay(0, ""uh-oh, y is true, exiting""); | ||
812 | return; | ||
813 | } | ||
814 | else llSay(0, ""Who needs x and y anyway?""); | ||
815 | |||
816 | // and now for my last trick | ||
817 | if (x >= y) llSay(0, ""x is true""); | ||
818 | else if (y != x) llSay(0, ""y is true""); | ||
819 | else if (!z) llSay(0, ""z is true""); | ||
820 | else if (!(a && b)) llSay(0, ""a is true""); | ||
821 | else if (b) llSay(0, ""b is true""); | ||
822 | else if (v) llSay(0, ""v is true""); | ||
823 | else llSay(0, ""Everything is lies!""); | ||
824 | } | ||
825 | } | ||
826 | "; | ||
827 | string expected = @" | ||
828 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
829 | { | ||
830 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
831 | LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0); | ||
832 | if (x && y) | ||
833 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Hello"")); | ||
834 | if (x || y) | ||
835 | { | ||
836 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Hi"")); | ||
837 | LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3); | ||
838 | return ; | ||
839 | } | ||
840 | if (x && y || z) | ||
841 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is true"")); | ||
842 | else | ||
843 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is false"")); | ||
844 | if (x == y) | ||
845 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is true"")); | ||
846 | else | ||
847 | if (y < x) | ||
848 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""y is true"")); | ||
849 | else | ||
850 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Who needs x and y anyway?"")); | ||
851 | if (x > y) | ||
852 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is true"")); | ||
853 | else | ||
854 | if (y <= x) | ||
855 | { | ||
856 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""uh-oh, y is true, exiting"")); | ||
857 | return ; | ||
858 | } | ||
859 | else | ||
860 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Who needs x and y anyway?"")); | ||
861 | if (x >= y) | ||
862 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""x is true"")); | ||
863 | else | ||
864 | if (y != x) | ||
865 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""y is true"")); | ||
866 | else | ||
867 | if (!z) | ||
868 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""z is true"")); | ||
869 | else | ||
870 | if (!(a && b)) | ||
871 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""a is true"")); | ||
872 | else | ||
873 | if (b) | ||
874 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""b is true"")); | ||
875 | else | ||
876 | if (v) | ||
877 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""v is true"")); | ||
878 | else | ||
879 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Everything is lies!"")); | ||
880 | } | ||
881 | "; | ||
882 | |||
883 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
884 | string output = cg.Convert(input); | ||
885 | Assert.AreEqual(expected, output); | ||
886 | } | ||
887 | |||
888 | [Test] | ||
889 | public void TestWhileLoop() | ||
890 | { | ||
891 | string input = @"// let's test while loops | ||
892 | |||
893 | default | ||
894 | { | ||
895 | touch_start(integer num_detected) | ||
896 | { | ||
897 | integer x = 1; | ||
898 | integer y = 0; | ||
899 | |||
900 | while (x) llSay(0, ""To infinity, and beyond!""); | ||
901 | while (0 || (x && 0)) | ||
902 | { | ||
903 | llSay(0, ""Never say never.""); | ||
904 | return; | ||
905 | } | ||
906 | } | ||
907 | } | ||
908 | "; | ||
909 | string expected = @" | ||
910 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
911 | { | ||
912 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
913 | LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0); | ||
914 | while (x) | ||
915 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""To infinity, and beyond!"")); | ||
916 | while (new LSL_Types.LSLInteger(0) || (x && new LSL_Types.LSLInteger(0))) | ||
917 | { | ||
918 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Never say never."")); | ||
919 | return ; | ||
920 | } | ||
921 | } | ||
922 | "; | ||
923 | |||
924 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
925 | string output = cg.Convert(input); | ||
926 | Assert.AreEqual(expected, output); | ||
927 | } | ||
928 | |||
929 | [Test] | ||
930 | public void TestDoWhileLoop() | ||
931 | { | ||
932 | string input = @"// let's test do-while loops | ||
933 | |||
934 | default | ||
935 | { | ||
936 | touch_start(integer num_detected) | ||
937 | { | ||
938 | integer x = 1; | ||
939 | integer y = 0; | ||
940 | |||
941 | do llSay(0, ""And we're doing...""); | ||
942 | while (x); | ||
943 | |||
944 | do | ||
945 | { | ||
946 | llSay(0, ""I like it here. I wish we could stay here forever.""); | ||
947 | y--; | ||
948 | } while (y); | ||
949 | } | ||
950 | } | ||
951 | "; | ||
952 | string expected = @" | ||
953 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
954 | { | ||
955 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
956 | LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0); | ||
957 | do | ||
958 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""And we're doing..."")); | ||
959 | while (x); | ||
960 | do | ||
961 | { | ||
962 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""I like it here. I wish we could stay here forever."")); | ||
963 | y--; | ||
964 | } | ||
965 | while (y); | ||
966 | } | ||
967 | "; | ||
968 | |||
969 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
970 | string output = cg.Convert(input); | ||
971 | Assert.AreEqual(expected, output); | ||
972 | } | ||
973 | |||
974 | [Test] | ||
975 | public void TestForLoop() | ||
976 | { | ||
977 | string input = @"// let's test for loops | ||
978 | |||
979 | default | ||
980 | { | ||
981 | touch_start(integer num_detected) | ||
982 | { | ||
983 | integer x = 1; | ||
984 | integer y = 0; | ||
985 | |||
986 | for (x = 10; x >= 0; x--) | ||
987 | { | ||
988 | llOwnerSay(""Launch in T minus "" + x); | ||
989 | IncreaseRocketPower(); | ||
990 | } | ||
991 | |||
992 | for (x = 0, y = 6; y > 0 && x != y; x++, y--) llOwnerSay(""Hi "" + x + "", "" + y); | ||
993 | for (x = 0, y = 6; ! y; x++,y--) llOwnerSay(""Hi "" + x + "", "" + y); | ||
994 | } | ||
995 | } | ||
996 | "; | ||
997 | string expected = @" | ||
998 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
999 | { | ||
1000 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
1001 | LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0); | ||
1002 | for (x = new LSL_Types.LSLInteger(10); x >= new LSL_Types.LSLInteger(0); x--) | ||
1003 | { | ||
1004 | llOwnerSay(new LSL_Types.LSLString(""Launch in T minus "") + x); | ||
1005 | IncreaseRocketPower(); | ||
1006 | } | ||
1007 | for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); y > new LSL_Types.LSLInteger(0) && x != y; x++, y--) | ||
1008 | llOwnerSay(new LSL_Types.LSLString(""Hi "") + x + new LSL_Types.LSLString("", "") + y); | ||
1009 | for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); !y; x++, y--) | ||
1010 | llOwnerSay(new LSL_Types.LSLString(""Hi "") + x + new LSL_Types.LSLString("", "") + y); | ||
1011 | } | ||
1012 | "; | ||
1013 | |||
1014 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1015 | string output = cg.Convert(input); | ||
1016 | Assert.AreEqual(expected, output); | ||
1017 | } | ||
1018 | |||
1019 | [Test] | ||
1020 | public void TestFloatsWithTrailingDecimal() | ||
1021 | { | ||
1022 | string input = @"// a curious feature of LSL that allows floats to be defined with a trailing dot | ||
1023 | |||
1024 | default | ||
1025 | { | ||
1026 | touch_start(integer num_detected) | ||
1027 | { | ||
1028 | float y = 1.; | ||
1029 | y = 1.E3; | ||
1030 | y = 1.e3; | ||
1031 | y = 1.E+3; | ||
1032 | y = 1.e+3; | ||
1033 | y = 1.E-3; | ||
1034 | y = 1.e-3; | ||
1035 | y = -1.E3; | ||
1036 | y = -1.e3; | ||
1037 | y = -1.E+3; | ||
1038 | y = -1.e+3; | ||
1039 | y = -1.E-3; | ||
1040 | y = -1.e-3; | ||
1041 | y = 12. + -1.E3 - 1.e-2; | ||
1042 | vector v = <0.,0.,0.>; | ||
1043 | } | ||
1044 | } | ||
1045 | "; | ||
1046 | string expected = @" | ||
1047 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1048 | { | ||
1049 | LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.0); | ||
1050 | y = new LSL_Types.LSLFloat(1.0E3); | ||
1051 | y = new LSL_Types.LSLFloat(1.0e3); | ||
1052 | y = new LSL_Types.LSLFloat(1.0E+3); | ||
1053 | y = new LSL_Types.LSLFloat(1.0e+3); | ||
1054 | y = new LSL_Types.LSLFloat(1.0E-3); | ||
1055 | y = new LSL_Types.LSLFloat(1.0e-3); | ||
1056 | y = -new LSL_Types.LSLFloat(1.0E3); | ||
1057 | y = -new LSL_Types.LSLFloat(1.0e3); | ||
1058 | y = -new LSL_Types.LSLFloat(1.0E+3); | ||
1059 | y = -new LSL_Types.LSLFloat(1.0e+3); | ||
1060 | y = -new LSL_Types.LSLFloat(1.0E-3); | ||
1061 | y = -new LSL_Types.LSLFloat(1.0e-3); | ||
1062 | y = new LSL_Types.LSLFloat(12.0) + -new LSL_Types.LSLFloat(1.0E3) - new LSL_Types.LSLFloat(1.0e-2); | ||
1063 | LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0)); | ||
1064 | } | ||
1065 | "; | ||
1066 | |||
1067 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1068 | string output = cg.Convert(input); | ||
1069 | Assert.AreEqual(expected, output); | ||
1070 | } | ||
1071 | |||
1072 | [Test] | ||
1073 | public void TestUnaryAndBinaryOperators() | ||
1074 | { | ||
1075 | string input = @"// let's test a few more operators | ||
1076 | |||
1077 | default | ||
1078 | { | ||
1079 | touch_start(integer num_detected) | ||
1080 | { | ||
1081 | integer x = 2; | ||
1082 | integer y = 1; | ||
1083 | integer z = x ^ y; | ||
1084 | x = ~ z; | ||
1085 | x = ~(y && z); | ||
1086 | y = x >> z; | ||
1087 | z = y << x; | ||
1088 | } | ||
1089 | } | ||
1090 | "; | ||
1091 | string expected = @" | ||
1092 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1093 | { | ||
1094 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2); | ||
1095 | LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(1); | ||
1096 | LSL_Types.LSLInteger z = x ^ y; | ||
1097 | x = ~z; | ||
1098 | x = ~(y && z); | ||
1099 | y = x >> z; | ||
1100 | z = y << x; | ||
1101 | } | ||
1102 | "; | ||
1103 | |||
1104 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1105 | string output = cg.Convert(input); | ||
1106 | Assert.AreEqual(expected, output); | ||
1107 | } | ||
1108 | |||
1109 | [Test] | ||
1110 | public void TestTypecasts() | ||
1111 | { | ||
1112 | string input = @"// let's test typecasts | ||
1113 | |||
1114 | default | ||
1115 | { | ||
1116 | touch_start(integer num_detected) | ||
1117 | { | ||
1118 | string s = """"; | ||
1119 | integer x = 1; | ||
1120 | |||
1121 | s = (string) x++; | ||
1122 | s = (string) x; | ||
1123 | s = (string) <0., 0., 0.>; | ||
1124 | s = (string) <1., 1., 1., 1.>; | ||
1125 | s = (integer) ""1""; | ||
1126 | s = (string) llSomethingThatReturnsInteger(); | ||
1127 | s = (string) 134; | ||
1128 | s = (string) (x ^ y | (z && l)) + (string) (x + y - 13); | ||
1129 | llOwnerSay(""s is: "" + s); | ||
1130 | } | ||
1131 | } | ||
1132 | "; | ||
1133 | string expected = @" | ||
1134 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1135 | { | ||
1136 | LSL_Types.LSLString s = new LSL_Types.LSLString(""""); | ||
1137 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1); | ||
1138 | s = (LSL_Types.LSLString) (x++); | ||
1139 | s = (LSL_Types.LSLString) (x); | ||
1140 | s = (LSL_Types.LSLString) (new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0))); | ||
1141 | s = (LSL_Types.LSLString) (new LSL_Types.Quaternion(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0))); | ||
1142 | s = (LSL_Types.LSLInteger) (new LSL_Types.LSLString(""1"")); | ||
1143 | s = (LSL_Types.LSLString) (llSomethingThatReturnsInteger()); | ||
1144 | s = (LSL_Types.LSLString) (new LSL_Types.LSLInteger(134)); | ||
1145 | s = (LSL_Types.LSLString) (x ^ y | (z && l)) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13)); | ||
1146 | llOwnerSay(new LSL_Types.LSLString(""s is: "") + s); | ||
1147 | } | ||
1148 | "; | ||
1149 | |||
1150 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1151 | string output = cg.Convert(input); | ||
1152 | Assert.AreEqual(expected, output); | ||
1153 | } | ||
1154 | |||
1155 | [Test] | ||
1156 | public void TestStates() | ||
1157 | { | ||
1158 | string input = @"// let's test states | ||
1159 | |||
1160 | default | ||
1161 | { | ||
1162 | touch_start(integer num_detected) | ||
1163 | { | ||
1164 | llSay(0, ""Going to state 'statetwo'""); | ||
1165 | state statetwo; | ||
1166 | } | ||
1167 | } | ||
1168 | |||
1169 | state statetwo | ||
1170 | { | ||
1171 | state_entry() | ||
1172 | { | ||
1173 | llSay(0, ""Going to the default state""); | ||
1174 | state default; | ||
1175 | } | ||
1176 | } | ||
1177 | "; | ||
1178 | string expected = @" | ||
1179 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1180 | { | ||
1181 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Going to state 'statetwo'"")); | ||
1182 | state(""statetwo""); | ||
1183 | } | ||
1184 | public void statetwo_event_state_entry() | ||
1185 | { | ||
1186 | llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(""Going to the default state"")); | ||
1187 | state(""default""); | ||
1188 | } | ||
1189 | "; | ||
1190 | |||
1191 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1192 | string output = cg.Convert(input); | ||
1193 | Assert.AreEqual(expected, output); | ||
1194 | } | ||
1195 | |||
1196 | [Test] | ||
1197 | public void TestHexIntegerConstants() | ||
1198 | { | ||
1199 | string input = @"// let's test hex integers | ||
1200 | |||
1201 | default | ||
1202 | { | ||
1203 | touch_start(integer num_detected) | ||
1204 | { | ||
1205 | integer x = 0x23; | ||
1206 | integer x = 0x2f34B; | ||
1207 | integer x = 0x2F34b; | ||
1208 | integer x = 0x2F34B; | ||
1209 | integer x = 0x2f34b; | ||
1210 | } | ||
1211 | } | ||
1212 | "; | ||
1213 | string expected = @" | ||
1214 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1215 | { | ||
1216 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x23); | ||
1217 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34B); | ||
1218 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34b); | ||
1219 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34B); | ||
1220 | LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34b); | ||
1221 | } | ||
1222 | "; | ||
1223 | |||
1224 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1225 | string output = cg.Convert(input); | ||
1226 | Assert.AreEqual(expected, output); | ||
1227 | } | ||
1228 | |||
1229 | [Test] | ||
1230 | public void TestJumps() | ||
1231 | { | ||
1232 | string input = @"// let's test jumps | ||
1233 | |||
1234 | default | ||
1235 | { | ||
1236 | touch_start(integer num_detected) | ||
1237 | { | ||
1238 | jump here; | ||
1239 | llOwnerSay(""Uh oh, the jump didn't work""); | ||
1240 | @here; | ||
1241 | llOwnerSay(""After the jump""); | ||
1242 | } | ||
1243 | } | ||
1244 | "; | ||
1245 | string expected = @" | ||
1246 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1247 | { | ||
1248 | goto here; | ||
1249 | llOwnerSay(new LSL_Types.LSLString(""Uh oh, the jump didn't work"")); | ||
1250 | here: | ||
1251 | llOwnerSay(new LSL_Types.LSLString(""After the jump"")); | ||
1252 | } | ||
1253 | "; | ||
1254 | |||
1255 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1256 | string output = cg.Convert(input); | ||
1257 | Assert.AreEqual(expected, output); | ||
1258 | } | ||
1259 | |||
1260 | [Test] | ||
1261 | public void TestImplicitVariableInitialization() | ||
1262 | { | ||
1263 | string input = @"// let's test implicitly initializing variables | ||
1264 | |||
1265 | default | ||
1266 | { | ||
1267 | touch_start(integer num_detected) | ||
1268 | { | ||
1269 | integer i; integer j = 14; | ||
1270 | float f; float g = 14.0; | ||
1271 | string s; string t = ""Hi there""; | ||
1272 | list l; list m = [1, 2, 3]; | ||
1273 | vector v; vector w = <1.0, 0.1, 0.5>; | ||
1274 | rotation r; rotation u = <0.8, 0.7, 0.6, llSomeFunc()>; | ||
1275 | key k; key n = ""ping""; | ||
1276 | } | ||
1277 | } | ||
1278 | "; | ||
1279 | string expected = @" | ||
1280 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1281 | { | ||
1282 | LSL_Types.LSLInteger i = 0; | ||
1283 | LSL_Types.LSLInteger j = new LSL_Types.LSLInteger(14); | ||
1284 | LSL_Types.LSLFloat f = 0.0; | ||
1285 | LSL_Types.LSLFloat g = new LSL_Types.LSLFloat(14.0); | ||
1286 | LSL_Types.LSLString s = """"; | ||
1287 | LSL_Types.LSLString t = new LSL_Types.LSLString(""Hi there""); | ||
1288 | LSL_Types.list l = new LSL_Types.list(); | ||
1289 | LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3)); | ||
1290 | LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0); | ||
1291 | LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5)); | ||
1292 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(0.0, 0.0, 0.0, 0.0); | ||
1293 | LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc()); | ||
1294 | LSL_Types.LSLString k = """"; | ||
1295 | LSL_Types.LSLString n = new LSL_Types.LSLString(""ping""); | ||
1296 | } | ||
1297 | "; | ||
1298 | |||
1299 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1300 | string output = cg.Convert(input); | ||
1301 | Assert.AreEqual(expected, output); | ||
1302 | } | ||
1303 | |||
1304 | [Test] | ||
1305 | public void TestMultipleEqualsExpression() | ||
1306 | { | ||
1307 | string input = @"// let's test x = y = 5 type expressions | ||
1308 | |||
1309 | default | ||
1310 | { | ||
1311 | touch_start(integer num_detected) | ||
1312 | { | ||
1313 | integer x; | ||
1314 | integer y; | ||
1315 | x = y = 5; | ||
1316 | x += y -= 5; | ||
1317 | llOwnerSay(""x is: "" + (string) x + "", y is: "" + (string) y); | ||
1318 | } | ||
1319 | } | ||
1320 | "; | ||
1321 | string expected = @" | ||
1322 | public void default_event_touch_start(LSL_Types.LSLInteger num_detected) | ||
1323 | { | ||
1324 | LSL_Types.LSLInteger x = 0; | ||
1325 | LSL_Types.LSLInteger y = 0; | ||
1326 | x = y = new LSL_Types.LSLInteger(5); | ||
1327 | x += y -= new LSL_Types.LSLInteger(5); | ||
1328 | llOwnerSay(new LSL_Types.LSLString(""x is: "") + (LSL_Types.LSLString) (x) + new LSL_Types.LSLString("", y is: "") + (LSL_Types.LSLString) (y)); | ||
1329 | } | ||
1330 | "; | ||
1331 | |||
1332 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1333 | string output = cg.Convert(input); | ||
1334 | Assert.AreEqual(expected, output); | ||
1335 | } | ||
1336 | |||
1337 | [Test] | ||
1338 | public void TestUnaryExpressionLastInVectorConstant() | ||
1339 | { | ||
1340 | string input = @"// let's test unary expressions some more | ||
1341 | |||
1342 | default | ||
1343 | { | ||
1344 | state_entry() | ||
1345 | { | ||
1346 | vector v = <x,y,-0.5>; | ||
1347 | } | ||
1348 | } | ||
1349 | "; | ||
1350 | string expected = @" | ||
1351 | public void default_event_state_entry() | ||
1352 | { | ||
1353 | LSL_Types.Vector3 v = new LSL_Types.Vector3(x, y, -new LSL_Types.LSLFloat(0.5)); | ||
1354 | } | ||
1355 | "; | ||
1356 | |||
1357 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1358 | string output = cg.Convert(input); | ||
1359 | Assert.AreEqual(expected, output); | ||
1360 | } | ||
1361 | |||
1362 | [Test] | ||
1363 | public void TestVectorMemberPlusEquals() | ||
1364 | { | ||
1365 | string input = @"// let's test unary expressions some more | ||
1366 | |||
1367 | default | ||
1368 | { | ||
1369 | state_entry() | ||
1370 | { | ||
1371 | vector v = llGetPos(); | ||
1372 | v.z += 4; | ||
1373 | v.z -= 4; | ||
1374 | v.z *= 4; | ||
1375 | v.z /= 4; | ||
1376 | v.z %= 4; | ||
1377 | } | ||
1378 | } | ||
1379 | "; | ||
1380 | string expected = @" | ||
1381 | public void default_event_state_entry() | ||
1382 | { | ||
1383 | LSL_Types.Vector3 v = llGetPos(); | ||
1384 | v.z += new LSL_Types.LSLInteger(4); | ||
1385 | v.z -= new LSL_Types.LSLInteger(4); | ||
1386 | v.z *= new LSL_Types.LSLInteger(4); | ||
1387 | v.z /= new LSL_Types.LSLInteger(4); | ||
1388 | v.z %= new LSL_Types.LSLInteger(4); | ||
1389 | } | ||
1390 | "; | ||
1391 | |||
1392 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1393 | string output = cg.Convert(input); | ||
1394 | Assert.AreEqual(expected, output); | ||
1395 | } | ||
1396 | |||
1397 | [Test] | ||
1398 | public void TestWhileLoopWithNoBody() | ||
1399 | { | ||
1400 | string input = @"default | ||
1401 | { | ||
1402 | state_entry() | ||
1403 | { | ||
1404 | while (1<0); | ||
1405 | } | ||
1406 | }"; | ||
1407 | |||
1408 | string expected = @" | ||
1409 | public void default_event_state_entry() | ||
1410 | { | ||
1411 | while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0)) | ||
1412 | ; | ||
1413 | } | ||
1414 | "; | ||
1415 | |||
1416 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1417 | string output = cg.Convert(input); | ||
1418 | Assert.AreEqual(expected, output); | ||
1419 | } | ||
1420 | |||
1421 | [Test] | ||
1422 | public void TestDoWhileLoopWithNoBody() | ||
1423 | { | ||
1424 | string input = @"default | ||
1425 | { | ||
1426 | state_entry() | ||
1427 | { | ||
1428 | do; | ||
1429 | while (1<0); | ||
1430 | } | ||
1431 | }"; | ||
1432 | |||
1433 | string expected = @" | ||
1434 | public void default_event_state_entry() | ||
1435 | { | ||
1436 | do | ||
1437 | ; | ||
1438 | while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0)); | ||
1439 | } | ||
1440 | "; | ||
1441 | |||
1442 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1443 | string output = cg.Convert(input); | ||
1444 | Assert.AreEqual(expected, output); | ||
1445 | } | ||
1446 | |||
1447 | [Test] | ||
1448 | public void TestIfWithNoBody() | ||
1449 | { | ||
1450 | string input = @"default | ||
1451 | { | ||
1452 | state_entry() | ||
1453 | { | ||
1454 | if (1<0); | ||
1455 | } | ||
1456 | }"; | ||
1457 | |||
1458 | string expected = @" | ||
1459 | public void default_event_state_entry() | ||
1460 | { | ||
1461 | if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0)) | ||
1462 | ; | ||
1463 | } | ||
1464 | "; | ||
1465 | |||
1466 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1467 | string output = cg.Convert(input); | ||
1468 | Assert.AreEqual(expected, output); | ||
1469 | } | ||
1470 | |||
1471 | [Test] | ||
1472 | public void TestIfElseWithNoBody() | ||
1473 | { | ||
1474 | string input = @"default | ||
1475 | { | ||
1476 | state_entry() | ||
1477 | { | ||
1478 | if (1<0); | ||
1479 | else; | ||
1480 | } | ||
1481 | }"; | ||
1482 | |||
1483 | string expected = @" | ||
1484 | public void default_event_state_entry() | ||
1485 | { | ||
1486 | if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0)) | ||
1487 | ; | ||
1488 | else | ||
1489 | ; | ||
1490 | } | ||
1491 | "; | ||
1492 | |||
1493 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1494 | string output = cg.Convert(input); | ||
1495 | Assert.AreEqual(expected, output); | ||
1496 | } | ||
1497 | |||
1498 | [Test] | ||
1499 | public void TestForLoopWithNoBody() | ||
1500 | { | ||
1501 | string input = @"default | ||
1502 | { | ||
1503 | state_entry() | ||
1504 | { | ||
1505 | for (x = 4; 1<0; x += 2); | ||
1506 | } | ||
1507 | }"; | ||
1508 | |||
1509 | string expected = @" | ||
1510 | public void default_event_state_entry() | ||
1511 | { | ||
1512 | for (x = new LSL_Types.LSLInteger(4); new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2)) | ||
1513 | ; | ||
1514 | } | ||
1515 | "; | ||
1516 | |||
1517 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1518 | string output = cg.Convert(input); | ||
1519 | Assert.AreEqual(expected, output); | ||
1520 | } | ||
1521 | |||
1522 | [Test] | ||
1523 | public void TestAssignmentInIfWhileDoWhile() | ||
1524 | { | ||
1525 | string input = @"default | ||
1526 | { | ||
1527 | state_entry() | ||
1528 | { | ||
1529 | integer x; | ||
1530 | |||
1531 | while (x = 14) llOwnerSay(""x is: "" + (string) x); | ||
1532 | |||
1533 | if (x = 24) llOwnerSay(""x is: "" + (string) x); | ||
1534 | |||
1535 | do | ||
1536 | llOwnerSay(""x is: "" + (string) x); | ||
1537 | while (x = 44); | ||
1538 | } | ||
1539 | }"; | ||
1540 | |||
1541 | string expected = @" | ||
1542 | public void default_event_state_entry() | ||
1543 | { | ||
1544 | LSL_Types.LSLInteger x = 0; | ||
1545 | while (x = new LSL_Types.LSLInteger(14)) | ||
1546 | llOwnerSay(new LSL_Types.LSLString(""x is: "") + (LSL_Types.LSLString) (x)); | ||
1547 | if (x = new LSL_Types.LSLInteger(24)) | ||
1548 | llOwnerSay(new LSL_Types.LSLString(""x is: "") + (LSL_Types.LSLString) (x)); | ||
1549 | do | ||
1550 | llOwnerSay(new LSL_Types.LSLString(""x is: "") + (LSL_Types.LSLString) (x)); | ||
1551 | while (x = new LSL_Types.LSLInteger(44)); | ||
1552 | } | ||
1553 | "; | ||
1554 | |||
1555 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1556 | string output = cg.Convert(input); | ||
1557 | Assert.AreEqual(expected, output); | ||
1558 | } | ||
1559 | |||
1560 | [Test] | ||
1561 | public void TestLSLListHack() | ||
1562 | { | ||
1563 | string input = @"default | ||
1564 | { | ||
1565 | state_entry() | ||
1566 | { | ||
1567 | list l = [""hello""]; | ||
1568 | l = (l=[]) + l + ""world""; | ||
1569 | } | ||
1570 | }"; | ||
1571 | |||
1572 | string expected = @" | ||
1573 | public void default_event_state_entry() | ||
1574 | { | ||
1575 | LSL_Types.list l = new LSL_Types.list(new LSL_Types.LSLString(""hello"")); | ||
1576 | l = (l = new LSL_Types.list()) + l + new LSL_Types.LSLString(""world""); | ||
1577 | } | ||
1578 | "; | ||
1579 | |||
1580 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1581 | string output = cg.Convert(input); | ||
1582 | Assert.AreEqual(expected, output); | ||
1583 | } | ||
1584 | |||
1585 | [Test] | ||
1586 | [ExpectedException("Tools.CSToolsException")] | ||
1587 | public void TestSyntaxError() | ||
1588 | { | ||
1589 | string input = @"default | ||
1590 | { | ||
1591 | state_entry() | ||
1592 | { | ||
1593 | integer y | ||
1594 | } | ||
1595 | } | ||
1596 | "; | ||
1597 | try | ||
1598 | { | ||
1599 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1600 | cg.Convert(input); | ||
1601 | } | ||
1602 | catch (Tools.CSToolsException e) | ||
1603 | { | ||
1604 | // The syntax error is on line 6, char 5 (expected ';', found | ||
1605 | // '}'). | ||
1606 | Regex r = new Regex("Line ([0-9]+), char ([0-9]+)"); | ||
1607 | Match m = r.Match(e.Message); | ||
1608 | Assert.AreEqual("6", m.Groups[1].Value); | ||
1609 | Assert.AreEqual("5", m.Groups[2].Value); | ||
1610 | |||
1611 | throw; | ||
1612 | } | ||
1613 | } | ||
1614 | |||
1615 | [Test] | ||
1616 | [ExpectedException("Tools.CSToolsException")] | ||
1617 | public void TestSyntaxErrorDeclaringVariableInForLoop() | ||
1618 | { | ||
1619 | string input = @"default | ||
1620 | { | ||
1621 | state_entry() | ||
1622 | { | ||
1623 | for (integer x = 0; x < 10; x++) llOwnerSay(""x is: "" + (string) x); | ||
1624 | } | ||
1625 | } | ||
1626 | "; | ||
1627 | try | ||
1628 | { | ||
1629 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1630 | cg.Convert(input); | ||
1631 | } | ||
1632 | catch (Tools.CSToolsException e) | ||
1633 | { | ||
1634 | // The syntax error is on line 5, char 14 (Syntax error) | ||
1635 | Regex r = new Regex("Line ([0-9]+), char ([0-9]+)"); | ||
1636 | Match m = r.Match(e.Message); | ||
1637 | Assert.AreEqual("5", m.Groups[1].Value); | ||
1638 | Assert.AreEqual("14", m.Groups[2].Value); | ||
1639 | |||
1640 | throw; | ||
1641 | } | ||
1642 | } | ||
1643 | } | ||
1644 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs new file mode 100644 index 0000000..7725d8d --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using System.CodeDom.Compiler; | ||
30 | using System.Collections.Generic; | ||
31 | using Microsoft.CSharp; | ||
32 | using NUnit.Framework; | ||
33 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Tests the LSL compiler. Among other things, test that error messages | ||
39 | /// generated by the C# compiler can be mapped to prper lines/columns in | ||
40 | /// the LSL source. | ||
41 | /// </summary> | ||
42 | [TestFixture] | ||
43 | public class CompilerTest | ||
44 | { | ||
45 | private string m_testDir; | ||
46 | private CSharpCodeProvider m_CSCodeProvider; | ||
47 | private CompilerParameters m_compilerParameters; | ||
48 | private CompilerResults m_compilerResults; | ||
49 | |||
50 | /// <summary> | ||
51 | /// Creates a temporary directory where build artifacts are stored. | ||
52 | /// </summary> | ||
53 | [TestFixtureSetUp] | ||
54 | public void Init() | ||
55 | { | ||
56 | m_testDir = Path.Combine(Path.GetTempPath(), "opensim_compilerTest_" + Path.GetRandomFileName()); | ||
57 | |||
58 | if (!Directory.Exists(m_testDir)) | ||
59 | { | ||
60 | // Create the temporary directory for housing build artifacts. | ||
61 | Directory.CreateDirectory(m_testDir); | ||
62 | } | ||
63 | |||
64 | // Create a CSCodeProvider and CompilerParameters. | ||
65 | m_CSCodeProvider = new CSharpCodeProvider(); | ||
66 | m_compilerParameters = new CompilerParameters(); | ||
67 | |||
68 | string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin"); | ||
69 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); | ||
70 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); | ||
71 | m_compilerParameters.GenerateExecutable = false; | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Removes the temporary build directory and any build artifacts | ||
76 | /// inside it. | ||
77 | /// </summary> | ||
78 | [TestFixtureTearDown] | ||
79 | public void CleanUp() | ||
80 | { | ||
81 | if (Directory.Exists(m_testDir)) | ||
82 | { | ||
83 | // Blow away the temporary directory with artifacts. | ||
84 | Directory.Delete(m_testDir, true); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | /// <summary> | ||
89 | /// Test the C# compiler error message can be mapped to the correct | ||
90 | /// line/column in the LSL source when an undeclared variable is used. | ||
91 | /// </summary> | ||
92 | //[Test] | ||
93 | public void TestUseUndeclaredVariable() | ||
94 | { | ||
95 | m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); | ||
96 | |||
97 | string input = @"default | ||
98 | { | ||
99 | state_entry() | ||
100 | { | ||
101 | integer y = x + 3; | ||
102 | } | ||
103 | }"; | ||
104 | |||
105 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
106 | string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + | ||
107 | "namespace SecondLife { " + | ||
108 | "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + | ||
109 | "public Script() { } " + | ||
110 | cg.Convert(input) + | ||
111 | "} }\n"; | ||
112 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap; | ||
113 | |||
114 | m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); | ||
115 | |||
116 | Assert.AreEqual(new KeyValuePair<int, int>(5, 21), | ||
117 | positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Test that a string can be cast to string and another string | ||
122 | /// concatenated. | ||
123 | /// </summary> | ||
124 | //[Test] | ||
125 | public void TestCastAndConcatString() | ||
126 | { | ||
127 | m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); | ||
128 | |||
129 | string input = @"string s = "" a string""; | ||
130 | |||
131 | default | ||
132 | { | ||
133 | state_entry() | ||
134 | { | ||
135 | key gAvatarKey = llDetectedKey(0); | ||
136 | string tmp = (string) gAvatarKey + s; | ||
137 | llSay(0, tmp); | ||
138 | } | ||
139 | }"; | ||
140 | |||
141 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
142 | string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + | ||
143 | "namespace SecondLife { " + | ||
144 | "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + | ||
145 | "public Script() { } " + | ||
146 | cg.Convert(input) + | ||
147 | "} }\n"; | ||
148 | m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); | ||
149 | |||
150 | Assert.AreEqual(0, m_compilerResults.Errors.Count); | ||
151 | } | ||
152 | } | ||
153 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs new file mode 100644 index 0000000..272d06c --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | |||
@@ -0,0 +1,603 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLFloat | ||
37 | { | ||
38 | // Used for testing equality of two floats. | ||
39 | private double _lowPrecisionTolerance = 0.000001; | ||
40 | |||
41 | private Dictionary<int, double> m_intDoubleSet; | ||
42 | private Dictionary<double, double> m_doubleDoubleSet; | ||
43 | private Dictionary<double, int> m_doubleIntSet; | ||
44 | private Dictionary<double, int> m_doubleUintSet; | ||
45 | private Dictionary<string, double> m_stringDoubleSet; | ||
46 | private Dictionary<double, string> m_doubleStringSet; | ||
47 | private List<int> m_intList; | ||
48 | private List<double> m_doubleList; | ||
49 | |||
50 | /// <summary> | ||
51 | /// Sets up dictionaries and arrays used in the tests. | ||
52 | /// </summary> | ||
53 | [TestFixtureSetUp] | ||
54 | public void SetUpDataSets() | ||
55 | { | ||
56 | m_intDoubleSet = new Dictionary<int, double>(); | ||
57 | m_intDoubleSet.Add(2, 2.0); | ||
58 | m_intDoubleSet.Add(-2, -2.0); | ||
59 | m_intDoubleSet.Add(0, 0.0); | ||
60 | m_intDoubleSet.Add(1, 1.0); | ||
61 | m_intDoubleSet.Add(-1, -1.0); | ||
62 | m_intDoubleSet.Add(999999999, 999999999.0); | ||
63 | m_intDoubleSet.Add(-99999999, -99999999.0); | ||
64 | |||
65 | m_doubleDoubleSet = new Dictionary<double, double>(); | ||
66 | m_doubleDoubleSet.Add(2.0, 2.0); | ||
67 | m_doubleDoubleSet.Add(-2.0, -2.0); | ||
68 | m_doubleDoubleSet.Add(0.0, 0.0); | ||
69 | m_doubleDoubleSet.Add(1.0, 1.0); | ||
70 | m_doubleDoubleSet.Add(-1.0, -1.0); | ||
71 | m_doubleDoubleSet.Add(999999999.0, 999999999.0); | ||
72 | m_doubleDoubleSet.Add(-99999999.0, -99999999.0); | ||
73 | m_doubleDoubleSet.Add(0.5, 0.5); | ||
74 | m_doubleDoubleSet.Add(0.0005, 0.0005); | ||
75 | m_doubleDoubleSet.Add(0.6805, 0.6805); | ||
76 | m_doubleDoubleSet.Add(-0.5, -0.5); | ||
77 | m_doubleDoubleSet.Add(-0.0005, -0.0005); | ||
78 | m_doubleDoubleSet.Add(-0.6805, -0.6805); | ||
79 | m_doubleDoubleSet.Add(548.5, 548.5); | ||
80 | m_doubleDoubleSet.Add(2.0005, 2.0005); | ||
81 | m_doubleDoubleSet.Add(349485435.6805, 349485435.6805); | ||
82 | m_doubleDoubleSet.Add(-548.5, -548.5); | ||
83 | m_doubleDoubleSet.Add(-2.0005, -2.0005); | ||
84 | m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805); | ||
85 | |||
86 | m_doubleIntSet = new Dictionary<double, int>(); | ||
87 | m_doubleIntSet.Add(2.0, 2); | ||
88 | m_doubleIntSet.Add(-2.0, -2); | ||
89 | m_doubleIntSet.Add(0.0, 0); | ||
90 | m_doubleIntSet.Add(1.0, 1); | ||
91 | m_doubleIntSet.Add(-1.0, -1); | ||
92 | m_doubleIntSet.Add(999999999.0, 999999999); | ||
93 | m_doubleIntSet.Add(-99999999.0, -99999999); | ||
94 | m_doubleIntSet.Add(0.5, 0); | ||
95 | m_doubleIntSet.Add(0.0005, 0); | ||
96 | m_doubleIntSet.Add(0.6805, 0); | ||
97 | m_doubleIntSet.Add(-0.5, 0); | ||
98 | m_doubleIntSet.Add(-0.0005, 0); | ||
99 | m_doubleIntSet.Add(-0.6805, 0); | ||
100 | m_doubleIntSet.Add(548.5, 548); | ||
101 | m_doubleIntSet.Add(2.0005, 2); | ||
102 | m_doubleIntSet.Add(349485435.6805, 349485435); | ||
103 | m_doubleIntSet.Add(-548.5, -548); | ||
104 | m_doubleIntSet.Add(-2.0005, -2); | ||
105 | m_doubleIntSet.Add(-349485435.6805, -349485435); | ||
106 | |||
107 | m_doubleUintSet = new Dictionary<double, int>(); | ||
108 | m_doubleUintSet.Add(2.0, 2); | ||
109 | m_doubleUintSet.Add(-2.0, 2); | ||
110 | m_doubleUintSet.Add(0.0, 0); | ||
111 | m_doubleUintSet.Add(1.0, 1); | ||
112 | m_doubleUintSet.Add(-1.0, 1); | ||
113 | m_doubleUintSet.Add(999999999.0, 999999999); | ||
114 | m_doubleUintSet.Add(-99999999.0, 99999999); | ||
115 | m_doubleUintSet.Add(0.5, 0); | ||
116 | m_doubleUintSet.Add(0.0005, 0); | ||
117 | m_doubleUintSet.Add(0.6805, 0); | ||
118 | m_doubleUintSet.Add(-0.5, 0); | ||
119 | m_doubleUintSet.Add(-0.0005, 0); | ||
120 | m_doubleUintSet.Add(-0.6805, 0); | ||
121 | m_doubleUintSet.Add(548.5, 548); | ||
122 | m_doubleUintSet.Add(2.0005, 2); | ||
123 | m_doubleUintSet.Add(349485435.6805, 349485435); | ||
124 | m_doubleUintSet.Add(-548.5, 548); | ||
125 | m_doubleUintSet.Add(-2.0005, 2); | ||
126 | m_doubleUintSet.Add(-349485435.6805, 349485435); | ||
127 | |||
128 | m_stringDoubleSet = new Dictionary<string, double>(); | ||
129 | m_stringDoubleSet.Add("2", 2.0); | ||
130 | m_stringDoubleSet.Add("-2", -2.0); | ||
131 | m_stringDoubleSet.Add("1", 1.0); | ||
132 | m_stringDoubleSet.Add("-1", -1.0); | ||
133 | m_stringDoubleSet.Add("0", 0.0); | ||
134 | m_stringDoubleSet.Add("999999999.0", 999999999.0); | ||
135 | m_stringDoubleSet.Add("-99999999.0", -99999999.0); | ||
136 | m_stringDoubleSet.Add("0.5", 0.5); | ||
137 | m_stringDoubleSet.Add("0.0005", 0.0005); | ||
138 | m_stringDoubleSet.Add("0.6805", 0.6805); | ||
139 | m_stringDoubleSet.Add("-0.5", -0.5); | ||
140 | m_stringDoubleSet.Add("-0.0005", -0.0005); | ||
141 | m_stringDoubleSet.Add("-0.6805", -0.6805); | ||
142 | m_stringDoubleSet.Add("548.5", 548.5); | ||
143 | m_stringDoubleSet.Add("2.0005", 2.0005); | ||
144 | m_stringDoubleSet.Add("349485435.6805", 349485435.6805); | ||
145 | m_stringDoubleSet.Add("-548.5", -548.5); | ||
146 | m_stringDoubleSet.Add("-2.0005", -2.0005); | ||
147 | m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); | ||
148 | |||
149 | m_doubleStringSet = new Dictionary<double, string>(); | ||
150 | m_doubleStringSet.Add(2.0, "2.000000"); | ||
151 | m_doubleStringSet.Add(-2.0, "-2.000000"); | ||
152 | m_doubleStringSet.Add(1.0, "1.000000"); | ||
153 | m_doubleStringSet.Add(-1.0, "-1.000000"); | ||
154 | m_doubleStringSet.Add(0.0, "0.000000"); | ||
155 | m_doubleStringSet.Add(999999999.0, "999999999.000000"); | ||
156 | m_doubleStringSet.Add(-99999999.0, "-99999999.000000"); | ||
157 | m_doubleStringSet.Add(0.5, "0.500000"); | ||
158 | m_doubleStringSet.Add(0.0005, "0.000500"); | ||
159 | m_doubleStringSet.Add(0.6805, "0.680500"); | ||
160 | m_doubleStringSet.Add(-0.5, "-0.500000"); | ||
161 | m_doubleStringSet.Add(-0.0005, "-0.000500"); | ||
162 | m_doubleStringSet.Add(-0.6805, "-0.680500"); | ||
163 | m_doubleStringSet.Add(548.5, "548.500000"); | ||
164 | m_doubleStringSet.Add(2.0005, "2.000500"); | ||
165 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); | ||
166 | m_doubleStringSet.Add(-548.5, "-548.500000"); | ||
167 | m_doubleStringSet.Add(-2.0005, "-2.000500"); | ||
168 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); | ||
169 | |||
170 | m_doubleList = new List<double>(); | ||
171 | m_doubleList.Add(2.0); | ||
172 | m_doubleList.Add(-2.0); | ||
173 | m_doubleList.Add(1.0); | ||
174 | m_doubleList.Add(-1.0); | ||
175 | m_doubleList.Add(999999999.0); | ||
176 | m_doubleList.Add(-99999999.0); | ||
177 | m_doubleList.Add(0.5); | ||
178 | m_doubleList.Add(0.0005); | ||
179 | m_doubleList.Add(0.6805); | ||
180 | m_doubleList.Add(-0.5); | ||
181 | m_doubleList.Add(-0.0005); | ||
182 | m_doubleList.Add(-0.6805); | ||
183 | m_doubleList.Add(548.5); | ||
184 | m_doubleList.Add(2.0005); | ||
185 | m_doubleList.Add(349485435.6805); | ||
186 | m_doubleList.Add(-548.5); | ||
187 | m_doubleList.Add(-2.0005); | ||
188 | m_doubleList.Add(-349485435.6805); | ||
189 | |||
190 | m_intList = new List<int>(); | ||
191 | m_intList.Add(2); | ||
192 | m_intList.Add(-2); | ||
193 | m_intList.Add(0); | ||
194 | m_intList.Add(1); | ||
195 | m_intList.Add(-1); | ||
196 | m_intList.Add(999999999); | ||
197 | m_intList.Add(-99999999); | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Tests constructing a LSLFloat from an integer. | ||
202 | /// </summary> | ||
203 | [Test] | ||
204 | public void TestConstructFromInt() | ||
205 | { | ||
206 | LSL_Types.LSLFloat testFloat; | ||
207 | |||
208 | foreach (KeyValuePair<int, double> number in m_intDoubleSet) | ||
209 | { | ||
210 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
211 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Tests constructing a LSLFloat from a double. | ||
217 | /// </summary> | ||
218 | [Test] | ||
219 | public void TestConstructFromDouble() | ||
220 | { | ||
221 | LSL_Types.LSLFloat testFloat; | ||
222 | |||
223 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
224 | { | ||
225 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
226 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /// <summary> | ||
231 | /// Tests LSLFloat is correctly cast explicitly to integer. | ||
232 | /// </summary> | ||
233 | [Test] | ||
234 | public void TestExplicitCastLSLFloatToInt() | ||
235 | { | ||
236 | int testNumber; | ||
237 | |||
238 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) | ||
239 | { | ||
240 | testNumber = (int) new LSL_Types.LSLFloat(number.Key); | ||
241 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | /// <summary> | ||
246 | /// Tests LSLFloat is correctly cast explicitly to unsigned integer. | ||
247 | /// </summary> | ||
248 | [Test] | ||
249 | public void TestExplicitCastLSLFloatToUint() | ||
250 | { | ||
251 | uint testNumber; | ||
252 | |||
253 | foreach (KeyValuePair<double, int> number in m_doubleUintSet) | ||
254 | { | ||
255 | testNumber = (uint) new LSL_Types.LSLFloat(number.Key); | ||
256 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /// <summary> | ||
261 | /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero. | ||
262 | /// </summary> | ||
263 | [Test] | ||
264 | public void TestImplicitCastLSLFloatToBooleanTrue() | ||
265 | { | ||
266 | LSL_Types.LSLFloat testFloat; | ||
267 | bool testBool; | ||
268 | |||
269 | foreach (double number in m_doubleList) | ||
270 | { | ||
271 | testFloat = new LSL_Types.LSLFloat(number); | ||
272 | testBool = testFloat; | ||
273 | |||
274 | Assert.IsTrue(testBool); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /// <summary> | ||
279 | /// Tests LSLFloat is correctly cast implicitly to Boolean if zero. | ||
280 | /// </summary> | ||
281 | [Test] | ||
282 | public void TestImplicitCastLSLFloatToBooleanFalse() | ||
283 | { | ||
284 | LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); | ||
285 | bool testBool = testFloat; | ||
286 | |||
287 | Assert.IsFalse(testBool); | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Tests integer is correctly cast implicitly to LSLFloat. | ||
292 | /// </summary> | ||
293 | [Test] | ||
294 | public void TestImplicitCastIntToLSLFloat() | ||
295 | { | ||
296 | LSL_Types.LSLFloat testFloat; | ||
297 | |||
298 | foreach (int number in m_intList) | ||
299 | { | ||
300 | testFloat = number; | ||
301 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | /// <summary> | ||
306 | /// Tests LSLInteger is correctly cast implicitly to LSLFloat. | ||
307 | /// </summary> | ||
308 | [Test] | ||
309 | public void TestImplicitCastLSLIntegerToLSLFloat() | ||
310 | { | ||
311 | LSL_Types.LSLFloat testFloat; | ||
312 | |||
313 | foreach (int number in m_intList) | ||
314 | { | ||
315 | testFloat = new LSL_Types.LSLInteger(number); | ||
316 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Tests LSLInteger is correctly cast explicitly to LSLFloat. | ||
322 | /// </summary> | ||
323 | [Test] | ||
324 | public void TestExplicitCastLSLIntegerToLSLFloat() | ||
325 | { | ||
326 | LSL_Types.LSLFloat testFloat; | ||
327 | |||
328 | foreach (int number in m_intList) | ||
329 | { | ||
330 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number); | ||
331 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | /// <summary> | ||
336 | /// Tests string is correctly cast explicitly to LSLFloat. | ||
337 | /// </summary> | ||
338 | [Test] | ||
339 | public void TestExplicitCastStringToLSLFloat() | ||
340 | { | ||
341 | LSL_Types.LSLFloat testFloat; | ||
342 | |||
343 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
344 | { | ||
345 | testFloat = (LSL_Types.LSLFloat) number.Key; | ||
346 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | /// <summary> | ||
351 | /// Tests LSLString is correctly cast implicitly to LSLFloat. | ||
352 | /// </summary> | ||
353 | [Test] | ||
354 | public void TestExplicitCastLSLStringToLSLFloat() | ||
355 | { | ||
356 | LSL_Types.LSLFloat testFloat; | ||
357 | |||
358 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
359 | { | ||
360 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key); | ||
361 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /// <summary> | ||
366 | /// Tests double is correctly cast implicitly to LSLFloat. | ||
367 | /// </summary> | ||
368 | [Test] | ||
369 | public void TestImplicitCastDoubleToLSLFloat() | ||
370 | { | ||
371 | LSL_Types.LSLFloat testFloat; | ||
372 | |||
373 | foreach (double number in m_doubleList) | ||
374 | { | ||
375 | testFloat = number; | ||
376 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /// <summary> | ||
381 | /// Tests LSLFloat is correctly cast implicitly to double. | ||
382 | /// </summary> | ||
383 | [Test] | ||
384 | public void TestImplicitCastLSLFloatToDouble() | ||
385 | { | ||
386 | double testNumber; | ||
387 | LSL_Types.LSLFloat testFloat; | ||
388 | |||
389 | foreach (double number in m_doubleList) | ||
390 | { | ||
391 | testFloat = new LSL_Types.LSLFloat(number); | ||
392 | testNumber = testFloat; | ||
393 | |||
394 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
395 | } | ||
396 | } | ||
397 | |||
398 | /// <summary> | ||
399 | /// Tests LSLFloat is correctly cast explicitly to float | ||
400 | /// </summary> | ||
401 | [Test] | ||
402 | public void TestExplicitCastLSLFloatToFloat() | ||
403 | { | ||
404 | float testFloat; | ||
405 | float numberAsFloat; | ||
406 | LSL_Types.LSLFloat testLSLFloat; | ||
407 | foreach (double number in m_doubleList) | ||
408 | { | ||
409 | testLSLFloat = new LSL_Types.LSLFloat(number); | ||
410 | numberAsFloat = (float)number; | ||
411 | testFloat = (float)testLSLFloat; | ||
412 | |||
413 | Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); | ||
414 | } | ||
415 | } | ||
416 | |||
417 | |||
418 | /// <summary> | ||
419 | /// Tests the equality (==) operator. | ||
420 | /// </summary> | ||
421 | [Test] | ||
422 | public void TestEqualsOperator() | ||
423 | { | ||
424 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
425 | |||
426 | foreach (double number in m_doubleList) | ||
427 | { | ||
428 | testFloatA = new LSL_Types.LSLFloat(number); | ||
429 | testFloatB = new LSL_Types.LSLFloat(number); | ||
430 | Assert.IsTrue(testFloatA == testFloatB); | ||
431 | |||
432 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
433 | Assert.IsFalse(testFloatA == testFloatB); | ||
434 | } | ||
435 | } | ||
436 | |||
437 | /// <summary> | ||
438 | /// Tests the inequality (!=) operator. | ||
439 | /// </summary> | ||
440 | [Test] | ||
441 | public void TestNotEqualOperator() | ||
442 | { | ||
443 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
444 | |||
445 | foreach (double number in m_doubleList) | ||
446 | { | ||
447 | testFloatA = new LSL_Types.LSLFloat(number); | ||
448 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
449 | Assert.IsTrue(testFloatA != testFloatB); | ||
450 | |||
451 | testFloatB = new LSL_Types.LSLFloat(number); | ||
452 | Assert.IsFalse(testFloatA != testFloatB); | ||
453 | } | ||
454 | } | ||
455 | |||
456 | /// <summary> | ||
457 | /// Tests the increment operator. | ||
458 | /// </summary> | ||
459 | [Test] | ||
460 | public void TestIncrementOperator() | ||
461 | { | ||
462 | LSL_Types.LSLFloat testFloat; | ||
463 | double testNumber; | ||
464 | |||
465 | foreach (double number in m_doubleList) | ||
466 | { | ||
467 | testFloat = new LSL_Types.LSLFloat(number); | ||
468 | |||
469 | testNumber = testFloat++; | ||
470 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
471 | |||
472 | testNumber = testFloat; | ||
473 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance)); | ||
474 | |||
475 | testNumber = ++testFloat; | ||
476 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance)); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | /// <summary> | ||
481 | /// Tests the decrement operator. | ||
482 | /// </summary> | ||
483 | [Test] | ||
484 | public void TestDecrementOperator() | ||
485 | { | ||
486 | LSL_Types.LSLFloat testFloat; | ||
487 | double testNumber; | ||
488 | |||
489 | foreach (double number in m_doubleList) | ||
490 | { | ||
491 | testFloat = new LSL_Types.LSLFloat(number); | ||
492 | |||
493 | testNumber = testFloat--; | ||
494 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
495 | |||
496 | testNumber = testFloat; | ||
497 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance)); | ||
498 | |||
499 | testNumber = --testFloat; | ||
500 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance)); | ||
501 | } | ||
502 | } | ||
503 | |||
504 | /// <summary> | ||
505 | /// Tests LSLFloat.ToString(). | ||
506 | /// </summary> | ||
507 | [Test] | ||
508 | public void TestToString() | ||
509 | { | ||
510 | LSL_Types.LSLFloat testFloat; | ||
511 | |||
512 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
513 | { | ||
514 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
515 | Assert.AreEqual(number.Value, testFloat.ToString()); | ||
516 | } | ||
517 | } | ||
518 | |||
519 | /// <summary> | ||
520 | /// Tests addition of two LSLFloats. | ||
521 | /// </summary> | ||
522 | [Test] | ||
523 | public void TestAddTwoLSLFloats() | ||
524 | { | ||
525 | LSL_Types.LSLFloat testResult; | ||
526 | |||
527 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
528 | { | ||
529 | testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); | ||
530 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /// <summary> | ||
535 | /// Tests subtraction of two LSLFloats. | ||
536 | /// </summary> | ||
537 | [Test] | ||
538 | public void TestSubtractTwoLSLFloats() | ||
539 | { | ||
540 | LSL_Types.LSLFloat testResult; | ||
541 | |||
542 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
543 | { | ||
544 | testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); | ||
545 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); | ||
546 | } | ||
547 | } | ||
548 | |||
549 | /// <summary> | ||
550 | /// Tests multiplication of two LSLFloats. | ||
551 | /// </summary> | ||
552 | [Test] | ||
553 | public void TestMultiplyTwoLSLFloats() | ||
554 | { | ||
555 | LSL_Types.LSLFloat testResult; | ||
556 | |||
557 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
558 | { | ||
559 | testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); | ||
560 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); | ||
561 | } | ||
562 | } | ||
563 | |||
564 | /// <summary> | ||
565 | /// Tests division of two LSLFloats. | ||
566 | /// </summary> | ||
567 | [Test] | ||
568 | public void TestDivideTwoLSLFloats() | ||
569 | { | ||
570 | LSL_Types.LSLFloat testResult; | ||
571 | |||
572 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
573 | { | ||
574 | if (number.Value != 0.0) // Let's avoid divide by zero. | ||
575 | { | ||
576 | testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); | ||
577 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | |||
582 | /// <summary> | ||
583 | /// Tests boolean correctly cast implicitly to LSLFloat. | ||
584 | /// </summary> | ||
585 | [Test] | ||
586 | public void TestImplicitCastBooleanToLSLFloat() | ||
587 | { | ||
588 | LSL_Types.LSLFloat testFloat; | ||
589 | |||
590 | testFloat = (1 == 0); | ||
591 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
592 | |||
593 | testFloat = (1 == 1); | ||
594 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
595 | |||
596 | testFloat = false; | ||
597 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
598 | |||
599 | testFloat = true; | ||
600 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
601 | } | ||
602 | } | ||
603 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs new file mode 100644 index 0000000..f826c00 --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLInteger | ||
37 | { | ||
38 | private Dictionary<double, int> m_doubleIntSet; | ||
39 | private Dictionary<string, int> m_stringIntSet; | ||
40 | |||
41 | /// <summary> | ||
42 | /// Sets up dictionaries and arrays used in the tests. | ||
43 | /// </summary> | ||
44 | [TestFixtureSetUp] | ||
45 | public void SetUpDataSets() | ||
46 | { | ||
47 | m_doubleIntSet = new Dictionary<double, int>(); | ||
48 | m_doubleIntSet.Add(2.0, 2); | ||
49 | m_doubleIntSet.Add(-2.0, -2); | ||
50 | m_doubleIntSet.Add(0.0, 0); | ||
51 | m_doubleIntSet.Add(1.0, 1); | ||
52 | m_doubleIntSet.Add(-1.0, -1); | ||
53 | m_doubleIntSet.Add(999999999.0, 999999999); | ||
54 | m_doubleIntSet.Add(-99999999.0, -99999999); | ||
55 | |||
56 | m_stringIntSet = new Dictionary<string, int>(); | ||
57 | m_stringIntSet.Add("2", 2); | ||
58 | m_stringIntSet.Add("-2", -2); | ||
59 | m_stringIntSet.Add("0", 0); | ||
60 | m_stringIntSet.Add("1", 1); | ||
61 | m_stringIntSet.Add("-1", -1); | ||
62 | m_stringIntSet.Add("123.9", 123); | ||
63 | m_stringIntSet.Add("999999999", 999999999); | ||
64 | m_stringIntSet.Add("-99999999", -99999999); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Tests LSLFloat is correctly cast explicitly to LSLInteger. | ||
69 | /// </summary> | ||
70 | [Test] | ||
71 | public void TestExplicitCastLSLFloatToLSLInteger() | ||
72 | { | ||
73 | LSL_Types.LSLInteger testInteger; | ||
74 | |||
75 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) | ||
76 | { | ||
77 | testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key); | ||
78 | Assert.AreEqual(testInteger.value, number.Value); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// Tests string is correctly cast explicitly to LSLInteger. | ||
84 | /// </summary> | ||
85 | [Test] | ||
86 | public void TestExplicitCastStringToLSLInteger() | ||
87 | { | ||
88 | LSL_Types.LSLInteger testInteger; | ||
89 | |||
90 | foreach (KeyValuePair<string, int> number in m_stringIntSet) | ||
91 | { | ||
92 | testInteger = (LSL_Types.LSLInteger) number.Key; | ||
93 | Assert.AreEqual(testInteger.value, number.Value); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Tests LSLString is correctly cast explicitly to LSLInteger. | ||
99 | /// </summary> | ||
100 | [Test] | ||
101 | public void TestExplicitCastLSLStringToLSLInteger() | ||
102 | { | ||
103 | LSL_Types.LSLInteger testInteger; | ||
104 | |||
105 | foreach (KeyValuePair<string, int> number in m_stringIntSet) | ||
106 | { | ||
107 | testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key); | ||
108 | Assert.AreEqual(testInteger.value, number.Value); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Tests boolean correctly cast implicitly to LSLInteger. | ||
114 | /// </summary> | ||
115 | [Test] | ||
116 | public void TestImplicitCastBooleanToLSLInteger() | ||
117 | { | ||
118 | LSL_Types.LSLInteger testInteger; | ||
119 | |||
120 | testInteger = (1 == 0); | ||
121 | Assert.AreEqual(0, testInteger.value); | ||
122 | |||
123 | testInteger = (1 == 1); | ||
124 | Assert.AreEqual(1, testInteger.value); | ||
125 | |||
126 | testInteger = false; | ||
127 | Assert.AreEqual(0, testInteger.value); | ||
128 | |||
129 | testInteger = true; | ||
130 | Assert.AreEqual(1, testInteger.value); | ||
131 | } | ||
132 | } | ||
133 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs new file mode 100644 index 0000000..49e5023 --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestLSLString | ||
37 | { | ||
38 | private Dictionary<double, string> m_doubleStringSet; | ||
39 | |||
40 | /// <summary> | ||
41 | /// Sets up dictionaries and arrays used in the tests. | ||
42 | /// </summary> | ||
43 | [TestFixtureSetUp] | ||
44 | public void SetUpDataSets() | ||
45 | { | ||
46 | m_doubleStringSet = new Dictionary<double, string>(); | ||
47 | m_doubleStringSet.Add(2, "2.000000"); | ||
48 | m_doubleStringSet.Add(-2, "-2.000000"); | ||
49 | m_doubleStringSet.Add(0, "0.000000"); | ||
50 | m_doubleStringSet.Add(1, "1.000000"); | ||
51 | m_doubleStringSet.Add(-1, "-1.000000"); | ||
52 | m_doubleStringSet.Add(999999999, "999999999.000000"); | ||
53 | m_doubleStringSet.Add(-99999999, "-99999999.000000"); | ||
54 | m_doubleStringSet.Add(0.5, "0.500000"); | ||
55 | m_doubleStringSet.Add(0.0005, "0.000500"); | ||
56 | m_doubleStringSet.Add(0.6805, "0.680500"); | ||
57 | m_doubleStringSet.Add(-0.5, "-0.500000"); | ||
58 | m_doubleStringSet.Add(-0.0005, "-0.000500"); | ||
59 | m_doubleStringSet.Add(-0.6805, "-0.680500"); | ||
60 | m_doubleStringSet.Add(548.5, "548.500000"); | ||
61 | m_doubleStringSet.Add(2.0005, "2.000500"); | ||
62 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); | ||
63 | m_doubleStringSet.Add(-548.5, "-548.500000"); | ||
64 | m_doubleStringSet.Add(-2.0005, "-2.000500"); | ||
65 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Tests constructing a LSLString from an LSLFloat. | ||
70 | /// </summary> | ||
71 | [Test] | ||
72 | public void TestConstructFromLSLFloat() | ||
73 | { | ||
74 | LSL_Types.LSLString testString; | ||
75 | |||
76 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
77 | { | ||
78 | testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key)); | ||
79 | Assert.AreEqual(number.Value, testString.m_string); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Tests constructing a LSLString from an LSLFloat. | ||
85 | /// </summary> | ||
86 | [Test] | ||
87 | public void TestExplicitCastLSLFloatToLSLString() | ||
88 | { | ||
89 | LSL_Types.LSLString testString; | ||
90 | |||
91 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
92 | { | ||
93 | testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key); | ||
94 | Assert.AreEqual(number.Value, testString.m_string); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /// <summary> | ||
99 | /// Test constructing a Quaternion from a string. | ||
100 | /// </summary> | ||
101 | [Test] | ||
102 | public void TestExplicitCastLSLStringToQuaternion() | ||
103 | { | ||
104 | string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>"; | ||
105 | LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString); | ||
106 | |||
107 | LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711); | ||
108 | LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString; | ||
109 | LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString; | ||
110 | |||
111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); | ||
112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); | ||
113 | } | ||
114 | |||
115 | /// <summary> | ||
116 | /// Tests boolean correctly cast explicitly to LSLString. | ||
117 | /// </summary> | ||
118 | [Test] | ||
119 | public void TestImplicitCastBooleanToLSLFloat() | ||
120 | { | ||
121 | LSL_Types.LSLString testString; | ||
122 | |||
123 | testString = (LSL_Types.LSLString) (1 == 0); | ||
124 | Assert.AreEqual("0", testString.m_string); | ||
125 | |||
126 | testString = (LSL_Types.LSLString) (1 == 1); | ||
127 | Assert.AreEqual("1", testString.m_string); | ||
128 | |||
129 | testString = (LSL_Types.LSLString) false; | ||
130 | Assert.AreEqual("0", testString.m_string); | ||
131 | |||
132 | testString = (LSL_Types.LSLString) true; | ||
133 | Assert.AreEqual("1", testString.m_string); | ||
134 | } | ||
135 | } | ||
136 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs new file mode 100644 index 0000000..9e8d716 --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Tests the LSL_Types.list class. | ||
37 | /// </summary> | ||
38 | [TestFixture] | ||
39 | public class LSL_TypesTestList | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Tests concatenating a string to a list. | ||
43 | /// </summary> | ||
44 | [Test] | ||
45 | public void TestConcatenateString() | ||
46 | { | ||
47 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
48 | testList += "addition"; | ||
49 | |||
50 | Assert.AreEqual(4, testList.Length); | ||
51 | Assert.AreEqual("addition", testList.Data[3]); | ||
52 | Assert.AreEqual(typeof(System.String), testList.Data[3].GetType()); | ||
53 | |||
54 | LSL_Types.list secondTestList = testList + "more"; | ||
55 | |||
56 | Assert.AreEqual(5, secondTestList.Length); | ||
57 | Assert.AreEqual("more", secondTestList.Data[4]); | ||
58 | Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType()); | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Tests concatenating an integer to a list. | ||
63 | /// </summary> | ||
64 | [Test] | ||
65 | public void TestConcatenateInteger() | ||
66 | { | ||
67 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
68 | testList += 20; | ||
69 | |||
70 | Assert.AreEqual(4, testList.Length); | ||
71 | Assert.AreEqual(20, testList.Data[3]); | ||
72 | Assert.AreEqual(typeof(int), testList.Data[3].GetType()); | ||
73 | |||
74 | LSL_Types.list secondTestList = testList + 2; | ||
75 | |||
76 | Assert.AreEqual(5, secondTestList.Length); | ||
77 | Assert.AreEqual(2, secondTestList.Data[4]); | ||
78 | Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType()); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Tests concatenating a double to a list. | ||
83 | /// </summary> | ||
84 | [Test] | ||
85 | public void TestConcatenateDouble() | ||
86 | { | ||
87 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | ||
88 | testList += 2.0; | ||
89 | |||
90 | Assert.AreEqual(4, testList.Length); | ||
91 | Assert.AreEqual(2.0, testList.Data[3]); | ||
92 | Assert.AreEqual(typeof(double), testList.Data[3].GetType()); | ||
93 | |||
94 | LSL_Types.list secondTestList = testList + 0.04; | ||
95 | |||
96 | Assert.AreEqual(5, secondTestList.Length); | ||
97 | Assert.AreEqual(0.04, secondTestList.Data[4]); | ||
98 | Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Tests casting LSLInteger item to LSLInteger. | ||
103 | /// </summary> | ||
104 | [Test] | ||
105 | public void TestCastLSLIntegerItemToLSLInteger() | ||
106 | { | ||
107 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123); | ||
108 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
109 | |||
110 | Assert.AreEqual(testValue, (LSL_Types.LSLInteger)testList.Data[0]); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Tests casting LSLFloat item to LSLFloat. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestCastLSLFloatItemToLSLFloat() | ||
118 | { | ||
119 | LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987); | ||
120 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
121 | |||
122 | Assert.AreEqual(testValue, (LSL_Types.LSLFloat)testList.Data[0]); | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// Tests casting LSLString item to LSLString. | ||
127 | /// </summary> | ||
128 | [Test] | ||
129 | public void TestCastLSLStringItemToLSLString() | ||
130 | { | ||
131 | LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there"); | ||
132 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
133 | |||
134 | Assert.AreEqual(testValue, (LSL_Types.LSLString)testList.Data[0]); | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Tests casting Vector3 item to Vector3. | ||
139 | /// </summary> | ||
140 | [Test] | ||
141 | public void TestCastVector3ItemToVector3() | ||
142 | { | ||
143 | LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987); | ||
144 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
145 | |||
146 | Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]); | ||
147 | } | ||
148 | /// <summary> | ||
149 | /// Tests casting Quaternion item to Quaternion. | ||
150 | /// </summary> | ||
151 | [Test] | ||
152 | public void TestCastQuaternionItemToQuaternion() | ||
153 | { | ||
154 | LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987); | ||
155 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
156 | |||
157 | Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]); | ||
158 | } | ||
159 | |||
160 | |||
161 | } | ||
162 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs new file mode 100644 index 0000000..fb2c00c --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Tests.Common; | ||
31 | using OpenSim.Region.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class LSL_TypesTestVector3 | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Tests for Vector3 | ||
40 | /// </summary> | ||
41 | [Test] | ||
42 | |||
43 | public void TestDotProduct() | ||
44 | { | ||
45 | // The numbers we test for. | ||
46 | Dictionary<string, double> expectsSet = new Dictionary<string, double>(); | ||
47 | expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0); | ||
48 | expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0); | ||
49 | |||
50 | double result; | ||
51 | string[] parts; | ||
52 | string[] delim = { "*" }; | ||
53 | |||
54 | foreach (KeyValuePair<string, double> ex in expectsSet) | ||
55 | { | ||
56 | parts = ex.Key.Split(delim, System.StringSplitOptions.None); | ||
57 | result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]); | ||
58 | Assert.AreEqual(ex.Value, result); | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | } | ||