aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/media/Test%20sim/test/TESTICLE_LSL.lsl
diff options
context:
space:
mode:
Diffstat (limited to 'media/Test%20sim/test/TESTICLE_LSL.lsl')
-rwxr-xr-xmedia/Test%20sim/test/TESTICLE_LSL.lsl454
1 files changed, 454 insertions, 0 deletions
diff --git a/media/Test%20sim/test/TESTICLE_LSL.lsl b/media/Test%20sim/test/TESTICLE_LSL.lsl
new file mode 100755
index 0000000..023600e
--- /dev/null
+++ b/media/Test%20sim/test/TESTICLE_LSL.lsl
@@ -0,0 +1,454 @@
1integer verbosity = 1;
2
3// All those that fail at compile time, or cause crashes, are commented out
4
5integer testsPassed = 0;
6integer testsFailed = 0;
7
8
9testPassed(string description, string actual, string expected)
10{
11 ++testsPassed;
12 llSay(0, description);
13}
14
15testFailed(string description, string actual, string expected)
16{
17 ++testsFailed;
18// llSay(0, "FAILED!: " + description + " (" + actual + " expected " + expected + ")");
19llSay(0, "FAILED!: " + description);
20}
21
22ensureTrue(string description, integer actual)
23{
24 if(actual)
25 {
26 testPassed(description, (string) actual, (string) TRUE);
27 }
28 else
29 {
30 testFailed(description, (string) actual, (string) TRUE);
31 }
32}
33
34ensureFalse(string description, integer actual)
35{
36 if(actual)
37 {
38 testFailed(description, (string) actual, (string) FALSE);
39 }
40 else
41 {
42 testPassed(description, (string) actual, (string) FALSE);
43 }
44}
45
46ensureIntegerEqual(string description, integer actual, integer expected)
47{
48 if(actual == expected)
49 {
50 testPassed(description, (string) actual, (string) expected);
51 }
52 else
53 {
54 testFailed(description, (string) actual, (string) expected);
55 }
56}
57
58ensureFloatEqual(string description, float actual, float expected)
59{
60 if(actual == expected)
61 {
62 testPassed(description, (string) actual, (string) expected);
63 }
64 else
65 {
66 testFailed(description, (string) actual, (string) expected);
67 }
68}
69
70ensureStringEqual(string description, string actual, string expected)
71{
72 if(actual == expected)
73 {
74 testPassed(description, (string) actual, (string) expected);
75 }
76 else
77 {
78 testFailed(description, (string) actual, (string) expected);
79 }
80}
81
82ensureVectorEqual(string description, vector actual, vector expected)
83{
84 if(actual == expected)
85 {
86 testPassed(description, (string) actual, (string) expected);
87 }
88 else
89 {
90 testFailed(description, (string) actual, (string) expected);
91 }
92}
93
94ensureRotationEqual(string description, rotation actual, rotation expected)
95{
96 if(actual == expected)
97 {
98 testPassed(description, (string) actual, (string) expected);
99 }
100 else
101 {
102 testFailed(description, (string) actual, (string) expected);
103 }
104}
105
106ensureListEqual(string description, list actual, list expected)
107{
108 if(actual == expected)
109 {
110 testPassed(description, (string) actual, (string) expected);
111 }
112 else
113 {
114 testFailed(description, (string) actual, (string) expected);
115 }
116}
117
118integer gInteger = 5;
119float gFloat = 1.5;
120string gString = "foo";
121vector gVector = <1, 2, 3>;
122rotation gRot = <1, 2, 3, 4>;
123
124integer testReturn()
125{
126 return 1;
127}
128
129integer testParameters(integer param)
130{
131 param = param + 1;
132 return param;
133}
134
135integer testRecursion(integer param)
136{
137 if(param <= 0)
138 {
139 return 0;
140 }
141 else
142 {
143 return testRecursion(param - 1);
144 }
145}
146
147
148
149
150default
151{
152 state_entry()
153 {
154 integer success = 1;
155 string result = "";
156
157 // reset globals
158 gInteger = 5;
159 gFloat = 1.5;
160 gString = "foo";
161// gVector = <1, 2, 3>;
162 gRot = <1, 2, 3, 4>;
163 testsPassed = 0;
164 testsFailed = 0;
165
166
167 //
168 // Put your tests here.
169 //
170
171 // truth
172 ensureIntegerEqual("TRUE", TRUE, TRUE);
173 ensureIntegerEqual("FALSE", FALSE, FALSE);
174
175 // equality
176 ensureIntegerEqual("(TRUE == TRUE)", (TRUE == TRUE), TRUE);
177 ensureIntegerEqual("(TRUE == FALSE)", (TRUE == FALSE), FALSE);
178 ensureIntegerEqual("(TRUE == FALSE)", (TRUE == FALSE), FALSE);
179 ensureIntegerEqual("(FALSE == FALSE)", (FALSE == FALSE), TRUE);
180
181 // inequality
182 ensureIntegerEqual("(TRUE != TRUE)", (TRUE != TRUE), FALSE);
183 ensureIntegerEqual("(TRUE != FALSE)", (TRUE != FALSE), TRUE);
184 ensureIntegerEqual("(TRUE != FALSE)", (TRUE != FALSE), TRUE);
185 ensureIntegerEqual("(FALSE != FALSE)", (FALSE != FALSE), FALSE);
186
187 // and
188 ensureIntegerEqual("(TRUE && TRUE)", (TRUE && TRUE), TRUE);
189 ensureIntegerEqual("(TRUE && FALSE)", (TRUE && FALSE), FALSE);
190 ensureIntegerEqual("(FALSE && TRUE)", (FALSE && TRUE), FALSE);
191 ensureIntegerEqual("(FALSE && FALSE)", (FALSE && FALSE), FALSE);
192
193 // or
194 ensureIntegerEqual("(TRUE || TRUE)", (TRUE || TRUE), TRUE);
195 ensureIntegerEqual("(TRUE || FALSE)", (TRUE || FALSE), TRUE);
196 ensureIntegerEqual("(FALSE || TRUE)", (FALSE || TRUE), TRUE);
197 ensureIntegerEqual("(FALSE || FALSE)", (FALSE || FALSE), FALSE);
198
199 // not
200 ensureIntegerEqual("(! TRUE)", (! TRUE), FALSE);
201 ensureIntegerEqual("(! FALSE)", (! FALSE), TRUE);
202
203 // greater than
204 ensureIntegerEqual("(1 > 0)", (1 > 0), TRUE);
205 ensureIntegerEqual("(0 > 1)", (0 > 1), FALSE);
206 ensureIntegerEqual("(1 > 1)", (1 > 1), FALSE);
207
208 // less than
209 ensureIntegerEqual("(0 < 1)", (0 < 1), TRUE);
210 ensureIntegerEqual("(1 < 0)", (1 < 0), FALSE);
211 ensureIntegerEqual("(1 < 1)", (1 < 1), FALSE);
212
213 // greater than or equal
214 ensureIntegerEqual("(1 >= 0)", (1 >= 0), TRUE);
215 ensureIntegerEqual("(0 >= 1)", (0 >= 1), FALSE);
216 ensureIntegerEqual("(1 >= 1)", (1 >= 1), TRUE);
217
218 // tess than or equal
219 ensureIntegerEqual("(0 <= 1)", (0 <= 1), TRUE);
220 ensureIntegerEqual("(1 <= 0)", (1 <= 0), FALSE);
221 ensureIntegerEqual("(1 <= 1)", (1 <= 1), TRUE);
222
223 // bitwise and
224 ensureIntegerEqual("(10 & 25)", (10 & 25), 8);
225
226 // bitwise or
227 ensureIntegerEqual("(10 | 25)", (10 | 25), 27);
228
229 // bitwise not
230// ensureIntegerEqual("~10", ~10, -11);
231
232 // xor
233// ensureIntegerEqual("(10 ^ 25)", (10 ^ 25), 19);
234
235 // right shift
236 ensureIntegerEqual("(523 >> 2)", (523 >> 2), 130);
237
238 // left shift
239 ensureIntegerEqual("(523 << 2)", (523 << 2), 2092);
240
241 // addition
242 ensureIntegerEqual("(1 + 1)", (1 + 1), 2);
243 ensureFloatEqual("(1 + 1.1)", (1 + 1.1), 2.1);
244 ensureFloatEqual("(1.1 + 1)", (1.1 + 1), 2.1);
245 ensureFloatEqual("(1.1 + 1.1)", (1.1 + 1.1), 2.2);
246 ensureStringEqual("\"foo\" + \"bar\"", "foo" + "bar", "foobar");
247// ensureVectorEqual("(<1.1, 2.2, 3.3> + <4.4, 5.5, 6.6>)", (<1.1, 2.2, 3.3> + <4.4, 5.5, 6.6>), <5.5, 7.7, 9.9>);
248// ensureRotationEqual("(<1.1, 2.2, 3.3, 4.4> + <4.4, 5.5, 6.6, 3.3>)", (<1.1, 2.2, 3.3, 4.4> + <4.4, 5.5, 6.6, 3.3>), <5.5, 7.7, 9.9, 7.7>);
249// ensureListEqual("([1] + 2)", ([1] + 2), [1,2]);
250// ensureListEqual("([] + 1.5)", ([] + 1.5), [1.5]);
251// ensureListEqual("([\"foo\"] + \"bar\")", (["foo"] + "bar"), ["foo", "bar"]);
252// ensureListEqual("([] + <1,2,3>)", ([] + <1,2,3>), [<1,2,3>]);
253// ensureListEqual("([] + <1,2,3,4>)", ([] + <1,2,3,4>), [<1,2,3,4>]);
254
255 // subtraction
256 ensureIntegerEqual("(1 - 1)", (1 - 1), 0);
257 ensureFloatEqual("(1 - 0.5)", (1 - 0.5), 0.5);
258 ensureFloatEqual("(1.5 - 1)", (1.5 - 1), 0.5);
259 ensureFloatEqual("(2.2 - 1.1)", (2.2 - 1.1), 1.1);
260// ensureVectorEqual("(<1.5, 2.5, 3.5> - <4.5, 5.5, 6.5>)", (<1.5, 2.5, 3.5> - <4.5, 5.5, 6.5>), <-3.0, -3.0, -3.0>);
261// ensureRotationEqual("(<1.5, 2.5, 3.5, 4.5> - <4.5, 5.5, 6.5, 7.5>)", (<1.5, 2.5, 3.5, 4.5> - <4.5, 5.5, 6.5, 7.5>), <-3.0, -3.0, -3.0, -3.0>);
262
263 // multiplication
264 ensureIntegerEqual("(2 * 3)", (2 * 3), 6);
265 ensureFloatEqual("(2 * 3.5)", (2 * 3.5), 7.0);
266 ensureFloatEqual("(2.5 * 3)", (2.5 * 3), 7.5);
267 ensureFloatEqual("(2.5 * 3.5)", (2.5 * 3.5), 8.75);
268// ensureVectorEqual("(<1.1, 2.2, 3.3> * 2)", (<1.1, 2.2, 3.3> * 2), <2.2, 4.4, 6.6>);
269// ensureVectorEqual("(<2.2, 4.4, 6.6> * 2.0)", (<2.2, 4.4, 6.6> * 2.0), <4.4, 8.8, 13.2>);
270// ensureFloatEqual("(<1.0, 2.0, 3.0> * <4.0, 5.0, 6.0>)", (<1.0, 2.0, 3.0> * <4.0, 5.0, 6.0>), 32.0);
271
272 // division
273 ensureIntegerEqual("(2 / 2)", (2 / 2), 1);
274 ensureFloatEqual("(2.2 / 2)", (2.2 / 2), 1.1);
275 ensureFloatEqual("(3 / 1.5)", (3 / 1.5), 2.0);
276 ensureFloatEqual("(2.2 / 2.0)", (2.2 / 2.0), 1.1);
277// ensureVectorEqual("(<1.0, 2.0, 3.0> / 2)", (<1.0, 2.0, 3.0> / 2), <0.5, 1.0, 1.5>);
278// ensureVectorEqual("(<3.0, 6.0, 9.0> / 1.5)", (<3.0, 6.0, 9.0> / 1.5), <2.0, 4.0, 6.0>);
279
280 // modulo
281 ensureIntegerEqual("(3 % 1)", (3 % 1), 0);
282// ensureVectorEqual("(<1.0, 2.0, 3.0> % <4.0, 5.0, 6.0>)", (<1.0, 2.0, 3.0> % <4.0, 5.0, 6.0>), <-3.0, 6.0, -3.0>);
283
284 // assignment
285 integer i = 1;
286 ensureIntegerEqual("i = 1;", i, 1);
287
288 // addition assignment
289 i = 1;
290 i += 1;
291 ensureIntegerEqual("i = 1; i += 1;", i, 2);
292
293 // subtraction assignment
294 i = 1;
295 i -= 1;
296 ensureIntegerEqual("i = 1; i -= 1;", i, 0);
297
298 // multiplication assignment
299 i = 2;
300 i *= 2;
301 ensureIntegerEqual("i = 2; i *= 2;", i, 4);
302
303 // division assignment
304 i = 2;
305 i /= 2;
306 ensureIntegerEqual("i = 2; i /= 2;", i, 1);
307
308 // modulo assignment
309 i = 3;
310 i %= 1;
311 ensureIntegerEqual("i = 3; i %= 1;", i, 0);
312
313 // post increment.
314 i = 1;
315 ensureIntegerEqual("i = 1; (i == 2) && (i++ == 1)", (i == 2) && (i++ == 1), TRUE);
316
317 // pre increment.
318 i = 1;
319 ensureIntegerEqual("i = 1; (i == 2) && (++i == 2)", (i == 2) && (++i == 2), TRUE);
320
321 // post decrement.
322 i = 1;
323 ensureIntegerEqual("i = 1; (i == 0) && (i-- == 1)", (i == 0) && (i-- == 1), TRUE);
324
325 // pre decrement.
326 i = 1;
327 ensureIntegerEqual("i = 1; (i == 0) && (--i == 0)", (i == 0) && (--i == 0), TRUE);
328
329 // casting
330 ensureFloatEqual("((float)2)", ((float)2), 2.0);
331 ensureStringEqual("((string)2)", ((string)2), "2");
332 ensureIntegerEqual("((integer) 1.5)", ((integer) 1.5), 1);
333 ensureStringEqual("((string) 1.5)", ((string) 1.5), "1.500000");
334 ensureIntegerEqual("((integer) \"0xF\")", ((integer) "0xF"), 15);
335 ensureIntegerEqual("((integer) \"2\")", ((integer) "2"), 2);
336 ensureFloatEqual("((float) \"1.5\")", ((float) "1.5"), 1.5);
337// ensureVectorEqual("((vector) \"<1,2,3>\")", ((vector) "<1,2,3>"), <1,2,3>);
338// ensureRotationEqual("((rotation) \"<1,2,3,4>\")", ((rotation) "<1,2,3,4>"), <1,2,3,4>);
339 ensureStringEqual("((string) <1,2,3>)", ((string) <1,2,3>), "<1.00000, 2.00000, 3.00000>");
340 ensureStringEqual("((string) <1,2,3,4>)", ((string) <1,2,3,4>), "<1.00000, 2.00000, 3.00000, 4.00000>");
341 ensureStringEqual("((string) [1,2.5,<1,2,3>])", ((string) [1,2.5,<1,2,3>]), "12.500000<1.000000, 2.000000, 3.000000>");
342
343 // while
344 i = 0;
345// while(i < 10) ++i;
346 ensureIntegerEqual("i = 0; while(i < 10) ++i", i, 10);
347
348 // do while
349 i = 0;
350// do {++i;} while(i < 10);
351 ensureIntegerEqual("i = 0; do {++i;} while(i < 10);", i, 10);
352
353 // for
354// for(i = 0; i < 10; ++i);
355 ensureIntegerEqual("for(i = 0; i < 10; ++i);", i, 10);
356
357 // jump
358 i = 1;
359// jump SkipAssign;
360 i = 2;
361// @SkipAssign;
362 ensureIntegerEqual("i = 1; jump SkipAssign; i = 2; @SkipAssign;", i, 1);
363
364 // return
365 ensureIntegerEqual("testReturn()", testReturn(), 1);
366
367 // parameters
368 ensureIntegerEqual("testParameters(1)", testParameters(1), 2);
369
370 // variable parameters
371 i = 1;
372 ensureIntegerEqual("i = 1; testParameters(i)", testParameters(i), 2);
373
374 // recursion
375 ensureIntegerEqual("testRecursion(10)", testRecursion(10), 0);
376
377 // globals
378 ensureIntegerEqual("gInteger", gInteger, 5);
379 ensureFloatEqual("gFloat", gFloat, 1.5);
380 ensureStringEqual("gString", gString, "foo");
381// ensureVectorEqual("gVector", gVector, <1, 2, 3>);
382// ensureRotationEqual("gRot", gRot, <1, 2, 3, 4>);
383
384 // global assignment
385 gInteger = 1;
386 ensureIntegerEqual("gInteger = 1", gInteger, 1);
387
388 gFloat = 0.5;
389 ensureFloatEqual("gFloat = 0.5", gFloat, 0.5);
390
391 gString = "bar";
392 ensureStringEqual("gString = \"bar\"", gString, "bar");
393
394// gVector = <3,3,3>;
395// ensureVectorEqual("gVector = <3,3,3>", gVector, <3,3,3>);
396
397// gRot = <3,3,3,3>;
398// ensureRotationEqual("gRot = <3,3,3,3>", gRot, <3,3,3,3>);
399
400 // vector accessor
401 vector v;
402 v.x = 3;
403 ensureFloatEqual("v.x", v.x, 3);
404
405 // rotation accessor
406 rotation q;
407 q.s = 5;
408 ensureFloatEqual("q.s", q.s, 5);
409
410 // global vector accessor
411 gVector.y = 17.5;
412 ensureFloatEqual("gVector.y = 17.5", gVector.y, 17.5);
413
414 // global rotation accessor
415 gRot.z = 19.5;
416 ensureFloatEqual("gRot.z = 19.5", gRot.z, 19.5);
417
418 // list equality
419 list l = (list) 5;
420 list l2 = (list) 5;
421 ensureListEqual("list l = (list) 5; list l2 = (list) 5", l, l2);
422 ensureListEqual("list l = (list) 5", l, [5]);
423 ensureListEqual("[1.5, 6, <1,2,3>, <1,2,3,4>]", [1.5, 6, <1,2,3>, <1,2,3,4>], [1.5, 6, <1,2,3>, <1,2,3,4>]);
424
425
426 if (testsFailed > 0)
427 {
428 if (0 == verbosity)
429 result = result + "Shhh.";
430 if (1 == verbosity)
431 result = result + "Failed the testicle.";
432 if (2 == verbosity)
433 result = result + "The script called '" + llGetScriptName() + ".lsl' has failed " + (string) testsFailed + " of it's " + (string) (testsFailed + testsPassed) + " tests.";
434 result = result + " - FAILURE!!!";
435 }
436 else
437 {
438 if (0 == verbosity)
439 result = result + "Shhh.";
440 if (1 == verbosity)
441 result = result + "Passed the testicle.";
442 if (2 == verbosity)
443 result = result + "The script called '" + llGetScriptName() + ".lsl' has passed all " + (string) (testsFailed + testsPassed) + " of it's tests.";
444 result = result + " - SUCCESS";
445 }
446
447 llSay(0, llGetScriptName() + ": " + result);
448 }
449
450 on_rez(integer start_param)
451 {
452 llResetScript();
453 }
454}