Renamed 'symbol_table' to 'symtbl'.
[mpsl.git] / stress.c
blob606082cfe1931f7eca0b356fca7ed119b2f8d9e3
1 /*
3 MPSL - Minimum Profit Scripting Language
4 Copyright (C) 2003/2007 Angel Ortega <angel@triptico.com>
6 stress.c - Stress tests for MPSL.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
26 #include <stdio.h>
27 #include <string.h>
28 #include <wchar.h>
30 #include "mpdm.h"
31 #include "mpsl.h"
33 /* total number of tests and oks */
34 int tests = 0;
35 int oks = 0;
37 /* failed tests messages */
38 char *failed_msgs[5000];
39 int i_failed_msgs = 0;
41 /*******************
42 Code
43 ********************/
45 void do_test(char *str, int ok)
47 char tmp[1024];
49 sprintf(tmp, "%s: %s\n", str, ok ? "OK!" : "*** Failed ***");
50 printf(tmp);
52 tests++;
54 if (ok)
55 oks++;
56 else
57 failed_msgs[i_failed_msgs++] = strdup(tmp);
61 /* tests */
63 void do_set(mpdm_t * v1, mpdm_t v2)
65 mpdm_unref(*v1);
66 *v1 = mpdm_ref(v2);
70 mpdm_t do_test_mpsl(char *code)
72 static mpdm_t v = NULL;
74 do_set(&v, mpsl_compile(MPDM_MBS(code)));
76 printf("Compile: ");
77 do_test(code, v != NULL);
78 return (v);
82 mpdm_t do_test_mpsl_file(char *file)
84 static mpdm_t v = NULL;
86 do_set(&v, mpsl_compile_file(MPDM_MBS(file)));
88 printf("Compile file: ");
89 do_test(file, v != NULL);
90 return (v);
94 mpdm_t do_test_exec(mpdm_t x, mpdm_t a)
96 static mpdm_t v = NULL;
98 do_set(&v, mpdm_exec(x, a));
100 return (v);
104 void test_mpsl(void)
106 mpdm_t v;
108 printf("MPSL (Minimum Profit Scripting Language)\n\n");
110 v = mpsl_compile(MPDM_LS(L"a=1;"));
111 do_test_exec(v, NULL);
113 printf("MPSL compilation tests-------------\n");
115 do_test_mpsl("a=1;");
116 do_test_mpsl("a.b.c=1;");
117 do_test_mpsl("a.b.c=d;");
118 do_test_mpsl("a.b.c=d.e.f;");
119 do_test_mpsl("a[\"b\"]=1;");
120 do_test_mpsl("a[\"b\"].c=1;");
121 do_test_mpsl("a[\"b\"][\"c\"]=1;");
122 do_test_mpsl("/* empty hash */ days={};");
123 do_test_mpsl("days.lunes=\"monday\";");
124 do_test_mpsl("days[\"martes\"]=\"tuesday\";");
126 do_test_mpsl("1 + ((3 - 5) * 8);");
127 do_test_mpsl("1.5 + ((3.1 - 5.8) * 8.0);");
128 do_test_mpsl("a=1 + ((3 - 5) * 8);");
129 do_test_mpsl("2 + 3 * 4;");
130 do_test_mpsl("2 * 3 + 4;");
132 do_test_mpsl("/* hash */ y={ 'enero' => 'january', 'febrero' => 'february' };");
133 do_test_mpsl("/* array */ a=[\"this\", \"one\", \"is\", 666, \"cool\"];");
135 do_test_mpsl
136 ("/* greatest common divisor (Euclid's algorithm) */ sub gcd(m, n) { while (m > 0) { if(n > m) { local t = m; m = n; n = t; } m -= n; } n; }");
138 do_test_mpsl("/* range assign */ a = [ 1 .. 1000 ];");
140 do_test_mpsl("a.b.c ++;");
141 do_test_mpsl("a.b.c --;");
142 do_test_mpsl("a.b.c += 100;");
144 do_test_mpsl("foreach (a, [ 1 .. 1000 ]) { print(a); }");
146 do_test_mpsl("local a;");
147 do_test_mpsl("local a, b, c;");
148 do_test_mpsl("local a = 666;");
149 do_test_mpsl("local a; a = 666;");
151 do_test_mpsl("a > b - 1;");
152 do_test_mpsl("a > b - 1 && a < c + 1;");
154 do_test_mpsl("a = NULL;");
155 do_test_mpsl("a = 100; b = 200;c = 300;");
156 do_test_mpsl("sub test {a = 100; b = 200;c = 300;}");
157 do_test_mpsl("sub test (d, e) {a = 100; b = 200;c = b;}");
158 do_test_mpsl("a();");
159 do_test_mpsl("! 1 > 2;");
160 do_test_mpsl("! (1 > 2);");
161 do_test_mpsl("1 != 2;");
162 do_test_mpsl("\"hello\" ne \"goodbye\";");
164 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; }"));
165 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; d=2; }"));
166 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; d=2; e=3; }"));
170 void test_mpsl2(void)
172 mpdm_t v;
173 mpdm_t w;
175 /* execution tests */
176 v = do_test_mpsl("666;");
177 mpdm_dump(v);
178 v = do_test_exec(v, NULL);
179 do_test("literal number", mpdm_ival(v) == 666);
181 v = do_test_mpsl("\"goodbye\";");
182 v = do_test_exec(v, NULL);
183 do_test("literal string", mpdm_cmp(v, MPDM_LS(L"goodbye")) == 0);
185 v = do_test_mpsl("1 + 3 + 5;");
186 v = do_test_exec(v, NULL);
187 do_test("mpsl calculator 1", mpdm_rval(v) == 9.0);
189 v = do_test_mpsl("1 + ((3 - 5) * 8);");
190 v = do_test_exec(v, NULL);
191 do_test("mpsl calculator 2", mpdm_rval(v) == -15.0);
193 /* next value cannot be tested as an exact equality,
194 as rounding errors will manifest */
195 v = do_test_mpsl("1.5 + ((3.1 - 5.8) * 8.0);");
196 v = do_test_exec(v, NULL);
197 do_test("mpsl calculator 3", mpdm_rval(v) < -20.0 && mpdm_rval(v) > -21.0);
199 v = do_test_mpsl("2 + 3 * 4;");
200 v = do_test_exec(v, NULL);
201 do_test("mpsl calculator 4", mpdm_rval(v) == 14.0);
203 v = do_test_mpsl("2 * 3 + 4;");
204 v = do_test_exec(v, NULL);
205 do_test("mpsl calculator 5", mpdm_rval(v) == 10.0);
207 v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL);
208 w = do_test_exec(do_test_mpsl("2 + (3 * 4);"), NULL);
209 do_test("mpsl calculator 6 (operator precedence)", mpdm_rval(v) == mpdm_rval(w));
211 v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL);
212 w = do_test_exec(do_test_mpsl("(2 + 3) * 4;"), NULL);
213 do_test("mpsl calculator 7 (operator precedence)", mpdm_rval(v) != mpdm_rval(w));
215 v = do_test_mpsl("/* array */ [\"this\", \"one\", \"is\", 666, \"cool\"];");
216 v = do_test_exec(v, NULL);
217 mpdm_dump(v);
218 do_test("mpsl array", mpdm_ival(mpdm_aget(v, 3)) == 666);
220 v = do_test_mpsl
221 ("/* hash */ { \"enero\" => \"january\", \"febrero\" => \"february\" };");
222 v = do_test_exec(v, NULL);
223 mpdm_dump(v);
224 do_test("mpsl hash", mpdm_cmp(mpdm_hget(v,
225 MPDM_LS(L"febrero")),
226 MPDM_LS(L"february")) == 0);
228 v = do_test_mpsl("! 1;");
229 v = do_test_exec(v, NULL);
230 do_test("boolean not 1", v == NULL);
231 v = do_test_mpsl("! 0;");
232 v = do_test_exec(v, NULL);
233 do_test("boolean not 2", v != NULL);
235 v = do_test_mpsl("1 && 3;");
236 v = do_test_exec(v, NULL);
237 do_test("boolean and 1", mpdm_ival(v) == 3);
238 v = do_test_mpsl("1 && 0;");
239 v = do_test_exec(v, NULL);
240 do_test("boolean and 2", !mpsl_is_true(v));
241 v = do_test_mpsl("0 && 1;");
242 v = do_test_exec(v, NULL);
243 do_test("boolean and 3", !mpsl_is_true(v));
245 v = do_test_mpsl("1 || 3;");
246 v = do_test_exec(v, NULL);
247 do_test("boolean or 1", mpdm_ival(v) == 1);
248 v = do_test_mpsl("2 || 0;");
249 v = do_test_exec(v, NULL);
250 do_test("boolean or 2", mpdm_ival(v) == 2);
251 v = do_test_mpsl("0 || 3;");
252 v = do_test_exec(v, NULL);
253 do_test("boolean or 3", mpdm_ival(v) == 3);
255 v = do_test_mpsl("6 == 6;");
256 v = do_test_exec(v, NULL);
257 do_test("numeric == 1", v != NULL);
258 v = do_test_mpsl("8.0 == 8.0;");
259 v = do_test_exec(v, NULL);
260 do_test("numeric == 2", v != NULL);
261 v = do_test_mpsl("6 == 8;");
262 v = do_test_exec(v, NULL);
263 do_test("numeric == 3", v == NULL);
265 v = do_test_mpsl("6 != 6;");
266 v = do_test_exec(v, NULL);
267 do_test("numeric != 1", v == NULL);
268 v = do_test_mpsl("8.0 != 8.0;");
269 v = do_test_exec(v, NULL);
270 do_test("numeric != 2", v == NULL);
271 v = do_test_mpsl("6 != 8;");
272 v = do_test_exec(v, NULL);
273 do_test("numeric != 3", v != NULL);
275 v = do_test_mpsl("6 < 6;");
276 v = do_test_exec(v, NULL);
277 do_test("numeric < 1", v == NULL);
278 v = do_test_mpsl("8 < 6;");
279 v = do_test_exec(v, NULL);
280 do_test("numeric < 2", v == NULL);
281 v = do_test_mpsl("5 < 6;");
282 v = do_test_exec(v, NULL);
283 do_test("numeric < 3", v != NULL);
285 v = do_test_mpsl("6 > 6;");
286 v = do_test_exec(v, NULL);
287 do_test("numeric > 1", v == NULL);
288 v = do_test_mpsl("8 > 6;");
289 v = do_test_exec(v, NULL);
290 do_test("numeric > 2", v != NULL);
291 v = do_test_mpsl("5 > 6;");
292 v = do_test_exec(v, NULL);
293 do_test("numeric > 3", v == NULL);
295 v = do_test_mpsl("6 <= 6;");
296 v = do_test_exec(v, NULL);
297 do_test("numeric <= 1", v != NULL);
298 v = do_test_mpsl("8 <= 6;");
299 v = do_test_exec(v, NULL);
300 do_test("numeric <= 2", v == NULL);
301 v = do_test_mpsl("5 <= 6;");
302 v = do_test_exec(v, NULL);
303 do_test("numeric <= 3", v != NULL);
305 v = do_test_mpsl("6 >= 6;");
306 v = do_test_exec(v, NULL);
307 do_test("numeric >= 1", v != NULL);
308 v = do_test_mpsl("8 >= 6;");
309 v = do_test_exec(v, NULL);
310 do_test("numeric >= 2", v != NULL);
311 v = do_test_mpsl("5 >= 6;");
312 v = do_test_exec(v, NULL);
313 do_test("numeric >= 3", v == NULL);
315 v = do_test_mpsl("11 % 6;");
316 v = do_test_exec(v, NULL);
317 do_test("modulo", mpdm_ival(v) == 5);
319 v = do_test_mpsl("variable=16384;");
320 mpdm_dump(v);
321 v = do_test_exec(v, NULL);
322 do_test("assign 1", mpdm_ival(v) == 16384);
324 v = do_test_mpsl("array=[10, 20, 30, 40];");
325 v = do_test_exec(v, NULL);
326 do_test("assign 2", mpdm_ival(mpdm_aget(v, 2)) == 30);
328 v = do_test_mpsl("a=1; b=2; c=3;");
329 mpdm_dump(v);
330 v = do_test_exec(v, NULL);
332 v = do_test_mpsl("CACHE={}; CACHE.regex=[]; CACHE.regex[0]=12345;");
333 v = do_test_exec(v, NULL);
335 v = do_test_mpsl("variable;");
336 v = do_test_exec(v, NULL);
337 do_test("symval 1", mpdm_ival(v) == 16384);
339 v = do_test_mpsl("variable2=1 + ((3 - 5) * 8); variable2;");
340 mpdm_dump(v);
341 v = do_test_exec(v, NULL);
342 do_test("symval 2", mpdm_rval(v) == -15);
344 v = do_test_mpsl("variable3=variable2 * 2;");
345 v = do_test_exec(v, NULL);
346 do_test("symval 3", mpdm_ival(v) == -30);
348 v = do_test_mpsl("sub mysum(a, b) { a + b; }");
349 mpdm_dump(v);
350 v = do_test_exec(v, NULL);
351 do_test("sub 1", v != NULL);
353 v = do_test_mpsl("sub pi() { 3.1416; }");
354 mpdm_dump(v);
355 v = do_test_exec(v, NULL);
356 do_test("sub 2", v != NULL);
358 v = do_test_mpsl("var10=pi();");
359 v = do_test_exec(v, NULL);
360 do_test("exec 1", mpdm_rval(v) == 3.1416);
362 v = do_test_mpsl("var11=pi() * 10000; var11;");
363 v = do_test_exec(v, NULL);
364 do_test("exec 2", mpdm_rval(v) == 31416);
366 v = do_test_mpsl("mysum(100, 20);");
367 v = do_test_exec(v, NULL);
368 do_test("exec 3", mpdm_rval(v) == 120.0);
370 v = do_test_mpsl("a = NULL;");
371 v = do_test_exec(v, NULL);
372 do_test("NULL 1", v == NULL);
374 v = do_test_mpsl("a == NULL;");
375 v = do_test_exec(v, NULL);
376 do_test("NULL 2", mpdm_ival(v) == 1);
378 v = do_test_mpsl("local a, b; a = 1; b = 2;");
379 v = do_test_exec(v, NULL);
381 v = do_test_mpsl("a == NULL;");
382 v = do_test_exec(v, NULL);
383 do_test("local 1", mpdm_ival(v) == 1);
385 v = do_test_mpsl("66 * -1;");
386 v = do_test_exec(v, NULL);
387 do_test("uminus", mpdm_ival(v) == -66);
389 v = do_test_mpsl("\"test\" eq \"test\";");
390 v = do_test_exec(v, NULL);
391 do_test("streq 1", mpsl_is_true(v));
393 v = do_test_mpsl("\"test\" eq \"prueba\";");
394 v = do_test_exec(v, NULL);
395 do_test("streq 1", !mpsl_is_true(v));
397 v = do_test_mpsl("a = 6; ++ a;");
398 v = do_test_exec(v, NULL);
399 do_test("pinc", mpdm_ival(v) == 7);
401 v = do_test_mpsl("a++;");
402 v = do_test_exec(v, NULL);
403 do_test("sinc", mpdm_ival(v) == 7);
405 v = do_test_mpsl("a += 10;");
406 v = do_test_exec(v, NULL);
407 do_test("iadd", mpdm_ival(v) == 18);
409 v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a == b) c=1000; c;");
410 v = do_test_exec(v, NULL);
411 do_test("if 1", mpdm_ival(v) == 3);
413 v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a <= b) c=1000; c;");
414 v = do_test_exec(v, NULL);
415 do_test("if 2", mpdm_ival(v) == 1000);
417 v = do_test_mpsl("local a, b, c; a=1; b=2; if(a == b) c=1000; else c=2000; c;");
418 v = do_test_exec(v, NULL);
419 do_test("ifelse", mpdm_ival(v) == 2000);
421 v = do_test_mpsl("local a; a = 0; while(a < 100) { a++; } a;");
422 v = do_test_exec(v, NULL);
423 do_test("ifelse", mpdm_ival(v) == 100);
425 v = do_test_mpsl("a=mysum(100, 50); a;");
426 v = do_test_exec(v, NULL);
427 do_test("mysum 1", mpdm_ival(v) == 150);
429 v = do_test_mpsl("a=mysum(2000, 500); a;");
430 v = do_test_exec(v, NULL);
431 do_test("mysum 2", mpdm_ival(v) == 2500);
433 w = mpdm_ref(MPDM_A(2));
434 mpdm_aset(w, MPDM_I(100), 0);
435 mpdm_aset(w, MPDM_I(50), 1);
437 /* asks for the value of the mysum symbol (the code) */
438 v = do_test_mpsl("mysum;");
439 /* executes, so mysum() itself is being returned */
440 v = do_test_exec(v, NULL);
441 mpdm_dump(v);
442 do_test("mysum 3", mpdm_ival(do_test_exec(v, w)) == 150);
444 mpdm_aset(w, MPDM_I(75), 1);
445 do_test("mysum 4", mpdm_ival(do_test_exec(v, w)) == 175);
447 /* compiles (and executes) the definition of gcd() */
448 v = do_test_mpsl
449 ("/* greatest common divisor (Euclid's algorithm) */ sub gcd(m, n) { while (m > 0) { if(n > m) { local t = m; m = n; n = t; } m -= n; } n; }");
450 do_test_exec(v, NULL);
452 /* gets a pointer to gcd() */
453 v = do_test_exec(do_test_mpsl("gcd;"), NULL);
454 mpdm_dump(v);
456 /* executes gcd(100, 50); */
457 mpdm_aset(w, MPDM_I(50), 1);
458 do_test("gcd() 1", mpdm_ival(do_test_exec(v, w)) == 50);
460 /* executes gcd(100, 75); */
461 mpdm_aset(w, MPDM_I(75), 1);
462 do_test("gcd() 2", mpdm_ival(do_test_exec(v, w)) == 25);
464 mpdm_unref(w);
466 /* string concatenation */
467 w = mpdm_ref(MPDM_LS(L"big lebowski"));
469 v = do_test_mpsl("\"big\" ~ \" lebowski\";");
470 do_test("~ (strcat 1)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);
472 v = do_test_mpsl("\"big\" ~ \" \" ~ \"lebowski\";");
473 do_test("~ (strcat 2)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);
475 mpdm_unref(w);
479 void test_mpsl3(void)
481 mpdm_t v;
483 v = do_test_mpsl("v=[10,20]; w=v[0]; w;");
484 mpdm_dump(v);
485 v = do_test_exec(v, NULL);
486 mpdm_dump(v);
488 /* library functions tests */
489 v = do_test_mpsl("dump( [1, 2, 3, 4, 5] );");
490 do_test_exec(v, NULL);
492 v = do_test_mpsl("if(size([2, 3, 4]) == 3) { dump(\"YES\"); } else { dump(\"NO\"); }");
493 do_test_exec(v, NULL);
495 v = do_test_mpsl("is_array(1);");
496 do_test("is_array 1", do_test_exec(v, NULL) == NULL);
497 v = do_test_mpsl("is_array([]);");
498 do_test("is_array 2", do_test_exec(v, NULL) != NULL);
499 v = do_test_mpsl("is_array({});");
500 do_test("is_array 3", do_test_exec(v, NULL) != NULL);
502 v = do_test_mpsl("is_hash(1);");
503 do_test("is_hash 1", do_test_exec(v, NULL) == NULL);
504 v = do_test_mpsl("is_hash([]);");
505 do_test("is_hash 2", do_test_exec(v, NULL) == NULL);
506 v = do_test_mpsl("is_hash({});");
507 do_test("is_hash 3", do_test_exec(v, NULL) != NULL);
509 v = do_test_mpsl("v=splice(\"inventions of life\", NULL, 0, 10); v[1];");
510 v = do_test_exec(v, NULL);
511 do_test("splice 1", mpdm_cmp(v, MPDM_LS(L"inventions")) == 0);
513 v = do_test_mpsl("v[0];");
514 v = do_test_exec(v, NULL);
515 do_test("splice 2", mpdm_cmp(v, MPDM_LS(L" of life")) == 0);
517 v = do_test_mpsl("sub func() { if(1 == 1) { return(6); 24; } 12; }");
518 v = do_test_exec(v, NULL);
519 v = do_test_mpsl("a=func();");
520 v = do_test_exec(v, NULL);
521 do_test("return 1", mpdm_ival(v) == 6);
523 v = do_test_mpsl("a=func(); 500;");
524 v = do_test_exec(v, NULL);
525 do_test("return 2", mpdm_ival(v) == 500);
527 v = do_test_mpsl("sub func() { while(1 == 1) { return(6); 24; } 12; }");
528 v = do_test_exec(v, NULL);
529 v = do_test_mpsl("a=func();");
530 v = do_test_exec(v, NULL);
531 do_test("return 3", mpdm_ival(v) == 6);
533 v = do_test_mpsl("sub func() { foreach(a, [1 .. 10]) { return(6); 24; } 12; }");
534 v = do_test_exec(v, NULL);
535 v = do_test_mpsl("a=func();");
536 v = do_test_exec(v, NULL);
537 do_test("return 4", mpdm_ival(v) == 6);
539 v = do_test_mpsl("a=1; while(a < 10) { a++; } a;");
540 v = do_test_exec(v, NULL);
541 do_test("while", mpdm_ival(v) == 10);
543 v = do_test_mpsl("a=1; while(a < 10) { if(a == 5) break; a++; } a;");
544 v = do_test_exec(v, NULL);
545 do_test("break", mpdm_ival(v) == 5);
547 v = do_test_mpsl("b=0; foreach(a, [1, 2, 3, 4]) { dump(a); b += a; } return(b);");
548 v = do_test_exec(v, NULL);
549 do_test("foreach", mpdm_ival(v) == 10);
551 v = do_test_mpsl("b=0; foreach(a, [1 .. 20]) { dump(a); b += a; } return(b);");
552 v = do_test_exec(v, NULL);
553 do_test("foreach+range 1", mpdm_ival(v) == 210);
555 v = do_test_mpsl("b=0; foreach(a, [20 .. 1]) { dump(a); b += a; } return(b);");
556 v = do_test_exec(v, NULL);
557 do_test("foreach+range 2", mpdm_ival(v) == 210);
559 v = do_test_mpsl("print(\"print: \", 1, 2, [1, 2, 3], func(), 4);");
560 v = do_test_exec(v, NULL);
562 v = do_test_mpsl("'This is\\na string.';");
563 v = do_test_exec(v, NULL);
564 mpdm_dump(v);
566 v = do_test_mpsl("\"This is\\na string.\";");
567 v = do_test_exec(v, NULL);
568 mpdm_dump(v);
570 v = do_test_mpsl("sub t(h) { dump(h); dump(h.x); h.x; } H={}; H.x=5; t(H);");
571 v = do_test_exec(v, NULL);
572 do_test("Accesing a hash's component passed as argument", mpdm_ival(v) == 5);
574 /* mpdm_dump(mpdm_root());*/
578 void test_mpsl_file(void)
580 mpdm_t v;
582 mpsl_trace = 0;
584 /* Create an INC array with the current directory */
585 mpdm_exec(mpsl_compile(MPDM_LS(L"INC = [ '.' ];")), NULL);
587 printf("Compiling from file:\n");
588 v = do_test_mpsl_file("test.mpsl");
589 v = do_test_exec(v, NULL);
593 void test_abort_and_eval(void)
595 mpdm_t v;
596 mpdm_t e;
598 mpsl_abort = 0;
599 v = mpsl_compile(MPDM_LS(L"1000;"));
600 do_test("Abort 1", mpdm_ival(mpdm_exec(v, NULL)) == 1000);
602 /* set global abort function */
603 mpsl_abort = 1;
604 do_test("Abort 2", mpdm_exec(v, NULL) == NULL);
606 mpsl_abort = 0;
607 do_test("Abort 3", mpdm_ival(mpdm_exec(v, NULL)) == 1000);
609 mpsl_error(NULL);
611 v = mpsl_eval(MPDM_LS(L"invalid_code()"), NULL);
612 e = mpdm_hget_s(mpdm_root(), L"ERROR");
613 printf("The following error is OK:\n");
614 mpdm_dump(e);
615 do_test("eval 1", v == NULL && e != NULL);
617 v = mpsl_eval(MPDM_LS(L"undef_func();"), NULL);
618 e = mpdm_hget_s(mpdm_root(), L"ERROR");
619 printf("The following error is also OK:\n");
620 mpdm_dump(e);
621 do_test("eval 2", v == NULL && e != NULL);
623 v = mpsl_eval(MPDM_LS(L"load('unexistent_file.mpsl');"), NULL);
624 e = mpdm_hget_s(mpdm_root(), L"ERROR");
625 printf("The following error is also OK:\n");
626 mpdm_dump(e);
627 do_test("eval 3", v == NULL && e != NULL);
629 v = mpsl_eval(MPDM_LS(L"2000;"), NULL);
630 e = mpdm_hget_s(mpdm_root(), L"ERROR");
631 do_test("eval 4", mpdm_ival(v) == 2000 && e == NULL);
635 int main(void)
637 mpsl_startup();
639 mpdm->default_sweep = 64;
641 mpsl_trace = 1;
642 test_mpsl();
643 test_mpsl2();
644 test_mpsl3();
645 test_mpsl_file();
646 test_abort_and_eval();
648 printf("memory: %d\n", mpdm->memory_usage);
649 mpdm_sweep(-1);
650 mpdm_sweep(-1);
651 mpdm_sweep(-1);
652 mpdm_sweep(-1);
653 mpdm_sweep(-1);
654 mpdm_sweep(-1);
655 mpdm_sweep(-1);
656 mpdm_sweep(-1);
657 mpdm_sweep(-1);
658 printf("memory: %d\n", mpdm->memory_usage);
660 mpsl_shutdown();
662 printf("\n*** Total tests passed: %d/%d\n", oks, tests);
664 if (oks == tests)
665 printf("*** ALL TESTS PASSED\n");
666 else {
667 int n;
669 printf("*** %d %s\n", tests - oks, "TESTS ---FAILED---");
671 printf("\nFailed tests:\n\n");
672 for (n = 0; n < i_failed_msgs; n++)
673 printf("%s", failed_msgs[n]);
676 return (0);