00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018
00019 #if defined(DEBUG)
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <spl/Log.h>
00024 #include <spl/math/Math.h>
00025 #include <spl/String.h>
00026
00027 using namespace spl;
00028
00029 static void _TestTStringNull()
00030 {
00031 DEBUG_FREE_HEAP();
00032
00033 String *str = new String("bob");
00034 UNIT_ASSERT( "String 1 content", strcmp(str->GetChars(), "bob") == 0 );
00035 UNIT_ASSERT( "String 1 len", str->Length() == 3 );
00036 DEBUG_CLEAR_MEM_CHECK_POINTS();
00037 DEBUG_NOTE_MEM( str );
00038 str->CheckMem();
00039 UNIT_ASSERT_MEM_NOTED("_TestStringNull 1.0");
00040
00041 delete str;
00042 DEBUG_CLEAR_MEM_CHECK_POINTS();
00043 UNIT_ASSERT_MEM_NOTED("_TestStringNull 1.1");
00044
00045 _debugValidateHeap();
00046
00047 Log::SWriteOkFail( "String test null" );
00048 }
00049
00050 static void _TestStringTrim()
00051 {
00052 String *str = new String("abc");
00053 StringPtr ret = str->Trim();
00054 UNIT_ASSERT( "_TestStringTrim 1", strcmp(ret->GetChars(), "abc") == 0 );
00055 UNIT_ASSERT( "_TestStringTrim 2", ret->Length() == 3 );
00056 DEBUG_CLEAR_MEM_CHECK_POINTS();
00057 DEBUG_NOTE_MEM( str );
00058 str->CheckMem();
00059 ret.CheckMem();
00060 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 1");
00061 delete str;
00062 DEBUG_CLEAR_MEM_CHECK_POINTS();
00063 ret.CheckMem();
00064 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 2");
00065
00066 str = new String(" abc");
00067 ret = str->Trim();
00068 str->ValidateMem();
00069 UNIT_ASSERT( "_TestStringTrim 3", strcmp(ret->GetChars(), "abc") == 0 );
00070 UNIT_ASSERT( "_TestStringTrim 4", ret->Length() == 3 );
00071 DEBUG_CLEAR_MEM_CHECK_POINTS();
00072 DEBUG_NOTE_MEM( str );
00073 str->CheckMem();
00074 ret.CheckMem();
00075 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 3");
00076 delete str;
00077 DEBUG_CLEAR_MEM_CHECK_POINTS();
00078 ret.CheckMem();
00079 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 4");
00080
00081 str = new String("abc ");
00082 ret = str->Trim();
00083 str->ValidateMem();
00084 UNIT_ASSERT( "_TestStringTrim 5", strcmp(ret->GetChars(), "abc") == 0 );
00085 UNIT_ASSERT( "_TestStringTrim 6", ret->Length() == 3 );
00086 DEBUG_CLEAR_MEM_CHECK_POINTS();
00087 DEBUG_NOTE_MEM( str );
00088 str->CheckMem();
00089 ret.CheckMem();
00090 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 5");
00091 delete str;
00092 DEBUG_CLEAR_MEM_CHECK_POINTS();
00093 ret.CheckMem();
00094 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 6");
00095
00096 str = new String(" abc ");
00097 ret = str->Trim();
00098 str->ValidateMem();
00099 UNIT_ASSERT( "_TestStringTrim 7", strcmp(ret->GetChars(), "abc") == 0 );
00100 UNIT_ASSERT( "_TestStringTrim 8", ret->Length() == 3 );
00101 DEBUG_CLEAR_MEM_CHECK_POINTS();
00102 DEBUG_NOTE_MEM( str );
00103 str->CheckMem();
00104 ret.CheckMem();
00105 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 7");
00106 delete str;
00107 DEBUG_CLEAR_MEM_CHECK_POINTS();
00108 ret.CheckMem();
00109 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 8");
00110
00111 str = new String(" ab c ");
00112 ret = str->Trim();
00113 str->ValidateMem();
00114 UNIT_ASSERT( "_TestStringTrim 9", strcmp(ret->GetChars(), "ab c") == 0 );
00115 UNIT_ASSERT( "_TestStringTrim 10", ret->Length() == 4 );
00116 DEBUG_CLEAR_MEM_CHECK_POINTS();
00117 DEBUG_NOTE_MEM( str );
00118 str->CheckMem();
00119 ret.CheckMem();
00120 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 9");
00121 delete str;
00122 DEBUG_CLEAR_MEM_CHECK_POINTS();
00123 ret.CheckMem();
00124 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 10");
00125
00126 Log::SWriteOkFail( "String test Trim" );
00127 }
00128
00129 static void _TestStringRTrim()
00130 {
00131 String *str = new String("abc");
00132 StringPtr ret = str->RTrim();
00133 UNIT_ASSERT( "_TestStringRTrim 1", strcmp(ret->GetChars(), "abc") == 0 );
00134 UNIT_ASSERT( "_TestStringRTrim 2", ret->Length() == 3 );
00135 DEBUG_CLEAR_MEM_CHECK_POINTS();
00136 DEBUG_NOTE_MEM( str );
00137 str->CheckMem();
00138 ret.CheckMem();
00139 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 1");
00140 delete str;
00141 DEBUG_CLEAR_MEM_CHECK_POINTS();
00142 ret.CheckMem();
00143 UNIT_ASSERT_MEM_NOTED("_TestStringTrim 2");
00144
00145 str = new String(" abc");
00146 ret = str->RTrim();
00147 str->ValidateMem();
00148 UNIT_ASSERT( "_TestStringRTrim 3", strcmp(ret->GetChars(), " abc") == 0 );
00149 UNIT_ASSERT( "_TestStringRTrim 4", ret->Length() == 4 );
00150 DEBUG_CLEAR_MEM_CHECK_POINTS();
00151 DEBUG_NOTE_MEM( str );
00152 str->CheckMem();
00153 ret.CheckMem();
00154 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 3");
00155 delete str;
00156 DEBUG_CLEAR_MEM_CHECK_POINTS();
00157 ret.CheckMem();
00158 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 4");
00159
00160 str = new String("abc ");
00161 ret = str->RTrim();
00162 str->ValidateMem();
00163 UNIT_ASSERT( "_TestStringRTrim 5", strcmp(ret->GetChars(), "abc") == 0 );
00164 UNIT_ASSERT( "_TestStringRTrim 6", ret->Length() == 3 );
00165 DEBUG_CLEAR_MEM_CHECK_POINTS();
00166 DEBUG_NOTE_MEM( str );
00167 str->CheckMem();
00168 ret.CheckMem();
00169 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 5");
00170 delete str;
00171 DEBUG_CLEAR_MEM_CHECK_POINTS();
00172 ret.CheckMem();
00173 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 6");
00174
00175 str = new String(" abc ");
00176 ret = str->RTrim();
00177 str->ValidateMem();
00178 UNIT_ASSERT( "_TestStringRTrim 7", strcmp(ret->GetChars(), " abc") == 0 );
00179 UNIT_ASSERT( "_TestStringRTrim 8", ret->Length() == 4 );
00180 DEBUG_CLEAR_MEM_CHECK_POINTS();
00181 DEBUG_NOTE_MEM( str );
00182 str->CheckMem();
00183 ret.CheckMem();
00184 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 7");
00185 delete str;
00186 DEBUG_CLEAR_MEM_CHECK_POINTS();
00187 ret.CheckMem();
00188 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 8");
00189
00190 str = new String(" ab c ");
00191 ret = str->RTrim();
00192 str->ValidateMem();
00193 UNIT_ASSERT( "_TestStringRTrim 9", strcmp(ret->GetChars(), " ab c") == 0 );
00194 UNIT_ASSERT( "_TestStringRTrim 10", ret->Length() == 6 );
00195 DEBUG_CLEAR_MEM_CHECK_POINTS();
00196 DEBUG_NOTE_MEM( str );
00197 str->CheckMem();
00198 ret.CheckMem();
00199 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 9");
00200 delete str;
00201 DEBUG_CLEAR_MEM_CHECK_POINTS();
00202 ret.CheckMem();
00203 UNIT_ASSERT_MEM_NOTED("_TestStringRTrim 10");
00204
00205 Log::SWriteOkFail( "String test Trim" );
00206 }
00207
00208 static void _TestStringRTrimRegression1()
00209 {
00210 String base("42.4200000");
00211 StringPtr trimmed = base.RTrim('0');
00212 UNIT_ASSERT("Should be 42.42", *trimmed == "42.42");
00213
00214 Log::SWriteOkFail( "String test RTrim regression 1" );
00215 }
00216
00217 static void _TestStringSet()
00218 {
00219 String *a = new String("a");
00220 a->Set("b");
00221 UNIT_ASSERT( "_TestStringSet 1.3", a->Equals("b") );
00222
00223 DEBUG_CLEAR_MEM_CHECK_POINTS();
00224 DEBUG_NOTE_MEM(a);
00225 a->CheckMem();
00226 UNIT_ASSERT_MEM_NOTED("_TestStringSet 1.4");
00227
00228 delete a;
00229 Log::SWriteOkFail( "String test Set" );
00230 }
00231
00232 static void _TestStringCopyConstruct()
00233 {
00234 String a("a");
00235 UNIT_ASSERT( "_TestStringCopyConstruct 1.0", a.Equals("a") );
00236 UNIT_ASSERT( "_TestStringCopyConstruct 1.1", a == a );
00237 DEBUG_CLEAR_MEM_CHECK_POINTS();
00238 a.CheckMem();
00239 UNIT_ASSERT_MEM_NOTED("_TestStringCopyConstruct 1.2");
00240
00241 String b("b");
00242 DEBUG_CLEAR_MEM_CHECK_POINTS();
00243 a.CheckMem();
00244 b.CheckMem();
00245 UNIT_ASSERT_MEM_NOTED("_TestStringCopyConstruct 1.3");
00246 UNIT_ASSERT( "_TestStringCopyConstruct 1,2", b.Equals("b") );
00247 UNIT_ASSERT( "_TestStringCopyConstruct 1,2a", b != a );
00248 UNIT_ASSERT( "_TestStringCopyConstruct 1,2a", a != b );
00249
00250 b = a;
00251 UNIT_ASSERT( "_TestStringCopyConstruct 1.3", a.Equals("a") );
00252 UNIT_ASSERT( "_TestStringCopyConstruct 1,4", b.Equals("a") );
00253 UNIT_ASSERT( "_TestStringCopyConstruct 1,5", b == a );
00254 UNIT_ASSERT( "_TestStringCopyConstruct 1,5", b == a );
00255
00256 DEBUG_CLEAR_MEM_CHECK_POINTS();
00257 a.CheckMem();
00258 b.CheckMem();
00259 UNIT_ASSERT_MEM_NOTED("_TestStringCopyConstruct 1.4");
00260
00261 Log::SWriteOkFail( "String test copy constructor 1" );
00262 }
00263
00264 void _TestStringFormat()
00265 {
00266 const char *ptr = "Hello world!";
00267 char *np = 0;
00268 int i = 5;
00269 unsigned int bs = sizeof(int)*8;
00270 int mi;
00271
00272 mi = (1 << (bs-1)) + 1;
00273
00274 StringPtr str = String::Format("printf test\n");
00275 UNIT_ASSERT("printf test\\n", str->Equals("printf test\n"));
00276 str = String::Format("%s\n", ptr);
00277 UNIT_ASSERT("Hello world!\\n", str->Equals("Hello world!\n"));
00278 str = String::Format("%s is null pointer\n", np);
00279 UNIT_ASSERT("%s is null pointer\\n", str->Equals("(null) is null pointer\n"));
00280 str = String::Format("%d = 5\n", i);
00281 UNIT_ASSERT("%d = 5\\n", str->Equals("5 = 5\n"));
00282 str = String::Format("%d = - max int\n", mi);
00283 UNIT_ASSERT("%d = - max int\\n", str->Equals("-2147483647 = - max int\n"));
00284 str = String::Format("char %c = 'a'\n", 'a');
00285 UNIT_ASSERT("char %c = 'a'\\n", str->Equals("char a = 'a'\n"));
00286 str = String::Format("hex %x = ff\n", 0xff);
00287 UNIT_ASSERT("hex %x = ff\\n", str->Equals("hex ff = ff\n"));
00288 str = String::Format("hex %02x = 00\n", 0);
00289 UNIT_ASSERT("hex %02x = 00\\n", str->Equals("hex 00 = 00\n"));
00290 str = String::Format("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
00291 UNIT_ASSERT("signed %d = unsigned %u = hex %x\\n", str->Equals("signed -3 = unsigned 4294967293 = hex fffffffd\n"));
00292 str = String::Format("%d %s(s)%", 0, "message");
00293 UNIT_ASSERT("%d %s(s)%", str->Equals("0 message(s)"));
00294 str = String::Format("\n");
00295 UNIT_ASSERT("\\n", str->Equals("\n"));
00296 str = String::Format("%d %s(s) with %%\n", 0, "message");
00297 UNIT_ASSERT("%d %s(s) with %%\\n", str->Equals("0 message(s) with %\n"));
00298 str = String::Format("justif: \"%-10s\"\n", "left");
00299 UNIT_ASSERT("justif: \"%-10s\"\\n", str->Equals("justif: \"left \"\n"));
00300 str = String::Format("justif: \"%10s\"\n", "right");
00301 UNIT_ASSERT("justif: \"%10s\"\\n", str->Equals("justif: \" right\"\n"));
00302 str = String::Format(" 3: %04d zero padded\n", 3);
00303 UNIT_ASSERT(" 3: %04d zero padded\\n", str->Equals(" 3: 0003 zero padded\n"));
00304 str = String::Format(" 3: %-4d left justif.\n", 3);
00305 UNIT_ASSERT(" 3: %-4d left justif.\\n", str->Equals(" 3: 3 left justif.\n"));
00306 str = String::Format(" 3: %4d right justif.\n", 3);
00307 UNIT_ASSERT(" 3: %4d right justif.\\n", str->Equals(" 3: 3 right justif.\n"));
00308 str = String::Format("-3: %04d zero padded\n", -3);
00309 UNIT_ASSERT("-3: %04d zero padded\\n", str->Equals("-3: -003 zero padded\n"));
00310 str = String::Format("-3: %-4d left justif.\n", -3);
00311 UNIT_ASSERT("-3: %-4d left justif.\\n", str->Equals("-3: -3 left justif.\n"));
00312 str = String::Format("-3: %4d right justif.\n", -3);
00313 UNIT_ASSERT("-3: %4d right justif.\\n", str->Equals("-3: -3 right justif.\n"));
00314
00315 DEBUG_CLEAR_MEM_CHECK_POINTS();
00316 str.CheckMem();
00317 UNIT_ASSERT_MEM_NOTED("String::Format 1.4");
00318
00319 Log::SWriteOkFail( "String::Format" );
00320 }
00321
00322 void _TestStringFormat2()
00323 {
00324 char buf[256];
00325 sprintf(buf, "%f", Math::PI());
00326
00327 StringPtr str = String::Format("%f", Math::PI());
00328 UNIT_ASSERT("%f test", str->Equals(buf));
00329
00330 DEBUG_CLEAR_MEM_CHECK_POINTS();
00331 str.CheckMem();
00332 UNIT_ASSERT_MEM_NOTED("String::Format 2.1");
00333
00334 Log::SWriteOkFail( "String::Format" );
00335 }
00336
00337 void _TestStringInter()
00338 {
00339 {
00340 String s;
00341 DEBUG_CLEAR_MEM_CHECK_POINTS();
00342 UNIT_ASSERT_MEM_NOTED("String::Inter 1.0");
00343 }
00344
00345 StringPtr str = String::Intern("The time has come");
00346 UNIT_ASSERT("The time has come", str->Equals("The time has come"));
00347
00348 DEBUG_CLEAR_MEM_CHECK_POINTS();
00349 str.CheckMem();
00350 UNIT_ASSERT_MEM_NOTED("String::Format 1.1");
00351
00352 Log::SWriteOkFail( "String::Intern" );
00353 }
00354
00355 void _TestStringReplace()
00356 {
00357 String str("abcabcabc");
00358 StringPtr repl = str.Replace('a', 'z');
00359 UNIT_ASSERT("Replace 1", repl->Equals("zbczbczbc"));
00360
00361 DEBUG_CLEAR_MEM_CHECK_POINTS();
00362 str.CheckMem();
00363 repl.CheckMem();
00364 UNIT_ASSERT_MEM_NOTED("String::Replace 2");
00365
00366 repl = str.Replace('c', 'z');
00367 UNIT_ASSERT("Replace 1.1", repl->Equals("abzabzabz"));
00368
00369 DEBUG_CLEAR_MEM_CHECK_POINTS();
00370 str.CheckMem();
00371 repl.CheckMem();
00372 UNIT_ASSERT_MEM_NOTED("String::Replace 2.1");
00373
00374 repl = str.Replace("a", "z");
00375 UNIT_ASSERT("Replace 3", repl->Equals("zbczbczbc"));
00376
00377 DEBUG_CLEAR_MEM_CHECK_POINTS();
00378 str.CheckMem();
00379 repl.CheckMem();
00380 UNIT_ASSERT_MEM_NOTED("String::Replace 4");
00381
00382 repl = str.Replace("c", "z");
00383 UNIT_ASSERT("Replace 5", repl->Equals("abzabzabz"));
00384
00385 DEBUG_CLEAR_MEM_CHECK_POINTS();
00386 str.CheckMem();
00387 repl.CheckMem();
00388 UNIT_ASSERT_MEM_NOTED("String::Replace 6");
00389
00390 repl = str.Replace("ab", "z");
00391 UNIT_ASSERT("Replace 7", repl->Equals("zczczc"));
00392
00393 DEBUG_CLEAR_MEM_CHECK_POINTS();
00394 str.CheckMem();
00395 repl.CheckMem();
00396 UNIT_ASSERT_MEM_NOTED("String::Replace 8");
00397
00398 repl = str.Replace("ab", "z23");
00399 UNIT_ASSERT("Replace 9", repl->Equals("z23cz23cz23c"));
00400
00401 DEBUG_CLEAR_MEM_CHECK_POINTS();
00402 str.CheckMem();
00403 repl.CheckMem();
00404 UNIT_ASSERT_MEM_NOTED("String::Replace 10");
00405
00406 repl = str.Replace("bc", "qpr");
00407 UNIT_ASSERT("Replace 11", repl->Equals("aqpraqpraqpr"));
00408
00409 DEBUG_CLEAR_MEM_CHECK_POINTS();
00410 str.CheckMem();
00411 repl.CheckMem();
00412 UNIT_ASSERT_MEM_NOTED("String::Replace 12");
00413
00414 Log::SWriteOkFail( "String::Replace" );
00415 }
00416
00417 static void _TestStringLeft()
00418 {
00419 String str("abcabcabc");
00420 StringPtr left = str.Left(3);
00421 UNIT_ASSERT("Left 1", left->Equals("abc"));
00422
00423 DEBUG_CLEAR_MEM_CHECK_POINTS();
00424 str.CheckMem();
00425 left.CheckMem();
00426 UNIT_ASSERT_MEM_NOTED("Left::Left 2");
00427
00428 left = str.Left(1);
00429 UNIT_ASSERT("Left 3", left->Equals("a"));
00430
00431 DEBUG_CLEAR_MEM_CHECK_POINTS();
00432 str.CheckMem();
00433 left.CheckMem();
00434 UNIT_ASSERT_MEM_NOTED("Left::Left 4");
00435
00436 left = str.Left(0);
00437 UNIT_ASSERT("Left 5", left->Equals(""));
00438
00439 DEBUG_CLEAR_MEM_CHECK_POINTS();
00440 str.CheckMem();
00441 left.CheckMem();
00442 UNIT_ASSERT_MEM_NOTED("Left::Left 6");
00443
00444 left = left->Left(1);
00445 UNIT_ASSERT("Left 7", left->Equals(""));
00446
00447 DEBUG_CLEAR_MEM_CHECK_POINTS();
00448 str.CheckMem();
00449 left.CheckMem();
00450 UNIT_ASSERT_MEM_NOTED("Left::Left 8");
00451
00452 Log::SWriteOkFail( "String::Left" );
00453 }
00454
00455 static void _TestStringRight()
00456 {
00457 String str("abcabcabc1");
00458 StringPtr right = str.Right(3);
00459 UNIT_ASSERT("Right 1", right->Equals("bc1"));
00460
00461 DEBUG_CLEAR_MEM_CHECK_POINTS();
00462 str.CheckMem();
00463 right.CheckMem();
00464 UNIT_ASSERT_MEM_NOTED("String::Right 2");
00465
00466 right = str.Right(1);
00467 UNIT_ASSERT("Right 3", right->Equals("1"));
00468
00469 DEBUG_CLEAR_MEM_CHECK_POINTS();
00470 str.CheckMem();
00471 right.CheckMem();
00472 UNIT_ASSERT_MEM_NOTED("String::Right 4");
00473
00474 right = str.Right(0);
00475 UNIT_ASSERT("Right 5", right->Equals(""));
00476
00477 DEBUG_CLEAR_MEM_CHECK_POINTS();
00478 str.CheckMem();
00479 right.CheckMem();
00480 UNIT_ASSERT_MEM_NOTED("String::Right 6");
00481
00482 right = right->Right(1);
00483 UNIT_ASSERT("Right 7", right->Equals(""));
00484
00485 DEBUG_CLEAR_MEM_CHECK_POINTS();
00486 str.CheckMem();
00487 right.CheckMem();
00488 UNIT_ASSERT_MEM_NOTED("String::Right 8");
00489
00490 Log::SWriteOkFail( "String::Right" );
00491 }
00492
00493 static void _TestStringCompOps()
00494 {
00495 String left("abc");
00496 String right("xyz");
00497 UNIT_ASSERT(">", left < right);
00498 UNIT_ASSERT("<", !(left > right));
00499 UNIT_ASSERT("==", !(left == right));
00500 UNIT_ASSERT("!=", (left != right));
00501 UNIT_ASSERT("<=", (left <= right));
00502 UNIT_ASSERT(">=", !(left >= right));
00503 UNIT_ASSERT("Comapre", left.Compare(right) < 0);
00504 UNIT_ASSERT("Comapre", right.Compare(left) > 0);
00505 UNIT_ASSERT("Equals", !left.Equals(right));
00506 UNIT_ASSERT("Equals", !right.Equals(left));
00507 UNIT_ASSERT("CompareNoCase", left.CompareNoCase("ABC") == 0);
00508 UNIT_ASSERT("EqualsIgnoreCase", left.EqualsIgnoreCase("ABC"));
00509
00510 left = "xyz";
00511 UNIT_ASSERT(">", !(left < right));
00512 UNIT_ASSERT("<", !(left > right));
00513 UNIT_ASSERT("== 2", (left == right));
00514 UNIT_ASSERT("!= ", !(left != right));
00515 UNIT_ASSERT("<=", (left <= right));
00516 UNIT_ASSERT(">=", (left >= right));
00517 UNIT_ASSERT("Comapre", left.Compare(right) == 0);
00518 UNIT_ASSERT("Comapre", right.Compare(left) == 0);
00519 UNIT_ASSERT("Equals" ,left.Equals(right));
00520 UNIT_ASSERT("Equals", right.Equals(left));
00521
00522 DEBUG_CLEAR_MEM_CHECK_POINTS();
00523 left.CheckMem();
00524 right.CheckMem();
00525 UNIT_ASSERT_MEM_NOTED("String comparision mem");
00526
00527 Log::SWriteOkFail( "String comparison operations" );
00528 }
00529
00530 static void _TestStringMid()
00531 {
00532 String str("abc");
00533 StringPtr mid = str.Mid(0, 1);
00534
00535 UNIT_ASSERT("Mid", *mid == "a");
00536 mid = str.Mid(1, 2);
00537 UNIT_ASSERT("Mid", *mid == "b");
00538 mid = str.Mid(2, 3);
00539 UNIT_ASSERT("Mid", *mid == "c");
00540
00541 DEBUG_CLEAR_MEM_CHECK_POINTS();
00542 str.CheckMem();
00543 mid.CheckMem();
00544 UNIT_ASSERT_MEM_NOTED("String comparision mem");
00545
00546 Log::SWriteOkFail( "String::Mid" );
00547 }
00548
00549 static void _TestStringUpper()
00550 {
00551 String str("abc");
00552 StringPtr upper = str.ToUpper();
00553
00554 UNIT_ASSERT("Upper", *upper == "ABC");
00555 upper = upper->ToLower();
00556 UNIT_ASSERT("Lower", *upper == "abc");
00557
00558 DEBUG_CLEAR_MEM_CHECK_POINTS();
00559 str.CheckMem();
00560 upper.CheckMem();
00561 UNIT_ASSERT_MEM_NOTED("String upper mem");
00562
00563 Log::SWriteOkFail( "String::Upper" );
00564 }
00565
00566 static void _TestStringCat()
00567 {
00568 String a("ABC");
00569 String b("xyz");
00570
00571 UNIT_ASSERT("+", (a + b) == "ABCxyz");
00572 UNIT_ASSERT("+", ("ABC" + b) == "ABCxyz");
00573
00574 DEBUG_CLEAR_MEM_CHECK_POINTS();
00575 a.CheckMem();
00576 b.CheckMem();
00577 UNIT_ASSERT_MEM_NOTED("String +");
00578
00579 Log::SWriteOkFail( "String::+" );
00580 }
00581
00582 static void _TestStringBase64()
00583 {
00584 const char* txt = "Now is the time";
00585 RefCountPtr<String> enc = String::Base64Encode(txt, (int)strlen(txt));
00586 RefCountPtr<Array<byte> > dec = String::Base64Decode(*enc);
00587 String decStr((const char *)dec->Data(), dec->Length());
00588
00589 UNIT_ASSERT("Base64 text", decStr == txt);
00590
00591 DEBUG_CLEAR_MEM_CHECK_POINTS();
00592 enc.CheckMem();
00593 dec.CheckMem();
00594 decStr.CheckMem();
00595 UNIT_ASSERT_MEM_NOTED("String Base64");
00596
00597 Log::SWriteOkFail( "String::Base64" );
00598 }
00599
00600 void TestTString( )
00601 {
00602 _TestTStringNull();
00603 DEBUG_CLEAR_MEM_CHECK_POINTS();
00604 UNIT_ASSERT_MEM_NOTED("TestTString A");
00605 DEBUG_FREE_HEAP();
00606
00607 _TestStringTrim();
00608 DEBUG_CLEAR_MEM_CHECK_POINTS();
00609 UNIT_ASSERT_MEM_NOTED("TestTString D");
00610 DEBUG_FREE_HEAP();
00611
00612 _TestStringRTrim();
00613 DEBUG_CLEAR_MEM_CHECK_POINTS();
00614 UNIT_ASSERT_MEM_NOTED("TestString RTrim");
00615 DEBUG_FREE_HEAP();
00616
00617 _TestStringSet();
00618 DEBUG_CLEAR_MEM_CHECK_POINTS();
00619 UNIT_ASSERT_MEM_NOTED("TestTString E");
00620 DEBUG_FREE_HEAP();
00621
00622 _TestStringCopyConstruct();
00623 DEBUG_CLEAR_MEM_CHECK_POINTS();
00624 UNIT_ASSERT_MEM_NOTED("TestTString F");
00625 DEBUG_FREE_HEAP();
00626
00627 _TestStringFormat();
00628 DEBUG_CLEAR_MEM_CHECK_POINTS();
00629 UNIT_ASSERT_MEM_NOTED("TestTString G");
00630 DEBUG_FREE_HEAP();
00631
00632 _TestStringFormat2();
00633 DEBUG_CLEAR_MEM_CHECK_POINTS();
00634 UNIT_ASSERT_MEM_NOTED("TestTString H");
00635 DEBUG_FREE_HEAP();
00636
00637 _TestStringInter();
00638 DEBUG_CLEAR_MEM_CHECK_POINTS();
00639 UNIT_ASSERT_MEM_NOTED("TestTString I");
00640 DEBUG_FREE_HEAP();
00641
00642 _TestStringReplace();
00643 DEBUG_CLEAR_MEM_CHECK_POINTS();
00644 UNIT_ASSERT_MEM_NOTED("TestTString J");
00645 DEBUG_FREE_HEAP();
00646
00647 _TestStringLeft();
00648 DEBUG_CLEAR_MEM_CHECK_POINTS();
00649 UNIT_ASSERT_MEM_NOTED("TestTString K");
00650 DEBUG_FREE_HEAP();
00651
00652 _TestStringRight();
00653 DEBUG_CLEAR_MEM_CHECK_POINTS();
00654 UNIT_ASSERT_MEM_NOTED("TestTString L");
00655 DEBUG_FREE_HEAP();
00656
00657 _TestStringCompOps();
00658 DEBUG_CLEAR_MEM_CHECK_POINTS();
00659 UNIT_ASSERT_MEM_NOTED("TestTString M");
00660 DEBUG_FREE_HEAP();
00661
00662 _TestStringMid();
00663 DEBUG_CLEAR_MEM_CHECK_POINTS();
00664 UNIT_ASSERT_MEM_NOTED("TestTString N");
00665 DEBUG_FREE_HEAP();
00666
00667 _TestStringUpper();
00668 DEBUG_CLEAR_MEM_CHECK_POINTS();
00669 UNIT_ASSERT_MEM_NOTED("TestTString O");
00670 DEBUG_FREE_HEAP();
00671
00672 _TestStringCat();
00673 DEBUG_CLEAR_MEM_CHECK_POINTS();
00674 UNIT_ASSERT_MEM_NOTED("TestTString P");
00675 DEBUG_FREE_HEAP();
00676
00677 _TestStringRTrimRegression1();
00678 DEBUG_CLEAR_MEM_CHECK_POINTS();
00679 UNIT_ASSERT_MEM_NOTED("TestTString Q");
00680 DEBUG_FREE_HEAP();
00681
00682 _TestStringBase64();
00683 DEBUG_CLEAR_MEM_CHECK_POINTS();
00684 UNIT_ASSERT_MEM_NOTED("TestTString 64");
00685 DEBUG_FREE_HEAP();
00686 }
00687
00688 #endif