nsprpub/lib/tests/string.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "plstr.h"
michael@0 7 #include "nspr.h"
michael@0 8
michael@0 9 #include <stdio.h>
michael@0 10
michael@0 11 /* PL_strlen */
michael@0 12 PRBool test_001(void)
michael@0 13 {
michael@0 14 static struct
michael@0 15 {
michael@0 16 const char *str;
michael@0 17 PRUint32 len;
michael@0 18 } array[] =
michael@0 19 {
michael@0 20 { (const char *)0, 0 },
michael@0 21 { "", 0 },
michael@0 22 { "a", 1 },
michael@0 23 { "abcdefg", 7 },
michael@0 24 { "abcdefg\0hijk", 7 }
michael@0 25 };
michael@0 26
michael@0 27 int i;
michael@0 28
michael@0 29 printf("Test 001 (PL_strlen) ..."); fflush(stdout);
michael@0 30
michael@0 31 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 32 {
michael@0 33 if( PL_strlen(array[i].str) != array[i].len )
michael@0 34 {
michael@0 35 printf("FAIL (%d: %s->%d, %d)\n", i,
michael@0 36 array[i].str ? array[i].str : "(null)",
michael@0 37 PL_strlen(array[i].str), array[i].len);
michael@0 38 return PR_FALSE;
michael@0 39 }
michael@0 40 }
michael@0 41
michael@0 42 printf("PASS\n");
michael@0 43 return PR_TRUE;
michael@0 44 }
michael@0 45
michael@0 46 /* PL_strnlen */
michael@0 47 PRBool test_002(void)
michael@0 48 {
michael@0 49 static struct
michael@0 50 {
michael@0 51 const char *str;
michael@0 52 PRUint32 max;
michael@0 53 PRUint32 len;
michael@0 54 } array[] =
michael@0 55 {
michael@0 56 { (const char *)0, 0, 0 },
michael@0 57 { (const char *)0, 12, 0 },
michael@0 58 { "", 0, 0 },
michael@0 59 { "", 12, 0 },
michael@0 60 { "a", 0, 0 },
michael@0 61 { "a", 1, 1 },
michael@0 62 { "a", 12, 1 },
michael@0 63 { "abcdefg", 0, 0 },
michael@0 64 { "abcdefg", 1, 1 },
michael@0 65 { "abcdefg", 7, 7 },
michael@0 66 { "abcdefg", 12, 7 },
michael@0 67 { "abcdefg\0hijk", 0, 0 },
michael@0 68 { "abcdefg\0hijk", 1, 1 },
michael@0 69 { "abcdefg\0hijk", 7, 7 },
michael@0 70 { "abcdefg\0hijk", 12, 7 },
michael@0 71 };
michael@0 72
michael@0 73 int i;
michael@0 74
michael@0 75 printf("Test 002 (PL_strnlen) ..."); fflush(stdout);
michael@0 76
michael@0 77 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 78 {
michael@0 79 if( PL_strnlen(array[i].str, array[i].max) != array[i].len )
michael@0 80 {
michael@0 81 printf("FAIL (%d: %s,%d->%d, %d)\n", i,
michael@0 82 array[i].str ? array[i].str : "(null)", array[i].max,
michael@0 83 PL_strnlen(array[i].str, array[i].max), array[i].len);
michael@0 84 return PR_FALSE;
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 printf("PASS\n");
michael@0 89 return PR_TRUE;
michael@0 90 }
michael@0 91
michael@0 92 /* PL_strcpy */
michael@0 93 PRBool test_003(void)
michael@0 94 {
michael@0 95 static char buffer[ 1024 ];
michael@0 96
michael@0 97 static struct
michael@0 98 {
michael@0 99 const char *str;
michael@0 100 char *dest;
michael@0 101 char *rv;
michael@0 102 PRBool comp;
michael@0 103 } array[] =
michael@0 104 {
michael@0 105 { (const char *)0, (char *)0, (char *)0, PR_FALSE },
michael@0 106 { (const char *)0, buffer, (char *)0, PR_FALSE },
michael@0 107 { "", (char *)0, (char *)0, PR_FALSE },
michael@0 108 { "", buffer, buffer, PR_TRUE },
michael@0 109 { "a", (char *)0, (char *)0, PR_FALSE },
michael@0 110 { "a", buffer, buffer, PR_TRUE },
michael@0 111 { "abcdefg", (char *)0, (char *)0, PR_FALSE },
michael@0 112 { "abcdefg", buffer, buffer, PR_TRUE },
michael@0 113 { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
michael@0 114 { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
michael@0 115 };
michael@0 116
michael@0 117 int i;
michael@0 118
michael@0 119 printf("Test 003 (PL_strcpy) ..."); fflush(stdout);
michael@0 120
michael@0 121 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 122 {
michael@0 123 char *rv;
michael@0 124 const char *a = array[i].str;
michael@0 125 const char *b = (const char *)array[i].dest;
michael@0 126
michael@0 127 rv = PL_strcpy(array[i].dest, array[i].str);
michael@0 128 if( array[i].rv != rv )
michael@0 129 {
michael@0 130 printf("FAIL %d: (0x%x, %s)->0x%x\n", i, array[i].dest,
michael@0 131 array[i].str ? array[i].str : "(null)", rv);
michael@0 132 return PR_FALSE;
michael@0 133 }
michael@0 134
michael@0 135 if( array[i].comp )
michael@0 136 {
michael@0 137 while( 1 )
michael@0 138 {
michael@0 139 if( *a != *b )
michael@0 140 {
michael@0 141 printf("FAIL %d: %s->%.32s\n", i,
michael@0 142 array[i].str ? array[i].str : "(null)",
michael@0 143 array[i].dest ? array[i].dest : "(null)");
michael@0 144 return PR_FALSE;
michael@0 145 }
michael@0 146
michael@0 147 if( (char)0 == *a ) break;
michael@0 148
michael@0 149 a++;
michael@0 150 b++;
michael@0 151 }
michael@0 152 }
michael@0 153 }
michael@0 154
michael@0 155 printf("PASS\n");
michael@0 156 return PR_TRUE;
michael@0 157 }
michael@0 158
michael@0 159 /* PL_strncpy */
michael@0 160 PRBool test_004(void)
michael@0 161 {
michael@0 162 static char buffer[ 1024 ];
michael@0 163
michael@0 164 static struct
michael@0 165 {
michael@0 166 const char *str;
michael@0 167 PRUint32 len;
michael@0 168 char *dest;
michael@0 169 char *rv;
michael@0 170 PRBool comp;
michael@0 171 const char *result;
michael@0 172 PRBool nulled;
michael@0 173 } array[] =
michael@0 174 {
michael@0 175 { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 176 { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 177 { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 178 { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 179 { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 180 { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 181 { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 182 { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 183 { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 184 { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 185 { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
michael@0 186 { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
michael@0 187 { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 188 { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 189 { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 190 { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 191 { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
michael@0 192 { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
michael@0 193 { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 194 { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 195 { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 196 { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 197 { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
michael@0 198 { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
michael@0 199 { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 200 { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 201 { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 202 { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 203 { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
michael@0 204 { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
michael@0 205 { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 206 { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 207 { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 208 { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 209 { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
michael@0 210 { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
michael@0 211 { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 212 { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 213 { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 214 { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 215 { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
michael@0 216 { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
michael@0 217 { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 218 { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 219 { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 220 { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
michael@0 221 { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
michael@0 222 { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
michael@0 223 };
michael@0 224
michael@0 225 int i;
michael@0 226
michael@0 227 printf("Test 004 (PL_strncpy) ..."); fflush(stdout);
michael@0 228
michael@0 229 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 230 {
michael@0 231 char *rv;
michael@0 232 int j;
michael@0 233
michael@0 234 for( j = 0; j < sizeof(buffer); j++ )
michael@0 235 buffer[j] = '-';
michael@0 236
michael@0 237 rv = PL_strncpy(array[i].dest, array[i].str, array[i].len);
michael@0 238 if( array[i].rv != rv )
michael@0 239 {
michael@0 240 printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
michael@0 241 array[i].str ? array[i].str : "(null)", array[i].len, rv);
michael@0 242 return PR_FALSE;
michael@0 243 }
michael@0 244
michael@0 245 if( array[i].comp )
michael@0 246 {
michael@0 247 const char *a = array[i].result;
michael@0 248 const char *b = array[i].dest;
michael@0 249
michael@0 250 while( *a )
michael@0 251 {
michael@0 252 if( *a != *b )
michael@0 253 {
michael@0 254 printf("FAIL %d: %s != %.32s\n", i,
michael@0 255 array[i].result, array[i].dest);
michael@0 256 return PR_FALSE;
michael@0 257 }
michael@0 258
michael@0 259 a++;
michael@0 260 b++;
michael@0 261 }
michael@0 262
michael@0 263 if( array[i].nulled )
michael@0 264 {
michael@0 265 if( *b != '\0' )
michael@0 266 {
michael@0 267 printf("FAIL %d: not terminated\n", i);
michael@0 268 return PR_FALSE;
michael@0 269 }
michael@0 270 }
michael@0 271 else
michael@0 272 {
michael@0 273 if( *b != '-' )
michael@0 274 {
michael@0 275 printf("FAIL %d: overstepped\n", i);
michael@0 276 return PR_FALSE;
michael@0 277 }
michael@0 278 }
michael@0 279 }
michael@0 280 }
michael@0 281
michael@0 282 printf("PASS\n");
michael@0 283 return PR_TRUE;
michael@0 284 }
michael@0 285
michael@0 286 /* PL_strncpyz */
michael@0 287 PRBool test_005(void)
michael@0 288 {
michael@0 289 static char buffer[ 1024 ];
michael@0 290
michael@0 291 static struct
michael@0 292 {
michael@0 293 const char *str;
michael@0 294 PRUint32 len;
michael@0 295 char *dest;
michael@0 296 char *rv;
michael@0 297 PRBool comp;
michael@0 298 const char *result;
michael@0 299 } array[] =
michael@0 300 {
michael@0 301 { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 302 { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 303 { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 304 { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 305 { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 306 { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 307 { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 308 { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 309 { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 310 { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 311 { "", 1, buffer, buffer, PR_TRUE, "" },
michael@0 312 { "", 7, buffer, buffer, PR_TRUE, "" },
michael@0 313 { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 314 { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 315 { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 316 { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 317 { "b", 1, buffer, buffer, PR_TRUE, "" },
michael@0 318 { "c", 7, buffer, buffer, PR_TRUE, "c" },
michael@0 319 { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 320 { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 321 { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 322 { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 323 { "fg", 1, buffer, buffer, PR_TRUE, "" },
michael@0 324 { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
michael@0 325 { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 326 { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 327 { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 328 { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 329 { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
michael@0 330 { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
michael@0 331 { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 332 { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 333 { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 334 { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 335 { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
michael@0 336 { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
michael@0 337 { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 338 { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 339 { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 340 { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 341 { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
michael@0 342 { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
michael@0 343 { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 344 { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
michael@0 345 { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 346 { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
michael@0 347 { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
michael@0 348 { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
michael@0 349 };
michael@0 350
michael@0 351 int i;
michael@0 352
michael@0 353 printf("Test 005 (PL_strncpyz) ..."); fflush(stdout);
michael@0 354
michael@0 355 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 356 {
michael@0 357 char *rv;
michael@0 358 int j;
michael@0 359
michael@0 360 for( j = 0; j < sizeof(buffer); j++ )
michael@0 361 buffer[j] = '-';
michael@0 362
michael@0 363 rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len);
michael@0 364 if( array[i].rv != rv )
michael@0 365 {
michael@0 366 printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
michael@0 367 array[i].str ? array[i].str : "(null)", array[i].len, rv);
michael@0 368 return PR_FALSE;
michael@0 369 }
michael@0 370
michael@0 371 if( array[i].comp )
michael@0 372 {
michael@0 373 const char *a = array[i].result;
michael@0 374 const char *b = array[i].dest;
michael@0 375
michael@0 376 while( 1 )
michael@0 377 {
michael@0 378 if( *a != *b )
michael@0 379 {
michael@0 380 printf("FAIL %d: %s != %.32s\n", i,
michael@0 381 array[i].result, array[i].dest);
michael@0 382 return PR_FALSE;
michael@0 383 }
michael@0 384
michael@0 385 if( (char)0 == *a ) break;
michael@0 386
michael@0 387 a++;
michael@0 388 b++;
michael@0 389 }
michael@0 390 }
michael@0 391 }
michael@0 392
michael@0 393 printf("PASS\n");
michael@0 394 return PR_TRUE;
michael@0 395 }
michael@0 396
michael@0 397 /* PL_strdup */
michael@0 398 PRBool test_006(void)
michael@0 399 {
michael@0 400 static const char *array[] =
michael@0 401 {
michael@0 402 (const char *)0,
michael@0 403 "",
michael@0 404 "a",
michael@0 405 "abcdefg"
michael@0 406 };
michael@0 407
michael@0 408 int i;
michael@0 409
michael@0 410 printf("Test 006 (PL_strdup) ..."); fflush(stdout);
michael@0 411
michael@0 412 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 413 {
michael@0 414 char *rv = PL_strdup(array[i]);
michael@0 415
michael@0 416 if( (char *)0 == rv )
michael@0 417 {
michael@0 418 printf("FAIL %d: 0x%x -> 0\n", i, array[i]);
michael@0 419 return PR_FALSE;
michael@0 420 }
michael@0 421
michael@0 422 if( (const char *)0 == array[i] )
michael@0 423 {
michael@0 424 if( (char)0 != *rv )
michael@0 425 {
michael@0 426 printf("FAIL %d: (const char *)0 -> %.32s\n", i, rv);
michael@0 427 return PR_FALSE;
michael@0 428 }
michael@0 429 }
michael@0 430 else
michael@0 431 {
michael@0 432 const char *a = array[i];
michael@0 433 const char *b = (const char *)rv;
michael@0 434
michael@0 435 while( 1 )
michael@0 436 {
michael@0 437 if( *a != *b )
michael@0 438 {
michael@0 439 printf("FAIL %d: %s != %.32s\n", i, array[i], rv);
michael@0 440 return PR_FALSE;
michael@0 441 }
michael@0 442
michael@0 443 if( (char)0 == *a ) break;
michael@0 444
michael@0 445 a++;
michael@0 446 b++;
michael@0 447 }
michael@0 448
michael@0 449 }
michael@0 450 PL_strfree(rv);
michael@0 451 }
michael@0 452
michael@0 453 printf("PASS\n");
michael@0 454 return PR_TRUE;
michael@0 455 }
michael@0 456
michael@0 457 /* PL_strndup */
michael@0 458 PRBool test_007(void)
michael@0 459 {
michael@0 460 static struct
michael@0 461 {
michael@0 462 const char *str;
michael@0 463 PRUint32 len;
michael@0 464 const char *result;
michael@0 465 } array[] =
michael@0 466 {
michael@0 467 { (const char *)0, 0, "" },
michael@0 468 { (const char *)0, 1, "" },
michael@0 469 { (const char *)0, 7, "" },
michael@0 470 { "", 0, "" },
michael@0 471 { "", 1, "" },
michael@0 472 { "", 7, "" },
michael@0 473 { "a", 0, "" },
michael@0 474 { "a", 1, "a" },
michael@0 475 { "a", 7, "a" },
michael@0 476 { "ab", 0, "" },
michael@0 477 { "ab", 1, "a" },
michael@0 478 { "ab", 7, "ab" },
michael@0 479 { "abcdefg", 0, "" },
michael@0 480 { "abcdefg", 1, "a" },
michael@0 481 { "abcdefg", 7, "abcdefg" },
michael@0 482 { "abcdefghijk", 0, "" },
michael@0 483 { "abcdefghijk", 1, "a" },
michael@0 484 { "abcdefghijk", 7, "abcdefg" },
michael@0 485 { "abcdef\0ghijk", 0, "" },
michael@0 486 { "abcdef\0ghijk", 1, "a" },
michael@0 487 { "abcdef\0ghijk", 7, "abcdef" }
michael@0 488 };
michael@0 489
michael@0 490 int i;
michael@0 491
michael@0 492 printf("Test 007 (PL_strndup) ..."); fflush(stdout);
michael@0 493
michael@0 494 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 495 {
michael@0 496 char *rv = PL_strndup(array[i].str, array[i].len);
michael@0 497 const char *a;
michael@0 498 const char *b;
michael@0 499
michael@0 500 if( (char *)0 == rv )
michael@0 501 {
michael@0 502 printf("FAIL %d: %s,%lu -> 0\n", i,
michael@0 503 array[i].str ? array[i].str : "(null)", array[i].len);
michael@0 504 return PR_FALSE;
michael@0 505 }
michael@0 506
michael@0 507 a = array[i].result;
michael@0 508 b = (const char *)rv;
michael@0 509
michael@0 510 while( 1 )
michael@0 511 {
michael@0 512 if( *a != *b )
michael@0 513 {
michael@0 514 printf("FAIL %d: %s != %.32s\n", i, array[i].result, rv);
michael@0 515 return PR_FALSE;
michael@0 516 }
michael@0 517
michael@0 518 if( (char)0 == *a ) break;
michael@0 519
michael@0 520 a++;
michael@0 521 b++;
michael@0 522 }
michael@0 523
michael@0 524 free(rv);
michael@0 525 }
michael@0 526
michael@0 527 printf("PASS\n");
michael@0 528 return PR_TRUE;
michael@0 529 }
michael@0 530
michael@0 531 /* PL_strcat */
michael@0 532 PRBool test_008(void)
michael@0 533 {
michael@0 534 static struct
michael@0 535 {
michael@0 536 const char *first;
michael@0 537 const char *second;
michael@0 538 const char *result;
michael@0 539 } array[] =
michael@0 540 {
michael@0 541 { (const char *)0, (const char *)0, (const char *)0 },
michael@0 542 { (const char *)0, "xyz", (const char *)0 },
michael@0 543 { "", (const char *)0, "" },
michael@0 544 { "", "", "" },
michael@0 545 { "ab", "", "ab" },
michael@0 546 { "cd", "ef", "cdef" },
michael@0 547 { "gh\0X", "", "gh" },
michael@0 548 { "ij\0X", "kl", "ijkl" },
michael@0 549 { "mn\0X", "op\0X", "mnop" },
michael@0 550 { "qr", "st\0X", "qrst" },
michael@0 551 { "uv\0X", "wx\0X", "uvwx" }
michael@0 552 };
michael@0 553
michael@0 554 int i;
michael@0 555
michael@0 556 printf("Test 008 (PL_strcat) ..."); fflush(stdout);
michael@0 557
michael@0 558 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 559 {
michael@0 560 char buffer[ 1024 ];
michael@0 561 int j;
michael@0 562 char *rv;
michael@0 563
michael@0 564 for( j = 0; j < sizeof(buffer); j++ )
michael@0 565 buffer[j] = '-';
michael@0 566
michael@0 567 if( (const char *)0 != array[i].first )
michael@0 568 (void)PL_strcpy(buffer, array[i].first);
michael@0 569
michael@0 570 rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
michael@0 571 array[i].second);
michael@0 572
michael@0 573 if( (const char *)0 == array[i].result )
michael@0 574 {
michael@0 575 if( (char *)0 != rv )
michael@0 576 {
michael@0 577 printf("FAIL %d: %s+%s -> %.32s, not zero\n", i,
michael@0 578 array[i].first ? array[i].first : "(null)",
michael@0 579 array[i].second ? array[i].second : "(null)",
michael@0 580 rv);
michael@0 581 return PR_FALSE;
michael@0 582 }
michael@0 583 }
michael@0 584 else
michael@0 585 {
michael@0 586 if( (char *)0 == rv )
michael@0 587 {
michael@0 588 printf("FAIL %d: %s+%s -> null, not %s\n", i,
michael@0 589 array[i].first ? array[i].first : "(null)",
michael@0 590 array[i].second ? array[i].second : "(null)",
michael@0 591 array[i].result);
michael@0 592 return PR_FALSE;
michael@0 593 }
michael@0 594 else
michael@0 595 {
michael@0 596 const char *a = array[i].result;
michael@0 597 const char *b = (const char *)rv;
michael@0 598
michael@0 599 while( 1 )
michael@0 600 {
michael@0 601 if( *a != *b )
michael@0 602 {
michael@0 603 printf("FAIL %d: %s+%s -> %.32s, not %s\n", i,
michael@0 604 array[i].first ? array[i].first : "(null)",
michael@0 605 array[i].second ? array[i].second : "(null)",
michael@0 606 rv, array[i].result);
michael@0 607 return PR_FALSE;
michael@0 608 }
michael@0 609
michael@0 610 if( (char)0 == *a ) break;
michael@0 611
michael@0 612 a++;
michael@0 613 b++;
michael@0 614 }
michael@0 615 }
michael@0 616 }
michael@0 617 }
michael@0 618
michael@0 619 printf("PASS\n");
michael@0 620 return PR_TRUE;
michael@0 621 }
michael@0 622
michael@0 623 /* PL_strncat */
michael@0 624 PRBool test_009(void)
michael@0 625 {
michael@0 626 static struct
michael@0 627 {
michael@0 628 const char *first;
michael@0 629 const char *second;
michael@0 630 PRUint32 length;
michael@0 631 PRBool nulled;
michael@0 632 const char *result;
michael@0 633 } array[] =
michael@0 634 {
michael@0 635 { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
michael@0 636 { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
michael@0 637 { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
michael@0 638 { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
michael@0 639 { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
michael@0 640 { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
michael@0 641 { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
michael@0 642 { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
michael@0 643 { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
michael@0 644 { "", (const char *)0, 0, PR_TRUE, "" },
michael@0 645 { "", (const char *)0, 1, PR_TRUE, "" },
michael@0 646 { "", (const char *)0, 7, PR_TRUE, "" },
michael@0 647 { "", "", 0, PR_TRUE, "" },
michael@0 648 { "", "", 1, PR_TRUE, "" },
michael@0 649 { "", "", 7, PR_TRUE, "" },
michael@0 650 { "", "abcdefgh", 0, PR_TRUE, "" },
michael@0 651 { "", "abcdefgh", 1, PR_FALSE, "a" },
michael@0 652 { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
michael@0 653 { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
michael@0 654 { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
michael@0 655 { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
michael@0 656 { "xyz", "", 0, PR_TRUE, "xyz" },
michael@0 657 { "xyz", "", 1, PR_TRUE, "xyz" },
michael@0 658 { "xyz", "", 7, PR_TRUE, "xyz" },
michael@0 659 { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
michael@0 660 { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
michael@0 661 { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
michael@0 662 };
michael@0 663
michael@0 664 int i;
michael@0 665
michael@0 666 printf("Test 009 (PL_strncat) ..."); fflush(stdout);
michael@0 667
michael@0 668 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 669 {
michael@0 670 char buffer[ 1024 ];
michael@0 671 int j;
michael@0 672 char *rv;
michael@0 673
michael@0 674 for( j = 0; j < sizeof(buffer); j++ )
michael@0 675 buffer[j] = '-';
michael@0 676
michael@0 677 if( (const char *)0 != array[i].first )
michael@0 678 (void)PL_strcpy(buffer, array[i].first);
michael@0 679
michael@0 680 rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
michael@0 681 array[i].second, array[i].length);
michael@0 682
michael@0 683 if( (const char *)0 == array[i].result )
michael@0 684 {
michael@0 685 if( (char *)0 != rv )
michael@0 686 {
michael@0 687 printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
michael@0 688 array[i].first ? array[i].first : "(null)",
michael@0 689 array[i].second ? array[i].second : "(null)",
michael@0 690 array[i].length, rv);
michael@0 691 return PR_FALSE;
michael@0 692 }
michael@0 693 }
michael@0 694 else
michael@0 695 {
michael@0 696 if( (char *)0 == rv )
michael@0 697 {
michael@0 698 printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
michael@0 699 array[i].first ? array[i].first : "(null)",
michael@0 700 array[i].second ? array[i].second : "(null)",
michael@0 701 array[i].length, array[i].result);
michael@0 702 return PR_FALSE;
michael@0 703 }
michael@0 704 else
michael@0 705 {
michael@0 706 const char *a = array[i].result;
michael@0 707 const char *b = (const char *)rv;
michael@0 708
michael@0 709 while( *a )
michael@0 710 {
michael@0 711 if( *a != *b )
michael@0 712 {
michael@0 713 printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
michael@0 714 array[i].first ? array[i].first : "(null)",
michael@0 715 array[i].second ? array[i].second : "(null)",
michael@0 716 array[i].length, rv, array[i].result);
michael@0 717 return PR_FALSE;
michael@0 718 }
michael@0 719
michael@0 720 a++;
michael@0 721 b++;
michael@0 722 }
michael@0 723
michael@0 724 if( array[i].nulled )
michael@0 725 {
michael@0 726 if( (char)0 != *b )
michael@0 727 {
michael@0 728 printf("FAIL %d: %s+%s/%lu -> not nulled\n", i,
michael@0 729 array[i].first ? array[i].first : "(null)",
michael@0 730 array[i].second ? array[i].second : "(null)",
michael@0 731 array[i].length);
michael@0 732 return PR_FALSE;
michael@0 733 }
michael@0 734 }
michael@0 735 else
michael@0 736 {
michael@0 737 if( (char)0 == *b )
michael@0 738 {
michael@0 739 printf("FAIL %d: %s+%s/%lu -> overrun\n", i,
michael@0 740 array[i].first ? array[i].first : "(null)",
michael@0 741 array[i].second ? array[i].second : "(null)",
michael@0 742 array[i].length);
michael@0 743 return PR_FALSE;
michael@0 744 }
michael@0 745 }
michael@0 746 }
michael@0 747 }
michael@0 748 }
michael@0 749
michael@0 750 printf("PASS\n");
michael@0 751 return PR_TRUE;
michael@0 752 }
michael@0 753
michael@0 754 /* PL_strcatn */
michael@0 755 PRBool test_010(void)
michael@0 756 {
michael@0 757 static struct
michael@0 758 {
michael@0 759 const char *first;
michael@0 760 const char *second;
michael@0 761 PRUint32 length;
michael@0 762 const char *result;
michael@0 763 } array[] =
michael@0 764 {
michael@0 765 { (const char *)0, (const char *)0, 0, (const char *)0 },
michael@0 766 { (const char *)0, (const char *)0, 1, (const char *)0 },
michael@0 767 { (const char *)0, (const char *)0, 7, (const char *)0 },
michael@0 768 { (const char *)0, "", 0, (const char *)0 },
michael@0 769 { (const char *)0, "", 1, (const char *)0 },
michael@0 770 { (const char *)0, "", 7, (const char *)0 },
michael@0 771 { (const char *)0, "stuff", 0, (const char *)0 },
michael@0 772 { (const char *)0, "stuff", 1, (const char *)0 },
michael@0 773 { (const char *)0, "stuff", 7, (const char *)0 },
michael@0 774 { "", (const char *)0, 0, "" },
michael@0 775 { "", (const char *)0, 1, "" },
michael@0 776 { "", (const char *)0, 7, "" },
michael@0 777 { "", "", 0, "" },
michael@0 778 { "", "", 1, "" },
michael@0 779 { "", "", 7, "" },
michael@0 780 { "", "abcdefgh", 0, "" },
michael@0 781 { "", "abcdefgh", 1, "" },
michael@0 782 { "", "abcdefgh", 7, "abcdef" },
michael@0 783 { "xyz", (const char *)0, 0, "xyz" },
michael@0 784 { "xyz", (const char *)0, 1, "xyz" },
michael@0 785 { "xyz", (const char *)0, 7, "xyz" },
michael@0 786 { "xyz", "", 0, "xyz" },
michael@0 787 { "xyz", "", 1, "xyz" },
michael@0 788 { "xyz", "", 7, "xyz" },
michael@0 789 { "xyz", "abcdefgh", 0, "xyz" },
michael@0 790 { "xyz", "abcdefgh", 1, "xyz" },
michael@0 791 { "xyz", "abcdefgh", 7, "xyzabc" }
michael@0 792 };
michael@0 793
michael@0 794 int i;
michael@0 795
michael@0 796 printf("Test 010 (PL_strcatn) ..."); fflush(stdout);
michael@0 797
michael@0 798 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 799 {
michael@0 800 char buffer[ 1024 ];
michael@0 801 int j;
michael@0 802 char *rv;
michael@0 803
michael@0 804 for( j = 0; j < sizeof(buffer); j++ )
michael@0 805 buffer[j] = '-';
michael@0 806
michael@0 807 if( (const char *)0 != array[i].first )
michael@0 808 (void)PL_strcpy(buffer, array[i].first);
michael@0 809
michael@0 810 rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer,
michael@0 811 array[i].length, array[i].second);
michael@0 812
michael@0 813 if( (const char *)0 == array[i].result )
michael@0 814 {
michael@0 815 if( (char *)0 != rv )
michael@0 816 {
michael@0 817 printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
michael@0 818 array[i].first ? array[i].first : "(null)",
michael@0 819 array[i].second ? array[i].second : "(null)",
michael@0 820 array[i].length, rv);
michael@0 821 return PR_FALSE;
michael@0 822 }
michael@0 823 }
michael@0 824 else
michael@0 825 {
michael@0 826 if( (char *)0 == rv )
michael@0 827 {
michael@0 828 printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
michael@0 829 array[i].first ? array[i].first : "(null)",
michael@0 830 array[i].second ? array[i].second : "(null)",
michael@0 831 array[i].length, array[i].result);
michael@0 832 return PR_FALSE;
michael@0 833 }
michael@0 834 else
michael@0 835 {
michael@0 836 const char *a = array[i].result;
michael@0 837 const char *b = (const char *)rv;
michael@0 838
michael@0 839 while( 1 )
michael@0 840 {
michael@0 841 if( *a != *b )
michael@0 842 {
michael@0 843 printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
michael@0 844 array[i].first ? array[i].first : "(null)",
michael@0 845 array[i].second ? array[i].second : "(null)",
michael@0 846 array[i].length, rv, array[i].result);
michael@0 847 return PR_FALSE;
michael@0 848 }
michael@0 849
michael@0 850 if( (char)0 == *a ) break;
michael@0 851
michael@0 852 a++;
michael@0 853 b++;
michael@0 854 }
michael@0 855 }
michael@0 856 }
michael@0 857 }
michael@0 858
michael@0 859 printf("PASS\n");
michael@0 860 return PR_TRUE;
michael@0 861 }
michael@0 862
michael@0 863 /* PL_strcmp */
michael@0 864 PRBool test_011(void)
michael@0 865 {
michael@0 866 static struct
michael@0 867 {
michael@0 868 const char *one;
michael@0 869 const char *two;
michael@0 870 PRIntn sign;
michael@0 871 } array[] =
michael@0 872 {
michael@0 873 { (const char *)0, (const char *)0, 0 },
michael@0 874 { (const char *)0, "word", -1 },
michael@0 875 { "word", (const char *)0, 1 },
michael@0 876 { "word", "word", 0 },
michael@0 877 { "aZYXVUT", "bZYXVUT", -1 },
michael@0 878 { "aZYXVUT", "bAAAAAA", -1 },
michael@0 879 { "a", "aa", -1 },
michael@0 880 { "a", "a", 0 },
michael@0 881 { "a", "A", 1 },
michael@0 882 { "aaaaa", "baaaa", -1 },
michael@0 883 { "aaaaa", "abaaa", -1 },
michael@0 884 { "aaaaa", "aabaa", -1 },
michael@0 885 { "aaaaa", "aaaba", -1 },
michael@0 886 { "aaaaa", "aaaab", -1 },
michael@0 887 { "bZYXVUT", "aZYXVUT", 1 },
michael@0 888 { "bAAAAAA", "aZYXVUT", 1 },
michael@0 889 { "aa", "a", 1 },
michael@0 890 { "A", "a", -1 },
michael@0 891 { "baaaa", "aaaaa", 1 },
michael@0 892 { "abaaa", "aaaaa", 1 },
michael@0 893 { "aabaa", "aaaaa", 1 },
michael@0 894 { "aaaba", "aaaaa", 1 },
michael@0 895 { "aaaab", "aaaaa", 1 },
michael@0 896 { "word", "Word", 1 },
michael@0 897 { "word", "wOrd", 1 },
michael@0 898 { "word", "woRd", 1 },
michael@0 899 { "word", "worD", 1 },
michael@0 900 { "WORD", "wORD", -1 },
michael@0 901 { "WORD", "WoRD", -1 },
michael@0 902 { "WORD", "WOrD", -1 },
michael@0 903 { "WORD", "WORd", -1 }
michael@0 904 };
michael@0 905
michael@0 906 int i;
michael@0 907
michael@0 908 printf("Test 011 (PL_strcmp) ..."); fflush(stdout);
michael@0 909
michael@0 910 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 911 {
michael@0 912 PRIntn rv = PL_strcmp(array[i].one, array[i].two);
michael@0 913
michael@0 914 switch( array[i].sign )
michael@0 915 {
michael@0 916 case -1:
michael@0 917 if( rv < 0 ) continue;
michael@0 918 break;
michael@0 919 case 1:
michael@0 920 if( rv > 0 ) continue;
michael@0 921 break;
michael@0 922 case 0:
michael@0 923 if( 0 == rv ) continue;
michael@0 924 break;
michael@0 925 default:
michael@0 926 PR_NOT_REACHED("static data inconsistancy");
michael@0 927 break;
michael@0 928 }
michael@0 929
michael@0 930 printf("FAIL %d: %s-%s -> %d, not %d\n", i,
michael@0 931 array[i].one ? array[i].one : "(null)",
michael@0 932 array[i].two ? array[i].two : "(null)",
michael@0 933 rv, array[i].sign);
michael@0 934 return PR_FALSE;
michael@0 935 }
michael@0 936
michael@0 937 printf("PASS\n");
michael@0 938 return PR_TRUE;
michael@0 939 }
michael@0 940
michael@0 941 /* PL_strncmp */
michael@0 942 PRBool test_012(void)
michael@0 943 {
michael@0 944 static struct
michael@0 945 {
michael@0 946 const char *one;
michael@0 947 const char *two;
michael@0 948 PRUint32 max;
michael@0 949 PRIntn sign;
michael@0 950 } array[] =
michael@0 951 {
michael@0 952 { (const char *)0, (const char *)0, 0, 0 },
michael@0 953 { (const char *)0, (const char *)0, 1, 0 },
michael@0 954 { (const char *)0, (const char *)0, 4, 0 },
michael@0 955 { (const char *)0, "word", 0, -1 },
michael@0 956 { (const char *)0, "word", 1, -1 },
michael@0 957 { (const char *)0, "word", 4, -1 },
michael@0 958 { "word", (const char *)0, 0, 1 },
michael@0 959 { "word", (const char *)0, 1, 1 },
michael@0 960 { "word", (const char *)0, 4, 1 },
michael@0 961 { "word", "word", 0, 0 },
michael@0 962 { "word", "word", 1, 0 },
michael@0 963 { "word", "word", 3, 0 },
michael@0 964 { "word", "word", 5, 0 },
michael@0 965 { "aZYXVUT", "bZYXVUT", 0, 0 },
michael@0 966 { "aZYXVUT", "bZYXVUT", 1, -1 },
michael@0 967 { "aZYXVUT", "bZYXVUT", 4, -1 },
michael@0 968 { "aZYXVUT", "bZYXVUT", 9, -1 },
michael@0 969 { "aZYXVUT", "bAAAAAA", 0, 0 },
michael@0 970 { "aZYXVUT", "bAAAAAA", 1, -1 },
michael@0 971 { "aZYXVUT", "bAAAAAA", 4, -1 },
michael@0 972 { "aZYXVUT", "bAAAAAA", 5, -1 },
michael@0 973 { "a", "aa", 0, 0 },
michael@0 974 { "a", "aa", 1, 0 },
michael@0 975 { "a", "aa", 4, -1 },
michael@0 976 { "a", "a", 0, 0 },
michael@0 977 { "a", "a", 1, 0 },
michael@0 978 { "a", "a", 4, 0 },
michael@0 979 { "a", "A", 0, 0 },
michael@0 980 { "a", "A", 1, 1 },
michael@0 981 { "a", "A", 4, 1 },
michael@0 982 { "aaaaa", "baaaa", 0, 0 },
michael@0 983 { "aaaaa", "baaaa", 1, -1 },
michael@0 984 { "aaaaa", "baaaa", 4, -1 },
michael@0 985 { "aaaaa", "abaaa", 0, 0 },
michael@0 986 { "aaaaa", "abaaa", 1, 0 },
michael@0 987 { "aaaaa", "abaaa", 4, -1 },
michael@0 988 { "aaaaa", "aabaa", 0, 0 },
michael@0 989 { "aaaaa", "aabaa", 1, 0 },
michael@0 990 { "aaaaa", "aabaa", 4, -1 },
michael@0 991 { "aaaaa", "aaaba", 0, 0 },
michael@0 992 { "aaaaa", "aaaba", 1, 0 },
michael@0 993 { "aaaaa", "aaaba", 4, -1 },
michael@0 994 { "aaaaa", "aaaab", 0, 0 },
michael@0 995 { "aaaaa", "aaaab", 1, 0 },
michael@0 996 { "aaaaa", "aaaab", 4, 0 },
michael@0 997 { "bZYXVUT", "aZYXVUT", 0, 0 },
michael@0 998 { "bZYXVUT", "aZYXVUT", 1, 1 },
michael@0 999 { "bZYXVUT", "aZYXVUT", 4, 1 },
michael@0 1000 { "bAAAAAA", "aZYXVUT", 0, 0 },
michael@0 1001 { "bAAAAAA", "aZYXVUT", 1, 1 },
michael@0 1002 { "bAAAAAA", "aZYXVUT", 4, 1 },
michael@0 1003 { "aa", "a", 0, 0 },
michael@0 1004 { "aa", "a", 1, 0 },
michael@0 1005 { "aa", "a", 4, 1 },
michael@0 1006 { "A", "a", 0, 0 },
michael@0 1007 { "A", "a", 1, -1 },
michael@0 1008 { "A", "a", 4, -1 },
michael@0 1009 { "baaaa", "aaaaa", 0, 0 },
michael@0 1010 { "baaaa", "aaaaa", 1, 1 },
michael@0 1011 { "baaaa", "aaaaa", 4, 1 },
michael@0 1012 { "abaaa", "aaaaa", 0, 0 },
michael@0 1013 { "abaaa", "aaaaa", 1, 0 },
michael@0 1014 { "abaaa", "aaaaa", 4, 1 },
michael@0 1015 { "aabaa", "aaaaa", 0, 0 },
michael@0 1016 { "aabaa", "aaaaa", 1, 0 },
michael@0 1017 { "aabaa", "aaaaa", 4, 1 },
michael@0 1018 { "aaaba", "aaaaa", 0, 0 },
michael@0 1019 { "aaaba", "aaaaa", 1, 0 },
michael@0 1020 { "aaaba", "aaaaa", 4, 1 },
michael@0 1021 { "aaaab", "aaaaa", 0, 0 },
michael@0 1022 { "aaaab", "aaaaa", 1, 0 },
michael@0 1023 { "aaaab", "aaaaa", 4, 0 },
michael@0 1024 { "word", "Word", 0, 0 },
michael@0 1025 { "word", "Word", 1, 1 },
michael@0 1026 { "word", "Word", 3, 1 },
michael@0 1027 { "word", "wOrd", 0, 0 },
michael@0 1028 { "word", "wOrd", 1, 0 },
michael@0 1029 { "word", "wOrd", 3, 1 },
michael@0 1030 { "word", "woRd", 0, 0 },
michael@0 1031 { "word", "woRd", 1, 0 },
michael@0 1032 { "word", "woRd", 3, 1 },
michael@0 1033 { "word", "worD", 0, 0 },
michael@0 1034 { "word", "worD", 1, 0 },
michael@0 1035 { "word", "worD", 3, 0 },
michael@0 1036 { "WORD", "wORD", 0, 0 },
michael@0 1037 { "WORD", "wORD", 1, -1 },
michael@0 1038 { "WORD", "wORD", 3, -1 },
michael@0 1039 { "WORD", "WoRD", 0, 0 },
michael@0 1040 { "WORD", "WoRD", 1, 0 },
michael@0 1041 { "WORD", "WoRD", 3, -1 },
michael@0 1042 { "WORD", "WOrD", 0, 0 },
michael@0 1043 { "WORD", "WOrD", 1, 0 },
michael@0 1044 { "WORD", "WOrD", 3, -1 },
michael@0 1045 { "WORD", "WORd", 0, 0 },
michael@0 1046 { "WORD", "WORd", 1, 0 },
michael@0 1047 { "WORD", "WORd", 3, 0 }
michael@0 1048
michael@0 1049 };
michael@0 1050
michael@0 1051 int i;
michael@0 1052
michael@0 1053 printf("Test 012 (PL_strncmp) ..."); fflush(stdout);
michael@0 1054
michael@0 1055 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1056 {
michael@0 1057 PRIntn rv = PL_strncmp(array[i].one, array[i].two, array[i].max);
michael@0 1058
michael@0 1059 switch( array[i].sign )
michael@0 1060 {
michael@0 1061 case -1:
michael@0 1062 if( rv < 0 ) continue;
michael@0 1063 break;
michael@0 1064 case 1:
michael@0 1065 if( rv > 0 ) continue;
michael@0 1066 break;
michael@0 1067 case 0:
michael@0 1068 if( 0 == rv ) continue;
michael@0 1069 break;
michael@0 1070 default:
michael@0 1071 PR_NOT_REACHED("static data inconsistancy");
michael@0 1072 break;
michael@0 1073 }
michael@0 1074
michael@0 1075 printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
michael@0 1076 array[i].one ? array[i].one : "(null)",
michael@0 1077 array[i].two ? array[i].two : "(null)",
michael@0 1078 array[i].max, rv, array[i].sign);
michael@0 1079 return PR_FALSE;
michael@0 1080 }
michael@0 1081
michael@0 1082 printf("PASS\n");
michael@0 1083 return PR_TRUE;
michael@0 1084 }
michael@0 1085
michael@0 1086 /* PL_strcasecmp */
michael@0 1087 PRBool test_013(void)
michael@0 1088 {
michael@0 1089 static struct
michael@0 1090 {
michael@0 1091 const char *one;
michael@0 1092 const char *two;
michael@0 1093 PRIntn sign;
michael@0 1094 } array[] =
michael@0 1095 {
michael@0 1096 { (const char *)0, (const char *)0, 0 },
michael@0 1097 { (const char *)0, "word", -1 },
michael@0 1098 { "word", (const char *)0, 1 },
michael@0 1099 { "word", "word", 0 },
michael@0 1100 { "aZYXVUT", "bZYXVUT", -1 },
michael@0 1101 { "aZYXVUT", "bAAAAAA", -1 },
michael@0 1102 { "a", "aa", -1 },
michael@0 1103 { "a", "a", 0 },
michael@0 1104 { "a", "A", 0 },
michael@0 1105 { "aaaaa", "baaaa", -1 },
michael@0 1106 { "aaaaa", "abaaa", -1 },
michael@0 1107 { "aaaaa", "aabaa", -1 },
michael@0 1108 { "aaaaa", "aaaba", -1 },
michael@0 1109 { "aaaaa", "aaaab", -1 },
michael@0 1110 { "bZYXVUT", "aZYXVUT", 1 },
michael@0 1111 { "bAAAAAA", "aZYXVUT", 1 },
michael@0 1112 { "aa", "a", 1 },
michael@0 1113 { "A", "a", 0 },
michael@0 1114 { "baaaa", "aaaaa", 1 },
michael@0 1115 { "abaaa", "aaaaa", 1 },
michael@0 1116 { "aabaa", "aaaaa", 1 },
michael@0 1117 { "aaaba", "aaaaa", 1 },
michael@0 1118 { "aaaab", "aaaaa", 1 },
michael@0 1119 { "word", "Word", 0 },
michael@0 1120 { "word", "wOrd", 0 },
michael@0 1121 { "word", "woRd", 0 },
michael@0 1122 { "word", "worD", 0 },
michael@0 1123 { "WORD", "wORD", 0 },
michael@0 1124 { "WORD", "WoRD", 0 },
michael@0 1125 { "WORD", "WOrD", 0 },
michael@0 1126 { "WORD", "WORd", 0 }
michael@0 1127 };
michael@0 1128
michael@0 1129 int i;
michael@0 1130
michael@0 1131 printf("Test 013 (PL_strcasecmp) ..."); fflush(stdout);
michael@0 1132
michael@0 1133 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1134 {
michael@0 1135 PRIntn rv = PL_strcasecmp(array[i].one, array[i].two);
michael@0 1136
michael@0 1137 switch( array[i].sign )
michael@0 1138 {
michael@0 1139 case -1:
michael@0 1140 if( rv < 0 ) continue;
michael@0 1141 break;
michael@0 1142 case 1:
michael@0 1143 if( rv > 0 ) continue;
michael@0 1144 break;
michael@0 1145 case 0:
michael@0 1146 if( 0 == rv ) continue;
michael@0 1147 break;
michael@0 1148 default:
michael@0 1149 PR_NOT_REACHED("static data inconsistancy");
michael@0 1150 break;
michael@0 1151 }
michael@0 1152
michael@0 1153 printf("FAIL %d: %s-%s -> %d, not %d\n", i,
michael@0 1154 array[i].one ? array[i].one : "(null)",
michael@0 1155 array[i].two ? array[i].two : "(null)",
michael@0 1156 rv, array[i].sign);
michael@0 1157 return PR_FALSE;
michael@0 1158 }
michael@0 1159
michael@0 1160 printf("PASS\n");
michael@0 1161 return PR_TRUE;
michael@0 1162 }
michael@0 1163
michael@0 1164 /* PL_strncasecmp */
michael@0 1165 PRBool test_014(void)
michael@0 1166 {
michael@0 1167 static struct
michael@0 1168 {
michael@0 1169 const char *one;
michael@0 1170 const char *two;
michael@0 1171 PRUint32 max;
michael@0 1172 PRIntn sign;
michael@0 1173 } array[] =
michael@0 1174 {
michael@0 1175 { (const char *)0, (const char *)0, 0, 0 },
michael@0 1176 { (const char *)0, (const char *)0, 1, 0 },
michael@0 1177 { (const char *)0, (const char *)0, 4, 0 },
michael@0 1178 { (const char *)0, "word", 0, -1 },
michael@0 1179 { (const char *)0, "word", 1, -1 },
michael@0 1180 { (const char *)0, "word", 4, -1 },
michael@0 1181 { "word", (const char *)0, 0, 1 },
michael@0 1182 { "word", (const char *)0, 1, 1 },
michael@0 1183 { "word", (const char *)0, 4, 1 },
michael@0 1184 { "word", "word", 0, 0 },
michael@0 1185 { "word", "word", 1, 0 },
michael@0 1186 { "word", "word", 3, 0 },
michael@0 1187 { "word", "word", 5, 0 },
michael@0 1188 { "aZYXVUT", "bZYXVUT", 0, 0 },
michael@0 1189 { "aZYXVUT", "bZYXVUT", 1, -1 },
michael@0 1190 { "aZYXVUT", "bZYXVUT", 4, -1 },
michael@0 1191 { "aZYXVUT", "bZYXVUT", 9, -1 },
michael@0 1192 { "aZYXVUT", "bAAAAAA", 0, 0 },
michael@0 1193 { "aZYXVUT", "bAAAAAA", 1, -1 },
michael@0 1194 { "aZYXVUT", "bAAAAAA", 4, -1 },
michael@0 1195 { "aZYXVUT", "bAAAAAA", 5, -1 },
michael@0 1196 { "a", "aa", 0, 0 },
michael@0 1197 { "a", "aa", 1, 0 },
michael@0 1198 { "a", "aa", 4, -1 },
michael@0 1199 { "a", "a", 0, 0 },
michael@0 1200 { "a", "a", 1, 0 },
michael@0 1201 { "a", "a", 4, 0 },
michael@0 1202 { "a", "A", 0, 0 },
michael@0 1203 { "a", "A", 1, 0 },
michael@0 1204 { "a", "A", 4, 0 },
michael@0 1205 { "aaaaa", "baaaa", 0, 0 },
michael@0 1206 { "aaaaa", "baaaa", 1, -1 },
michael@0 1207 { "aaaaa", "baaaa", 4, -1 },
michael@0 1208 { "aaaaa", "abaaa", 0, 0 },
michael@0 1209 { "aaaaa", "abaaa", 1, 0 },
michael@0 1210 { "aaaaa", "abaaa", 4, -1 },
michael@0 1211 { "aaaaa", "aabaa", 0, 0 },
michael@0 1212 { "aaaaa", "aabaa", 1, 0 },
michael@0 1213 { "aaaaa", "aabaa", 4, -1 },
michael@0 1214 { "aaaaa", "aaaba", 0, 0 },
michael@0 1215 { "aaaaa", "aaaba", 1, 0 },
michael@0 1216 { "aaaaa", "aaaba", 4, -1 },
michael@0 1217 { "aaaaa", "aaaab", 0, 0 },
michael@0 1218 { "aaaaa", "aaaab", 1, 0 },
michael@0 1219 { "aaaaa", "aaaab", 4, 0 },
michael@0 1220 { "bZYXVUT", "aZYXVUT", 0, 0 },
michael@0 1221 { "bZYXVUT", "aZYXVUT", 1, 1 },
michael@0 1222 { "bZYXVUT", "aZYXVUT", 4, 1 },
michael@0 1223 { "bAAAAAA", "aZYXVUT", 0, 0 },
michael@0 1224 { "bAAAAAA", "aZYXVUT", 1, 1 },
michael@0 1225 { "bAAAAAA", "aZYXVUT", 4, 1 },
michael@0 1226 { "aa", "a", 0, 0 },
michael@0 1227 { "aa", "a", 1, 0 },
michael@0 1228 { "aa", "a", 4, 1 },
michael@0 1229 { "A", "a", 0, 0 },
michael@0 1230 { "A", "a", 1, 0 },
michael@0 1231 { "A", "a", 4, 0 },
michael@0 1232 { "baaaa", "aaaaa", 0, 0 },
michael@0 1233 { "baaaa", "aaaaa", 1, 1 },
michael@0 1234 { "baaaa", "aaaaa", 4, 1 },
michael@0 1235 { "abaaa", "aaaaa", 0, 0 },
michael@0 1236 { "abaaa", "aaaaa", 1, 0 },
michael@0 1237 { "abaaa", "aaaaa", 4, 1 },
michael@0 1238 { "aabaa", "aaaaa", 0, 0 },
michael@0 1239 { "aabaa", "aaaaa", 1, 0 },
michael@0 1240 { "aabaa", "aaaaa", 4, 1 },
michael@0 1241 { "aaaba", "aaaaa", 0, 0 },
michael@0 1242 { "aaaba", "aaaaa", 1, 0 },
michael@0 1243 { "aaaba", "aaaaa", 4, 1 },
michael@0 1244 { "aaaab", "aaaaa", 0, 0 },
michael@0 1245 { "aaaab", "aaaaa", 1, 0 },
michael@0 1246 { "aaaab", "aaaaa", 4, 0 },
michael@0 1247 { "word", "Word", 0, 0 },
michael@0 1248 { "word", "Word", 1, 0 },
michael@0 1249 { "word", "Word", 3, 0 },
michael@0 1250 { "word", "wOrd", 0, 0 },
michael@0 1251 { "word", "wOrd", 1, 0 },
michael@0 1252 { "word", "wOrd", 3, 0 },
michael@0 1253 { "word", "woRd", 0, 0 },
michael@0 1254 { "word", "woRd", 1, 0 },
michael@0 1255 { "word", "woRd", 3, 0 },
michael@0 1256 { "word", "worD", 0, 0 },
michael@0 1257 { "word", "worD", 1, 0 },
michael@0 1258 { "word", "worD", 3, 0 },
michael@0 1259 { "WORD", "wORD", 0, 0 },
michael@0 1260 { "WORD", "wORD", 1, 0 },
michael@0 1261 { "WORD", "wORD", 3, 0 },
michael@0 1262 { "WORD", "WoRD", 0, 0 },
michael@0 1263 { "WORD", "WoRD", 1, 0 },
michael@0 1264 { "WORD", "WoRD", 3, 0 },
michael@0 1265 { "WORD", "WOrD", 0, 0 },
michael@0 1266 { "WORD", "WOrD", 1, 0 },
michael@0 1267 { "WORD", "WOrD", 3, 0 },
michael@0 1268 { "WORD", "WORd", 0, 0 },
michael@0 1269 { "WORD", "WORd", 1, 0 },
michael@0 1270 { "WORD", "WORd", 3, 0 }
michael@0 1271 };
michael@0 1272
michael@0 1273 int i;
michael@0 1274
michael@0 1275 printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout);
michael@0 1276
michael@0 1277 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1278 {
michael@0 1279 PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max);
michael@0 1280
michael@0 1281 switch( array[i].sign )
michael@0 1282 {
michael@0 1283 case -1:
michael@0 1284 if( rv < 0 ) continue;
michael@0 1285 break;
michael@0 1286 case 1:
michael@0 1287 if( rv > 0 ) continue;
michael@0 1288 break;
michael@0 1289 case 0:
michael@0 1290 if( 0 == rv ) continue;
michael@0 1291 break;
michael@0 1292 default:
michael@0 1293 PR_NOT_REACHED("static data inconsistancy");
michael@0 1294 break;
michael@0 1295 }
michael@0 1296
michael@0 1297 printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
michael@0 1298 array[i].one ? array[i].one : "(null)",
michael@0 1299 array[i].two ? array[i].two : "(null)",
michael@0 1300 array[i].max, rv, array[i].sign);
michael@0 1301 return PR_FALSE;
michael@0 1302 }
michael@0 1303
michael@0 1304 printf("PASS\n");
michael@0 1305 return PR_TRUE;
michael@0 1306 }
michael@0 1307
michael@0 1308 /* PL_strchr */
michael@0 1309 PRBool test_015(void)
michael@0 1310 {
michael@0 1311 static struct
michael@0 1312 {
michael@0 1313 const char *str;
michael@0 1314 char chr;
michael@0 1315 PRBool ret;
michael@0 1316 PRUint32 off;
michael@0 1317 } array[] =
michael@0 1318 {
michael@0 1319 { (const char *)0, 'a', PR_FALSE, 0 },
michael@0 1320 { (const char *)0, '\0', PR_FALSE, 0 },
michael@0 1321 { "abcdefg", 'a', PR_TRUE, 0 },
michael@0 1322 { "abcdefg", 'b', PR_TRUE, 1 },
michael@0 1323 { "abcdefg", 'c', PR_TRUE, 2 },
michael@0 1324 { "abcdefg", 'd', PR_TRUE, 3 },
michael@0 1325 { "abcdefg", 'e', PR_TRUE, 4 },
michael@0 1326 { "abcdefg", 'f', PR_TRUE, 5 },
michael@0 1327 { "abcdefg", 'g', PR_TRUE, 6 },
michael@0 1328 { "abcdefg", 'h', PR_FALSE, 0 },
michael@0 1329 { "abcdefg", '\0', PR_TRUE, 7 },
michael@0 1330 { "abcdefg", 'A', PR_FALSE, 0 },
michael@0 1331 { "abcdefg", 'B', PR_FALSE, 0 },
michael@0 1332 { "abcdefg", 'C', PR_FALSE, 0 },
michael@0 1333 { "abcdefg", 'D', PR_FALSE, 0 },
michael@0 1334 { "abcdefg", 'E', PR_FALSE, 0 },
michael@0 1335 { "abcdefg", 'F', PR_FALSE, 0 },
michael@0 1336 { "abcdefg", 'G', PR_FALSE, 0 },
michael@0 1337 { "abcdefg", 'H', PR_FALSE, 0 },
michael@0 1338 { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
michael@0 1339 { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
michael@0 1340 { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
michael@0 1341 { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
michael@0 1342 { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
michael@0 1343 { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
michael@0 1344 { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
michael@0 1345 { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
michael@0 1346 { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
michael@0 1347 };
michael@0 1348
michael@0 1349 int i;
michael@0 1350
michael@0 1351 printf("Test 015 (PL_strchr) ..."); fflush(stdout);
michael@0 1352
michael@0 1353 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1354 {
michael@0 1355 char *rv = PL_strchr(array[i].str, array[i].chr);
michael@0 1356
michael@0 1357 if( PR_FALSE == array[i].ret )
michael@0 1358 {
michael@0 1359 if( (char *)0 != rv )
michael@0 1360 {
michael@0 1361 printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
michael@0 1362 array[i].chr, rv);
michael@0 1363 return PR_FALSE;
michael@0 1364 }
michael@0 1365 }
michael@0 1366 else
michael@0 1367 {
michael@0 1368 if( (char *)0 == rv )
michael@0 1369 {
michael@0 1370 printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
michael@0 1371 array[i].chr, array[i].off);
michael@0 1372 return PR_FALSE;
michael@0 1373 }
michael@0 1374
michael@0 1375 if( &array[i].str[ array[i].off ] != rv )
michael@0 1376 {
michael@0 1377 printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
michael@0 1378 array[i].chr, rv, array[i].str, array[i].off);
michael@0 1379 return PR_FALSE;
michael@0 1380 }
michael@0 1381 }
michael@0 1382 }
michael@0 1383
michael@0 1384 printf("PASS\n");
michael@0 1385 return PR_TRUE;
michael@0 1386 }
michael@0 1387
michael@0 1388 /* PL_strrchr */
michael@0 1389 PRBool test_016(void)
michael@0 1390 {
michael@0 1391 static struct
michael@0 1392 {
michael@0 1393 const char *str;
michael@0 1394 char chr;
michael@0 1395 PRBool ret;
michael@0 1396 PRUint32 off;
michael@0 1397 } array[] =
michael@0 1398 {
michael@0 1399 { (const char *)0, 'a', PR_FALSE, 0 },
michael@0 1400 { (const char *)0, '\0', PR_FALSE, 0 },
michael@0 1401 { "abcdefg", 'a', PR_TRUE, 0 },
michael@0 1402 { "abcdefg", 'b', PR_TRUE, 1 },
michael@0 1403 { "abcdefg", 'c', PR_TRUE, 2 },
michael@0 1404 { "abcdefg", 'd', PR_TRUE, 3 },
michael@0 1405 { "abcdefg", 'e', PR_TRUE, 4 },
michael@0 1406 { "abcdefg", 'f', PR_TRUE, 5 },
michael@0 1407 { "abcdefg", 'g', PR_TRUE, 6 },
michael@0 1408 { "abcdefg", 'h', PR_FALSE, 0 },
michael@0 1409 { "abcdefg", '\0', PR_TRUE, 7 },
michael@0 1410 { "abcdefg", 'A', PR_FALSE, 0 },
michael@0 1411 { "abcdefg", 'B', PR_FALSE, 0 },
michael@0 1412 { "abcdefg", 'C', PR_FALSE, 0 },
michael@0 1413 { "abcdefg", 'D', PR_FALSE, 0 },
michael@0 1414 { "abcdefg", 'E', PR_FALSE, 0 },
michael@0 1415 { "abcdefg", 'F', PR_FALSE, 0 },
michael@0 1416 { "abcdefg", 'G', PR_FALSE, 0 },
michael@0 1417 { "abcdefg", 'H', PR_FALSE, 0 },
michael@0 1418 { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
michael@0 1419 { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
michael@0 1420 { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
michael@0 1421 { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
michael@0 1422 { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
michael@0 1423 { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
michael@0 1424 { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
michael@0 1425 { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
michael@0 1426 { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
michael@0 1427 };
michael@0 1428
michael@0 1429 int i;
michael@0 1430
michael@0 1431 printf("Test 016 (PL_strrchr) ..."); fflush(stdout);
michael@0 1432
michael@0 1433 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1434 {
michael@0 1435 char *rv = PL_strrchr(array[i].str, array[i].chr);
michael@0 1436
michael@0 1437 if( PR_FALSE == array[i].ret )
michael@0 1438 {
michael@0 1439 if( (char *)0 != rv )
michael@0 1440 {
michael@0 1441 printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
michael@0 1442 array[i].chr, rv);
michael@0 1443 return PR_FALSE;
michael@0 1444 }
michael@0 1445 }
michael@0 1446 else
michael@0 1447 {
michael@0 1448 if( (char *)0 == rv )
michael@0 1449 {
michael@0 1450 printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
michael@0 1451 array[i].chr, array[i].off);
michael@0 1452 return PR_FALSE;
michael@0 1453 }
michael@0 1454
michael@0 1455 if( &array[i].str[ array[i].off ] != rv )
michael@0 1456 {
michael@0 1457 printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
michael@0 1458 array[i].chr, rv, array[i].str, array[i].off);
michael@0 1459 return PR_FALSE;
michael@0 1460 }
michael@0 1461 }
michael@0 1462 }
michael@0 1463
michael@0 1464 printf("PASS\n");
michael@0 1465 return PR_TRUE;
michael@0 1466 }
michael@0 1467
michael@0 1468 /* PL_strnchr */
michael@0 1469 PRBool test_017(void)
michael@0 1470 {
michael@0 1471 static struct
michael@0 1472 {
michael@0 1473 const char *str;
michael@0 1474 char chr;
michael@0 1475 PRUint32 max;
michael@0 1476 PRBool ret;
michael@0 1477 PRUint32 off;
michael@0 1478 } array[] =
michael@0 1479 {
michael@0 1480 { (const char *)0, 'a', 2, PR_FALSE, 0 },
michael@0 1481 { (const char *)0, '\0', 2, PR_FALSE, 0 },
michael@0 1482 { "abcdefg", 'a', 5, PR_TRUE, 0 },
michael@0 1483 { "abcdefg", 'b', 5, PR_TRUE, 1 },
michael@0 1484 { "abcdefg", 'c', 5, PR_TRUE, 2 },
michael@0 1485 { "abcdefg", 'd', 5, PR_TRUE, 3 },
michael@0 1486 { "abcdefg", 'e', 5, PR_TRUE, 4 },
michael@0 1487 { "abcdefg", 'f', 5, PR_FALSE, 0 },
michael@0 1488 { "abcdefg", 'g', 5, PR_FALSE, 0 },
michael@0 1489 { "abcdefg", 'h', 5, PR_FALSE, 0 },
michael@0 1490 { "abcdefg", '\0', 5, PR_FALSE, 0 },
michael@0 1491 { "abcdefg", '\0', 15, PR_TRUE, 7 },
michael@0 1492 { "abcdefg", 'A', 5, PR_FALSE, 0 },
michael@0 1493 { "abcdefg", 'B', 5, PR_FALSE, 0 },
michael@0 1494 { "abcdefg", 'C', 5, PR_FALSE, 0 },
michael@0 1495 { "abcdefg", 'D', 5, PR_FALSE, 0 },
michael@0 1496 { "abcdefg", 'E', 5, PR_FALSE, 0 },
michael@0 1497 { "abcdefg", 'F', 5, PR_FALSE, 0 },
michael@0 1498 { "abcdefg", 'G', 5, PR_FALSE, 0 },
michael@0 1499 { "abcdefg", 'H', 5, PR_FALSE, 0 },
michael@0 1500 { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
michael@0 1501 { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
michael@0 1502 { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
michael@0 1503 { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
michael@0 1504 { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
michael@0 1505 { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
michael@0 1506 { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
michael@0 1507 { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
michael@0 1508 { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
michael@0 1509 { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
michael@0 1510 { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
michael@0 1511 };
michael@0 1512
michael@0 1513 int i;
michael@0 1514
michael@0 1515 printf("Test 017 (PL_strnchr) ..."); fflush(stdout);
michael@0 1516
michael@0 1517 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1518 {
michael@0 1519 char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max);
michael@0 1520
michael@0 1521 if( PR_FALSE == array[i].ret )
michael@0 1522 {
michael@0 1523 if( (char *)0 != rv )
michael@0 1524 {
michael@0 1525 printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
michael@0 1526 array[i].chr, array[i].max, rv);
michael@0 1527 return PR_FALSE;
michael@0 1528 }
michael@0 1529 }
michael@0 1530 else
michael@0 1531 {
michael@0 1532 if( (char *)0 == rv )
michael@0 1533 {
michael@0 1534 printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
michael@0 1535 array[i].chr, array[i].max, array[i].off);
michael@0 1536 return PR_FALSE;
michael@0 1537 }
michael@0 1538
michael@0 1539 if( &array[i].str[ array[i].off ] != rv )
michael@0 1540 {
michael@0 1541 printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
michael@0 1542 array[i].chr, array[i].max, rv, array[i].str, array[i].off);
michael@0 1543 return PR_FALSE;
michael@0 1544 }
michael@0 1545 }
michael@0 1546 }
michael@0 1547
michael@0 1548 printf("PASS\n");
michael@0 1549 return PR_TRUE;
michael@0 1550 }
michael@0 1551
michael@0 1552 /* PL_strnrchr */
michael@0 1553 PRBool test_018(void)
michael@0 1554 {
michael@0 1555 static struct
michael@0 1556 {
michael@0 1557 const char *str;
michael@0 1558 char chr;
michael@0 1559 PRUint32 max;
michael@0 1560 PRBool ret;
michael@0 1561 PRUint32 off;
michael@0 1562 } array[] =
michael@0 1563 {
michael@0 1564 { (const char *)0, 'a', 2, PR_FALSE, 0 },
michael@0 1565 { (const char *)0, '\0', 2, PR_FALSE, 0 },
michael@0 1566 { "abcdefg", 'a', 5, PR_TRUE, 0 },
michael@0 1567 { "abcdefg", 'b', 5, PR_TRUE, 1 },
michael@0 1568 { "abcdefg", 'c', 5, PR_TRUE, 2 },
michael@0 1569 { "abcdefg", 'd', 5, PR_TRUE, 3 },
michael@0 1570 { "abcdefg", 'e', 5, PR_TRUE, 4 },
michael@0 1571 { "abcdefg", 'f', 5, PR_FALSE, 0 },
michael@0 1572 { "abcdefg", 'g', 5, PR_FALSE, 0 },
michael@0 1573 { "abcdefg", 'h', 5, PR_FALSE, 0 },
michael@0 1574 { "abcdefg", '\0', 5, PR_FALSE, 0 },
michael@0 1575 { "abcdefg", '\0', 15, PR_TRUE, 7 },
michael@0 1576 { "abcdefg", 'A', 5, PR_FALSE, 0 },
michael@0 1577 { "abcdefg", 'B', 5, PR_FALSE, 0 },
michael@0 1578 { "abcdefg", 'C', 5, PR_FALSE, 0 },
michael@0 1579 { "abcdefg", 'D', 5, PR_FALSE, 0 },
michael@0 1580 { "abcdefg", 'E', 5, PR_FALSE, 0 },
michael@0 1581 { "abcdefg", 'F', 5, PR_FALSE, 0 },
michael@0 1582 { "abcdefg", 'G', 5, PR_FALSE, 0 },
michael@0 1583 { "abcdefg", 'H', 5, PR_FALSE, 0 },
michael@0 1584 { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
michael@0 1585 { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
michael@0 1586 { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
michael@0 1587 { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
michael@0 1588 { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
michael@0 1589 { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
michael@0 1590 { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
michael@0 1591 { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
michael@0 1592 { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
michael@0 1593 { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
michael@0 1594 { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
michael@0 1595 };
michael@0 1596
michael@0 1597 int i;
michael@0 1598
michael@0 1599 printf("Test 018 (PL_strnrchr) ..."); fflush(stdout);
michael@0 1600
michael@0 1601 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1602 {
michael@0 1603 char *rv = PL_strnrchr(array[i].str, array[i].chr, array[i].max);
michael@0 1604
michael@0 1605 if( PR_FALSE == array[i].ret )
michael@0 1606 {
michael@0 1607 if( (char *)0 != rv )
michael@0 1608 {
michael@0 1609 printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
michael@0 1610 array[i].chr, array[i].max, rv);
michael@0 1611 return PR_FALSE;
michael@0 1612 }
michael@0 1613 }
michael@0 1614 else
michael@0 1615 {
michael@0 1616 if( (char *)0 == rv )
michael@0 1617 {
michael@0 1618 printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
michael@0 1619 array[i].chr, array[i].max, array[i].off);
michael@0 1620 return PR_FALSE;
michael@0 1621 }
michael@0 1622
michael@0 1623 if( &array[i].str[ array[i].off ] != rv )
michael@0 1624 {
michael@0 1625 printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
michael@0 1626 array[i].chr, array[i].max, rv, array[i].str, array[i].off);
michael@0 1627 return PR_FALSE;
michael@0 1628 }
michael@0 1629 }
michael@0 1630 }
michael@0 1631
michael@0 1632 printf("PASS\n");
michael@0 1633 return PR_TRUE;
michael@0 1634 }
michael@0 1635
michael@0 1636 /* PL_strpbrk */
michael@0 1637 PRBool test_019(void)
michael@0 1638 {
michael@0 1639 static struct
michael@0 1640 {
michael@0 1641 const char *str;
michael@0 1642 const char *chrs;
michael@0 1643 PRBool ret;
michael@0 1644 PRUint32 off;
michael@0 1645 } array[] =
michael@0 1646 {
michael@0 1647 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 1648 { (const char *)0, "abc", PR_FALSE, 0 },
michael@0 1649 { "abc", (const char *)0, PR_FALSE, 0 },
michael@0 1650 { "abcdefg", "", PR_FALSE, 0 },
michael@0 1651 { "", "aeiou", PR_FALSE, 0 },
michael@0 1652 { "abcdefg", "ae", PR_TRUE, 0 },
michael@0 1653 { "abcdefg", "ei", PR_TRUE, 4 },
michael@0 1654 { "abcdefg", "io", PR_FALSE, 0 },
michael@0 1655 { "abcdefg", "bcd", PR_TRUE, 1 },
michael@0 1656 { "abcdefg", "cbd", PR_TRUE, 1 },
michael@0 1657 { "abcdefg", "dbc", PR_TRUE, 1 },
michael@0 1658 { "abcdefg", "ghi", PR_TRUE, 6 },
michael@0 1659 { "abcdefg", "AE", PR_FALSE, 0 },
michael@0 1660 { "abcdefg", "EI", PR_FALSE, 0 },
michael@0 1661 { "abcdefg", "IO", PR_FALSE, 0 },
michael@0 1662 { "abcdefg", "BCD", PR_FALSE, 0 },
michael@0 1663 { "abcdefg", "CBD", PR_FALSE, 0 },
michael@0 1664 { "abcdefg", "DBC", PR_FALSE, 0 },
michael@0 1665 { "abcdefg", "GHI", PR_FALSE, 0 },
michael@0 1666 { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
michael@0 1667 { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
michael@0 1668 { "abcdefgabcdefg", "io", PR_FALSE, 0 },
michael@0 1669 { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
michael@0 1670 { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
michael@0 1671 { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
michael@0 1672 { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
michael@0 1673 { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
michael@0 1674 { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
michael@0 1675 { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
michael@0 1676 { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
michael@0 1677 { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
michael@0 1678 { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
michael@0 1679 { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
michael@0 1680 };
michael@0 1681
michael@0 1682 int i;
michael@0 1683
michael@0 1684 printf("Test 019 (PL_strpbrk) ..."); fflush(stdout);
michael@0 1685
michael@0 1686 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1687 {
michael@0 1688 char *rv = PL_strpbrk(array[i].str, array[i].chrs);
michael@0 1689
michael@0 1690 if( PR_FALSE == array[i].ret )
michael@0 1691 {
michael@0 1692 if( (char *)0 != rv )
michael@0 1693 {
michael@0 1694 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 1695 array[i].str ? array[i].str : "(null)",
michael@0 1696 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1697 rv);
michael@0 1698 return PR_FALSE;
michael@0 1699 }
michael@0 1700 }
michael@0 1701 else
michael@0 1702 {
michael@0 1703 if( (char *)0 == rv )
michael@0 1704 {
michael@0 1705 printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
michael@0 1706 array[i].str ? array[i].str : "(null)",
michael@0 1707 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1708 array[i].off);
michael@0 1709 return PR_FALSE;
michael@0 1710 }
michael@0 1711
michael@0 1712 if( &array[i].str[ array[i].off ] != rv )
michael@0 1713 {
michael@0 1714 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 1715 array[i].str ? array[i].str : "(null)",
michael@0 1716 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1717 rv, array[i].str, array[i].off);
michael@0 1718 return PR_FALSE;
michael@0 1719 }
michael@0 1720 }
michael@0 1721 }
michael@0 1722
michael@0 1723 printf("PASS\n");
michael@0 1724 return PR_TRUE;
michael@0 1725 }
michael@0 1726
michael@0 1727 /* PL_strprbrk */
michael@0 1728 PRBool test_020(void)
michael@0 1729 {
michael@0 1730 static struct
michael@0 1731 {
michael@0 1732 const char *str;
michael@0 1733 const char *chrs;
michael@0 1734 PRBool ret;
michael@0 1735 PRUint32 off;
michael@0 1736 } array[] =
michael@0 1737 {
michael@0 1738 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 1739 { (const char *)0, "abc", PR_FALSE, 0 },
michael@0 1740 { "abc", (const char *)0, PR_FALSE, 0 },
michael@0 1741 { "abcdefg", "", PR_FALSE, 0 },
michael@0 1742 { "", "aeiou", PR_FALSE, 0 },
michael@0 1743 { "abcdefg", "ae", PR_TRUE, 4 },
michael@0 1744 { "abcdefg", "ei", PR_TRUE, 4 },
michael@0 1745 { "abcdefg", "io", PR_FALSE, 0 },
michael@0 1746 { "abcdefg", "bcd", PR_TRUE, 3 },
michael@0 1747 { "abcdefg", "cbd", PR_TRUE, 3 },
michael@0 1748 { "abcdefg", "dbc", PR_TRUE, 3 },
michael@0 1749 { "abcdefg", "ghi", PR_TRUE, 6 },
michael@0 1750 { "abcdefg", "AE", PR_FALSE, 0 },
michael@0 1751 { "abcdefg", "EI", PR_FALSE, 0 },
michael@0 1752 { "abcdefg", "IO", PR_FALSE, 0 },
michael@0 1753 { "abcdefg", "BCD", PR_FALSE, 0 },
michael@0 1754 { "abcdefg", "CBD", PR_FALSE, 0 },
michael@0 1755 { "abcdefg", "DBC", PR_FALSE, 0 },
michael@0 1756 { "abcdefg", "GHI", PR_FALSE, 0 },
michael@0 1757 { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
michael@0 1758 { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
michael@0 1759 { "abcdefgabcdefg", "io", PR_FALSE, 0 },
michael@0 1760 { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
michael@0 1761 { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
michael@0 1762 { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
michael@0 1763 { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
michael@0 1764 { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
michael@0 1765 { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
michael@0 1766 { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
michael@0 1767 { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
michael@0 1768 { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
michael@0 1769 { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
michael@0 1770 { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
michael@0 1771 };
michael@0 1772
michael@0 1773 int i;
michael@0 1774
michael@0 1775 printf("Test 020 (PL_strprbrk) ..."); fflush(stdout);
michael@0 1776
michael@0 1777 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1778 {
michael@0 1779 char *rv = PL_strprbrk(array[i].str, array[i].chrs);
michael@0 1780
michael@0 1781 if( PR_FALSE == array[i].ret )
michael@0 1782 {
michael@0 1783 if( (char *)0 != rv )
michael@0 1784 {
michael@0 1785 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 1786 array[i].str ? array[i].str : "(null)",
michael@0 1787 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1788 rv);
michael@0 1789 return PR_FALSE;
michael@0 1790 }
michael@0 1791 }
michael@0 1792 else
michael@0 1793 {
michael@0 1794 if( (char *)0 == rv )
michael@0 1795 {
michael@0 1796 printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
michael@0 1797 array[i].str ? array[i].str : "(null)",
michael@0 1798 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1799 array[i].off);
michael@0 1800 return PR_FALSE;
michael@0 1801 }
michael@0 1802
michael@0 1803 if( &array[i].str[ array[i].off ] != rv )
michael@0 1804 {
michael@0 1805 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 1806 array[i].str ? array[i].str : "(null)",
michael@0 1807 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1808 rv, array[i].str, array[i].off);
michael@0 1809 return PR_FALSE;
michael@0 1810 }
michael@0 1811 }
michael@0 1812 }
michael@0 1813
michael@0 1814 printf("PASS\n");
michael@0 1815 return PR_TRUE;
michael@0 1816 }
michael@0 1817
michael@0 1818 /* PL_strnpbrk */
michael@0 1819 PRBool test_021(void)
michael@0 1820 {
michael@0 1821 static struct
michael@0 1822 {
michael@0 1823 const char *str;
michael@0 1824 const char *chrs;
michael@0 1825 PRUint32 max;
michael@0 1826 PRBool ret;
michael@0 1827 PRUint32 off;
michael@0 1828 } array[] =
michael@0 1829 {
michael@0 1830 { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
michael@0 1831 { (const char *)0, "abc", 3, PR_FALSE, 0 },
michael@0 1832 { "abc", (const char *)0, 3, PR_FALSE, 0 },
michael@0 1833 { "abcdefg", "", 3, PR_FALSE, 0 },
michael@0 1834 { "", "aeiou", 3, PR_FALSE, 0 },
michael@0 1835 { "abcdefg", "ae", 0, PR_FALSE, 0 },
michael@0 1836 { "abcdefg", "ae", 1, PR_TRUE, 0 },
michael@0 1837 { "abcdefg", "ae", 4, PR_TRUE, 0 },
michael@0 1838 { "abcdefg", "ae", 5, PR_TRUE, 0 },
michael@0 1839 { "abcdefg", "ae", 6, PR_TRUE, 0 },
michael@0 1840 { "abcdefg", "ei", 4, PR_FALSE, 0 },
michael@0 1841 { "abcdefg", "io", 10, PR_FALSE, 0 },
michael@0 1842 { "abcdefg", "bcd", 2, PR_TRUE, 1 },
michael@0 1843 { "abcdefg", "cbd", 2, PR_TRUE, 1 },
michael@0 1844 { "abcdefg", "dbc", 2, PR_TRUE, 1 },
michael@0 1845 { "abcdefg", "ghi", 6, PR_FALSE, 0 },
michael@0 1846 { "abcdefg", "ghi", 7, PR_TRUE, 6 },
michael@0 1847 { "abcdefg", "AE", 9, PR_FALSE, 0 },
michael@0 1848 { "abcdefg", "EI", 9, PR_FALSE, 0 },
michael@0 1849 { "abcdefg", "IO", 9, PR_FALSE, 0 },
michael@0 1850 { "abcdefg", "BCD", 9, PR_FALSE, 0 },
michael@0 1851 { "abcdefg", "CBD", 9, PR_FALSE, 0 },
michael@0 1852 { "abcdefg", "DBC", 9, PR_FALSE, 0 },
michael@0 1853 { "abcdefg", "GHI", 9, PR_FALSE, 0 },
michael@0 1854 { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
michael@0 1855 { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
michael@0 1856 { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
michael@0 1857 { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
michael@0 1858 { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
michael@0 1859 { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
michael@0 1860 { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
michael@0 1861 { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
michael@0 1862 { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
michael@0 1863 { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
michael@0 1864 { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
michael@0 1865 { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
michael@0 1866 { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
michael@0 1867 { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
michael@0 1868 };
michael@0 1869
michael@0 1870 int i;
michael@0 1871
michael@0 1872 printf("Test 021 (PL_strnpbrk) ..."); fflush(stdout);
michael@0 1873
michael@0 1874 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1875 {
michael@0 1876 char *rv = PL_strnpbrk(array[i].str, array[i].chrs, array[i].max);
michael@0 1877
michael@0 1878 if( PR_FALSE == array[i].ret )
michael@0 1879 {
michael@0 1880 if( (char *)0 != rv )
michael@0 1881 {
michael@0 1882 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 1883 array[i].str ? array[i].str : "(null)",
michael@0 1884 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1885 array[i].max, rv);
michael@0 1886 return PR_FALSE;
michael@0 1887 }
michael@0 1888 }
michael@0 1889 else
michael@0 1890 {
michael@0 1891 if( (char *)0 == rv )
michael@0 1892 {
michael@0 1893 printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
michael@0 1894 array[i].str ? array[i].str : "(null)",
michael@0 1895 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1896 array[i].max, array[i].off);
michael@0 1897 return PR_FALSE;
michael@0 1898 }
michael@0 1899
michael@0 1900 if( &array[i].str[ array[i].off ] != rv )
michael@0 1901 {
michael@0 1902 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 1903 array[i].str ? array[i].str : "(null)",
michael@0 1904 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1905 array[i].max, rv, array[i].str, array[i].off);
michael@0 1906 return PR_FALSE;
michael@0 1907 }
michael@0 1908 }
michael@0 1909 }
michael@0 1910
michael@0 1911 printf("PASS\n");
michael@0 1912 return PR_TRUE;
michael@0 1913 }
michael@0 1914
michael@0 1915 /* PL_strnprbrk */
michael@0 1916 PRBool test_022(void)
michael@0 1917 {
michael@0 1918 static struct
michael@0 1919 {
michael@0 1920 const char *str;
michael@0 1921 const char *chrs;
michael@0 1922 PRUint32 max;
michael@0 1923 PRBool ret;
michael@0 1924 PRUint32 off;
michael@0 1925 } array[] =
michael@0 1926 {
michael@0 1927 { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
michael@0 1928 { (const char *)0, "abc", 3, PR_FALSE, 0 },
michael@0 1929 { "abc", (const char *)0, 3, PR_FALSE, 0 },
michael@0 1930 { "abcdefg", "", 3, PR_FALSE, 0 },
michael@0 1931 { "", "aeiou", 3, PR_FALSE, 0 },
michael@0 1932 { "abcdefg", "ae", 0, PR_FALSE, 0 },
michael@0 1933 { "abcdefg", "ae", 1, PR_TRUE, 0 },
michael@0 1934 { "abcdefg", "ae", 4, PR_TRUE, 0 },
michael@0 1935 { "abcdefg", "ae", 5, PR_TRUE, 4 },
michael@0 1936 { "abcdefg", "ae", 6, PR_TRUE, 4 },
michael@0 1937 { "abcdefg", "ei", 4, PR_FALSE, 0 },
michael@0 1938 { "abcdefg", "io", 10, PR_FALSE, 0 },
michael@0 1939 { "abcdefg", "bcd", 2, PR_TRUE, 1 },
michael@0 1940 { "abcdefg", "cbd", 2, PR_TRUE, 1 },
michael@0 1941 { "abcdefg", "dbc", 2, PR_TRUE, 1 },
michael@0 1942 { "abcdefg", "bcd", 3, PR_TRUE, 2 },
michael@0 1943 { "abcdefg", "cbd", 3, PR_TRUE, 2 },
michael@0 1944 { "abcdefg", "dbc", 3, PR_TRUE, 2 },
michael@0 1945 { "abcdefg", "bcd", 5, PR_TRUE, 3 },
michael@0 1946 { "abcdefg", "cbd", 5, PR_TRUE, 3 },
michael@0 1947 { "abcdefg", "dbc", 5, PR_TRUE, 3 },
michael@0 1948 { "abcdefg", "bcd", 15, PR_TRUE, 3 },
michael@0 1949 { "abcdefg", "cbd", 15, PR_TRUE, 3 },
michael@0 1950 { "abcdefg", "dbc", 15, PR_TRUE, 3 },
michael@0 1951 { "abcdefg", "ghi", 6, PR_FALSE, 0 },
michael@0 1952 { "abcdefg", "ghi", 7, PR_TRUE, 6 },
michael@0 1953 { "abcdefg", "AE", 9, PR_FALSE, 0 },
michael@0 1954 { "abcdefg", "EI", 9, PR_FALSE, 0 },
michael@0 1955 { "abcdefg", "IO", 9, PR_FALSE, 0 },
michael@0 1956 { "abcdefg", "BCD", 9, PR_FALSE, 0 },
michael@0 1957 { "abcdefg", "CBD", 9, PR_FALSE, 0 },
michael@0 1958 { "abcdefg", "DBC", 9, PR_FALSE, 0 },
michael@0 1959 { "abcdefg", "GHI", 9, PR_FALSE, 0 },
michael@0 1960 { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
michael@0 1961 { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
michael@0 1962 { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
michael@0 1963 { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
michael@0 1964 { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
michael@0 1965 { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
michael@0 1966 { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
michael@0 1967 { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
michael@0 1968 { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
michael@0 1969 { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
michael@0 1970 { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
michael@0 1971 { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
michael@0 1972 { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
michael@0 1973 { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
michael@0 1974 };
michael@0 1975
michael@0 1976 int i;
michael@0 1977
michael@0 1978 printf("Test 022 (PL_strnprbrk) ..."); fflush(stdout);
michael@0 1979
michael@0 1980 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 1981 {
michael@0 1982 char *rv = PL_strnprbrk(array[i].str, array[i].chrs, array[i].max);
michael@0 1983
michael@0 1984 if( PR_FALSE == array[i].ret )
michael@0 1985 {
michael@0 1986 if( (char *)0 != rv )
michael@0 1987 {
michael@0 1988 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 1989 array[i].str ? array[i].str : "(null)",
michael@0 1990 array[i].chrs ? array[i].chrs : "(null)",
michael@0 1991 array[i].max, rv);
michael@0 1992 return PR_FALSE;
michael@0 1993 }
michael@0 1994 }
michael@0 1995 else
michael@0 1996 {
michael@0 1997 if( (char *)0 == rv )
michael@0 1998 {
michael@0 1999 printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
michael@0 2000 array[i].str ? array[i].str : "(null)",
michael@0 2001 array[i].chrs ? array[i].chrs : "(null)",
michael@0 2002 array[i].max, array[i].off);
michael@0 2003 return PR_FALSE;
michael@0 2004 }
michael@0 2005
michael@0 2006 if( &array[i].str[ array[i].off ] != rv )
michael@0 2007 {
michael@0 2008 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2009 array[i].str ? array[i].str : "(null)",
michael@0 2010 array[i].chrs ? array[i].chrs : "(null)",
michael@0 2011 array[i].max, rv, array[i].str, array[i].off);
michael@0 2012 return PR_FALSE;
michael@0 2013 }
michael@0 2014 }
michael@0 2015 }
michael@0 2016
michael@0 2017 printf("PASS\n");
michael@0 2018 return PR_TRUE;
michael@0 2019 }
michael@0 2020
michael@0 2021 /* PL_strstr */
michael@0 2022 PRBool test_023(void)
michael@0 2023 {
michael@0 2024 static struct
michael@0 2025 {
michael@0 2026 const char *str;
michael@0 2027 const char *sub;
michael@0 2028 PRBool ret;
michael@0 2029 PRUint32 off;
michael@0 2030 } array[] =
michael@0 2031 {
michael@0 2032 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 2033 { (const char *)0, "blah", PR_FALSE, 0 },
michael@0 2034 { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
michael@0 2035 { "blah-de-blah", "blah", PR_TRUE, 0 },
michael@0 2036 { "", "blah", PR_FALSE, 0 },
michael@0 2037 { "blah-de-blah", "", PR_FALSE, 0 },
michael@0 2038 { "abcdefg", "a", PR_TRUE, 0 },
michael@0 2039 { "abcdefg", "c", PR_TRUE, 2 },
michael@0 2040 { "abcdefg", "e", PR_TRUE, 4 },
michael@0 2041 { "abcdefg", "g", PR_TRUE, 6 },
michael@0 2042 { "abcdefg", "i", PR_FALSE, 0 },
michael@0 2043 { "abcdefg", "ab", PR_TRUE, 0 },
michael@0 2044 { "abcdefg", "cd", PR_TRUE, 2 },
michael@0 2045 { "abcdefg", "ef", PR_TRUE, 4 },
michael@0 2046 { "abcdefg", "gh", PR_FALSE, 0 },
michael@0 2047 { "abcdabc", "bc", PR_TRUE, 1 },
michael@0 2048 { "abcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2049 { "abcdefgabcdefg", "a", PR_TRUE, 0 },
michael@0 2050 { "abcdefgabcdefg", "c", PR_TRUE, 2 },
michael@0 2051 { "abcdefgabcdefg", "e", PR_TRUE, 4 },
michael@0 2052 { "abcdefgabcdefg", "g", PR_TRUE, 6 },
michael@0 2053 { "abcdefgabcdefg", "i", PR_FALSE, 0 },
michael@0 2054 { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
michael@0 2055 { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
michael@0 2056 { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
michael@0 2057 { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
michael@0 2058 { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
michael@0 2059 { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2060 { "ABCDEFG", "a", PR_FALSE, 0 },
michael@0 2061 { "ABCDEFG", "c", PR_FALSE, 0 },
michael@0 2062 { "ABCDEFG", "e", PR_FALSE, 0 },
michael@0 2063 { "ABCDEFG", "g", PR_FALSE, 0 },
michael@0 2064 { "ABCDEFG", "i", PR_FALSE, 0 },
michael@0 2065 { "ABCDEFG", "ab", PR_FALSE, 0 },
michael@0 2066 { "ABCDEFG", "cd", PR_FALSE, 0 },
michael@0 2067 { "ABCDEFG", "ef", PR_FALSE, 0 },
michael@0 2068 { "ABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2069 { "ABCDABC", "bc", PR_FALSE, 0 },
michael@0 2070 { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
michael@0 2071 { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
michael@0 2072 { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
michael@0 2073 { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
michael@0 2074 { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
michael@0 2075 { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
michael@0 2076 { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
michael@0 2077 { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
michael@0 2078 { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
michael@0 2079 { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2080 { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
michael@0 2081 { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
michael@0 2082 };
michael@0 2083
michael@0 2084 int i;
michael@0 2085
michael@0 2086 printf("Test 023 (PL_strstr) ..."); fflush(stdout);
michael@0 2087
michael@0 2088 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2089 {
michael@0 2090 char *rv = PL_strstr(array[i].str, array[i].sub);
michael@0 2091
michael@0 2092 if( PR_FALSE == array[i].ret )
michael@0 2093 {
michael@0 2094 if( (char *)0 != rv )
michael@0 2095 {
michael@0 2096 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 2097 array[i].str ? array[i].str : "(null)",
michael@0 2098 array[i].sub ? array[i].sub : "(null)",
michael@0 2099 rv);
michael@0 2100 return PR_FALSE;
michael@0 2101 }
michael@0 2102 }
michael@0 2103 else
michael@0 2104 {
michael@0 2105 if( (char *)0 == rv )
michael@0 2106 {
michael@0 2107 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
michael@0 2108 array[i].str ? array[i].str : "(null)",
michael@0 2109 array[i].sub ? array[i].sub : "(null)",
michael@0 2110 array[i].str, array[i].off);
michael@0 2111 return PR_FALSE;
michael@0 2112 }
michael@0 2113
michael@0 2114 if( &array[i].str[ array[i].off ] != rv )
michael@0 2115 {
michael@0 2116 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2117 array[i].str ? array[i].str : "(null)",
michael@0 2118 array[i].sub ? array[i].sub : "(null)",
michael@0 2119 rv, array[i].str, array[i].off);
michael@0 2120 return PR_FALSE;
michael@0 2121 }
michael@0 2122 }
michael@0 2123 }
michael@0 2124
michael@0 2125 printf("PASS\n");
michael@0 2126 return PR_TRUE;
michael@0 2127 }
michael@0 2128
michael@0 2129 /* PL_strrstr */
michael@0 2130 PRBool test_024(void)
michael@0 2131 {
michael@0 2132 static struct
michael@0 2133 {
michael@0 2134 const char *str;
michael@0 2135 const char *sub;
michael@0 2136 PRBool ret;
michael@0 2137 PRUint32 off;
michael@0 2138 } array[] =
michael@0 2139 {
michael@0 2140 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 2141 { (const char *)0, "blah", PR_FALSE, 0 },
michael@0 2142 { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
michael@0 2143 { "blah-de-blah", "blah", PR_TRUE, 8 },
michael@0 2144 { "", "blah", PR_FALSE, 0 },
michael@0 2145 { "blah-de-blah", "", PR_FALSE, 0 },
michael@0 2146 { "abcdefg", "a", PR_TRUE, 0 },
michael@0 2147 { "abcdefg", "c", PR_TRUE, 2 },
michael@0 2148 { "abcdefg", "e", PR_TRUE, 4 },
michael@0 2149 { "abcdefg", "g", PR_TRUE, 6 },
michael@0 2150 { "abcdefg", "i", PR_FALSE, 0 },
michael@0 2151 { "abcdefg", "ab", PR_TRUE, 0 },
michael@0 2152 { "abcdefg", "cd", PR_TRUE, 2 },
michael@0 2153 { "abcdefg", "ef", PR_TRUE, 4 },
michael@0 2154 { "abcdefg", "gh", PR_FALSE, 0 },
michael@0 2155 { "abcdabc", "bc", PR_TRUE, 5 },
michael@0 2156 { "abcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2157 { "abcdefgabcdefg", "a", PR_TRUE, 7 },
michael@0 2158 { "abcdefgabcdefg", "c", PR_TRUE, 9 },
michael@0 2159 { "abcdefgabcdefg", "e", PR_TRUE, 11 },
michael@0 2160 { "abcdefgabcdefg", "g", PR_TRUE, 13 },
michael@0 2161 { "abcdefgabcdefg", "i", PR_FALSE, 0 },
michael@0 2162 { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
michael@0 2163 { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
michael@0 2164 { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
michael@0 2165 { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
michael@0 2166 { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
michael@0 2167 { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
michael@0 2168 { "ABCDEFG", "a", PR_FALSE, 0 },
michael@0 2169 { "ABCDEFG", "c", PR_FALSE, 0 },
michael@0 2170 { "ABCDEFG", "e", PR_FALSE, 0 },
michael@0 2171 { "ABCDEFG", "g", PR_FALSE, 0 },
michael@0 2172 { "ABCDEFG", "i", PR_FALSE, 0 },
michael@0 2173 { "ABCDEFG", "ab", PR_FALSE, 0 },
michael@0 2174 { "ABCDEFG", "cd", PR_FALSE, 0 },
michael@0 2175 { "ABCDEFG", "ef", PR_FALSE, 0 },
michael@0 2176 { "ABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2177 { "ABCDABC", "bc", PR_FALSE, 0 },
michael@0 2178 { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
michael@0 2179 { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
michael@0 2180 { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
michael@0 2181 { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
michael@0 2182 { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
michael@0 2183 { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
michael@0 2184 { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
michael@0 2185 { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
michael@0 2186 { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
michael@0 2187 { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2188 { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
michael@0 2189 { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
michael@0 2190 };
michael@0 2191
michael@0 2192 int i;
michael@0 2193
michael@0 2194 printf("Test 024 (PL_strrstr) ..."); fflush(stdout);
michael@0 2195
michael@0 2196 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2197 {
michael@0 2198 char *rv = PL_strrstr(array[i].str, array[i].sub);
michael@0 2199
michael@0 2200 if( PR_FALSE == array[i].ret )
michael@0 2201 {
michael@0 2202 if( (char *)0 != rv )
michael@0 2203 {
michael@0 2204 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 2205 array[i].str ? array[i].str : "(null)",
michael@0 2206 array[i].sub ? array[i].sub : "(null)",
michael@0 2207 rv);
michael@0 2208 return PR_FALSE;
michael@0 2209 }
michael@0 2210 }
michael@0 2211 else
michael@0 2212 {
michael@0 2213 if( (char *)0 == rv )
michael@0 2214 {
michael@0 2215 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
michael@0 2216 array[i].str ? array[i].str : "(null)",
michael@0 2217 array[i].sub ? array[i].sub : "(null)",
michael@0 2218 array[i].str, array[i].off);
michael@0 2219 return PR_FALSE;
michael@0 2220 }
michael@0 2221
michael@0 2222 if( &array[i].str[ array[i].off ] != rv )
michael@0 2223 {
michael@0 2224 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2225 array[i].str ? array[i].str : "(null)",
michael@0 2226 array[i].sub ? array[i].sub : "(null)",
michael@0 2227 rv, array[i].str, array[i].off);
michael@0 2228 return PR_FALSE;
michael@0 2229 }
michael@0 2230 }
michael@0 2231 }
michael@0 2232
michael@0 2233 printf("PASS\n");
michael@0 2234 return PR_TRUE;
michael@0 2235 }
michael@0 2236
michael@0 2237 /* PL_strnstr */
michael@0 2238 PRBool test_025(void)
michael@0 2239 {
michael@0 2240 static struct
michael@0 2241 {
michael@0 2242 const char *str;
michael@0 2243 const char *sub;
michael@0 2244 PRUint32 max;
michael@0 2245 PRBool ret;
michael@0 2246 PRUint32 off;
michael@0 2247 } array[] =
michael@0 2248 {
michael@0 2249 { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
michael@0 2250 { (const char *)0, "blah", 12, PR_FALSE, 0 },
michael@0 2251 { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
michael@0 2252 { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
michael@0 2253 { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
michael@0 2254 { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
michael@0 2255 { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
michael@0 2256 { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
michael@0 2257 { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
michael@0 2258 { "", "blah", 12, PR_FALSE, 0 },
michael@0 2259 { "blah-de-blah", "", 12, PR_FALSE, 0 },
michael@0 2260 { "abcdefg", "a", 5, PR_TRUE, 0 },
michael@0 2261 { "abcdefg", "c", 5, PR_TRUE, 2 },
michael@0 2262 { "abcdefg", "e", 5, PR_TRUE, 4 },
michael@0 2263 { "abcdefg", "g", 5, PR_FALSE, 0 },
michael@0 2264 { "abcdefg", "i", 5, PR_FALSE, 0 },
michael@0 2265 { "abcdefg", "ab", 5, PR_TRUE, 0 },
michael@0 2266 { "abcdefg", "cd", 5, PR_TRUE, 2 },
michael@0 2267 { "abcdefg", "ef", 5, PR_FALSE, 0 },
michael@0 2268 { "abcdefg", "gh", 5, PR_FALSE, 0 },
michael@0 2269 { "abcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2270 { "abcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2271 { "abcdabc", "bc", 7, PR_TRUE, 1 },
michael@0 2272 { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2273 { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2274 { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2275 { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
michael@0 2276 { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
michael@0 2277 { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
michael@0 2278 { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
michael@0 2279 { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
michael@0 2280 { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
michael@0 2281 { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
michael@0 2282 { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
michael@0 2283 { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
michael@0 2284 { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2285 { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2286 { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
michael@0 2287 { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2288 { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2289 { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2290 { "ABCDEFG", "a", 5, PR_FALSE, 0 },
michael@0 2291 { "ABCDEFG", "c", 5, PR_FALSE, 0 },
michael@0 2292 { "ABCDEFG", "e", 5, PR_FALSE, 0 },
michael@0 2293 { "ABCDEFG", "g", 5, PR_FALSE, 0 },
michael@0 2294 { "ABCDEFG", "i", 5, PR_FALSE, 0 },
michael@0 2295 { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
michael@0 2296 { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
michael@0 2297 { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
michael@0 2298 { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
michael@0 2299 { "ABCDABC", "bc", 5, PR_FALSE, 0 },
michael@0 2300 { "ABCDABC", "bc", 6, PR_FALSE, 0 },
michael@0 2301 { "ABCDABC", "bc", 7, PR_FALSE, 0 },
michael@0 2302 { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2303 { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
michael@0 2304 { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
michael@0 2305 { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
michael@0 2306 { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
michael@0 2307 { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
michael@0 2308 { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
michael@0 2309 { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
michael@0 2310 { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
michael@0 2311 { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
michael@0 2312 { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
michael@0 2313 { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
michael@0 2314 { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
michael@0 2315 { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
michael@0 2316 { "ABCDABCABCDABC", "bc", 7, PR_FALSE, },
michael@0 2317 { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2318 { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
michael@0 2319 { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
michael@0 2320 };
michael@0 2321
michael@0 2322 int i;
michael@0 2323
michael@0 2324 printf("Test 025 (PL_strnstr) ..."); fflush(stdout);
michael@0 2325
michael@0 2326 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2327 {
michael@0 2328 char *rv = PL_strnstr(array[i].str, array[i].sub, array[i].max);
michael@0 2329
michael@0 2330 if( PR_FALSE == array[i].ret )
michael@0 2331 {
michael@0 2332 if( (char *)0 != rv )
michael@0 2333 {
michael@0 2334 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 2335 array[i].str ? array[i].str : "(null)",
michael@0 2336 array[i].sub ? array[i].sub : "(null)",
michael@0 2337 array[i].max, rv);
michael@0 2338 return PR_FALSE;
michael@0 2339 }
michael@0 2340 }
michael@0 2341 else
michael@0 2342 {
michael@0 2343 if( (char *)0 == rv )
michael@0 2344 {
michael@0 2345 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
michael@0 2346 array[i].str ? array[i].str : "(null)",
michael@0 2347 array[i].sub ? array[i].sub : "(null)",
michael@0 2348 array[i].max, array[i].str, array[i].off);
michael@0 2349 return PR_FALSE;
michael@0 2350 }
michael@0 2351
michael@0 2352 if( &array[i].str[ array[i].off ] != rv )
michael@0 2353 {
michael@0 2354 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2355 array[i].str ? array[i].str : "(null)",
michael@0 2356 array[i].sub ? array[i].sub : "(null)",
michael@0 2357 array[i].max, rv, array[i].str, array[i].off);
michael@0 2358 return PR_FALSE;
michael@0 2359 }
michael@0 2360 }
michael@0 2361 }
michael@0 2362
michael@0 2363 printf("PASS\n");
michael@0 2364 return PR_TRUE;
michael@0 2365 }
michael@0 2366
michael@0 2367 /* PL_strnrstr */
michael@0 2368 PRBool test_026(void)
michael@0 2369 {
michael@0 2370 static struct
michael@0 2371 {
michael@0 2372 const char *str;
michael@0 2373 const char *sub;
michael@0 2374 PRUint32 max;
michael@0 2375 PRBool ret;
michael@0 2376 PRUint32 off;
michael@0 2377 } array[] =
michael@0 2378 {
michael@0 2379 { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
michael@0 2380 { (const char *)0, "blah", 12, PR_FALSE, 0 },
michael@0 2381 { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
michael@0 2382 { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
michael@0 2383 { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
michael@0 2384 { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
michael@0 2385 { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
michael@0 2386 { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
michael@0 2387 { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
michael@0 2388 { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
michael@0 2389 { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
michael@0 2390 { "", "blah", 12, PR_FALSE, 0 },
michael@0 2391 { "blah-de-blah", "", 12, PR_FALSE, 0 },
michael@0 2392 { "abcdefg", "a", 5, PR_TRUE, 0 },
michael@0 2393 { "abcdefg", "c", 5, PR_TRUE, 2 },
michael@0 2394 { "abcdefg", "e", 5, PR_TRUE, 4 },
michael@0 2395 { "abcdefg", "g", 5, PR_FALSE, 0 },
michael@0 2396 { "abcdefg", "i", 5, PR_FALSE, 0 },
michael@0 2397 { "abcdefg", "ab", 5, PR_TRUE, 0 },
michael@0 2398 { "abcdefg", "cd", 5, PR_TRUE, 2 },
michael@0 2399 { "abcdefg", "ef", 5, PR_FALSE, 0 },
michael@0 2400 { "abcdefg", "gh", 5, PR_FALSE, 0 },
michael@0 2401 { "abcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2402 { "abcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2403 { "abcdabc", "bc", 7, PR_TRUE, 5 },
michael@0 2404 { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2405 { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2406 { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2407 { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
michael@0 2408 { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
michael@0 2409 { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
michael@0 2410 { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
michael@0 2411 { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
michael@0 2412 { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
michael@0 2413 { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
michael@0 2414 { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
michael@0 2415 { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
michael@0 2416 { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
michael@0 2417 { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
michael@0 2418 { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
michael@0 2419 { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
michael@0 2420 { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
michael@0 2421 { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
michael@0 2422 { "ABCDEFG", "a", 5, PR_FALSE, 0 },
michael@0 2423 { "ABCDEFG", "c", 5, PR_FALSE, 0 },
michael@0 2424 { "ABCDEFG", "e", 5, PR_FALSE, 0 },
michael@0 2425 { "ABCDEFG", "g", 5, PR_FALSE, 0 },
michael@0 2426 { "ABCDEFG", "i", 5, PR_FALSE, 0 },
michael@0 2427 { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
michael@0 2428 { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
michael@0 2429 { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
michael@0 2430 { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
michael@0 2431 { "ABCDABC", "bc", 5, PR_FALSE, 0 },
michael@0 2432 { "ABCDABC", "bc", 6, PR_FALSE, 0 },
michael@0 2433 { "ABCDABC", "bc", 7, PR_FALSE, 0 },
michael@0 2434 { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2435 { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
michael@0 2436 { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
michael@0 2437 { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
michael@0 2438 { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
michael@0 2439 { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
michael@0 2440 { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
michael@0 2441 { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
michael@0 2442 { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
michael@0 2443 { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
michael@0 2444 { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
michael@0 2445 { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
michael@0 2446 { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
michael@0 2447 { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
michael@0 2448 { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
michael@0 2449 { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
michael@0 2450 { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
michael@0 2451 { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
michael@0 2452 };
michael@0 2453
michael@0 2454 int i;
michael@0 2455
michael@0 2456 printf("Test 026 (PL_strnrstr) ..."); fflush(stdout);
michael@0 2457
michael@0 2458 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2459 {
michael@0 2460 char *rv = PL_strnrstr(array[i].str, array[i].sub, array[i].max);
michael@0 2461
michael@0 2462 if( PR_FALSE == array[i].ret )
michael@0 2463 {
michael@0 2464 if( (char *)0 != rv )
michael@0 2465 {
michael@0 2466 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 2467 array[i].str ? array[i].str : "(null)",
michael@0 2468 array[i].sub ? array[i].sub : "(null)",
michael@0 2469 array[i].max, rv);
michael@0 2470 return PR_FALSE;
michael@0 2471 }
michael@0 2472 }
michael@0 2473 else
michael@0 2474 {
michael@0 2475 if( (char *)0 == rv )
michael@0 2476 {
michael@0 2477 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
michael@0 2478 array[i].str ? array[i].str : "(null)",
michael@0 2479 array[i].sub ? array[i].sub : "(null)",
michael@0 2480 array[i].max, array[i].str, array[i].off);
michael@0 2481 return PR_FALSE;
michael@0 2482 }
michael@0 2483
michael@0 2484 if( &array[i].str[ array[i].off ] != rv )
michael@0 2485 {
michael@0 2486 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2487 array[i].str ? array[i].str : "(null)",
michael@0 2488 array[i].sub ? array[i].sub : "(null)",
michael@0 2489 array[i].max, rv, array[i].str, array[i].off);
michael@0 2490 return PR_FALSE;
michael@0 2491 }
michael@0 2492 }
michael@0 2493 }
michael@0 2494
michael@0 2495 printf("PASS\n");
michael@0 2496 return PR_TRUE;
michael@0 2497 }
michael@0 2498
michael@0 2499 /* PL_strcasestr */
michael@0 2500 PRBool test_027(void)
michael@0 2501 {
michael@0 2502 static struct
michael@0 2503 {
michael@0 2504 const char *str;
michael@0 2505 const char *sub;
michael@0 2506 PRBool ret;
michael@0 2507 PRUint32 off;
michael@0 2508 } array[] =
michael@0 2509 {
michael@0 2510 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 2511 { (const char *)0, "blah", PR_FALSE, 0 },
michael@0 2512 { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
michael@0 2513 { "blah-de-blah", "blah", PR_TRUE, 0 },
michael@0 2514 { "", "blah", PR_FALSE, 0 },
michael@0 2515 { "blah-de-blah", "", PR_FALSE, 0 },
michael@0 2516 { "abcdefg", "a", PR_TRUE, 0 },
michael@0 2517 { "abcdefg", "c", PR_TRUE, 2 },
michael@0 2518 { "abcdefg", "e", PR_TRUE, 4 },
michael@0 2519 { "abcdefg", "g", PR_TRUE, 6 },
michael@0 2520 { "abcdefg", "i", PR_FALSE, 0 },
michael@0 2521 { "abcdefg", "ab", PR_TRUE, 0 },
michael@0 2522 { "abcdefg", "cd", PR_TRUE, 2 },
michael@0 2523 { "abcdefg", "ef", PR_TRUE, 4 },
michael@0 2524 { "abcdefg", "gh", PR_FALSE, 0 },
michael@0 2525 { "abcdabc", "bc", PR_TRUE, 1 },
michael@0 2526 { "abcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2527 { "abcdefgabcdefg", "a", PR_TRUE, 0 },
michael@0 2528 { "abcdefgabcdefg", "c", PR_TRUE, 2 },
michael@0 2529 { "abcdefgabcdefg", "e", PR_TRUE, 4 },
michael@0 2530 { "abcdefgabcdefg", "g", PR_TRUE, 6 },
michael@0 2531 { "abcdefgabcdefg", "i", PR_FALSE, 0 },
michael@0 2532 { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
michael@0 2533 { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
michael@0 2534 { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
michael@0 2535 { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
michael@0 2536 { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
michael@0 2537 { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2538 { "ABCDEFG", "a", PR_TRUE, 0 },
michael@0 2539 { "ABCDEFG", "c", PR_TRUE, 2 },
michael@0 2540 { "ABCDEFG", "e", PR_TRUE, 4 },
michael@0 2541 { "ABCDEFG", "g", PR_TRUE, 6 },
michael@0 2542 { "ABCDEFG", "i", PR_FALSE, 0 },
michael@0 2543 { "ABCDEFG", "ab", PR_TRUE, 0 },
michael@0 2544 { "ABCDEFG", "cd", PR_TRUE, 2 },
michael@0 2545 { "ABCDEFG", "ef", PR_TRUE, 4 },
michael@0 2546 { "ABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2547 { "ABCDABC", "bc", PR_TRUE, 1 },
michael@0 2548 { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
michael@0 2549 { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
michael@0 2550 { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
michael@0 2551 { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
michael@0 2552 { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
michael@0 2553 { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
michael@0 2554 { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
michael@0 2555 { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
michael@0 2556 { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
michael@0 2557 { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2558 { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
michael@0 2559 { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
michael@0 2560 };
michael@0 2561
michael@0 2562 int i;
michael@0 2563
michael@0 2564 printf("Test 027 (PL_strcasestr) ..."); fflush(stdout);
michael@0 2565
michael@0 2566 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2567 {
michael@0 2568 char *rv = PL_strcasestr(array[i].str, array[i].sub);
michael@0 2569
michael@0 2570 if( PR_FALSE == array[i].ret )
michael@0 2571 {
michael@0 2572 if( (char *)0 != rv )
michael@0 2573 {
michael@0 2574 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 2575 array[i].str ? array[i].str : "(null)",
michael@0 2576 array[i].sub ? array[i].sub : "(null)",
michael@0 2577 rv);
michael@0 2578 return PR_FALSE;
michael@0 2579 }
michael@0 2580 }
michael@0 2581 else
michael@0 2582 {
michael@0 2583 if( (char *)0 == rv )
michael@0 2584 {
michael@0 2585 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
michael@0 2586 array[i].str ? array[i].str : "(null)",
michael@0 2587 array[i].sub ? array[i].sub : "(null)",
michael@0 2588 array[i].str, array[i].off);
michael@0 2589 return PR_FALSE;
michael@0 2590 }
michael@0 2591
michael@0 2592 if( &array[i].str[ array[i].off ] != rv )
michael@0 2593 {
michael@0 2594 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2595 array[i].str ? array[i].str : "(null)",
michael@0 2596 array[i].sub ? array[i].sub : "(null)",
michael@0 2597 rv, array[i].str, array[i].off);
michael@0 2598 return PR_FALSE;
michael@0 2599 }
michael@0 2600 }
michael@0 2601 }
michael@0 2602
michael@0 2603 printf("PASS\n");
michael@0 2604 return PR_TRUE;
michael@0 2605 }
michael@0 2606
michael@0 2607 /* PL_strcaserstr */
michael@0 2608 PRBool test_028(void)
michael@0 2609 {
michael@0 2610 static struct
michael@0 2611 {
michael@0 2612 const char *str;
michael@0 2613 const char *sub;
michael@0 2614 PRBool ret;
michael@0 2615 PRUint32 off;
michael@0 2616 } array[] =
michael@0 2617 {
michael@0 2618 { (const char *)0, (const char *)0, PR_FALSE, 0 },
michael@0 2619 { (const char *)0, "blah", PR_FALSE, 0 },
michael@0 2620 { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
michael@0 2621 { "blah-de-blah", "blah", PR_TRUE, 8 },
michael@0 2622 { "", "blah", PR_FALSE, 0 },
michael@0 2623 { "blah-de-blah", "", PR_FALSE, 0 },
michael@0 2624 { "abcdefg", "a", PR_TRUE, 0 },
michael@0 2625 { "abcdefg", "c", PR_TRUE, 2 },
michael@0 2626 { "abcdefg", "e", PR_TRUE, 4 },
michael@0 2627 { "abcdefg", "g", PR_TRUE, 6 },
michael@0 2628 { "abcdefg", "i", PR_FALSE, 0 },
michael@0 2629 { "abcdefg", "ab", PR_TRUE, 0 },
michael@0 2630 { "abcdefg", "cd", PR_TRUE, 2 },
michael@0 2631 { "abcdefg", "ef", PR_TRUE, 4 },
michael@0 2632 { "abcdefg", "gh", PR_FALSE, 0 },
michael@0 2633 { "abcdabc", "bc", PR_TRUE, 5 },
michael@0 2634 { "abcdefg", "abcdefg", PR_TRUE, 0 },
michael@0 2635 { "abcdefgabcdefg", "a", PR_TRUE, 7 },
michael@0 2636 { "abcdefgabcdefg", "c", PR_TRUE, 9 },
michael@0 2637 { "abcdefgabcdefg", "e", PR_TRUE, 11 },
michael@0 2638 { "abcdefgabcdefg", "g", PR_TRUE, 13 },
michael@0 2639 { "abcdefgabcdefg", "i", PR_FALSE, 0 },
michael@0 2640 { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
michael@0 2641 { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
michael@0 2642 { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
michael@0 2643 { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
michael@0 2644 { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
michael@0 2645 { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
michael@0 2646 { "ABCDEFG", "a", PR_TRUE, 0 },
michael@0 2647 { "ABCDEFG", "c", PR_TRUE, 2 },
michael@0 2648 { "ABCDEFG", "e", PR_TRUE, 4 },
michael@0 2649 { "ABCDEFG", "g", PR_TRUE, 6 },
michael@0 2650 { "ABCDEFG", "i", PR_FALSE, 0 },
michael@0 2651 { "ABCDEFG", "ab", PR_TRUE, 0 },
michael@0 2652 { "ABCDEFG", "cd", PR_TRUE, 2 },
michael@0 2653 { "ABCDEFG", "ef", PR_TRUE, 4 },
michael@0 2654 { "ABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2655 { "ABCDABC", "bc", PR_TRUE, 5 },
michael@0 2656 { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
michael@0 2657 { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
michael@0 2658 { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
michael@0 2659 { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
michael@0 2660 { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
michael@0 2661 { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
michael@0 2662 { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
michael@0 2663 { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
michael@0 2664 { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
michael@0 2665 { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
michael@0 2666 { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
michael@0 2667 { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
michael@0 2668 };
michael@0 2669
michael@0 2670 int i;
michael@0 2671
michael@0 2672 printf("Test 028 (PL_strcaserstr) ..."); fflush(stdout);
michael@0 2673
michael@0 2674 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2675 {
michael@0 2676 char *rv = PL_strcaserstr(array[i].str, array[i].sub);
michael@0 2677
michael@0 2678 if( PR_FALSE == array[i].ret )
michael@0 2679 {
michael@0 2680 if( (char *)0 != rv )
michael@0 2681 {
michael@0 2682 printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
michael@0 2683 array[i].str ? array[i].str : "(null)",
michael@0 2684 array[i].sub ? array[i].sub : "(null)",
michael@0 2685 rv);
michael@0 2686 return PR_FALSE;
michael@0 2687 }
michael@0 2688 }
michael@0 2689 else
michael@0 2690 {
michael@0 2691 if( (char *)0 == rv )
michael@0 2692 {
michael@0 2693 printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
michael@0 2694 array[i].str ? array[i].str : "(null)",
michael@0 2695 array[i].sub ? array[i].sub : "(null)",
michael@0 2696 array[i].str, array[i].off);
michael@0 2697 return PR_FALSE;
michael@0 2698 }
michael@0 2699
michael@0 2700 if( &array[i].str[ array[i].off ] != rv )
michael@0 2701 {
michael@0 2702 printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2703 array[i].str ? array[i].str : "(null)",
michael@0 2704 array[i].sub ? array[i].sub : "(null)",
michael@0 2705 rv, array[i].str, array[i].off);
michael@0 2706 return PR_FALSE;
michael@0 2707 }
michael@0 2708 }
michael@0 2709 }
michael@0 2710
michael@0 2711 printf("PASS\n");
michael@0 2712 return PR_TRUE;
michael@0 2713 }
michael@0 2714
michael@0 2715 /* PL_strncasestr */
michael@0 2716 PRBool test_029(void)
michael@0 2717 {
michael@0 2718 static struct
michael@0 2719 {
michael@0 2720 const char *str;
michael@0 2721 const char *sub;
michael@0 2722 PRUint32 max;
michael@0 2723 PRBool ret;
michael@0 2724 PRUint32 off;
michael@0 2725 } array[] =
michael@0 2726 {
michael@0 2727 { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
michael@0 2728 { (const char *)0, "blah", 12, PR_FALSE, 0 },
michael@0 2729 { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
michael@0 2730 { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
michael@0 2731 { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
michael@0 2732 { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
michael@0 2733 { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
michael@0 2734 { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
michael@0 2735 { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
michael@0 2736 { "", "blah", 12, PR_FALSE, 0 },
michael@0 2737 { "blah-de-blah", "", 12, PR_FALSE, 0 },
michael@0 2738 { "abcdefg", "a", 5, PR_TRUE, 0 },
michael@0 2739 { "abcdefg", "c", 5, PR_TRUE, 2 },
michael@0 2740 { "abcdefg", "e", 5, PR_TRUE, 4 },
michael@0 2741 { "abcdefg", "g", 5, PR_FALSE, 0 },
michael@0 2742 { "abcdefg", "i", 5, PR_FALSE, 0 },
michael@0 2743 { "abcdefg", "ab", 5, PR_TRUE, 0 },
michael@0 2744 { "abcdefg", "cd", 5, PR_TRUE, 2 },
michael@0 2745 { "abcdefg", "ef", 5, PR_FALSE, 0 },
michael@0 2746 { "abcdefg", "gh", 5, PR_FALSE, 0 },
michael@0 2747 { "abcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2748 { "abcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2749 { "abcdabc", "bc", 7, PR_TRUE, 1 },
michael@0 2750 { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2751 { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2752 { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2753 { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
michael@0 2754 { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
michael@0 2755 { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
michael@0 2756 { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
michael@0 2757 { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
michael@0 2758 { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
michael@0 2759 { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
michael@0 2760 { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
michael@0 2761 { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
michael@0 2762 { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2763 { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2764 { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
michael@0 2765 { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2766 { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2767 { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2768 { "ABCDEFG", "a", 5, PR_TRUE, 0 },
michael@0 2769 { "ABCDEFG", "c", 5, PR_TRUE, 2 },
michael@0 2770 { "ABCDEFG", "e", 5, PR_TRUE, 4 },
michael@0 2771 { "ABCDEFG", "g", 5, PR_FALSE, 0 },
michael@0 2772 { "ABCDEFG", "i", 5, PR_FALSE, 0 },
michael@0 2773 { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
michael@0 2774 { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
michael@0 2775 { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
michael@0 2776 { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
michael@0 2777 { "ABCDABC", "bc", 5, PR_TRUE, 1 },
michael@0 2778 { "ABCDABC", "bc", 6, PR_TRUE, 1 },
michael@0 2779 { "ABCDABC", "bc", 7, PR_TRUE, 1 },
michael@0 2780 { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2781 { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2782 { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2783 { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
michael@0 2784 { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
michael@0 2785 { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
michael@0 2786 { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
michael@0 2787 { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
michael@0 2788 { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
michael@0 2789 { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
michael@0 2790 { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
michael@0 2791 { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
michael@0 2792 { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
michael@0 2793 { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
michael@0 2794 { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
michael@0 2795 { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2796 { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2797 { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
michael@0 2798 };
michael@0 2799
michael@0 2800 int i;
michael@0 2801
michael@0 2802 printf("Test 029 (PL_strncasestr) ..."); fflush(stdout);
michael@0 2803
michael@0 2804 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2805 {
michael@0 2806 char *rv = PL_strncasestr(array[i].str, array[i].sub, array[i].max);
michael@0 2807
michael@0 2808 if( PR_FALSE == array[i].ret )
michael@0 2809 {
michael@0 2810 if( (char *)0 != rv )
michael@0 2811 {
michael@0 2812 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 2813 array[i].str ? array[i].str : "(null)",
michael@0 2814 array[i].sub ? array[i].sub : "(null)",
michael@0 2815 array[i].max, rv);
michael@0 2816 return PR_FALSE;
michael@0 2817 }
michael@0 2818 }
michael@0 2819 else
michael@0 2820 {
michael@0 2821 if( (char *)0 == rv )
michael@0 2822 {
michael@0 2823 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
michael@0 2824 array[i].str ? array[i].str : "(null)",
michael@0 2825 array[i].sub ? array[i].sub : "(null)",
michael@0 2826 array[i].max, array[i].str, array[i].off);
michael@0 2827 return PR_FALSE;
michael@0 2828 }
michael@0 2829
michael@0 2830 if( &array[i].str[ array[i].off ] != rv )
michael@0 2831 {
michael@0 2832 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2833 array[i].str ? array[i].str : "(null)",
michael@0 2834 array[i].sub ? array[i].sub : "(null)",
michael@0 2835 array[i].max, rv, array[i].str, array[i].off);
michael@0 2836 return PR_FALSE;
michael@0 2837 }
michael@0 2838 }
michael@0 2839 }
michael@0 2840
michael@0 2841 printf("PASS\n");
michael@0 2842 return PR_TRUE;
michael@0 2843 }
michael@0 2844
michael@0 2845 /* PL_strncaserstr */
michael@0 2846 PRBool test_030(void)
michael@0 2847 {
michael@0 2848 static struct
michael@0 2849 {
michael@0 2850 const char *str;
michael@0 2851 const char *sub;
michael@0 2852 PRUint32 max;
michael@0 2853 PRBool ret;
michael@0 2854 PRUint32 off;
michael@0 2855 } array[] =
michael@0 2856 {
michael@0 2857 { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
michael@0 2858 { (const char *)0, "blah", 12, PR_FALSE, 0 },
michael@0 2859 { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
michael@0 2860 { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
michael@0 2861 { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
michael@0 2862 { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
michael@0 2863 { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
michael@0 2864 { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
michael@0 2865 { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
michael@0 2866 { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
michael@0 2867 { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
michael@0 2868 { "", "blah", 12, PR_FALSE, 0 },
michael@0 2869 { "blah-de-blah", "", 12, PR_FALSE, 0 },
michael@0 2870 { "abcdefg", "a", 5, PR_TRUE, 0 },
michael@0 2871 { "abcdefg", "c", 5, PR_TRUE, 2 },
michael@0 2872 { "abcdefg", "e", 5, PR_TRUE, 4 },
michael@0 2873 { "abcdefg", "g", 5, PR_FALSE, 0 },
michael@0 2874 { "abcdefg", "i", 5, PR_FALSE, 0 },
michael@0 2875 { "abcdefg", "ab", 5, PR_TRUE, 0 },
michael@0 2876 { "abcdefg", "cd", 5, PR_TRUE, 2 },
michael@0 2877 { "abcdefg", "ef", 5, PR_FALSE, 0 },
michael@0 2878 { "abcdefg", "gh", 5, PR_FALSE, 0 },
michael@0 2879 { "abcdabc", "bc", 5, PR_TRUE, 1 },
michael@0 2880 { "abcdabc", "bc", 6, PR_TRUE, 1 },
michael@0 2881 { "abcdabc", "bc", 7, PR_TRUE, 5 },
michael@0 2882 { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2883 { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2884 { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2885 { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
michael@0 2886 { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
michael@0 2887 { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
michael@0 2888 { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
michael@0 2889 { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
michael@0 2890 { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
michael@0 2891 { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
michael@0 2892 { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
michael@0 2893 { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
michael@0 2894 { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
michael@0 2895 { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
michael@0 2896 { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
michael@0 2897 { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
michael@0 2898 { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
michael@0 2899 { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
michael@0 2900 { "ABCDEFG", "a", 5, PR_TRUE, 0 },
michael@0 2901 { "ABCDEFG", "c", 5, PR_TRUE, 2 },
michael@0 2902 { "ABCDEFG", "e", 5, PR_TRUE, 4 },
michael@0 2903 { "ABCDEFG", "g", 5, PR_FALSE, 0 },
michael@0 2904 { "ABCDEFG", "i", 5, PR_FALSE, 0 },
michael@0 2905 { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
michael@0 2906 { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
michael@0 2907 { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
michael@0 2908 { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
michael@0 2909 { "ABCDABC", "bc", 5, PR_TRUE, 1 },
michael@0 2910 { "ABCDABC", "bc", 6, PR_TRUE, 1 },
michael@0 2911 { "ABCDABC", "bc", 7, PR_TRUE, 5 },
michael@0 2912 { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
michael@0 2913 { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
michael@0 2914 { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
michael@0 2915 { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
michael@0 2916 { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
michael@0 2917 { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
michael@0 2918 { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
michael@0 2919 { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
michael@0 2920 { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
michael@0 2921 { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
michael@0 2922 { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
michael@0 2923 { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
michael@0 2924 { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
michael@0 2925 { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
michael@0 2926 { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
michael@0 2927 { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
michael@0 2928 { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
michael@0 2929 { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
michael@0 2930 };
michael@0 2931
michael@0 2932 int i;
michael@0 2933
michael@0 2934 printf("Test 030 (PL_strncaserstr)..."); fflush(stdout);
michael@0 2935
michael@0 2936 for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
michael@0 2937 {
michael@0 2938 char *rv = PL_strncaserstr(array[i].str, array[i].sub, array[i].max);
michael@0 2939
michael@0 2940 if( PR_FALSE == array[i].ret )
michael@0 2941 {
michael@0 2942 if( (char *)0 != rv )
michael@0 2943 {
michael@0 2944 printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
michael@0 2945 array[i].str ? array[i].str : "(null)",
michael@0 2946 array[i].sub ? array[i].sub : "(null)",
michael@0 2947 array[i].max, rv);
michael@0 2948 return PR_FALSE;
michael@0 2949 }
michael@0 2950 }
michael@0 2951 else
michael@0 2952 {
michael@0 2953 if( (char *)0 == rv )
michael@0 2954 {
michael@0 2955 printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
michael@0 2956 array[i].str ? array[i].str : "(null)",
michael@0 2957 array[i].sub ? array[i].sub : "(null)",
michael@0 2958 array[i].max, array[i].str, array[i].off);
michael@0 2959 return PR_FALSE;
michael@0 2960 }
michael@0 2961
michael@0 2962 if( &array[i].str[ array[i].off ] != rv )
michael@0 2963 {
michael@0 2964 printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
michael@0 2965 array[i].str ? array[i].str : "(null)",
michael@0 2966 array[i].sub ? array[i].sub : "(null)",
michael@0 2967 array[i].max, rv, array[i].str, array[i].off);
michael@0 2968 return PR_FALSE;
michael@0 2969 }
michael@0 2970 }
michael@0 2971 }
michael@0 2972
michael@0 2973 printf("PASS\n");
michael@0 2974 return PR_TRUE;
michael@0 2975 }
michael@0 2976
michael@0 2977 /* PL_strtok_r */
michael@0 2978 PRBool test_031(void)
michael@0 2979 {
michael@0 2980 static const char *tokens[] = {
michael@0 2981 "wtc", "relyea", "nelsonb", "jpierre", "nicolson",
michael@0 2982 "ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein"
michael@0 2983 };
michael@0 2984
michael@0 2985 static const char *seps[] = {
michael@0 2986 ", ", ",", " ", "\t", ",,,", " ,", " ", " \t\t", ","
michael@0 2987 };
michael@0 2988
michael@0 2989 static const char s2[] = ", \t";
michael@0 2990
michael@0 2991 char string[ 1024 ];
michael@0 2992 char *s1;
michael@0 2993 char *token;
michael@0 2994 char *lasts;
michael@0 2995 unsigned int i;
michael@0 2996
michael@0 2997 printf("Test 031 (PL_strtok_r) ..."); fflush(stdout);
michael@0 2998
michael@0 2999 /* Build the string. */
michael@0 3000 string[0] = '\0';
michael@0 3001 for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ )
michael@0 3002 {
michael@0 3003 PL_strcat(string, tokens[i]);
michael@0 3004 PL_strcat(string, seps[i]);
michael@0 3005 }
michael@0 3006
michael@0 3007 /* Scan the string for tokens. */
michael@0 3008 i = 0;
michael@0 3009 s1 = string;
michael@0 3010 while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL)
michael@0 3011 {
michael@0 3012 if( PL_strcmp(token, tokens[i]) != 0 )
michael@0 3013 {
michael@0 3014 printf("FAIL wrong token scanned\n");
michael@0 3015 return PR_FALSE;
michael@0 3016 }
michael@0 3017 i++;
michael@0 3018 s1 = NULL;
michael@0 3019 }
michael@0 3020 if( i != sizeof(tokens)/sizeof(tokens[0]) )
michael@0 3021 {
michael@0 3022 printf("FAIL wrong number of tokens scanned\n");
michael@0 3023 return PR_FALSE;
michael@0 3024 }
michael@0 3025
michael@0 3026 printf("PASS\n");
michael@0 3027 return PR_TRUE;
michael@0 3028 }
michael@0 3029
michael@0 3030 int
michael@0 3031 main
michael@0 3032 (
michael@0 3033 int argc,
michael@0 3034 char *argv[]
michael@0 3035 )
michael@0 3036 {
michael@0 3037 printf("Testing the Portable Library string functions:\n");
michael@0 3038
michael@0 3039 if( 1
michael@0 3040 && test_001()
michael@0 3041 && test_001()
michael@0 3042 && test_002()
michael@0 3043 && test_003()
michael@0 3044 && test_004()
michael@0 3045 && test_005()
michael@0 3046 && test_006()
michael@0 3047 && test_007()
michael@0 3048 && test_008()
michael@0 3049 && test_009()
michael@0 3050 && test_010()
michael@0 3051 && test_011()
michael@0 3052 && test_012()
michael@0 3053 && test_013()
michael@0 3054 && test_014()
michael@0 3055 && test_015()
michael@0 3056 && test_016()
michael@0 3057 && test_017()
michael@0 3058 && test_018()
michael@0 3059 && test_019()
michael@0 3060 && test_020()
michael@0 3061 && test_021()
michael@0 3062 && test_022()
michael@0 3063 && test_023()
michael@0 3064 && test_024()
michael@0 3065 && test_025()
michael@0 3066 && test_026()
michael@0 3067 && test_027()
michael@0 3068 && test_028()
michael@0 3069 && test_029()
michael@0 3070 && test_030()
michael@0 3071 && test_031()
michael@0 3072 )
michael@0 3073 {
michael@0 3074 printf("Suite passed.\n");
michael@0 3075 return 0;
michael@0 3076 }
michael@0 3077 else
michael@0 3078 {
michael@0 3079 printf("Suite failed.\n");
michael@0 3080 return 1;
michael@0 3081 }
michael@0 3082
michael@0 3083 /*NOTREACHED*/
michael@0 3084 }

mercurial