Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libbstring / test.cpp
blob01228f52c93eb0b18aa9ecc59d87caa78dc25b3e
1 //
2 // This source file is part of the bstring string library. This code was
3 // written by Paul Hsieh in 2002-2006, and is covered by the BSD open source
4 // license. Refer to the accompanying documentation for details on usage and
5 // license.
6 //
8 //
9 // test.cpp
11 // This file is the C++ unit test for Bstrlib
14 #include <stdio.h>
15 #include <stdarg.h>
16 #include "bstrlib.h"
17 #include "bstrwrap.h"
19 // Exceptions must be turned on in the compiler to successfully run
20 // this test. The compiler must also support STL.
22 #define dumpOutQty (32)
23 static bstring dumpOut[dumpOutQty];
24 static unsigned int rot = 0;
26 char * dumpBstring (const bstring b) {
27 rot = (rot + 1) % (unsigned) dumpOutQty;
28 if (dumpOut[rot] == NULL) {
29 dumpOut[rot] = bfromcstr ("");
30 if (dumpOut[rot] == NULL) return "FATAL INTERNAL ERROR";
32 dumpOut[rot]->slen = 0;
33 if (b == NULL) {
34 bcatcstr (dumpOut[rot], "NULL");
35 } else {
36 char msg[32];
37 sprintf (msg, "%p", (void *)b);
38 bcatcstr (dumpOut[rot], msg);
40 if (b->slen < 0) {
41 sprintf (msg, ":[err:slen=%d<0]", b->slen);
42 bcatcstr (dumpOut[rot], msg);
43 } else {
44 if (b->mlen > 0 && b->mlen < b->slen) {
45 sprintf (msg, ":[err:mlen=%d<slen=%d]", b->mlen, b->slen);
46 bcatcstr (dumpOut[rot], msg);
47 } else {
48 if (b->mlen == -1) {
49 bcatcstr (dumpOut[rot], "[p]");
50 } else if (b->mlen < 0) {
51 bcatcstr (dumpOut[rot], "[c]");
53 bcatcstr (dumpOut[rot], ":");
54 if (b->data == NULL) {
55 bcatcstr (dumpOut[rot], "[err:data=NULL]");
56 } else {
57 bcatcstr (dumpOut[rot], "\"");
58 bcatcstr (dumpOut[rot], (const char *) b->data);
59 bcatcstr (dumpOut[rot], "\"");
64 return (char *) dumpOut[rot]->data;
67 int test0 (void) {
68 int ret = 0;
70 printf ("TEST: CBString constructor\n");
72 try {
73 printf ("\tCBString c;\n");
74 CBString c0;
75 ret += (0 != c0.length());
76 ret += '\0' != ((const char *)c0)[c0.length()];
78 printf ("\tCBString c(\"test\");\n");
79 CBString c1 ("test");
80 ret += (c1 != "test");
81 ret += '\0' != ((const char *)c1)[c1.length()];
83 printf ("\tCBString c(25, \"test\");\n");
84 CBString c8 (25, "test");
85 ret += (c8 != "test");
86 ret += c8.mlen < 25;
87 ret += '\0' != ((const char *)c8)[c8.length()];
89 printf ("\tCBString c('t');\n");
90 CBString c2 ('t');
91 ret += (c2 != "t");
92 ret += '\0' != ((const char *)c2)[c2.length()];
94 printf ("\tCBString c('\\0');\n");
95 CBString c3 ('\0');
96 ret += (1 != c3.length()) || ('\0' != c3[0]);
97 ret += '\0' != ((const char *)c3)[c3.length()];
99 printf ("\tCBString c(bstr[\"test\"]);\n");
100 struct tagbstring t = bsStatic ("test");
101 CBString c4 (t);
102 ret += (c4 != t.data);
103 ret += '\0' != ((const char *)c4)[c4.length()];
105 printf ("\tCBString c(CBstr[\"test\"]);\n");
106 CBString c5 (c1);
107 ret += (c1 != c5);
108 ret += '\0' != ((const char *)c5)[c5.length()];
110 printf ("\tCBString c('x',5);\n");
111 CBString c6 ('x',5);
112 ret += (c6 != "xxxxx");
113 ret += '\0' != ((const char *)c6)[c6.length()];
115 printf ("\tCBString c(\"123456\",4);\n");
116 CBString c7 ((void *)"123456",4);
117 ret += (c7 != "1234");
118 ret += '\0' != ((const char *)c7)[c7.length()];
121 catch (struct CBStringException err) {
122 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
123 ret ++;
126 printf ("\t# failures: %d\n", ret);
127 return ret;
130 #define EXCEPTION_EXPECTED(line) \
131 try { \
132 line; \
133 ret++; \
134 printf ("\tException was expected\n"); \
136 catch (struct CBStringException) { }
138 int test1 (void) {
139 int ret = 0;
141 printf ("TEST: CBString = operator\n");
143 try {
144 CBString c0;
145 struct tagbstring t = bsStatic ("test");
147 ret += c0.iswriteprotected();
148 c0.writeprotect ();
149 ret += 1 != c0.iswriteprotected();
150 EXCEPTION_EXPECTED (c0 = 'x');
151 EXCEPTION_EXPECTED (c0 = (unsigned char) 'x');
152 EXCEPTION_EXPECTED (c0 = "test");
153 EXCEPTION_EXPECTED (c0 = CBString ("test"));
154 EXCEPTION_EXPECTED (c0 = t);
156 catch (struct CBStringException err) {
157 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
158 ret ++;
161 try {
162 CBString c0, c1;
163 struct tagbstring t = bsStatic ("test");
165 printf ("\tc = 'x';\n");
166 c0 = 'x';
167 ret += (c0 != "x");
168 ret += '\0' != ((const char *)c0)[c0.length()];
169 printf ("\tc = (unsigned char)'x';\n");
170 c0 = (unsigned char) 'x';
171 ret += (c0 != "x");
172 ret += '\0' != ((const char *)c0)[c0.length()];
173 printf ("\tc = \"test\";\n");
174 c0 = "test";
175 ret += (c0 != "test");
176 ret += '\0' != ((const char *)c0)[c0.length()];
177 printf ("\tc = CBStr[\"test\"];\n");
178 c1 = c0;
179 ret += (c0 != c1);
180 ret += '\0' != ((const char *)c1)[c1.length()];
181 printf ("\tc = tbstr[\"test\"];\n");
182 c0 = t;
183 ret += (c0 != "test");
184 ret += '\0' != ((const char *)c0)[c0.length()];
187 catch (struct CBStringException err) {
188 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
189 ret ++;
192 printf ("\t# failures: %d\n", ret);
193 return ret;
196 int test2 (void) {
197 int ret = 0;
199 printf ("TEST: CBString += operator\n");
201 try {
202 CBString c0;
203 struct tagbstring t = bsStatic ("test");
205 c0.writeprotect ();
206 EXCEPTION_EXPECTED (c0 += 'x');
207 EXCEPTION_EXPECTED (c0 += (unsigned char) 'x');
208 EXCEPTION_EXPECTED (c0 += "test");
209 EXCEPTION_EXPECTED (c0 += CBString ("test"));
210 EXCEPTION_EXPECTED (c0 += t);
212 catch (struct CBStringException err) {
213 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
214 ret ++;
217 try {
218 CBString c0;
219 struct tagbstring t = bsStatic ("extra");
221 c0 = "test";
222 printf ("\tc += 'x';\n");
223 c0 += 'x';
224 ret += (c0 != "testx");
225 ret += '\0' != ((const char *)c0)[c0.length()];
226 printf ("\tc += (unsigned char)'x';\n");
227 c0 += (unsigned char) 'y';
228 ret += (c0 != "testxy");
229 ret += '\0' != ((const char *)c0)[c0.length()];
230 printf ("\tc += \"test\";\n");
231 c0 += "test";
232 ret += (c0 != "testxytest");
233 ret += '\0' != ((const char *)c0)[c0.length()];
234 printf ("\tc += CBStr[\"test\"];\n");
235 c0 += CBString (c0);
236 ret += (c0 != "testxytesttestxytest");
237 ret += '\0' != ((const char *)c0)[c0.length()];
238 printf ("\tc += tbstr[\"test\"];\n");
239 c0 += t;
240 ret += (c0 != "testxytesttestxytestextra");
241 ret += '\0' != ((const char *)c0)[c0.length()];
244 catch (struct CBStringException err) {
245 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
246 ret ++;
249 printf ("\t# failures: %d\n", ret);
250 return ret;
253 int test3 (void) {
254 int ret = 0;
256 try {
257 CBString c0, c1;
258 struct tagbstring t = bsStatic ("extra");
260 printf ("TEST: CBString + operator\n");
262 c1 = "test";
263 printf ("\tc + 'x';\n");
264 c0 = c1 + 'x';
265 ret += (c0 != "testx");
266 ret += '\0' != ((const char *)c0)[c0.length()];
267 printf ("\tc + (unsigned char)'x';\n");
268 c0 = c1 + (unsigned char) 'y';
269 ret += (c0 != "testy");
270 ret += '\0' != ((const char *)c0)[c0.length()];
271 printf ("\tc + \"test\";\n");
272 c0 = c1 + (const char *) "stuff";
273 ret += (c0 != "teststuff");
274 ret += '\0' != ((const char *)c0)[c0.length()];
275 printf ("\tc + (unsigned char *) \"test\";\n");
276 c0 = c1 + (const unsigned char *) "stuff";
277 ret += (c0 != "teststuff");
278 ret += '\0' != ((const char *)c0)[c0.length()];
279 printf ("\tc + CBStr[\"test\"];\n");
280 c0 = c1 + CBString ("other");
281 ret += (c0 != "testother");
282 ret += '\0' != ((const char *)c0)[c0.length()];
283 printf ("\tc + tbstr[\"test\"];\n");
284 c0 = c1 + t;
285 ret += (c0 != "testextra");
286 ret += '\0' != ((const char *)c0)[c0.length()];
288 printf ("TEST: + CBString operator\n");
290 printf ("\t'x' + c;\n");
291 c0 = 'x' + c1;
292 ret += (c0 != "xtest");
293 ret += '\0' != ((const char *)c0)[c0.length()];
294 printf ("\t(unsigned char)'y' + c;\n");
295 c0 = (unsigned char) 'y' + c1;
296 ret += (c0 != "ytest");
297 ret += '\0' != ((const char *)c0)[c0.length()];
298 printf ("\t\"test\" + c;\n");
299 c0 = (const char *) "stuff" + c1;
300 ret += (c0 != "stufftest");
301 ret += '\0' != ((const char *)c0)[c0.length()];
302 printf ("\t(unsigned char *) \"test\" + c;\n");
303 c0 = (const unsigned char *) "stuff" + c1;
304 ret += (c0 != "stufftest");
305 ret += '\0' != ((const char *)c0)[c0.length()];
306 printf ("\ttbstr[\"extra\"] + c;\n");
307 c0 = t + c1;
308 ret += (c0 != "extratest");
309 ret += '\0' != ((const char *)c0)[c0.length()];
312 catch (struct CBStringException err) {
313 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
314 ret ++;
317 printf ("\t# failures: %d\n", ret);
318 return ret;
321 int test4 (void) {
322 int ret = 0;
324 try {
325 printf ("TEST: CBString == operator\n");
327 CBString c0, c1, c2;
329 c0 = c1 = "test";
330 c2 = "other";
332 printf ("\tc == d;\n");
333 ret += !(c0 == c1);
334 ret += (c0 == c2);
336 printf ("\tc == \"test\";\n");
337 ret += !(c0 == "test");
338 ret += (c2 == "test");
340 printf ("\tc == (unsigned char *) \"test\";\n");
341 ret += !(c0 == (unsigned char *) "test");
342 ret += (c2 == (unsigned char *) "test");
345 catch (struct CBStringException err) {
346 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
347 ret ++;
350 printf ("\t# failures: %d\n", ret);
351 return ret;
354 int test5 (void) {
355 int ret = 0;
357 try {
358 printf ("TEST: CBString != operator\n");
360 CBString c0, c1, c2;
362 c0 = c1 = "test";
363 c2 = "other";
365 printf ("\tc != d;\n");
366 ret += (c0 != c1);
367 ret += !(c0 != c2);
369 printf ("\tc != \"test\";\n");
370 ret += (c0 != "test");
371 ret += !(c2 != "test");
373 printf ("\tc != (unsigned char *) \"test\";\n");
374 ret += (c0 != (unsigned char *) "test");
375 ret += !(c2 != (unsigned char *) "test");
378 catch (struct CBStringException err) {
379 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
380 ret ++;
383 printf ("\t# failures: %d\n", ret);
384 return ret;
387 int test6 (void) {
388 int ret = 0;
390 try {
391 printf ("TEST: CBString <, <= operators\n");
393 CBString c0, c1, c2;
395 c0 = c1 = "test";
396 c2 = "other";
398 printf ("\tc < d;\n");
399 ret += (c0 < c1);
400 ret += (c0 < c2);
401 ret += (c1 < c0);
402 ret += !(c2 < c0);
404 printf ("\tc <= d;\n");
405 ret += !(c0 <= c1);
406 ret += (c0 <= c2);
407 ret += !(c1 <= c0);
408 ret += !(c2 <= c0);
410 printf ("\tc < \"test\";\n");
411 ret += (c0 < "test");
412 ret += (c1 < "test");
413 ret += !(c2 < "test");
414 ret += (c0 < "other");
415 ret += (c1 < "other");
416 ret += (c2 < "other");
418 printf ("\tc <= \"test\";\n");
419 ret += !(c0 <= "test");
420 ret += !(c1 <= "test");
421 ret += !(c2 <= "test");
422 ret += (c0 <= "other");
423 ret += (c1 <= "other");
424 ret += !(c2 <= "other");
426 printf ("\tc < (unsigned char *) \"test\";\n");
427 ret += (c0 < (const char *) "test");
428 ret += (c1 < (const char *) "test");
429 ret += !(c2 < (const char *) "test");
430 ret += (c0 < (const char *) "other");
431 ret += (c1 < (const char *) "other");
432 ret += (c2 < (const char *) "other");
434 printf ("\tc <= (unsigned char *) \"test\";\n");
435 ret += !(c0 <= (const char *) "test");
436 ret += !(c1 <= (const char *) "test");
437 ret += !(c2 <= (const char *) "test");
438 ret += (c0 <= (const char *) "other");
439 ret += (c1 <= (const char *) "other");
440 ret += !(c2 <= (const char *) "other");
443 catch (struct CBStringException err) {
444 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
445 ret ++;
448 printf ("\t# failures: %d\n", ret);
449 return ret;
452 int test7 (void) {
453 int ret = 0;
455 try {
456 printf ("TEST: CBString >, >= operators\n");
458 CBString c0, c1, c2;
460 c0 = c1 = "test";
461 c2 = "other";
463 printf ("\tc >= d;\n");
464 ret += !(c0 >= c1);
465 ret += !(c0 >= c2);
466 ret += !(c1 >= c0);
467 ret += (c2 >= c0);
469 printf ("\tc > d;\n");
470 ret += (c0 > c1);
471 ret += !(c0 > c2);
472 ret += (c1 > c0);
473 ret += (c2 > c0);
475 printf ("\tc >= \"test\";\n");
476 ret += !(c0 >= "test");
477 ret += !(c1 >= "test");
478 ret += (c2 >= "test");
479 ret += !(c0 >= "other");
480 ret += !(c1 >= "other");
481 ret += !(c2 >= "other");
483 printf ("\tc > \"test\";\n");
484 ret += (c0 > "test");
485 ret += (c1 > "test");
486 ret += (c2 > "test");
487 ret += !(c0 > "other");
488 ret += !(c1 > "other");
489 ret += (c2 > "other");
491 printf ("\tc >= (unsigned char *) \"test\";\n");
492 ret += !(c0 >= (const char *) "test");
493 ret += !(c1 >= (const char *) "test");
494 ret += (c2 >= (const char *) "test");
495 ret += !(c0 >= (const char *) "other");
496 ret += !(c1 >= (const char *) "other");
497 ret += !(c2 >= (const char *) "other");
499 printf ("\tc > (unsigned char *) \"test\";\n");
500 ret += (c0 > (const char *) "test");
501 ret += (c1 > (const char *) "test");
502 ret += (c2 > (const char *) "test");
503 ret += !(c0 > (const char *) "other");
504 ret += !(c1 > (const char *) "other");
505 ret += (c2 > (const char *) "other");
508 catch (struct CBStringException err) {
509 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
510 ret ++;
513 printf ("\t# failures: %d\n", ret);
514 return ret;
517 int test8 (void) {
518 int ret = 0;
520 try {
521 printf ("TEST: (const char *) CBString operator\n");
523 CBString c0 ("test"), c1 ("other");
525 printf ("\t(const char *) CBString\n");
526 ret += 0 != memcmp ((const char *) c0, "test", 5);
527 ret += 0 != memcmp ((const char *) c1, "other", 6);
529 printf ("\t(const unsigned char *) CBString\n");
530 ret += 0 != memcmp ((const unsigned char *) c0, "test", 5);
531 ret += 0 != memcmp ((const unsigned char *) c1, "other", 6);
534 catch (struct CBStringException err) {
535 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
536 ret ++;
539 printf ("\t# failures: %d\n", ret);
540 return ret;
543 int test9 (void) {
544 int ret = 0;
546 try {
547 printf ("TEST: (double), (float), (int) CBString operators\n");
548 CBString c0 ("1.2e3"), c1("100"), c2("100.55");
549 printf ("\t(double) \"%s\"\n", (const char *) c0);
550 ret += 1.2e3 != (double) c0;
551 printf ("\t(float) \"%s\"\n", (const char *) c0);
552 ret += 1.2e3 != (float) c0;
553 printf ("\t(int) \"%s\"\n", (const char *) c1);
554 ret += 100 != (float) c1;
555 printf ("\t(int) \"%s\"\n", (const char *) c2);
556 ret += 100 != (int) c2;
557 printf ("\t(unsigned int) \"%s\"\n", (const char *) c2);
558 ret += 100 != (unsigned int) c2;
560 catch (struct CBStringException err) {
561 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
562 ret ++;
565 try {
566 CBString c0 ("xxxxx");
567 printf ("\t(double) \"%s\"\n", (const char *) c0);
568 ret += -1.2e3 != (double) c0;
570 catch (struct CBStringException err) {
571 printf ("\tException (%s) correctly thrown\n", err.what());
574 try {
575 CBString c0 ("xxxxx");
576 printf ("\t(float) \"%s\"\n", (const char *) c0);
577 ret += -1.2e3 != (float) c0;
579 catch (struct CBStringException err) {
580 printf ("\tException (%s) correctly thrown\n", err.what());
583 try {
584 CBString c0 ("xxxxx");
585 printf ("\t(int) \"%s\"\n", (const char *) c0);
586 ret += -100 != (int) c0;
588 catch (struct CBStringException err) {
589 printf ("\tException (%s) correctly thrown\n", err.what());
592 try {
593 CBString c0 ("xxxxx");
594 printf ("\t(unsigned int) \"%s\"\n", (const char *) c0);
595 ret += 1000 != (unsigned int) c0;
597 catch (struct CBStringException err) {
598 printf ("\tException (%s) correctly thrown\n", err.what());
601 printf ("\t# failures: %d\n", ret);
602 return ret;
605 int test10 (void) {
606 int ret = 0;
608 try {
609 printf ("TEST: length() method\n");
610 CBString c0, c1("Test");
612 printf ("\t\"%s\".length();\n", (const char *) c0);
613 ret += 0 != c0.length();
614 printf ("\t\"%s\".length();\n", (const char *) c1);
615 ret += 4 != c1.length();
618 catch (struct CBStringException err) {
619 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
620 ret ++;
623 printf ("\t# failures: %d\n", ret);
624 return ret;
627 int test11 (void) {
628 int ret = 0;
630 printf ("TEST: character() method, [] operator\n");
632 try {
633 CBString c0("test");
634 c0.writeprotect ();
635 ret += c0[0] != 't';
636 ret += (1 + c0[0]) != 'u';
637 ret += ((unsigned char) c0[0] + 1) != 'u';
638 ret += c0.character(0) != 't';
639 EXCEPTION_EXPECTED (c0[0] = 'x');
640 EXCEPTION_EXPECTED (c0.character(0) = 'x');
642 catch (struct CBStringException err) {
643 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
644 ret ++;
647 try {
648 CBString c0("Test");
650 printf ("\t\"%s\".character ();\n", (const char *) c0);
651 ret += 's' != c0.character (2);
652 c0.character (2) = 'x';
653 ret += c0 != "Text";
655 printf ("\t\"%s\"[];\n", (const char *) c0);
656 ret += 'T' != c0[0];
657 c0[0] = 't';
658 ret += c0 != "text";
660 catch (struct CBStringException err) {
661 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
662 ret ++;
665 try {
666 CBString c0;
667 printf ("\t\"%s\".character ();\n", (const char *) c0);
668 ret += '?' != c0.character (0);
670 catch (struct CBStringException err) {
671 printf ("\tException (%s) correctly thrown\n", err.what());
674 try {
675 CBString c0;
676 printf ("\t\"%s\"[];\n", (const char *) c0);
677 ret += '?' != c0[0];
679 catch (struct CBStringException err) {
680 printf ("\tException (%s) correctly thrown\n", err.what());
683 printf ("\t# failures: %d\n", ret);
684 return ret;
687 int test12 (void) {
688 int ret = 0;
690 #ifndef BSTRLIB_NOVSNP
691 printf ("TEST: format(), formata() methods\n");
693 try {
694 CBString c0;
696 c0.writeprotect ();
697 EXCEPTION_EXPECTED (c0.format ("%s(%d)", "extra", 4));
698 EXCEPTION_EXPECTED (c0.formata ("%s(%d)", "extra", 4));
700 catch (struct CBStringException err) {
701 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
702 ret ++;
705 try {
706 CBString c0, c1("Test"), c2, c3;
708 printf ("\tc.format (...);\n");
709 c0.format ("%s(%d)", "extra", 4);
710 ret += c0 != "extra(4)";
712 c2 = c0 + c0 + c0 + c0;
713 c2 += c2;
714 c2.insert (0, "x");
715 c3.format ("x%s%s%s%s%s%s%s%s", (const char *) c0, (const char *) c0
716 , (const char *) c0, (const char *) c0
717 , (const char *) c0, (const char *) c0
718 , (const char *) c0, (const char *) c0);
719 ret += c2 != c3;
721 printf ("\t\"%s\".formata (...);\n", (const char *) c1);
722 c1.formata ("%s(%d)", "extra", 4);
723 ret += c1 != "Testextra(4)";
725 c2 = c0 + c0 + c0 + c0;
726 c2 += c2;
727 c2.insert (0, "x");
728 c3 = "x";
729 c3.formata ("%s%s%s%s%s%s%s%s", (const char *) c0, (const char *) c0
730 , (const char *) c0, (const char *) c0
731 , (const char *) c0, (const char *) c0
732 , (const char *) c0, (const char *) c0);
733 ret += c2 != c3;
735 catch (struct CBStringException err) {
736 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
737 ret ++;
740 printf ("\t# failures: %d\n", ret);
741 #endif
742 return ret;
745 int test13 (void) {
746 int ret = 0;
748 try {
749 printf ("TEST: find() method\n");
750 CBString c0, c1("Test");
752 printf ("\t\"%s\".find (CBString());\n", (const char *) c0);
753 ret += -1 != c0.find (CBString("x"));
754 ret += 1 != c1.find (CBString("e"));
756 printf ("\t\"%s\".find (char *);\n", (const char *) c0);
757 ret += -1 != c0.find ("x");
758 ret += 1 != c1.find ("e");
760 ret += 8 != CBString ("sssssssssap").find ("sap");
761 ret += 9 != CBString ("sssssssssap").find ("ap");
762 ret += 9 != CBString ("sssssssssap").find ("ap", 3);
763 ret += 9 != CBString ("sssssssssap").find ("a");
764 ret += 9 != CBString ("sssssssssap").find ("a", 3);
765 ret += -1 != CBString ("sssssssssap").find ("x");
766 ret += -1 != CBString ("sssssssssap").find ("x", 3);
767 ret += -1 != CBString ("sssssssssap").find ("ax");
768 ret += -1 != CBString ("sssssssssap").find ("ax", 3);
769 ret += -1 != CBString ("sssssssssap").find ("sax");
770 ret += -1 != CBString ("sssssssssap").find ("sax", 1);
771 ret += 8 != CBString ("sssssssssap").find ("sap", 3);
772 ret += 9 != CBString ("ssssssssssap").find ("sap", 3);
773 ret += 0 != CBString ("sssssssssap").find ("s");
774 ret += 3 != CBString ("sssssssssap").find ("s", 3);
775 ret += 9 != CBString ("sssssssssap").find ("a");
776 ret += 9 != CBString ("sssssssssap").find ("a", 5);
777 ret += 8 != CBString ("sasasasasap").find ("sap");
778 ret += 9 != CBString ("ssasasasasap").find ("sap");
780 printf ("\t\"%s\".find (char);\n", (const char *) c0);
781 ret += -1 != c0.find ('x');
782 ret += 1 != c1.find ('e');
784 printf ("TEST: reversefind () method\n");
785 printf ("\t\"%s\".reversefind (CBString());\n", (const char *) c0);
786 ret += -1 != c0.reversefind (CBString("x"), c0.length());
787 ret += 1 != c1.reversefind (CBString("e"), c1.length());
789 printf ("\t\"%s\".reversefind (char *);\n", (const char *) c0);
790 ret += -1 != c0.reversefind ("x", c0.length());
791 ret += 1 != c1.reversefind ("e", c1.length());
793 printf ("\t\"%s\".reversefind (char);\n", (const char *) c0);
794 ret += -1 != c0.reversefind ('x', c0.length());
795 ret += 1 != c1.reversefind ('e', c1.length());
798 catch (struct CBStringException err) {
799 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
800 ret ++;
803 printf ("\t# failures: %d\n", ret);
804 return ret;
807 int test14 (void) {
808 int ret = 0;
810 try {
811 printf ("TEST: findchr(), reversefindchr() methods\n");
812 CBString c0, c1("Test");
814 printf ("\t\"%s\".findchr (CBString(\"abcdef\"));\n", (const char *) c0);
815 ret += -1 != c0.findchr (CBString ("abcdef"));
816 printf ("\t\"%s\".findchr (CBString(\"abcdef\"));\n", (const char *) c1);
817 ret += 1 != c1.findchr (CBString ("abcdef"));
818 printf ("\t\"%s\".findchr (\"abcdef\");\n", (const char *) c0);
819 ret += -1 != c0.findchr ("abcdef");
820 printf ("\t\"%s\".findchr (\"abcdef\");\n", (const char *) c1);
821 ret += 1 != c1.findchr ("abcdef");
823 printf ("\t\"%s\".reversefindchr (CBString(\"abcdef\"));\n", (const char *) c0);
824 ret += -1 != c0.reversefindchr (CBString ("abcdef"), c0.length());
825 printf ("\t\"%s\".reversefindchr (CBString(\"abcdef\"));\n", (const char *) c1);
826 ret += 1 != c1.reversefindchr (CBString ("abcdef"), c1.length());
827 printf ("\t\"%s\".reversefindchr (\"abcdef\");\n", (const char *) c0);
828 ret += -1 != c0.reversefindchr ("abcdef", c0.length());
829 printf ("\t\"%s\".reversefindchr (\"abcdef\");\n", (const char *) c1);
830 ret += 1 != c1.reversefindchr ("abcdef", c1.length());
833 catch (struct CBStringException err) {
834 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
835 ret ++;
838 printf ("\t# failures: %d\n", ret);
839 return ret;
842 int test15 (void) {
843 int ret = 0;
845 try {
846 printf ("TEST: nfindchr(), nreversefindchr() methods\n");
847 CBString c0, c1("Test");
849 printf ("\t\"%s\".nfindchr (CBString(\"abcdef\"));\n", (const char *) c0);
850 ret += -1 != c0.nfindchr (CBString ("abcdef"));
851 printf ("\t\"%s\".nfindchr (CBString(\"abcdef\"));\n", (const char *) c1);
852 ret += 0 != c1.nfindchr (CBString ("abcdef"));
853 printf ("\t\"%s\".nfindchr (\"abcdef\");\n", (const char *) c0);
854 ret += -1 != c0.nfindchr ("abcdef");
855 printf ("\t\"%s\".nfindchr (\"abcdef\");\n", (const char *) c1);
856 ret += 0 != c1.nfindchr ("abcdef");
858 printf ("\t\"%s\".nreversefindchr (CBString(\"abcdef\"));\n", (const char *) c0);
859 ret += -1 != c0.nreversefindchr (CBString ("abcdef"), c0.length());
860 printf ("\t\"%s\".nreversefindchr (CBString(\"abcdef\"));\n", (const char *) c1);
861 ret += 3 != c1.nreversefindchr (CBString ("abcdef"), c1.length());
862 printf ("\t\"%s\".nreversefindchr (\"abcdef\");\n", (const char *) c0);
863 ret += -1 != c0.nreversefindchr ("abcdef", c0.length());
864 printf ("\t\"%s\".nreversefindchr (\"abcdef\");\n", (const char *) c1);
865 ret += 3 != c1.nreversefindchr ("abcdef", c1.length());
868 catch (struct CBStringException err) {
869 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
870 ret ++;
873 printf ("\t# failures: %d\n", ret);
874 return ret;
877 int test16 (void) {
878 int ret = 0;
880 printf ("TEST: midstr() method\n");
882 try {
883 CBString c0, c1("bogus"), c2;
885 printf ("\t\"%s\".midstr (1,3)\n", (const char *) c0);
886 ret += (c2 = c0.midstr (1,3)) != "";
887 ret += '\0' != ((const char *)c2)[c2.length ()];
889 printf ("\t\"%s\".midstr (1,3)\n", (const char *) c1);
890 ret += (c2 = c1.midstr (1,3)) != "ogu";
891 ret += '\0' != ((const char *)c2)[c2.length ()];
894 catch (struct CBStringException err) {
895 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
896 ret ++;
899 printf ("\t# failures: %d\n", ret);
900 return ret;
903 int test17 (void) {
904 int ret = 0;
906 printf ("TEST: fill() method\n");
908 try {
909 CBString c0;
911 c0.writeprotect ();
912 EXCEPTION_EXPECTED (c0.fill (5, 'x'));
914 catch (struct CBStringException err) {
915 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
916 ret ++;
919 try {
920 CBString c0, c1("Test-test");
922 printf ("\t\"%s\".fill(5,'x')\n", (const char *) c0);
923 c0.fill (5, 'x');
924 ret += c0 != "xxxxx";
926 printf ("\t\"%s\".fill(5,'x')\n", (const char *) c1);
927 c1.fill (5, 'x');
928 ret += c1 != "xxxxx";
930 catch (struct CBStringException err) {
931 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
932 ret ++;
935 printf ("\t# failures: %d\n", ret);
936 return ret;
939 int test18 (void) {
940 int ret = 0;
942 printf ("TEST: alloc() method\n");
944 try {
945 CBString c0;
947 c0.writeprotect ();
948 EXCEPTION_EXPECTED (c0.alloc (5));
950 catch (struct CBStringException err) {
951 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
952 ret ++;
955 try {
956 CBString c0, c1("Test-test");
958 printf ("\t\"%s\".alloc(5)\n", (const char *) c0);
959 c0.alloc (5);
960 ret += c0 != "";
962 printf ("\t\"%s\".alloc(5)\n", (const char *) c1);
963 c1.alloc (5);
964 ret += c1 != "Test-test";
966 catch (struct CBStringException err) {
967 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
968 ret ++;
971 try {
972 CBString c0;
974 printf ("\t\"%s\".alloc(0)\n", (const char *) c0);
975 c0.alloc (0);
976 ret += c0 != "Error";
978 catch (struct CBStringException err) {
979 printf ("\tException (%s) properly thrown\n", err.what());
982 try {
983 CBString c0;
985 printf ("\t\"%s\".alloc(-1)\n", (const char *) c0);
986 c0.alloc (-1);
987 ret += c0 != "Error";
989 catch (struct CBStringException err) {
990 printf ("\tException (%s) properly thrown\n", err.what());
993 printf ("\t# failures: %d\n", ret);
994 return ret;
997 int test19 (void) {
998 int ret = 0;
1000 printf ("TEST: setsubstr() method\n");
1002 try {
1003 CBString c0("Test-test");
1005 c0.writeprotect ();
1006 EXCEPTION_EXPECTED (c0.setsubstr (4, "extra"));
1008 catch (struct CBStringException err) {
1009 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1010 ret ++;
1013 try {
1014 CBString c0, c1("Test-test");
1016 printf ("\t\"%s\".setsubstr (4,\"extra\")\n", (const char *) c0);
1017 c0.setsubstr (4, "extra");
1018 ret += c0 != " extra";
1019 printf ("\t\"%s\".setsubstr (4,\"extra\")\n", (const char *) c1);
1020 c1.setsubstr (4, "extra");
1021 ret += c1 != "Testextra";
1024 catch (struct CBStringException err) {
1025 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1026 ret ++;
1029 try {
1030 CBString c0;
1032 printf ("\t\"%s\".setsubstr(-1,\"extra\")\n", (const char *) c0);
1033 c0.setsubstr (-1, "extra");
1034 ret ++;
1036 catch (struct CBStringException err) {
1037 printf ("\tException (%s) properly thrown\n", err.what());
1040 printf ("\t# failures: %d\n", ret);
1041 return ret;
1044 int test20 (void) {
1045 int ret = 0;
1047 printf ("TEST: insert() method\n");
1049 try {
1050 CBString c0("Test-test");
1052 c0.writeprotect ();
1053 EXCEPTION_EXPECTED (c0.insert (4, "extra"));
1055 catch (struct CBStringException err) {
1056 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1057 ret ++;
1060 try {
1061 CBString c0, c1("Test-test");
1063 printf ("\t\"%s\".insert (4,\"extra\")\n", (const char *) c0);
1064 c0.insert (4, "extra");
1065 ret += c0 != " extra";
1066 printf ("\t\"%s\".insert (4,\"extra\")\n", (const char *) c1);
1067 c1.insert (4, "extra");
1068 ret += c1 != "Testextra-test";
1071 catch (struct CBStringException err) {
1072 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1073 ret ++;
1076 try {
1077 CBString c0;
1079 printf ("\t\"%s\".insert(-1,\"extra\")\n", (const char *) c0);
1080 c0.insert (-1, "extra");
1081 ret ++;
1083 catch (struct CBStringException err) {
1084 printf ("\tException (%s) properly thrown\n", err.what());
1087 printf ("\t# failures: %d\n", ret);
1088 return ret;
1091 int test21 (void) {
1092 int ret = 0;
1094 printf ("TEST: insertchrs() method\n");
1096 try {
1097 CBString c0("Test-test");
1099 c0.writeprotect ();
1100 EXCEPTION_EXPECTED (c0.insertchrs (4, 2, 'x'));
1102 catch (struct CBStringException err) {
1103 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1104 ret ++;
1107 try {
1108 CBString c0, c1("Test-test");
1110 printf ("\t\"%s\".insertchrs (4,2,'x')\n", (const char *) c0);
1111 c0.insertchrs (4, 2, 'x');
1112 ret += c0 != "xxxxxx";
1113 printf ("\t\"%s\".insertchrs (4,2,'x')\n", (const char *) c1);
1114 c1.insertchrs (4, 2, 'x');
1115 ret += c1 != "Testxx-test";
1117 catch (struct CBStringException err) {
1118 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1119 ret ++;
1122 try {
1123 CBString c0;
1125 printf ("\t\"%s\".insertchrs (-1,2,'x')\n", (const char *) c0);
1126 c0.insertchrs (-1, 2, 'x');
1127 ret ++;
1129 catch (struct CBStringException err) {
1130 printf ("\tException (%s) properly thrown\n", err.what());
1133 printf ("\t# failures: %d\n", ret);
1134 return ret;
1137 int test22 (void) {
1138 int ret = 0;
1140 printf ("TEST: replace() method\n");
1142 try {
1143 CBString c0("Test-test");
1145 c0.writeprotect ();
1146 EXCEPTION_EXPECTED (c0.replace (4, 2, "beef"));
1148 catch (struct CBStringException err) {
1149 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1150 ret ++;
1153 try {
1154 CBString c0, c1("Test-test");
1156 printf ("\t\"%s\".replace (4,2,\"beef\")\n", (const char *) c0);
1157 c0.replace (4, 2, CBString ("beef"));
1158 ret += c0 != " beef";
1159 c0 = "";
1160 c0.replace (4, 2, "beef");
1161 ret += c0 != " beef";
1163 printf ("\t\"%s\".replace (4,2,\"beef\")\n", (const char *) c1);
1164 c1.replace (4, 2, CBString ("beef"));
1165 ret += c1 != "Testbeefest";
1166 c1 = "Test-test";
1167 c1.replace (4, 2, "beef");
1168 ret += c1 != "Testbeefest";
1170 catch (struct CBStringException err) {
1171 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1172 ret ++;
1175 printf ("\t# failures: %d\n", ret);
1176 return ret;
1179 int test23 (void) {
1180 int ret = 0;
1182 printf ("TEST: findreplace() method\n");
1184 try {
1185 CBString c0, c1("Test-test");
1187 printf ("\t\"%s\".findreplace (\"est\",\"beef\")\n", (const char *) c0);
1188 c0.findreplace ("est", "beef");
1189 ret += c0 != "";
1190 c0 = "";
1191 c0.findreplace (CBString ("est"), CBString ("beef"));
1192 ret += c0 != "";
1194 printf ("\t\"%s\".findreplace (\"est\",\"beef\")\n", (const char *) c1);
1195 c1.findreplace ("est", "beef");
1196 ret += c1 != "Tbeef-tbeef";
1197 c1 = "Test-test";
1198 c1.findreplace (CBString ("est"), CBString ("beef"));
1199 ret += c1 != "Tbeef-tbeef";
1202 catch (struct CBStringException err) {
1203 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1204 ret ++;
1207 try {
1208 CBString c0, c1("TeSt-tEsT");
1210 printf ("\t\"%s\".findreplacecaseless (\"est\",\"beef\")\n", (const char *) c0);
1211 c0.findreplacecaseless ("est", "beef");
1212 ret += c0 != "";
1213 c0 = "";
1214 c0.findreplacecaseless (CBString ("est"), CBString ("beef"));
1215 ret += c0 != "";
1217 printf ("\t\"%s\".findreplacecaseless (\"est\",\"beef\")\n", (const char *) c1);
1218 c1.findreplacecaseless ("est", "beef");
1219 ret += c1 != "Tbeef-tbeef";
1220 c1 = "Test-test";
1221 c1.findreplacecaseless (CBString ("est"), CBString ("beef"));
1222 ret += c1 != "Tbeef-tbeef";
1225 catch (struct CBStringException err) {
1226 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1227 ret ++;
1230 printf ("\t# failures: %d\n", ret);
1231 return ret;
1234 int test24 (void) {
1235 int ret = 0;
1237 printf ("TEST: remove() method\n");
1239 try {
1240 CBString c0, c1("Test-test");
1242 printf ("\t\"%s\".remove (4,2)\n", (const char *) c0);
1243 c0.remove (4, 2);
1244 ret += c0 != "";
1246 printf ("\t\"%s\".remove (4,2)\n", (const char *) c1);
1247 c1.remove (4, 2);
1248 ret += c1 != "Testest";
1250 catch (struct CBStringException err) {
1251 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1252 ret ++;
1255 printf ("\t# failures: %d\n", ret);
1256 return ret;
1259 int test25 (void) {
1260 int ret = 0;
1262 printf ("TEST: trunc() method\n");
1264 try {
1265 CBString c0, c1("Test-test");
1267 printf ("\t\"%s\".trunc (4)\n", (const char *) c0);
1268 c0.trunc (4);
1269 ret += c0 != "";
1271 printf ("\t\"%s\".trunc (4)\n", (const char *) c1);
1272 c1.trunc (4);
1273 ret += c1 != "Test";
1275 catch (struct CBStringException err) {
1276 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1277 ret ++;
1280 printf ("\t# failures: %d\n", ret);
1281 return ret;
1284 int test26 (void) {
1285 int ret = 0;
1287 printf ("TEST: repeat() method\n");
1289 try {
1290 CBString c0, c1("Test");
1292 printf ("\t\"%s\".repeat (4)\n", (const char *) c0);
1293 c0.repeat (4);
1294 ret += c0 != "";
1296 printf ("\t\"%s\".repeat (4)\n", (const char *) c1);
1297 c1.repeat (4);
1298 ret += c1 != "TestTestTestTest";
1299 c1 = "Test";
1300 c1.repeat (4);
1301 ret += c1 != "TestTestTestTest";
1303 catch (struct CBStringException err) {
1304 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1305 ret ++;
1308 printf ("\t# failures: %d\n", ret);
1309 return ret;
1312 int test27 (void) {
1313 int ret = 0;
1315 printf ("TEST: ltrim(), rtrim() methods\n");
1317 try {
1318 CBString c0, c1(" Test "), c2(" ");
1320 printf ("\t\"%s\".ltrim ()\n", (const char *) c0);
1321 c0.ltrim ();
1322 ret += c0 != "";
1323 c0 = "";
1324 c0.rtrim ();
1325 ret += c0 != "";
1327 printf ("\t\"%s\".ltrim ()\n", (const char *) c1);
1328 c1.ltrim ();
1329 ret += c1 != "Test ";
1330 c1 = " Test ";
1331 c1.rtrim ();
1332 ret += c1 != " Test";
1334 printf ("\t\"%s\".ltrim ()\n", (const char *) c2);
1335 c2.ltrim ();
1336 ret += c2 != "";
1337 c2 = " ";
1338 c2.rtrim ();
1339 ret += c2 != "";
1341 catch (struct CBStringException err) {
1342 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1343 ret ++;
1346 printf ("\t# failures: %d\n", ret);
1347 return ret;
1350 int test28 (void) {
1351 int ret = 0;
1353 printf ("TEST: split(), join() mechanisms\n");
1355 try {
1356 CBString c0, c1("a b c d e f");
1357 struct CBStringList s;
1358 s.split (c1, ' ');
1360 c0.writeprotect ();
1361 EXCEPTION_EXPECTED (c0.join (s));
1363 catch (struct CBStringException err) {
1364 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1365 ret ++;
1368 try {
1369 CBString c0, c1("a b c d e f");
1370 struct CBStringList s;
1372 printf ("\t\"%s\".split (' ')\n", (const char *) c1);
1374 s.split (c1, ' ');
1375 CBString c2(s), c3(s, ',');
1377 printf ("\tc.join (<...>)\n");
1379 ret += c2 != "abcdef";
1380 ret += c3 != "a,b,c,d,e,f";
1381 c0.join (s);
1382 ret += c0 != "abcdef";
1383 c0.join (s, ',');
1384 ret += c0 != "a,b,c,d,e,f";
1386 CBString strPepe = "valor1@valor2@valor3@@@valor6";
1387 for (unsigned char c = (unsigned char) '\0';;c++) {
1388 CBStringList sl;
1389 CBString x;
1391 sl.split (strPepe, c);
1392 x.join (sl, c);
1393 if (x != strPepe) {
1394 printf ("\tfailure[%d] split/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x);
1395 ret++;
1396 break;
1398 if (UCHAR_MAX == c) break;
1402 CBStringList sl;
1403 CBString x;
1405 sl.splitstr (strPepe, CBString ("or"));
1406 x.join (sl, CBString ("or"));
1407 if (x != strPepe) {
1408 printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x);
1409 ret++;
1414 CBStringList sl;
1415 CBString x;
1417 sl.splitstr (strPepe, CBString ("6"));
1418 x.join (sl, CBString ("6"));
1419 if (x != strPepe) {
1420 printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x);
1421 ret++;
1426 CBStringList sl;
1427 CBString x;
1429 sl.splitstr (strPepe, CBString ("val"));
1430 x.join (sl, CBString ("val"));
1431 if (x != strPepe) {
1432 printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x);
1433 ret++;
1438 CBStringList sl;
1439 CBString x;
1441 sl.splitstr (strPepe, CBString ("@@"));
1442 x.join (sl, CBString ("@@"));
1443 if (x != strPepe) {
1444 printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x);
1445 ret++;
1450 catch (struct CBStringException err) {
1451 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1452 ret ++;
1455 printf ("\t# failures: %d\n", ret);
1456 return ret;
1459 int test29 (void) {
1460 int ret = 0;
1462 printf ("TEST: caselessEqual(), caselessCmp() mechanisms\n");
1464 try {
1465 CBString c0("Test"), c1("test"), c2("testy");
1467 printf ("\t\"%s\".caselessEqual (\"%s\")\n", (const char *) c0, (const char *) c1);
1468 ret += 1 != c0.caselessEqual (c1);
1469 ret += 1 != c1.caselessEqual (c0);
1470 printf ("\t\"%s\".caselessEqual (\"%s\")\n", (const char *) c0, (const char *) c2);
1471 ret += 0 != c0.caselessEqual (c2);
1472 ret += 0 != c2.caselessEqual (c0);
1474 printf ("\t\"%s\".caselessCmp (\"%s\")\n", (const char *) c0, (const char *) c1);
1475 ret += 0 != c0.caselessCmp (c1);
1476 ret += 0 != c1.caselessCmp (c0);
1477 printf ("\t\"%s\".caselessCmp (\"%s\")\n", (const char *) c0, (const char *) c2);
1478 ret += 0 == c0.caselessCmp (c2);
1479 ret += 0 == c2.caselessCmp (c0);
1481 catch (struct CBStringException err) {
1482 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1483 ret ++;
1486 printf ("\t# failures: %d\n", ret);
1487 return ret;
1490 int test30 (void) {
1491 int ret = 0;
1493 printf ("TEST: toupper(), tolower() mechanisms\n");
1495 try {
1496 CBString c0("Test-test");
1498 c0.writeprotect ();
1499 EXCEPTION_EXPECTED (c0.toupper());
1500 EXCEPTION_EXPECTED (c0.tolower());
1502 catch (struct CBStringException err) {
1503 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1504 ret ++;
1507 try {
1508 CBString c0;
1510 c0 = "Test";
1511 printf ("\t\"%s\".toupper ()\n", (const char *) c0);
1512 c0.toupper();
1513 ret += c0 != "TEST";
1515 c0 = "Test";
1516 printf ("\t\"%s\".tolower ()\n", (const char *) c0);
1517 c0.tolower ();
1518 ret += c0 != "test";
1520 catch (struct CBStringException err) {
1521 printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
1522 ret ++;
1525 printf ("\t# failures: %d\n", ret);
1526 return ret;
1529 static size_t test31_aux (void *buff, size_t elsize, size_t nelem, void *parm) {
1530 buff = buff;
1531 elsize = elsize;
1532 nelem = nelem;
1533 parm = parm;
1534 return 0;
1537 int test31 (void) {
1538 CBString c;
1539 int ret = 0;
1541 printf ("TEST: CBStream test\n");
1543 CBStream s((bNread) test31_aux, NULL);
1544 s << CBString("Test");
1546 ret += ((c = s.read ()) != CBString ("Test"));
1547 ret += !s.eof();
1549 printf ("\t\"%s\" through CBStream.read()\n", (const char *) c);
1551 s << CBString("Test");
1553 c.trunc (0);
1554 ret += ((s >> c) != CBString ("Test"));
1555 ret += !s.eof();
1557 printf ("\t\"%s\" through CBStream.>>\n", (const char *) c);
1559 return ret;
1562 int main () {
1563 int ret = 0;
1565 printf ("Direct case testing of CPP core functions\n");
1567 ret += test0 ();
1568 ret += test1 ();
1569 ret += test2 ();
1570 ret += test3 ();
1571 ret += test4 ();
1572 ret += test5 ();
1573 ret += test6 ();
1574 ret += test7 ();
1575 ret += test8 ();
1576 ret += test9 ();
1577 ret += test10 ();
1578 ret += test11 ();
1579 ret += test12 ();
1580 ret += test13 ();
1581 ret += test14 ();
1582 ret += test15 ();
1583 ret += test16 ();
1584 ret += test17 ();
1585 ret += test18 ();
1586 ret += test19 ();
1587 ret += test20 ();
1588 ret += test21 ();
1589 ret += test22 ();
1590 ret += test23 ();
1591 ret += test24 ();
1592 ret += test25 ();
1593 ret += test26 ();
1594 ret += test27 ();
1595 ret += test28 ();
1596 ret += test29 ();
1597 ret += test30 ();
1598 ret += test31 ();
1600 printf ("# test failures: %d\n", ret);
1602 return 0;