00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef EMBEDDED_BUILD
00016 #include "t_basis.rh"
00017 #endif
00018
00019
00020
00021
00022 #include <basis/chaos.h>
00023 #include <basis/earth_time.h>
00024 #include <basis/function.h>
00025 #include <basis/guards.h>
00026 #include <basis/istring.h>
00027 #include <basis/sequence.h>
00028 #include <basis/string_array.h>
00029 #include <data_struct/static_memory_gremlin.h>
00030 #include <mechanisms/time_stamp.h>
00031 #include <loggers/file_logger.h>
00032 #include <data_struct/static_memory_gremlin.h>
00033 #include <textual/byte_format.h>
00034 #include <textual/string_convert.h>
00035 #include <textual/string_manipulation.h>
00036
00037 #ifdef __WIN32__
00038 #include <comdef.h>
00039 #endif
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043
00044 HOOPLE_STARTUP_CODE;
00045
00046 using namespace earth_time;
00047
00048 chaos rando;
00049
00050
00051
00052
00053 #define out program_wide_logger()
00054 #define static_class_name() "t_istring"
00055
00056 const float TEST_RUNTIME_DEFAULT = .5 * MINUTE_ms;
00057
00058
00059 #define WHERE __WHERE__.s()
00060
00061
00062
00063 int compnum = 0;
00064 #define test(expr) \
00065 compnum++; \
00066 if (expr) { \
00067 istring fred(istring::SPRINTF, "operator test %d did not work", ++compnum); \
00068 deadly_error(WHERE, func, fred.observe()); \
00069 }
00070
00071 static istring staticity_test("yo!");
00072
00073
00074 void run_test_01()
00075 {
00076 FUNCDEF("run_test_01");
00077
00078 const int TEST_EMPTY = 10000000;
00079 time_stamp started;
00080 for (int i = 0; i < TEST_EMPTY; i++) {
00081 istring glob = istring::empty_string();
00082 }
00083 int duration = int(time_stamp().value() - started.value());
00084 out.log(isprintf("duration of empty string test=%d ms", duration));
00085
00086
00087 istring fred1("hyeargh!");
00088 istring fred2("matey.");
00089 istring fred3;
00090 fred3 = fred1;
00091 fred3 += fred2;
00092 istring fred4(fred2);
00093
00094 if (fred1.length() != int(strlen(fred1.s())))
00095 deadly_error(WHERE, func, "length is incorrect (a).");
00096 if (fred2.length() != int(strlen(fred2.s())))
00097 deadly_error(WHERE, func, "length is incorrect (b).");
00098 if (fred3.length() != int(strlen(fred3.s())))
00099 deadly_error(WHERE, func, "length is incorrect (c).");
00100 if (fred4.length() != int(strlen(fred4.s())))
00101 deadly_error(WHERE, func, "length is incorrect (d).");
00102
00103 #ifdef DEBUG_STRING_TEST
00104 out.log("[ " + fred1 + " & " + fred2 + "] -> " + fred3);
00105 #endif
00106
00107 if (fred1 != istring("hyeargh!"))
00108 deadly_error(WHERE, func, "failure in comparison (a).");
00109 if (fred2 != istring("matey."))
00110 deadly_error(WHERE, func, "failure in comparison (b).");
00111 if (fred3 != istring("hyeargh!matey."))
00112 deadly_error(WHERE, func, "failure in comparison (c).");
00113 if (fred4 != istring("matey."))
00114 deadly_error(WHERE, func, "failure in comparison (d-1).");
00115 if (fred4 != fred2)
00116 deadly_error(WHERE, func, "failure in comparison (d-2).");
00117
00118 isprintf nullo;
00119 if ( (nullo != istring()) || (istring() != nullo) )
00120 deadly_error(WHERE, func, "blank isprintf isn't blank.");
00121 if ( (nullo != istring::empty_string())
00122 || (istring::empty_string() != nullo) )
00123 deadly_error(WHERE, func, "blank isprintf isn't empty.");
00124
00125 }
00126
00127 void run_test_02()
00128 {
00129 FUNCDEF("run_test_02");
00130
00131 istring *fred1 = new istring("flipper ate");
00132 istring *fred2 = new istring(" my sandwich.");
00133 istring *fred3 = new istring;
00134 *fred3 = *fred1;
00135 *fred3 += *fred2;
00136
00137
00138 *fred2 += (char *)NIL;
00139 *fred3 += (char *)NIL;
00140
00141 #ifdef DEBUG_STRING_TEST
00142 out.log(istring("[ ") + *fred1 + " & " + *fred2 + "] -> " + *fred3);
00143 #endif
00144
00145 int die = false;
00146 if (*fred1 != istring("flipper ate")) die++;
00147 if (*fred2 != istring(" my sandwich.")) die++;
00148 if (*fred3 != istring("flipper ate my sandwich.")) die++;
00149 if (die) deadly_error(WHERE, func, "failure in comparison");
00150 delete fred1;
00151 delete fred2;
00152 delete fred3;
00153 }
00154
00155 void run_test_03()
00156 {
00157 FUNCDEF("run_test_03");
00158
00159 istring fleermipe("hello my frobious.");
00160 fleermipe.zap(0, fleermipe.length() - 1);
00161 if (fleermipe.length() != 0)
00162 deadly_error(WHERE, func, "length not 0 after deleting entire istring");
00163 }
00164
00165 void run_test_04()
00166 {
00167 FUNCDEF("run_test_04");
00168 istring test_string("this test string will be chopped up.");
00169 #ifdef DEBUG_STRING_TEST
00170 out.log(istring("original is: ") + test_string);
00171 #endif
00172 istring fred(test_string.s());
00173 fred.zap(0, fred.find('w'));
00174
00175 #ifdef DEBUG_STRING_TEST
00176 out.log(istring("now, the one chopped through 'w' is: ") + fred);
00177 #endif
00178
00179 if (fred != istring("ill be chopped up."))
00180 deadly_error(WHERE, func, "first zap failed");
00181
00182 istring blorg(test_string);
00183 blorg.zap(blorg.find('p'), blorg.length() - 1);
00184 #ifdef DEBUG_STRING_TEST
00185 out.log(istring("now the one chopped from p to the end: ") + blorg);
00186 #endif
00187
00188 if (blorg != istring("this test string will be cho"))
00189 deadly_error(WHERE, func, "second zap failed");
00190
00191 istring fleen;
00192 fleen += test_string;
00193 fleen.zap(7, 14);
00194 #ifdef DEBUG_STRING_TEST
00195 out.log(istring("now the one with 7 through 14 missing: ") + fleen);
00196 #endif
00197
00198 if (fleen != istring("this teg will be chopped up."))
00199 deadly_error(WHERE, func, "third zap failed");
00200
00201 #ifdef DEBUG_STRING_TEST
00202 out.log(istring("original istring is now: ") + test_string);
00203 #endif
00204 if (test_string != istring("this test string will be chopped up."))
00205 deadly_error(WHERE, func, "original istring was changed");
00206 }
00207
00208 void run_test_05()
00209 {
00210 FUNCDEF("run_test_05");
00211 #ifdef DEBUG_STRING_TEST
00212 out.log("about to test weird things:");
00213 #endif
00214 istring frieda("glorp");
00215 istring jorb(frieda);
00216 istring *kleeg = new istring(jorb.s());
00217 istring plok = frieda;
00218 test(frieda != jorb);
00219 test(jorb != *kleeg);
00220 test(*kleeg != plok);
00221 test(plok != frieda);
00222 istring glorp("glorp");
00223 test(frieda != glorp);
00224
00225 WHACK(kleeg);
00226
00227 #ifdef DEBUG_STRING_TEST
00228 out.log("strings matched up okay.");
00229 #endif
00230
00231
00232 istring bubba("gumpternations");
00233 bubba += "_02193";
00234 #ifdef DEBUG_STRING_TEST
00235 out.log(istring("bubba = ") + bubba);
00236 #endif
00237 if (bubba != istring("gumpternations_02193"))
00238 deadly_error(WHERE, func, "+= on char pointer failed.");
00239
00240 istring bubelah("laksos");
00241 bubelah += '3';
00242 bubelah += '8';
00243 bubelah += '2';
00244 #ifdef DEBUG_STRING_TEST
00245 out.log(istring("bubelah = ") + bubelah);
00246 #endif
00247 if (bubelah != istring("laksos382"))
00248 deadly_error(WHERE, func, "+= on char failed.");
00249
00250 istring simple_spr0(istring::SPRINTF, "%% yoga splorch %%");
00251 #ifdef DEBUG_STRING_TEST
00252 out.log(istring("simple sprintf 0 = ") + simple_spr0);
00253 #endif
00254 if (simple_spr0 != istring("% yoga splorch %"))
00255 deadly_error(WHERE, func, "simple sprintf 0 is wrong");
00256 istring simple_spr1(istring::SPRINTF, "%d", 23);
00257 #ifdef DEBUG_STRING_TEST
00258 out.log(istring("simple sprintf 1 = ") + simple_spr1);
00259 #endif
00260 if (simple_spr1 != istring("23"))
00261 deadly_error(WHERE, func, "simple sprintf 1 is wrong");
00262 istring simple_spr2(istring::SPRINTF, "%s", "yoyo");
00263 #ifdef DEBUG_STRING_TEST
00264 out.log(istring("simple sprintf 2 = ") + simple_spr2);
00265 #endif
00266 if (simple_spr2 != istring("yoyo"))
00267 deadly_error(WHERE, func, "simple sprintf 2 is wrong");
00268
00269 istring sprintest(istring::SPRINTF, "%s has got me up the %s some %d "
00270 "times, in %p with %d and %lu.", "marge", "ladder", 32, &kleeg,
00271 812377487L, 213123123L);
00272 istring sprintest2;
00273 sprintest2.reset(istring::SPRINTF, "%s has got me up the %s some %d "
00274 "times, in %p with %d and %lu.", "marge", "ladder", 32, &kleeg,
00275 812377487L, 213123123L);
00276 istring addr(istring::SPRINTF, "%p", &kleeg);
00277 #ifdef DEBUG_STRING_TEST
00278 out.log("here is your istring sir...");
00279 out.log(sprintest);
00280 out.log("and addr we will see is...");
00281 out.log(addr);
00282 #endif
00283 if (sprintest != istring(istring::SPRINTF, "marge has got me up the "
00284 "ladder some 32 times, in %s with 812377487 and 213123123.", addr.s()))
00285 deadly_error(WHERE, func, "constructed istring is wrong");
00286 if (sprintest2 != istring(istring::SPRINTF, "marge has got me up the "
00287 "ladder some 32 times, in %s with 812377487 and 213123123.", addr.s()))
00288 deadly_error(WHERE, func, "reset istring is wrong");
00289 }
00290
00291 void run_test_06()
00292 {
00293 FUNCDEF("run_test_06");
00294 istring bungee;
00295 bungee += "this istring";
00296 bungee += " has been constructed gradua";
00297 bungee += 'l';
00298 bungee += 'l';
00299 bungee += 'y';
00300 istring blorpun(istring::SPRINTF, " out of severa%c", 'l');
00301 bungee += blorpun;
00302 bungee += " different bits,\nincluding";
00303 istring freeple(istring::SPRINTF, "%s constructed %s blarg from %f ", " this", "silly", 3.14159265358);
00304 bungee += freeple;
00305 bungee += "radians awa";
00306 bungee += 'y';
00307 bungee += '.';
00308 bungee += "\nhow does it look?\n";
00309 #ifdef DEBUG_STRING_TEST
00310 out.log(bungee);
00311 #endif
00312
00313
00314 if (bungee != istring("this istring has been constructed gradually out of several different bits,\nincluding this constructed silly blarg from 3.141593 radians away.\nhow does it look?\n"))
00315 deadly_error(WHERE, func, "constructed istring is wrong");
00316 }
00317
00318 void run_test_07()
00319 {
00320 FUNCDEF("run_test_07");
00321 istring a("axes");
00322 istring b("bakesales");
00323 istring x("xylophone");
00324
00325 test(a >= x);
00326 test(a == b);
00327 test(a > b);
00328 test(b >= x);
00329 test(x <= a);
00330 test(x != x);
00331 test(a != a);
00332 #ifdef DEBUG_STRING_TEST
00333 out.log("comparisons worked");
00334 #endif
00335 }
00336
00337 void run_test_08()
00338 {
00339 FUNCDEF("run_test_08");
00340 #ifdef DEBUG_STRING_TEST
00341 out.log("now testing + operator");
00342 #endif
00343 istring a("fred");
00344 istring b(" is");
00345 istring c(" his");
00346 istring d(" name.");
00347 istring e;
00348 e = a + b + c + d;
00349 #ifdef DEBUG_STRING_TEST
00350 out.log(istring("result is: ") + e);
00351 #endif
00352 istring f;
00353 f = d + c + b + a;
00354 #ifdef DEBUG_STRING_TEST
00355 out.log(istring("reverse is: ") + f);
00356 #endif
00357 istring g;
00358 g = a + c + d + b;
00359 #ifdef DEBUG_STRING_TEST
00360 out.log(istring("tibetan style is: ") + g);
00361 #endif
00362 int die = false;
00363 if (e != istring("fred is his name.")) die++;
00364 if (f != istring(" name. his isfred")) die++;
00365 if (g != istring("fred his name. is")) die++;
00366 if (die) deadly_error(WHERE, func, "istring looks wrong");
00367 }
00368
00369 void run_test_09()
00370 {
00371 FUNCDEF("run_test_09");
00372 istring bleer(istring::SPRINTF, "urghla burgla #%d\n", 23);
00373 char holder[50];
00374 for (int i = 0; i < bleer.length(); i++) {
00375 bleer.stuff(holder, i);
00376 #ifdef DEBUG_STRING_TEST
00377 out.log(istring(istring::SPRINTF, "%d", i) + " has: " + holder);
00378 #endif
00379 istring my_copy(bleer);
00380 my_copy.zap(i, bleer.length() - 1);
00381 if (my_copy != istring(holder))
00382 deadly_error(WHERE, func, "inaccurate stuff");
00383 }
00384 }
00385
00386 void run_test_10()
00387 {
00388 FUNCDEF("run_test_10");
00389 #ifdef DEBUG_STRING_TEST
00390 out.log("The tenth ones:");
00391 #endif
00392 istring george("this one will be mangled.");
00393 if (george.length() != int(strlen(george.s())))
00394 deadly_error(WHERE, func, "length is incorrect (q).");
00395 istring tmp1(george.substring(1, 7));
00396 istring tmp2 = george.substring(10, george.length() - 1);
00397 #ifdef DEBUG_STRING_TEST
00398 out.log(tmp1 + "... " + tmp2);
00399 #endif
00400 if (tmp1 == tmp2)
00401 deadly_error(WHERE, func, "bizarre equality occurred!!");
00402 if ( (tmp1 > tmp2) || (tmp2 < tmp1) )
00403 deadly_error(WHERE, func, "bizarre comparison error.");
00404 if (george.length() != int(strlen(george.s())))
00405 deadly_error(WHERE, func, "length is incorrect (z).");
00406 #ifdef DEBUG_STRING_TEST
00407 out.log(george.substring(1, 7));
00408 out.log("... ");
00409 out.log(george.substring(10, george.length() - 1));
00410 #endif
00411 if (george.length() != int(strlen(george.s())))
00412 deadly_error(WHERE, func, "length is incorrect (a).");
00413 george.insert(14, "terribly ");
00414 if (george.length() != int(strlen(george.s())))
00415 deadly_error(WHERE, func, "length is incorrect (b).");
00416 #ifdef DEBUG_STRING_TEST
00417 out.log(george);
00418 #endif
00419 istring chunky;
00420 istring mssr_boef_la_tet("eeyoy eye eye capn");
00421 mssr_boef_la_tet.substring(chunky, 2, 7);
00422 if (chunky != "yoy ey")
00423 deadly_error(WHERE, func, "contents wrong after substring");
00424
00425 istring fred(george);
00426 if (!george.compare(fred, 0, 0, george.length() - 1))
00427 deadly_error(WHERE, func, "did not work");
00428 if (!george.compare(fred, 8, 8, george.length() - 1 - 8))
00429 deadly_error(WHERE, func, "partial did not work");
00430
00431 if (george.length() != int(strlen(george.s())))
00432 deadly_error(WHERE, func, "length is incorrect (c).");
00433 george.zap(14, 22);
00434 #ifdef DEBUG_STRING_TEST
00435 out.log(george);
00436 #endif
00437 istring fred_part;
00438 fred_part = fred.substring(0, 13);
00439 if (fred_part.length() != int(strlen(fred_part.s())))
00440 deadly_error(WHERE, func, "length incorrect (d).");
00441 if (!george.compare(fred_part, 0, 0, 13))
00442 deadly_error(WHERE, func, "did not work");
00443 fred_part = fred.substring(23, fred.length() - 1);
00444 if (fred_part.length() != int(strlen(fred_part.s())))
00445 deadly_error(WHERE, func, "length incorrect (e).");
00446 if (!george.compare(fred_part, 14, 0, fred_part.length() - 1))
00447 deadly_error(WHERE, func, "did not work");
00448 #ifdef DEBUG_STRING_TEST
00449 out.log("compares okay");
00450 #endif
00451 }
00452
00453 void run_test_11()
00454 {
00455 FUNCDEF("run_test_11");
00456 istring empty;
00457 if (empty.length())
00458 deadly_error(WHERE, func, "empty string judged not");
00459 if (! (!empty.length()) )
00460 deadly_error(WHERE, func, "not on empty string doesn't work");
00461 istring non_empty("grungee");
00462 if (!non_empty.length())
00463 deadly_error(WHERE, func, "non-empty string judged empty");
00464 if (! (! (!non_empty.length()) ) )
00465 deadly_error(WHERE, func, "not on non-empty string doesn't work");
00466 }
00467
00468 void run_test_12()
00469 {
00470 FUNCDEF("run_test_12");
00471 istring elf0(istring::SPRINTF, "%%_%%_%%");
00472 if (strcmp(elf0.s(), "%_%_%"))
00473 deadly_error(WHERE, func, "failed %% printing");
00474
00475 char fred[6] = { 'h', 'y', 'a', 'r', 'g', '\0' };
00476 istring fred_copy(istring::UNTERMINATED, fred, 5);
00477 if (fred_copy.length() != 5)
00478 deadly_error(WHERE, func, "length of copy is wrong");
00479 if (fred_copy != istring("hyarg"))
00480 deadly_error(WHERE, func, "length of copy is wrong");
00481
00482 char hugh[6] = { 'o', 'y', 'o', 'b', 'o', 'y' };
00483 istring hugh_copy(istring::UNTERMINATED, hugh, 3);
00484 if (hugh_copy.length() != 3)
00485 deadly_error(WHERE, func, "length of copy is wrong");
00486 if (hugh_copy != istring("oyo"))
00487 deadly_error(WHERE, func, "length of copy is wrong");
00488
00489 istring another_copy;
00490 another_copy.reset(istring::UNTERMINATED, fred, strlen(fred));
00491 if (another_copy.length() != 5)
00492 deadly_error(WHERE, func, "length of reset copy is wrong");
00493 if (another_copy != istring("hyarg"))
00494 deadly_error(WHERE, func, "length of reset copy is wrong");
00495 }
00496
00497 void run_test_13()
00498 {
00499 FUNCDEF("run_test_13");
00500
00501 const istring churg("borjh sjh oiweoklj");
00502 istring pud = churg;
00503 istring flug = "kase iqk aksjir kljasdo";
00504 const char *nerf = "ausd qwoeui sof zjh qwei";
00505 istring snorp = nerf;
00506 pud = "snugbo";
00507 snorp = flug;
00508 istring pundit("murph");
00509 pundit = nerf;
00510 }
00511
00512 void run_test_14()
00513 {
00514 FUNCDEF("run_test_14");
00515
00516 const int longish_size = 5000;
00517 char temp[longish_size];
00518 for (int i = 0; i < longish_size; i++)
00519 temp[i] = char(rando.inclusive(1, 255));
00520 temp[longish_size - 1] = '\0';
00521 istring longish(istring::SPRINTF, "this is a really darned long string of stuff: %s,\nbut doesn't it look interesting?", temp);
00522
00523 longish.zap(longish.length() / 3, 2 * longish.length() / 3);
00524 longish += longish;
00525 if (longish.length() != int(strlen(longish.s())))
00526 deadly_error(WHERE, func, "length is incorrect.");
00527 }
00528
00529 void run_test_15()
00530 {
00531 FUNCDEF("run_test_15");
00532
00533 int try_1 = 32767;
00534 istring testy(istring::SPRINTF, "%d", try_1);
00535 if (testy.convert(95) == 95)
00536 deadly_error(WHERE, func, "default value returned, so it failed.");
00537 else if (testy.convert(95) != try_1)
00538 deadly_error(WHERE, func, "correct value was not returned.");
00539
00540 long try_2 = 2938754L;
00541 testy = istring(istring::SPRINTF, "%ld", try_2);
00542 if (testy.convert(98L) == 98L)
00543 deadly_error(WHERE, func, "default value returned, so it failed.");
00544 else if (testy.convert(98L) != try_2)
00545 deadly_error(WHERE, func, "correct value was not returned.");
00546
00547 testy = istring(istring::SPRINTF, "%ld", try_2);
00548 if (testy.convert(98L) == 98L)
00549 deadly_error(WHERE, func, "default value returned, so it failed.");
00550 else if (testy.convert(98L) != try_2)
00551 deadly_error(WHERE, func, "correct value was not returned.");
00552
00553 #ifndef EMBEDDED_BUILD // until float support added in (blocked out 3/8/96).
00554 float try_3 = float(2938.754);
00555 testy = istring(istring::SPRINTF, "%f", try_3);
00556 float found = testy.convert(float(98.6));
00557 if (found == 98.6)
00558 deadly_error(WHERE, func, "default value returned, so it failed.");
00559 else if (found != try_3)
00560 deadly_error(WHERE, func, "correct value was not returned.");
00561
00562 {
00563 double try_4 = 25598437.712385;
00564 testy = istring(istring::SPRINTF, "%f", try_4);
00565 double found2 = testy.convert(double(98.6));
00566 if (found2 == 98.6)
00567 deadly_error(WHERE, func, "default value returned, so it failed.");
00568 else if (found2 != try_4)
00569 deadly_error(WHERE, func, "correct value was not returned.");
00570 }
00571
00572 {
00573 double try_4 = 25598437.712385e38;
00574 testy = istring(istring::SPRINTF, "%f", try_4);
00575 double found2 = testy.convert(double(98.6));
00576 if (found2 == 98.6)
00577 deadly_error(WHERE, func, "default value returned, so it failed.");
00578 else if (found2 != try_4)
00579 deadly_error(WHERE, func, "correct value was not returned.");
00580 }
00581 #endif
00582 }
00583
00584 void run_test_16()
00585 {
00586 FUNCDEF("run_test_16");
00587
00588 istring gorf("abc");
00589 for (int i = -3; i < 25; i++) gorf[i] = 't';
00590 if (gorf != istring("ttt"))
00591 deadly_error(WHERE, func, "correct value was not returned (a).");
00592 if (gorf.length() != 3)
00593 deadly_error(WHERE, func, "length is incorrect (a).");
00594 gorf.insert(3, istring("bru"));
00595 if (gorf != istring("tttbru"))
00596 deadly_error(WHERE, func, "correct value was not returned (b).");
00597 if (gorf.length() != 6)
00598 deadly_error(WHERE, func, "length is incorrect (b).");
00599 gorf.insert(35, istring("snu"));
00600 if (gorf != istring("tttbru"))
00601 deadly_error(WHERE, func, "correct value was not returned (c).");
00602 if (gorf.length() != 6)
00603 deadly_error(WHERE, func, "length is incorrect (c).");
00604 gorf.insert(-30, istring("eep"));
00605 if (gorf != istring("tttbru"))
00606 deadly_error(WHERE, func, "correct value was not returned (d).");
00607 if (gorf.length() != 6)
00608 deadly_error(WHERE, func, "length is incorrect (d).");
00609 }
00610
00611 void run_test_17()
00612 {
00613 FUNCDEF("run_test_17");
00614
00615
00616
00617 istring("jubjo");
00618 istring("obo");
00619 istring("flrrpominort").substring(3, 6);
00620 }
00621
00622 void run_test_18()
00623 {
00624 FUNCDEF("run_test_18");
00625
00626 #ifdef AFXDLL
00627 AfxSetResourceHandle(GET_INSTANCE_HANDLE());
00628
00629
00630
00631 istring libname = rc_string(IDS_BASIS_NAME);
00632 if (libname != istring("Basis Library"))
00633 deadly_error(WHERE, func,
00634 (istring("library name is a mismatch: comes out as \"")
00635 + libname + istring("\".")).s());
00636 #define IDS_SOME_BAD_UNKNOWN_STRING_HANDLE 30802
00637 istring bogus_name = rc_string(IDS_SOME_BAD_UNKNOWN_STRING_HANDLE);
00638 if (bogus_name.length())
00639 deadly_error(WHERE, func, "bogus rc string had length");
00640
00641
00642 istring george("yo yo yo");
00643 CString hal = convert(george);
00644 istring borgia = convert(hal);
00645
00646 #ifdef DEBUG_STRING_TEST
00647 out.log(istring("cstringy conversions: ") + george);
00648 out.log((const char *)hal);
00649 out.log(borgia);
00650 #endif
00651
00652 if (borgia != george)
00653 deadly_error(WHERE, func, "got the wrong value");
00654 #endif
00655 }
00656
00657 void run_test_19()
00658 {
00659 FUNCDEF("run_test_19");
00660
00661 istring problematic_example(istring::SPRINTF, "this should have %d% more "
00662 "stuffing than before!", 20);
00663
00664 if (problematic_example != istring("this should have 20% more stuffing than before!"))
00665 deadly_error(WHERE, func, "failure to print correct phrase");
00666 }
00667
00668 void run_test_20()
00669 {
00670 FUNCDEF("run_test_20");
00671
00672
00673
00674 char myText[] = "OK";
00675 istring myString(istring::SPRINTF, "%04s", myText);
00676 #ifdef DEBUG_STRING_TEST
00677 out.log(istring("first try gets: ") + myString);
00678 #endif
00679
00680 char myText8[] = "OK";
00681 char my_text_4[90];
00682 sprintf(my_text_4, "%4s", myText8);
00683 #ifdef DEBUG_STRING_TEST
00684 out.log(istring("second try gets: ") + istring(my_text_4));
00685 #endif
00686
00687 #ifndef EMBEDDED_BUILD
00688
00689
00690 char myText2[] = "OK";
00691 char myText3[50];
00692 sprintf(myText3, "%4s", myText2);
00693 istring myString2(myText3);
00694 #ifdef DEBUG_STRING_TEST
00695 out.log(istring("third try gets: ") + myString2);
00696 #endif
00697 #endif // firmware.
00698 }
00699
00700 void run_test_21()
00701 {
00702 FUNCDEF("run_test_21");
00703
00704 istring spacey(" dufunk ");
00705 istring temp = spacey;
00706 temp.strip_spaces(istring::FROM_FRONT);
00707 if (temp != istring("dufunk "))
00708 deadly_error(WHERE, func, "created wrong string");
00709 temp = spacey;
00710 temp.strip_spaces(istring::FROM_END);
00711 if (temp != istring(" dufunk"))
00712 deadly_error(WHERE, func, "created wrong string");
00713 temp = spacey;
00714 temp.strip_spaces(istring::FROM_BOTH_SIDES);
00715 if (temp != istring("dufunk"))
00716 deadly_error(WHERE, func, "created wrong string");
00717
00718 istring placemat("mary had a red hooded cobra she kept around her neck "
00719 "and it hissed at the people as they walked by her tent.");
00720 if (!placemat.replace("had", "bought"))
00721 deadly_error(WHERE, func, "replace failed");
00722 if (placemat.replace("hoded", "bought"))
00723 deadly_error(WHERE, func, "replace didn't fail but should have");
00724 if (!placemat.replace("she", "funkateria"))
00725 deadly_error(WHERE, func, "replace failed");
00726 if (!placemat.replace("hooded", "hood"))
00727 deadly_error(WHERE, func, "replace failed");
00728 if (!placemat.replace("cobra", "in the"))
00729 deadly_error(WHERE, func, "replace failed");
00730
00731 int indy = placemat.find("kept");
00732 if (negative(indy))
00733 deadly_error(WHERE, func, "couldn't find string");
00734 placemat[indy - 1] = '.';
00735 placemat.zap(indy, placemat.end());
00736 if (placemat != istring("mary bought a red hood in the funkateria."))
00737 deadly_error(WHERE, func, "got wrong result string");
00738 }
00739
00740 void run_test_22()
00741 {
00742 FUNCDEF("run_test_22");
00743
00744 istring B("buzz*buzz*");
00745 {
00746 int x = B.find('*');
00747 if (x != 4)
00748 deadly_error(WHERE, func, "got wrong index for first");
00749 x++;
00750 x = B.find('*', x);
00751 if (x != 9)
00752 deadly_error(WHERE, func, "got wrong index for second");
00753 x++;
00754 x = B.find('*', x);
00755
00756
00757 if (x > 0)
00758 deadly_error(WHERE, func, "got wrong outcome for third");
00759 }
00760 {
00761 int x = B.find("z*");
00762 if (x != 3)
00763 deadly_error(WHERE, func, "got wrong index for fourth");
00764 x++;
00765 x = B.find("z*", x);
00766 if (x != 8)
00767 deadly_error(WHERE, func, "got wrong index for fifth");
00768 x++;
00769 x = B.find("z*", x);
00770
00771
00772 if (x > 0)
00773 deadly_error(WHERE, func, "got wrong outcome for sixth");
00774 }
00775
00776 }
00777
00778 void run_test_23()
00779 {
00780 FUNCDEF("run_test_23");
00781
00782 istring strip_string("!@#$%^&*()");
00783
00784 istring no_stripper("this shouldn't change");
00785 no_stripper.strip(strip_string, istring::FROM_BOTH_SIDES);
00786 if (no_stripper != istring("this shouldn't change"))
00787 deadly_error(WHERE, func, "first test failed comparison");
00788
00789 istring strippee_orig("&$(*(@&@*()()!()@*(@(*fudge#((@(*@**#)(@#)(#");
00790 istring strippee(strippee_orig);
00791 strippee.strip(strip_string, istring::FROM_BOTH_SIDES);
00792 if (strippee != istring("fudge"))
00793 deadly_error(WHERE, func, "second test failed comparison");
00794
00795 strippee = strippee_orig;
00796 strippee.strip(strip_string, istring::FROM_FRONT);
00797 if (strippee != istring("fudge#((@(*@**#)(@#)(#"))
00798 deadly_error(WHERE, func, "third test failed comparison");
00799
00800 strippee = strippee_orig;
00801 strippee.strip(strip_string, istring::FROM_END);
00802 if (strippee != istring("&$(*(@&@*()()!()@*(@(*fudge"))
00803 deadly_error(WHERE, func, "fourth test failed comparison");
00804 }
00805
00806 void run_test_24()
00807 {
00808 FUNCDEF("run_test_24");
00809 #ifdef __WIN32__
00810
00811 _bstr_t beast("abcdefgh");
00812 #ifdef DEBUG_STRING_TEST
00813 out.log(istring("the beast is ") + beast.operator char *() +
00814 istring(istring::SPRINTF, " with length %d", beast.length()));
00815 #endif
00816 istring convert = beast;
00817 #ifdef DEBUG_STRING_TEST
00818 out.log(istring("the convert is ") + convert
00819 + istring(istring::SPRINTF, " with length %d", convert.length()));
00820 #endif
00821 if (convert != "abcdefgh")
00822 deadly_error(WHERE, func, "first test failed comparison");
00823
00824 istring jethro("i want a hog sandwich");
00825 _bstr_t pork = string_convert::to_bstr_t(jethro);
00826 if (strcmp(pork.operator char *(), jethro.s()))
00827 deadly_error(WHERE, func, "second test failed comparison");
00828 #endif
00829 }
00830
00831 void run_test_25()
00832 {
00833 FUNCDEF("run_test_25");
00834
00835 istring fred = "asdoiuaoisud";
00836 if (fred != "") {}
00837 else
00838 deadly_error(WHERE, func, "first test failed comparison");
00839 istring bub = fred;
00840 if (fred != bub)
00841 deadly_error(WHERE, func, "second test failed comparison");
00842 fred = "";
00843 if (fred != "")
00844 deadly_error(WHERE, func, "third test failed comparison");
00845 else if (fred.length())
00846 deadly_error(WHERE, func, "fourth test failed comparison");
00847 }
00848
00849 void run_test_26()
00850 {
00851 FUNCDEF("run_test_26");
00852
00853
00854 istring t1 = timestamp(false, false);
00855 istring t2 = timestamp(false, true);
00856 istring t3 = timestamp(true, false);
00857 istring t4 = timestamp(true, true);
00858 }
00859
00860 void run_test_27()
00861 {
00862 FUNCDEF("run_test_27");
00863
00864
00865 earth_time::day_in_year d1 = date_now();
00866 earth_time::clock_time t1 = time_now();
00867 earth_time::time_locus dt1 = now();
00868 istring sd1 = d1.text_form();
00869 istring st1 = t1.text_form();
00870 istring sdt1 = dt1.text_form();
00871 }
00872
00873 void run_test_28()
00874 {
00875 FUNCDEF("run_test_28");
00876
00877 u_int in1 = 27;
00878 u_short in2 = 39;
00879 char in3 = 'Q';
00880 istring testy(istring::SPRINTF, "%u:%hu:%c", in1, in2, in3);
00881 if (testy != "27:39:Q")
00882 deadly_error(WHERE, func, "fourth test failed comparison");
00883 }
00884
00885 void run_test_29()
00886 {
00887 FUNCDEF("run_test_29");
00888
00889 istring a("would an onion smell so sweet?");
00890 byte_array p1;
00891 a.pack(p1);
00892 istring b;
00893 if (!b.unpack(p1))
00894 deadly_error(WHERE, func, "first unpack failed");
00895 if (b != a)
00896 deadly_error(WHERE, func, "first comparison failed");
00897 a = "128 salamanders cannot be wrong.";
00898 a.pack(p1);
00899 if (!b.unpack(p1))
00900 deadly_error(WHERE, func, "second unpack failed");
00901 if (b != a)
00902 deadly_error(WHERE, func, "second comparison failed");
00903 }
00904
00905 void standard_sprintf_test(const char *parm_string)
00906 {
00907 FUNCDEF("standard_sprintf_test");
00908 istring print_into(' ', 20000);
00909 print_into[0] = '\0';
00910 sprintf(print_into.s(), "%d %ld %u %hu %s", int(rando.inclusive(0, 23945)),
00911 long(rando.inclusive(-2394, 2998238)), u_int(rando.inclusive(0, 124395)),
00912 u_short(rando.inclusive(0, 65535)), parm_string);
00913 sprintf(print_into.s(), "%c %d %c %s %s %lu", char(rando.inclusive('a', 'z')),
00914 int(rando.inclusive(0, 23945)), char(rando.inclusive('A', 'Z')),
00915 parm_string, parm_string, u_long(rando.inclusive(0, 2998238)));
00916 }
00917
00918 void istring_sprintf_test(const char *parm_string)
00919 {
00920 FUNCDEF("istring_sprintf_test");
00921 istring print_into(' ', 20000);
00922 print_into[0] = '\0';
00923 print_into.sprintf("%d %ld %u %hu %s", int(rando.inclusive(0, 23945)),
00924 long(rando.inclusive(-2394, 2998238)), u_int(rando.inclusive(0, 124395)),
00925 u_short(rando.inclusive(0, 65535)), parm_string);
00926 print_into.sprintf("%c %d %c %s %s %lu", char(rando.inclusive('a', 'z')),
00927 int(rando.inclusive(0, 23945)), char(rando.inclusive('A', 'Z')),
00928 parm_string, parm_string, u_long(rando.inclusive(0, 2998238)));
00929 }
00930
00931 void run_test_30()
00932 {
00933 FUNCDEF("run_test_30");
00934
00935
00936 istring parm_string = string_manipulation::make_random_name(40, 140);
00937 time_stamp start;
00938 const int iterations = 3000;
00939 for (int i = 0; i < iterations; i++)
00940 standard_sprintf_test(parm_string.s());
00941 double standard_took = time_stamp().value() - start.value();
00942 start.reset();
00943 for (int j = 0; j < iterations; j++)
00944 istring_sprintf_test(parm_string.s());
00945 double istring_took = time_stamp().value() - start.value();
00946 #ifdef DEBUG_STRING_TEST
00947 out.log(istring(istring::SPRINTF, "the standard sprintf took %f ms "
00948 "while the istring sprintf took %f", standard_took, istring_took));
00949 #endif
00950
00951 float ratio = float(istring_took) / float(standard_took);
00952
00953 out.log(istring(istring::SPRINTF, "istring was %03.3f%% slower "
00954 "than standard.", ratio * 100.0));
00955
00956
00957 if (istring_took <= standard_took) {
00958 out.log("istring was faster or equal to sprintf.");
00959 } else {
00960
00961 if (ratio >= .50)
00962 out.log(istring(istring::SPRINTF, "istring took way too much longer "
00963 "than sprintf: ratio was %f.", ratio));
00964 }
00965 }
00966
00967 void run_test_31()
00968 {
00969 FUNCDEF("run_test_31");
00970
00971 istring dashes('-', 20);
00972 istring non_plusses('+', 0);
00973 istring plusses('+', 1);
00974 if (dashes.length() != 20)
00975 deadly_error(WHERE, func, istring("dashes has wrong length!"));
00976 if (dashes != istring("--------------------"))
00977 deadly_error(WHERE, func, istring("dashes has wrong contents!"));
00978 if (non_plusses.length())
00979 deadly_error(WHERE, func, istring("non_plusses has wrong length!"));
00980 if (plusses.length() != 1)
00981 deadly_error(WHERE, func, istring("plusses has wrong length!"));
00982 if (plusses != istring("+"))
00983 deadly_error(WHERE, func, istring("plusses has wrong contents!"));
00984 if (plusses != istring('+', 1))
00985 deadly_error(WHERE, func, istring("plusses second compare failed!"));
00986 }
00987
00988 void run_test_32()
00989 {
00990 FUNCDEF("run_test_32");
00991
00992
00993 const int CHUNK_SIZE = 2 * MEGABYTE;
00994
00995
00996 const int MIN_ADDITION = 10000; const int MAX_ADDITION = 80000;
00997
00998 const int BUILD_AND_BURN_ITERATIONS = 7;
00999
01000
01001
01002 istring slab;
01003
01004
01005
01006
01007 for (int iters = 0; iters < BUILD_AND_BURN_ITERATIONS; iters++) {
01008
01009 int size = 0;
01010
01011
01012 while (slab.length() < CHUNK_SIZE - MAX_ADDITION - 20) {
01013
01014 istring addition = string_manipulation::make_random_name(MIN_ADDITION,
01015 MAX_ADDITION);
01016 slab += addition;
01017 size += addition.length();
01018 if (size != slab.length())
01019 deadly_error(WHERE, func, istring("size is incorrect after add!"));
01020 }
01021
01022
01023 while (slab.length()) {
01024
01025 int zap_start = rando.inclusive(0, slab.end());
01026 int zap_end = rando.inclusive(0, slab.end());
01027 flip_increasing(zap_start, zap_end);
01028 int range_length = zap_end - zap_start + 1;
01029 if (negative(range_length))
01030 deadly_error(WHERE, func, istring("flip_increasing failed!"));
01031 slab.zap(zap_start, zap_end);
01032 size -= range_length;
01033 if (size != slab.length())
01034 deadly_error(WHERE, func, istring("size is incorrect after zap!"));
01035 }
01036 }
01037 }
01038
01039 void run_test_33()
01040 {
01041 FUNCDEF("run_test_33");
01042
01043 {
01044 istring to_modify("\\\\feeby\\path\\yo");
01045 if (!to_modify.replace("\\", "/"))
01046 deadly_error(WHERE, func, "failed to replace the string");
01047 if (to_modify != "/\\feeby\\path\\yo")
01048 deadly_error(WHERE, func, "produced wrong resultant string");
01049 while (to_modify.replace("\\", "/")) {}
01050 if (to_modify != "//feeby/path/yo")
01051 deadly_error(WHERE, func, "produced wrong final string");
01052 }
01053 {
01054 istring to_modify("\\superduper\\dynamo\\looper");
01055 if (!to_modify.replace("\\", "/"))
01056 deadly_error(WHERE, func, "failed to replace the string");
01057 if (to_modify != istring("/superduper\\dynamo\\looper"))
01058 deadly_error(WHERE, func, "produced wrong resultant string");
01059 while (to_modify.replace("\\", "/")) {}
01060 if (to_modify != "/superduper/dynamo/looper")
01061 deadly_error(WHERE, func, "produced wrong final string");
01062 }
01063 {
01064 istring id = "/SRV=1/SRC=1";
01065 istring id1 = id;
01066 while (id1.replace("/", " ")) {}
01067
01068
01069 if (id1 != " SRV=1 SRC=1")
01070 deadly_error(WHERE, func, "produced wrong final string");
01071
01072 istring id2 = id;
01073 while (id2.replace("=", ":")) {}
01074
01075
01076 if (id2 != "/SRV:1/SRC:1")
01077 deadly_error(WHERE, func, "produced wrong final string");
01078 }
01079 }
01080
01081 void run_test_34()
01082 {
01083 FUNCDEF("run_test_34");
01084
01085
01086
01087
01088 {
01089
01090
01091
01092
01093 const char *hebba1 = "hebba heeba hoobalah beeb";
01094 const char *hebba2 = "hebba heeba hoobalah beeba";
01095
01096 if (istring::slow_strncasecmp(hebba1, hebba2) >= 0)
01097 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01098 if (istring::slow_strncasecmp(hebba2, hebba1) <= 0)
01099 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01100 const char *hebba3 = "hebba heeba hoobalah beeba";
01101 if (istring::slow_strncasecmp(hebba3, hebba2) != 0)
01102 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01103 if (istring::slow_strncasecmp(hebba2, hebba3) != 0)
01104 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01105 const char *hebba4 = "hebba heeba hoobalah beea";
01106 if (istring::slow_strncasecmp(hebba4, hebba1) >= 0)
01107 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01108 if (istring::slow_strncasecmp(hebba1, hebba4) <= 0)
01109 deadly_error(WHERE, func, "A: slow_strncasecmp was incorrect");
01110
01111
01112 istring ends_pat1 = "crungohila.exe";
01113 istring ends_mat1 = ".exe";
01114 if (!ends_pat1.ends(ends_mat1))
01115 deadly_error(WHERE, func, "A: ends was incorrect");
01116 istring ends_pat2 = "link_parser.obj";
01117 istring ends_mat2 = ".res";
01118 if (ends_pat2.ends(ends_mat2))
01119 deadly_error(WHERE, func, "B: ends was incorrect");
01120 istring begins_pat1 = "fudzolioc";
01121 istring begins_mat1 = "fudz";
01122 if (!begins_pat1.begins(begins_mat1))
01123 deadly_error(WHERE, func, "begins was incorrect");
01124
01125
01126 istring iends_pat1 = "cruNgoHila.Exe";
01127 istring iends_mat1 = ".eXE";
01128 if (!iends_pat1.iends(iends_mat1))
01129 deadly_error(WHERE, func, "A: iends was incorrect");
01130 istring iends_pat2 = "link_paRser.Obj";
01131 istring iends_mat2 = ".rEs";
01132 if (iends_pat2.ibegins(iends_mat2))
01133 deadly_error(WHERE, func, "B: iends was incorrect");
01134 istring ibegins_pat1 = "fuDZoliOc";
01135 istring ibegins_mat1 = "fudz";
01136 if (!ibegins_pat1.ibegins(ibegins_mat1))
01137 deadly_error(WHERE, func, "ibegins was incorrect");
01138
01139
01140 array<istring> strings;
01141 const int MAX_NAMES = 100;
01142 for (int i = 0; i < MAX_NAMES; i++)
01143 strings += string_manipulation::make_random_name();
01144 const int MAX_TESTS = 400;
01145 for (int j = 0; j < MAX_TESTS; j++) {
01146 int str1 = rando.inclusive(0, MAX_NAMES - 1);
01147 int str2 = rando.inclusive(0, MAX_NAMES - 1);
01148 int result1 = istring::slow_strncasecmp(strings[str1].s(), strings[str2].s());
01149 if (result1)
01150 result1 = result1 / absolute_value(result1);
01151 istring s1 = strings[str1].lower();
01152 istring s2 = strings[str2].lower();
01153 int result2 = strcmp(s1.s(), s2.s());
01154 if (result2)
01155 result2 = result2 / absolute_value(result2);
01156 if (result1 != result2)
01157 deadly_error(WHERE, func,
01158 istring(istring::SPRINTF, "slow_strncasecmp was different "
01159 "from strcmp:\r\n"
01160 "the first was %s, second was %s, res1=%d, res2=%d",
01161 s1.s(), s2.s(), result1, result2));
01162 }
01163 }
01164 }
01165
01166 void run_test_35()
01167 {
01168 FUNCDEF("run_test_35");
01169
01170 istring termo('R', 2812);
01171 termo[1008] = '\0';
01172 termo.shrink();
01173 if (termo.get_implem().internal_real_length() != 1010)
01174 deadly_error(WHERE, func, isprintf("failure in shrunken size: "
01175 "wanted 1010 and got %d.", termo.get_implem().internal_real_length()));
01176 istring termo2('R', 1008);
01177 if (termo != termo2)
01178 deadly_error(WHERE, func, "wrong value produced");
01179 }
01180
01181 void run_test_36()
01182 {
01183 FUNCDEF("run_test_36");
01184
01185
01186 string_array torpid;
01187 torpid += "york";
01188 torpid += "burger";
01189 torpid += "petunia";
01190 torpid += "dumptruck";
01191 if (torpid.text_form() != "\"york\",\"burger\",\"petunia\",\"dumptruck\"")
01192 deadly_error(WHERE, func, "wrong value computed");
01193 string_array sacral;
01194 sacral += "gumboat";
01195 if (sacral.text_form() != "\"gumboat\"")
01196 deadly_error(WHERE, func, "wrong value computed");
01197
01198 string_array paknid;
01199 paknid += "gorboochy";
01200 paknid += "rangolent";
01201 byte_array packed;
01202 basis::pack(packed, paknid);
01203
01204 string_array upnort;
01205 if (!basis::unpack(packed, upnort))
01206 deadly_error(WHERE, func, "failed to unpack");
01207 if (packed.length())
01208 deadly_error(WHERE, func, "array still has bytes!");
01209
01210 string_array stongent;
01211 stongent += "pemulack";
01212 stongent += "bluzzent";
01213 stongent += "crupto";
01214 stongent += "floonack";
01215 stongent += "atoona";
01216 packed.reset();
01217 basis::pack(packed, stongent);
01218
01219 string_array belzorp;
01220 if (!basis::unpack(packed, belzorp))
01221 deadly_error(WHERE, func, "failed to unpack");
01222 if (packed.length())
01223 deadly_error(WHERE, func, "array still has bytes!");
01224 }
01225
01226 void run_test_37()
01227 {
01228 FUNCDEF("run_test_37");
01229
01230
01231 istring a("would an onion smell so sweet?");
01232 byte_array p1;
01233 a.pack(p1);
01234 istring b;
01235 if (!b.unpack(p1))
01236 deadly_error(WHERE, func, "first unpack failed");
01237 if (b != a)
01238 deadly_error(WHERE, func, "first comparison failed");
01239 a = "128 salamanders cannot be wrong.";
01240 a.pack(p1);
01241 if (!b.unpack(p1))
01242 deadly_error(WHERE, func, "second unpack failed");
01243 if (b != a)
01244 deadly_error(WHERE, func, "second comparison failed");
01245 }
01246
01247 void run_test_38()
01248 {
01249 FUNCDEF("run_test_38");
01250 double to_print = 2.345;
01251 isprintf non_deadly("%.1f", to_print);
01253
01254 to_print = 1.797E+254;
01255
01256
01257 char bucket[2000];
01258 bucket[0] = '\0';
01259 sprintf(bucket, "%.1f", to_print);
01261
01262 isprintf deadly("%.1f", to_print);
01264 }
01265
01266 void run_test_39()
01267 {
01268 FUNCDEF("run_test_39");
01269 istring find_set = "!?.;";
01270 istring test_1 = "how do i get to balthazar square? it stinks!";
01271 if (test_1.find_any(find_set) != 32)
01272 deadly_error(WHERE, func, "first find returned wrong result");
01273 if (test_1.find_any(find_set, 33) != 44)
01274 deadly_error(WHERE, func, "second find returned wrong result");
01275 if (test_1.find_any(find_set, 40, true) != 32)
01276 deadly_error(WHERE, func, "third find returned wrong result");
01277 }
01278
01279 void run_test_40()
01280 {
01281 FUNCDEF("run_test_40");
01282 int test_num = 1;
01283 #define test_name() isprintf("test %d: ", test_num)
01284 {
01285 istring target = "xabab";
01286 istring from = "ab";
01287 istring to = "dc";
01288 if (!target.replace_all(from, to))
01289 deadly_error(WHERE, func, test_name() + "didn't find from string");
01290 if (target != "xdcdc")
01291 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01292 test_num++;
01293 }
01294 {
01295 istring target = "xabab";
01296 istring from = "ab";
01297 istring to = "ab";
01298 if (!target.replace_all(from, to))
01299 deadly_error(WHERE, func, test_name() + "didn't find from string");
01300 if (target != "xabab")
01301 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01302 test_num++;
01303 }
01304 {
01305 istring target = "xabab";
01306 istring from = "ab";
01307 istring to = "a";
01308 if (!target.replace_all(from, to))
01309 deadly_error(WHERE, func, test_name() + "didn't find from string");
01310 if (target != "xaa")
01311 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01312 test_num++;
01313 }
01314 {
01315 istring target = "ababx";
01316 istring from = "ab";
01317 istring to = "a";
01318 if (!target.replace_all(from, to))
01319 deadly_error(WHERE, func, test_name() + "didn't find from string");
01320 if (target != "aax")
01321 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01322 test_num++;
01323 }
01324 {
01325 istring target = "suzzle rumpetzzes gnargle rezztor";
01326 istring from = "zz";
01327 istring to = "zzz";
01328 if (!target.replace_all(from, to))
01329 deadly_error(WHERE, func, test_name() + "didn't find from string");
01330 if (target != "suzzzle rumpetzzzes gnargle rezzztor")
01331 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01332 test_num++;
01333 }
01334 {
01335 istring target = "qqqq";
01336 istring from = "q";
01337 istring to = "qqq";
01338 if (!target.replace_all(from, to))
01339 deadly_error(WHERE, func, test_name() + "didn't find from string");
01340 if (target != "qqqqqqqqqqqq")
01341 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01342 test_num++;
01343 }
01344 {
01345 istring target = "glorg snorp pendle funk";
01346 istring from = " ";
01347 istring to = "";
01348 if (!target.replace_all(from, to))
01349 deadly_error(WHERE, func, test_name() + "didn't find from string");
01350 if (target != "glorgsnorppendlefunk")
01351 deadly_error(WHERE, func, test_name() + "didn't replace properly");
01352 test_num++;
01353 }
01354 }
01355
01356 void run_test_41()
01357 {
01358 FUNCDEF("run_test_41");
01359 int test_num = 0;
01360 #define test_name() isprintf("test %d: ", test_num)
01361 {
01362 test_num++;
01363 istring target = "xabab";
01364 istring finding1 = "ab";
01365 if (target.find_non_match(finding1, 0, false) != 0)
01366 deadly_error(WHERE, func, test_name() + "didn't find right location A");
01367 istring finding2 = "xb";
01368 if (target.find_non_match(finding2, target.length() - 1, true) != 3)
01369 deadly_error(WHERE, func, test_name() + "didn't find right location B");
01370 istring finding3 = "c";
01371 if (target.find_non_match(finding3, 0, false) != 0)
01372 deadly_error(WHERE, func, test_name() + "wrong answer for test C");
01373 if (target.find_non_match(finding3, target.length() - 1, true)
01374 != target.length() - 1)
01375 deadly_error(WHERE, func, test_name() + "wrong answer for test D");
01376 }
01377 {
01378 test_num++;
01379 istring target = "abcadefghoota";
01380 istring finding1 = "bcdfghot";
01381 if (target.find_non_match(finding1, 0, false) != 0)
01382 deadly_error(WHERE, func, test_name() + "didn't find right location A");
01383 if (target.find_non_match(finding1, 1, false) != 3)
01384 deadly_error(WHERE, func, test_name() + "didn't find right location B");
01385 if (target.find_non_match(finding1, target.length() - 1, true)
01386 != target.length() - 1)
01387 deadly_error(WHERE, func, test_name() + "didn't find right location C");
01388 if (target.find_non_match(finding1, target.length() - 2, true) != 5)
01389 deadly_error(WHERE, func, test_name() + "didn't find right location D");
01390 if (target.find_non_match(finding1, 3, false) != 3)
01391 deadly_error(WHERE, func, test_name() + "didn't find right location E");
01392 if (target.find_non_match(finding1, 4, false) != 5)
01393 deadly_error(WHERE, func, test_name() + "didn't find right location F");
01394
01395 }
01396
01397
01398 }
01399
01400 int main(int formal(argc), char *formal(argv)[])
01401 {
01402 FUNCDEF("main");
01403 SET_DEFAULT_COMBO_LOGGER;
01404
01405 if (staticity_test != istring("yo!"))
01406 deadly_error(WHERE, func, "wrong contents");
01407
01408 time_stamp end_time(TEST_RUNTIME_DEFAULT);
01409
01410
01411 int i = 0;
01412 while (time_stamp() < end_time) {
01413
01414 i++;
01415 #ifdef DEBUG_STRING_TEST
01416 out.log(istring(istring::SPRINTF, "index %d", i));
01417 #endif
01418
01419
01420 run_test_41();
01421
01422
01423 run_test_01(); run_test_02(); run_test_03(); run_test_04(); run_test_05();
01424 run_test_06(); run_test_07(); run_test_08(); run_test_09(); run_test_10();
01425 run_test_11(); run_test_12(); run_test_13(); run_test_14(); run_test_15();
01426 run_test_16(); run_test_17(); run_test_18(); run_test_19(); run_test_20();
01427 run_test_21(); run_test_22(); run_test_23(); run_test_24(); run_test_25();
01428 run_test_26(); run_test_27(); run_test_28(); run_test_29(); run_test_30();
01429 run_test_31(); run_test_32(); run_test_33(); run_test_34(); run_test_35();
01430 run_test_36(); run_test_37(); run_test_38(); run_test_39(); run_test_40();
01431 run_test_41();
01432 }
01433
01434 istring to_print("istring:: works for those functions tested.");
01435 guards::alert_message(to_print.s());
01436 return 0;
01437 }
01438
01439 #undef static_class_name
01440