A unification of subroutine and block frame creation.
[mpsl.git] / stress.c
blobdcebcdb4809fbe17cccb43c2ea066e41455f5ed3
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("/* 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; }");
137 do_test_mpsl("/* range assign */ a = [ 1 .. 1000 ];");
139 do_test_mpsl("a.b.c ++;");
140 do_test_mpsl("a.b.c --;");
141 do_test_mpsl("a.b.c += 100;");
143 do_test_mpsl("foreach (a, [ 1 .. 1000 ]) { print(a); }");
145 do_test_mpsl("local a;");
146 do_test_mpsl("local a, b, c;");
147 do_test_mpsl("local a = 666;");
148 do_test_mpsl("local a; a = 666;");
150 do_test_mpsl("a > b - 1;");
151 do_test_mpsl("a > b - 1 && a < c + 1;");
153 do_test_mpsl("a = NULL;");
154 do_test_mpsl("a = 100; b = 200;c = 300;");
155 do_test_mpsl("sub test {a = 100; b = 200;c = 300;}");
156 do_test_mpsl("sub test (d, e) {a = 100; b = 200;c = b;}");
157 do_test_mpsl("a();");
158 do_test_mpsl("! 1 > 2;");
159 do_test_mpsl("! (1 > 2);");
160 do_test_mpsl("1 != 2;");
161 do_test_mpsl("\"hello\" ne \"goodbye\";");
163 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; }"));
164 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; d=2; }"));
165 mpdm_dump(do_test_mpsl("sub test(a, b) { c=1; d=2; e=3; }"));
169 void test_mpsl2(void)
171 mpdm_t v;
172 mpdm_t w;
174 /* execution tests */
175 v = do_test_mpsl("666;");
176 mpdm_dump(v);
177 v = do_test_exec(v, NULL);
178 do_test("literal number", mpdm_ival(v) == 666);
180 v = do_test_mpsl("\"goodbye\";");
181 v = do_test_exec(v, NULL);
182 do_test("literal string", mpdm_cmp(v, MPDM_LS(L"goodbye")) == 0);
184 v = do_test_mpsl("1 + 3 + 5;");
185 v = do_test_exec(v, NULL);
186 do_test("mpsl calculator 1", mpdm_rval(v) == 9.0);
188 v = do_test_mpsl("1 + ((3 - 5) * 8);");
189 v = do_test_exec(v, NULL);
190 do_test("mpsl calculator 2", mpdm_rval(v) == -15.0);
192 /* next value cannot be tested as an exact equality,
193 as rounding errors will manifest */
194 v = do_test_mpsl("1.5 + ((3.1 - 5.8) * 8.0);");
195 v = do_test_exec(v, NULL);
196 do_test("mpsl calculator 3",
197 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("/* hash */ { \"enero\" => \"january\", \"febrero\" => \"february\" };");
221 v = do_test_exec(v, NULL);
222 mpdm_dump(v);
223 do_test("mpsl hash", mpdm_cmp(mpdm_hget(v,
224 MPDM_LS(L"febrero")), MPDM_LS(L"february")) == 0);
226 v = do_test_mpsl("! 1;");
227 v = do_test_exec(v, NULL);
228 do_test("boolean not 1", v == NULL);
229 v = do_test_mpsl("! 0;");
230 v = do_test_exec(v, NULL);
231 do_test("boolean not 2", v != NULL);
233 v = do_test_mpsl("1 && 3;");
234 v = do_test_exec(v, NULL);
235 do_test("boolean and 1", mpdm_ival(v) == 3);
236 v = do_test_mpsl("1 && 0;");
237 v = do_test_exec(v, NULL);
238 do_test("boolean and 2", !mpsl_is_true(v));
239 v = do_test_mpsl("0 && 1;");
240 v = do_test_exec(v, NULL);
241 do_test("boolean and 3", !mpsl_is_true(v));
243 v = do_test_mpsl("1 || 3;");
244 v = do_test_exec(v, NULL);
245 do_test("boolean or 1", mpdm_ival(v) == 1);
246 v = do_test_mpsl("2 || 0;");
247 v = do_test_exec(v, NULL);
248 do_test("boolean or 2", mpdm_ival(v) == 2);
249 v = do_test_mpsl("0 || 3;");
250 v = do_test_exec(v, NULL);
251 do_test("boolean or 3", mpdm_ival(v) == 3);
253 v = do_test_mpsl("6 == 6;");
254 v = do_test_exec(v, NULL);
255 do_test("numeric == 1", v != NULL);
256 v = do_test_mpsl("8.0 == 8.0;");
257 v = do_test_exec(v, NULL);
258 do_test("numeric == 2", v != NULL);
259 v = do_test_mpsl("6 == 8;");
260 v = do_test_exec(v, NULL);
261 do_test("numeric == 3", v == NULL);
263 v = do_test_mpsl("6 != 6;");
264 v = do_test_exec(v, NULL);
265 do_test("numeric != 1", v == NULL);
266 v = do_test_mpsl("8.0 != 8.0;");
267 v = do_test_exec(v, NULL);
268 do_test("numeric != 2", v == NULL);
269 v = do_test_mpsl("6 != 8;");
270 v = do_test_exec(v, NULL);
271 do_test("numeric != 3", v != NULL);
273 v = do_test_mpsl("6 < 6;");
274 v = do_test_exec(v, NULL);
275 do_test("numeric < 1", v == NULL);
276 v = do_test_mpsl("8 < 6;");
277 v = do_test_exec(v, NULL);
278 do_test("numeric < 2", v == NULL);
279 v = do_test_mpsl("5 < 6;");
280 v = do_test_exec(v, NULL);
281 do_test("numeric < 3", v != NULL);
283 v = do_test_mpsl("6 > 6;");
284 v = do_test_exec(v, NULL);
285 do_test("numeric > 1", v == NULL);
286 v = do_test_mpsl("8 > 6;");
287 v = do_test_exec(v, NULL);
288 do_test("numeric > 2", v != NULL);
289 v = do_test_mpsl("5 > 6;");
290 v = do_test_exec(v, NULL);
291 do_test("numeric > 3", v == NULL);
293 v = do_test_mpsl("6 <= 6;");
294 v = do_test_exec(v, NULL);
295 do_test("numeric <= 1", v != NULL);
296 v = do_test_mpsl("8 <= 6;");
297 v = do_test_exec(v, NULL);
298 do_test("numeric <= 2", v == NULL);
299 v = do_test_mpsl("5 <= 6;");
300 v = do_test_exec(v, NULL);
301 do_test("numeric <= 3", v != NULL);
303 v = do_test_mpsl("6 >= 6;");
304 v = do_test_exec(v, NULL);
305 do_test("numeric >= 1", v != NULL);
306 v = do_test_mpsl("8 >= 6;");
307 v = do_test_exec(v, NULL);
308 do_test("numeric >= 2", v != NULL);
309 v = do_test_mpsl("5 >= 6;");
310 v = do_test_exec(v, NULL);
311 do_test("numeric >= 3", v == NULL);
313 v = do_test_mpsl("11 % 6;");
314 v = do_test_exec(v, NULL);
315 do_test("modulo", mpdm_ival(v) == 5);
317 v = do_test_mpsl("variable=16384;");
318 mpdm_dump(v);
319 v = do_test_exec(v, NULL);
320 do_test("assign 1", mpdm_ival(v) == 16384);
322 v = do_test_mpsl("array=[10, 20, 30, 40];");
323 v = do_test_exec(v, NULL);
324 do_test("assign 2", mpdm_ival(mpdm_aget(v, 2)) == 30);
326 v = do_test_mpsl("a=1; b=2; c=3;");
327 mpdm_dump(v);
328 v = do_test_exec(v, NULL);
330 v = do_test_mpsl("CACHE={}; CACHE.regex=[]; CACHE.regex[0]=12345;");
331 v = do_test_exec(v, NULL);
333 v = do_test_mpsl("variable;");
334 v = do_test_exec(v, NULL);
335 do_test("symval 1", mpdm_ival(v) == 16384);
337 v = do_test_mpsl("variable2=1 + ((3 - 5) * 8); variable2;");
338 mpdm_dump(v);
339 v = do_test_exec(v, NULL);
340 do_test("symval 2", mpdm_rval(v) == -15);
342 v = do_test_mpsl("variable3=variable2 * 2;");
343 v = do_test_exec(v, NULL);
344 do_test("symval 3", mpdm_ival(v) == -30);
346 v = do_test_mpsl("sub mysum(a, b) { a + b; }");
347 mpdm_dump(v);
348 v = do_test_exec(v, NULL);
349 do_test("sub 1", v != NULL);
351 v = do_test_mpsl("sub pi() { 3.1416; }");
352 mpdm_dump(v);
353 v = do_test_exec(v, NULL);
354 do_test("sub 2", v != NULL);
356 v = do_test_mpsl("var10=pi();");
357 v = do_test_exec(v, NULL);
358 do_test("exec 1", mpdm_rval(v) == 3.1416);
360 v = do_test_mpsl("var11=pi() * 10000; var11;");
361 v = do_test_exec(v, NULL);
362 do_test("exec 2", mpdm_rval(v) == 31416);
364 v = do_test_mpsl("mysum(100, 20);");
365 v = do_test_exec(v, NULL);
366 do_test("exec 3", mpdm_rval(v) == 120.0);
368 v = do_test_mpsl("a = NULL;");
369 v = do_test_exec(v, NULL);
370 do_test("NULL 1", v == NULL);
372 v = do_test_mpsl("a == NULL;");
373 v = do_test_exec(v, NULL);
374 do_test("NULL 2", mpdm_ival(v) == 1);
376 v = do_test_mpsl("local a, b; a = 1; b = 2;");
377 v = do_test_exec(v, NULL);
379 v = do_test_mpsl("a == NULL;");
380 v = do_test_exec(v, NULL);
381 do_test("local 1", mpdm_ival(v) == 1);
383 v = do_test_mpsl("66 * -1;");
384 v = do_test_exec(v, NULL);
385 do_test("uminus", mpdm_ival(v) == -66);
387 v = do_test_mpsl("\"test\" eq \"test\";");
388 v = do_test_exec(v, NULL);
389 do_test("streq 1", mpsl_is_true(v));
391 v = do_test_mpsl("\"test\" eq \"prueba\";");
392 v = do_test_exec(v, NULL);
393 do_test("streq 1", ! mpsl_is_true(v));
395 v = do_test_mpsl("a = 6; ++ a;");
396 v = do_test_exec(v, NULL);
397 do_test("pinc", mpdm_ival(v) == 7);
399 v = do_test_mpsl("a++;");
400 v = do_test_exec(v, NULL);
401 do_test("sinc", mpdm_ival(v) == 7);
403 v = do_test_mpsl("a += 10;");
404 v = do_test_exec(v, NULL);
405 do_test("iadd", mpdm_ival(v) == 18);
407 v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a == b) c=1000; c;");
408 v = do_test_exec(v, NULL);
409 do_test("if 1", mpdm_ival(v) == 3);
411 v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a <= b) c=1000; c;");
412 v = do_test_exec(v, NULL);
413 do_test("if 2", mpdm_ival(v) == 1000);
415 v = do_test_mpsl("local a, b, c; a=1; b=2; if(a == b) c=1000; else c=2000; c;");
416 v = do_test_exec(v, NULL);
417 do_test("ifelse", mpdm_ival(v) == 2000);
419 v = do_test_mpsl("local a; a = 0; while(a < 100) { a++; } a;");
420 v = do_test_exec(v, NULL);
421 do_test("ifelse", mpdm_ival(v) == 100);
423 v = do_test_mpsl("a=mysum(100, 50); a;");
424 v = do_test_exec(v, NULL);
425 do_test("mysum 1", mpdm_ival(v) == 150);
427 v = do_test_mpsl("a=mysum(2000, 500); a;");
428 v = do_test_exec(v, NULL);
429 do_test("mysum 2", mpdm_ival(v) == 2500);
431 w = mpdm_ref(MPDM_A(2));
432 mpdm_aset(w, MPDM_I(100), 0);
433 mpdm_aset(w, MPDM_I(50), 1);
435 /* asks for the value of the mysum symbol (the code) */
436 v = do_test_mpsl("mysum;");
437 /* executes, so mysum() itself is being returned */
438 v = do_test_exec(v, NULL);
439 mpdm_dump(v);
440 do_test("mysum 3", mpdm_ival(do_test_exec(v, w)) == 150);
442 mpdm_aset(w, MPDM_I(75), 1);
443 do_test("mysum 4", mpdm_ival(do_test_exec(v, w)) == 175);
445 /* compiles (and executes) the definition of gcd() */
446 v = do_test_mpsl("/* 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; }");
447 do_test_exec(v, NULL);
449 /* gets a pointer to gcd() */
450 v = do_test_exec(do_test_mpsl("gcd;"), NULL);
451 mpdm_dump(v);
453 /* executes gcd(100, 50); */
454 mpdm_aset(w, MPDM_I(50), 1);
455 do_test("gcd() 1", mpdm_ival(do_test_exec(v, w)) == 50);
457 /* executes gcd(100, 75); */
458 mpdm_aset(w, MPDM_I(75), 1);
459 do_test("gcd() 2", mpdm_ival(do_test_exec(v, w)) == 25);
461 mpdm_unref(w);
463 /* string concatenation */
464 w = mpdm_ref(MPDM_LS(L"big lebowski"));
466 v = do_test_mpsl("\"big\" ~ \" lebowski\";");
467 do_test("~ (strcat 1)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);
469 v = do_test_mpsl("\"big\" ~ \" \" ~ \"lebowski\";");
470 do_test("~ (strcat 2)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);
472 mpdm_unref(w);
476 void test_mpsl3(void)
478 mpdm_t v;
480 v = do_test_mpsl("v=[10,20]; w=v[0]; w;");
481 mpdm_dump(v);
482 v = do_test_exec(v, NULL);
483 mpdm_dump(v);
485 /* library functions tests */
486 v = do_test_mpsl("dump( [1, 2, 3, 4, 5] );");
487 do_test_exec(v, NULL);
489 v = do_test_mpsl("if(size([2, 3, 4]) == 3) { dump(\"YES\"); } else { dump(\"NO\"); }");
490 do_test_exec(v, NULL);
492 v = do_test_mpsl("is_array(1);");
493 do_test("is_array 1", do_test_exec(v, NULL) == NULL);
494 v = do_test_mpsl("is_array([]);");
495 do_test("is_array 2", do_test_exec(v, NULL) != NULL);
496 v = do_test_mpsl("is_array({});");
497 do_test("is_array 3", do_test_exec(v, NULL) != NULL);
499 v = do_test_mpsl("is_hash(1);");
500 do_test("is_hash 1", do_test_exec(v, NULL) == NULL);
501 v = do_test_mpsl("is_hash([]);");
502 do_test("is_hash 2", do_test_exec(v, NULL) == NULL);
503 v = do_test_mpsl("is_hash({});");
504 do_test("is_hash 3", do_test_exec(v, NULL) != NULL);
506 v = do_test_mpsl("v=splice(\"inventions of life\", NULL, 0, 10); v[1];");
507 v = do_test_exec(v, NULL);
508 do_test("splice 1", mpdm_cmp(v, MPDM_LS(L"inventions")) == 0);
510 v = do_test_mpsl("v[0];");
511 v = do_test_exec(v, NULL);
512 do_test("splice 2", mpdm_cmp(v, MPDM_LS(L" of life")) == 0);
514 v = do_test_mpsl("sub func() { if(1 == 1) { return(6); 24; } 12; }");
515 v = do_test_exec(v, NULL);
516 v = do_test_mpsl("a=func();");
517 v = do_test_exec(v, NULL);
518 do_test("return 1", mpdm_ival(v) == 6);
520 v = do_test_mpsl("a=func(); 500;");
521 v = do_test_exec(v, NULL);
522 do_test("return 2", mpdm_ival(v) == 500);
524 v = do_test_mpsl("sub func() { while(1 == 1) { return(6); 24; } 12; }");
525 v = do_test_exec(v, NULL);
526 v = do_test_mpsl("a=func();");
527 v = do_test_exec(v, NULL);
528 do_test("return 3", mpdm_ival(v) == 6);
530 v = do_test_mpsl("sub func() { foreach(a, [1 .. 10]) { return(6); 24; } 12; }");
531 v = do_test_exec(v, NULL);
532 v = do_test_mpsl("a=func();");
533 v = do_test_exec(v, NULL);
534 do_test("return 4", mpdm_ival(v) == 6);
536 v = do_test_mpsl("a=1; while(a < 10) { a++; } a;");
537 v = do_test_exec(v, NULL);
538 do_test("while", mpdm_ival(v) == 10);
540 v = do_test_mpsl("a=1; while(a < 10) { if(a == 5) break; a++; } a;");
541 v = do_test_exec(v, NULL);
542 do_test("break", mpdm_ival(v) == 5);
544 v = do_test_mpsl("b=0; foreach(a, [1, 2, 3, 4]) { dump(a); b += a; } return(b);");
545 v = do_test_exec(v, NULL);
546 do_test("foreach", mpdm_ival(v) == 10);
548 v = do_test_mpsl("b=0; foreach(a, [1 .. 20]) { dump(a); b += a; } return(b);");
549 v = do_test_exec(v, NULL);
550 do_test("foreach+range 1", mpdm_ival(v) == 210);
552 v = do_test_mpsl("b=0; foreach(a, [20 .. 1]) { dump(a); b += a; } return(b);");
553 v = do_test_exec(v, NULL);
554 do_test("foreach+range 2", mpdm_ival(v) == 210);
556 v = do_test_mpsl("print(\"print: \", 1, 2, [1, 2, 3], func(), 4);");
557 v = do_test_exec(v, NULL);
559 v = do_test_mpsl("'This is\\na string.';");
560 v = do_test_exec(v, NULL);
561 mpdm_dump(v);
563 v = do_test_mpsl("\"This is\\na string.\";");
564 v = do_test_exec(v, NULL);
565 mpdm_dump(v);
567 v = do_test_mpsl("sub t(h) { dump(h); dump(h.x); h.x; } H={}; H.x=5; t(H);");
568 v = do_test_exec(v, NULL);
569 do_test("Accesing a hash's component passed as argument", mpdm_ival(v) == 5);
571 /* mpdm_dump(mpdm_root());*/
575 void test_mpsl_file(void)
577 mpdm_t v;
579 mpsl_trace = 0;
581 /* Create an INC array with the current directory */
582 mpdm_exec(mpsl_compile(MPDM_LS(L"INC = [ '.' ];")), NULL);
584 printf("Compiling from file:\n");
585 v = do_test_mpsl_file("test.mpsl");
586 v = do_test_exec(v, NULL);
590 void test_abort_and_eval(void)
592 mpdm_t v;
593 mpdm_t e;
595 mpsl_abort = 0;
596 v = mpsl_compile(MPDM_LS(L"1000;"));
597 do_test("Abort 1", mpdm_ival(mpdm_exec(v, NULL)) == 1000);
599 /* set global abort function */
600 mpsl_abort = 1;
601 do_test("Abort 2", mpdm_exec(v, NULL) == NULL);
603 mpsl_abort = 0;
604 do_test("Abort 3", mpdm_ival(mpdm_exec(v, NULL)) == 1000);
606 mpsl_error(NULL);
608 v = mpsl_eval(MPDM_LS(L"invalid_code()"), NULL);
609 e = mpdm_hget_s(mpdm_root(), L"ERROR");
610 printf("The following error is OK:\n");
611 mpdm_dump(e);
612 do_test("eval 1", v == NULL && e != NULL);
614 v = mpsl_eval(MPDM_LS(L"undef_func();"), NULL);
615 e = mpdm_hget_s(mpdm_root(), L"ERROR");
616 printf("The following error is also OK:\n");
617 mpdm_dump(e);
618 do_test("eval 2", v == NULL && e != NULL);
620 v = mpsl_eval(MPDM_LS(L"load('unexistent_file.mpsl');"), NULL);
621 e = mpdm_hget_s(mpdm_root(), L"ERROR");
622 printf("The following error is also OK:\n");
623 mpdm_dump(e);
624 do_test("eval 3", v == NULL && e != NULL);
626 v = mpsl_eval(MPDM_LS(L"2000;"), NULL);
627 e = mpdm_hget_s(mpdm_root(), L"ERROR");
628 do_test("eval 4", mpdm_ival(v) == 2000 && e == NULL);
632 int main(void)
634 mpsl_startup();
636 mpdm->default_sweep = 64;
638 mpsl_trace = 1;
639 test_mpsl();
640 test_mpsl2();
641 test_mpsl3();
642 test_mpsl_file();
643 test_abort_and_eval();
645 printf("memory: %d\n", mpdm->memory_usage);
646 mpdm_sweep(-1);
647 mpdm_sweep(-1);
648 mpdm_sweep(-1);
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 printf("memory: %d\n", mpdm->memory_usage);
657 mpsl_shutdown();
659 printf("\n*** Total tests passed: %d/%d\n", oks, tests);
661 if(oks == tests)
662 printf("*** ALL TESTS PASSED\n");
663 else
665 int n;
667 printf("*** %d %s\n", tests - oks, "TESTS ---FAILED---");
669 printf("\nFailed tests:\n\n");
670 for(n = 0;n < i_failed_msgs;n++)
671 printf("%s", failed_msgs[n]);
674 return(0);