Back to index

lightning-sunbird  0.9+nobinonly
nsStringTest.h
Go to the documentation of this file.
00001 /********************************************************************************************
00002  *
00003  * MODULES NOTES:
00004  *
00005  *  This file is designed to help test the new nsString classes.
00006  * 
00007  * Contributor(s):
00008  *   Rick Gessner <rickg@netscape.com>
00009  * 
00010  * History:
00011  *
00012  *  02.29.2000: Original files (rickg)
00013  *  03.02.2000: Flesh out the interface to be compatible with old library (rickg)
00014  *  
00015  ********************************************************************************************/
00016 
00017 #ifndef _STRINGTEST
00018 #define _STRINGTEST
00019 
00020 
00021 #include "nsString.h"
00022 #include "nsReadableUtils.h"
00023 #include <time.h>
00024 
00025 #define USE_STL 
00026 
00027 #ifdef USE_STL
00028 #include <string>
00029 using namespace std;
00030 #endif
00031 
00032 #define USE_WIDE  1
00033 #ifdef  USE_WIDE
00034   #define stringtype  nsString
00035   #define astringtype nsAutoString
00036   #define chartype    PRUnichar
00037 #else
00038   #define stringtype  nsCString
00039   #define astringtype nsCAutoString
00040   #define chartype    char
00041 #endif
00042 
00043 
00044 #include <stdio.h>
00045 
00046 
00047 
00048 static const char* kConstructorError = "constructor error";
00049 static const char* kComparisonError  = "Comparision error!";
00050 static const char* kEqualsError = "Equals error!";
00051 
00052 static char* kNumbers[]={"0123456789","0\01\02\03\04\05\06\07\08\09\0\0\0"};
00053 static char* kLetters[]={"abcdefghij","a\0b\0c\0d\0e\0f\0g\0h\0i\0j\0\0\0"};
00054 static char* kAAA[]={"AAA","A\0A\0A\0\0\0"};
00055 static char* kBBB[]={"BBB","B\0B\0B\0\0\0"};
00056 static char* kHello[]={"hello","h\0e\0l\0l\0o\0\0\0"};
00057 static char* kWSHello[]={"  hello  "," \0 \0h\0e\0l\0l\0o\0 \0 \0\0\0"};
00058 
00059 
00060 
00061 /********************************************************
00062   
00063     This class's only purpose in life is to test the 
00064     netscape string library. We exercise the string
00065     API's here, and do a bit of performance testing
00066     against the standard c++ library string (from STL).
00067 
00068  ********************************************************/
00069 class CStringTester {
00070 public:
00071   CStringTester() {
00072     TestConstructors();
00073     TestAutoStrings();
00074     TestAppend();
00075     TestAssignAndAdd();
00076     TestInsert();
00077     TestDelete();
00078     TestTruncate();
00079     TestLogical();
00080     TestLexomorphic();
00081     TestCreators();
00082     TestNumerics();
00083     TestExtractors();
00084     TestSearching();
00085     TestSubsumables();
00086     TestRandomOps();
00087     TestReplace();
00088     TestRegressions();
00089     TestStringPerformance();
00090     TestWideStringPerformance();
00091   }
00092 protected:
00093     int TestConstructors();
00094     int TestLogical();
00095     int TestAutoStrings();
00096     int TestAppend();
00097     int TestAssignAndAdd();
00098     int TestInsert();
00099     int TestDelete();
00100     int TestTruncate();
00101     int TestLexomorphic();
00102     int TestCreators();
00103     int TestNumerics();
00104     int TestExtractors();
00105     int TestSearching();
00106     int TestSubsumables();
00107     int TestRandomOps();
00108     int TestReplace();
00109     int TestStringPerformance();
00110     int TestWideStringPerformance();
00111     int TestRegressions();
00112 };
00113 
00114 
00115 class Stopwatch {
00116 public:
00117   Stopwatch() {
00118     start=clock();
00119   }
00120 
00121   void Stop() {
00122     stop=clock();
00123   }
00124 
00125   double Elapsed() {
00126     return (double)(stop - start) / CLOCKS_PER_SEC;
00127   }
00128 
00129   void Print(const char* msg= "") {
00130     printf("%s %f\n",msg,Elapsed());
00131   }
00132   
00133   clock_t start,stop;
00134 };
00135 
00142 int CStringTester::TestSearching(){
00143   int result=0;
00144 
00145 
00146 
00147   PRUnichar pbuf[10]={'e','f','g',0};
00148   PRUnichar pbuf2[10]={'a','b','c',0};
00149 
00150 
00151   //Since there is so much ground to cover with searching, we use a typedef to 
00152   //allow you to vary the string type being searched...
00153 
00154 
00155   stringtype theDest("abcdefghijkabc");
00156   nsString  s1("ijk");
00157   nsCString c1("ijk");
00158 
00159   PRInt32 pos=theDest.Find(pbuf);
00160   NS_ASSERTION(pos==4,"Error: Find routine");
00161 
00162   pos=theDest.Find(pbuf2,PR_FALSE,-1);
00163   NS_ASSERTION(pos==0,"Error: Find routine");
00164 
00165   pos=theDest.Find(pbuf2,PR_FALSE,pos+1);
00166   NS_ASSERTION(pos==11,"Error: Find routine");
00167 
00168   pos=theDest.FindChar('a');
00169   NS_ASSERTION(pos==0,"Error: Find routine");
00170 
00171   pos=theDest.FindChar('a',PR_FALSE,pos+1);
00172   NS_ASSERTION(pos==11,"Error: Find routine");
00173 
00174   pos=theDest.Find("efg");
00175   NS_ASSERTION(pos==4,"Error: Find routine");
00176 
00177   pos=theDest.Find("EFG",PR_TRUE);
00178   NS_ASSERTION(pos==4,"Error: Find routine");
00179 
00180   pos=theDest.FindChar('d');
00181   NS_ASSERTION(pos==3,"Error: Find char routine");
00182 
00183   pos=theDest.Find(s1);
00184   NS_ASSERTION(pos==8,"Error: Find char routine");
00185 
00186   pos=theDest.FindCharInSet("12k");
00187   NS_ASSERTION(pos==10,"Error: Findcharinset routine");
00188 
00189   pos=theDest.FindCharInSet(pbuf);
00190   NS_ASSERTION(pos==4,"Error: Findcharinset routine");
00191 
00192   pos=theDest.FindCharInSet(s1);
00193   NS_ASSERTION(pos==8,"Error: Findcharinset routine");
00194 
00195   pos=theDest.Find("efg",PR_FALSE,2);
00196   NS_ASSERTION(pos==4,"Error: Find routine");
00197 
00198   pos=theDest.RFindCharInSet("12k");
00199   NS_ASSERTION(pos==10,"Error: RFindcharinset routine");
00200 
00201   pos=theDest.RFindCharInSet("xyz");
00202   NS_ASSERTION(pos==-1,"Error: RFindcharinset routine");
00203 
00204   pos=theDest.RFindCharInSet(pbuf);
00205   NS_ASSERTION(pos==6,"Error: RFindcharinset routine");
00206 
00207   pos=theDest.RFindCharInSet(s1);
00208   NS_ASSERTION(pos==10,"Error: RFindcharinset routine");
00209 
00210   pos=theDest.RFind("efg");
00211   NS_ASSERTION(pos==4,"Error: RFind routine");
00212 
00213   pos=theDest.RFind("xxx");
00214   NS_ASSERTION(pos==-1,"Error: RFind routine"); //this should fail
00215 
00216   pos=theDest.RFind("");
00217   NS_ASSERTION(pos==-1,"Error: RFind routine"); //this too should fail.
00218 
00219   pos=theDest.RFindChar('a',PR_FALSE,4);
00220   NS_ASSERTION(pos==-1,"Error: RFind routine");
00221 
00222 
00223     //now try searching with FindChar using offset and count...
00224   {
00225     stringtype s1("hello there rick");
00226 
00227     PRInt32 pos=s1.FindChar('r');  //this will search from the beginning, and for the length of the string.
00228     NS_ASSERTION(pos==9,"Error: FindChar() with offset and count");
00229 
00230     pos=s1.FindChar('r',PR_FALSE,0,5);  //this will search from the front using count. THIS WILL FAIL!
00231     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00232 
00233     pos=s1.FindChar('r',PR_FALSE,0,10);  //this will search from the front using count. THIS WILL SUCCEED!
00234     NS_ASSERTION(pos==9,"Error: FindChar() with offset and count");
00235 
00236     pos=s1.FindChar('i',PR_FALSE,5,5);  //this will search from the middle using count. THIS WILL FAIL!
00237     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00238 
00239     pos=s1.FindChar('i',PR_FALSE,5,10);  //this will search from the middle using count. THIS WILL SUCCEED!
00240     NS_ASSERTION(pos==13,"Error: FindChar() with offset and count");
00241 
00242     pos=s1.FindChar('k',PR_FALSE,10,2);  //this will search from near the end using count. THIS WILL FAIL!
00243     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00244 
00245     pos=s1.FindChar('k',PR_FALSE,10,7);  //this will search from near the end using count. THIS WILL SUCCEED!
00246     NS_ASSERTION(pos==15,"Error: FindChar() with offset and count");
00247 
00248     //now let's try a few with bad data...
00249 
00250     pos=s1.FindChar('k',PR_FALSE,100,2);  //this will search from a bad offset. THIS WILL FAIL!
00251     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00252 
00253     pos=s1.FindChar('k',PR_FALSE,10,0);  //this will search for a bad count. THIS WILL FAIL!
00254     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00255 
00256     pos=s1.FindChar('k',PR_FALSE,10,20);  //this will search for a bad count. THIS WILL SUCCEED!
00257     NS_ASSERTION(pos==15,"Error: FindChar() with offset and count");
00258 
00259     pos=s1.FindChar('k',PR_FALSE,10,4);  //this will search for a bad count. THIS WILL FAIL!
00260     NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count");
00261 
00262     pos=10;
00263   }
00264 
00265     //now try searching with RFindChar using offset and count...
00266   {
00267     stringtype s1("hello there rick");
00268 
00269     PRInt32 pos=s1.RFindChar('o');  //this will search from the end, and for the length of the string.
00270     NS_ASSERTION(pos==4,"Error: RFindChar() with offset and count");
00271 
00272     pos=s1.RFindChar('i');  //this will search from the end, and for the length of the string.
00273     NS_ASSERTION(pos==13,"Error: RFindChar() with offset and count");
00274 
00275     pos=s1.RFindChar(' ',PR_FALSE,-1,4);  //this will search from the end, and for the length of the string.
00276     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); //THIS WILL FAIL
00277 
00278     pos=s1.RFindChar(' ',PR_FALSE,12,1);  //this will search from the middle, and for the length of 1.
00279     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); //THIS WILL FAIL
00280 
00281     pos=s1.RFindChar(' ',PR_FALSE,12,2);  //this will search from the middle, and for the length of 2.
00282     NS_ASSERTION(pos==11,"Error: RFindChar() with offset and count"); //THIS WILL SUCCEED
00283 
00284     pos=s1.RFindChar('o',PR_FALSE,-1,5);  //this will search from the end using count. THIS WILL FAIL!
00285     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count");
00286 
00287     pos=s1.RFindChar('o',PR_FALSE,-1,12);  //this will search from the front using count. THIS WILL SUCCEED!
00288     NS_ASSERTION(pos==4,"Error: RFindChar() with offset and count");
00289 
00290     pos=s1.RFindChar('l',PR_FALSE,8,2);  //this will search from the middle using count. THIS WILL FAIL!
00291     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count");
00292 
00293     pos=s1.RFindChar('l',PR_FALSE,8,7);  //this will search from the middle using count. THIS WILL SUCCEED!
00294     NS_ASSERTION(pos==3,"Error: RFindChar() with offset and count");
00295 
00296 //***
00297 
00298     pos=s1.RFindChar('h',PR_FALSE,3,2);  //this will search from near the end using count. THIS WILL FAIL!
00299     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count");
00300 
00301     pos=s1.RFindChar('h',PR_FALSE,3,7);  //this will search from near the end using count. THIS WILL SUCCEED!
00302     NS_ASSERTION(pos==0,"Error: RFindChar() with offset and count");
00303 
00304     //now let's try a few with bad data...
00305 
00306     pos=s1.RFindChar('k',PR_FALSE,100,2);  //this will search from a bad offset. THIS WILL FAIL!
00307     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count");
00308 
00309     pos=s1.RFindChar('k',PR_FALSE,10,0);  //this will search for a bad count. THIS WILL FAIL!
00310     NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count");
00311 
00312     pos=10;
00313   }
00314 
00315     //now try searching with Find() using offset and count...
00316   {
00317     stringtype s1("hello there rick");
00318 
00319     PRInt32 pos= s1.Find("there",PR_FALSE,0,4); //first search from front using offset
00320     NS_ASSERTION(pos==-1,"Error: Find() with offset and count");  //THIS WILL FAIL
00321 
00322     pos= s1.Find("there",PR_FALSE,0,8); //first search from front using count
00323     NS_ASSERTION(pos==6,"Error: Find) with offset and count");  //THIS WILL SUCCEED
00324 
00325     pos= s1.Find("there",PR_FALSE,4,1); //first search from front using count
00326     NS_ASSERTION(pos==-1,"Error: Find() with offset and count");  //THIS WILL FAIL
00327 
00328     pos= s1.Find("there",PR_FALSE,5,2); //first search from front using count
00329     NS_ASSERTION(pos==6,"Error: Find() with offset and count");  //THIS WILL SUCCEED
00330 
00331     pos= s1.Find("there",PR_FALSE,6,1); //first search from front using count
00332     NS_ASSERTION(pos==6,"Error: Find() with offset and count");  //THIS WILL SUCCEED
00333 
00334     pos= s1.Find("there",PR_FALSE,6,0); //first search from front using a bogus count
00335     NS_ASSERTION(pos==-1,"Error: Find() with offset and count");  //THIS WILL FAIL
00336     
00337     pos= s1.Find("k",PR_FALSE,15,1); //first search from end using a count
00338     NS_ASSERTION(pos==15,"Error: Find() with offset and count");  //THIS WILL SUCCEED
00339 
00340     pos= s1.Find("k",PR_FALSE,15,10); //first search from end using a LARGE count
00341     NS_ASSERTION(pos==15,"Error: Find() with offset and count");  //THIS WILL SUCCEED
00342 
00343     pos= s1.Find("k",PR_FALSE,25,10); //first search from bogus offset using a LARGE count
00344     NS_ASSERTION(pos==-1,"Error: Find() with offset and count");  //THIS WILL FAIL
00345 
00346     pos=10;
00347   }
00348 
00349         //now try substringsearching with RFind() using offset and count...
00350   {
00351     nsString s1("abcdefghijklmnopqrstuvwxyz");
00352 
00353     PRInt32 pos= s1.RFind("ghi"); //first search from end using count
00354     NS_ASSERTION(pos==6,"Error: RFind() with offset and count");  //THIS WILL SUCCEED!
00355 
00356     pos= s1.RFind("nop",PR_FALSE,-1,4); //first search from end using count
00357     NS_ASSERTION(pos==-1,"Error: RFind() with offset and count");  //THIS WILL FAIL
00358 
00359     pos= s1.RFind("nop",PR_FALSE,-1,15); //first search from end using count
00360     NS_ASSERTION(pos==13,"Error: RFind() with offset and count");  //THIS WILL SUCCEED
00361 
00362     pos= s1.RFind("nop",PR_FALSE,16,3); //first search from middle using count
00363     NS_ASSERTION(pos==-1,"Error: RFind() with offset and count");  //THIS WILL FAIL
00364 
00365     pos= s1.RFind("nop",PR_FALSE,16,7); //first search from middle using count
00366     NS_ASSERTION(pos==13,"Error: RFind() with offset and count");  //THIS WILL SUCCEED
00367 
00368     pos= s1.RFind("nop",PR_FALSE,0,1); //first search from front using count
00369     NS_ASSERTION(pos==-1,"Error: RFind() with offset and count");  //THIS WILL FAIL
00370 
00371     pos= s1.RFind("abc",PR_FALSE,0,1); //first search from middle using count
00372     NS_ASSERTION(pos==0,"Error: RFind() with offset and count");  //THIS WILL SUCCEED
00373 
00374     pos= s1.RFind("foo",PR_FALSE,10,100); //first search from front using bogus count
00375     NS_ASSERTION(pos==-1,"Error: RFind() with offset and count");  //THIS WILL FAIL
00376 
00377     pos= s1.RFind("ghi",PR_FALSE,30,1); //first search from middle using bogus offset
00378     NS_ASSERTION(pos==-1,"Error: RFind() with offset and count");  //THIS WILL FAIL
00379 
00380     pos=10;
00381   }
00382 
00383     //Various UNICODE tests...
00384   {
00385       //do some searching against chinese unicode chars...
00386 
00387     PRUnichar chinese[] = {0x4e41,0x4e42, 0x4e43, 0x0000}; // 3 chinese  unicode
00388 
00389     nsString  T2(chinese);
00390     nsString  T2copy(chinese); 
00391 
00392     pos = T2.FindCharInSet("A");
00393     NS_ASSERTION(kNotFound==pos,"Error in FindCharInSet");
00394 
00395     pos=T2.RFindCharInSet("A",2);
00396     NS_ASSERTION(kNotFound==pos,"Error in RFindCharInSet");
00397 
00398     pos=T2.Find("A", PR_FALSE, 0, 1);
00399     NS_ASSERTION(kNotFound==pos,"Error in Find");
00400 
00401     pos=T2.RFind("A", PR_FALSE, 2, 1);
00402     NS_ASSERTION(kNotFound==pos,"Error in RFind");
00403 
00404     T2.ReplaceChar("A",' ');
00405     NS_ASSERTION(T2==T2copy,"Error in ReplaceChar");
00406 
00407       //Here's the 3rd FTang unicode test...
00408 
00409     static char test4[]="ABCDEF";
00410     static char test4b[]=" BCDEF";
00411     
00412     PRUnichar test5[]={0x4e41, 0x0000};
00413     PRUnichar test6[]={0x0041, 0x0000};
00414  
00415     nsCString T4(test4);
00416     nsCString T4copy(test4);
00417     nsCString T4copyb(test4b);
00418     nsCString T5(test5);
00419     nsCString T6(test6);
00420  
00421     pos = T4.FindCharInSet(T5.get());
00422     NS_ASSERTION(0==pos,"Error in FindcharInSet"); //This should succeed.
00423 
00424     pos = T4.FindCharInSet(T6.get());
00425     NS_ASSERTION(kNotFound<pos,"Error in FindcharInSet");  //This should succeed.
00426 
00427     pos = T4.RFindCharInSet(T5.get(),2);
00428     NS_ASSERTION(0==pos,"Error in RFindCharInSet");  //This should fail.
00429 
00430     pos = T4.RFindCharInSet(T6.get(),2);
00431     NS_ASSERTION(kNotFound<pos,"Error in RFindCharInSet");  //This should fail.
00432 
00433     pos = T4.Find(T5.get(), PR_FALSE, 0, 1);
00434     NS_ASSERTION(0==pos,"Error in Find");  //This should succeed.
00435 
00436     pos= T4.Find(T6.get(), PR_FALSE, 0, 1);
00437     NS_ASSERTION(kNotFound<pos,"Error in Find"); //This should fail.
00438 
00439     pos = T4.RFind(T5.get(), PR_FALSE, 2, 1);
00440     NS_ASSERTION(kNotFound==pos,"Error in RFind");
00441     
00442     pos =T4.RFind(T6.get(), PR_FALSE, 2, 1);
00443     NS_ASSERTION(kNotFound==pos,"Error in RFind");
00444 
00445 
00446 /*  
00447   NOT WORKING IN NEW STRING YET...
00448 
00449     T4.ReplaceChar(PRUnichar(0x4E41),PRUnichar(' '));
00450     if(T4 != T4copy)
00451        printf("nsCString::ReplaceChar(PRUnichar, PRUnichar) error- replace when it should not\n");
00452 
00453     T4 = test4;
00454     T4.ReplaceChar(PRUnichar(0x0041),PRUnichar(' '));
00455     if(T4 != T4copyb)
00456        printf("nsCString::ReplaceChar(PRUnichar, PRUnichar) error- not replace when it should\n");
00457 
00458 */
00459 
00460   } 
00461 
00462     return result;
00463 }
00464 
00471 int CStringTester::TestConstructors(){
00472   int result=0;
00473   PRUnichar  pbuf[10]={'f','o','o',0};
00474   PRUnichar*  buf=pbuf;
00475 
00476   nsString  s1("hello world");
00477   nsCString c1("what's up");
00478 
00479 
00480   //Test nsCString constructors...
00481   {
00482     nsCString temp0; 
00483     nsCString temp1(s1);
00484     NS_ASSERTION(temp1==s1,"nsCString Constructor error");
00485 
00486     nsCString temp2(c1);
00487     NS_ASSERTION(temp2==c1,"nsCString Constructor error");
00488   
00489     nsCString temp3("hello world");
00490     NS_ASSERTION(temp3=="hello world","nsCString Constructor error");
00491   
00492     nsCString temp4(pbuf);
00493     NS_ASSERTION(temp4==pbuf,"nsCString Constructor error");
00494   
00495     nsCString temp5('a');
00496     NS_ASSERTION(temp5=="a","nsCString Constructor error");
00497   
00498     nsCString temp6(PRUnichar('a'));
00499     NS_ASSERTION(temp5=="a","nsCString Constructor error");
00500   }
00501 
00502     //now just for fun, let's construct 2byte from 1byte and back...
00503   {
00504     nsCString temp0("hello");
00505     nsString  temp1(temp0);
00506     nsCString temp2(temp1);
00507   }
00508 
00509   return result;
00510 }
00511 
00518 int CStringTester::TestLogical(){
00519   int result=0;
00520   stringtype temp8("aaaa");
00521   stringtype temp8a("AAAA");
00522   stringtype  temp9("bbbb");
00523 
00524   const char* aaaa="aaaa";
00525   const char* bbbb="bbbb";
00526 
00527 
00528     //First, test a known error that got checked into the tree...
00529   {
00530     nsString mURL("file:///c|/test/foo.txt");
00531     PRBool result=mURL.Equals("file:/",PR_FALSE);
00532     NS_ASSERTION(!result,kEqualsError);
00533     result=mURL.Equals("file:/",PR_FALSE,5);
00534     NS_ASSERTION(result,kEqualsError);
00535     result=mURL.Equals("file:/",PR_FALSE,-1);
00536     NS_ASSERTION(!result,kEqualsError);
00537 
00538     nsString s1("rick");
00539     result=s1.Equals("rick",PR_FALSE,6);
00540     result++;
00541   }
00542 
00543 
00544   {
00545     //this little piece of code tests to see whether the PL_strcmp series works
00546     //correctly even when we have strings whose buffers contain nulls.
00547 
00548     char *buf1 = "what's up \0\0 doc?";
00549     char *buf2 = "what's up \0\0 dog?";
00550 
00551     nsString s1(buf2,17);
00552 
00553     PRInt32 result=s1.Compare(buf1,PR_TRUE,17);
00554     result=s1.FindChar('?');
00555     result++;  
00556   }
00557 
00558   {
00559     nsString foo("#text");
00560     PRInt32 cmp=foo.Compare("pre",PR_FALSE,-1);
00561     cmp=cmp;
00562   }
00563 
00564     //First test the string compare routines...
00565 
00566   NS_ASSERTION(0>temp8.Compare(bbbb),kComparisonError);
00567   NS_ASSERTION(0>temp8.Compare(temp9),kComparisonError);
00568   NS_ASSERTION(0<temp9.Compare(temp8),kComparisonError);
00569   NS_ASSERTION(0==temp8.Compare(temp8a,PR_TRUE),kComparisonError);
00570   NS_ASSERTION(0==temp8.Compare(aaaa),kComparisonError);
00571 
00572     //Now test the boolean operators...
00573   NS_ASSERTION(temp8==temp8,kComparisonError);
00574   NS_ASSERTION(temp8==aaaa,kComparisonError);
00575 
00576   NS_ASSERTION(temp8!=temp9,kComparisonError);
00577   NS_ASSERTION(temp8!=bbbb,kComparisonError);
00578 
00579   NS_ASSERTION(((temp8<temp9) && (temp9>=temp8)),kComparisonError);
00580 
00581   NS_ASSERTION(((temp9>temp8) && (temp8<=temp9)),kComparisonError);
00582   NS_ASSERTION(temp9>aaaa,kComparisonError);
00583 
00584   NS_ASSERTION(temp8<=temp8,kComparisonError);
00585   NS_ASSERTION(temp8<=temp9,kComparisonError);
00586   NS_ASSERTION(temp8<=bbbb,kComparisonError);
00587 
00588   NS_ASSERTION(((temp9>=temp8) && (temp8<temp9)),kComparisonError);
00589   NS_ASSERTION(temp9>=temp8,kComparisonError);
00590   NS_ASSERTION(temp9>=aaaa,kComparisonError);
00591 
00592   NS_ASSERTION(temp8.Equals(temp8),kEqualsError);
00593   NS_ASSERTION(temp8.Equals(aaaa),kEqualsError);
00594   
00595   stringtype temp10(temp8);
00596   ToUpperCase(temp10);
00597   NS_ASSERTION(temp8.Equals(temp10,PR_TRUE),kEqualsError);
00598   NS_ASSERTION(temp8.Equals("AAAA",PR_TRUE),kEqualsError);
00599 
00600 
00601     //now test the new string Equals APIs..
00602   {
00603     nsCString s1("hello there");
00604     NS_ASSERTION(s1.Equals("hello there"),kEqualsError);
00605     NS_ASSERTION(s1.Equals("hello rick",PR_FALSE,5),kEqualsError);
00606     NS_ASSERTION(!s1.Equals("hello rick",PR_FALSE-1),kEqualsError);
00607 
00608     nsCString s2("");
00609     NS_ASSERTION(s2.Equals(""),kEqualsError);
00610 
00611     nsCString s3("view-source:");
00612     NS_ASSERTION(s3.Equals("VIEW-SOURCE:",PR_TRUE,12),kEqualsError);
00613   }
00614 
00615     //now test the count argument...
00616   {
00617     nsString s1("rickgessner");
00618     nsString s2("rickricardo");
00619     PRInt32 result=s1.Compare(s2);  //assume no case conversion, and full-length comparison...
00620     result=s1.Compare(s2,PR_FALSE,4);
00621     result=s1.Compare(s2,PR_FALSE,5);
00622 
00623     PRBool  b=s1.Equals(s2);
00624     b=s1.Equals("rick",PR_FALSE,4);  
00625     b=s1.Equals("rickz",PR_FALSE,5);  
00626 
00627     result=10;
00628 
00629     nsString s3("view");
00630 
00631 #define kString "view-source"
00632 
00633     b=s3.Equals(kString);
00634     result=10;
00635   }
00636 
00637   return result;
00638 }
00639 
00646 int CStringTester::TestAssignAndAdd(){
00647   int result=0;
00648 
00649   static const char* s1="hello";
00650   static const char* s2="world";
00651   static const PRUnichar pbuf[] = {' ','w','o','r','l','d',0};
00652 
00653   nsString ns1("I'm an nsString");
00654   nsCString nc1("I'm an nsCString");
00655 
00656   nsAutoString as1("nsAutoString source");
00657   nsCAutoString ac1("nsCAutoString source");
00658 
00659 
00660   {
00661       //****  Test assignments to nsCString...
00662 
00663     nsCString theDest;
00664     theDest.Assign(theDest);  //assign nsString to itself
00665     theDest.Assign(ns1);  //assign an nsString to an nsString
00666     NS_ASSERTION(theDest==ns1,"Assignment error");
00667 
00668     theDest.Assign(nc1);  //assign an nsCString to an nsString
00669     NS_ASSERTION(theDest==nc1,"Assignment error");
00670     
00671     theDest.Assign(as1); //assign an nsAutoString to an nsString
00672 //    NS_ASSERTION(theDest==as1,"Assignment error");
00673     
00674     theDest.Assign(ac1); //assign an nsCAutoString to an nsString
00675 //    NS_ASSERTION(theDest==ac1,"Assignment error");
00676     
00677     theDest.Assign("simple char*");  //assign a char* to an nsString
00678     NS_ASSERTION(theDest=="simple char*","Assignment error");
00679     
00680     theDest.Assign(pbuf);  //assign a PRUnichar* to an nsString
00681     NS_ASSERTION(theDest==pbuf,"Assignment error");
00682     
00683     theDest.Assign('!');  //assign a char to an nsString
00684     NS_ASSERTION(theDest=="!","Assignment error");
00685     
00686     theDest.Assign(PRUnichar('$'));  //assign a char to an nsString
00687     NS_ASSERTION(theDest=="$","Assignment error");
00688 
00689     theDest=ns1;
00690     NS_ASSERTION(theDest==ns1,"Assignment error");
00691     
00692     theDest=nc1;
00693     NS_ASSERTION(theDest==nc1,"Assignment error");
00694     
00695     theDest='a';
00696     NS_ASSERTION(theDest=="a","Assignment error");
00697     
00698     theDest=PRUnichar('a');
00699     NS_ASSERTION(theDest=="a","Assignment error");
00700     
00701     theDest=s1;
00702     NS_ASSERTION(theDest==s1,"Assignment error");
00703     
00704     theDest=pbuf;
00705     NS_ASSERTION(theDest==pbuf,"Assignment error");
00706 
00707   } 
00708 
00709     //test operator+()...
00710   {
00711 
00712   /* NOT WORKING YET...
00713     nsString s1("hello");
00714     nsString s2(" world");
00715     nsCString c1(" world");
00716     
00717     stringtype theDest;
00718     
00719     theDest=s1+s2;
00720     NS_ASSERTION(theDest=="hello world","Assignment error");
00721 
00722     theDest=s1+c1;
00723     NS_ASSERTION(theDest=="hello world","Assignment error");
00724 
00725     theDest=s1+" world";
00726     NS_ASSERTION(theDest=="hello world","Assignment error");
00727 
00728     theDest=s1+pbuf;
00729     NS_ASSERTION(theDest=="hello world","Assignment error");
00730 
00731     theDest=s1+'!';
00732     NS_ASSERTION(theDest=="hello!","Assignment error");
00733 
00734     theDest=s1+PRUnichar('!');
00735     NS_ASSERTION(theDest=="hello!","Assignment error");
00736 */
00737     
00738   }
00739 
00740   return result;
00741 }
00742 
00743 
00750 int CStringTester::TestAppend(){
00751   int result=0;
00752 
00753 
00754   static const char* s1="hello";
00755   static const char* s2="world";
00756   static const PRUnichar pbuf[] = {' ','w','o','r','l','d',0};
00757   static const PRUnichar pbuf1[] = {'a','b','c','d','l','d'};
00758 
00759 
00760   stringtype theDest;
00761   theDest.Append((float)100.100);
00762   NS_ASSERTION(theDest=="100.1","Append(float) error");
00763 
00764   theDest.Truncate();
00765   theDest.Append(12345);
00766   NS_ASSERTION(theDest=="12345","Append(int) error");
00767 
00768   theDest.Truncate();
00769   theDest.Append(pbuf1,1);
00770   NS_ASSERTION(theDest=="a","Append(PRUnichar*,count) error");
00771 
00772   theDest.Truncate();
00773   theDest.Append('a');
00774   NS_ASSERTION(theDest=="a","Append(char) error");
00775 
00776 
00777   static const PRUnichar pbuf2[] = {'w','h','a','t','s',' ','u','p',' ','d','o','c','?',0};
00778 
00779   theDest.Truncate();
00780   theDest.Append(pbuf,20); //try appending more chars than actual length of pbuf
00781   NS_ASSERTION(theDest!=pbuf,"Append(PRUnichar*) error");
00782   //(NOTE: if you tell me to append X chars, I'll assume you really have X chars, and the length
00783   //       get's set accordingly. This test really is correct; it just seems odd.
00784 
00785   theDest.Truncate(0);
00786   theDest.Append(pbuf,5); //try appending fewer chars than actual length of pbuf
00787   NS_ASSERTION(theDest==" worl","Append(PRUnichar*) error");
00788 
00789   theDest.Truncate(0);
00790   theDest.Append(pbuf);    //try appending all of pbuf
00791   NS_ASSERTION(theDest==pbuf,"Append(PRUnichar*) error");
00792 
00793   char* ss=0;
00794   theDest.Truncate();
00795   theDest.Append(ss);       //try appending NULL
00796   NS_ASSERTION(theDest=="","Append(nullstr) error");
00797 
00798   theDest.Append(pbuf,0);   //try appending nothing
00799   NS_ASSERTION(theDest=="","Append(nullstr) error");
00800 
00801 
00802   {
00803     //test improvement to unichar appends...
00804     stringtype s1("hello");
00805     char c='!';
00806     s1+=c;
00807     NS_ASSERTION(s1=="hello!","operator+=() error");
00808 
00809     c=(char)0xfa;
00810     s1+=c;
00811     s1.Append(c);
00812 
00813     PRUnichar theChar='f';
00814     s1+=theChar;
00815 
00816     char theChar2='g';
00817     s1+=theChar2;
00818 
00819 //    long theLong= 1234;
00820 //    s1+=theLong;
00821 
00822   }
00823 
00824   {
00825       //this just proves we can append nulls in our buffers...
00826     stringtype c("hello");
00827     stringtype s(" there");
00828     c.Append(s);
00829     char buf[]={'a','b',0,'d','e'};
00830     s.Append(buf,5);
00831   }
00832 
00833 
00834   stringtype temp2("there");
00835 
00836     theDest.Append(temp2);
00837     theDest.Append(" xxx ");
00838     theDest.Append(pbuf);
00839     theDest.Append('4');
00840     theDest.Append(PRUnichar('Z'));
00841 
00842     stringtype a(s1);
00843     stringtype b(s2);
00844 
00845     theDest.Truncate();
00846     temp2.Truncate();
00847 
00848 /* NOT WORKING YET...
00849     theDest=a+b;
00850     temp2=a+"world!";
00851     temp2=a+pbuf;
00852     stringtype temp3;
00853     temp3=temp2+'!';
00854 */
00855   return result;
00856 }
00857 
00858 
00865 int CStringTester::TestExtractors(){
00866   int result=0;
00867 
00868   //first test the 2 byte version...
00869 
00870 
00871   {
00872     nsString temp1("hello there rick");
00873     nsString temp2;
00874 
00875     temp1.Left(temp2,10);
00876     NS_ASSERTION(temp2=="hello ther","Left() error");
00877 
00878     temp1.Mid(temp2,6,5);
00879     NS_ASSERTION(temp2=="there","Mid() error");
00880 
00881     temp1.Right(temp2,4);
00882     NS_ASSERTION(temp2=="rick","Right() error");
00883 
00884       //Now test the character accessor methods...
00885     nsString theString("hello");
00886     PRUint32 len=theString.Length();
00887     PRUnichar theChar;
00888     for(PRUint32 i=0;i<len;i++) {
00889       theChar=theString.CharAt(i);
00890     }
00891 
00892 /* NOT WORKING YET...
00893     theChar=theString.First();
00894     theChar=theString.Last();
00895     theChar=theString[3];
00896     theString.SetCharAt('X',3);
00897 */
00898   }
00899 
00900     //now test the 1 byte version
00901   {
00902     nsCString temp1("hello there rick");
00903     nsCString temp2;
00904     temp1.Left(temp2,10);
00905     temp1.Mid(temp2,6,5);
00906     temp1.Right(temp2,4);
00907 
00908       //Now test the character accessor methods...
00909     nsCString theString("hello");
00910     PRUint32 len=theString.Length();
00911     char ch;
00912     for(PRUint32 i=0;i<len;i++) {
00913       ch=theString.CharAt(i);
00914     }
00915 
00916 /* NOT WORKING YET...
00917 
00918     ch=theString.First();
00919     ch=theString.Last();
00920     ch=theString[3];
00921     theString.SetCharAt('X',3);
00922 */
00923   }
00924 
00925 
00926   return result;
00927 }
00928 
00929 
00930 
00937 int CStringTester::TestCreators(){
00938   int result=0;
00939 
00940 /* NOT WORKING YET
00941   {
00942     nsString  theString5("");
00943     char* str0 = ToNewCString(theString5);
00944     Recycle(str0);
00945 
00946     theString5+="hello rick";
00947     nsString* theString6=theString5.ToNewString();
00948     delete theString6;
00949 
00950     nsString  theString1("hello again");
00951     PRUnichar* thePBuf=ToNewUnicode(theString1);
00952     if(thePBuf)
00953       Recycle(thePBuf);
00954 
00955     char* str = ToNewCString(theString5);
00956     if(str)
00957       Recycle(str);
00958 
00959     char buffer[6];
00960     theString5.ToCString(buffer,sizeof(buffer));
00961     
00962   }
00963 
00964   {
00965     nsCString  theString5("hello rick");
00966     nsCString* theString6=theString5.ToNewString();
00967     delete theString6;
00968 
00969     PRUnichar* thePBuf=ToNewUnicode(theString5);
00970     if(thePBuf)
00971       Recycle(thePBuf);
00972 
00973     char* str = ToNewCString(theString5);
00974     if(str)
00975       Recycle(str);
00976 
00977     char buffer[100];
00978     theString5.ToCString(buffer,sizeof(buffer)-1);
00979     nsCString  theOther=theString5.GetBuffer();
00980   }
00981   */
00982   return result;
00983 }
00984 
00985 
00992 int CStringTester::TestInsert(){
00993   int result=0;
00994 
00995   {
00996     static const char pbuf[] = " world";
00997 
00998     nsCString temp1("hello rick");
00999     temp1.Insert("there ",6); //char* insertion
01000     NS_ASSERTION(temp1=="hello there rick","Insert error");
01001 
01002     temp1.Insert(pbuf,3); //prunichar* insertion
01003     NS_ASSERTION(temp1=="hel worldlo there rick","Insert error");
01004 
01005     temp1.Insert("?",10); //char insertion
01006     NS_ASSERTION(temp1=="hel worldl?o there rick","Insert error");
01007 
01008     temp1.Insert('*',10); //char insertion
01009     NS_ASSERTION(temp1=="hel worldl*?o there rick","Insert error");
01010 
01011     temp1.Insert("xxx",100,3); //this should append.
01012     NS_ASSERTION(temp1=="hel worldl*?o there rickxxx","Insert error");
01013 
01014     nsCString temp2("abcdefghijklmnopqrstuvwxyz");
01015 //    temp2.Insert(temp1,10);
01016     temp2.Cut(20,5);
01017     NS_ASSERTION(temp2=="abcdefghijklmnopqrstz","Insert error");
01018 
01019     temp2.Cut(100,100); //this should fail.
01020     NS_ASSERTION(temp2=="abcdefghijklmnopqrstz","Insert error");
01021 
01022   }
01023 
01024   {
01025     static const PRUnichar pbuf[] = {' ','w','o','r','l','d',0};
01026 
01027 
01028     nsString temp1("llo rick");
01029 
01030     temp1.Insert("he",0); //char* insertion
01031     NS_ASSERTION(temp1=="hello rick","Insert error");
01032 
01033     temp1.Insert("there ",6); //char* insertion
01034     NS_ASSERTION(temp1=="hello there rick","Insert error");
01035 
01036     temp1.Insert(pbuf,3); //prunichar* insertion
01037     NS_ASSERTION(temp1=="hel worldlo there rick","Insert error");
01038 
01039     temp1.Insert("?",10); //char insertion
01040     NS_ASSERTION(temp1=="hel worldl?o there rick","Insert error");
01041 
01042     temp1.Insert('*',10); //char insertion
01043     NS_ASSERTION(temp1=="hel worldl*?o there rick","Insert error");
01044 
01045     temp1.Insert("xxx",100,3); //this should append.
01046     NS_ASSERTION(temp1=="hel worldl*?o there rickxxx","Insert error");
01047 
01048     nsString temp2("abcdefghijklmnopqrstuvwxyz");
01049 //    temp2.Insert(temp1,10);
01050     temp2.Cut(20,5);
01051     NS_ASSERTION(temp2=="abcdefghijklmnopqrstz","Insert error");
01052 
01053     temp2.Cut(100,100); //this should fail.
01054     NS_ASSERTION(temp2=="abcdefghijklmnopqrstz","Insert error");
01055 
01056   }
01057 
01058   return result;
01059 }
01060 
01061 
01062  
01069 int CStringTester::TestDelete(){
01070   int result=0;
01071   
01072   //NOTE: You need to run this test program twice for this method to work. 
01073   //      Once with USE_WIDE defined, and once without (to test nsCString)
01074 
01075     //let's try some whacky string deleting calls
01076   {
01077     const char* pbuf = "whats up doc?";
01078 
01079     nsCString s1(pbuf);
01080     s1.Cut(3,20); //try deleting more chars than actual length of pbuf
01081     NS_ASSERTION(s1=="wha","Cut error");
01082 
01083     s1=pbuf;
01084     s1.Cut(3,-10);
01085     NS_ASSERTION(s1==pbuf,"Cut error");
01086 
01087     s1=pbuf;
01088     s1.Cut(3,2);
01089     NS_ASSERTION(s1=="wha up doc?","Cut error");
01090 
01091   }
01092 
01093     //let's try some whacky string deleting calls
01094   {
01095     const PRUnichar pbuf[] = {'w','h','a','t','s',' ','u','p',' ','d','o','c','?',0};
01096 
01097     nsString s1(pbuf);
01098     s1.Cut(3,20); //try deleting more chars than actual length of pbuf
01099     NS_ASSERTION(s1=="wha","Cut error");
01100 
01101     s1=pbuf;
01102     s1.Cut(3,-10);
01103     NS_ASSERTION(s1==pbuf,"Cut error");
01104 
01105     s1=pbuf;
01106     s1.Cut(3,2);
01107     NS_ASSERTION(s1=="wha up doc?","Cut error");
01108   }
01109 
01110 
01111   {
01112     nsCString s;
01113     int i;
01114     for(i=0;i<518;i++) {
01115       s.Append("0123456789");
01116     }
01117     s+="abc";
01118     s.Cut(0,5);
01119   }
01120 
01121   {
01122     astringtype ab("ab");
01123     stringtype abcde("cde");
01124     stringtype cut("abcdef");
01125     cut.Cut(7,10); //this is out of bounds, so ignore...
01126     //cut.DebugDump(cout);
01127     cut.Cut(5,2); //cut last chars
01128     //cut.DebugDump(cout);
01129     cut.Cut(1,1); //cut first char
01130     //cut.DebugDump(cout);
01131     cut.Cut(2,1); //cut one from the middle
01132     //cut.DebugDump(cout);
01133     cut="Hello there Rick";
01134     //cut.DebugDump(cout);
01135 }
01136 
01137   return result;
01138 }
01139 
01146 int CStringTester::TestTruncate(){
01147   int result=0;
01148     //test delete against a twobyte string...
01149 
01150   {
01151     nsCString s0;
01152     nsCString s1(kNumbers[0]);
01153     s0=s1;
01154     s0.Truncate(100); //should fail
01155     s0.Truncate(5); //should work
01156     s0.Truncate(0); //should work
01157   }
01158 
01159   {
01160     nsString s0;
01161     nsString s1(kNumbers[0]);
01162     s0=s1;
01163     s0.Truncate(100); //should fail
01164     s0.Truncate(5); //should work
01165     s0.Truncate(0); //should work
01166   }
01167   return result;
01168 }
01169 
01176 int CStringTester::TestNumerics(){
01177   int result=0;
01178 
01179   //try a few numeric conversion routines...
01180   {
01181     nsCString str1("-12345");
01182     NS_ASSERTION(str1=="-12345","Append(int) error");
01183 
01184     nsString str2("hello");
01185     nsString str3;
01186     nsString str4("0");
01187     nsString str5("&#183;");
01188     nsString str6("&xi;");
01189     nsString str7("#xe3;");
01190     nsString str8("#FF;");
01191     nsCString str9("-#xa?a;"); //should return -10 (decimal)
01192     nsCString str10("&#191;");
01193     nsCString str11("&#vvv;");
01194     nsCString str12("-vvv;");
01195     nsCString str13("-f");
01196 
01197     PRInt32 err;
01198     PRInt32 theInt=str1.ToInteger(&err);
01199     theInt=str2.ToInteger(&err);
01200     NS_ASSERTION(theInt==14,"ToInteger error");
01201 
01202     theInt=str3.ToInteger(&err);
01203     NS_ASSERTION(theInt==0,"ToInteger error");
01204 
01205     theInt=str4.ToInteger(&err);
01206     NS_ASSERTION(theInt==0,"ToInteger error");
01207 
01208     theInt=str5.ToInteger(&err);
01209     NS_ASSERTION(theInt==183,"ToInteger error");
01210 
01211     theInt=str6.ToInteger(&err);
01212     NS_ASSERTION(theInt==0,"ToInteger error");
01213 
01214     theInt=str7.ToInteger(&err,16);
01215     NS_ASSERTION(theInt==227,"ToInteger error");
01216 
01217     theInt=str8.ToInteger(&err,kAutoDetect);
01218     NS_ASSERTION(theInt==255,"ToInteger error");
01219 
01220     theInt=str9.ToInteger(&err,kAutoDetect);
01221     NS_ASSERTION(theInt==-10,"ToInteger error");
01222 
01223     theInt=str10.ToInteger(&err);
01224     NS_ASSERTION(theInt==191,"ToInteger error");
01225 
01226     theInt=str11.ToInteger(&err);
01227     NS_ASSERTION(theInt==0,"ToInteger error");
01228 
01229     theInt=str12.ToInteger(&err);
01230     NS_ASSERTION(theInt==0,"ToInteger error");
01231 
01232     theInt=str13.ToInteger(&err);
01233     NS_ASSERTION(theInt==-15,"ToInteger error");
01234 
01235 
01236     Stopwatch watch;
01237     int i;
01238     for(i=0;i<1000000;i++){
01239       theInt=str1.ToInteger(&err,16);
01240     }
01241     watch.Stop();
01242     watch.Print("ToInteger() ");
01243 
01244     str1="100.100";
01245     float theFloat=str1.ToFloat(&err);
01246   }
01247   //try a few numeric conversion routines...
01248   {
01249     nsCString str1("10000");
01250     nsCString str2("hello");
01251     nsCString str3;
01252     PRInt32 err;
01253     PRInt32 theInt=str1.ToInteger(&err);
01254     NS_ASSERTION(theInt==10000,"ToInteger error");
01255 
01256     theInt=str2.ToInteger(&err);
01257     NS_ASSERTION(theInt==14,"ToInteger error");
01258     
01259     theInt=str3.ToInteger(&err);
01260     NS_ASSERTION(theInt==0,"ToInteger error");
01261 
01262     str1="100.100";
01263     float theFloat=str1.ToFloat(&err);
01264   }
01265   return 0;
01266 }
01267 
01274 int CStringTester::TestLexomorphic(){
01275   int result=0;
01276     //test delete against a twobyte string...
01277 
01278   //NOTE: You need to run this test program twice for this method to work. 
01279   //      Once with USE_WIDE defined, and once without (to test nsCString)
01280 
01281 
01282   {
01283     nsString theTag("FOO");
01284     nsString theLower;
01285     theTag.ToLowerCase(theLower);
01286     int x=5;
01287   }
01288   
01289   PRUnichar pbuf[] = {'h','e','l','l','o','\n','\n','\n','\n',250,'\n','\n','\n','\n','\n','\n','r','i','c','k',0};
01290 
01291     //and hey, why not do a few lexo-morphic tests...
01292   nsString s0(pbuf);
01293   ToUpperCase(s0);
01294   ToLowerCase(s0);
01295   s0.StripChars("l");
01296   s0.StripChars("\n");
01297   s0.StripChar(250);
01298   NS_ASSERTION(s0=="heorick","Stripchars error");
01299 
01300   {
01301     nsAutoString s1(pbuf);
01302     s1.CompressSet("\n ",' ');
01303   }
01304 
01305   {
01306 
01307     char pbuf[] = { 0x1C, 0x04, 0x1D, 0x04, 0x20, 0x00, 0x2D, 0x00, 0x20, 0x00, 0x23, 0x04, 0x20, 0x00, 0x40, 0x04,
01308                     0x43, 0x04, 0x3B, 0x04, 0x4F, 0x04, 0x20, 0x00, 0x30, 0x04, 0x40, 0x04, 0x3C, 0x04, 0x38, 0x04,
01309                     0x38, 0x04, 0x20, 0x00, 0x2D, 0x00, 0x20, 0x00, 0x32, 0x04, 0x42, 0x04, 0x3E, 0x04, 0x40, 0x04,
01310                     0x3E, 0x04, 0x41, 0x04, 0x42, 0x04, 0x35, 0x04, 0x3F, 0x04, 0x35, 0x04, 0x3D, 0x04, 0x3D, 0x04, 
01311                     0x4B, 0x04, 0x35, 0x04, 0x20, 0x00, 0x3B, 0x04, 0x38, 0x04, 0x46, 0x04, 0x30, 0x04, 0x20, 0x00,
01312                     0x2D, 0x00, 0x20, 0x00, 0x30, 0x00, 0x39, 0x00, 0x2F, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 
01313                     0x30, 0x00, 0x00, 0x00};
01314 
01315     nsAutoString temp((PRUnichar*)pbuf);
01316     nsAutoString temp1(temp);
01317     temp.CompressWhitespace();
01318     PRBool equals=temp.Equals(temp1);
01319 
01320   }
01321 
01322   {
01323     nsString s1("   ");
01324     s1.Trim("; \t");
01325     s1="helvetica";
01326     s1.Trim("; \t");
01327   }
01328 
01329   s0.Insert("  ",0);
01330   NS_ASSERTION(s0=="  heorick","Stripchars error");
01331 
01332   s0.Append("  ");
01333   NS_ASSERTION(s0=="  heorick  ","Stripchars error");
01334   
01335   s0.Trim(" ",PR_TRUE,PR_TRUE);
01336   NS_ASSERTION(s0=="heorick","Stripchars error");
01337 
01338   s0.Append("  abc  123  xyz  ");
01339   s0.CompressWhitespace();
01340   NS_ASSERTION(s0=="heorick abc 123 xyz","CompressWS error");
01341 
01342   s0.ReplaceChar('r','b');
01343   NS_ASSERTION(s0=="heobick abc 123 xyz","ReplaceChar error");
01344 
01345   s0=pbuf;
01346   ToUpperCase(s0);
01347   ToLowerCase(s0);
01348   s0.Append("\n\n\n \r \r \r \t \t \t");
01349   s0.StripWhitespace();
01350 
01351   nsCAutoString s1("\n\r hello \n\n\n\r\r\r\t rick \t\t ");
01352   ToUpperCase(s1);
01353   ToLowerCase(s1);
01354   s1.StripChars("o");
01355   s1.Trim(" ",PR_TRUE,PR_TRUE);
01356   s1.CompressWhitespace();
01357   NS_ASSERTION(s1=="hell rick","Compress Error");
01358 
01359   s1.ReplaceChar('h','w');
01360   NS_ASSERTION(s1=="well rick","Compress Error");
01361 
01362   ToUpperCase(s1);
01363   NS_ASSERTION(s1=="WELL RICK","Compress Error");
01364 
01365   ToLowerCase(s1);
01366   s1.Append("\n\n\n \r \r \r \t \t \t");
01367   s1.StripWhitespace();
01368   NS_ASSERTION(s1=="wellrick","Compress Error");
01369 
01370   {
01371     nsCString temp("aaaa");
01372     int i;
01373     for(i=0;i<100;i++) {
01374       temp+="0123456789.";
01375     }
01376     temp.StripChars("a2468");
01377     i=5;
01378 
01379     temp="   hello rick    ";
01380     temp.StripChars("\n\r\t\b ");
01381     NS_ASSERTION(temp=="hellorick","This isn't good");
01382   }
01383 
01384   return result;
01385 }
01386 
01393 int CStringTester::TestAutoStrings(){
01394   int result=0;
01395 
01396   PRUnichar pbuf[] = {'h','e','l','l','o',0};
01397 
01398   //this test makes sure that autostrings who assume ownership of a buffer, 
01399   //don't also try to copy that buffer onto itself... (was a bug)
01400   {
01401     nsAutoString  temp0; 
01402     nsAutoString  temp1("hello rick");
01403     nsAutoString  temp3(pbuf);
01404 
01405 /*  NOT WORKING...
01406     nsAutoString  temp4(CBufDescriptor((char*)pbuf,PR_TRUE,5,5));
01407 */
01408     nsAutoString  temp5(temp3);
01409     nsString      s(pbuf);
01410     nsAutoString  temp6(s);
01411 
01412 /*  NOT WORKING...
01413     char buffer[500];
01414     nsAutoString  temp7(CBufDescriptor((PRUnichar*)buffer,PR_TRUE,sizeof(buffer)-10/2,0));
01415     temp7="hello, my name is inigo montoya.";
01416 */
01417 
01418     nsAutoString as;
01419     int i;
01420     for(i=0;i<30;i++){
01421       as+='a';
01422     }
01423     PRBool b=PR_TRUE; //this line doesn't do anything, it just gives a convenient breakpoint.
01424     NS_ASSERTION(as=="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","error in operator+=()");
01425   }
01426 
01427 
01428   {
01429     nsCAutoString  temp0; 
01430     nsCAutoString  temp1("hello rick");
01431 
01432 
01433     //nsCAutoString  temp2("hello rick",PR_TRUE,5);
01434     nsCAutoString  temp3(pbuf);
01435 
01436     {
01437       const char* buf="hello rick";
01438       int len=strlen(buf);
01439 
01440 //       nsAutoString   temp4(CBufDescriptor(buf,PR_TRUE,len+1,len));  //NOT WORKING
01441     }
01442 
01443     nsCAutoString  temp5(temp3);
01444     nsString       s(pbuf);
01445     nsCAutoString  temp6(s);  //create one from a nsString
01446 
01447     nsCAutoString as;
01448     int i;
01449     for(i=0;i<30;i++){
01450       as+='a';
01451     }
01452     PRBool b=PR_TRUE;
01453 
01454 #if 0
01455 
01456 /* NOT WORKING
01457     char buffer[500];
01458 
01459     nsCAutoString s3(CBufDescriptor(buffer,PR_TRUE,sizeof(buffer)-1,0));
01460     s3="hello, my name is inigo montoya.";
01461   */
01462       //make an autostring that copies an nsString...
01463     nsString s0("eat icecream");
01464     nsCAutoString s4(s0); 
01465     nsCAutoString s5(s0.get());
01466     nsString aaa("hi there rick");
01467 #endif
01468   }
01469 
01470   const char* st="hello again";
01471   nsString s; //this also forces nsString to run it's selftest.
01472   s=st;
01473   nsAutoString astr;
01474   astr=st;
01475 
01476   return result;
01477 }
01478 
01485 int CStringTester::TestSubsumables(){
01486   int result=0;
01487   char* buf="hello rick";
01488 
01489   return result;
01490 }
01491 
01498 int CStringTester::TestRandomOps(){
01499   int result=0;
01500 
01501 #if 0
01502 
01503   char* str[]={"abc ","xyz ","123 ","789 ","*** ","... "};
01504 
01505   string    theSTLString;
01506   nsString theString;
01507   nsString thePrevString;
01508 
01509   enum  ops {eNOP,eAppend,eDelete,eInsert};
01510   char* opStrs[] = {"nop","append","delete","insert"};
01511   
01512    srand( (unsigned)time( NULL ) );   
01513 
01514    int err[] = {1,7,9,6,0,4,1,1,1,1};
01515 
01516   ops theOp=eNOP;
01517   int pos,len,index;
01518 
01519   fstream output("c:/temp/out.file",ios::out);
01520   output<<"dump!";
01521 
01522   for(int theOpIndex=0;theOpIndex<1000000;theOpIndex++){
01523     
01524     int r=rand();
01525     char buf[100];
01526     sprintf(buf,"%i",r);
01527     len=strlen(buf);
01528     index=buf[len-1]-'0';
01529 
01530     //debug... index=err[theOp];
01531 
01532     switch(index) {
01533       case 0:
01534       case 1:
01535       case 2:
01536         theSTLString.append(str[index]);
01537         theString.Append(str[index]);
01538         theOp=eAppend;
01539         break;
01540 
01541       case 3:
01542       case 4:
01543       case 5:
01544         theOp=eInsert;
01545         if (theString.Length()>2) {
01546           pos=theString.Length()/2;
01547           theSTLString.insert(pos,str[index],4);
01548           theString.Insert(str[index],pos);
01549         }
01550         break;
01551 
01552       case 6:
01553       case 7:
01554       case 8:
01555       case 9:
01556         theOp=eDelete;
01557         if(theString.Length()>10) {
01558           len=theString.Length()/2;
01559           pos=theString.Length()/4;
01560           theSTLString.erase(pos,len);
01561           theString.Cut(pos,len);
01562         }
01563         break;
01564 
01565       default:
01566         theOp=eNOP;
01567 
01568     } //for
01569 
01570     if(eNOP<theOp) {
01571 
01572       int lendiff=theString.Length()-theSTLString.length();
01573       PRBool equals=theString.Equals(theSTLString.c_str());
01574       if(((lendiff)) || (!equals)) {
01575         printf("Error in %s at:%i len:%i (%s)!\n",opStrs[theOp],pos,len,str[index]);
01576         output.close();
01577         theString.Equals(theSTLString.c_str());
01578 
01579         if(theOp==eInsert) {
01580           thePrevString.Insert(str[index],pos);
01581         }
01582         else if(theOp==eAppend) {
01583           thePrevString.Append(str[index]);
01584         }
01585         return 0;
01586       }
01587 
01588 #if FOO
01589       output<< opStrs[theOp];
01590       if((eInsert==theOp) || (eAppend==theOp)){
01591         output<< "(" << str[index] << ", " << pos << ") ";
01592       }
01593 
01594       thePrevString.ToCString(buffer,1000,0);
01595       output << " Old: [" << buffer << "]";
01596       theString.ToCString(buffer,1000,0);
01597       output << " New: [" << buffer << "]";
01598       output << " STL: [" << theSTLString.c_str() << "]" << endl;
01599 
01600       if(theString.mStringValue.mLength>300) {
01601         theString.Truncate();
01602         theSTLString.erase();
01603       }
01604 #endif
01605       thePrevString=theString;
01606     }
01607   }
01608 #endif
01609   return result;
01610 }
01611 
01612 
01619 int CStringTester::TestReplace(){
01620   int result=0;
01621 
01622   const char* find="..";
01623   const char* rep= "+";
01624 
01625   const char* s1="hello..there..rick..gessner.";
01626   const char* s2="hello+there+rick+gessner.";
01627 
01628   nsCString s(s1);
01629   s.ReplaceSubstring(find,rep);
01630   NS_ASSERTION(s==s2,"ReplaceSubstring error");
01631 
01632   s.ReplaceSubstring(rep,find);
01633   NS_ASSERTION(s==s1,"ReplaceSubstring error");
01634 
01635   return result;
01636 }
01637 
01638 
01645 int CStringTester::TestWideStringPerformance() {
01646 
01647   printf("Widestring performance tests...\n");
01648 
01649   char* libname[] = {"STL","nsString",0};
01650 
01651 
01652     //**************************************************
01653     //Test Construction  against STL::wstring...
01654     //**************************************************
01655   {
01656     nsString theConst;
01657     for(int z=0;z<10;z++){
01658       theConst.Append("0123456789");
01659     }
01660     
01661     Stopwatch watch1;
01662     int i;
01663     for(i=0;i<1000000;i++){
01664       nsString s(theConst);
01665     }
01666     watch1.Stop();
01667 
01668     wchar_t wbuf[] = {'a','b','c','d','e','f','g','h','i','j',0};
01669     wstring theConst2;
01670     for(int w=0;w<10;w++){
01671       theConst2.append(wbuf);
01672     }
01673 
01674     Stopwatch watch2;
01675 #ifdef USE_STL
01676     for(i=0;i<1000000;i++){
01677       wstring s(theConst2);
01678     }
01679 #endif
01680     watch2.Stop();
01681 
01682     printf("Construct(abcde)    NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01683   }
01684 
01685 
01686     //**************************************************
01687     //Test append("abcde") against STL::wstring...
01688     //**************************************************
01689   {
01690 
01691     PRUnichar pbuf[10]={'a','b','c','d','e',0};
01692     
01693     Stopwatch watch1;
01694     int i;
01695     for(i=0;i<1000;i++){
01696       nsString s;
01697       for(int j=0;j<200;j++){
01698         s.Append("abcde");
01699       }
01700     }
01701     watch1.Stop();
01702 
01703     wchar_t wbuf[10] = {'a','b','c','d','e',0};
01704 
01705     Stopwatch watch2;
01706 #ifdef USE_STL
01707     for(i=0;i<1000;i++){
01708       wstring s;
01709       for(int j=0;j<200;j++){
01710         s.append(wbuf);
01711       }
01712     }
01713 #endif
01714     watch2.Stop();
01715 
01716     printf("Append(abcde)       NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01717   }
01718 
01719     //**************************************************
01720     //Test append(char) against STL::wstring
01721     //**************************************************
01722   {
01723 
01724     Stopwatch watch1;
01725     int i;
01726     for(i=0;i<500;i++){
01727       nsString s;
01728       for(int j=0;j<200;j++){
01729         s.Append('a');
01730       }
01731     }
01732     watch1.Stop();
01733 
01734 
01735     Stopwatch watch2;
01736 #ifdef USE_STL
01737     for(i=0;i<500;i++){
01738       wstring s;
01739       wchar_t theChar('a');
01740       for(int j=0;j<200;j++){
01741         s.append('a',1);
01742       }
01743     }
01744 #endif
01745     watch2.Stop();
01746     
01747     printf("Append('a')         NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01748     int x=0;
01749   }
01750 
01751     //**************************************************
01752     //Test insert("123") against STL::wstring
01753     //**************************************************
01754   {
01755 
01756     PRUnichar pbuf1[10]={'a','b','c','d','e','f',0};
01757     PRUnichar pbuf2[10]={'1','2','3',0};
01758 
01759     Stopwatch watch1;
01760     int i;
01761     for(i=0;i<1000;i++){
01762       nsString s("abcdef");
01763       int inspos=3;
01764       for(int j=0;j<100;j++){
01765         s.Insert(pbuf2,inspos);
01766         inspos+=3;
01767       }
01768     }
01769     watch1.Stop();
01770 
01771 
01772     wchar_t wbuf1[10] = {'a','b','c','d','e','f',0};
01773     wchar_t wbuf2[10] = {'1','2','3',0};
01774 
01775     Stopwatch watch2;
01776 #ifdef USE_STL
01777     for(i=0;i<1000;i++){
01778       wstring s(wbuf1);
01779       int inspos=3;
01780       for(int j=0;j<100;j++){
01781         s.insert(inspos,wbuf2);
01782         inspos+=3;
01783       }
01784     }  
01785 #endif
01786     watch2.Stop();
01787 
01788     printf("Insert(123)         NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01789     int x=0;
01790   }
01791 
01792     //**************************************************
01793     //Let's test substring searching performance...
01794     //**************************************************
01795   {
01796     PRUnichar pbuf1[] = {'a','a','a','a','a','a','a','a','a','a','b',0};
01797     PRUnichar pbuf2[]   = {'a','a','b',0};
01798 
01799     nsString s(pbuf1);
01800     nsString target(pbuf2);
01801 
01802     Stopwatch watch1;
01803     int i;
01804     for(i=-1;i<200000;i++) {
01805       PRInt32 result=s.Find(target,PR_FALSE);
01806     }
01807     watch1.Stop();
01808 
01809     Stopwatch watch2;
01810 #ifdef USE_STL
01811     wchar_t wbuf1[] = {'a','a','a','a','a','a','a','a','a','a','b',0};
01812     wchar_t wbuf2[] = {'a','a','b',0};
01813     wstring ws(wbuf1);
01814     wstring wtarget(wbuf2);
01815 
01816     for(i=-1;i<200000;i++) {
01817       PRInt32 result=ws.find(wtarget);
01818     }
01819 #endif
01820     watch2.Stop();
01821 
01822     printf("Find(aab)           NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01823   }
01824 
01825     //**************************************************
01826     //Now let's test comparisons...
01827     //**************************************************
01828   {
01829     nsString  s("aaaaaaaaaaaaaaaaaaab");
01830     PRUnichar target[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','b',0};
01831     size_t theLen=(sizeof(target)-1)/2;
01832 
01833     Stopwatch watch1;
01834     int result=0;
01835     int i;
01836     for(i=-1;i<1000000;i++) {
01837       result=s.Compare(target,PR_FALSE,theLen);
01838       result++;
01839     }
01840     watch1.Stop();
01841 
01842     Stopwatch watch2;
01843 #ifdef USE_STL
01844     wchar_t buf[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','b',0};
01845     wstring ws(buf);
01846     wchar_t wtarget[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','b',0};
01847 
01848     for(i=-1;i<1000000;i++) {
01849       result=ws.compare(0,theLen,wtarget);
01850       result++;
01851     }
01852 #endif
01853     watch2.Stop();
01854 
01855     printf("Compare(aaaaaaaab)  NSString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01856 
01857   }
01858 
01859     //**************************************************
01860     //Now lets test string deletions...
01861     //**************************************************
01862   {
01863 
01864     int strcount=6000;
01865     int outerIter=100;
01866     int innerIter=100;
01867 
01868     PRUnichar pbuf[] = {'1','2','3','4','5','6','7','8','9','0',0};
01869     nsString source1;  //build up our target string...
01870     int i;
01871     for(i=0;i<strcount;i++) {
01872       source1.Append(pbuf);
01873     }
01874 
01875     Stopwatch watch1;
01876 
01877     for(i=0;i<outerIter;i++) {    
01878       nsString s1(source1);
01879       for(int j=0;j<100;j++){
01880         s1.Cut(20,50);
01881       }
01882     }
01883     watch1.Stop();
01884     printf("Cut(...)            NSString: %f ",watch1.Elapsed());
01885 
01886 #ifdef USE_STL
01887 
01888     wchar_t wbuf[] = {'1','2','3','4','5','6','7','8','9','0',0};
01889     wstring source2;  //build up our target string...
01890 
01891     for(i=0;i<strcount;i++) {
01892       source2.append(wbuf);
01893     }
01894 
01895     Stopwatch watch2;
01896 
01897     for(i=0;i<outerIter;i++) {
01898       wstring s2(source2);
01899       for(int j=0;j<100;j++){
01900         s2.erase(20,50);
01901       }
01902     }
01903     watch2.Stop();
01904 
01905     printf(" STL: %f",watch2.Elapsed());
01906 #endif
01907     printf("\n");
01908 
01909   }
01910 
01911     //**************************************************
01912     //Now let's test the findChar routine...
01913     //**************************************************
01914   {
01915 
01916     nsString s1;
01917     int i;
01918     for(i=0;i<100;i++) {
01919       s1.Append("1234567890",10);
01920     }
01921     s1+="xyz";
01922 
01923     Stopwatch watch1;
01924     for(i=0;i<100000;i++) {
01925       int f=s1.FindChar('z',PR_FALSE,0);
01926     }
01927     watch1.Stop();
01928     printf("FindChar('z')       NSString: %f",watch1.Elapsed());
01929 
01930 #ifdef USE_STL
01931     wchar_t wbuf[] = {'1','2','3','4','5','6','7','8','9','0',0};
01932     wstring s2;
01933     for( i=0;i<100;i++) {
01934       s2.append(wbuf);
01935     }
01936     wchar_t wbuf2[] = {'x','y','z',0};
01937     s2.append(wbuf2);
01938 
01939     Stopwatch watch2;
01940 
01941     for(i=0;i<100000;i++) {
01942       int f=s2.find_first_of('z',0);
01943     }
01944     watch2.Stop();
01945     printf("  STL: %f",watch2.Elapsed());
01946 #endif
01947     printf("\n");
01948 
01949   }
01950   return 0;
01951 }
01952 
01953 
01954 /************************************************************************************************
01955  * 
01956  *  This method tests the performance of various methods.
01957  * 
01958  ************************************************************************************************/
01959 int CStringTester::TestStringPerformance() {
01960   printf("c-String performance tests...\n");
01961 
01962   char* libname[] = {"STL","nsString",0};
01963 
01964     //**************************************************
01965     //Test Construction  against STL::wstring...
01966     //**************************************************
01967   {
01968     nsCString theConst;
01969     for(int z=0;z<10;z++){
01970       theConst.Append("0123456789");
01971     }
01972     
01973     Stopwatch watch1;
01974     int i;
01975     for(i=0;i<1000000;i++){
01976       nsCString s(theConst);
01977     }
01978     watch1.Stop();
01979 
01980     char wbuf[] = {'a','b','c','d','e','f','g','h','i','j',0};
01981     string theConst2;
01982     for(int w=0;w<10;w++){
01983       theConst2.append(wbuf);
01984     }
01985 
01986     Stopwatch watch2;
01987 #ifdef USE_STL
01988     for(i=0;i<1000000;i++){
01989       string s(theConst2);
01990     }
01991 #endif
01992     watch2.Stop();
01993 
01994     printf("Construct(abcde)    NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
01995   }
01996 
01997     //**************************************************
01998     //Test append("abcde") against STL...
01999     //**************************************************
02000 
02001   {
02002     
02003     Stopwatch watch1;
02004     int i;
02005     for(i=0;i<1000;i++){
02006       nsCString s;
02007       for(int j=0;j<200;j++){
02008         s.Append("abcde",5);
02009       }
02010     }
02011     watch1.Stop();
02012 
02013     Stopwatch watch2;
02014 #ifdef USE_STL
02015     for(i=0;i<1000;i++){
02016       string s;
02017       for(int j=0;j<200;j++){
02018         s.append("abcde",5);
02019       }
02020     }
02021 #endif
02022     watch2.Stop();
02023   
02024     printf("Append(abcde)       NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02025     int x=0;
02026   }
02027 
02028     //**************************************************
02029     //Test append(char) against STL
02030     //**************************************************
02031   {
02032 
02033     Stopwatch watch1;
02034     int i;
02035     for(i=0;i<500;i++){
02036       nsCString s;
02037       for(int j=0;j<200;j++){
02038         s.Append('a');
02039       }
02040     }
02041     watch1.Stop();
02042 
02043     Stopwatch watch2;
02044 #ifdef USE_STL
02045     for(i=0;i<500;i++){
02046       string s;
02047       wchar_t theChar('a');
02048       for(int j=0;j<200;j++){
02049         s.append('a',1);
02050       }
02051     }
02052 #endif
02053     watch2.Stop();
02054   
02055     printf("Append('a')         NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02056     int x=0;
02057   }
02058 
02059     //**************************************************
02060     //Test insert("123") against STL
02061     //**************************************************
02062   {
02063 
02064     char pbuf1[10]={'a','b','c','d','e','f',0};
02065     char pbuf2[10]={'1','2','3',0};
02066 
02067     Stopwatch watch1;
02068     int i;
02069     for(i=0;i<1000;i++){
02070       nsCString s("abcdef");
02071       int inspos=3;
02072       for(int j=0;j<100;j++){
02073         s.Insert(pbuf2,inspos);
02074         inspos+=3;
02075       }
02076     }
02077     watch1.Stop();
02078 
02079     Stopwatch watch2;
02080 #ifdef USE_STL
02081     for(i=0;i<1000;i++){
02082       string s(pbuf1);
02083       int inspos=3;
02084       for(int j=0;j<100;j++){
02085         s.insert(inspos,pbuf2);
02086         inspos+=3;
02087       }
02088     }
02089 #endif
02090     watch2.Stop();
02091   
02092     printf("insert(123)         NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02093     int x=0;
02094   }
02095 
02096     //**************************************************
02097     //Let's test substring searching performance...
02098     //**************************************************
02099   {
02100     char *pbuf1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
02101                  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
02102                  "aab";
02103                
02104     char *pbuf2 = "aab";
02105 
02106     nsCString s(pbuf1);
02107 
02108     Stopwatch watch1;
02109     int i;
02110     for(i=-1;i<20000;i++) {
02111       PRInt32 result=s.Find(pbuf2,PR_FALSE);
02112     }
02113     watch1.Stop();
02114 
02115     Stopwatch watch2;
02116 #ifdef USE_STL
02117     string ws(pbuf1);
02118     for(i=-1;i<20000;i++) {
02119       PRInt32 result=ws.find(pbuf2);
02120     }
02121 #endif
02122     watch2.Stop();
02123 
02124     printf("Find(aab)           NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02125   }
02126 
02127     //**************************************************
02128     //Now let's test comparisons...
02129     //**************************************************
02130   {
02131     char*  target="aaaaaaaaaaaaab";
02132     size_t theLen=strlen(target);
02133 
02134     Stopwatch watch1;
02135     nsCString  s("aaaaaaaaaaaaaaaaaaab");
02136     int result=0;
02137     int i;
02138     for(i=-1;i<1000000;i++) {
02139       result=s.Compare(target,PR_FALSE,theLen);
02140       result++;
02141     }
02142     watch1.Stop();
02143 
02144     Stopwatch watch2;
02145 #ifdef USE_STL
02146     string ws("aaaaaaaaaaaaaaaaaaab");
02147     for(i=-1;i<1000000;i++) {
02148       result=ws.compare(0,theLen,target);
02149       result++;
02150     }
02151 #endif
02152     watch2.Stop();
02153 
02154     printf("Compare(aaaaaaaab)  NSCString: %f  STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02155 
02156   }
02157 
02158     //**************************************************
02159     //Now lets test string deletions...
02160     //**************************************************
02161   {
02162 
02163     int strcount=6000;
02164     int outerIter=100;
02165     int innerIter=100;
02166 
02167     char* buffer = "1234567890";
02168     nsCString source1;  //build up our target string...
02169     int i;
02170     for(i=0;i<strcount;i++) {
02171       source1.Append(buffer);
02172     }
02173 
02174     Stopwatch watch1;
02175     for(i=0;i<outerIter;i++) {    
02176       nsCString s1(source1);
02177       for(int j=0;j<innerIter;j++){
02178         s1.Cut(20,50);
02179       }
02180     }
02181     watch1.Stop();
02182     printf("Cut(...)            NSCString: %f ",watch1.Elapsed());
02183 
02184 #ifdef USE_STL
02185     string source2;  //build up our target string...
02186     for(i=0;i<strcount;i++) {
02187       source2.append(buffer);
02188     }
02189 
02190     Stopwatch watch2;
02191     for(i=0;i<outerIter;i++) {
02192       string s2(source2);
02193       for(int j=0;j<innerIter;j++){
02194         s2.erase(20,50);
02195       }
02196     }
02197     watch2.Stop();
02198 
02199     printf(" STL: %f",watch2.Elapsed());
02200 #endif
02201     printf("\n");
02202   }
02203 
02204 
02205     //**************************************************
02206     //Now let's test the findChar routine...
02207     //**************************************************
02208   {
02209 
02210     nsCString s1;
02211     int i;
02212     for(i=0;i<100;i++) {
02213       s1.Append("1234567890",10);
02214     }
02215     s1+="xyz";
02216 
02217     Stopwatch watch1;
02218     for(i=0;i<100000;i++) {
02219       int f=s1.FindChar('z',PR_FALSE,0);
02220     }
02221     watch1.Stop();
02222     printf("FindChar('z')       NSCString: %f ",watch1.Elapsed());
02223 
02224 #ifdef USE_STL
02225     string s2;
02226     for( i=0;i<100;i++) {
02227       s2.append("1234567890");
02228     }
02229     s2.append("xyz");
02230 
02231     Stopwatch watch2;
02232     for(i=0;i<100000;i++) {
02233       int f=s2.find_first_of('z',0);
02234     }
02235     watch2.Stop();
02236     printf(" STL: %f\n",watch1.Elapsed(),watch2.Elapsed());
02237 #endif
02238     printf("\n");
02239 
02240   }
02241   return 0;
02242 }
02243 
02244 
02251 int CStringTester::TestRegressions() {
02252 
02253   nsString s("FTP: Netscape</a>");
02254   PRInt32 result=s.Find("</A>",PR_TRUE);
02255 
02256     //this was a known bug...
02257   {
02258     nsString s0("");
02259     PRInt32 pos=s0.RFind("-->");
02260     nsString s1("debug");
02261     pos=s1.RFind("b");
02262     pos=s1.RFind("de",PR_FALSE,1);
02263     pos=10;
02264   }
02265 
02266     //this was a known bug...
02267   {
02268     nsString s0("RDF:RDF");
02269     PRInt32 pos=s0.Find(":");
02270     pos=10;
02271   }
02272 
02273   return result;
02274 }
02275 
02276 #endif
02277