Back to index

lightning-sunbird  0.9+nobinonly
string.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "plstr.h"
00039 #include "nspr.h"
00040 
00041 #include <stdio.h>
00042 
00043 /* PL_strlen */
00044 PRBool test_001(void)
00045 {
00046     static struct
00047     {
00048         const char *str;
00049         PRUint32    len;
00050     } array[] =
00051       {
00052           { (const char *)0, 0 },
00053           { "", 0 },
00054           { "a", 1 },
00055           { "abcdefg", 7 },
00056           { "abcdefg\0hijk", 7 }
00057       };
00058 
00059     int i;
00060 
00061     printf("Test 001 (PL_strlen)      ..."); fflush(stdout);
00062 
00063     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00064     {
00065         if( PL_strlen(array[i].str) != array[i].len )
00066         {
00067             printf("FAIL (%d: %s->%d, %d)\n", i, 
00068                    array[i].str ? array[i].str : "(null)",
00069                    PL_strlen(array[i].str), array[i].len);
00070             return PR_FALSE;
00071         }
00072     }
00073 
00074     printf("PASS\n");
00075     return PR_TRUE;
00076 }
00077 
00078 /* PL_strnlen */
00079 PRBool test_002(void)
00080 {
00081     static struct
00082     {
00083         const char *str;
00084         PRUint32    max;
00085         PRUint32    len;
00086     } array[] =
00087       {
00088           { (const char *)0, 0, 0 },
00089           { (const char *)0, 12, 0 },
00090           { "", 0, 0 },
00091           { "", 12, 0 },
00092           { "a", 0, 0 },
00093           { "a", 1, 1 },
00094           { "a", 12, 1 },
00095           { "abcdefg", 0, 0 },
00096           { "abcdefg", 1, 1 },
00097           { "abcdefg", 7, 7 },
00098           { "abcdefg", 12, 7 },
00099           { "abcdefg\0hijk", 0, 0 },
00100           { "abcdefg\0hijk", 1, 1 },
00101           { "abcdefg\0hijk", 7, 7 },
00102           { "abcdefg\0hijk", 12, 7 },
00103       };
00104 
00105     int i;
00106 
00107     printf("Test 002 (PL_strnlen)     ..."); fflush(stdout);
00108 
00109     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00110     {
00111         if( PL_strnlen(array[i].str, array[i].max) != array[i].len )
00112         {
00113             printf("FAIL (%d: %s,%d->%d, %d)\n", i,
00114                    array[i].str ? array[i].str : "(null)", array[i].max,
00115                    PL_strnlen(array[i].str, array[i].max), array[i].len);
00116             return PR_FALSE;
00117         }
00118     }
00119 
00120     printf("PASS\n");
00121     return PR_TRUE;
00122 }
00123 
00124 /* PL_strcpy */
00125 PRBool test_003(void)
00126 {
00127     static char buffer[ 1024 ];
00128 
00129     static struct
00130     {
00131         const char *str;
00132         char       *dest;
00133         char       *rv;
00134         PRBool      comp;
00135     } array[] =
00136       {
00137           { (const char *)0, (char *)0, (char *)0, PR_FALSE },
00138           { (const char *)0, buffer, (char *)0, PR_FALSE },
00139           { "", (char *)0, (char *)0, PR_FALSE },
00140           { "", buffer, buffer, PR_TRUE },
00141           { "a", (char *)0, (char *)0, PR_FALSE },
00142           { "a", buffer, buffer, PR_TRUE },
00143           { "abcdefg", (char *)0, (char *)0, PR_FALSE },
00144           { "abcdefg", buffer, buffer, PR_TRUE },
00145           { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
00146           { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
00147       };
00148 
00149     int i;
00150 
00151     printf("Test 003 (PL_strcpy)      ..."); fflush(stdout);
00152 
00153     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00154     {
00155         char *rv;
00156         const char *a = array[i].str;
00157         const char *b = (const char *)array[i].dest;
00158 
00159         rv = PL_strcpy(array[i].dest, array[i].str);
00160         if( array[i].rv != rv )
00161         {
00162             printf("FAIL %d: (0x%x, %s)->0x%x\n", i, array[i].dest,
00163                    array[i].str ? array[i].str : "(null)", rv);
00164             return PR_FALSE;
00165         }
00166 
00167         if( array[i].comp )
00168         {
00169             while( 1 )
00170             {
00171                 if( *a != *b )
00172                 {
00173                     printf("FAIL %d: %s->%.32s\n", i, 
00174                            array[i].str ? array[i].str : "(null)", 
00175                            array[i].dest ? array[i].dest : "(null)");
00176                     return PR_FALSE;
00177                 }
00178 
00179                 if( (char)0 == *a ) break;
00180 
00181                 a++;
00182                 b++;
00183             }
00184         }
00185     }
00186 
00187     printf("PASS\n");
00188     return PR_TRUE;
00189 }
00190 
00191 /* PL_strncpy */
00192 PRBool test_004(void)
00193 {
00194     static char buffer[ 1024 ];
00195 
00196     static struct
00197     {
00198         const char *str;
00199         PRUint32    len;
00200         char       *dest;
00201         char       *rv;
00202         PRBool      comp;
00203         const char *result;
00204         PRBool      nulled;
00205     } array[] =
00206       {
00207           { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00208           { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00209           { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00210           { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00211           { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00212           { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00213           { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00214           { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00215           { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00216           { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00217           { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
00218           { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
00219           { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00220           { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00221           { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00222           { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00223           { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
00224           { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
00225           { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00226           { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00227           { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00228           { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00229           { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
00230           { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
00231           { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00232           { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00233           { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00234           { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00235           { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
00236           { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
00237           { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00238           { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00239           { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00240           { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00241           { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
00242           { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
00243           { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00244           { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00245           { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00246           { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00247           { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
00248           { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
00249           { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00250           { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
00251           { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00252           { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
00253           { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
00254           { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
00255       };
00256 
00257     int i;
00258 
00259     printf("Test 004 (PL_strncpy)     ..."); fflush(stdout);
00260 
00261     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00262     {
00263         char *rv;
00264         int j;
00265 
00266         for( j = 0; j < sizeof(buffer); j++ )
00267             buffer[j] = '-';
00268 
00269         rv = PL_strncpy(array[i].dest, array[i].str, array[i].len);
00270         if( array[i].rv != rv )
00271         {
00272             printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
00273                    array[i].str ? array[i].str : "(null)", array[i].len, rv);
00274             return PR_FALSE;
00275         }
00276 
00277         if( array[i].comp )
00278         {
00279             const char *a = array[i].result;
00280             const char *b = array[i].dest;
00281 
00282             while( *a )
00283             {
00284                 if( *a != *b )
00285                 {
00286                     printf("FAIL %d: %s != %.32s\n", i, 
00287                            array[i].result, array[i].dest);
00288                     return PR_FALSE;
00289                 }
00290 
00291                 a++;
00292                 b++;
00293             }
00294 
00295             if( array[i].nulled )
00296             {
00297                 if( *b != '\0' )
00298                 {
00299                     printf("FAIL %d: not terminated\n", i);
00300                     return PR_FALSE;
00301                 }
00302             }
00303             else
00304             {
00305                 if( *b != '-' )
00306                 {
00307                     printf("FAIL %d: overstepped\n", i);
00308                     return PR_FALSE;
00309                 }
00310             }
00311         }
00312     }
00313                 
00314     printf("PASS\n");
00315     return PR_TRUE;
00316 }
00317 
00318 /* PL_strncpyz */
00319 PRBool test_005(void)
00320 {
00321     static char buffer[ 1024 ];
00322 
00323     static struct
00324     {
00325         const char *str;
00326         PRUint32    len;
00327         char       *dest;
00328         char       *rv;
00329         PRBool      comp;
00330         const char *result;
00331     } array[] =
00332       {
00333           { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00334           { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00335           { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00336           { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00337           { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
00338           { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
00339           { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00340           { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00341           { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00342           { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00343           { "", 1, buffer, buffer, PR_TRUE, "" },
00344           { "", 7, buffer, buffer, PR_TRUE, "" },
00345           { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00346           { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00347           { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00348           { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00349           { "b", 1, buffer, buffer, PR_TRUE, "" },
00350           { "c", 7, buffer, buffer, PR_TRUE, "c" },
00351           { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00352           { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00353           { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00354           { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00355           { "fg", 1, buffer, buffer, PR_TRUE, "" },
00356           { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
00357           { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00358           { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00359           { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00360           { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00361           { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
00362           { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
00363           { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00364           { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00365           { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00366           { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00367           { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
00368           { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
00369           { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00370           { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00371           { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00372           { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00373           { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
00374           { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
00375           { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00376           { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
00377           { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00378           { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
00379           { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
00380           { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
00381       };
00382 
00383     int i;
00384 
00385     printf("Test 005 (PL_strncpyz)    ..."); fflush(stdout);
00386 
00387     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00388     {
00389         char *rv;
00390         int j;
00391 
00392         for( j = 0; j < sizeof(buffer); j++ )
00393             buffer[j] = '-';
00394 
00395         rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len);
00396         if( array[i].rv != rv )
00397         {
00398             printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
00399                    array[i].str ? array[i].str : "(null)", array[i].len, rv);
00400             return PR_FALSE;
00401         }
00402 
00403         if( array[i].comp )
00404         {
00405             const char *a = array[i].result;
00406             const char *b = array[i].dest;
00407 
00408             while( 1 )
00409             {
00410                 if( *a != *b )
00411                 {
00412                     printf("FAIL %d: %s != %.32s\n", i, 
00413                            array[i].result, array[i].dest);
00414                     return PR_FALSE;
00415                 }
00416 
00417                 if( (char)0 == *a ) break;
00418 
00419                 a++;
00420                 b++;
00421             }
00422         }
00423     }
00424                 
00425     printf("PASS\n");
00426     return PR_TRUE;
00427 }
00428 
00429 /* PL_strdup */
00430 PRBool test_006(void)
00431 {
00432     static const char *array[] =
00433     {
00434         (const char *)0,
00435         "",
00436         "a",
00437         "abcdefg"
00438     };
00439 
00440     int i;
00441 
00442     printf("Test 006 (PL_strdup)      ..."); fflush(stdout);
00443 
00444     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00445     {
00446         char *rv = PL_strdup(array[i]);
00447 
00448         if( (char *)0 == rv )
00449         {
00450             printf("FAIL %d: 0x%x -> 0\n", i, array[i]);
00451             return PR_FALSE;
00452         }
00453 
00454         if( (const char *)0 == array[i] )
00455         {
00456             if( (char)0 != *rv )
00457             {
00458                 printf("FAIL %d: (const char *)0 -> %.32s\n", i, rv);
00459                 return PR_FALSE;
00460             }
00461         }
00462         else
00463         {
00464             const char *a = array[i];
00465             const char *b = (const char *)rv;
00466 
00467             while( 1 )
00468             {
00469                 if( *a != *b )
00470                 {
00471                     printf("FAIL %d: %s != %.32s\n", i, array[i], rv);
00472                     return PR_FALSE;
00473                 }
00474 
00475                 if( (char)0 == *a ) break;
00476 
00477                 a++;
00478                 b++;
00479             }
00480 
00481         }
00482         PL_strfree(rv);
00483     }
00484 
00485     printf("PASS\n");
00486     return PR_TRUE;
00487 }
00488 
00489 /* PL_strndup */
00490 PRBool test_007(void)
00491 {
00492     static struct
00493     {
00494         const char *str;
00495         PRUint32    len;
00496         const char *result;
00497     } array[] =
00498       {
00499           { (const char *)0, 0, "" },
00500           { (const char *)0, 1, "" },
00501           { (const char *)0, 7, "" },
00502           { "", 0, "" },
00503           { "", 1, "" },
00504           { "", 7, "" },
00505           { "a", 0, "" },
00506           { "a", 1, "a" },
00507           { "a", 7, "a" },
00508           { "ab", 0, "" },
00509           { "ab", 1, "a" },
00510           { "ab", 7, "ab" },
00511           { "abcdefg", 0, "" },
00512           { "abcdefg", 1, "a" },
00513           { "abcdefg", 7, "abcdefg" },
00514           { "abcdefghijk", 0, "" },
00515           { "abcdefghijk", 1, "a" },
00516           { "abcdefghijk", 7, "abcdefg" },
00517           { "abcdef\0ghijk", 0, "" },
00518           { "abcdef\0ghijk", 1, "a" },
00519           { "abcdef\0ghijk", 7, "abcdef" }
00520       };
00521 
00522     int i;
00523 
00524     printf("Test 007 (PL_strndup)     ..."); fflush(stdout);
00525 
00526     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00527     {
00528         char *rv = PL_strndup(array[i].str, array[i].len);
00529         const char *a;
00530         const char *b;
00531 
00532         if( (char *)0 == rv )
00533         {
00534             printf("FAIL %d: %s,%lu -> 0\n", i, 
00535                    array[i].str ? array[i].str : "(null)", array[i].len);
00536             return PR_FALSE;
00537         }
00538 
00539         a = array[i].result;
00540         b = (const char *)rv;
00541 
00542         while( 1 )
00543         {
00544             if( *a != *b )
00545             {
00546                 printf("FAIL %d: %s != %.32s\n", i, array[i].result, rv);
00547                 return PR_FALSE;
00548             }
00549 
00550             if( (char)0 == *a ) break;
00551 
00552             a++;
00553             b++;
00554         }
00555 
00556         free(rv);
00557     }
00558 
00559     printf("PASS\n");
00560     return PR_TRUE;
00561 }
00562 
00563 /* PL_strcat */
00564 PRBool test_008(void)
00565 {
00566     static struct
00567     {
00568         const char *first;
00569         const char *second;
00570         const char *result;
00571     } array[] =
00572       {
00573           { (const char *)0, (const char *)0, (const char *)0 },
00574           { (const char *)0, "xyz", (const char *)0 },
00575           { "", (const char *)0, "" },
00576           { "", "", "" },
00577           { "ab", "", "ab" },
00578           { "cd", "ef", "cdef" },
00579           { "gh\0X", "", "gh" },
00580           { "ij\0X", "kl", "ijkl" },
00581           { "mn\0X", "op\0X", "mnop" },
00582           { "qr", "st\0X", "qrst" },
00583           { "uv\0X", "wx\0X", "uvwx" }
00584       };
00585 
00586     int i;
00587 
00588     printf("Test 008 (PL_strcat)      ..."); fflush(stdout);
00589 
00590     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00591     {
00592         char buffer[ 1024 ];
00593         int j;
00594         char *rv;
00595 
00596         for( j = 0; j < sizeof(buffer); j++ )
00597             buffer[j] = '-';
00598 
00599         if( (const char *)0 != array[i].first )
00600             (void)PL_strcpy(buffer, array[i].first);
00601 
00602         rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
00603                        array[i].second);
00604 
00605         if( (const char *)0 == array[i].result )
00606         {
00607             if( (char *)0 != rv )
00608             {
00609                 printf("FAIL %d: %s+%s -> %.32s, not zero\n", i,
00610                        array[i].first ? array[i].first : "(null)",
00611                        array[i].second ? array[i].second : "(null)",
00612                        rv);
00613                 return PR_FALSE;
00614             }
00615         }
00616         else
00617         {
00618             if( (char *)0 == rv )
00619             {
00620                 printf("FAIL %d: %s+%s -> null, not %s\n", i,
00621                        array[i].first ? array[i].first : "(null)",
00622                        array[i].second ? array[i].second : "(null)",
00623                        array[i].result);
00624                 return PR_FALSE;
00625             }
00626             else
00627             {
00628                 const char *a = array[i].result;
00629                 const char *b = (const char *)rv;
00630 
00631                 while( 1 )
00632                 {
00633                     if( *a != *b )
00634                     {
00635                         printf("FAIL %d: %s+%s -> %.32s, not %s\n", i,
00636                                array[i].first ? array[i].first : "(null)",
00637                                array[i].second ? array[i].second : "(null)",
00638                                rv, array[i].result);
00639                         return PR_FALSE;
00640                     }
00641 
00642                     if( (char)0 == *a ) break;
00643 
00644                     a++;
00645                     b++;
00646                 }
00647             }
00648         }
00649     }
00650 
00651     printf("PASS\n");
00652     return PR_TRUE;
00653 }
00654 
00655 /* PL_strncat */
00656 PRBool test_009(void)
00657 {
00658     static struct
00659     {
00660         const char *first;
00661         const char *second;
00662         PRUint32    length;
00663         PRBool      nulled;
00664         const char *result;
00665     } array[] = 
00666       {
00667           { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
00668           { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
00669           { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
00670           { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
00671           { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
00672           { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
00673           { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
00674           { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
00675           { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
00676           { "", (const char *)0, 0, PR_TRUE, "" },
00677           { "", (const char *)0, 1, PR_TRUE, "" },
00678           { "", (const char *)0, 7, PR_TRUE, "" },
00679           { "", "", 0, PR_TRUE, "" },
00680           { "", "", 1, PR_TRUE, "" },
00681           { "", "", 7, PR_TRUE, "" },
00682           { "", "abcdefgh", 0, PR_TRUE, "" },
00683           { "", "abcdefgh", 1, PR_FALSE, "a" },
00684           { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
00685           { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
00686           { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
00687           { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
00688           { "xyz", "", 0, PR_TRUE, "xyz" },
00689           { "xyz", "", 1, PR_TRUE, "xyz" },
00690           { "xyz", "", 7, PR_TRUE, "xyz" },
00691           { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
00692           { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
00693           { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
00694       };
00695 
00696     int i;
00697 
00698     printf("Test 009 (PL_strncat)     ..."); fflush(stdout);
00699 
00700     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00701     {
00702         char buffer[ 1024 ];
00703         int j;
00704         char *rv;
00705 
00706         for( j = 0; j < sizeof(buffer); j++ )
00707             buffer[j] = '-';
00708 
00709         if( (const char *)0 != array[i].first )
00710             (void)PL_strcpy(buffer, array[i].first);
00711 
00712         rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
00713                          array[i].second, array[i].length);
00714 
00715         if( (const char *)0 == array[i].result )
00716         {
00717             if( (char *)0 != rv )
00718             {
00719                 printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
00720                        array[i].first ? array[i].first : "(null)",
00721                        array[i].second ? array[i].second : "(null)",
00722                        array[i].length, rv);
00723                 return PR_FALSE;
00724             }
00725         }
00726         else
00727         {
00728             if( (char *)0 == rv )
00729             {
00730                 printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
00731                        array[i].first ? array[i].first : "(null)",
00732                        array[i].second ? array[i].second : "(null)",
00733                        array[i].length, array[i].result);
00734                 return PR_FALSE;
00735             }
00736             else
00737             {
00738                 const char *a = array[i].result;
00739                 const char *b = (const char *)rv;
00740 
00741                 while( *a )
00742                 {
00743                     if( *a != *b )
00744                     {
00745                         printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
00746                                array[i].first ? array[i].first : "(null)",
00747                                array[i].second ? array[i].second : "(null)",
00748                                array[i].length, rv, array[i].result);
00749                         return PR_FALSE;
00750                     }
00751 
00752                     a++;
00753                     b++;
00754                 }
00755 
00756                 if( array[i].nulled )
00757                 {
00758                     if( (char)0 != *b )
00759                     {
00760                         printf("FAIL %d: %s+%s/%lu -> not nulled\n", i,
00761                                array[i].first ? array[i].first : "(null)",
00762                                array[i].second ? array[i].second : "(null)",
00763                                array[i].length);
00764                         return PR_FALSE;
00765                     }
00766                 }
00767                 else
00768                 {
00769                     if( (char)0 == *b )
00770                     {
00771                         printf("FAIL %d: %s+%s/%lu -> overrun\n", i,
00772                                array[i].first ? array[i].first : "(null)",
00773                                array[i].second ? array[i].second : "(null)",
00774                                array[i].length);
00775                         return PR_FALSE;
00776                     }
00777                 }
00778             }
00779         }
00780     }
00781 
00782     printf("PASS\n");
00783     return PR_TRUE;
00784 }
00785 
00786 /* PL_strcatn */
00787 PRBool test_010(void)
00788 {
00789     static struct
00790     {
00791         const char *first;
00792         const char *second;
00793         PRUint32    length;
00794         const char *result;
00795     } array[] = 
00796       {
00797           { (const char *)0, (const char *)0, 0, (const char *)0 },
00798           { (const char *)0, (const char *)0, 1, (const char *)0 },
00799           { (const char *)0, (const char *)0, 7, (const char *)0 },
00800           { (const char *)0, "", 0, (const char *)0 },
00801           { (const char *)0, "", 1, (const char *)0 },
00802           { (const char *)0, "", 7, (const char *)0 },
00803           { (const char *)0, "stuff", 0, (const char *)0 },
00804           { (const char *)0, "stuff", 1, (const char *)0 },
00805           { (const char *)0, "stuff", 7, (const char *)0 },
00806           { "", (const char *)0, 0, "" },
00807           { "", (const char *)0, 1, "" },
00808           { "", (const char *)0, 7, "" },
00809           { "", "", 0, "" },
00810           { "", "", 1, "" },
00811           { "", "", 7, "" },
00812           { "", "abcdefgh", 0, "" },
00813           { "", "abcdefgh", 1, "" },
00814           { "", "abcdefgh", 7, "abcdef" },
00815           { "xyz", (const char *)0, 0, "xyz" },
00816           { "xyz", (const char *)0, 1, "xyz" },
00817           { "xyz", (const char *)0, 7, "xyz" },
00818           { "xyz", "", 0, "xyz" },
00819           { "xyz", "", 1, "xyz" },
00820           { "xyz", "", 7, "xyz" },
00821           { "xyz", "abcdefgh", 0, "xyz" },
00822           { "xyz", "abcdefgh", 1, "xyz" },
00823           { "xyz", "abcdefgh", 7, "xyzabc" }
00824       };
00825 
00826     int i;
00827 
00828     printf("Test 010 (PL_strcatn)     ..."); fflush(stdout);
00829 
00830     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00831     {
00832         char buffer[ 1024 ];
00833         int j;
00834         char *rv;
00835 
00836         for( j = 0; j < sizeof(buffer); j++ )
00837             buffer[j] = '-';
00838 
00839         if( (const char *)0 != array[i].first )
00840             (void)PL_strcpy(buffer, array[i].first);
00841 
00842         rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer,
00843                         array[i].length, array[i].second);
00844 
00845         if( (const char *)0 == array[i].result )
00846         {
00847             if( (char *)0 != rv )
00848             {
00849                 printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
00850                        array[i].first ? array[i].first : "(null)",
00851                        array[i].second ? array[i].second : "(null)",
00852                        array[i].length, rv);
00853                 return PR_FALSE;
00854             }
00855         }
00856         else
00857         {
00858             if( (char *)0 == rv )
00859             {
00860                 printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
00861                        array[i].first ? array[i].first : "(null)",
00862                        array[i].second ? array[i].second : "(null)",
00863                        array[i].length, array[i].result);
00864                 return PR_FALSE;
00865             }
00866             else
00867             {
00868                 const char *a = array[i].result;
00869                 const char *b = (const char *)rv;
00870 
00871                 while( 1 )
00872                 {
00873                     if( *a != *b )
00874                     {
00875                         printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
00876                                array[i].first ? array[i].first : "(null)",
00877                                array[i].second ? array[i].second : "(null)",
00878                                array[i].length, rv, array[i].result);
00879                         return PR_FALSE;
00880                     }
00881 
00882                     if( (char)0 == *a ) break;
00883 
00884                     a++;
00885                     b++;
00886                 }
00887             }
00888         }
00889     }
00890 
00891     printf("PASS\n");
00892     return PR_TRUE;
00893 }
00894 
00895 /* PL_strcmp */
00896 PRBool test_011(void)
00897 {
00898     static struct
00899     {
00900         const char *one;
00901         const char *two;
00902         PRIntn      sign;
00903     } array[] =
00904       {
00905           { (const char *)0, (const char *)0, 0 },
00906           { (const char *)0, "word", -1 },
00907           { "word", (const char *)0, 1 },
00908           { "word", "word", 0 },
00909           { "aZYXVUT", "bZYXVUT", -1 },
00910           { "aZYXVUT", "bAAAAAA", -1 },
00911           { "a", "aa", -1 },
00912           { "a", "a", 0 },
00913           { "a", "A", 1 },
00914           { "aaaaa", "baaaa", -1 },
00915           { "aaaaa", "abaaa", -1 },
00916           { "aaaaa", "aabaa", -1 },
00917           { "aaaaa", "aaaba", -1 },
00918           { "aaaaa", "aaaab", -1 },
00919           { "bZYXVUT", "aZYXVUT", 1 },
00920           { "bAAAAAA", "aZYXVUT", 1 },
00921           { "aa", "a", 1 },
00922           { "A", "a", -1 },
00923           { "baaaa", "aaaaa", 1 },
00924           { "abaaa", "aaaaa", 1 },
00925           { "aabaa", "aaaaa", 1 },
00926           { "aaaba", "aaaaa", 1 },
00927           { "aaaab", "aaaaa", 1 },
00928           { "word", "Word", 1 },
00929           { "word", "wOrd", 1 },
00930           { "word", "woRd", 1 },
00931           { "word", "worD", 1 },
00932           { "WORD", "wORD", -1 },
00933           { "WORD", "WoRD", -1 },
00934           { "WORD", "WOrD", -1 },
00935           { "WORD", "WORd", -1 }
00936       };
00937 
00938     int i;
00939 
00940     printf("Test 011 (PL_strcmp)      ..."); fflush(stdout);
00941 
00942     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
00943     {
00944         PRIntn rv = PL_strcmp(array[i].one, array[i].two);
00945 
00946         switch( array[i].sign )
00947         {
00948             case -1:
00949                 if( rv < 0 ) continue;
00950                 break;
00951             case 1:
00952                 if( rv > 0 ) continue;
00953                 break;
00954             case 0:
00955                 if( 0 == rv ) continue;
00956                 break;
00957             default:
00958                 PR_NOT_REACHED("static data inconsistancy");
00959                 break;
00960         }
00961 
00962         printf("FAIL %d: %s-%s -> %d, not %d\n", i,
00963                array[i].one ? array[i].one : "(null)",
00964                array[i].two ? array[i].two : "(null)",
00965                rv, array[i].sign);
00966         return PR_FALSE;
00967     }
00968 
00969     printf("PASS\n");
00970     return PR_TRUE;
00971 }
00972 
00973 /* PL_strncmp */
00974 PRBool test_012(void)
00975 {
00976     static struct
00977     {
00978         const char *one;
00979         const char *two;
00980         PRUint32    max;
00981         PRIntn      sign;
00982     } array[] =
00983       {
00984           { (const char *)0, (const char *)0, 0, 0 },
00985           { (const char *)0, (const char *)0, 1, 0 },
00986           { (const char *)0, (const char *)0, 4, 0 },
00987           { (const char *)0, "word", 0, -1 },
00988           { (const char *)0, "word", 1, -1 },
00989           { (const char *)0, "word", 4, -1 },
00990           { "word", (const char *)0, 0, 1 },
00991           { "word", (const char *)0, 1, 1 },
00992           { "word", (const char *)0, 4, 1 },
00993           { "word", "word", 0, 0 },
00994           { "word", "word", 1, 0 },
00995           { "word", "word", 3, 0 },
00996           { "word", "word", 5, 0 },
00997           { "aZYXVUT", "bZYXVUT", 0, 0 },
00998           { "aZYXVUT", "bZYXVUT", 1, -1 },
00999           { "aZYXVUT", "bZYXVUT", 4, -1 },
01000           { "aZYXVUT", "bZYXVUT", 9, -1 },
01001           { "aZYXVUT", "bAAAAAA", 0, 0 },
01002           { "aZYXVUT", "bAAAAAA", 1, -1 },
01003           { "aZYXVUT", "bAAAAAA", 4, -1 },
01004           { "aZYXVUT", "bAAAAAA", 5, -1 },
01005           { "a", "aa", 0, 0 },
01006           { "a", "aa", 1, 0 },
01007           { "a", "aa", 4, -1 },
01008           { "a", "a", 0, 0 },
01009           { "a", "a", 1, 0 },
01010           { "a", "a", 4, 0 },
01011           { "a", "A", 0, 0 },
01012           { "a", "A", 1, 1 },
01013           { "a", "A", 4, 1 },
01014           { "aaaaa", "baaaa", 0, 0 },
01015           { "aaaaa", "baaaa", 1, -1 },
01016           { "aaaaa", "baaaa", 4, -1 },
01017           { "aaaaa", "abaaa", 0, 0 },
01018           { "aaaaa", "abaaa", 1, 0 },
01019           { "aaaaa", "abaaa", 4, -1 },
01020           { "aaaaa", "aabaa", 0, 0 },
01021           { "aaaaa", "aabaa", 1, 0 },
01022           { "aaaaa", "aabaa", 4, -1 },
01023           { "aaaaa", "aaaba", 0, 0 },
01024           { "aaaaa", "aaaba", 1, 0 },
01025           { "aaaaa", "aaaba", 4, -1 },
01026           { "aaaaa", "aaaab", 0, 0 },
01027           { "aaaaa", "aaaab", 1, 0 },
01028           { "aaaaa", "aaaab", 4, 0 },
01029           { "bZYXVUT", "aZYXVUT", 0, 0 },
01030           { "bZYXVUT", "aZYXVUT", 1, 1 },
01031           { "bZYXVUT", "aZYXVUT", 4, 1 },
01032           { "bAAAAAA", "aZYXVUT", 0, 0 },
01033           { "bAAAAAA", "aZYXVUT", 1, 1 },
01034           { "bAAAAAA", "aZYXVUT", 4, 1 },
01035           { "aa", "a", 0, 0 },
01036           { "aa", "a", 1, 0 },
01037           { "aa", "a", 4, 1 },
01038           { "A", "a", 0, 0 },
01039           { "A", "a", 1, -1 },
01040           { "A", "a", 4, -1 },
01041           { "baaaa", "aaaaa", 0, 0 },
01042           { "baaaa", "aaaaa", 1, 1 },
01043           { "baaaa", "aaaaa", 4, 1 },
01044           { "abaaa", "aaaaa", 0, 0 },
01045           { "abaaa", "aaaaa", 1, 0 },
01046           { "abaaa", "aaaaa", 4, 1 },
01047           { "aabaa", "aaaaa", 0, 0 },
01048           { "aabaa", "aaaaa", 1, 0 },
01049           { "aabaa", "aaaaa", 4, 1 },
01050           { "aaaba", "aaaaa", 0, 0 },
01051           { "aaaba", "aaaaa", 1, 0 },
01052           { "aaaba", "aaaaa", 4, 1 },
01053           { "aaaab", "aaaaa", 0, 0 },
01054           { "aaaab", "aaaaa", 1, 0 },
01055           { "aaaab", "aaaaa", 4, 0 },
01056           { "word", "Word", 0, 0 },
01057           { "word", "Word", 1, 1 },
01058           { "word", "Word", 3, 1 },
01059           { "word", "wOrd", 0, 0 },
01060           { "word", "wOrd", 1, 0 },
01061           { "word", "wOrd", 3, 1 },
01062           { "word", "woRd", 0, 0 },
01063           { "word", "woRd", 1, 0 },
01064           { "word", "woRd", 3, 1 },
01065           { "word", "worD", 0, 0 },
01066           { "word", "worD", 1, 0 },
01067           { "word", "worD", 3, 0 },
01068           { "WORD", "wORD", 0, 0 },
01069           { "WORD", "wORD", 1, -1 },
01070           { "WORD", "wORD", 3, -1 },
01071           { "WORD", "WoRD", 0, 0 },
01072           { "WORD", "WoRD", 1, 0 },
01073           { "WORD", "WoRD", 3, -1 },
01074           { "WORD", "WOrD", 0, 0 },
01075           { "WORD", "WOrD", 1, 0 },
01076           { "WORD", "WOrD", 3, -1 },
01077           { "WORD", "WORd", 0, 0 },
01078           { "WORD", "WORd", 1, 0 },
01079           { "WORD", "WORd", 3, 0 }
01080 
01081       };
01082 
01083     int i;
01084 
01085     printf("Test 012 (PL_strncmp)     ..."); fflush(stdout);
01086 
01087     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01088     {
01089         PRIntn rv = PL_strncmp(array[i].one, array[i].two, array[i].max);
01090 
01091         switch( array[i].sign )
01092         {
01093             case -1:
01094                 if( rv < 0 ) continue;
01095                 break;
01096             case 1:
01097                 if( rv > 0 ) continue;
01098                 break;
01099             case 0:
01100                 if( 0 == rv ) continue;
01101                 break;
01102             default:
01103                 PR_NOT_REACHED("static data inconsistancy");
01104                 break;
01105         }
01106 
01107         printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
01108                array[i].one ? array[i].one : "(null)",
01109                array[i].two ? array[i].two : "(null)",
01110                array[i].max, rv, array[i].sign);
01111         return PR_FALSE;
01112     }
01113 
01114     printf("PASS\n");
01115     return PR_TRUE;
01116 }
01117 
01118 /* PL_strcasecmp */
01119 PRBool test_013(void)
01120 {
01121     static struct
01122     {
01123         const char *one;
01124         const char *two;
01125         PRIntn      sign;
01126     } array[] =
01127       {
01128           { (const char *)0, (const char *)0, 0 },
01129           { (const char *)0, "word", -1 },
01130           { "word", (const char *)0, 1 },
01131           { "word", "word", 0 },
01132           { "aZYXVUT", "bZYXVUT", -1 },
01133           { "aZYXVUT", "bAAAAAA", -1 },
01134           { "a", "aa", -1 },
01135           { "a", "a", 0 },
01136           { "a", "A", 0 },
01137           { "aaaaa", "baaaa", -1 },
01138           { "aaaaa", "abaaa", -1 },
01139           { "aaaaa", "aabaa", -1 },
01140           { "aaaaa", "aaaba", -1 },
01141           { "aaaaa", "aaaab", -1 },
01142           { "bZYXVUT", "aZYXVUT", 1 },
01143           { "bAAAAAA", "aZYXVUT", 1 },
01144           { "aa", "a", 1 },
01145           { "A", "a", 0 },
01146           { "baaaa", "aaaaa", 1 },
01147           { "abaaa", "aaaaa", 1 },
01148           { "aabaa", "aaaaa", 1 },
01149           { "aaaba", "aaaaa", 1 },
01150           { "aaaab", "aaaaa", 1 },
01151           { "word", "Word", 0 },
01152           { "word", "wOrd", 0 },
01153           { "word", "woRd", 0 },
01154           { "word", "worD", 0 },
01155           { "WORD", "wORD", 0 },
01156           { "WORD", "WoRD", 0 },
01157           { "WORD", "WOrD", 0 },
01158           { "WORD", "WORd", 0 }
01159       };
01160 
01161     int i;
01162 
01163     printf("Test 013 (PL_strcasecmp)  ..."); fflush(stdout);
01164 
01165     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01166     {
01167         PRIntn rv = PL_strcasecmp(array[i].one, array[i].two);
01168 
01169         switch( array[i].sign )
01170         {
01171             case -1:
01172                 if( rv < 0 ) continue;
01173                 break;
01174             case 1:
01175                 if( rv > 0 ) continue;
01176                 break;
01177             case 0:
01178                 if( 0 == rv ) continue;
01179                 break;
01180             default:
01181                 PR_NOT_REACHED("static data inconsistancy");
01182                 break;
01183         }
01184 
01185         printf("FAIL %d: %s-%s -> %d, not %d\n", i,
01186                array[i].one ? array[i].one : "(null)",
01187                array[i].two ? array[i].two : "(null)",
01188                rv, array[i].sign);
01189         return PR_FALSE;
01190     }
01191 
01192     printf("PASS\n");
01193     return PR_TRUE;
01194 }
01195 
01196 /* PL_strncasecmp */
01197 PRBool test_014(void)
01198 {
01199     static struct
01200     {
01201         const char *one;
01202         const char *two;
01203         PRUint32    max;
01204         PRIntn      sign;
01205     } array[] =
01206       {
01207           { (const char *)0, (const char *)0, 0, 0 },
01208           { (const char *)0, (const char *)0, 1, 0 },
01209           { (const char *)0, (const char *)0, 4, 0 },
01210           { (const char *)0, "word", 0, -1 },
01211           { (const char *)0, "word", 1, -1 },
01212           { (const char *)0, "word", 4, -1 },
01213           { "word", (const char *)0, 0, 1 },
01214           { "word", (const char *)0, 1, 1 },
01215           { "word", (const char *)0, 4, 1 },
01216           { "word", "word", 0, 0 },
01217           { "word", "word", 1, 0 },
01218           { "word", "word", 3, 0 },
01219           { "word", "word", 5, 0 },
01220           { "aZYXVUT", "bZYXVUT", 0, 0 },
01221           { "aZYXVUT", "bZYXVUT", 1, -1 },
01222           { "aZYXVUT", "bZYXVUT", 4, -1 },
01223           { "aZYXVUT", "bZYXVUT", 9, -1 },
01224           { "aZYXVUT", "bAAAAAA", 0, 0 },
01225           { "aZYXVUT", "bAAAAAA", 1, -1 },
01226           { "aZYXVUT", "bAAAAAA", 4, -1 },
01227           { "aZYXVUT", "bAAAAAA", 5, -1 },
01228           { "a", "aa", 0, 0 },
01229           { "a", "aa", 1, 0 },
01230           { "a", "aa", 4, -1 },
01231           { "a", "a", 0, 0 },
01232           { "a", "a", 1, 0 },
01233           { "a", "a", 4, 0 },
01234           { "a", "A", 0, 0 },
01235           { "a", "A", 1, 0 },
01236           { "a", "A", 4, 0 },
01237           { "aaaaa", "baaaa", 0, 0 },
01238           { "aaaaa", "baaaa", 1, -1 },
01239           { "aaaaa", "baaaa", 4, -1 },
01240           { "aaaaa", "abaaa", 0, 0 },
01241           { "aaaaa", "abaaa", 1, 0 },
01242           { "aaaaa", "abaaa", 4, -1 },
01243           { "aaaaa", "aabaa", 0, 0 },
01244           { "aaaaa", "aabaa", 1, 0 },
01245           { "aaaaa", "aabaa", 4, -1 },
01246           { "aaaaa", "aaaba", 0, 0 },
01247           { "aaaaa", "aaaba", 1, 0 },
01248           { "aaaaa", "aaaba", 4, -1 },
01249           { "aaaaa", "aaaab", 0, 0 },
01250           { "aaaaa", "aaaab", 1, 0 },
01251           { "aaaaa", "aaaab", 4, 0 },
01252           { "bZYXVUT", "aZYXVUT", 0, 0 },
01253           { "bZYXVUT", "aZYXVUT", 1, 1 },
01254           { "bZYXVUT", "aZYXVUT", 4, 1 },
01255           { "bAAAAAA", "aZYXVUT", 0, 0 },
01256           { "bAAAAAA", "aZYXVUT", 1, 1 },
01257           { "bAAAAAA", "aZYXVUT", 4, 1 },
01258           { "aa", "a", 0, 0 },
01259           { "aa", "a", 1, 0 },
01260           { "aa", "a", 4, 1 },
01261           { "A", "a", 0, 0 },
01262           { "A", "a", 1, 0 },
01263           { "A", "a", 4, 0 },
01264           { "baaaa", "aaaaa", 0, 0 },
01265           { "baaaa", "aaaaa", 1, 1 },
01266           { "baaaa", "aaaaa", 4, 1 },
01267           { "abaaa", "aaaaa", 0, 0 },
01268           { "abaaa", "aaaaa", 1, 0 },
01269           { "abaaa", "aaaaa", 4, 1 },
01270           { "aabaa", "aaaaa", 0, 0 },
01271           { "aabaa", "aaaaa", 1, 0 },
01272           { "aabaa", "aaaaa", 4, 1 },
01273           { "aaaba", "aaaaa", 0, 0 },
01274           { "aaaba", "aaaaa", 1, 0 },
01275           { "aaaba", "aaaaa", 4, 1 },
01276           { "aaaab", "aaaaa", 0, 0 },
01277           { "aaaab", "aaaaa", 1, 0 },
01278           { "aaaab", "aaaaa", 4, 0 },
01279           { "word", "Word", 0, 0 },
01280           { "word", "Word", 1, 0 },
01281           { "word", "Word", 3, 0 },
01282           { "word", "wOrd", 0, 0 },
01283           { "word", "wOrd", 1, 0 },
01284           { "word", "wOrd", 3, 0 },
01285           { "word", "woRd", 0, 0 },
01286           { "word", "woRd", 1, 0 },
01287           { "word", "woRd", 3, 0 },
01288           { "word", "worD", 0, 0 },
01289           { "word", "worD", 1, 0 },
01290           { "word", "worD", 3, 0 },
01291           { "WORD", "wORD", 0, 0 },
01292           { "WORD", "wORD", 1, 0 },
01293           { "WORD", "wORD", 3, 0 },
01294           { "WORD", "WoRD", 0, 0 },
01295           { "WORD", "WoRD", 1, 0 },
01296           { "WORD", "WoRD", 3, 0 },
01297           { "WORD", "WOrD", 0, 0 },
01298           { "WORD", "WOrD", 1, 0 },
01299           { "WORD", "WOrD", 3, 0 },
01300           { "WORD", "WORd", 0, 0 },
01301           { "WORD", "WORd", 1, 0 },
01302           { "WORD", "WORd", 3, 0 }
01303       };
01304 
01305     int i;
01306 
01307     printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout);
01308 
01309     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01310     {
01311         PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max);
01312 
01313         switch( array[i].sign )
01314         {
01315             case -1:
01316                 if( rv < 0 ) continue;
01317                 break;
01318             case 1:
01319                 if( rv > 0 ) continue;
01320                 break;
01321             case 0:
01322                 if( 0 == rv ) continue;
01323                 break;
01324             default:
01325                 PR_NOT_REACHED("static data inconsistancy");
01326                 break;
01327         }
01328 
01329         printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
01330                array[i].one ? array[i].one : "(null)",
01331                array[i].two ? array[i].two : "(null)",
01332                array[i].max, rv, array[i].sign);
01333         return PR_FALSE;
01334     }
01335 
01336     printf("PASS\n");
01337     return PR_TRUE;
01338 }
01339 
01340 /* PL_strchr */
01341 PRBool test_015(void)
01342 {
01343     static struct
01344     {
01345         const char *str;
01346         char        chr;
01347         PRBool      ret;
01348         PRUint32    off;
01349     } array[] =
01350       {
01351           { (const char *)0, 'a', PR_FALSE, 0 },
01352           { (const char *)0, '\0', PR_FALSE, 0 },
01353           { "abcdefg", 'a', PR_TRUE, 0 },
01354           { "abcdefg", 'b', PR_TRUE, 1 },
01355           { "abcdefg", 'c', PR_TRUE, 2 },
01356           { "abcdefg", 'd', PR_TRUE, 3 },
01357           { "abcdefg", 'e', PR_TRUE, 4 },
01358           { "abcdefg", 'f', PR_TRUE, 5 },
01359           { "abcdefg", 'g', PR_TRUE, 6 },
01360           { "abcdefg", 'h', PR_FALSE, 0 },
01361           { "abcdefg", '\0', PR_TRUE, 7 },
01362           { "abcdefg", 'A', PR_FALSE, 0 },
01363           { "abcdefg", 'B', PR_FALSE, 0 },
01364           { "abcdefg", 'C', PR_FALSE, 0 },
01365           { "abcdefg", 'D', PR_FALSE, 0 },
01366           { "abcdefg", 'E', PR_FALSE, 0 },
01367           { "abcdefg", 'F', PR_FALSE, 0 },
01368           { "abcdefg", 'G', PR_FALSE, 0 },
01369           { "abcdefg", 'H', PR_FALSE, 0 },
01370           { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
01371           { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
01372           { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
01373           { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
01374           { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
01375           { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
01376           { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
01377           { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
01378           { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
01379       };
01380 
01381     int i;
01382 
01383     printf("Test 015 (PL_strchr)      ..."); fflush(stdout);
01384 
01385     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01386     {
01387         char *rv = PL_strchr(array[i].str, array[i].chr);
01388 
01389         if( PR_FALSE == array[i].ret )
01390         {
01391             if( (char *)0 != rv )
01392             {
01393                 printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
01394                        array[i].chr, rv);
01395                 return PR_FALSE;
01396             }
01397         }
01398         else
01399         {
01400             if( (char *)0 == rv )
01401             {
01402                 printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
01403                        array[i].chr, array[i].off);
01404                 return PR_FALSE;
01405             }
01406 
01407             if( &array[i].str[ array[i].off ] != rv )
01408             {
01409                 printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
01410                        array[i].chr, rv, array[i].str, array[i].off);
01411                 return PR_FALSE;
01412             }
01413         }
01414     }
01415 
01416     printf("PASS\n");
01417     return PR_TRUE;
01418 }
01419 
01420 /* PL_strrchr */
01421 PRBool test_016(void)
01422 {
01423     static struct
01424     {
01425         const char *str;
01426         char        chr;
01427         PRBool      ret;
01428         PRUint32    off;
01429     } array[] =
01430       {
01431           { (const char *)0, 'a', PR_FALSE, 0 },
01432           { (const char *)0, '\0', PR_FALSE, 0 },
01433           { "abcdefg", 'a', PR_TRUE, 0 },
01434           { "abcdefg", 'b', PR_TRUE, 1 },
01435           { "abcdefg", 'c', PR_TRUE, 2 },
01436           { "abcdefg", 'd', PR_TRUE, 3 },
01437           { "abcdefg", 'e', PR_TRUE, 4 },
01438           { "abcdefg", 'f', PR_TRUE, 5 },
01439           { "abcdefg", 'g', PR_TRUE, 6 },
01440           { "abcdefg", 'h', PR_FALSE, 0 },
01441           { "abcdefg", '\0', PR_TRUE, 7 },
01442           { "abcdefg", 'A', PR_FALSE, 0 },
01443           { "abcdefg", 'B', PR_FALSE, 0 },
01444           { "abcdefg", 'C', PR_FALSE, 0 },
01445           { "abcdefg", 'D', PR_FALSE, 0 },
01446           { "abcdefg", 'E', PR_FALSE, 0 },
01447           { "abcdefg", 'F', PR_FALSE, 0 },
01448           { "abcdefg", 'G', PR_FALSE, 0 },
01449           { "abcdefg", 'H', PR_FALSE, 0 },
01450           { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
01451           { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
01452           { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
01453           { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
01454           { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
01455           { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
01456           { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
01457           { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
01458           { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
01459       };
01460 
01461     int i;
01462 
01463     printf("Test 016 (PL_strrchr)     ..."); fflush(stdout);
01464 
01465     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01466     {
01467         char *rv = PL_strrchr(array[i].str, array[i].chr);
01468 
01469         if( PR_FALSE == array[i].ret )
01470         {
01471             if( (char *)0 != rv )
01472             {
01473                 printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
01474                        array[i].chr, rv);
01475                 return PR_FALSE;
01476             }
01477         }
01478         else
01479         {
01480             if( (char *)0 == rv )
01481             {
01482                 printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
01483                        array[i].chr, array[i].off);
01484                 return PR_FALSE;
01485             }
01486 
01487             if( &array[i].str[ array[i].off ] != rv )
01488             {
01489                 printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
01490                        array[i].chr, rv, array[i].str, array[i].off);
01491                 return PR_FALSE;
01492             }
01493         }
01494     }
01495 
01496     printf("PASS\n");
01497     return PR_TRUE;
01498 }
01499 
01500 /* PL_strnchr */
01501 PRBool test_017(void)
01502 {
01503     static struct
01504     {
01505         const char *str;
01506         char        chr;
01507         PRUint32    max;
01508         PRBool      ret;
01509         PRUint32    off;
01510     } array[] =
01511       {
01512           { (const char *)0, 'a', 2, PR_FALSE, 0 },
01513           { (const char *)0, '\0', 2, PR_FALSE, 0 },
01514           { "abcdefg", 'a', 5, PR_TRUE, 0 },
01515           { "abcdefg", 'b', 5, PR_TRUE, 1 },
01516           { "abcdefg", 'c', 5, PR_TRUE, 2 },
01517           { "abcdefg", 'd', 5, PR_TRUE, 3 },
01518           { "abcdefg", 'e', 5, PR_TRUE, 4 },
01519           { "abcdefg", 'f', 5, PR_FALSE, 0 },
01520           { "abcdefg", 'g', 5, PR_FALSE, 0 },
01521           { "abcdefg", 'h', 5, PR_FALSE, 0 },
01522           { "abcdefg", '\0', 5, PR_FALSE, 0 },
01523           { "abcdefg", '\0', 15, PR_TRUE, 7 },
01524           { "abcdefg", 'A', 5, PR_FALSE, 0 },
01525           { "abcdefg", 'B', 5, PR_FALSE, 0 },
01526           { "abcdefg", 'C', 5, PR_FALSE, 0 },
01527           { "abcdefg", 'D', 5, PR_FALSE, 0 },
01528           { "abcdefg", 'E', 5, PR_FALSE, 0 },
01529           { "abcdefg", 'F', 5, PR_FALSE, 0 },
01530           { "abcdefg", 'G', 5, PR_FALSE, 0 },
01531           { "abcdefg", 'H', 5, PR_FALSE, 0 },
01532           { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
01533           { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
01534           { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
01535           { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
01536           { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
01537           { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
01538           { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
01539           { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
01540           { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
01541           { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
01542           { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
01543       };
01544 
01545     int i;
01546 
01547     printf("Test 017 (PL_strnchr)     ..."); fflush(stdout);
01548 
01549     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01550     {
01551         char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max);
01552 
01553         if( PR_FALSE == array[i].ret )
01554         {
01555             if( (char *)0 != rv )
01556             {
01557                 printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
01558                        array[i].chr, array[i].max, rv);
01559                 return PR_FALSE;
01560             }
01561         }
01562         else
01563         {
01564             if( (char *)0 == rv )
01565             {
01566                 printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
01567                        array[i].chr, array[i].max, array[i].off);
01568                 return PR_FALSE;
01569             }
01570 
01571             if( &array[i].str[ array[i].off ] != rv )
01572             {
01573                 printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
01574                        array[i].chr, array[i].max, rv, array[i].str, array[i].off);
01575                 return PR_FALSE;
01576             }
01577         }
01578     }
01579 
01580     printf("PASS\n");
01581     return PR_TRUE;
01582 }
01583 
01584 /* PL_strnrchr */
01585 PRBool test_018(void)
01586 {
01587     static struct
01588     {
01589         const char *str;
01590         char        chr;
01591         PRUint32    max;
01592         PRBool      ret;
01593         PRUint32    off;
01594     } array[] =
01595       {
01596           { (const char *)0, 'a', 2, PR_FALSE, 0 },
01597           { (const char *)0, '\0', 2, PR_FALSE, 0 },
01598           { "abcdefg", 'a', 5, PR_TRUE, 0 },
01599           { "abcdefg", 'b', 5, PR_TRUE, 1 },
01600           { "abcdefg", 'c', 5, PR_TRUE, 2 },
01601           { "abcdefg", 'd', 5, PR_TRUE, 3 },
01602           { "abcdefg", 'e', 5, PR_TRUE, 4 },
01603           { "abcdefg", 'f', 5, PR_FALSE, 0 },
01604           { "abcdefg", 'g', 5, PR_FALSE, 0 },
01605           { "abcdefg", 'h', 5, PR_FALSE, 0 },
01606           { "abcdefg", '\0', 5, PR_FALSE, 0 },
01607           { "abcdefg", '\0', 15, PR_TRUE, 7 },
01608           { "abcdefg", 'A', 5, PR_FALSE, 0 },
01609           { "abcdefg", 'B', 5, PR_FALSE, 0 },
01610           { "abcdefg", 'C', 5, PR_FALSE, 0 },
01611           { "abcdefg", 'D', 5, PR_FALSE, 0 },
01612           { "abcdefg", 'E', 5, PR_FALSE, 0 },
01613           { "abcdefg", 'F', 5, PR_FALSE, 0 },
01614           { "abcdefg", 'G', 5, PR_FALSE, 0 },
01615           { "abcdefg", 'H', 5, PR_FALSE, 0 },
01616           { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
01617           { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
01618           { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
01619           { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
01620           { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
01621           { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
01622           { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
01623           { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
01624           { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
01625           { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
01626           { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
01627       };
01628 
01629     int i;
01630 
01631     printf("Test 018 (PL_strnrchr)    ..."); fflush(stdout);
01632 
01633     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01634     {
01635         char *rv = PL_strnrchr(array[i].str, array[i].chr, array[i].max);
01636 
01637         if( PR_FALSE == array[i].ret )
01638         {
01639             if( (char *)0 != rv )
01640             {
01641                 printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
01642                        array[i].chr, array[i].max, rv);
01643                 return PR_FALSE;
01644             }
01645         }
01646         else
01647         {
01648             if( (char *)0 == rv )
01649             {
01650                 printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
01651                        array[i].chr, array[i].max, array[i].off);
01652                 return PR_FALSE;
01653             }
01654 
01655             if( &array[i].str[ array[i].off ] != rv )
01656             {
01657                 printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
01658                        array[i].chr, array[i].max, rv, array[i].str, array[i].off);
01659                 return PR_FALSE;
01660             }
01661         }
01662     }
01663 
01664     printf("PASS\n");
01665     return PR_TRUE;
01666 }
01667 
01668 /* PL_strpbrk */
01669 PRBool test_019(void)
01670 {
01671     static struct
01672     {
01673         const char *str;
01674         const char *chrs;
01675         PRBool      ret;
01676         PRUint32    off;
01677     } array[] =
01678       {
01679           { (const char *)0, (const char *)0, PR_FALSE, 0 },
01680           { (const char *)0, "abc", PR_FALSE, 0 },
01681           { "abc", (const char *)0, PR_FALSE, 0 },
01682           { "abcdefg", "", PR_FALSE, 0 },
01683           { "", "aeiou", PR_FALSE, 0 },
01684           { "abcdefg", "ae", PR_TRUE, 0 },
01685           { "abcdefg", "ei", PR_TRUE, 4 },
01686           { "abcdefg", "io", PR_FALSE, 0 },
01687           { "abcdefg", "bcd", PR_TRUE, 1 },
01688           { "abcdefg", "cbd", PR_TRUE, 1 },
01689           { "abcdefg", "dbc", PR_TRUE, 1 },
01690           { "abcdefg", "ghi", PR_TRUE, 6 },
01691           { "abcdefg", "AE", PR_FALSE, 0 },
01692           { "abcdefg", "EI", PR_FALSE, 0 },
01693           { "abcdefg", "IO", PR_FALSE, 0 },
01694           { "abcdefg", "BCD", PR_FALSE, 0 },
01695           { "abcdefg", "CBD", PR_FALSE, 0 },
01696           { "abcdefg", "DBC", PR_FALSE, 0 },
01697           { "abcdefg", "GHI", PR_FALSE, 0 },
01698           { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
01699           { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
01700           { "abcdefgabcdefg", "io", PR_FALSE, 0 },
01701           { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
01702           { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
01703           { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
01704           { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
01705           { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
01706           { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
01707           { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
01708           { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
01709           { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
01710           { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
01711           { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
01712       };
01713 
01714     int i;
01715 
01716     printf("Test 019 (PL_strpbrk)     ..."); fflush(stdout);
01717 
01718     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01719     {
01720         char *rv = PL_strpbrk(array[i].str, array[i].chrs);
01721 
01722         if( PR_FALSE == array[i].ret )
01723         {
01724             if( (char *)0 != rv )
01725             {
01726                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i, 
01727                        array[i].str ? array[i].str : "(null)",
01728                        array[i].chrs ? array[i].chrs : "(null)", 
01729                        rv);
01730                 return PR_FALSE;
01731             }
01732         }
01733         else
01734         {
01735             if( (char *)0 == rv )
01736             {
01737                 printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
01738                        array[i].str ? array[i].str : "(null)",
01739                        array[i].chrs ? array[i].chrs : "(null)", 
01740                        array[i].off);
01741                 return PR_FALSE;
01742             }
01743 
01744             if( &array[i].str[ array[i].off ] != rv )
01745             {
01746                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
01747                        array[i].str ? array[i].str : "(null)",
01748                        array[i].chrs ? array[i].chrs : "(null)", 
01749                        rv, array[i].str, array[i].off);
01750                 return PR_FALSE;
01751             }
01752         }
01753     }
01754 
01755     printf("PASS\n");
01756     return PR_TRUE;
01757 }
01758 
01759 /* PL_strprbrk */
01760 PRBool test_020(void)
01761 {
01762     static struct
01763     {
01764         const char *str;
01765         const char *chrs;
01766         PRBool      ret;
01767         PRUint32    off;
01768     } array[] =
01769       {
01770           { (const char *)0, (const char *)0, PR_FALSE, 0 },
01771           { (const char *)0, "abc", PR_FALSE, 0 },
01772           { "abc", (const char *)0, PR_FALSE, 0 },
01773           { "abcdefg", "", PR_FALSE, 0 },
01774           { "", "aeiou", PR_FALSE, 0 },
01775           { "abcdefg", "ae", PR_TRUE, 4 },
01776           { "abcdefg", "ei", PR_TRUE, 4 },
01777           { "abcdefg", "io", PR_FALSE, 0 },
01778           { "abcdefg", "bcd", PR_TRUE, 3 },
01779           { "abcdefg", "cbd", PR_TRUE, 3 },
01780           { "abcdefg", "dbc", PR_TRUE, 3 },
01781           { "abcdefg", "ghi", PR_TRUE, 6 },
01782           { "abcdefg", "AE", PR_FALSE, 0 },
01783           { "abcdefg", "EI", PR_FALSE, 0 },
01784           { "abcdefg", "IO", PR_FALSE, 0 },
01785           { "abcdefg", "BCD", PR_FALSE, 0 },
01786           { "abcdefg", "CBD", PR_FALSE, 0 },
01787           { "abcdefg", "DBC", PR_FALSE, 0 },
01788           { "abcdefg", "GHI", PR_FALSE, 0 },
01789           { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
01790           { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
01791           { "abcdefgabcdefg", "io", PR_FALSE, 0 },
01792           { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
01793           { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
01794           { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
01795           { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
01796           { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
01797           { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
01798           { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
01799           { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
01800           { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
01801           { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
01802           { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
01803       };
01804 
01805     int i;
01806 
01807     printf("Test 020 (PL_strprbrk)    ..."); fflush(stdout);
01808 
01809     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01810     {
01811         char *rv = PL_strprbrk(array[i].str, array[i].chrs);
01812 
01813         if( PR_FALSE == array[i].ret )
01814         {
01815             if( (char *)0 != rv )
01816             {
01817                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i, 
01818                        array[i].str ? array[i].str : "(null)",
01819                        array[i].chrs ? array[i].chrs : "(null)", 
01820                        rv);
01821                 return PR_FALSE;
01822             }
01823         }
01824         else
01825         {
01826             if( (char *)0 == rv )
01827             {
01828                 printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
01829                        array[i].str ? array[i].str : "(null)",
01830                        array[i].chrs ? array[i].chrs : "(null)", 
01831                        array[i].off);
01832                 return PR_FALSE;
01833             }
01834 
01835             if( &array[i].str[ array[i].off ] != rv )
01836             {
01837                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
01838                        array[i].str ? array[i].str : "(null)",
01839                        array[i].chrs ? array[i].chrs : "(null)", 
01840                        rv, array[i].str, array[i].off);
01841                 return PR_FALSE;
01842             }
01843         }
01844     }
01845 
01846     printf("PASS\n");
01847     return PR_TRUE;
01848 }
01849                        
01850 /* PL_strnpbrk */
01851 PRBool test_021(void)
01852 {
01853     static struct
01854     {
01855         const char *str;
01856         const char *chrs;
01857         PRUint32    max;
01858         PRBool      ret;
01859         PRUint32    off;
01860     } array[] =
01861       {
01862           { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
01863           { (const char *)0, "abc", 3, PR_FALSE, 0 },
01864           { "abc", (const char *)0, 3, PR_FALSE, 0 },
01865           { "abcdefg", "", 3, PR_FALSE, 0 },
01866           { "", "aeiou", 3, PR_FALSE, 0 },
01867           { "abcdefg", "ae", 0, PR_FALSE, 0 },
01868           { "abcdefg", "ae", 1, PR_TRUE, 0 },
01869           { "abcdefg", "ae", 4, PR_TRUE, 0 },
01870           { "abcdefg", "ae", 5, PR_TRUE, 0 },
01871           { "abcdefg", "ae", 6, PR_TRUE, 0 },
01872           { "abcdefg", "ei", 4, PR_FALSE, 0 },
01873           { "abcdefg", "io", 10, PR_FALSE, 0 },
01874           { "abcdefg", "bcd", 2, PR_TRUE, 1 },
01875           { "abcdefg", "cbd", 2, PR_TRUE, 1 },
01876           { "abcdefg", "dbc", 2, PR_TRUE, 1 },
01877           { "abcdefg", "ghi", 6, PR_FALSE, 0 },
01878           { "abcdefg", "ghi", 7, PR_TRUE, 6 },
01879           { "abcdefg", "AE", 9, PR_FALSE, 0 },
01880           { "abcdefg", "EI", 9, PR_FALSE, 0 },
01881           { "abcdefg", "IO", 9, PR_FALSE, 0 },
01882           { "abcdefg", "BCD", 9, PR_FALSE, 0 },
01883           { "abcdefg", "CBD", 9, PR_FALSE, 0 },
01884           { "abcdefg", "DBC", 9, PR_FALSE, 0 },
01885           { "abcdefg", "GHI", 9, PR_FALSE, 0 },
01886           { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
01887           { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
01888           { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
01889           { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
01890           { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
01891           { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
01892           { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
01893           { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
01894           { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
01895           { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
01896           { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
01897           { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
01898           { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
01899           { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
01900       };
01901 
01902     int i;
01903 
01904     printf("Test 021 (PL_strnpbrk)    ..."); fflush(stdout);
01905 
01906     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
01907     {
01908         char *rv = PL_strnpbrk(array[i].str, array[i].chrs, array[i].max);
01909 
01910         if( PR_FALSE == array[i].ret )
01911         {
01912             if( (char *)0 != rv )
01913             {
01914                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, 
01915                        array[i].str ? array[i].str : "(null)",
01916                        array[i].chrs ? array[i].chrs : "(null)", 
01917                        array[i].max, rv);
01918                 return PR_FALSE;
01919             }
01920         }
01921         else
01922         {
01923             if( (char *)0 == rv )
01924             {
01925                 printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
01926                        array[i].str ? array[i].str : "(null)",
01927                        array[i].chrs ? array[i].chrs : "(null)", 
01928                        array[i].max, array[i].off);
01929                 return PR_FALSE;
01930             }
01931 
01932             if( &array[i].str[ array[i].off ] != rv )
01933             {
01934                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
01935                        array[i].str ? array[i].str : "(null)",
01936                        array[i].chrs ? array[i].chrs : "(null)", 
01937                        array[i].max, rv, array[i].str, array[i].off);
01938                 return PR_FALSE;
01939             }
01940         }
01941     }
01942 
01943     printf("PASS\n");
01944     return PR_TRUE;
01945 }
01946 
01947 /* PL_strnprbrk */
01948 PRBool test_022(void)
01949 {
01950     static struct
01951     {
01952         const char *str;
01953         const char *chrs;
01954         PRUint32    max;
01955         PRBool      ret;
01956         PRUint32    off;
01957     } array[] =
01958       {
01959           { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
01960           { (const char *)0, "abc", 3, PR_FALSE, 0 },
01961           { "abc", (const char *)0, 3, PR_FALSE, 0 },
01962           { "abcdefg", "", 3, PR_FALSE, 0 },
01963           { "", "aeiou", 3, PR_FALSE, 0 },
01964           { "abcdefg", "ae", 0, PR_FALSE, 0 },
01965           { "abcdefg", "ae", 1, PR_TRUE, 0 },
01966           { "abcdefg", "ae", 4, PR_TRUE, 0 },
01967           { "abcdefg", "ae", 5, PR_TRUE, 4 },
01968           { "abcdefg", "ae", 6, PR_TRUE,  4 },
01969           { "abcdefg", "ei", 4, PR_FALSE, 0 },
01970           { "abcdefg", "io", 10, PR_FALSE, 0 },
01971           { "abcdefg", "bcd", 2, PR_TRUE, 1 },
01972           { "abcdefg", "cbd", 2, PR_TRUE, 1 },
01973           { "abcdefg", "dbc", 2, PR_TRUE, 1 },
01974           { "abcdefg", "bcd", 3, PR_TRUE, 2 },
01975           { "abcdefg", "cbd", 3, PR_TRUE, 2 },
01976           { "abcdefg", "dbc", 3, PR_TRUE, 2 },
01977           { "abcdefg", "bcd", 5, PR_TRUE, 3 },
01978           { "abcdefg", "cbd", 5, PR_TRUE, 3 },
01979           { "abcdefg", "dbc", 5, PR_TRUE, 3 },
01980           { "abcdefg", "bcd", 15, PR_TRUE, 3 },
01981           { "abcdefg", "cbd", 15, PR_TRUE, 3 },
01982           { "abcdefg", "dbc", 15, PR_TRUE, 3 },
01983           { "abcdefg", "ghi", 6, PR_FALSE, 0 },
01984           { "abcdefg", "ghi", 7, PR_TRUE, 6 },
01985           { "abcdefg", "AE", 9, PR_FALSE, 0 },
01986           { "abcdefg", "EI", 9, PR_FALSE, 0 },
01987           { "abcdefg", "IO", 9, PR_FALSE, 0 },
01988           { "abcdefg", "BCD", 9, PR_FALSE, 0 },
01989           { "abcdefg", "CBD", 9, PR_FALSE, 0 },
01990           { "abcdefg", "DBC", 9, PR_FALSE, 0 },
01991           { "abcdefg", "GHI", 9, PR_FALSE, 0 },
01992           { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
01993           { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
01994           { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
01995           { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
01996           { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
01997           { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
01998           { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
01999           { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
02000           { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
02001           { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
02002           { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
02003           { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
02004           { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
02005           { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
02006       };
02007 
02008     int i;
02009 
02010     printf("Test 022 (PL_strnprbrk)   ..."); fflush(stdout);
02011 
02012     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02013     {
02014         char *rv = PL_strnprbrk(array[i].str, array[i].chrs, array[i].max);
02015 
02016         if( PR_FALSE == array[i].ret )
02017         {
02018             if( (char *)0 != rv )
02019             {
02020                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, 
02021                        array[i].str ? array[i].str : "(null)",
02022                        array[i].chrs ? array[i].chrs : "(null)", 
02023                        array[i].max, rv);
02024                 return PR_FALSE;
02025             }
02026         }
02027         else
02028         {
02029             if( (char *)0 == rv )
02030             {
02031                 printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
02032                        array[i].str ? array[i].str : "(null)",
02033                        array[i].chrs ? array[i].chrs : "(null)", 
02034                        array[i].max, array[i].off);
02035                 return PR_FALSE;
02036             }
02037 
02038             if( &array[i].str[ array[i].off ] != rv )
02039             {
02040                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
02041                        array[i].str ? array[i].str : "(null)",
02042                        array[i].chrs ? array[i].chrs : "(null)", 
02043                        array[i].max, rv, array[i].str, array[i].off);
02044                 return PR_FALSE;
02045             }
02046         }
02047     }
02048 
02049     printf("PASS\n");
02050     return PR_TRUE;
02051 }
02052 
02053 /* PL_strstr */
02054 PRBool test_023(void)
02055 {
02056     static struct
02057     {
02058         const char *str;
02059         const char *sub;
02060         PRBool      ret;
02061         PRUint32    off;
02062     } array[] =
02063       {
02064           { (const char *)0, (const char *)0, PR_FALSE, 0 },
02065           { (const char *)0, "blah", PR_FALSE, 0 },
02066           { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
02067           { "blah-de-blah", "blah", PR_TRUE, 0 },
02068           { "", "blah", PR_FALSE, 0 },
02069           { "blah-de-blah", "", PR_FALSE, 0 },
02070           { "abcdefg", "a", PR_TRUE, 0 },
02071           { "abcdefg", "c", PR_TRUE, 2 },
02072           { "abcdefg", "e", PR_TRUE, 4 },
02073           { "abcdefg", "g", PR_TRUE, 6 },
02074           { "abcdefg", "i", PR_FALSE, 0 },
02075           { "abcdefg", "ab", PR_TRUE, 0 },
02076           { "abcdefg", "cd", PR_TRUE, 2 },
02077           { "abcdefg", "ef", PR_TRUE, 4 },
02078           { "abcdefg", "gh", PR_FALSE, 0 },
02079           { "abcdabc", "bc", PR_TRUE, 1 },
02080           { "abcdefg", "abcdefg", PR_TRUE, 0 },
02081           { "abcdefgabcdefg", "a", PR_TRUE, 0 },
02082           { "abcdefgabcdefg", "c", PR_TRUE, 2 },
02083           { "abcdefgabcdefg", "e", PR_TRUE, 4 },
02084           { "abcdefgabcdefg", "g", PR_TRUE, 6 },
02085           { "abcdefgabcdefg", "i", PR_FALSE, 0 },
02086           { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
02087           { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
02088           { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
02089           { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
02090           { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
02091           { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
02092           { "ABCDEFG", "a", PR_FALSE, 0 },
02093           { "ABCDEFG", "c", PR_FALSE, 0 },
02094           { "ABCDEFG", "e", PR_FALSE, 0 },
02095           { "ABCDEFG", "g", PR_FALSE, 0 },
02096           { "ABCDEFG", "i", PR_FALSE, 0 },
02097           { "ABCDEFG", "ab", PR_FALSE, 0 },
02098           { "ABCDEFG", "cd", PR_FALSE, 0 },
02099           { "ABCDEFG", "ef", PR_FALSE, 0 },
02100           { "ABCDEFG", "gh", PR_FALSE, 0 },
02101           { "ABCDABC", "bc", PR_FALSE, 0 },
02102           { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
02103           { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
02104           { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
02105           { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
02106           { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
02107           { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
02108           { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
02109           { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
02110           { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
02111           { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
02112           { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
02113           { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
02114       };
02115 
02116     int i;
02117 
02118     printf("Test 023 (PL_strstr)      ..."); fflush(stdout);
02119 
02120     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02121     {
02122         char *rv = PL_strstr(array[i].str, array[i].sub);
02123 
02124         if( PR_FALSE == array[i].ret )
02125         {
02126             if( (char *)0 != rv )
02127             {
02128                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
02129                        array[i].str ? array[i].str : "(null)",
02130                        array[i].sub ? array[i].sub : "(null)",
02131                        rv);
02132                 return PR_FALSE;
02133             }
02134         }
02135         else
02136         {
02137             if( (char *)0 == rv )
02138             {
02139                 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
02140                        array[i].str ? array[i].str : "(null)",
02141                        array[i].sub ? array[i].sub : "(null)",
02142                        array[i].str, array[i].off);
02143                 return PR_FALSE;
02144             }
02145 
02146             if( &array[i].str[ array[i].off ] != rv )
02147             {
02148                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
02149                        array[i].str ? array[i].str : "(null)",
02150                        array[i].sub ? array[i].sub : "(null)",
02151                        rv, array[i].str, array[i].off);
02152                 return PR_FALSE;
02153             }
02154         }
02155     }
02156 
02157     printf("PASS\n");
02158     return PR_TRUE;
02159 }
02160 
02161 /* PL_strrstr */
02162 PRBool test_024(void)
02163 {
02164     static struct
02165     {
02166         const char *str;
02167         const char *sub;
02168         PRBool      ret;
02169         PRUint32    off;
02170     } array[] =
02171       {
02172           { (const char *)0, (const char *)0, PR_FALSE, 0 },
02173           { (const char *)0, "blah", PR_FALSE, 0 },
02174           { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
02175           { "blah-de-blah", "blah", PR_TRUE, 8 },
02176           { "", "blah", PR_FALSE, 0 },
02177           { "blah-de-blah", "", PR_FALSE, 0 },
02178           { "abcdefg", "a", PR_TRUE, 0 },
02179           { "abcdefg", "c", PR_TRUE, 2 },
02180           { "abcdefg", "e", PR_TRUE, 4 },
02181           { "abcdefg", "g", PR_TRUE, 6 },
02182           { "abcdefg", "i", PR_FALSE, 0 },
02183           { "abcdefg", "ab", PR_TRUE, 0 },
02184           { "abcdefg", "cd", PR_TRUE, 2 },
02185           { "abcdefg", "ef", PR_TRUE, 4 },
02186           { "abcdefg", "gh", PR_FALSE, 0 },
02187           { "abcdabc", "bc", PR_TRUE, 5 },
02188           { "abcdefg", "abcdefg", PR_TRUE, 0 },
02189           { "abcdefgabcdefg", "a", PR_TRUE, 7 },
02190           { "abcdefgabcdefg", "c", PR_TRUE, 9 },
02191           { "abcdefgabcdefg", "e", PR_TRUE, 11 },
02192           { "abcdefgabcdefg", "g", PR_TRUE, 13 },
02193           { "abcdefgabcdefg", "i", PR_FALSE, 0 },
02194           { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
02195           { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
02196           { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
02197           { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
02198           { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
02199           { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
02200           { "ABCDEFG", "a", PR_FALSE, 0 },
02201           { "ABCDEFG", "c", PR_FALSE, 0 },
02202           { "ABCDEFG", "e", PR_FALSE, 0 },
02203           { "ABCDEFG", "g", PR_FALSE, 0 },
02204           { "ABCDEFG", "i", PR_FALSE, 0 },
02205           { "ABCDEFG", "ab", PR_FALSE, 0 },
02206           { "ABCDEFG", "cd", PR_FALSE, 0 },
02207           { "ABCDEFG", "ef", PR_FALSE, 0 },
02208           { "ABCDEFG", "gh", PR_FALSE, 0 },
02209           { "ABCDABC", "bc", PR_FALSE, 0 },
02210           { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
02211           { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
02212           { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
02213           { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
02214           { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
02215           { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
02216           { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
02217           { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
02218           { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
02219           { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
02220           { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
02221           { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
02222       };
02223 
02224     int i;
02225 
02226     printf("Test 024 (PL_strrstr)     ..."); fflush(stdout);
02227 
02228     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02229     {
02230         char *rv = PL_strrstr(array[i].str, array[i].sub);
02231 
02232         if( PR_FALSE == array[i].ret )
02233         {
02234             if( (char *)0 != rv )
02235             {
02236                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
02237                        array[i].str ? array[i].str : "(null)",
02238                        array[i].sub ? array[i].sub : "(null)",
02239                        rv);
02240                 return PR_FALSE;
02241             }
02242         }
02243         else
02244         {
02245             if( (char *)0 == rv )
02246             {
02247                 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
02248                        array[i].str ? array[i].str : "(null)",
02249                        array[i].sub ? array[i].sub : "(null)",
02250                        array[i].str, array[i].off);
02251                 return PR_FALSE;
02252             }
02253 
02254             if( &array[i].str[ array[i].off ] != rv )
02255             {
02256                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
02257                        array[i].str ? array[i].str : "(null)",
02258                        array[i].sub ? array[i].sub : "(null)",
02259                        rv, array[i].str, array[i].off);
02260                 return PR_FALSE;
02261             }
02262         }
02263     }
02264 
02265     printf("PASS\n");
02266     return PR_TRUE;
02267 }
02268 
02269 /* PL_strnstr */
02270 PRBool test_025(void)
02271 {
02272     static struct
02273     {
02274         const char *str;
02275         const char *sub;
02276         PRUint32    max;
02277         PRBool      ret;
02278         PRUint32    off;
02279     } array[] =
02280       {
02281           { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
02282           { (const char *)0, "blah", 12, PR_FALSE, 0 },
02283           { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
02284           { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
02285           { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
02286           { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
02287           { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
02288           { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
02289           { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
02290           { "", "blah", 12, PR_FALSE, 0 },
02291           { "blah-de-blah", "", 12, PR_FALSE, 0 },
02292           { "abcdefg", "a", 5, PR_TRUE, 0 },
02293           { "abcdefg", "c", 5, PR_TRUE, 2 },
02294           { "abcdefg", "e", 5, PR_TRUE, 4 },
02295           { "abcdefg", "g", 5, PR_FALSE, 0 },
02296           { "abcdefg", "i", 5, PR_FALSE, 0 },
02297           { "abcdefg", "ab", 5, PR_TRUE, 0 },
02298           { "abcdefg", "cd", 5, PR_TRUE, 2 },
02299           { "abcdefg", "ef", 5, PR_FALSE, 0 },
02300           { "abcdefg", "gh", 5, PR_FALSE, 0 },
02301           { "abcdabc", "bc", 5, PR_TRUE, 1 },
02302           { "abcdabc", "bc", 6, PR_TRUE, 1 },
02303           { "abcdabc", "bc", 7, PR_TRUE, 1 },
02304           { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
02305           { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
02306           { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
02307           { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
02308           { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
02309           { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
02310           { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
02311           { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
02312           { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
02313           { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
02314           { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
02315           { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
02316           { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
02317           { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
02318           { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
02319           { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
02320           { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
02321           { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
02322           { "ABCDEFG", "a", 5, PR_FALSE, 0 },
02323           { "ABCDEFG", "c", 5, PR_FALSE, 0 },
02324           { "ABCDEFG", "e", 5, PR_FALSE, 0 },
02325           { "ABCDEFG", "g", 5, PR_FALSE, 0 },
02326           { "ABCDEFG", "i", 5, PR_FALSE, 0 },
02327           { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
02328           { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
02329           { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
02330           { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
02331           { "ABCDABC", "bc", 5, PR_FALSE, 0 },
02332           { "ABCDABC", "bc", 6, PR_FALSE, 0 },
02333           { "ABCDABC", "bc", 7, PR_FALSE, 0 },
02334           { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02335           { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
02336           { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
02337           { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
02338           { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
02339           { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
02340           { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
02341           { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
02342           { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
02343           { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
02344           { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
02345           { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
02346           { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
02347           { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
02348           { "ABCDABCABCDABC", "bc", 7, PR_FALSE,  },
02349           { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02350           { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
02351           { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
02352       };
02353 
02354     int i;
02355 
02356     printf("Test 025 (PL_strnstr)     ..."); fflush(stdout);
02357 
02358     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02359     {
02360         char *rv = PL_strnstr(array[i].str, array[i].sub, array[i].max);
02361 
02362         if( PR_FALSE == array[i].ret )
02363         {
02364             if( (char *)0 != rv )
02365             {
02366                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
02367                        array[i].str ? array[i].str : "(null)",
02368                        array[i].sub ? array[i].sub : "(null)",
02369                        array[i].max, rv);
02370                 return PR_FALSE;
02371             }
02372         }
02373         else
02374         {
02375             if( (char *)0 == rv )
02376             {
02377                 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
02378                        array[i].str ? array[i].str : "(null)",
02379                        array[i].sub ? array[i].sub : "(null)",
02380                        array[i].max, array[i].str, array[i].off);
02381                 return PR_FALSE;
02382             }
02383 
02384             if( &array[i].str[ array[i].off ] != rv )
02385             {
02386                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
02387                        array[i].str ? array[i].str : "(null)",
02388                        array[i].sub ? array[i].sub : "(null)",
02389                        array[i].max, rv, array[i].str, array[i].off);
02390                 return PR_FALSE;
02391             }
02392         }
02393     }
02394 
02395     printf("PASS\n");
02396     return PR_TRUE;
02397 }
02398 
02399 /* PL_strnrstr */
02400 PRBool test_026(void)
02401 {
02402     static struct
02403     {
02404         const char *str;
02405         const char *sub;
02406         PRUint32    max;
02407         PRBool      ret;
02408         PRUint32    off;
02409     } array[] =
02410       {
02411           { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
02412           { (const char *)0, "blah", 12, PR_FALSE, 0 },
02413           { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
02414           { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
02415           { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
02416           { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
02417           { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
02418           { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
02419           { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
02420           { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
02421           { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
02422           { "", "blah", 12, PR_FALSE, 0 },
02423           { "blah-de-blah", "", 12, PR_FALSE, 0 },
02424           { "abcdefg", "a", 5, PR_TRUE, 0 },
02425           { "abcdefg", "c", 5, PR_TRUE, 2 },
02426           { "abcdefg", "e", 5, PR_TRUE, 4 },
02427           { "abcdefg", "g", 5, PR_FALSE, 0 },
02428           { "abcdefg", "i", 5, PR_FALSE, 0 },
02429           { "abcdefg", "ab", 5, PR_TRUE, 0 },
02430           { "abcdefg", "cd", 5, PR_TRUE, 2 },
02431           { "abcdefg", "ef", 5, PR_FALSE, 0 },
02432           { "abcdefg", "gh", 5, PR_FALSE, 0 },
02433           { "abcdabc", "bc", 5, PR_TRUE, 1 },
02434           { "abcdabc", "bc", 6, PR_TRUE, 1 },
02435           { "abcdabc", "bc", 7, PR_TRUE, 5 },
02436           { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
02437           { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
02438           { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
02439           { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
02440           { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
02441           { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
02442           { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
02443           { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
02444           { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
02445           { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
02446           { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
02447           { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
02448           { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
02449           { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
02450           { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
02451           { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
02452           { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
02453           { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
02454           { "ABCDEFG", "a", 5, PR_FALSE, 0 },
02455           { "ABCDEFG", "c", 5, PR_FALSE, 0 },
02456           { "ABCDEFG", "e", 5, PR_FALSE, 0 },
02457           { "ABCDEFG", "g", 5, PR_FALSE, 0 },
02458           { "ABCDEFG", "i", 5, PR_FALSE, 0 },
02459           { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
02460           { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
02461           { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
02462           { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
02463           { "ABCDABC", "bc", 5, PR_FALSE, 0 },
02464           { "ABCDABC", "bc", 6, PR_FALSE, 0 },
02465           { "ABCDABC", "bc", 7, PR_FALSE, 0 },
02466           { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02467           { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
02468           { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
02469           { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
02470           { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
02471           { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
02472           { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
02473           { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
02474           { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
02475           { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
02476           { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
02477           { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
02478           { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
02479           { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
02480           { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
02481           { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
02482           { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
02483           { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
02484       };
02485 
02486     int i;
02487 
02488     printf("Test 026 (PL_strnrstr)    ..."); fflush(stdout);
02489 
02490     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02491     {
02492         char *rv = PL_strnrstr(array[i].str, array[i].sub, array[i].max);
02493 
02494         if( PR_FALSE == array[i].ret )
02495         {
02496             if( (char *)0 != rv )
02497             {
02498                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
02499                        array[i].str ? array[i].str : "(null)",
02500                        array[i].sub ? array[i].sub : "(null)",
02501                        array[i].max, rv);
02502                 return PR_FALSE;
02503             }
02504         }
02505         else
02506         {
02507             if( (char *)0 == rv )
02508             {
02509                 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
02510                        array[i].str ? array[i].str : "(null)",
02511                        array[i].sub ? array[i].sub : "(null)",
02512                        array[i].max, array[i].str, array[i].off);
02513                 return PR_FALSE;
02514             }
02515 
02516             if( &array[i].str[ array[i].off ] != rv )
02517             {
02518                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
02519                        array[i].str ? array[i].str : "(null)",
02520                        array[i].sub ? array[i].sub : "(null)",
02521                        array[i].max, rv, array[i].str, array[i].off);
02522                 return PR_FALSE;
02523             }
02524         }
02525     }
02526 
02527     printf("PASS\n");
02528     return PR_TRUE;
02529 }
02530 
02531 /* PL_strcasestr */
02532 PRBool test_027(void)
02533 {
02534     static struct
02535     {
02536         const char *str;
02537         const char *sub;
02538         PRBool      ret;
02539         PRUint32    off;
02540     } array[] =
02541       {
02542           { (const char *)0, (const char *)0, PR_FALSE, 0 },
02543           { (const char *)0, "blah", PR_FALSE, 0 },
02544           { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
02545           { "blah-de-blah", "blah", PR_TRUE, 0 },
02546           { "", "blah", PR_FALSE, 0 },
02547           { "blah-de-blah", "", PR_FALSE, 0 },
02548           { "abcdefg", "a", PR_TRUE, 0 },
02549           { "abcdefg", "c", PR_TRUE, 2 },
02550           { "abcdefg", "e", PR_TRUE, 4 },
02551           { "abcdefg", "g", PR_TRUE, 6 },
02552           { "abcdefg", "i", PR_FALSE, 0 },
02553           { "abcdefg", "ab", PR_TRUE, 0 },
02554           { "abcdefg", "cd", PR_TRUE, 2 },
02555           { "abcdefg", "ef", PR_TRUE, 4 },
02556           { "abcdefg", "gh", PR_FALSE, 0 },
02557           { "abcdabc", "bc", PR_TRUE, 1 },
02558           { "abcdefg", "abcdefg", PR_TRUE, 0 },
02559           { "abcdefgabcdefg", "a", PR_TRUE, 0 },
02560           { "abcdefgabcdefg", "c", PR_TRUE, 2 },
02561           { "abcdefgabcdefg", "e", PR_TRUE, 4 },
02562           { "abcdefgabcdefg", "g", PR_TRUE, 6 },
02563           { "abcdefgabcdefg", "i", PR_FALSE, 0 },
02564           { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
02565           { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
02566           { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
02567           { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
02568           { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
02569           { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
02570           { "ABCDEFG", "a", PR_TRUE, 0 },
02571           { "ABCDEFG", "c", PR_TRUE, 2 },
02572           { "ABCDEFG", "e", PR_TRUE, 4 },
02573           { "ABCDEFG", "g", PR_TRUE, 6 },
02574           { "ABCDEFG", "i", PR_FALSE, 0 },
02575           { "ABCDEFG", "ab", PR_TRUE, 0 },
02576           { "ABCDEFG", "cd", PR_TRUE, 2 },
02577           { "ABCDEFG", "ef", PR_TRUE, 4 },
02578           { "ABCDEFG", "gh", PR_FALSE, 0 },
02579           { "ABCDABC", "bc", PR_TRUE, 1 },
02580           { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
02581           { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
02582           { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
02583           { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
02584           { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
02585           { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
02586           { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
02587           { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
02588           { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
02589           { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
02590           { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
02591           { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
02592       };
02593 
02594     int i;
02595 
02596     printf("Test 027 (PL_strcasestr)  ..."); fflush(stdout);
02597 
02598     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02599     {
02600         char *rv = PL_strcasestr(array[i].str, array[i].sub);
02601 
02602         if( PR_FALSE == array[i].ret )
02603         {
02604             if( (char *)0 != rv )
02605             {
02606                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
02607                        array[i].str ? array[i].str : "(null)",
02608                        array[i].sub ? array[i].sub : "(null)",
02609                        rv);
02610                 return PR_FALSE;
02611             }
02612         }
02613         else
02614         {
02615             if( (char *)0 == rv )
02616             {
02617                 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
02618                        array[i].str ? array[i].str : "(null)",
02619                        array[i].sub ? array[i].sub : "(null)",
02620                        array[i].str, array[i].off);
02621                 return PR_FALSE;
02622             }
02623 
02624             if( &array[i].str[ array[i].off ] != rv )
02625             {
02626                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
02627                        array[i].str ? array[i].str : "(null)",
02628                        array[i].sub ? array[i].sub : "(null)",
02629                        rv, array[i].str, array[i].off);
02630                 return PR_FALSE;
02631             }
02632         }
02633     }
02634 
02635     printf("PASS\n");
02636     return PR_TRUE;
02637 }
02638 
02639 /* PL_strcaserstr */
02640 PRBool test_028(void)
02641 {
02642     static struct
02643     {
02644         const char *str;
02645         const char *sub;
02646         PRBool      ret;
02647         PRUint32    off;
02648     } array[] =
02649       {
02650           { (const char *)0, (const char *)0, PR_FALSE, 0 },
02651           { (const char *)0, "blah", PR_FALSE, 0 },
02652           { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
02653           { "blah-de-blah", "blah", PR_TRUE, 8 },
02654           { "", "blah", PR_FALSE, 0 },
02655           { "blah-de-blah", "", PR_FALSE, 0 },
02656           { "abcdefg", "a", PR_TRUE, 0 },
02657           { "abcdefg", "c", PR_TRUE, 2 },
02658           { "abcdefg", "e", PR_TRUE, 4 },
02659           { "abcdefg", "g", PR_TRUE, 6 },
02660           { "abcdefg", "i", PR_FALSE, 0 },
02661           { "abcdefg", "ab", PR_TRUE, 0 },
02662           { "abcdefg", "cd", PR_TRUE, 2 },
02663           { "abcdefg", "ef", PR_TRUE, 4 },
02664           { "abcdefg", "gh", PR_FALSE, 0 },
02665           { "abcdabc", "bc", PR_TRUE, 5 },
02666           { "abcdefg", "abcdefg", PR_TRUE, 0 },
02667           { "abcdefgabcdefg", "a", PR_TRUE, 7 },
02668           { "abcdefgabcdefg", "c", PR_TRUE, 9 },
02669           { "abcdefgabcdefg", "e", PR_TRUE, 11 },
02670           { "abcdefgabcdefg", "g", PR_TRUE, 13 },
02671           { "abcdefgabcdefg", "i", PR_FALSE, 0 },
02672           { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
02673           { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
02674           { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
02675           { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
02676           { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
02677           { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
02678           { "ABCDEFG", "a", PR_TRUE, 0 },
02679           { "ABCDEFG", "c", PR_TRUE, 2 },
02680           { "ABCDEFG", "e", PR_TRUE, 4 },
02681           { "ABCDEFG", "g", PR_TRUE, 6 },
02682           { "ABCDEFG", "i", PR_FALSE, 0 },
02683           { "ABCDEFG", "ab", PR_TRUE, 0 },
02684           { "ABCDEFG", "cd", PR_TRUE, 2 },
02685           { "ABCDEFG", "ef", PR_TRUE, 4 },
02686           { "ABCDEFG", "gh", PR_FALSE, 0 },
02687           { "ABCDABC", "bc", PR_TRUE, 5 },
02688           { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
02689           { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
02690           { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
02691           { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
02692           { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
02693           { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
02694           { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
02695           { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
02696           { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
02697           { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
02698           { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
02699           { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
02700       };
02701 
02702     int i;
02703 
02704     printf("Test 028 (PL_strcaserstr) ..."); fflush(stdout);
02705 
02706     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02707     {
02708         char *rv = PL_strcaserstr(array[i].str, array[i].sub);
02709 
02710         if( PR_FALSE == array[i].ret )
02711         {
02712             if( (char *)0 != rv )
02713             {
02714                 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
02715                        array[i].str ? array[i].str : "(null)",
02716                        array[i].sub ? array[i].sub : "(null)",
02717                        rv);
02718                 return PR_FALSE;
02719             }
02720         }
02721         else
02722         {
02723             if( (char *)0 == rv )
02724             {
02725                 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
02726                        array[i].str ? array[i].str : "(null)",
02727                        array[i].sub ? array[i].sub : "(null)",
02728                        array[i].str, array[i].off);
02729                 return PR_FALSE;
02730             }
02731 
02732             if( &array[i].str[ array[i].off ] != rv )
02733             {
02734                 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
02735                        array[i].str ? array[i].str : "(null)",
02736                        array[i].sub ? array[i].sub : "(null)",
02737                        rv, array[i].str, array[i].off);
02738                 return PR_FALSE;
02739             }
02740         }
02741     }
02742 
02743     printf("PASS\n");
02744     return PR_TRUE;
02745 }
02746 
02747 /* PL_strncasestr */
02748 PRBool test_029(void)
02749 {
02750     static struct
02751     {
02752         const char *str;
02753         const char *sub;
02754         PRUint32    max;
02755         PRBool      ret;
02756         PRUint32    off;
02757     } array[] =
02758       {
02759           { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
02760           { (const char *)0, "blah", 12, PR_FALSE, 0 },
02761           { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
02762           { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
02763           { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
02764           { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
02765           { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
02766           { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
02767           { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
02768           { "", "blah", 12, PR_FALSE, 0 },
02769           { "blah-de-blah", "", 12, PR_FALSE, 0 },
02770           { "abcdefg", "a", 5, PR_TRUE, 0 },
02771           { "abcdefg", "c", 5, PR_TRUE, 2 },
02772           { "abcdefg", "e", 5, PR_TRUE, 4 },
02773           { "abcdefg", "g", 5, PR_FALSE, 0 },
02774           { "abcdefg", "i", 5, PR_FALSE, 0 },
02775           { "abcdefg", "ab", 5, PR_TRUE, 0 },
02776           { "abcdefg", "cd", 5, PR_TRUE, 2 },
02777           { "abcdefg", "ef", 5, PR_FALSE, 0 },
02778           { "abcdefg", "gh", 5, PR_FALSE, 0 },
02779           { "abcdabc", "bc", 5, PR_TRUE, 1 },
02780           { "abcdabc", "bc", 6, PR_TRUE, 1 },
02781           { "abcdabc", "bc", 7, PR_TRUE, 1 },
02782           { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
02783           { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
02784           { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
02785           { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
02786           { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
02787           { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
02788           { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
02789           { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
02790           { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
02791           { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
02792           { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
02793           { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
02794           { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
02795           { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
02796           { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
02797           { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
02798           { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
02799           { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
02800           { "ABCDEFG", "a", 5, PR_TRUE, 0 },
02801           { "ABCDEFG", "c", 5, PR_TRUE, 2 },
02802           { "ABCDEFG", "e", 5, PR_TRUE, 4 },
02803           { "ABCDEFG", "g", 5, PR_FALSE, 0 },
02804           { "ABCDEFG", "i", 5, PR_FALSE, 0 },
02805           { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
02806           { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
02807           { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
02808           { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
02809           { "ABCDABC", "bc", 5, PR_TRUE, 1 },
02810           { "ABCDABC", "bc", 6, PR_TRUE, 1 },
02811           { "ABCDABC", "bc", 7, PR_TRUE, 1 },
02812           { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02813           { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
02814           { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
02815           { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
02816           { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
02817           { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
02818           { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
02819           { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
02820           { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
02821           { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
02822           { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
02823           { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
02824           { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
02825           { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
02826           { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
02827           { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02828           { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
02829           { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
02830       };
02831 
02832     int i;
02833 
02834     printf("Test 029 (PL_strncasestr) ..."); fflush(stdout);
02835 
02836     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02837     {
02838         char *rv = PL_strncasestr(array[i].str, array[i].sub, array[i].max);
02839 
02840         if( PR_FALSE == array[i].ret )
02841         {
02842             if( (char *)0 != rv )
02843             {
02844                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
02845                        array[i].str ? array[i].str : "(null)",
02846                        array[i].sub ? array[i].sub : "(null)",
02847                        array[i].max, rv);
02848                 return PR_FALSE;
02849             }
02850         }
02851         else
02852         {
02853             if( (char *)0 == rv )
02854             {
02855                 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
02856                        array[i].str ? array[i].str : "(null)",
02857                        array[i].sub ? array[i].sub : "(null)",
02858                        array[i].max, array[i].str, array[i].off);
02859                 return PR_FALSE;
02860             }
02861 
02862             if( &array[i].str[ array[i].off ] != rv )
02863             {
02864                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
02865                        array[i].str ? array[i].str : "(null)",
02866                        array[i].sub ? array[i].sub : "(null)",
02867                        array[i].max, rv, array[i].str, array[i].off);
02868                 return PR_FALSE;
02869             }
02870         }
02871     }
02872 
02873     printf("PASS\n");
02874     return PR_TRUE;
02875 }
02876 
02877 /* PL_strncaserstr */
02878 PRBool test_030(void)
02879 {
02880     static struct
02881     {
02882         const char *str;
02883         const char *sub;
02884         PRUint32    max;
02885         PRBool      ret;
02886         PRUint32    off;
02887     } array[] =
02888       {
02889           { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
02890           { (const char *)0, "blah", 12, PR_FALSE, 0 },
02891           { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
02892           { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
02893           { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
02894           { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
02895           { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
02896           { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
02897           { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
02898           { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
02899           { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
02900           { "", "blah", 12, PR_FALSE, 0 },
02901           { "blah-de-blah", "", 12, PR_FALSE, 0 },
02902           { "abcdefg", "a", 5, PR_TRUE, 0 },
02903           { "abcdefg", "c", 5, PR_TRUE, 2 },
02904           { "abcdefg", "e", 5, PR_TRUE, 4 },
02905           { "abcdefg", "g", 5, PR_FALSE, 0 },
02906           { "abcdefg", "i", 5, PR_FALSE, 0 },
02907           { "abcdefg", "ab", 5, PR_TRUE, 0 },
02908           { "abcdefg", "cd", 5, PR_TRUE, 2 },
02909           { "abcdefg", "ef", 5, PR_FALSE, 0 },
02910           { "abcdefg", "gh", 5, PR_FALSE, 0 },
02911           { "abcdabc", "bc", 5, PR_TRUE, 1 },
02912           { "abcdabc", "bc", 6, PR_TRUE, 1 },
02913           { "abcdabc", "bc", 7, PR_TRUE, 5 },
02914           { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
02915           { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
02916           { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
02917           { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
02918           { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
02919           { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
02920           { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
02921           { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
02922           { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
02923           { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
02924           { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
02925           { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
02926           { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
02927           { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
02928           { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
02929           { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
02930           { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
02931           { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
02932           { "ABCDEFG", "a", 5, PR_TRUE, 0 },
02933           { "ABCDEFG", "c", 5, PR_TRUE, 2 },
02934           { "ABCDEFG", "e", 5, PR_TRUE, 4 },
02935           { "ABCDEFG", "g", 5, PR_FALSE, 0 },
02936           { "ABCDEFG", "i", 5, PR_FALSE, 0 },
02937           { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
02938           { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
02939           { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
02940           { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
02941           { "ABCDABC", "bc", 5, PR_TRUE, 1 },
02942           { "ABCDABC", "bc", 6, PR_TRUE, 1 },
02943           { "ABCDABC", "bc", 7, PR_TRUE, 5 },
02944           { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
02945           { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
02946           { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
02947           { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
02948           { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
02949           { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
02950           { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
02951           { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
02952           { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
02953           { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
02954           { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
02955           { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
02956           { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
02957           { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
02958           { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
02959           { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
02960           { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
02961           { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
02962       };
02963 
02964     int i;
02965 
02966     printf("Test 030 (PL_strncaserstr)..."); fflush(stdout);
02967 
02968     for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
02969     {
02970         char *rv = PL_strncaserstr(array[i].str, array[i].sub, array[i].max);
02971 
02972         if( PR_FALSE == array[i].ret )
02973         {
02974             if( (char *)0 != rv )
02975             {
02976                 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
02977                        array[i].str ? array[i].str : "(null)",
02978                        array[i].sub ? array[i].sub : "(null)",
02979                        array[i].max, rv);
02980                 return PR_FALSE;
02981             }
02982         }
02983         else
02984         {
02985             if( (char *)0 == rv )
02986             {
02987                 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
02988                        array[i].str ? array[i].str : "(null)",
02989                        array[i].sub ? array[i].sub : "(null)",
02990                        array[i].max, array[i].str, array[i].off);
02991                 return PR_FALSE;
02992             }
02993 
02994             if( &array[i].str[ array[i].off ] != rv )
02995             {
02996                 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
02997                        array[i].str ? array[i].str : "(null)",
02998                        array[i].sub ? array[i].sub : "(null)",
02999                        array[i].max, rv, array[i].str, array[i].off);
03000                 return PR_FALSE;
03001             }
03002         }
03003     }
03004 
03005     printf("PASS\n");
03006     return PR_TRUE;
03007 }
03008 
03009 /* PL_strtok_r */
03010 PRBool test_031(void)
03011 {
03012     static const char *tokens[] = {
03013         "wtc", "relyea", "nelsonb", "jpierre", "nicolson",
03014         "ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein"
03015     };
03016 
03017     static const char *seps[] = {
03018         ", ", ",", " ", "\t", ",,,", " ,", "    ", " \t\t", ","
03019     };
03020 
03021     static const char s2[] = ", \t";
03022 
03023     char string[ 1024 ];
03024     char *s1;
03025     char *token;
03026     char *lasts;
03027     unsigned int i;
03028 
03029     printf("Test 031 (PL_strtok_r)    ..."); fflush(stdout);
03030 
03031     /* Build the string. */
03032     string[0] = '\0';
03033     for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ )
03034     {
03035         PL_strcat(string, tokens[i]);
03036         PL_strcat(string, seps[i]);
03037     }
03038     
03039     /* Scan the string for tokens. */
03040     i = 0;
03041     s1 = string;
03042     while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL)
03043     {
03044         if( PL_strcmp(token, tokens[i]) != 0 )
03045         {
03046             printf("FAIL wrong token scanned\n");
03047             return PR_FALSE;
03048         }
03049         i++;
03050         s1 = NULL;
03051     }
03052     if( i != sizeof(tokens)/sizeof(tokens[0]) )
03053     {
03054         printf("FAIL wrong number of tokens scanned\n");
03055         return PR_FALSE;
03056     }
03057 
03058     printf("PASS\n");
03059     return PR_TRUE;
03060 }
03061 
03062 int
03063 main
03064 (
03065     int     argc,
03066     char   *argv[]
03067 )
03068 {
03069     printf("Testing the Portable Library string functions:\n");
03070 
03071     if( 1
03072         && test_001()
03073         && test_001()
03074         && test_002()
03075         && test_003()
03076         && test_004()
03077         && test_005()
03078         && test_006()
03079         && test_007()
03080         && test_008()
03081         && test_009()
03082         && test_010()
03083         && test_011()
03084         && test_012()
03085         && test_013()
03086         && test_014()
03087         && test_015()
03088         && test_016()
03089         && test_017()
03090         && test_018()
03091         && test_019()
03092         && test_020()
03093         && test_021()
03094         && test_022()
03095         && test_023()
03096         && test_024()
03097         && test_025()
03098         && test_026()
03099         && test_027()
03100         && test_028()
03101         && test_029()
03102         && test_030()
03103         && test_031()
03104       )
03105     {
03106         printf("Suite passed.\n");
03107         return 0;
03108     }
03109     else
03110     {
03111         printf("Suite failed.\n");
03112         return 1;
03113     }
03114 
03115     /*NOTREACHED*/
03116 }