00001
00034 #include <tut/tut.h>
00035
00036 #include "linden_common.h"
00037 #include "llstreamtools.h"
00038 #include "lltut.h"
00039
00040
00041 namespace tut
00042 {
00043 struct streamtools_data
00044 {
00045 };
00046 typedef test_group<streamtools_data> streamtools_test;
00047 typedef streamtools_test::object streamtools_object;
00048 tut::streamtools_test streamtools_testcase("streamtools");
00049
00050
00051 template<> template<>
00052 void streamtools_object::test<1>()
00053 {
00054 char arr[255];
00055 std::string str;
00056 std::string expected_result;
00057 std::string actual_result;
00058 std::istringstream is;
00059
00060 is.str(str = "");
00061 ensure("skip_whitespace: empty string", (false == skip_whitespace(is)));
00062
00063 is.clear();
00064 is.str(str = " SecondLife is a 3D World");
00065 skip_whitespace(is);
00066 is.get(arr, 255, '\0');
00067 expected_result = "SecondLife is a 3D World";
00068 ensure_equals("skip_whitespace: space", arr, expected_result);
00069
00070 is.clear();
00071 is.str(str = "\t \tSecondLife is a 3D World");
00072 skip_whitespace(is);
00073 is.get(arr, 255, '\0');
00074 expected_result = "SecondLife is a 3D World";
00075 ensure_equals("skip_whitespace: space and tabs", arr, expected_result);
00076
00077 is.clear();
00078 is.str(str = "\t \tSecondLife is a 3D World ");
00079 skip_whitespace(is);
00080 is.get(arr, 255, '\0');
00081 expected_result = "SecondLife is a 3D World ";
00082 ensure_equals("skip_whitespace: space at end", arr, expected_result);
00083
00084 is.clear();
00085 is.str(str = "\t \r\nSecondLife is a 3D World");
00086 skip_whitespace(is);
00087 is.get(arr, 255, '\0');
00088 expected_result = "\r\nSecondLife is a 3D World";
00089 ensure_equals("skip_whitespace: space at end", arr, expected_result);
00090 }
00091
00092
00093 template<> template<>
00094 void streamtools_object::test<2>()
00095 {
00096 char arr[255];
00097 std::string str;
00098 std::string expected_result;
00099 std::string actual_result;
00100 std::istringstream is;
00101 bool ret;
00102
00103 is.clear();
00104 is.str(str = " \tSecondLife is a 3D World.\n");
00105 skip_emptyspace(is);
00106 is.get(arr, 255, '\0');
00107 expected_result = "SecondLife is a 3D World.\n";
00108 ensure_equals("skip_emptyspace: space and tabs", arr, expected_result);
00109
00110 is.clear();
00111 is.str(str = " \t\r\n \r SecondLife is a 3D World.\n");
00112 skip_emptyspace(is);
00113 is.get(arr, 255, '\0');
00114 expected_result = "SecondLife is a 3D World.\n";
00115 ensure_equals("skip_emptyspace: space, tabs, carriage return, newline", arr, expected_result);
00116
00117 is.clear();
00118 is.str(str = "");
00119 ret = skip_emptyspace(is);
00120 is.get(arr, 255, '\0');
00121 ensure("skip_emptyspace: empty string", ret == false);
00122
00123 is.clear();
00124 is.str(str = " \r\n \t ");
00125 ret = skip_emptyspace(is);
00126 is.get(arr, 255, '\0');
00127 ensure("skip_emptyspace: space newline empty", ret == false);
00128 }
00129
00130
00131 template<> template<>
00132 void streamtools_object::test<3>()
00133 {
00134 char arr[255];
00135 std::string str;
00136 std::string expected_result;
00137 std::string actual_result;
00138 std::istringstream is;
00139 bool ret;
00140
00141 is.clear();
00142 is.str(str = " \t\r\n \r SecondLife is a 3D World.\n");
00143 skip_comments_and_emptyspace(is);
00144 is.get(arr, 255, '\0');
00145 expected_result = "SecondLife is a 3D World.\n";
00146 ensure_equals("skip_comments_and_emptyspace: space, tabs, carriage return, newline", arr, expected_result);
00147
00148 is.clear();
00149 is.str(str = "# \r\n SecondLife is a 3D World.");
00150 skip_comments_and_emptyspace(is);
00151 is.get(arr, 255, '\0');
00152 expected_result = "SecondLife is a 3D World.";
00153 ensure_equals("skip_comments_and_emptyspace: skip comment - 1", arr, expected_result);
00154
00155 is.clear();
00156 is.str(str = "# \r\n # SecondLife is a 3D World. ##");
00157 skip_comments_and_emptyspace(is);
00158 is.get(arr, 255, '\0');
00159 expected_result = "";
00160 ensure_equals("skip_comments_and_emptyspace: skip comment - 2", arr, expected_result);
00161
00162 is.clear();
00163 is.str(str = " \r\n SecondLife is a 3D World. ##");
00164 skip_comments_and_emptyspace(is);
00165 is.get(arr, 255, '\0');
00166 expected_result = "SecondLife is a 3D World. ##";
00167 ensure_equals("skip_comments_and_emptyspace: skip comment - 3", arr, expected_result);
00168
00169 is.clear();
00170 is.str(str = "");
00171 ret = skip_comments_and_emptyspace(is);
00172 is.get(arr, 255, '\0');
00173 ensure("skip_comments_and_emptyspace: empty string", ret == false);
00174
00175 is.clear();
00176 is.str(str = " \r\n \t # SecondLife is a 3D World");
00177 ret = skip_comments_and_emptyspace(is);
00178 is.get(arr, 255, '\0');
00179 ensure("skip_comments_and_emptyspace: space newline comment empty", ret == false);
00180 }
00181
00182
00183 template<> template<>
00184 void streamtools_object::test<4>()
00185 {
00186 char arr[255];
00187 std::string str;
00188 std::string expected_result;
00189 std::string actual_result;
00190 std::istringstream is;
00191 bool ret;
00192
00193 is.clear();
00194 is.str(str = "SecondLife is a 3D World.\n\n It provides an opportunity to the site \nuser to perform real life activities in virtual world.");
00195 skip_line(is);
00196 is.get(arr, 255, '\0');
00197 expected_result = "\n It provides an opportunity to the site \nuser to perform real life activities in virtual world.";
00198 ensure_equals("skip_line: 1 newline", arr, expected_result);
00199
00200 is.clear();
00201 is.str(expected_result);
00202 skip_line(is);
00203 is.get(arr, 255, '\0');
00204 expected_result = " It provides an opportunity to the site \nuser to perform real life activities in virtual world.";
00205 ensure_equals("skip_line: 2 newline", arr, expected_result);
00206
00207 is.clear();
00208 is.str(expected_result);
00209 skip_line(is);
00210 is.get(arr, 255, '\0');
00211 expected_result = "user to perform real life activities in virtual world.";
00212 ensure_equals("skip_line: 3 newline", arr, expected_result);
00213
00214 is.clear();
00215 is.str(str = "");
00216 ret = skip_line(is);
00217 ensure("skip_line: empty string", ret == false);
00218 }
00219
00220
00221
00222 template<> template<>
00223 void streamtools_object::test<5>()
00224 {
00225 char arr[255];
00226 std::string str;
00227 std::string expected_result;
00228 std::string actual_result;
00229 std::istringstream is;
00230 bool ret;
00231
00232 is.clear();
00233 is.str(str = "SecondLife is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world.");
00234 skip_to_next_word(is);
00235 is.get(arr, 255, '\0');
00236 expected_result = "is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world.";
00237 ensure_equals("skip_to_next_word: 1", arr, expected_result);
00238
00239 is.clear();
00240 is.str(expected_result);
00241 skip_to_next_word(is);
00242 skip_to_next_word(is);
00243 skip_to_next_word(is);
00244 is.get(arr, 255, '\0');
00245 expected_result = "It-provides an opportunity to the site \nuser to perform real life activities in virtual world.";
00246 ensure_equals("skip_to_next_word: get past .\n\n 2", arr, expected_result);
00247
00248 is.clear();
00249 is.str(expected_result);
00250 skip_to_next_word(is);
00251 expected_result = "provides an opportunity to the site \nuser to perform real life activities in virtual world.";
00252 is.get(arr, 255, '\0');
00253 ensure_equals("skip_to_next_word: get past -", arr, expected_result);
00254
00255 is.clear();
00256 is.str(str = "");
00257 ret = skip_to_next_word(is);
00258 ensure("skip_line: empty string", ret == false);
00259
00260 is.clear();
00261 is.str(str = " \r\n\r\n");
00262 ret = skip_to_next_word(is);
00263 ensure("skip_line: space new lines", ret == false);
00264 }
00265
00266
00267
00268 template<> template<>
00269 void streamtools_object::test<6>()
00270 {
00271 char arr[255];
00272 std::string str;
00273 std::string expected_result;
00274 std::string actual_result;
00275 std::istringstream is;
00276 bool ret;
00277
00278 is.clear();
00279 is.str(str = "FIRSTKEY followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.");
00280 ret = skip_to_end_of_next_keyword("FIRSTKEY", is);
00281 is.get(arr, 255, '\0');
00282 expected_result = " followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
00283 ensure_equals("skip_to_end_of_next_keyword: 1", arr, expected_result);
00284
00285 is.clear();
00286 is.str(expected_result);
00287 ret = skip_to_end_of_next_keyword("SECONDKEY", is);
00288 is.get(arr, 255, '\0');
00289 expected_result = "\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
00290 ensure_equals("skip_to_end_of_next_keyword: 2", arr, expected_result);
00291
00292 is.clear();
00293 is.str(expected_result);
00294 ret = skip_to_end_of_next_keyword("SECONDKEY", is);
00295 is.get(arr, 255, '\0');
00296 expected_result = "\nFOURTHKEY FOURTHVALUEis a 3DWorld.";
00297 ensure_equals("skip_to_end_of_next_keyword: 3", arr, expected_result);
00298
00299 is.clear();
00300 is.str(expected_result);
00301 ret = skip_to_end_of_next_keyword("FOURTHKEY", is);
00302 is.get(arr, 255, '\0');
00303 expected_result = " FOURTHVALUEis a 3DWorld.";
00304 ensure_equals("skip_to_end_of_next_keyword: 4", arr, expected_result);
00305
00306 is.clear();
00307 is.str(str = "{should be skipped as newline/space/tab does not follow but this one should be picked\n { Does it?\n");
00308 ret = skip_to_end_of_next_keyword("{", is);
00309 is.get(arr, 255, '\0');
00310 expected_result = " Does it?\n";
00311 ensure_equals("skip_to_end_of_next_keyword: multiple delim matches on same line", arr, expected_result);
00312
00313 is.clear();
00314 is.str(str = "Delim { could not be found at start");
00315 ret = skip_to_end_of_next_keyword("{", is);
00316 ensure("skip_to_end_of_next_keyword: delim should not be present", ret == false);
00317
00318 is.clear();
00319 is.str(str = "Empty Delim");
00320 ret = skip_to_end_of_next_keyword("", is);
00321 ensure("skip_to_end_of_next_keyword: empty delim should not be valid", ret == false);
00322
00323 is.clear();
00324 is.str(str = "");
00325 ret = skip_to_end_of_next_keyword("}", is);
00326 ensure("skip_to_end_of_next_keyword: empty string", ret == false);
00327 }
00328
00329
00330 template<> template<>
00331 void streamtools_object::test<7>()
00332 {
00333 std::string str;
00334 std::string expected_result;
00335 std::string actual_result;
00336 std::istringstream is;
00337 bool ret;
00338
00339 is.clear();
00340 is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
00341 actual_result = "";
00342 ret = get_word(actual_result, is);
00343 expected_result = "First";
00344 ensure_equals("get_word: 1", actual_result, expected_result);
00345
00346 actual_result = "";
00347 ret = get_word(actual_result, is);
00348 expected_result = "Second";
00349 ensure_equals("get_word: 2", actual_result, expected_result);
00350
00351 actual_result = "";
00352 ret = get_word(actual_result, is);
00353 expected_result = "Third";
00354 ensure_equals("get_word: 3", actual_result, expected_result);
00355
00356
00357
00358
00359
00360
00361
00362 actual_result = "";
00363 ret = get_word(actual_result, is);
00364 expected_result = "Fourth-ShouldThisBePartOfFourth";
00365 ensure_equals("get_word: 4", actual_result, expected_result);
00366
00367 actual_result = "";
00368 ret = get_word(actual_result, is);
00369 expected_result = "Fifth";
00370 ensure_equals("get_word: 5", actual_result, expected_result);
00371
00372 is.clear();
00373 is.str(str = " \t \r \n ");
00374 actual_result = "";
00375 ret = get_word(actual_result, is);
00376 ensure("get_word: empty all spaces, newline tabs", ret == false);
00377
00378 is.clear();
00379 is.str(str = "");
00380 actual_result = "";
00381 ret = get_word(actual_result, is);
00382 ensure("get_word: empty string", ret == false);
00383 }
00384
00385
00386 template<> template<>
00387 void streamtools_object::test<8>()
00388 {
00389 std::string str;
00390 std::string expected_result;
00391 std::string actual_result;
00392 std::istringstream is;
00393 bool ret;
00394
00395 is.clear();
00396 is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
00397 actual_result = "";
00398 ret = get_word(actual_result, is);
00399 actual_result = "";
00400 ret = get_word(actual_result, is);
00401 actual_result = "";
00402 ret = get_word(actual_result, is);
00403
00404
00405
00406
00407
00408
00409
00410 actual_result = "";
00411 ret = get_word(actual_result, is);
00412
00413 actual_result = "";
00414 ret = get_word(actual_result, is);
00415
00416 is.clear();
00417 is.str(str = " First Second \t \r \n Third Fourth_ShouldThisBePartOfFourth Fifth\n");
00418 ret = skip_to_next_word(is);
00419 ret = skip_to_next_word(is);
00420 ret = skip_to_next_word(is);
00421 ret = skip_to_next_word(is);
00422 ret = skip_to_next_word(is);
00423 expected_result = "";
00424
00425
00426 ret = get_word(expected_result, is);
00427 ensure_equals("get_word: skip_to_next_word compatibility", actual_result, expected_result);
00428 }
00429
00430
00431 template<> template<>
00432 void streamtools_object::test<9>()
00433 {
00434 std::string str;
00435 std::string expected_result;
00436 std::string actual_result;
00437 std::istringstream is;
00438 bool ret;
00439
00440 is.clear();
00441 is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n");
00442 actual_result = "";
00443 ret = get_word(actual_result, is, 255);
00444 expected_result = "First";
00445 ensure_equals("get_word: 1", actual_result, expected_result);
00446
00447 actual_result = "";
00448 ret = get_word(actual_result, is, 4);
00449 expected_result = "Seco";
00450 ensure_equals("get_word: 2", actual_result, expected_result);
00451
00452 actual_result = "";
00453 ret = get_word(actual_result, is, 255);
00454 expected_result = "nd";
00455 ensure_equals("get_word: 3", actual_result, expected_result);
00456
00457 actual_result = "";
00458 ret = get_word(actual_result, is, 0);
00459 expected_result = "";
00460 ensure_equals("get_word: 0 sized output", actual_result, expected_result);
00461
00462 actual_result = "";
00463 ret = get_word(actual_result, is, 255);
00464 expected_result = "Third";
00465 ensure_equals("get_word: 4", actual_result, expected_result);
00466
00467 is.clear();
00468 is.str(str = " \t \r \n ");
00469 actual_result = "";
00470 ret = get_word(actual_result, is, 255);
00471 ensure("get_word: empty all spaces, newline tabs", ret == false);
00472
00473 is.clear();
00474 is.str(str = "");
00475 actual_result = "";
00476 ret = get_word(actual_result, is, 255);
00477 ensure("get_word: empty string", ret == false);
00478 }
00479
00480
00481 template<> template<>
00482 void streamtools_object::test<10>()
00483 {
00484 std::string str;
00485 std::string expected_result;
00486 std::string actual_result;
00487 std::istringstream is;
00488 bool ret;
00489
00490 is.clear();
00491 is.str(str = "First Second \t \r\n Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n");
00492 actual_result = "";
00493 ret = get_line(actual_result, is);
00494 expected_result = "First Second \t \r\n";
00495 ensure_equals("get_line: 1", actual_result, expected_result);
00496
00497 actual_result = "";
00498 ret = get_line(actual_result, is);
00499 expected_result = " Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n";
00500 ensure_equals("get_line: 2", actual_result, expected_result);
00501
00502 is.clear();
00503 is.str(str = "\nFirst Line.\n\nSecond Line.\n");
00504 actual_result = "";
00505 ret = get_line(actual_result, is);
00506 expected_result = "\n";
00507 ensure_equals("get_line: First char as newline", actual_result, expected_result);
00508
00509 actual_result = "";
00510 ret = get_line(actual_result, is);
00511 expected_result = "First Line.\n";
00512 ensure_equals("get_line: 3", actual_result, expected_result);
00513
00514 actual_result = "";
00515 ret = get_line(actual_result, is);
00516 expected_result = "\n";
00517 ensure_equals("get_line: 4", actual_result, expected_result);
00518
00519 actual_result = "";
00520 ret = get_line(actual_result, is);
00521 expected_result = "Second Line.\n";
00522 ensure_equals("get_line: 5", actual_result, expected_result);
00523 }
00524
00525
00526 template<> template<>
00527 void streamtools_object::test<11>()
00528 {
00529 std::string str;
00530 std::string expected_result;
00531 std::string actual_result;
00532 std::istringstream is;
00533 bool ret;
00534
00535 is.clear();
00536 is.str(str = "One Line only with no newline");
00537 actual_result = "";
00538 ret = get_line(actual_result, is);
00539 expected_result = "One Line only with no newline";
00540 ensure_equals("get_line: No newline", actual_result, expected_result);
00541 ensure_equals("return value is good state of stream", ret, is.good());
00542 }
00543
00544
00545 template<> template<>
00546 void streamtools_object::test<12>()
00547 {
00548 std::string str;
00549 std::string expected_result;
00550 std::string actual_result;
00551 std::istringstream is;
00552 bool ret;
00553
00554
00555 is.clear();
00556 is.str(str = "Should not skip lone \r.\r\n");
00557 actual_result = "";
00558 ret = get_line(actual_result, is);
00559 expected_result = "Should not skip lone \r.\r\n";
00560 ensure_equals("get_line: carriage return skipped even though not followed by newline", actual_result, expected_result);
00561 }
00562
00563
00564 template<> template<>
00565 void streamtools_object::test<13>()
00566 {
00567 std::string str;
00568 std::string expected_result;
00569 std::string actual_result;
00570 std::istringstream is;
00571 bool ret;
00572
00573 is.clear();
00574 is.str(str = "\n");
00575 actual_result = "";
00576 ret = get_line(actual_result, is);
00577 expected_result = "\n";
00578 ensure_equals("get_line: Just newline", actual_result, expected_result);
00579 }
00580
00581
00582
00583 template<> template<>
00584 void streamtools_object::test<14>()
00585 {
00586 std::string str;
00587 std::string expected_result;
00588 std::string actual_result;
00589 std::istringstream is;
00590 bool ret;
00591
00592 is.clear();
00593 is.str(str = "First Line.\nSecond Line.\n");
00594 actual_result = "";
00595 ret = get_line(actual_result, is, 255);
00596 expected_result = "First Line.\n";
00597 ensure_equals("get_line: Basic Operation", actual_result, expected_result);
00598
00599 actual_result = "";
00600 ret = get_line(actual_result, is, sizeof("Second")-1);
00601 expected_result = "Second\n";
00602 ensure_equals("get_line: Insufficient length 1", actual_result, expected_result);
00603
00604 actual_result = "";
00605 ret = get_line(actual_result, is, 255);
00606 expected_result = " Line.\n";
00607 ensure_equals("get_line: Remainder after earlier insufficient length", actual_result, expected_result);
00608
00609 is.clear();
00610 is.str(str = "One Line only with no newline with limited length");
00611 actual_result = "";
00612 ret = get_line(actual_result, is, sizeof("One Line only with no newline with limited length")-1);
00613 expected_result = "One Line only with no newline with limited length\n";
00614 ensure_equals("get_line: No newline with limited length", actual_result, expected_result);
00615
00616 is.clear();
00617 is.str(str = "One Line only with no newline");
00618 actual_result = "";
00619 ret = get_line(actual_result, is, 255);
00620 expected_result = "One Line only with no newline";
00621 ensure_equals("get_line: No newline", actual_result, expected_result);
00622 }
00623
00624
00625 template<> template<>
00626 void streamtools_object::test<15>()
00627 {
00628 std::string str;
00629 std::string expected_result;
00630 std::string actual_result;
00631 std::istringstream is;
00632 bool ret;
00633
00634 is.clear();
00635 is.str(str = "One Line only with no newline");
00636 actual_result = "";
00637 ret = get_line(actual_result, is, 255);
00638 expected_result = "One Line only with no newline";
00639 ensure_equals("get_line: No newline", actual_result, expected_result);
00640 ensure_equals("return value is good state of stream", ret, is.good());
00641 }
00642
00643
00644 template<> template<>
00645 void streamtools_object::test<16>()
00646 {
00647 std::string str;
00648 std::string expected_result;
00649 bool ret;
00650
00651 str = "SecondLife is a 3D World";
00652
00653 ret = remove_last_char('d',str);
00654 expected_result = "SecondLife is a 3D Worl";
00655 ensure_equals("remove_last_char: should remove last char", str, expected_result);
00656
00657 str = "SecondLife is a 3D World";
00658 ret = remove_last_char('W',str);
00659 expected_result = "SecondLife is a 3D World";
00660 ensure_equals("remove_last_char: should not remove as it is not last char", str, expected_result);
00661 ensure("remove_last_char: should return false", ret == false);
00662
00663 str = "SecondLife is a 3D World\n";
00664 ret = remove_last_char('\n',str);
00665 expected_result = "SecondLife is a 3D World";
00666 ensure_equals("remove_last_char: should remove last newline", str, expected_result);
00667 ensure("remove_last_char: should remove newline and return true", ret == true);
00668 }
00669
00670
00671
00672 template<> template<>
00673 void streamtools_object::test<17>()
00674 {
00675 std::string str;
00676 std::string expected_result;
00677
00678 str = "SecondLife is a 3D world \\n";
00679 unescape_string(str);
00680 expected_result = "SecondLife is a 3D world \n";
00681 ensure_equals("unescape_string: newline", str, expected_result);
00682
00683 str = "SecondLife is a 3D world \\\\t \\n";
00684 unescape_string(str);
00685 expected_result = "SecondLife is a 3D world \\t \n";
00686 ensure_equals("unescape_string: backslash and newline", str, expected_result);
00687
00688 str = "SecondLife is a 3D world \\ ";
00689 unescape_string(str);
00690 expected_result = "SecondLife is a 3D world \\ ";
00691 ensure_equals("unescape_string: insufficient to unescape", str, expected_result);
00692
00693 str = "SecondLife is a 3D world \\n \\n \\n \\\\\\n";
00694 unescape_string(str);
00695 expected_result = "SecondLife is a 3D world \n \n \n \\\n";
00696 ensure_equals("unescape_string: multipel newline and backslash", str, expected_result);
00697
00698 str = "SecondLife is a 3D world \\t";
00699 unescape_string(str);
00700 expected_result = "SecondLife is a 3D world \\t";
00701 ensure_equals("unescape_string: leaves tab as is", str, expected_result);
00702
00703 str = "\\n";
00704 unescape_string(str);
00705 expected_result = "\n";
00706 ensure_equals("unescape_string: only a newline", str, expected_result);
00707 }
00708
00709
00710 template<> template<>
00711 void streamtools_object::test<18>()
00712 {
00713 std::string str;
00714 std::string expected_result;
00715
00716 str = "SecondLife is a 3D world \n";
00717 escape_string(str);
00718 expected_result = "SecondLife is a 3D world \\n";
00719 ensure_equals("escape_string: newline", str, expected_result);
00720
00721 str = "SecondLife is a 3D world \\t \n";
00722 escape_string(str);
00723 expected_result = "SecondLife is a 3D world \\\\t \\n";
00724 ensure_equals("escape_string: backslash and newline", str, expected_result);
00725
00726 str = "SecondLife is a 3D world \n \n \n \\\n";
00727 escape_string(str);
00728 expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\\\n";
00729 ensure_equals("escape_string: multipel newline and backslash", str, expected_result);
00730
00731 str = "SecondLife is a 3D world \t";
00732 escape_string(str);
00733 expected_result = "SecondLife is a 3D world \t";
00734 ensure_equals("unescape_string: leaves tab as is", str, expected_result);
00735
00736 str = "\n";
00737 escape_string(str);
00738 expected_result = "\\n";
00739 ensure_equals("unescape_string: only a newline", str, expected_result);
00740
00741
00742 str = "SecondLife is a 3D world \n \n \n \\\n";
00743 escape_string(str);
00744 unescape_string(str);
00745 expected_result = "SecondLife is a 3D world \n \n \n \\\n";
00746 ensure_equals("escape_string: should preserve with escape/unescape", str, expected_result);
00747
00748
00749 str = "SecondLife is a 3D world \\n \\n \\n \\\\";
00750 unescape_string(str);
00751 escape_string(str);
00752 expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\";
00753 ensure_equals("escape_string: should preserve with unescape/escape", str, expected_result);
00754 }
00755
00756
00757 template<> template<>
00758 void streamtools_object::test<19>()
00759 {
00760 std::string str;
00761 std::string expected_result;
00762
00763 str = "SecondLife is a 3D \n\nworld\n";
00764 replace_newlines_with_whitespace(str);
00765 expected_result = "SecondLife is a 3D world ";
00766 ensure_equals("replace_newlines_with_whitespace: replace all newline", str, expected_result);
00767
00768 str = "\nSecondLife is a 3D world\n";
00769 replace_newlines_with_whitespace(str);
00770 expected_result = " SecondLife is a 3D world ";
00771 ensure_equals("replace_newlines_with_whitespace: begin and newline", str, expected_result);
00772
00773 str = "SecondLife is a 3D world\r\t";
00774 replace_newlines_with_whitespace(str);
00775 expected_result = "SecondLife is a 3D world\r\t";
00776 ensure_equals("replace_newlines_with_whitespace: should only replace newline", str, expected_result);
00777
00778 str = "";
00779 replace_newlines_with_whitespace(str);
00780 expected_result = "";
00781 ensure_equals("replace_newlines_with_whitespace: empty string", str, expected_result);
00782 }
00783
00784
00785 template<> template<>
00786 void streamtools_object::test<20>()
00787 {
00788 std::string str;
00789 std::string expected_result;
00790
00791 str = "SecondLife is a \"\"3D world";
00792 remove_double_quotes(str);
00793 expected_result = "SecondLife is a 3D world";
00794 ensure_equals("remove_double_quotes: replace empty doube quotes", str, expected_result);
00795
00796 str = "SecondLife is a \"3D world";
00797 remove_double_quotes(str);
00798 expected_result = "SecondLife is a 3D world";
00799 ensure_equals("remove_double_quotes: keep as is it matching quote not found", str, expected_result);
00800 }
00801
00802
00803 template<> template<>
00804 void streamtools_object::test<21>()
00805 {
00806 }
00807
00808
00809 template<> template<>
00810 void streamtools_object::test<22>()
00811 {
00812 std::string s = "SecondLife is a 3D World";
00813 std::string keyword;
00814 std::string value;
00815 get_keyword_and_value(keyword, value, s);
00816 ensure("get_keyword_and_value: Unable to get Keyword and Value", ((keyword == "SecondLife") && (value == "is a 3D World")));
00817
00818 s = "SecondLife";
00819 get_keyword_and_value(keyword, value, s);
00820 ensure("get_keyword_and_value: value should be empty", ((keyword == "SecondLife") && (value == "")));
00821
00822 s = "SecondLife \t is cool! \n";
00823 get_keyword_and_value(keyword, value, s);
00824 ensure("get_keyword_and_value: remove space before value but not after", ((keyword == "SecondLife") && (value == "is cool! ")));
00825 }
00826
00827
00828 template<> template<>
00829 void streamtools_object::test<23>()
00830 {
00831 std::string s;
00832 std::string keyword = "SOME PRIOR KEYWORD";
00833 std::string value = "SOME PRIOR VALUE";
00834
00835 s = "SecondLife\n";
00836 get_keyword_and_value(keyword, value, s);
00837 ensure("get_keyword_and_value: terminated with newline. value should be empty", ((keyword == "SecondLife") && (value == "")));
00838 }
00839
00840
00841 template<> template<>
00842 void streamtools_object::test<24>()
00843 {
00844 std::string s;
00845 std::string keyword = "SOME PRIOR KEYWORD";
00846 std::string value = "SOME PRIOR VALUE";
00847
00848 s = "";
00849 get_keyword_and_value(keyword, value, s);
00850 ensure("get_keyword_and_value: empty string. keyword value should empty", ((keyword == "") && (value == "")));
00851 }
00852
00853
00854 template<> template<>
00855 void streamtools_object::test<25>()
00856 {
00857 std::string str = "First Line.\nSecond Line\n";
00858 std::istringstream is(str);
00859 char buf[255] = {0};
00860
00861 fullread(is, buf, 255);
00862 ensure_memory_matches("fullread: read with newlines", (void*) buf, str.size()-1, (void*) str.c_str(), str.size()-1);
00863
00864 is.clear();
00865 is.str(str = "First Line.\nSecond Line\n");
00866 memset(buf, 0, 255);
00867
00868 char expected_string[] = "First Line.\nSecond";
00869 int len = sizeof(expected_string)-1;
00870 fullread(is, buf, len);
00871 ensure_memory_matches("fullread: read with newlines", (void*) buf, len, (void*) &expected_string, len);
00872 }
00873
00874
00875
00876
00877 template<> template<>
00878 void streamtools_object::test<26>()
00879 {
00880 char arr[255];
00881 std::string str;
00882 std::string toCheck = "SecondLife" ;
00883 std::string expected_result;
00884 std::istringstream stream("SecondLife is a 3D World");
00885 stream >> toCheck.c_str();
00886 stream.get(arr, 255, '\0');
00887 expected_result = " is a 3D World";
00888 ensure_equals("istream << operator", arr, expected_result);
00889
00890 stream.clear();
00891 stream.str(str = "SecondLife is a 3D World");
00892 toCheck = "is";
00893 stream >> toCheck.c_str();
00894 ensure("istream << operator should have failed", stream.good() == false);
00895 }
00896 }