3 MPDM - Minimum Profit Data Manager
4 Copyright (C) 2003/2010 Angel Ortega <angel@triptico.com>
6 stress.c - Stress tests for MPDM.
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
34 /* total number of tests and oks */
38 /* failed tests messages */
39 char *failed_msgs
[5000];
40 int i_failed_msgs
= 0;
42 int do_benchmarks
= 0;
43 int do_multibyte_sregex_tests
= 0;
48 void _do_test(char *str
, int ok
, int src_line
)
52 sprintf(tmp
, "%s: %s (line %d)\n", str
, ok
? "OK!" : "*** Failed ***", src_line
);
60 failed_msgs
[i_failed_msgs
++] = strdup(tmp
);
63 #define do_test(str, ok) _do_test(str, ok, __LINE__)
65 #define C { int CC = mpdm->count
66 #define T(i) do_test("v counter", CC + i == mpdm->count); }
70 void test_counter(void)
74 C
; v
= MPDM_S(L
"hi"); T(1);
76 C
; w
= MPDM_A(0); T(1);
78 C
; mpdm_push(w
, v
); T(0);
80 C
; mpdm_adel(w
, 0); T(0); /* should fail in 2.x */
82 C
; mpdm_queue(w
, v
, 10); T(0);
84 C
; v
= MPDM_S(L
"this is a phrase"); T(1);
85 C
; w
= mpdm_split_s(L
" ", v
); T(5);
100 do_test("i == 65536", (i
== 65536));
101 do_test("v has MPDM_IVAL", (v
->flags
& MPDM_IVAL
));
104 do_test("r == 65536", (r
== 65536.0));
105 do_test("v has MPDM_RVAL", (v
->flags
& MPDM_RVAL
));
107 printf("mpdm_string: %ls\n", mpdm_string(MPDM_H(0)));
108 printf("mpdm_string: %ls\n", mpdm_string(MPDM_H(0)));
110 /* partial copies of strings */
111 v
= MPDM_LS(L
"this is not America");
112 v
= MPDM_NS((wchar_t *) v
->data
+ 4, 4);
114 do_test("Partial string values", mpdm_cmp(v
, MPDM_LS(L
" is ")) == 0);
116 v
= MPDM_S(L
"MUAHAHAHA!");
117 do_test("Testing mpdm_clone semantics 1", mpdm_clone(v
) == v
);
120 mpdm_aset(v
, MPDM_S(L
"evil"), 0);
121 mpdm_aset(v
, MPDM_S(L
"dead"), 1);
124 do_test("Testing mpdm_clone semantics 2.1", w
!= v
);
127 do_test("Testing mpdm_clone semantics 2.2", v
->ref
> 1);
128 do_test("Testing mpdm_clone semantics 2.3", mpdm_aget(w
, 0) == v
);
130 /* mbs / wcs tests */
131 v
= MPDM_MBS("This is (was) a multibyte string");
134 /* greek omega is 03a9 */
135 v
= MPDM_MBS("?Espa?a! (non-ASCII string, as ISO-8859-1 char *)");
137 printf("(Previous value will be NULL if locale doesn't match stress.c encoding)\n");
139 v
= MPDM_LS(L
"A capital greek omega between brackets [\x03a9]");
141 printf("(Previous value will only show on an Unicode terminal)\n");
145 do_test("rval 1", mpdm_rval(v
) == 3.1416);
146 do_test("ival 1", mpdm_ival(v
) == 3);
148 v
= MPDM_R(777777.0 / 2.0);
150 do_test("mpdm_rnew 1", mpdm_cmp(v
, MPDM_LS(L
"388888.5")) == 0);
152 v
= MPDM_R(388888.500);
154 do_test("mpdm_rnew 2", mpdm_cmp(v
, MPDM_LS(L
"388888.5")) == 0);
156 v
= MPDM_R(388888.412);
158 do_test("mpdm_rnew 3", mpdm_cmp(v
, MPDM_LS(L
"388888.412")) == 0);
160 v
= MPDM_R(388888.6543);
162 do_test("mpdm_rnew 4", mpdm_cmp(v
, MPDM_LS(L
"388888.6543")) == 0);
164 v
= MPDM_R(388888.0);
166 do_test("mpdm_rnew 5", mpdm_cmp(v
, MPDM_LS(L
"388888")) == 0);
168 v
= MPDM_R(0.050000);
170 do_test("mpdm_rnew 6", mpdm_cmp(v
, MPDM_LS(L
"0.05")) == 0);
174 do_test("mpdm_rnew 7", mpdm_cmp(v
, MPDM_LS(L
"0")) == 0);
176 v
= MPDM_LS(L
"0177");
177 do_test("mpdm_ival() for octal numbers", mpdm_ival(v
) == 0x7f);
179 v
= MPDM_LS(L
"0xFF");
180 do_test("mpdm_ival() for hexadecimal numbers", mpdm_ival(v
) == 255);
183 do_test("mpdm_rval() for octal numbers", mpdm_rval(v
) == 1.0);
185 v
= MPDM_LS(L
"0x7f");
186 do_test("mpdm_rval() for hexadecimal numbers", mpdm_ival(v
) == 127.0);
188 do_test("Two NULLs are equal", mpdm_cmp(NULL
, NULL
) == 0);
190 v
= MPDM_LS(L
"hahaha");
191 do_test("mpdm_cmp_s 1", mpdm_cmp_s(v
, L
"hahaha") == 0);
192 do_test("mpdm_cmp_s 2", mpdm_cmp_s(v
, L
"aahaha") > 0);
193 do_test("mpdm_cmp_s 3", mpdm_cmp_s(v
, L
"zahaha") < 0);
196 mpdm_t
sort_cb(mpdm_t args
)
200 /* sorts reversely */
201 d
= mpdm_cmp(mpdm_aget(args
, 1), mpdm_aget(args
, 0));
206 void test_array(void)
213 do_test("a->size == 0", (a
->size
== 0));
215 mpdm_push(a
, MPDM_LS(L
"sunday"));
216 mpdm_push(a
, MPDM_LS(L
"monday"));
217 mpdm_push(a
, MPDM_LS(L
"tuesday"));
218 mpdm_push(a
, MPDM_LS(L
"wednesday"));
219 mpdm_push(a
, MPDM_LS(L
"thursday"));
220 mpdm_push(a
, MPDM_LS(L
"friday"));
221 mpdm_push(a
, MPDM_LS(L
"saturday"));
223 do_test("a->size == 7", (a
->size
== 7));
226 mpdm_aset(a
, NULL
, 3);
230 do_test("NULLs are sorted on top", (mpdm_aget(a
, 0) == NULL
));
234 do_test("v is referenced again", (v
!= NULL
&& v
->ref
> 0));
237 do_test("mpdm_asort() works (1)", mpdm_cmp(mpdm_aget(a
, 0), MPDM_LS(L
"friday")) == 0);
238 do_test("mpdm_asort() works (2)",
239 mpdm_cmp(mpdm_aget(a
, 6), MPDM_LS(L
"wednesday")) == 0);
241 /* asort_cb sorts reversely */
242 mpdm_sort_cb(a
, 1, MPDM_X(sort_cb
));
244 do_test("mpdm_asort_cb() works (1)",
245 mpdm_cmp(mpdm_aget(a
, 6), MPDM_LS(L
"friday")) == 0);
246 do_test("mpdm_asort_cb() works (2)",
247 mpdm_cmp(mpdm_aget(a
, 0), MPDM_LS(L
"wednesday")) == 0);
251 mpdm_collapse(a
, 3, 1);
252 do_test("acollapse unrefs values", (v
->ref
< n
));
257 /* add several values */
258 for (n
= 0; n
< 10; n
++)
259 v
= mpdm_queue(a
, MPDM_I(n
), 10);
261 do_test("queue should still output NULL", (v
== NULL
));
263 v
= mpdm_queue(a
, MPDM_I(11), 10);
264 do_test("queue should no longer output NULL", (v
!= NULL
));
266 v
= mpdm_queue(a
, MPDM_I(12), 10);
267 do_test("queue should return 1", mpdm_ival(v
) == 1);
268 v
= mpdm_queue(a
, MPDM_I(13), 10);
269 do_test("queue should return 2", mpdm_ival(v
) == 2);
270 do_test("queue size should be 10", a
->size
== 10);
273 v
= mpdm_queue(a
, MPDM_I(14), 5);
276 do_test("queue size should be 5", a
->size
== 5);
277 do_test("last taken value should be 8", mpdm_ival(v
) == 8);
280 mpdm_aset(a
, MPDM_I(666), 6000);
282 do_test("array should have been automatically expanded", mpdm_size(a
) == 6001);
284 v
= mpdm_aget(a
, -1);
285 do_test("negative offsets in arrays 1", mpdm_ival(v
) == 666);
287 mpdm_aset(a
, MPDM_I(777), -2);
288 v
= mpdm_aget(a
, 5999);
289 do_test("negative offsets in arrays 2", mpdm_ival(v
) == 777);
291 mpdm_push(a
, MPDM_I(888));
292 v
= mpdm_aget(a
, -1);
293 do_test("negative offsets in arrays 3", mpdm_ival(v
) == 888);
296 mpdm_push(v
, MPDM_I(100));
299 /* array comparisons with mpdm_cmp() */
301 mpdm_aset(a
, MPDM_I(10), 0);
302 mpdm_aset(a
, MPDM_I(60), 1);
305 do_test("mpdm_cmp: array clones are equal", mpdm_cmp(a
, v
) == 0);
308 do_test("mpdm_cmp: shorter arrays are lesser", mpdm_cmp(a
, v
) > 0);
310 mpdm_push(v
, MPDM_I(80));
311 do_test("mpdm_cmp: 2# element is bigger, so array is bigger", mpdm_cmp(a
, v
) < 0);
323 do_test("hsize 1", mpdm_hsize(h
) == 0);
325 mpdm_hset(h
, MPDM_S(L
"mp"), MPDM_I(6));
326 v
= mpdm_hget(h
, MPDM_S(L
"mp"));
328 do_test("hsize 2", mpdm_hsize(h
) == 1);
330 do_test("hash: v != NULL", (v
!= NULL
));
332 do_test("hash: v == 6", (i
== 6));
334 mpdm_hset(h
, MPDM_S(L
"mp2"), MPDM_I(66));
335 v
= mpdm_hget(h
, MPDM_S(L
"mp2"));
337 do_test("hsize 3", mpdm_hsize(h
) == 2);
339 do_test("hash: v != NULL", (v
!= NULL
));
341 do_test("hash: v == 66", (i
== 66));
343 /* fills 100 values */
344 for (n
= 0; n
< 50; n
++)
345 mpdm_hset(h
, MPDM_I(n
), MPDM_I(n
* 10));
346 for (n
= 100; n
>= 50; n
--)
347 mpdm_hset(h
, MPDM_I(n
), MPDM_I(n
* 10));
349 do_test("hsize 4", mpdm_hsize(h
) == 103);
351 /* tests 100 values */
352 for (n
= 0; n
< 100; n
++) {
353 v
= mpdm_hget(h
, MPDM_I(n
));
358 do_test("hash: ival", (i
== n
* 10));
361 do_test("hash: hget", (v
!= NULL
));
364 printf("h's size: %d\n", mpdm_hsize(h
));
366 mpdm_hdel(h
, MPDM_LS(L
"mp"));
367 do_test("hsize 5", mpdm_hsize(h
) == 102);
375 /* use of non-strings as hashes */
379 mpdm_hset(h
, v
, MPDM_I(1234));
381 mpdm_hset(h
, v
, MPDM_I(12345));
383 mpdm_hset(h
, v
, MPDM_I(9876));
385 mpdm_hset(h
, v
, MPDM_I(6543));
386 i
= mpdm_ival(mpdm_hget(h
, v
));
389 do_test("hash: using non-strings as hash keys", (i
== 6543));
391 mpdm_hset(h
, MPDM_LS(L
"ok"), MPDM_I(666));
393 do_test("exists 1", mpdm_exists(h
, MPDM_LS(L
"ok")));
394 do_test("exists 2", !mpdm_exists(h
, MPDM_LS(L
"notok")));
397 v
= mpdm_hget_s(h
, L
"ok");
398 printf("v %s\n", v
== NULL
? "is NULL" : "is NOT NULL");
399 do_test("hget_s 1", mpdm_ival(v
) == 666);
404 for (n
= 0; n
< 1000; n
++) {
405 if (mpdm_hget_s(h
, L
"ok") != NULL
)
408 printf("i: %d\n", i
);
409 do_test("hget_s 1.2", i
== 1000);
412 mpdm_hget_s(h
, L
"ok");
414 do_test("hget 1.2.1", mpdm_hget(h
, MPDM_LS(L
"ok")) != NULL
);
416 mpdm_hset_s(h
, L
"ok", MPDM_I(777));
418 v
= mpdm_hget_s(h
, L
"ok");
419 do_test("hget_s + hset_s", mpdm_ival(v
) == 777);
423 void test_splice(void)
428 w
= mpdm_splice(MPDM_LS(L
"I'm agent Johnson"), MPDM_LS(L
"special "), 4, 0);
429 do_test("splice insertion",
430 mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I'm special agent Johnson")) == 0);
433 w
= mpdm_splice(MPDM_LS(L
"Life is a shit"), MPDM_LS(L
"cheat"), 10, 4);
434 do_test("splice insertion and deletion (1)",
435 mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"Life is a cheat")) == 0);
436 do_test("splice insertion and deletion (2)",
437 mpdm_cmp(mpdm_aget(w
, 1), MPDM_LS(L
"shit")) == 0);
440 w
= mpdm_splice(MPDM_LS(L
"I'm with dumb"), NULL
, 4, 4);
441 do_test("splice deletion (1)", mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I'm dumb")) == 0);
442 do_test("splice deletion (2)", mpdm_cmp(mpdm_aget(w
, 1), MPDM_LS(L
"with")) == 0);
445 v
= MPDM_LS(L
"It doesn't matter");
446 w
= mpdm_splice(v
, MPDM_LS(L
" two"), v
->size
, 0);
447 do_test("splice insertion at the end",
448 mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"It doesn't matter two")) == 0);
451 w
= mpdm_splice(NULL
, NULL
, 0, 0);
452 do_test("splice with two NULLS", (mpdm_aget(w
, 0) == NULL
));
454 w
= mpdm_splice(NULL
, MPDM_LS(L
"foo"), 0, 0);
455 do_test("splice with first value NULL",
456 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"foo")) == 0));
458 w
= mpdm_splice(MPDM_LS(L
"foo"), NULL
, 0, 0);
459 do_test("splice with second value NULL",
460 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"foo")) == 0));
462 v
= MPDM_LS(L
"I'm testing");
464 w
= mpdm_splice(v
, NULL
, 0, -1);
465 do_test("splice with negative del (1)",
466 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"")) == 0));
468 w
= mpdm_splice(v
, NULL
, 4, -1);
469 do_test("splice with negative del (2)",
470 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I'm ")) == 0));
472 w
= mpdm_splice(v
, NULL
, 4, -2);
473 do_test("splice with negative del (3)",
474 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I'm g")) == 0));
476 w
= mpdm_splice(v
, NULL
, 0, -4);
477 do_test("splice with negative del (4)",
478 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"ing")) == 0));
479 mpdm_dump(mpdm_aget(w
, 0));
481 w
= mpdm_splice(v
, NULL
, 4, -20);
482 do_test("splice with out-of-bounds negative del",
483 (mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I'm testing")) == 0));
487 void test_strcat(void)
492 w
= MPDM_LS(L
"something");
494 v
= mpdm_strcat(NULL
, NULL
);
495 do_test("mpdm_strcat(NULL, NULL) returns NULL", v
== NULL
);
497 v
= mpdm_strcat(NULL
, w
);
498 do_test("mpdm_strcat(NULL, w) returns w", mpdm_cmp(v
, w
) == 0);
500 v
= mpdm_strcat(w
, NULL
);
501 do_test("mpdm_strcat(w, NULL) returns w", mpdm_cmp(v
, w
) == 0);
504 v
= mpdm_strcat(NULL
, w
);
505 do_test("mpdm_strcat(NULL, \"\") returns \"\"", mpdm_cmp(v
, w
) == 0);
507 v
= mpdm_strcat(w
, NULL
);
508 do_test("mpdm_strcat(\"\", NULL) returns \"\"", mpdm_cmp(v
, w
) == 0);
510 v
= mpdm_strcat(w
, w
);
511 do_test("mpdm_strcat(\"\", \"\") returns \"\"", mpdm_cmp(v
, w
) == 0);
516 void test_split(void)
520 printf("mpdm_split test\n\n");
522 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
"four.elems.in.string"));
524 do_test("4 elems: ", (w
->size
== 4));
526 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
"unseparated string"));
528 do_test("1 elem: ", (w
->size
== 1));
530 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
".dot.at start"));
532 do_test("3 elems: ", (w
->size
== 3));
534 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
"dot.at end."));
536 do_test("3 elems: ", (w
->size
== 3));
538 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
"three...dots (two empty elements)"));
540 do_test("4 elems: ", (w
->size
== 4));
542 w
= mpdm_split(MPDM_S(L
"."), MPDM_S(L
"."));
544 do_test("2 elems: ", (w
->size
== 2));
546 w
= mpdm_split(NULL
, MPDM_S(L
"I am the man"));
547 do_test("NULL split 1: ", mpdm_size(w
) == 12);
548 do_test("NULL split 2: ", mpdm_cmp(mpdm_aget(w
, 0), MPDM_LS(L
"I")) == 0);
558 printf("mpdm_join test\n\n");
564 mpdm_aset(w
, MPDM_S(L
"ce"), 0);
566 v
= mpdm_join(NULL
, w
);
567 do_test("1 elem, no separator", (mpdm_cmp(v
, MPDM_LS(L
"ce")) == 0));
570 do_test("1 elem, '--' separator", (mpdm_cmp(v
, MPDM_LS(L
"ce")) == 0));
572 mpdm_push(w
, MPDM_LS(L
"n'est"));
574 do_test("2 elems, '--' separator", (mpdm_cmp(v
, MPDM_LS(L
"ce--n'est")) == 0));
576 mpdm_push(w
, MPDM_LS(L
"pas"));
578 do_test("3 elems, '--' separator", (mpdm_cmp(v
, MPDM_LS(L
"ce--n'est--pas")) == 0));
580 v
= mpdm_join(NULL
, w
);
581 do_test("3 elems, no separator", (mpdm_cmp(v
, MPDM_LS(L
"cen'estpas")) == 0));
585 static mpdm_t
active(mpdm_t args
)
596 printf("mpdm_sset / mpdm_sget tests\n\n");
598 mpdm_sset(NULL
, MPDM_LS(L
"mp"), MPDM_H(7));
599 mpdm_sset(NULL
, MPDM_LS(L
"mp.config"), MPDM_H(7));
600 mpdm_sset(NULL
, MPDM_LS(L
"mp.config.auto_indent"), MPDM_I(16384));
601 mpdm_sset(NULL
, MPDM_LS(L
"mp.config.use_regex"), MPDM_I(1357));
602 mpdm_sset(NULL
, MPDM_LS(L
"mp.config.gtk_font_face"), MPDM_LS(L
"profontwindows"));
603 mpdm_sset(NULL
, MPDM_LS(L
"mp.lines"), MPDM_A(2));
604 mpdm_sset(NULL
, MPDM_LS(L
"mp.lines.0"), MPDM_LS(L
"First post!"));
605 mpdm_sset(NULL
, MPDM_LS(L
"mp.lines.1"), MPDM_LS(L
"Second post!"));
606 mpdm_sset(NULL
, MPDM_LS(L
"mp.active"), MPDM_X(active
));
607 mpdm_sset(NULL
, MPDM_LS(L
"mp.active.syntax"), NULL
);
608 mpdm_dump(mpdm_root());
610 v
= mpdm_sget(NULL
, MPDM_LS(L
"mp.config.auto_indent"));
613 do_test("auto_indent == 16384", (i
== 16384));
623 mpdm_t eol
= MPDM_LS(L
"\n");
625 f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"w"));
628 printf("Can't create test.txt; no further file tests possible.\n");
632 do_test("Create test.txt", f
!= NULL
);
634 mpdm_write(f
, MPDM_LS(L
"0"));
636 mpdm_write(f
, MPDM_LS(L
"1"));
639 /* write WITHOUT eol */
640 mpdm_write(f
, MPDM_LS(L
"2"));
644 f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"r"));
646 do_test("test written file 0", mpdm_cmp(mpdm_read(f
), MPDM_LS(L
"0\n")) == 0);
647 do_test("test written file 1", mpdm_cmp(mpdm_read(f
), MPDM_LS(L
"1\n")) == 0);
648 do_test("test written file 2", mpdm_cmp(mpdm_read(f
), MPDM_LS(L
"2")) == 0);
649 do_test("test written file 3", mpdm_read(f
) == NULL
);
653 mpdm_unlink(MPDM_LS(L
"test.txt"));
654 do_test("unlink", mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"r")) == NULL
);
656 v
= mpdm_stat(MPDM_LS(L
"stress.c"));
657 printf("Stat from stress.c:\n");
660 /* v=mpdm_glob(MPDM_LS(L"*"));*/
662 v
= mpdm_glob(NULL
, NULL
);
667 void test_regex(void)
672 v
= mpdm_regex(MPDM_LS(L
"/[0-9]+/"), MPDM_LS(L
"123456"), 0);
673 do_test("regex 0", v
!= NULL
);
675 v
= mpdm_regex(MPDM_LS(L
"/[0-9]+/"), MPDM_I(65536), 0);
676 do_test("regex 1", v
!= NULL
);
678 v
= mpdm_regex(MPDM_LS(L
"/^[0-9]+$/"), MPDM_LS(L
"12345678"), 0);
679 do_test("regex 2", v
!= NULL
);
681 v
= mpdm_regex(MPDM_LS(L
"/^[0-9]+$/"), MPDM_I(1), 0);
682 do_test("regex 3", v
!= NULL
);
684 v
= mpdm_regex(MPDM_LS(L
"/^[0-9]+$/"), MPDM_LS(L
"A12345-678"), 0);
685 do_test("regex 4", v
== NULL
);
687 w
= MPDM_LS(L
"Hell street, 666");
688 v
= mpdm_regex(MPDM_LS(L
"/[0-9]+/"), w
, 0);
689 do_test("regex 5", mpdm_cmp(v
, MPDM_I(666)) == 0);
693 v
= mpdm_regex(MPDM_LS(L
"/regex/"), MPDM_LS(L
"CASE-INSENSITIVE REGEX"), 0);
694 do_test("regex 6.1 (case sensitive)", v
== NULL
);
696 v
= mpdm_regex(MPDM_LS(L
"/regex/i"), MPDM_LS(L
"CASE-INSENSITIVE REGEX"), 0);
697 do_test("regex 6.2 (case insensitive)", v
!= NULL
);
699 v=mpdm_regex(MPDM_LS(L"/[A-Z]+/"), MPDM_LS(L"case SENSITIVE regex"), 0);
700 do_test("regex 6.3 (case sensitive)", mpdm_cmp(v, MPDM_LS(L"SENSITIVE")) == 0);
702 v
= mpdm_regex(MPDM_LS(L
"/^\\s*/"), MPDM_LS(L
"123456"), 0);
703 do_test("regex 7", v
!= NULL
);
705 v
= mpdm_regex(MPDM_LS(L
"/^\\s+/"), MPDM_LS(L
"123456"), 0);
706 do_test("regex 8", v
== NULL
);
708 v
= mpdm_regex(MPDM_LS(L
"/^\\s+/"), NULL
, 0);
709 do_test("regex 9 (NULL string to match)", v
== NULL
);
713 v
= mpdm_sregex(MPDM_LS(L
"/A/"), MPDM_LS(L
"change all A to A"), MPDM_LS(L
"E"), 0);
714 do_test("sregex 0", mpdm_cmp(v
, MPDM_LS(L
"change all E to A")) == 0);
716 v
= mpdm_sregex(MPDM_LS(L
"/A/g"), MPDM_LS(L
"change all A to A"), MPDM_LS(L
"E"), 0);
717 do_test("sregex 1", mpdm_cmp(v
, MPDM_LS(L
"change all E to E")) == 0);
719 v
= mpdm_sregex(MPDM_LS(L
"/A+/g"), MPDM_LS(L
"change all AAAAAA to E"),
721 do_test("sregex 2", mpdm_cmp(v
, MPDM_LS(L
"change all E to E")) == 0);
723 v
= mpdm_sregex(MPDM_LS(L
"/A+/g"), MPDM_LS(L
"change all A A A A A A to E"),
725 do_test("sregex 3", mpdm_cmp(v
, MPDM_LS(L
"change all E E E E E E to E")) == 0);
727 v
= mpdm_sregex(MPDM_LS(L
"/A+/g"), MPDM_LS(L
"change all AAA A AA AAAAA A AAA to E"),
729 do_test("sregex 3.2", mpdm_cmp(v
, MPDM_LS(L
"change all E E E E E E to E")) == 0);
731 v
= mpdm_sregex(MPDM_LS(L
"/[0-9]+/g"), MPDM_LS(L
"1, 20, 333, 40 all are numbers"),
732 MPDM_LS(L
"numbers"), 0);
735 MPDM_LS(L
"numbers, numbers, numbers, numbers all are numbers")) == 0);
737 v
= mpdm_sregex(MPDM_LS(L
"/[a-zA-Z_]+/g"), MPDM_LS(L
"regex, mpdm_regex, TexMex"),
739 do_test("sregex 5", mpdm_cmp(v
, MPDM_LS(L
"sex, sex, sex")) == 0);
741 v
= mpdm_sregex(MPDM_LS(L
"/[a-zA-Z]+/g"), MPDM_LS(L
"regex, mpdm_regex, TexMex"),
743 do_test("sregex 6", mpdm_cmp(v
, MPDM_LS(L
", _, ")) == 0);
745 v
= mpdm_sregex(MPDM_LS(L
"/\\\\/g"), MPDM_LS(L
"\\MSDOS\\style\\path"),
747 do_test("sregex 7", mpdm_cmp(v
, MPDM_LS(L
"/MSDOS/style/path")) == 0);
749 v
= mpdm_sregex(MPDM_LS(L
"/regex/gi"), MPDM_LS(L
"regex, Regex, REGEX"),
751 do_test("sregex 8", mpdm_cmp(v
, MPDM_LS(L
"sex, sex, sex")) == 0);
753 v
= mpdm_sregex(NULL
, NULL
, NULL
, 0);
754 do_test("Previous sregex substitutions must be 3", mpdm_ival(v
) == 3);
756 /* & in substitution tests */
757 v
= MPDM_LS(L
"this string has many words");
758 v
= mpdm_sregex(MPDM_LS(L
"/[a-z]+/g"), v
, MPDM_LS(L
"[&]"), 0);
759 do_test("& in sregex target",
760 mpdm_cmp(v
, MPDM_LS(L
"[this] [string] [has] [many] [words]")) == 0);
762 v
= MPDM_LS(L
"this string has many words");
763 v
= mpdm_sregex(MPDM_LS(L
"/[a-z]+/g"), v
, MPDM_LS(L
"[\\&]"), 0);
764 do_test("escaped & in sregex target",
765 mpdm_cmp(v
, MPDM_LS(L
"[&] [&] [&] [&] [&]")) == 0);
767 v
= MPDM_LS(L
"this string has many words");
768 v
= mpdm_sregex(MPDM_LS(L
"/[a-z]+/g"), v
, MPDM_LS(L
"\\\\&"), 0);
769 do_test("escaped \\ in sregex target",
770 mpdm_cmp(v
, MPDM_LS(L
"\\this \\string \\has \\many \\words")) == 0);
772 v
= MPDM_LS(L
"hola ");
773 v
= mpdm_sregex(MPDM_LS(L
"/[ \t]$/"), v
, MPDM_LS(L
""), 0);
774 do_test("sregex output size 1", v
->size
== 4);
776 v
= MPDM_LS(L
"hola ");
777 v
= mpdm_sregex(MPDM_LS(L
"/[ \t]$/"), v
, NULL
, 0);
778 do_test("sregex output size 2", v
->size
== 4);
780 v
= MPDM_LS(L
"hola ");
781 v
= mpdm_sregex(MPDM_LS(L
"/[ \t]$/"), v
, MPDM_LS(L
"!"), 0);
782 do_test("sregex output size 3", v
->size
== 5);
784 /* multiple regex tests */
787 mpdm_push(w
, MPDM_LS(L
"/^[ \t]*/"));
788 mpdm_push(w
, MPDM_LS(L
"/[^ \t=]+/"));
789 mpdm_push(w
, MPDM_LS(L
"/[ \t]*=[ \t]*/"));
790 mpdm_push(w
, MPDM_LS(L
"/[^ \t]+/"));
791 mpdm_push(w
, MPDM_LS(L
"/[ \t]*$/"));
793 v
= mpdm_regex(w
, MPDM_LS(L
"key=value"), 0);
794 do_test("multi-regex 1.1", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"key")) == 0);
795 do_test("multi-regex 1.2", mpdm_cmp(mpdm_aget(v
, 3), MPDM_LS(L
"value")) == 0);
797 v
= mpdm_regex(w
, MPDM_LS(L
" key = value"), 0);
798 do_test("multi-regex 2.1", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"key")) == 0);
799 do_test("multi-regex 2.2", mpdm_cmp(mpdm_aget(v
, 3), MPDM_LS(L
"value")) == 0);
801 v
= mpdm_regex(w
, MPDM_LS(L
"\t\tkey\t=\tvalue "), 0);
802 do_test("multi-regex 3.1", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"key")) == 0);
803 do_test("multi-regex 3.2", mpdm_cmp(mpdm_aget(v
, 3), MPDM_LS(L
"value")) == 0);
805 /* v = mpdm_regex(w, MPDM_LS(L"key= "), 0);
806 do_test("multi-regex 4", v == NULL);
808 printf("Multiple line regexes\n");
809 w
= MPDM_LS(L
"/* this is\na C-like comment */");
810 v
= mpdm_regex(MPDM_LS(L
"|/\\*.+\\*/|"), w
, 0);
811 do_test("Multiline regex 1", mpdm_cmp(v
, w
) == 0);
813 v
= mpdm_regex(MPDM_LS(L
"/is$/"), w
, 0);
814 do_test("Multiline regex 2", v
== NULL
);
816 v
= mpdm_regex(MPDM_LS(L
"/is$/m"), w
, 0);
817 do_test("Multiline regex 3", mpdm_cmp(v
, MPDM_LS(L
"is")) == 0);
819 printf("Pitfalls on multibyte locales (f.e. utf-8)\n");
821 w
= MPDM_LS(L
"-\x03a9-");
823 v
= mpdm_regex(MPDM_LS(L
"/-$/"), w
, 0);
824 do_test("Multibyte environment regex 1", mpdm_cmp(v
, MPDM_LS(L
"-")) == 0);
826 if (do_multibyte_sregex_tests
) {
827 v
= mpdm_sregex(MPDM_LS(L
"/-$/"), w
, MPDM_LS(L
"~"), 0);
828 do_test("Multibyte environment sregex 1",
829 mpdm_cmp(v
, MPDM_LS(L
"-\x03a9~")) == 0);
831 v
= mpdm_sregex(MPDM_LS(L
"/-/g"), w
, MPDM_LS(L
"~"), 0);
832 do_test("Multibyte environment sregex 2",
833 mpdm_cmp(v
, MPDM_LS(L
"~\x03a9~")) == 0);
836 printf("Multibyte sregex test omitted; activate with -m\n");
838 /* 'last' flag tests */
839 v
= MPDM_LS(L
"this string has many words");
840 v
= mpdm_regex(MPDM_LS(L
"/[a-z]+/l"), v
, 0);
841 do_test("Flag l in mpdm_regex", mpdm_cmp(v
, MPDM_LS(L
"words")) == 0);
845 static mpdm_t
dumper(mpdm_t args
)
846 /* executable value */
853 static mpdm_t
sum(mpdm_t args
)
854 /* executable value: sum all args */
859 for (n
= t
= 0; n
< args
->size
; n
++)
860 t
+= mpdm_ival(mpdm_aget(args
, n
));
867 static mpdm_t
calculator(mpdm_t c
, mpdm_t args
)
868 /* 2 argument version: calculator. c contains a 'script' to
869 do things with the arguments */
876 /* to avoid destroying args */
877 a
= mpdm_clone(args
);
879 /* shift first argument */
883 for (n
= 0; n
< mpdm_size(c
); n
++) {
887 /* gets next value */
890 switch (*(wchar_t *) o
->data
) {
916 printf("test_exec\n");
926 mpdm_aset(w
, MPDM_I(100), 0);
927 mpdm_aset(w
, MPDM_I(220), 1);
928 mpdm_aset(w
, MPDM_I(333), 2);
930 do_test("exec 0", mpdm_ival(mpdm_exec(x
, w
)) == 653);
932 mpdm_push(w
, MPDM_I(1));
934 /* multiple executable value: vm and compiler support */
936 /* calculator 'script' */
938 mpdm_push(p
, MPDM_LS(L
"+"));
939 mpdm_push(p
, MPDM_LS(L
"-"));
940 mpdm_push(p
, MPDM_LS(L
"+"));
944 x
->flags
|= MPDM_EXEC
;
946 mpdm_aset(x
, MPDM_X(calculator
), 0);
949 do_test("exec 1", mpdm_ival(mpdm_exec(x
, w
)) == -12);
951 /* another 'script', different operations with the same values */
953 mpdm_push(p
, MPDM_LS(L
"*"));
954 mpdm_push(p
, MPDM_LS(L
"/"));
955 mpdm_push(p
, MPDM_LS(L
"+"));
959 do_test("exec 2", mpdm_ival(mpdm_exec(x
, w
)) == 67);
963 void test_encoding(void)
970 v
= MPDM_MBS("?Espa?a!\n");
972 printf("\nLocale encoding tests (will look bad if terminal is not ISO-8859-1)\n\n");
974 if ((f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"w"))) == NULL
) {
975 printf("Can't write test.txt; no further file test possible.\n");
982 f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"r"));
985 do_test("Locale encoding", mpdm_cmp(w
, v
) == 0);
989 ("\nutf8.txt loading (should look good only in UTF-8 terminals with good fonts)\n");
991 f
= mpdm_open(MPDM_LS(L
"utf8.txt"), MPDM_LS(L
"r"));
996 for (ptr
= w
->data
; *ptr
!= L
'\0'; ptr
++)
997 printf("%d", mpdm_wcwidth(*ptr
));
1000 if (mpdm_encoding(MPDM_LS(L
"UTF-8")) < 0) {
1001 printf("No multiple encoding (iconv) support; no more tests possible.\n");
1006 ("\nForced utf8.txt loading (should look good only in UTF-8 terminals with good fonts)\n");
1008 f
= mpdm_open(MPDM_LS(L
"utf8.txt"), MPDM_LS(L
"r"));
1013 /* new open file will use the specified encoding */
1014 f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"w"));
1018 f
= mpdm_open(MPDM_LS(L
"test.txt"), MPDM_LS(L
"r"));
1021 do_test("iconv encoding", mpdm_cmp(w
, v
) == 0);
1024 mpdm_encoding(NULL
);
1028 void test_gettext(void)
1033 printf("\nTesting gettext...\n");
1035 mpdm_gettext_domain(MPDM_LS(L
"stress"), MPDM_LS(L
"./po"));
1037 printf("Should follow a translated string of 'This is a test string':\n");
1038 v
= mpdm_gettext(MPDM_LS(L
"This is a test string"));
1041 printf("The same, but cached:\n");
1042 v
= mpdm_gettext(MPDM_LS(L
"This is a test string"));
1045 v
= mpdm_gettext(MPDM_LS(L
"This string is not translated"));
1048 printf("Ad-hoc translation hash:\n");
1050 mpdm_hset(h
, MPDM_LS(L
"test string"), MPDM_LS(L
"cadena de prueba"));
1052 mpdm_gettext_domain(MPDM_LS(L
"stress"), h
);
1053 v
= mpdm_gettext(MPDM_LS(L
"test string"));
1058 void timer(int secs
)
1060 static clock_t clks
= 0;
1068 printf("%.2f seconds\n", (float) (clock() - clks
) / (float) CLOCKS_PER_SEC
);
1074 void bench_hash(int i
, mpdm_t l
, int buckets
)
1080 printf("Hash of %d buckets: \n", buckets
);
1081 h
= MPDM_H(buckets
);
1084 for (n
= 0; n
< i
; n
++) {
1085 v
= mpdm_aget(l
, n
);
1090 printf("Bucket usage:\n");
1091 for(n=0;n < mpdm_size(h);n++)
1092 printf("\t%d: %d\n", n, mpdm_size(mpdm_aget(h, n)));
1098 void benchmark(void)
1106 if (!do_benchmarks
) {
1107 printf("Skipping benchmarks\nRun them with 'stress -b'\n");
1111 printf("BENCHMARKS\n");
1115 printf("Creating %d values...\n", i
);
1117 l
= mpdm_ref(MPDM_A(i
));
1118 for (n
= 0; n
< i
; n
++) {
1119 sprintf(tmp
, "%08x", n
);
1120 /* mpdm_aset(l, MPDM_MBS(tmp), n);*/
1121 mpdm_aset(l
, MPDM_I(n
), n
);
1126 bench_hash(i
, l
, 0);
1127 bench_hash(i
, l
, 61);
1128 bench_hash(i
, l
, 89);
1129 bench_hash(i
, l
, 127);
1135 void test_conversion(void)
1137 wchar_t *wptr
= NULL
;
1141 ptr
= mpdm_wcstombs(L
"", &size
);
1142 do_test("mpdm_wcstombs converts an empty string", ptr
!= NULL
);
1144 wptr
= mpdm_mbstowcs("", &size
, 0);
1145 do_test("mpdm_mbstowcs converts an empty string", wptr
!= NULL
);
1149 void test_pipes(void)
1155 if ((f
= mpdm_popen(MPDM_LS(L
"date"), MPDM_LS(L
"r"))) != NULL
) {
1161 printf("Pipe from 'date':\n");
1165 printf("Can't pipe to 'date'\n");
1169 void test_misc(void)
1171 printf("Home dir:\n");
1172 mpdm_dump(mpdm_home_dir());
1173 printf("App dir:\n");
1174 mpdm_dump(mpdm_app_dir());
1178 void test_sprintf(void)
1183 printf("sprintf tests\n");
1186 mpdm_push(v
, MPDM_I(100));
1187 mpdm_push(v
, MPDM_LS(L
"beers"));
1189 w
= mpdm_sprintf(MPDM_LS(L
"%d %s for me"), v
);
1190 do_test("sprintf 1", mpdm_cmp(w
, MPDM_LS(L
"100 beers for me")) == 0);
1192 w
= mpdm_sprintf(MPDM_LS(L
"%d %s for me %d"), v
);
1193 do_test("sprintf 2", mpdm_cmp(w
, MPDM_LS(L
"100 beers for me 0")) == 0);
1195 w
= mpdm_sprintf(MPDM_LS(L
"%10d %s for me"), v
);
1196 do_test("sprintf 3", mpdm_cmp(w
, MPDM_LS(L
" 100 beers for me")) == 0);
1198 w
= mpdm_sprintf(MPDM_LS(L
"%010d %s for me"), v
);
1199 do_test("sprintf 4", mpdm_cmp(w
, MPDM_LS(L
"0000000100 beers for me")) == 0);
1202 mpdm_push(v
, MPDM_R(3.1416));
1204 w
= mpdm_sprintf(MPDM_LS(L
"Value for PI is %6.4f"), v
);
1205 do_test("sprintf 2.1", mpdm_cmp(w
, MPDM_LS(L
"Value for PI is 3.1416")) == 0);
1207 w
= mpdm_sprintf(MPDM_LS(L
"Value for PI is %08.2f"), v
);
1208 do_test("sprintf 2.1", mpdm_cmp(w
, MPDM_LS(L
"Value for PI is 00003.14")) == 0);
1211 mpdm_push(v
, MPDM_LS(L
"stress"));
1213 w
= mpdm_sprintf(MPDM_LS(L
"This is a |%10s| test"), v
);
1214 do_test("sprintf 3.1", mpdm_cmp(w
, MPDM_LS(L
"This is a | stress| test")) == 0);
1216 w
= mpdm_sprintf(MPDM_LS(L
"This is a |%-10s| test"), v
);
1217 do_test("sprintf 3.2", mpdm_cmp(w
, MPDM_LS(L
"This is a |stress | test")) == 0);
1220 mpdm_push(v
, MPDM_I(0x263a));
1222 w
= mpdm_sprintf(MPDM_LS(L
"%c"), v
);
1223 do_test("sprintf 3.3", mpdm_cmp(w
, MPDM_LS(L
"\x263a")) == 0);
1226 mpdm_push(v
, MPDM_I(75));
1228 w
= mpdm_sprintf(MPDM_LS(L
"%d%%"), v
);
1229 do_test("sprintf 4.1", mpdm_cmp(w
, MPDM_LS(L
"75%")) == 0);
1231 w
= mpdm_sprintf(MPDM_LS(L
"%b"), v
);
1232 do_test("sprintf 5.1", mpdm_cmp(w
, MPDM_LS(L
"1001011")) == 0);
1238 mpdm_t v
= MPDM_S(L
"string");
1239 mpdm_t w
= mpdm_ulc(v
, 1);
1241 do_test("mpdm_ulc 1", mpdm_cmp(mpdm_ulc(v
, 1), w
) == 0);
1242 do_test("mpdm_ulc 2", mpdm_cmp(mpdm_ulc(w
, 0), v
) == 0);
1246 void test_scanf(void)
1250 v
= mpdm_sscanf(MPDM_LS(L
"%d %d"), MPDM_LS(L
"1234 5678"), 0);
1251 do_test("mpdm_sscanf_1.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"1234")) == 0);
1252 do_test("mpdm_sscanf_1.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"5678")) == 0);
1254 v
= mpdm_sscanf(MPDM_LS(L
"%s %f %d"), MPDM_LS(L
"this 12.34 5678"), 0);
1255 do_test("mpdm_sscanf_2.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"this")) == 0);
1256 do_test("mpdm_sscanf_2.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"12.34")) == 0);
1257 do_test("mpdm_sscanf_2.3", mpdm_cmp(mpdm_aget(v
, 2), MPDM_LS(L
"5678")) == 0);
1259 v
= mpdm_sscanf(MPDM_LS(L
"%s %*f %d"), MPDM_LS(L
"this 12.34 5678"), 0);
1260 do_test("mpdm_sscanf_3.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"this")) == 0);
1261 do_test("mpdm_sscanf_3.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"5678")) == 0);
1263 v
= mpdm_sscanf(MPDM_LS(L
"%4d%4d%2d%10d"), MPDM_LS(L
"12341234121234567890"), 0);
1264 do_test("mpdm_sscanf_4.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"1234")) == 0);
1265 do_test("mpdm_sscanf_4.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"1234")) == 0);
1266 do_test("mpdm_sscanf_4.3", mpdm_cmp(mpdm_aget(v
, 2), MPDM_LS(L
"12")) == 0);
1267 do_test("mpdm_sscanf_4.4", mpdm_cmp(mpdm_aget(v
, 3), MPDM_LS(L
"1234567890")) == 0);
1269 v
= mpdm_sscanf(MPDM_LS(L
"%[abc]%s"), MPDM_LS(L
"ccbaabcxaaae and more"), 0);
1270 do_test("mpdm_sscanf_5.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"ccbaabc")) == 0);
1271 do_test("mpdm_sscanf_5.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"xaaae")) == 0);
1273 v
= mpdm_sscanf(MPDM_LS(L
"%[a-d]%s"), MPDM_LS(L
"ccbaabcxaaae and more"), 0);
1274 do_test("mpdm_sscanf_6.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"ccbaabc")) == 0);
1275 do_test("mpdm_sscanf_6.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"xaaae")) == 0);
1277 v
= mpdm_sscanf(MPDM_LS(L
"%[^x]%s"), MPDM_LS(L
"ccbaabcxaaae and more"), 0);
1278 do_test("mpdm_sscanf_7.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"ccbaabc")) == 0);
1279 do_test("mpdm_sscanf_7.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"xaaae")) == 0);
1281 v
= mpdm_sscanf(MPDM_LS(L
"%[^:]: %s"), MPDM_LS(L
"key: value"), 0);
1282 do_test("mpdm_sscanf_8.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"key")) == 0);
1283 do_test("mpdm_sscanf_8.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"value")) == 0);
1285 v
= mpdm_sscanf(MPDM_LS(L
"%*[^/]/* %s */"), MPDM_LS(L
"this is code /* comment */ more code"), 0);
1286 do_test("mpdm_sscanf_9.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"comment")) == 0);
1288 v
= mpdm_sscanf(MPDM_LS(L
"%d%%%d"), MPDM_LS(L
"1234%5678"), 0);
1289 do_test("mpdm_sscanf_10.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"1234")) == 0);
1290 do_test("mpdm_sscanf_10.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"5678")) == 0);
1292 v
= mpdm_sscanf(MPDM_LS(L
"%*[abc]%n%*[^ ]%n"), MPDM_LS(L
"ccbaabcxaaae and more"), 0);
1293 do_test("mpdm_sscanf_11.1", mpdm_ival(mpdm_aget(v
, 0)) == 7);
1294 do_test("mpdm_sscanf_11.2", mpdm_ival(mpdm_aget(v
, 1)) == 12);
1296 v
= mpdm_sscanf(MPDM_LS(L
"/* %S */"), MPDM_LS(L
"/* inside the comment */"), 0);
1297 do_test("mpdm_sscanf_12.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"inside the comment")) == 0);
1299 v
= mpdm_sscanf(MPDM_LS(L
"/* %S */%s"), MPDM_LS(L
"/* inside the comment */outside"), 0);
1300 do_test("mpdm_sscanf_13.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"inside the comment")) == 0);
1301 do_test("mpdm_sscanf_13.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"outside")) == 0);
1303 v
= mpdm_sscanf(MPDM_LS(L
"%n"), MPDM_LS(L
""), 0);
1304 do_test("mpdm_sscanf_14.1", mpdm_size(v
) == 1 && mpdm_ival(mpdm_aget(v
, 0)) == 0);
1306 v
= mpdm_sscanf(MPDM_LS(L
"%[^%f]%f %[#%d@]"), MPDM_LS(L
"this 12.34 5678#12@34"), 0);
1307 do_test("mpdm_sscanf_15.1", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"this ")) == 0);
1308 do_test("mpdm_sscanf_15.2", mpdm_cmp(mpdm_aget(v
, 1), MPDM_LS(L
"12.34")) == 0);
1309 do_test("mpdm_sscanf_15.3", mpdm_cmp(mpdm_aget(v
, 2), MPDM_LS(L
"5678#12@34")) == 0);
1311 v
= mpdm_sscanf(MPDM_LS(L
"%*S\"%[^\n\"]\""), MPDM_LS(L
"a \"bbb\" c;"), 0);
1312 do_test("mpdm_sscanf_16", mpdm_cmp(mpdm_aget(v
, 0), MPDM_LS(L
"bbb")) == 0);
1316 void (*func
)(void) = NULL
;
1318 int main(int argc
, char *argv
[])
1321 if (strcmp(argv
[1], "-b") == 0)
1323 if (strcmp(argv
[1], "-m") == 0)
1324 do_multibyte_sregex_tests
= 1;
1329 printf("sizeof(struct mpdm_val): %ld\n", (long) sizeof(struct mpdm_val
));
1330 printf("sizeof(void *): %d\n", sizeof(void *));
1331 printf("sizeof(void (*func)(void)): %d\n", sizeof(func
));
1356 /* mpdm_dump_unref();*/
1358 printf("memory: %d\n", mpdm
->memory_usage
);
1368 printf("memory: %d\n", mpdm
->memory_usage
);
1370 /* mpdm_dump_unref();*/
1374 printf("\n*** Total tests passed: %d/%d\n", oks
, tests
);
1377 printf("*** ALL TESTS PASSED\n");
1381 printf("*** %d %s\n", tests
- oks
, "TESTS ---FAILED---");
1383 printf("\nFailed tests:\n\n");
1384 for (n
= 0; n
< i_failed_msgs
; n
++)
1385 printf("%s", failed_msgs
[n
]);