diff options
author | Sean Dague | 2008-09-08 20:34:45 +0000 |
---|---|---|
committer | Sean Dague | 2008-09-08 20:34:45 +0000 |
commit | ce0a8d7beffccbaeb6b603a96b7729278c4c9e75 (patch) | |
tree | faccd65637c0dab11b2dd787c8985cd7f2c9452b /OpenSim/Tests/Region | |
parent | Fix component order on a quaternion for the sit target. This caused (diff) | |
download | opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.zip opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.gz opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.bz2 opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.xz |
changes to Test directory structure per opensim-dev conversation
Diffstat (limited to 'OpenSim/Tests/Region')
12 files changed, 0 insertions, 3975 deletions
diff --git a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs deleted file mode 100644 index d89bb87..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs +++ /dev/null | |||
@@ -1,583 +0,0 @@ | |||
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 deleted file mode 100644 index d2839db..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
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 deleted file mode 100644 index 3aa52cb..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
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 deleted file mode 100644 index e63200e..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestList.cs +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
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 deleted file mode 100644 index 0a41f92..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
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 deleted file mode 100644 index fefcada..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs +++ /dev/null | |||
@@ -1,1605 +0,0 @@ | |||
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 | "\n public void default_event_state_entry()" + | ||
55 | "\n {" + | ||
56 | "\n }\n"; | ||
57 | |||
58 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
59 | string output = cg.Convert(input); | ||
60 | Assert.AreEqual(expected, output); | ||
61 | } | ||
62 | |||
63 | [Test] | ||
64 | public void TestCustomState() | ||
65 | { | ||
66 | string input = @"default | ||
67 | { | ||
68 | state_entry() | ||
69 | { | ||
70 | } | ||
71 | } | ||
72 | |||
73 | state another_state | ||
74 | { | ||
75 | no_sensor() | ||
76 | { | ||
77 | } | ||
78 | } | ||
79 | "; | ||
80 | string expected = | ||
81 | "\n public void default_event_state_entry()" + | ||
82 | "\n {" + | ||
83 | "\n }" + | ||
84 | "\n public void another_state_event_no_sensor()" + | ||
85 | "\n {" + | ||
86 | "\n }\n"; | ||
87 | |||
88 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
89 | string output = cg.Convert(input); | ||
90 | Assert.AreEqual(expected, output); | ||
91 | } | ||
92 | |||
93 | [Test] | ||
94 | public void TestEventWithArguments() | ||
95 | { | ||
96 | string input = @"default | ||
97 | { | ||
98 | at_rot_target(integer tnum, rotation targetrot, rotation ourrot) | ||
99 | { | ||
100 | } | ||
101 | } | ||
102 | "; | ||
103 | string expected = | ||
104 | "\n public void default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)" + | ||
105 | "\n {" + | ||
106 | "\n }\n"; | ||
107 | |||
108 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
109 | string output = cg.Convert(input); | ||
110 | Assert.AreEqual(expected, output); | ||
111 | } | ||
112 | |||
113 | [Test] | ||
114 | public void TestIntegerDeclaration() | ||
115 | { | ||
116 | string input = @"default | ||
117 | { | ||
118 | touch_start(integer num_detected) | ||
119 | { | ||
120 | integer x; | ||
121 | } | ||
122 | } | ||
123 | "; | ||
124 | string expected = | ||
125 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
126 | "\n {" + | ||
127 | "\n LSL_Types.LSLInteger x = 0;" + | ||
128 | "\n }\n"; | ||
129 | |||
130 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
131 | string output = cg.Convert(input); | ||
132 | Assert.AreEqual(expected, output); | ||
133 | } | ||
134 | |||
135 | [Test] | ||
136 | public void TestAssignments() | ||
137 | { | ||
138 | string input = @"default | ||
139 | { | ||
140 | touch_start(integer num_detected) | ||
141 | { | ||
142 | string y; | ||
143 | integer x = 14; | ||
144 | y = ""Hello""; | ||
145 | } | ||
146 | } | ||
147 | "; | ||
148 | string expected = | ||
149 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
150 | "\n {" + | ||
151 | "\n LSL_Types.LSLString y = \"\";" + | ||
152 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14);" + | ||
153 | "\n y = new LSL_Types.LSLString(\"Hello\");" + | ||
154 | "\n }\n"; | ||
155 | |||
156 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
157 | string output = cg.Convert(input); | ||
158 | Assert.AreEqual(expected, output); | ||
159 | } | ||
160 | |||
161 | [Test] | ||
162 | public void TestAdditionSubtractionOperator() | ||
163 | { | ||
164 | string input = @"default | ||
165 | { | ||
166 | touch_start(integer num_detected) | ||
167 | { | ||
168 | integer y = -3; | ||
169 | integer x = 14 + 6; | ||
170 | y = 12 +45+20+x + 23 + 1 + x + y; | ||
171 | y = 12 + -45 + - 20 + x + 23 + -1 + x + y; | ||
172 | } | ||
173 | } | ||
174 | "; | ||
175 | string expected = | ||
176 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)\n" + | ||
177 | " {\n" + | ||
178 | " LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);\n" + | ||
179 | " LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);\n" + | ||
180 | " 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;\n" + | ||
181 | " 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;\n" + | ||
182 | " }\n"; | ||
183 | |||
184 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
185 | string output = cg.Convert(input); | ||
186 | Assert.AreEqual(expected, output); | ||
187 | } | ||
188 | |||
189 | [Test] | ||
190 | public void TestStrings() | ||
191 | { | ||
192 | string input = @"default | ||
193 | { | ||
194 | touch_start(integer num_detected) | ||
195 | { | ||
196 | llOwnerSay(""Testing, 1, 2, 3""); | ||
197 | llSay(0, ""I can hear you!""); | ||
198 | some_custom_function(1, 2, 3 +x, 4, ""five"", ""arguments""); | ||
199 | } | ||
200 | } | ||
201 | "; | ||
202 | string expected = | ||
203 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
204 | "\n {" + | ||
205 | "\n llOwnerSay(new LSL_Types.LSLString(\"Testing, 1, 2, 3\"));" + | ||
206 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I can hear you!\"));" + | ||
207 | "\n 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\"));" + | ||
208 | "\n }" + | ||
209 | "\n"; | ||
210 | |||
211 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
212 | string output = cg.Convert(input); | ||
213 | Assert.AreEqual(expected, output); | ||
214 | } | ||
215 | |||
216 | [Test] | ||
217 | public void TestBinaryExpression() | ||
218 | { | ||
219 | string input = @"default | ||
220 | { | ||
221 | touch_start(integer num_detected) | ||
222 | { | ||
223 | integer y; | ||
224 | integer x = 14 + 6; | ||
225 | y = 12 - 3; | ||
226 | y = 12 * 3; | ||
227 | y = 12 / 3; | ||
228 | y = 12 | 3; | ||
229 | y = 12 & 3; | ||
230 | y = 12 % 3; | ||
231 | y = 12 + 45 - 20 * x / 23 | 1 & x + y; | ||
232 | } | ||
233 | } | ||
234 | "; | ||
235 | string expected = | ||
236 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
237 | "\n {" + | ||
238 | "\n LSL_Types.LSLInteger y = 0;" + | ||
239 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" + | ||
240 | "\n y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3);" + | ||
241 | "\n y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3);" + | ||
242 | "\n y = new LSL_Types.LSLInteger(12) / new LSL_Types.LSLInteger(3);" + | ||
243 | "\n y = new LSL_Types.LSLInteger(12) | new LSL_Types.LSLInteger(3);" + | ||
244 | "\n y = new LSL_Types.LSLInteger(12) & new LSL_Types.LSLInteger(3);" + | ||
245 | "\n y = new LSL_Types.LSLInteger(12) % new LSL_Types.LSLInteger(3);" + | ||
246 | "\n 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;" + | ||
247 | "\n }\n"; | ||
248 | |||
249 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
250 | string output = cg.Convert(input); | ||
251 | Assert.AreEqual(expected, output); | ||
252 | } | ||
253 | |||
254 | [Test] | ||
255 | public void TestFloatConstants() | ||
256 | { | ||
257 | string input = @"default | ||
258 | { | ||
259 | touch_start(integer num_detected) | ||
260 | { | ||
261 | float y = 1.1; | ||
262 | y = 1.123E3; | ||
263 | y = 1.123e3; | ||
264 | y = 1.123E+3; | ||
265 | y = 1.123e+3; | ||
266 | y = 1.123E-3; | ||
267 | y = 1.123e-3; | ||
268 | y = .4; | ||
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 = 12.3 + -1.45E3 - 1.20e-2; | ||
277 | } | ||
278 | } | ||
279 | "; | ||
280 | string expected = | ||
281 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
282 | "\n {" + | ||
283 | "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.1);" + | ||
284 | "\n y = new LSL_Types.LSLFloat(1.123E3);" + | ||
285 | "\n y = new LSL_Types.LSLFloat(1.123e3);" + | ||
286 | "\n y = new LSL_Types.LSLFloat(1.123E+3);" + | ||
287 | "\n y = new LSL_Types.LSLFloat(1.123e+3);" + | ||
288 | "\n y = new LSL_Types.LSLFloat(1.123E-3);" + | ||
289 | "\n y = new LSL_Types.LSLFloat(1.123e-3);" + | ||
290 | "\n y = new LSL_Types.LSLFloat(.4);" + | ||
291 | "\n y = -new LSL_Types.LSLFloat(1.123E3);" + | ||
292 | "\n y = -new LSL_Types.LSLFloat(1.123e3);" + | ||
293 | "\n y = -new LSL_Types.LSLFloat(1.123E+3);" + | ||
294 | "\n y = -new LSL_Types.LSLFloat(1.123e+3);" + | ||
295 | "\n y = -new LSL_Types.LSLFloat(1.123E-3);" + | ||
296 | "\n y = -new LSL_Types.LSLFloat(1.123e-3);" + | ||
297 | "\n y = -new LSL_Types.LSLFloat(.4);" + | ||
298 | "\n y = new LSL_Types.LSLFloat(12.3) + -new LSL_Types.LSLFloat(1.45E3) - new LSL_Types.LSLFloat(1.20e-2);" + | ||
299 | "\n }\n"; | ||
300 | |||
301 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
302 | string output = cg.Convert(input); | ||
303 | Assert.AreEqual(expected, output); | ||
304 | } | ||
305 | |||
306 | [Test] | ||
307 | public void TestComments() | ||
308 | { | ||
309 | string input = @"// this test tests comments | ||
310 | default | ||
311 | { | ||
312 | touch_start(integer num_detected) // this should be stripped | ||
313 | { | ||
314 | // fill in code here... | ||
315 | } | ||
316 | } | ||
317 | "; | ||
318 | string expected = | ||
319 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
320 | "\n {" + | ||
321 | "\n }\n"; | ||
322 | |||
323 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
324 | string output = cg.Convert(input); | ||
325 | Assert.AreEqual(expected, output); | ||
326 | } | ||
327 | |||
328 | [Test] | ||
329 | public void TestStringsWithEscapedQuotesAndComments() | ||
330 | { | ||
331 | string input = @"// this test tests strings, with escaped quotes and comments in strings | ||
332 | default | ||
333 | { | ||
334 | touch_start(integer num_detected) | ||
335 | { | ||
336 | string s1 = ""this is a string.""; | ||
337 | string s2 = ""this is a string ""+""with an escaped \"" inside it.""; | ||
338 | s1 = s2+"" and this ""+""is a string with // comments.""; | ||
339 | |||
340 | string onemore = ""[\^@]""; | ||
341 | |||
342 | string multiline = ""Good evening Sir, | ||
343 | my name is Steve. | ||
344 | I come from a rough area. | ||
345 | I used to be addicted to crack | ||
346 | but now I am off it and trying to stay clean. | ||
347 | That is why I am selling magazine subscriptions.""; // http://www.imdb.com/title/tt0151804/quotes | ||
348 | } | ||
349 | } | ||
350 | "; | ||
351 | |||
352 | string expected = | ||
353 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
354 | "\n {" + | ||
355 | "\n LSL_Types.LSLString s1 = new LSL_Types.LSLString(\"this is a string.\");" + | ||
356 | "\n LSL_Types.LSLString s2 = new LSL_Types.LSLString(\"this is a string \") + new LSL_Types.LSLString(\"with an escaped \\\" inside it.\");" + | ||
357 | "\n s1 = s2 + new LSL_Types.LSLString(\" and this \") + new LSL_Types.LSLString(\"is a string with // comments.\");" + | ||
358 | "\n LSL_Types.LSLString onemore = new LSL_Types.LSLString(\"[\\^@]\");" + | ||
359 | "\n 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.\");" + | ||
360 | "\n }\n"; | ||
361 | |||
362 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
363 | string output = cg.Convert(input); | ||
364 | Assert.AreEqual(expected, output); | ||
365 | } | ||
366 | |||
367 | [Test] | ||
368 | public void TestGlobalDefinedFunctions() | ||
369 | { | ||
370 | string input = @"// this test tests custom defined functions | ||
371 | |||
372 | string onefunc() | ||
373 | { | ||
374 | return ""Hi from onefunc()!""; | ||
375 | } | ||
376 | |||
377 | twofunc(string s) | ||
378 | { | ||
379 | llSay(1000, s); | ||
380 | } | ||
381 | |||
382 | default | ||
383 | { | ||
384 | touch_start(integer num_detected) | ||
385 | { | ||
386 | llSay(2000, onefunc()); | ||
387 | twofunc(); | ||
388 | } | ||
389 | } | ||
390 | "; | ||
391 | string expected = | ||
392 | "\n LSL_Types.LSLString onefunc()" + | ||
393 | "\n {" + | ||
394 | "\n return new LSL_Types.LSLString(\"Hi from onefunc()!\");" + | ||
395 | "\n }" + | ||
396 | "\n void twofunc(LSL_Types.LSLString s)" + | ||
397 | "\n {" + | ||
398 | "\n llSay(new LSL_Types.LSLInteger(1000), s);" + | ||
399 | "\n }" + | ||
400 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
401 | "\n {" + | ||
402 | "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" + | ||
403 | "\n twofunc();" + | ||
404 | "\n }\n"; | ||
405 | |||
406 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
407 | string output = cg.Convert(input); | ||
408 | Assert.AreEqual(expected, output); | ||
409 | } | ||
410 | |||
411 | [Test] | ||
412 | public void TestGlobalDeclaredVariables() | ||
413 | { | ||
414 | string input = @"// this test tests custom defined functions and global variables | ||
415 | |||
416 | string globalString; | ||
417 | integer globalInt = 14; | ||
418 | integer anotherGlobal = 20 * globalInt; | ||
419 | |||
420 | string onefunc() | ||
421 | { | ||
422 | globalString = "" ...and the global!""; | ||
423 | return ""Hi "" + | ||
424 | ""from "" + | ||
425 | ""onefunc()!"" + globalString; | ||
426 | } | ||
427 | |||
428 | twofunc(string s) | ||
429 | { | ||
430 | llSay(1000, s); | ||
431 | } | ||
432 | |||
433 | default | ||
434 | { | ||
435 | touch_start(integer num_detected) | ||
436 | { | ||
437 | llSay(2000, onefunc()); | ||
438 | twofunc(); | ||
439 | } | ||
440 | } | ||
441 | "; | ||
442 | string expected = | ||
443 | "\n LSL_Types.LSLString globalString = \"\";" + | ||
444 | "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" + | ||
445 | "\n LSL_Types.LSLInteger anotherGlobal = new LSL_Types.LSLInteger(20) * globalInt;" + | ||
446 | "\n LSL_Types.LSLString onefunc()" + | ||
447 | "\n {" + | ||
448 | "\n globalString = new LSL_Types.LSLString(\" ...and the global!\");" + | ||
449 | "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()!\") + globalString;" + | ||
450 | "\n }" + | ||
451 | "\n void twofunc(LSL_Types.LSLString s)" + | ||
452 | "\n {" + | ||
453 | "\n llSay(new LSL_Types.LSLInteger(1000), s);" + | ||
454 | "\n }" + | ||
455 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
456 | "\n {" + | ||
457 | "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" + | ||
458 | "\n twofunc();" + | ||
459 | "\n }\n"; | ||
460 | |||
461 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
462 | string output = cg.Convert(input); | ||
463 | Assert.AreEqual(expected, output); | ||
464 | } | ||
465 | |||
466 | [Test] | ||
467 | public void TestMoreAssignments() | ||
468 | { | ||
469 | string input = @"// this test tests +=, -=, *=, /=, %= | ||
470 | |||
471 | string globalString; | ||
472 | integer globalInt = 14; | ||
473 | |||
474 | string onefunc(string addition) | ||
475 | { | ||
476 | globalInt -= 2; | ||
477 | |||
478 | globalString += addition; | ||
479 | return ""Hi "" + | ||
480 | ""from "" + | ||
481 | ""onefunc()! "" + globalString; | ||
482 | } | ||
483 | |||
484 | default | ||
485 | { | ||
486 | touch_start(integer num_detected) | ||
487 | { | ||
488 | llSay(2000, onefunc()); | ||
489 | |||
490 | integer x = 2; | ||
491 | x *= 3; | ||
492 | x /= 14 + -2; | ||
493 | x %= 10; | ||
494 | } | ||
495 | } | ||
496 | "; | ||
497 | string expected = | ||
498 | "\n LSL_Types.LSLString globalString = \"\";" + | ||
499 | "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" + | ||
500 | "\n LSL_Types.LSLString onefunc(LSL_Types.LSLString addition)" + | ||
501 | "\n {" + | ||
502 | "\n globalInt -= new LSL_Types.LSLInteger(2);" + | ||
503 | "\n globalString += addition;" + | ||
504 | "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()! \") + globalString;" + | ||
505 | "\n }" + | ||
506 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
507 | "\n {" + | ||
508 | "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" + | ||
509 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" + | ||
510 | "\n x *= new LSL_Types.LSLInteger(3);" + | ||
511 | "\n x /= new LSL_Types.LSLInteger(14) + -new LSL_Types.LSLInteger(2);" + | ||
512 | "\n x %= new LSL_Types.LSLInteger(10);" + | ||
513 | "\n }\n"; | ||
514 | |||
515 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
516 | string output = cg.Convert(input); | ||
517 | Assert.AreEqual(expected, output); | ||
518 | } | ||
519 | |||
520 | [Test] | ||
521 | public void TestVectorConstantNotation() | ||
522 | { | ||
523 | string input = @"default | ||
524 | { | ||
525 | touch_start(integer num_detected) | ||
526 | { | ||
527 | vector y = <1.2, llGetMeAFloat(), 4.4>; | ||
528 | rotation x = <0.1, 0.1, one + 2, 0.9>; | ||
529 | |||
530 | y = <0.1, 0.1, 1.1 - three - two+eight*8>; | ||
531 | } | ||
532 | } | ||
533 | "; | ||
534 | string expected = | ||
535 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
536 | "\n {" + | ||
537 | "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" + | ||
538 | "\n 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));" + | ||
539 | "\n 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));" + | ||
540 | "\n }\n"; | ||
541 | |||
542 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
543 | string output = cg.Convert(input); | ||
544 | Assert.AreEqual(expected, output); | ||
545 | } | ||
546 | |||
547 | [Test] | ||
548 | public void TestVectorMemberAccess() | ||
549 | { | ||
550 | string input = @"default | ||
551 | { | ||
552 | touch_start(integer num_detected) | ||
553 | { | ||
554 | vector y = <1.2, llGetMeAFloat(), 4.4>; | ||
555 | x = y.x + 1.1; | ||
556 | y.x = 1.1; | ||
557 | } | ||
558 | } | ||
559 | "; | ||
560 | string expected = | ||
561 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
562 | "\n {" + | ||
563 | "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" + | ||
564 | "\n x = y.x + new LSL_Types.LSLFloat(1.1);" + | ||
565 | "\n y.x = new LSL_Types.LSLFloat(1.1);" + | ||
566 | "\n }\n"; | ||
567 | |||
568 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
569 | string output = cg.Convert(input); | ||
570 | Assert.AreEqual(expected, output); | ||
571 | } | ||
572 | |||
573 | [Test] | ||
574 | public void TestExpressionInParentheses() | ||
575 | { | ||
576 | string input = @"default | ||
577 | { | ||
578 | touch_start(integer num_detected) | ||
579 | { | ||
580 | integer y = -3; | ||
581 | integer x = 14 + 6; | ||
582 | y = 12 +45+20+x + (23 + 1) + x + y; | ||
583 | y = (12 + -45 + -20 + x + 23 )+ -1 + x + y; | ||
584 | } | ||
585 | } | ||
586 | "; | ||
587 | string expected = | ||
588 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
589 | "\n {" + | ||
590 | "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" + | ||
591 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" + | ||
592 | "\n 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;" + | ||
593 | "\n 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;" + | ||
594 | "\n }\n"; | ||
595 | |||
596 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
597 | string output = cg.Convert(input); | ||
598 | Assert.AreEqual(expected, output); | ||
599 | } | ||
600 | |||
601 | [Test] | ||
602 | public void TestIncrementDecrementOperator() | ||
603 | { | ||
604 | string input = @"// here we'll test the ++ and -- operators | ||
605 | |||
606 | default | ||
607 | { | ||
608 | touch_start(integer num_detected) | ||
609 | { | ||
610 | integer y = -3; | ||
611 | integer x = 14 + 6; | ||
612 | y = 12 +45+20+x++ + (23 + 1) + ++x + -- y; | ||
613 | y = (12 + -45 + -20 + x-- + 23 )+ -1 + x -- + ++y; | ||
614 | } | ||
615 | } | ||
616 | "; | ||
617 | string expected = | ||
618 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
619 | "\n {" + | ||
620 | "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" + | ||
621 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" + | ||
622 | "\n 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;" + | ||
623 | "\n 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;" + | ||
624 | "\n }\n"; | ||
625 | |||
626 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
627 | string output = cg.Convert(input); | ||
628 | Assert.AreEqual(expected, output); | ||
629 | } | ||
630 | |||
631 | [Test] | ||
632 | public void TestLists() | ||
633 | { | ||
634 | string input = @"// testing lists | ||
635 | |||
636 | default | ||
637 | { | ||
638 | touch_start(integer num_detected) | ||
639 | { | ||
640 | list l = []; | ||
641 | list m = [1, two, ""three"", <4.0, 4.0, 4.0>, 5 + 5]; | ||
642 | llCallSomeFunc(1, llAnotherFunc(), [1, 2, 3]); | ||
643 | } | ||
644 | } | ||
645 | "; | ||
646 | string expected = | ||
647 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
648 | "\n {" + | ||
649 | "\n LSL_Types.list l = new LSL_Types.list();" + | ||
650 | "\n 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));" + | ||
651 | "\n 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)));" + | ||
652 | "\n }\n"; | ||
653 | |||
654 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
655 | string output = cg.Convert(input); | ||
656 | Assert.AreEqual(expected, output); | ||
657 | } | ||
658 | |||
659 | [Test] | ||
660 | public void TestIfStatement() | ||
661 | { | ||
662 | string input = @"// let's test if statements | ||
663 | |||
664 | default | ||
665 | { | ||
666 | touch_start(integer num_detected) | ||
667 | { | ||
668 | integer x = 1; | ||
669 | |||
670 | if (x) llSay(0, ""Hello""); | ||
671 | if (1) | ||
672 | { | ||
673 | llSay(0, ""Hi""); | ||
674 | integer r = 3; | ||
675 | return; | ||
676 | } | ||
677 | |||
678 | if (f(x)) llSay(0, ""f(x) is true""); | ||
679 | else llSay(0, ""f(x) is false""); | ||
680 | |||
681 | if (x + y) llSay(0, ""x + y is true""); | ||
682 | else if (y - x) llSay(0, ""y - x is true""); | ||
683 | else llSay(0, ""Who needs x and y anyway?""); | ||
684 | |||
685 | if (x * y) llSay(0, ""x * y is true""); | ||
686 | else if (y / x) | ||
687 | { | ||
688 | llSay(0, ""uh-oh, y / x is true, exiting""); | ||
689 | return; | ||
690 | } | ||
691 | else llSay(0, ""Who needs x and y anyway?""); | ||
692 | |||
693 | // and now for my last trick | ||
694 | if (x % y) llSay(0, ""x is true""); | ||
695 | else if (y & x) llSay(0, ""y is true""); | ||
696 | else if (z | x) llSay(0, ""z is true""); | ||
697 | else if (a * (b + x)) llSay(0, ""a is true""); | ||
698 | else if (b) llSay(0, ""b is true""); | ||
699 | else if (v) llSay(0, ""v is true""); | ||
700 | else llSay(0, ""Everything is lies!""); | ||
701 | } | ||
702 | } | ||
703 | "; | ||
704 | string expected = | ||
705 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
706 | "\n {" + | ||
707 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
708 | "\n if (x)" + | ||
709 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" + | ||
710 | "\n if (new LSL_Types.LSLInteger(1))" + | ||
711 | "\n {" + | ||
712 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" + | ||
713 | "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" + | ||
714 | "\n return ;" + | ||
715 | "\n }" + | ||
716 | "\n if (f(x))" + | ||
717 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is true\"));" + | ||
718 | "\n else" + | ||
719 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is false\"));" + | ||
720 | "\n if (x + y)" + | ||
721 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x + y is true\"));" + | ||
722 | "\n else" + | ||
723 | "\n if (y - x)" + | ||
724 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y - x is true\"));" + | ||
725 | "\n else" + | ||
726 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" + | ||
727 | "\n if (x * y)" + | ||
728 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x * y is true\"));" + | ||
729 | "\n else" + | ||
730 | "\n if (y / x)" + | ||
731 | "\n {" + | ||
732 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y / x is true, exiting\"));" + | ||
733 | "\n return ;" + | ||
734 | "\n }" + | ||
735 | "\n else" + | ||
736 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" + | ||
737 | "\n if (x % y)" + | ||
738 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + | ||
739 | "\n else" + | ||
740 | "\n if (y & x)" + | ||
741 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" + | ||
742 | "\n else" + | ||
743 | "\n if (z | x)" + | ||
744 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" + | ||
745 | "\n else" + | ||
746 | "\n if (a * (b + x))" + | ||
747 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" + | ||
748 | "\n else" + | ||
749 | "\n if (b)" + | ||
750 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" + | ||
751 | "\n else" + | ||
752 | "\n if (v)" + | ||
753 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" + | ||
754 | "\n else" + | ||
755 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" + | ||
756 | "\n }\n"; | ||
757 | |||
758 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
759 | string output = cg.Convert(input); | ||
760 | Assert.AreEqual(expected, output); | ||
761 | } | ||
762 | |||
763 | [Test] | ||
764 | public void TestIfElseStatement() | ||
765 | { | ||
766 | string input = @"// let's test complex logical expressions | ||
767 | |||
768 | default | ||
769 | { | ||
770 | touch_start(integer num_detected) | ||
771 | { | ||
772 | integer x = 1; | ||
773 | integer y = 0; | ||
774 | |||
775 | if (x && y) llSay(0, ""Hello""); | ||
776 | if (x || y) | ||
777 | { | ||
778 | llSay(0, ""Hi""); | ||
779 | integer r = 3; | ||
780 | return; | ||
781 | } | ||
782 | |||
783 | if (x && y || z) llSay(0, ""x is true""); | ||
784 | else llSay(0, ""x is false""); | ||
785 | |||
786 | if (x == y) llSay(0, ""x is true""); | ||
787 | else if (y < x) llSay(0, ""y is true""); | ||
788 | else llSay(0, ""Who needs x and y anyway?""); | ||
789 | |||
790 | if (x > y) llSay(0, ""x is true""); | ||
791 | else if (y <= x) | ||
792 | { | ||
793 | llSay(0, ""uh-oh, y is true, exiting""); | ||
794 | return; | ||
795 | } | ||
796 | else llSay(0, ""Who needs x and y anyway?""); | ||
797 | |||
798 | // and now for my last trick | ||
799 | if (x >= y) llSay(0, ""x is true""); | ||
800 | else if (y != x) llSay(0, ""y is true""); | ||
801 | else if (!z) llSay(0, ""z is true""); | ||
802 | else if (!(a && b)) llSay(0, ""a is true""); | ||
803 | else if (b) llSay(0, ""b is true""); | ||
804 | else if (v) llSay(0, ""v is true""); | ||
805 | else llSay(0, ""Everything is lies!""); | ||
806 | } | ||
807 | } | ||
808 | "; | ||
809 | string expected = | ||
810 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
811 | "\n {" + | ||
812 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
813 | "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + | ||
814 | "\n if (x && y)" + | ||
815 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" + | ||
816 | "\n if (x || y)" + | ||
817 | "\n {" + | ||
818 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" + | ||
819 | "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" + | ||
820 | "\n return ;" + | ||
821 | "\n }" + | ||
822 | "\n if (x && y || z)" + | ||
823 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + | ||
824 | "\n else" + | ||
825 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is false\"));" + | ||
826 | "\n if (x == y)" + | ||
827 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + | ||
828 | "\n else" + | ||
829 | "\n if (y < x)" + | ||
830 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" + | ||
831 | "\n else" + | ||
832 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" + | ||
833 | "\n if (x > y)" + | ||
834 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + | ||
835 | "\n else" + | ||
836 | "\n if (y <= x)" + | ||
837 | "\n {" + | ||
838 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y is true, exiting\"));" + | ||
839 | "\n return ;" + | ||
840 | "\n }" + | ||
841 | "\n else" + | ||
842 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" + | ||
843 | "\n if (x >= y)" + | ||
844 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + | ||
845 | "\n else" + | ||
846 | "\n if (y != x)" + | ||
847 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" + | ||
848 | "\n else" + | ||
849 | "\n if (!z)" + | ||
850 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" + | ||
851 | "\n else" + | ||
852 | "\n if (!(a && b))" + | ||
853 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" + | ||
854 | "\n else" + | ||
855 | "\n if (b)" + | ||
856 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" + | ||
857 | "\n else" + | ||
858 | "\n if (v)" + | ||
859 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" + | ||
860 | "\n else" + | ||
861 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" + | ||
862 | "\n }\n"; | ||
863 | |||
864 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
865 | string output = cg.Convert(input); | ||
866 | Assert.AreEqual(expected, output); | ||
867 | } | ||
868 | |||
869 | [Test] | ||
870 | public void TestWhileLoop() | ||
871 | { | ||
872 | string input = @"// let's test while loops | ||
873 | |||
874 | default | ||
875 | { | ||
876 | touch_start(integer num_detected) | ||
877 | { | ||
878 | integer x = 1; | ||
879 | integer y = 0; | ||
880 | |||
881 | while (x) llSay(0, ""To infinity, and beyond!""); | ||
882 | while (0 || (x && 0)) | ||
883 | { | ||
884 | llSay(0, ""Never say never.""); | ||
885 | return; | ||
886 | } | ||
887 | } | ||
888 | } | ||
889 | "; | ||
890 | string expected = | ||
891 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
892 | "\n {" + | ||
893 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
894 | "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + | ||
895 | "\n while (x)" + | ||
896 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"To infinity, and beyond!\"));" + | ||
897 | "\n while (new LSL_Types.LSLInteger(0) || (x && new LSL_Types.LSLInteger(0)))" + | ||
898 | "\n {" + | ||
899 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Never say never.\"));" + | ||
900 | "\n return ;" + | ||
901 | "\n }" + | ||
902 | "\n }\n"; | ||
903 | |||
904 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
905 | string output = cg.Convert(input); | ||
906 | Assert.AreEqual(expected, output); | ||
907 | } | ||
908 | |||
909 | [Test] | ||
910 | public void TestDoWhileLoop() | ||
911 | { | ||
912 | string input = @"// let's test do-while loops | ||
913 | |||
914 | default | ||
915 | { | ||
916 | touch_start(integer num_detected) | ||
917 | { | ||
918 | integer x = 1; | ||
919 | integer y = 0; | ||
920 | |||
921 | do llSay(0, ""And we're doing...""); | ||
922 | while (x); | ||
923 | |||
924 | do | ||
925 | { | ||
926 | llSay(0, ""I like it here. I wish we could stay here forever.""); | ||
927 | y--; | ||
928 | } while (y); | ||
929 | } | ||
930 | } | ||
931 | "; | ||
932 | string expected = | ||
933 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
934 | "\n {" + | ||
935 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
936 | "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + | ||
937 | "\n do" + | ||
938 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"And we're doing...\"));" + | ||
939 | "\n while (x);" + | ||
940 | "\n do" + | ||
941 | "\n {" + | ||
942 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I like it here. I wish we could stay here forever.\"));" + | ||
943 | "\n y--;" + | ||
944 | "\n }" + | ||
945 | "\n while (y);" + | ||
946 | "\n }\n"; | ||
947 | |||
948 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
949 | string output = cg.Convert(input); | ||
950 | Assert.AreEqual(expected, output); | ||
951 | } | ||
952 | |||
953 | [Test] | ||
954 | public void TestForLoop() | ||
955 | { | ||
956 | string input = @"// let's test for loops | ||
957 | |||
958 | default | ||
959 | { | ||
960 | touch_start(integer num_detected) | ||
961 | { | ||
962 | integer x = 1; | ||
963 | integer y = 0; | ||
964 | |||
965 | for (x = 10; x >= 0; x--) | ||
966 | { | ||
967 | llOwnerSay(""Launch in T minus "" + x); | ||
968 | IncreaseRocketPower(); | ||
969 | } | ||
970 | |||
971 | for (x = 0, y = 6; y > 0 && x != y; x++, y--) llOwnerSay(""Hi "" + x + "", "" + y); | ||
972 | for (x = 0, y = 6; ! y; x++,y--) llOwnerSay(""Hi "" + x + "", "" + y); | ||
973 | } | ||
974 | } | ||
975 | "; | ||
976 | string expected = | ||
977 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
978 | "\n {" + | ||
979 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
980 | "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + | ||
981 | "\n for (x = new LSL_Types.LSLInteger(10); x >= new LSL_Types.LSLInteger(0); x--)" + | ||
982 | "\n {" + | ||
983 | "\n llOwnerSay(new LSL_Types.LSLString(\"Launch in T minus \") + x);" + | ||
984 | "\n IncreaseRocketPower();" + | ||
985 | "\n }" + | ||
986 | "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); y > new LSL_Types.LSLInteger(0) && x != y; x++, y--)" + | ||
987 | "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" + | ||
988 | "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); !y; x++, y--)" + | ||
989 | "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" + | ||
990 | "\n }\n"; | ||
991 | |||
992 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
993 | string output = cg.Convert(input); | ||
994 | Assert.AreEqual(expected, output); | ||
995 | } | ||
996 | |||
997 | [Test] | ||
998 | public void TestFloatsWithTrailingDecimal() | ||
999 | { | ||
1000 | string input = @"// a curious feature of LSL that allows floats to be defined with a trailing dot | ||
1001 | |||
1002 | default | ||
1003 | { | ||
1004 | touch_start(integer num_detected) | ||
1005 | { | ||
1006 | float y = 1.; | ||
1007 | y = 1.E3; | ||
1008 | y = 1.e3; | ||
1009 | y = 1.E+3; | ||
1010 | y = 1.e+3; | ||
1011 | y = 1.E-3; | ||
1012 | y = 1.e-3; | ||
1013 | y = -1.E3; | ||
1014 | y = -1.e3; | ||
1015 | y = -1.E+3; | ||
1016 | y = -1.e+3; | ||
1017 | y = -1.E-3; | ||
1018 | y = -1.e-3; | ||
1019 | y = 12. + -1.E3 - 1.e-2; | ||
1020 | vector v = <0.,0.,0.>; | ||
1021 | } | ||
1022 | } | ||
1023 | "; | ||
1024 | string expected = | ||
1025 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1026 | "\n {" + | ||
1027 | "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.0);" + | ||
1028 | "\n y = new LSL_Types.LSLFloat(1.0E3);" + | ||
1029 | "\n y = new LSL_Types.LSLFloat(1.0e3);" + | ||
1030 | "\n y = new LSL_Types.LSLFloat(1.0E+3);" + | ||
1031 | "\n y = new LSL_Types.LSLFloat(1.0e+3);" + | ||
1032 | "\n y = new LSL_Types.LSLFloat(1.0E-3);" + | ||
1033 | "\n y = new LSL_Types.LSLFloat(1.0e-3);" + | ||
1034 | "\n y = -new LSL_Types.LSLFloat(1.0E3);" + | ||
1035 | "\n y = -new LSL_Types.LSLFloat(1.0e3);" + | ||
1036 | "\n y = -new LSL_Types.LSLFloat(1.0E+3);" + | ||
1037 | "\n y = -new LSL_Types.LSLFloat(1.0e+3);" + | ||
1038 | "\n y = -new LSL_Types.LSLFloat(1.0E-3);" + | ||
1039 | "\n y = -new LSL_Types.LSLFloat(1.0e-3);" + | ||
1040 | "\n y = new LSL_Types.LSLFloat(12.0) + -new LSL_Types.LSLFloat(1.0E3) - new LSL_Types.LSLFloat(1.0e-2);" + | ||
1041 | "\n 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));" + | ||
1042 | "\n }\n"; | ||
1043 | |||
1044 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1045 | string output = cg.Convert(input); | ||
1046 | Assert.AreEqual(expected, output); | ||
1047 | } | ||
1048 | |||
1049 | [Test] | ||
1050 | public void TestUnaryAndBinaryOperators() | ||
1051 | { | ||
1052 | string input = @"// let's test a few more operators | ||
1053 | |||
1054 | default | ||
1055 | { | ||
1056 | touch_start(integer num_detected) | ||
1057 | { | ||
1058 | integer x = 2; | ||
1059 | integer y = 1; | ||
1060 | integer z = x ^ y; | ||
1061 | x = ~ z; | ||
1062 | x = ~(y && z); | ||
1063 | y = x >> z; | ||
1064 | z = y << x; | ||
1065 | } | ||
1066 | } | ||
1067 | "; | ||
1068 | string expected = | ||
1069 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1070 | "\n {" + | ||
1071 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" + | ||
1072 | "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(1);" + | ||
1073 | "\n LSL_Types.LSLInteger z = x ^ y;" + | ||
1074 | "\n x = ~z;" + | ||
1075 | "\n x = ~(y && z);" + | ||
1076 | "\n y = x >> z;" + | ||
1077 | "\n z = y << x;" + | ||
1078 | "\n }\n"; | ||
1079 | |||
1080 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1081 | string output = cg.Convert(input); | ||
1082 | Assert.AreEqual(expected, output); | ||
1083 | } | ||
1084 | |||
1085 | [Test] | ||
1086 | public void TestTypecasts() | ||
1087 | { | ||
1088 | string input = @"// let's test typecasts | ||
1089 | |||
1090 | default | ||
1091 | { | ||
1092 | touch_start(integer num_detected) | ||
1093 | { | ||
1094 | string s = """"; | ||
1095 | integer x = 1; | ||
1096 | |||
1097 | s = (string) x++; | ||
1098 | s = (string) x; | ||
1099 | s = (string) <0., 0., 0.>; | ||
1100 | s = (string) <1., 1., 1., 1.>; | ||
1101 | s = (integer) ""1""; | ||
1102 | s = (string) llSomethingThatReturnsInteger(); | ||
1103 | s = (string) 134; | ||
1104 | s = (string) (x ^ y | (z && l)) + (string) (x + y - 13); | ||
1105 | llOwnerSay(""s is: "" + s); | ||
1106 | } | ||
1107 | } | ||
1108 | "; | ||
1109 | string expected = | ||
1110 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1111 | "\n {" + | ||
1112 | "\n LSL_Types.LSLString s = new LSL_Types.LSLString(\"\");" + | ||
1113 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + | ||
1114 | "\n s = (LSL_Types.LSLString) (x++);" + | ||
1115 | "\n s = (LSL_Types.LSLString) (x);" + | ||
1116 | "\n 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)));" + | ||
1117 | "\n 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)));" + | ||
1118 | "\n s = (LSL_Types.LSLInteger) (new LSL_Types.LSLString(\"1\"));" + | ||
1119 | "\n s = (LSL_Types.LSLString) (llSomethingThatReturnsInteger());" + | ||
1120 | "\n s = (LSL_Types.LSLString) (new LSL_Types.LSLInteger(134));" + | ||
1121 | "\n s = (LSL_Types.LSLString) (x ^ y | (z && l)) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13));" + | ||
1122 | "\n llOwnerSay(new LSL_Types.LSLString(\"s is: \") + s);" + | ||
1123 | "\n }\n"; | ||
1124 | |||
1125 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1126 | string output = cg.Convert(input); | ||
1127 | Assert.AreEqual(expected, output); | ||
1128 | } | ||
1129 | |||
1130 | [Test] | ||
1131 | public void TestStates() | ||
1132 | { | ||
1133 | string input = @"// let's test states | ||
1134 | |||
1135 | default | ||
1136 | { | ||
1137 | touch_start(integer num_detected) | ||
1138 | { | ||
1139 | llSay(0, ""Going to state 'statetwo'""); | ||
1140 | state statetwo; | ||
1141 | } | ||
1142 | } | ||
1143 | |||
1144 | state statetwo | ||
1145 | { | ||
1146 | state_entry() | ||
1147 | { | ||
1148 | llSay(0, ""Going to the default state""); | ||
1149 | state default; | ||
1150 | } | ||
1151 | } | ||
1152 | "; | ||
1153 | string expected = | ||
1154 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1155 | "\n {" + | ||
1156 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to state 'statetwo'\"));" + | ||
1157 | "\n state(\"statetwo\");" + | ||
1158 | "\n }" + | ||
1159 | "\n public void statetwo_event_state_entry()" + | ||
1160 | "\n {" + | ||
1161 | "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to the default state\"));" + | ||
1162 | "\n state(\"default\");" + | ||
1163 | "\n }\n"; | ||
1164 | |||
1165 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1166 | string output = cg.Convert(input); | ||
1167 | Assert.AreEqual(expected, output); | ||
1168 | } | ||
1169 | |||
1170 | [Test] | ||
1171 | public void TestHexIntegerConstants() | ||
1172 | { | ||
1173 | string input = @"// let's test hex integers | ||
1174 | |||
1175 | default | ||
1176 | { | ||
1177 | touch_start(integer num_detected) | ||
1178 | { | ||
1179 | integer x = 0x23; | ||
1180 | integer x = 0x2f34B; | ||
1181 | integer x = 0x2F34b; | ||
1182 | integer x = 0x2F34B; | ||
1183 | integer x = 0x2f34b; | ||
1184 | } | ||
1185 | } | ||
1186 | "; | ||
1187 | string expected = | ||
1188 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1189 | "\n {" + | ||
1190 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x23);" + | ||
1191 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34B);" + | ||
1192 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34b);" + | ||
1193 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34B);" + | ||
1194 | "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34b);" + | ||
1195 | "\n }\n"; | ||
1196 | |||
1197 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1198 | string output = cg.Convert(input); | ||
1199 | Assert.AreEqual(expected, output); | ||
1200 | } | ||
1201 | |||
1202 | [Test] | ||
1203 | public void TestJumps() | ||
1204 | { | ||
1205 | string input = @"// let's test jumps | ||
1206 | |||
1207 | default | ||
1208 | { | ||
1209 | touch_start(integer num_detected) | ||
1210 | { | ||
1211 | jump here; | ||
1212 | llOwnerSay(""Uh oh, the jump didn't work""); | ||
1213 | @here; | ||
1214 | llOwnerSay(""After the jump""); | ||
1215 | } | ||
1216 | } | ||
1217 | "; | ||
1218 | string expected = | ||
1219 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1220 | "\n {" + | ||
1221 | "\n goto here;" + | ||
1222 | "\n llOwnerSay(new LSL_Types.LSLString(\"Uh oh, the jump didn't work\"));" + | ||
1223 | "\n here:" + | ||
1224 | "\n llOwnerSay(new LSL_Types.LSLString(\"After the jump\"));" + | ||
1225 | "\n }\n"; | ||
1226 | |||
1227 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1228 | string output = cg.Convert(input); | ||
1229 | Assert.AreEqual(expected, output); | ||
1230 | } | ||
1231 | |||
1232 | [Test] | ||
1233 | public void TestImplicitVariableInitialization() | ||
1234 | { | ||
1235 | string input = @"// let's test implicitly initializing variables | ||
1236 | |||
1237 | default | ||
1238 | { | ||
1239 | touch_start(integer num_detected) | ||
1240 | { | ||
1241 | integer i; integer j = 14; | ||
1242 | float f; float g = 14.0; | ||
1243 | string s; string t = ""Hi there""; | ||
1244 | list l; list m = [1, 2, 3]; | ||
1245 | vector v; vector w = <1.0, 0.1, 0.5>; | ||
1246 | rotation r; rotation u = <0.8, 0.7, 0.6, llSomeFunc()>; | ||
1247 | key k; key n = ""ping""; | ||
1248 | } | ||
1249 | } | ||
1250 | "; | ||
1251 | string expected = | ||
1252 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1253 | "\n {" + | ||
1254 | "\n LSL_Types.LSLInteger i = 0;" + | ||
1255 | "\n LSL_Types.LSLInteger j = new LSL_Types.LSLInteger(14);" + | ||
1256 | "\n LSL_Types.LSLFloat f = 0.0;" + | ||
1257 | "\n LSL_Types.LSLFloat g = new LSL_Types.LSLFloat(14.0);" + | ||
1258 | "\n LSL_Types.LSLString s = \"\";" + | ||
1259 | "\n LSL_Types.LSLString t = new LSL_Types.LSLString(\"Hi there\");" + | ||
1260 | "\n LSL_Types.list l = new LSL_Types.list();" + | ||
1261 | "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" + | ||
1262 | "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0);" + | ||
1263 | "\n 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));" + | ||
1264 | "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(0.0, 0.0, 0.0, 0.0);" + | ||
1265 | "\n 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());" + | ||
1266 | "\n LSL_Types.LSLString k = \"\";" + | ||
1267 | "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" + | ||
1268 | "\n }\n"; | ||
1269 | |||
1270 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1271 | string output = cg.Convert(input); | ||
1272 | Assert.AreEqual(expected, output); | ||
1273 | } | ||
1274 | |||
1275 | [Test] | ||
1276 | public void TestMultipleEqualsExpression() | ||
1277 | { | ||
1278 | string input = @"// let's test x = y = 5 type expressions | ||
1279 | |||
1280 | default | ||
1281 | { | ||
1282 | touch_start(integer num_detected) | ||
1283 | { | ||
1284 | integer x; | ||
1285 | integer y; | ||
1286 | x = y = 5; | ||
1287 | x += y -= 5; | ||
1288 | llOwnerSay(""x is: "" + (string) x + "", y is: "" + (string) y); | ||
1289 | } | ||
1290 | } | ||
1291 | "; | ||
1292 | string expected = | ||
1293 | "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + | ||
1294 | "\n {" + | ||
1295 | "\n LSL_Types.LSLInteger x = 0;" + | ||
1296 | "\n LSL_Types.LSLInteger y = 0;" + | ||
1297 | "\n x = y = new LSL_Types.LSLInteger(5);" + | ||
1298 | "\n x += y -= new LSL_Types.LSLInteger(5);" + | ||
1299 | "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x) + new LSL_Types.LSLString(\", y is: \") + (LSL_Types.LSLString) (y));" + | ||
1300 | "\n }\n"; | ||
1301 | |||
1302 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1303 | string output = cg.Convert(input); | ||
1304 | Assert.AreEqual(expected, output); | ||
1305 | } | ||
1306 | |||
1307 | [Test] | ||
1308 | public void TestUnaryExpressionLastInVectorConstant() | ||
1309 | { | ||
1310 | string input = @"// let's test unary expressions some more | ||
1311 | |||
1312 | default | ||
1313 | { | ||
1314 | state_entry() | ||
1315 | { | ||
1316 | vector v = <x,y,-0.5>; | ||
1317 | } | ||
1318 | } | ||
1319 | "; | ||
1320 | string expected = | ||
1321 | "\n public void default_event_state_entry()" + | ||
1322 | "\n {" + | ||
1323 | "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(x, y, -new LSL_Types.LSLFloat(0.5));" + | ||
1324 | "\n }\n"; | ||
1325 | |||
1326 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1327 | string output = cg.Convert(input); | ||
1328 | Assert.AreEqual(expected, output); | ||
1329 | } | ||
1330 | |||
1331 | [Test] | ||
1332 | public void TestVectorMemberPlusEquals() | ||
1333 | { | ||
1334 | string input = @"// let's test unary expressions some more | ||
1335 | |||
1336 | default | ||
1337 | { | ||
1338 | state_entry() | ||
1339 | { | ||
1340 | vector v = llGetPos(); | ||
1341 | v.z += 4; | ||
1342 | v.z -= 4; | ||
1343 | v.z *= 4; | ||
1344 | v.z /= 4; | ||
1345 | v.z %= 4; | ||
1346 | } | ||
1347 | } | ||
1348 | "; | ||
1349 | string expected = | ||
1350 | "\n public void default_event_state_entry()" + | ||
1351 | "\n {" + | ||
1352 | "\n LSL_Types.Vector3 v = llGetPos();" + | ||
1353 | "\n v.z += new LSL_Types.LSLInteger(4);" + | ||
1354 | "\n v.z -= new LSL_Types.LSLInteger(4);" + | ||
1355 | "\n v.z *= new LSL_Types.LSLInteger(4);" + | ||
1356 | "\n v.z /= new LSL_Types.LSLInteger(4);" + | ||
1357 | "\n v.z %= new LSL_Types.LSLInteger(4);" + | ||
1358 | "\n }\n"; | ||
1359 | |||
1360 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1361 | string output = cg.Convert(input); | ||
1362 | Assert.AreEqual(expected, output); | ||
1363 | } | ||
1364 | |||
1365 | [Test] | ||
1366 | public void TestWhileLoopWithNoBody() | ||
1367 | { | ||
1368 | string input = @"default | ||
1369 | { | ||
1370 | state_entry() | ||
1371 | { | ||
1372 | while (1<0); | ||
1373 | } | ||
1374 | }"; | ||
1375 | |||
1376 | string expected = | ||
1377 | "\n public void default_event_state_entry()" + | ||
1378 | "\n {" + | ||
1379 | "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" + | ||
1380 | "\n ;" + | ||
1381 | "\n }\n"; | ||
1382 | |||
1383 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1384 | string output = cg.Convert(input); | ||
1385 | Assert.AreEqual(expected, output); | ||
1386 | } | ||
1387 | |||
1388 | [Test] | ||
1389 | public void TestDoWhileLoopWithNoBody() | ||
1390 | { | ||
1391 | string input = @"default | ||
1392 | { | ||
1393 | state_entry() | ||
1394 | { | ||
1395 | do; | ||
1396 | while (1<0); | ||
1397 | } | ||
1398 | }"; | ||
1399 | |||
1400 | string expected = | ||
1401 | "\n public void default_event_state_entry()" + | ||
1402 | "\n {" + | ||
1403 | "\n do" + | ||
1404 | "\n ;" + | ||
1405 | "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0));" + | ||
1406 | "\n }\n"; | ||
1407 | |||
1408 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1409 | string output = cg.Convert(input); | ||
1410 | Assert.AreEqual(expected, output); | ||
1411 | } | ||
1412 | |||
1413 | [Test] | ||
1414 | public void TestIfWithNoBody() | ||
1415 | { | ||
1416 | string input = @"default | ||
1417 | { | ||
1418 | state_entry() | ||
1419 | { | ||
1420 | if (1<0); | ||
1421 | } | ||
1422 | }"; | ||
1423 | |||
1424 | string expected = | ||
1425 | "\n public void default_event_state_entry()" + | ||
1426 | "\n {" + | ||
1427 | "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" + | ||
1428 | "\n ;" + | ||
1429 | "\n }\n"; | ||
1430 | |||
1431 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1432 | string output = cg.Convert(input); | ||
1433 | Assert.AreEqual(expected, output); | ||
1434 | } | ||
1435 | |||
1436 | [Test] | ||
1437 | public void TestIfElseWithNoBody() | ||
1438 | { | ||
1439 | string input = @"default | ||
1440 | { | ||
1441 | state_entry() | ||
1442 | { | ||
1443 | if (1<0); | ||
1444 | else; | ||
1445 | } | ||
1446 | }"; | ||
1447 | |||
1448 | string expected = | ||
1449 | "\n public void default_event_state_entry()" + | ||
1450 | "\n {" + | ||
1451 | "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" + | ||
1452 | "\n ;" + | ||
1453 | "\n else" + | ||
1454 | "\n ;" + | ||
1455 | "\n }\n"; | ||
1456 | |||
1457 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1458 | string output = cg.Convert(input); | ||
1459 | Assert.AreEqual(expected, output); | ||
1460 | } | ||
1461 | |||
1462 | [Test] | ||
1463 | public void TestForLoopWithNoBody() | ||
1464 | { | ||
1465 | string input = @"default | ||
1466 | { | ||
1467 | state_entry() | ||
1468 | { | ||
1469 | for (x = 4; 1<0; x += 2); | ||
1470 | } | ||
1471 | }"; | ||
1472 | |||
1473 | string expected = | ||
1474 | "\n public void default_event_state_entry()" + | ||
1475 | "\n {" + | ||
1476 | "\n for (x = new LSL_Types.LSLInteger(4); new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" + | ||
1477 | "\n ;" + | ||
1478 | "\n }\n"; | ||
1479 | |||
1480 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1481 | string output = cg.Convert(input); | ||
1482 | Assert.AreEqual(expected, output); | ||
1483 | } | ||
1484 | |||
1485 | [Test] | ||
1486 | public void TestAssignmentInIfWhileDoWhile() | ||
1487 | { | ||
1488 | string input = @"default | ||
1489 | { | ||
1490 | state_entry() | ||
1491 | { | ||
1492 | integer x; | ||
1493 | |||
1494 | while (x = 14) llOwnerSay(""x is: "" + (string) x); | ||
1495 | |||
1496 | if (x = 24) llOwnerSay(""x is: "" + (string) x); | ||
1497 | |||
1498 | do | ||
1499 | llOwnerSay(""x is: "" + (string) x); | ||
1500 | while (x = 44); | ||
1501 | } | ||
1502 | }"; | ||
1503 | |||
1504 | string expected = | ||
1505 | "\n public void default_event_state_entry()" + | ||
1506 | "\n {" + | ||
1507 | "\n LSL_Types.LSLInteger x = 0;" + | ||
1508 | "\n while (x = new LSL_Types.LSLInteger(14))" + | ||
1509 | "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" + | ||
1510 | "\n if (x = new LSL_Types.LSLInteger(24))" + | ||
1511 | "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" + | ||
1512 | "\n do" + | ||
1513 | "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" + | ||
1514 | "\n while (x = new LSL_Types.LSLInteger(44));" + | ||
1515 | "\n }\n"; | ||
1516 | |||
1517 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1518 | string output = cg.Convert(input); | ||
1519 | Assert.AreEqual(expected, output); | ||
1520 | } | ||
1521 | |||
1522 | [Test] | ||
1523 | public void TestLSLListHack() | ||
1524 | { | ||
1525 | string input = @"default | ||
1526 | { | ||
1527 | state_entry() | ||
1528 | { | ||
1529 | list l = [""hello""]; | ||
1530 | l = (l=[]) + l + ""world""; | ||
1531 | } | ||
1532 | }"; | ||
1533 | |||
1534 | string expected = | ||
1535 | "\n public void default_event_state_entry()" + | ||
1536 | "\n {" + | ||
1537 | "\n LSL_Types.list l = new LSL_Types.list(new LSL_Types.LSLString(\"hello\"));" + | ||
1538 | "\n l = (l = new LSL_Types.list()) + l + new LSL_Types.LSLString(\"world\");" + | ||
1539 | "\n }\n"; | ||
1540 | |||
1541 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1542 | string output = cg.Convert(input); | ||
1543 | Assert.AreEqual(expected, output); | ||
1544 | } | ||
1545 | |||
1546 | [Test] | ||
1547 | [ExpectedException(typeof(Tools.CSToolsException))] | ||
1548 | public void TestSyntaxError() | ||
1549 | { | ||
1550 | string input = @"default | ||
1551 | { | ||
1552 | state_entry() | ||
1553 | { | ||
1554 | integer y | ||
1555 | } | ||
1556 | } | ||
1557 | "; | ||
1558 | try | ||
1559 | { | ||
1560 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1561 | cg.Convert(input); | ||
1562 | } | ||
1563 | catch (Tools.CSToolsException e) | ||
1564 | { | ||
1565 | // The syntax error is on line 6, char 5 (expected ';', found | ||
1566 | // '}'). | ||
1567 | Regex r = new Regex("Line ([0-9]+), char ([0-9]+)"); | ||
1568 | Match m = r.Match(e.Message); | ||
1569 | Assert.AreEqual("6", m.Groups[1].Value); | ||
1570 | Assert.AreEqual("5", m.Groups[2].Value); | ||
1571 | |||
1572 | throw; | ||
1573 | } | ||
1574 | } | ||
1575 | |||
1576 | [Test] | ||
1577 | [ExpectedException(typeof(Tools.CSToolsException))] | ||
1578 | public void TestSyntaxErrorDeclaringVariableInForLoop() | ||
1579 | { | ||
1580 | string input = @"default | ||
1581 | { | ||
1582 | state_entry() | ||
1583 | { | ||
1584 | for (integer x = 0; x < 10; x++) llOwnerSay(""x is: "" + (string) x); | ||
1585 | } | ||
1586 | } | ||
1587 | "; | ||
1588 | try | ||
1589 | { | ||
1590 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
1591 | cg.Convert(input); | ||
1592 | } | ||
1593 | catch (Tools.CSToolsException e) | ||
1594 | { | ||
1595 | // The syntax error is on line 5, char 14 (Syntax error) | ||
1596 | Regex r = new Regex("Line ([0-9]+), char ([0-9]+)"); | ||
1597 | Match m = r.Match(e.Message); | ||
1598 | Assert.AreEqual("5", m.Groups[1].Value); | ||
1599 | Assert.AreEqual("14", m.Groups[2].Value); | ||
1600 | |||
1601 | throw; | ||
1602 | } | ||
1603 | } | ||
1604 | } | ||
1605 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs deleted file mode 100644 index 7725d8d..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
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 deleted file mode 100644 index 272d06c..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs +++ /dev/null | |||
@@ -1,603 +0,0 @@ | |||
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 deleted file mode 100644 index f826c00..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
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 deleted file mode 100644 index 49e5023..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
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 deleted file mode 100644 index 7da28dd..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
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(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); | ||
48 | testList += new LSL_Types.LSLString("addition"); | ||
49 | |||
50 | Assert.AreEqual(4, testList.Length); | ||
51 | Assert.AreEqual(new LSL_Types.LSLString("addition"), testList.Data[3]); | ||
52 | Assert.AreEqual(typeof(LSL_Types.LSLString), testList.Data[3].GetType()); | ||
53 | |||
54 | LSL_Types.list secondTestList = testList + new LSL_Types.LSLString("more"); | ||
55 | |||
56 | Assert.AreEqual(5, secondTestList.Length); | ||
57 | Assert.AreEqual(new LSL_Types.LSLString("more"), secondTestList.Data[4]); | ||
58 | Assert.AreEqual(typeof(LSL_Types.LSLString), 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(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); | ||
68 | testList += new LSL_Types.LSLInteger(20); | ||
69 | |||
70 | Assert.AreEqual(4, testList.Length); | ||
71 | Assert.AreEqual(new LSL_Types.LSLInteger(20), testList.Data[3]); | ||
72 | Assert.AreEqual(typeof(LSL_Types.LSLInteger), testList.Data[3].GetType()); | ||
73 | |||
74 | LSL_Types.list secondTestList = testList + new LSL_Types.LSLInteger(2); | ||
75 | |||
76 | Assert.AreEqual(5, secondTestList.Length); | ||
77 | Assert.AreEqual(new LSL_Types.LSLInteger(2), secondTestList.Data[4]); | ||
78 | Assert.AreEqual(typeof(LSL_Types.LSLInteger), secondTestList.Data[4].GetType()); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Tests concatenating a float to a list. | ||
83 | /// </summary> | ||
84 | [Test] | ||
85 | public void TestConcatenateDouble() | ||
86 | { | ||
87 | LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); | ||
88 | testList += new LSL_Types.LSLFloat(2.0f); | ||
89 | |||
90 | Assert.AreEqual(4, testList.Length); | ||
91 | Assert.AreEqual(new LSL_Types.LSLFloat(2.0f), testList.Data[3]); | ||
92 | Assert.AreEqual(typeof(LSL_Types.LSLFloat), testList.Data[3].GetType()); | ||
93 | |||
94 | LSL_Types.list secondTestList = testList + new LSL_Types.LSLFloat(0.04f); | ||
95 | |||
96 | Assert.AreEqual(5, secondTestList.Length); | ||
97 | Assert.AreEqual(new LSL_Types.LSLFloat(0.04f), secondTestList.Data[4]); | ||
98 | Assert.AreEqual(typeof(LSL_Types.LSLFloat), 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 | /// <summary> | ||
163 | /// Tests GetLSLIntegerItem for LSLInteger item. | ||
164 | /// </summary> | ||
165 | [Test] | ||
166 | public void TestGetLSLIntegerItemForLSLIntegerItem() | ||
167 | { | ||
168 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911); | ||
169 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
170 | |||
171 | Assert.AreEqual(testValue, testList.GetLSLIntegerItem(0)); | ||
172 | } | ||
173 | |||
174 | /// <summary> | ||
175 | /// Tests GetLSLFloatItem for LSLFloat item. | ||
176 | /// </summary> | ||
177 | [Test] | ||
178 | public void TestGetLSLFloatItemForLSLFloatItem() | ||
179 | { | ||
180 | LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876); | ||
181 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
182 | |||
183 | Assert.AreEqual(testValue, testList.GetLSLFloatItem(0)); | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Tests GetLSLFloatItem for LSLInteger item. | ||
188 | /// </summary> | ||
189 | [Test] | ||
190 | public void TestGetLSLFloatItemForLSLIntegerItem() | ||
191 | { | ||
192 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987); | ||
193 | LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue); | ||
194 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
195 | |||
196 | Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0)); | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Tests GetLSLStringItem for LSLString item. | ||
201 | /// </summary> | ||
202 | [Test] | ||
203 | public void TestGetLSLStringItemForLSLStringItem() | ||
204 | { | ||
205 | LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all"); | ||
206 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
207 | |||
208 | Assert.AreEqual(testValue, testList.GetLSLStringItem(0)); | ||
209 | } | ||
210 | |||
211 | /// <summary> | ||
212 | /// Tests GetLSLStringItem for key item. | ||
213 | /// </summary> | ||
214 | [Test] | ||
215 | public void TestGetLSLStringItemForKeyItem() | ||
216 | { | ||
217 | LSL_Types.key testValue | ||
218 | = new LSL_Types.key("98000000-0000-2222-3333-100000001000"); | ||
219 | LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue); | ||
220 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
221 | |||
222 | Assert.AreEqual(testStringValue, testList.GetLSLStringItem(0)); | ||
223 | } | ||
224 | |||
225 | /// <summary> | ||
226 | /// Tests GetVector3Item for Vector3 item. | ||
227 | /// </summary> | ||
228 | [Test] | ||
229 | public void TestGetVector3ItemForVector3Item() | ||
230 | { | ||
231 | LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987); | ||
232 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
233 | |||
234 | Assert.AreEqual(testValue, testList.GetVector3Item(0)); | ||
235 | } | ||
236 | /// <summary> | ||
237 | /// Tests GetQuaternionItem for Quaternion item. | ||
238 | /// </summary> | ||
239 | [Test] | ||
240 | public void TestGetQuaternionItemForQuaternionItem() | ||
241 | { | ||
242 | LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987); | ||
243 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
244 | |||
245 | Assert.AreEqual(testValue, testList.GetQuaternionItem(0)); | ||
246 | } | ||
247 | |||
248 | /// <summary> | ||
249 | /// Tests GetKeyItem for key item. | ||
250 | /// </summary> | ||
251 | [Test] | ||
252 | public void TestGetKeyItemForKeyItem() | ||
253 | { | ||
254 | LSL_Types.key testValue | ||
255 | = new LSL_Types.key("00000000-0000-2222-3333-100000001012"); | ||
256 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
257 | |||
258 | Assert.AreEqual(testValue, testList.GetKeyItem(0)); | ||
259 | } | ||
260 | } | ||
261 | } | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs deleted file mode 100644 index fb2c00c..0000000 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
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 | } | ||