michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "plstr.h" michael@0: #include "nspr.h" michael@0: michael@0: #include michael@0: michael@0: /* PL_strlen */ michael@0: PRBool test_001(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: PRUint32 len; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 0 }, michael@0: { "", 0 }, michael@0: { "a", 1 }, michael@0: { "abcdefg", 7 }, michael@0: { "abcdefg\0hijk", 7 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 001 (PL_strlen) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: if( PL_strlen(array[i].str) != array[i].len ) michael@0: { michael@0: printf("FAIL (%d: %s->%d, %d)\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: PL_strlen(array[i].str), array[i].len); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnlen */ michael@0: PRBool test_002(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: PRUint32 max; michael@0: PRUint32 len; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 0, 0 }, michael@0: { (const char *)0, 12, 0 }, michael@0: { "", 0, 0 }, michael@0: { "", 12, 0 }, michael@0: { "a", 0, 0 }, michael@0: { "a", 1, 1 }, michael@0: { "a", 12, 1 }, michael@0: { "abcdefg", 0, 0 }, michael@0: { "abcdefg", 1, 1 }, michael@0: { "abcdefg", 7, 7 }, michael@0: { "abcdefg", 12, 7 }, michael@0: { "abcdefg\0hijk", 0, 0 }, michael@0: { "abcdefg\0hijk", 1, 1 }, michael@0: { "abcdefg\0hijk", 7, 7 }, michael@0: { "abcdefg\0hijk", 12, 7 }, michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 002 (PL_strnlen) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: if( PL_strnlen(array[i].str, array[i].max) != array[i].len ) michael@0: { michael@0: printf("FAIL (%d: %s,%d->%d, %d)\n", i, michael@0: array[i].str ? array[i].str : "(null)", array[i].max, michael@0: PL_strnlen(array[i].str, array[i].max), array[i].len); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcpy */ michael@0: PRBool test_003(void) michael@0: { michael@0: static char buffer[ 1024 ]; michael@0: michael@0: static struct michael@0: { michael@0: const char *str; michael@0: char *dest; michael@0: char *rv; michael@0: PRBool comp; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (char *)0, (char *)0, PR_FALSE }, michael@0: { (const char *)0, buffer, (char *)0, PR_FALSE }, michael@0: { "", (char *)0, (char *)0, PR_FALSE }, michael@0: { "", buffer, buffer, PR_TRUE }, michael@0: { "a", (char *)0, (char *)0, PR_FALSE }, michael@0: { "a", buffer, buffer, PR_TRUE }, michael@0: { "abcdefg", (char *)0, (char *)0, PR_FALSE }, michael@0: { "abcdefg", buffer, buffer, PR_TRUE }, michael@0: { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE }, michael@0: { "wxyz\0abcdefg", buffer, buffer, PR_TRUE } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 003 (PL_strcpy) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv; michael@0: const char *a = array[i].str; michael@0: const char *b = (const char *)array[i].dest; michael@0: michael@0: rv = PL_strcpy(array[i].dest, array[i].str); michael@0: if( array[i].rv != rv ) michael@0: { michael@0: printf("FAIL %d: (0x%x, %s)->0x%x\n", i, array[i].dest, michael@0: array[i].str ? array[i].str : "(null)", rv); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( array[i].comp ) michael@0: { michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s->%.32s\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].dest ? array[i].dest : "(null)"); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncpy */ michael@0: PRBool test_004(void) michael@0: { michael@0: static char buffer[ 1024 ]; michael@0: michael@0: static struct michael@0: { michael@0: const char *str; michael@0: PRUint32 len; michael@0: char *dest; michael@0: char *rv; michael@0: PRBool comp; michael@0: const char *result; michael@0: PRBool nulled; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE }, michael@0: { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE }, michael@0: { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE }, michael@0: { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE }, michael@0: { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE }, michael@0: { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE }, michael@0: { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE }, michael@0: { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE }, michael@0: { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE }, michael@0: { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE }, michael@0: { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE }, michael@0: { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE }, michael@0: { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE }, michael@0: { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE }, michael@0: { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE }, michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 004 (PL_strncpy) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv; michael@0: int j; michael@0: michael@0: for( j = 0; j < sizeof(buffer); j++ ) michael@0: buffer[j] = '-'; michael@0: michael@0: rv = PL_strncpy(array[i].dest, array[i].str, array[i].len); michael@0: if( array[i].rv != rv ) michael@0: { michael@0: printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest, michael@0: array[i].str ? array[i].str : "(null)", array[i].len, rv); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( array[i].comp ) michael@0: { michael@0: const char *a = array[i].result; michael@0: const char *b = array[i].dest; michael@0: michael@0: while( *a ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s != %.32s\n", i, michael@0: array[i].result, array[i].dest); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: michael@0: if( array[i].nulled ) michael@0: { michael@0: if( *b != '\0' ) michael@0: { michael@0: printf("FAIL %d: not terminated\n", i); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( *b != '-' ) michael@0: { michael@0: printf("FAIL %d: overstepped\n", i); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncpyz */ michael@0: PRBool test_005(void) michael@0: { michael@0: static char buffer[ 1024 ]; michael@0: michael@0: static struct michael@0: { michael@0: const char *str; michael@0: PRUint32 len; michael@0: char *dest; michael@0: char *rv; michael@0: PRBool comp; michael@0: const char *result; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "", 7, buffer, buffer, PR_TRUE, "" }, michael@0: { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "b", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "c", 7, buffer, buffer, PR_TRUE, "c" }, michael@0: { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "fg", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "hi", 7, buffer, buffer, PR_TRUE, "hi" }, michael@0: { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" }, michael@0: { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" }, michael@0: { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" }, michael@0: { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 }, michael@0: { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" }, michael@0: { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" }, michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 005 (PL_strncpyz) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv; michael@0: int j; michael@0: michael@0: for( j = 0; j < sizeof(buffer); j++ ) michael@0: buffer[j] = '-'; michael@0: michael@0: rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len); michael@0: if( array[i].rv != rv ) michael@0: { michael@0: printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest, michael@0: array[i].str ? array[i].str : "(null)", array[i].len, rv); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( array[i].comp ) michael@0: { michael@0: const char *a = array[i].result; michael@0: const char *b = array[i].dest; michael@0: michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s != %.32s\n", i, michael@0: array[i].result, array[i].dest); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strdup */ michael@0: PRBool test_006(void) michael@0: { michael@0: static const char *array[] = michael@0: { michael@0: (const char *)0, michael@0: "", michael@0: "a", michael@0: "abcdefg" michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 006 (PL_strdup) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strdup(array[i]); michael@0: michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: 0x%x -> 0\n", i, array[i]); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (const char *)0 == array[i] ) michael@0: { michael@0: if( (char)0 != *rv ) michael@0: { michael@0: printf("FAIL %d: (const char *)0 -> %.32s\n", i, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: const char *a = array[i]; michael@0: const char *b = (const char *)rv; michael@0: michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s != %.32s\n", i, array[i], rv); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: michael@0: } michael@0: PL_strfree(rv); michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strndup */ michael@0: PRBool test_007(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: PRUint32 len; michael@0: const char *result; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 0, "" }, michael@0: { (const char *)0, 1, "" }, michael@0: { (const char *)0, 7, "" }, michael@0: { "", 0, "" }, michael@0: { "", 1, "" }, michael@0: { "", 7, "" }, michael@0: { "a", 0, "" }, michael@0: { "a", 1, "a" }, michael@0: { "a", 7, "a" }, michael@0: { "ab", 0, "" }, michael@0: { "ab", 1, "a" }, michael@0: { "ab", 7, "ab" }, michael@0: { "abcdefg", 0, "" }, michael@0: { "abcdefg", 1, "a" }, michael@0: { "abcdefg", 7, "abcdefg" }, michael@0: { "abcdefghijk", 0, "" }, michael@0: { "abcdefghijk", 1, "a" }, michael@0: { "abcdefghijk", 7, "abcdefg" }, michael@0: { "abcdef\0ghijk", 0, "" }, michael@0: { "abcdef\0ghijk", 1, "a" }, michael@0: { "abcdef\0ghijk", 7, "abcdef" } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 007 (PL_strndup) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strndup(array[i].str, array[i].len); michael@0: const char *a; michael@0: const char *b; michael@0: michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%lu -> 0\n", i, michael@0: array[i].str ? array[i].str : "(null)", array[i].len); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: a = array[i].result; michael@0: b = (const char *)rv; michael@0: michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s != %.32s\n", i, array[i].result, rv); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: michael@0: free(rv); michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcat */ michael@0: PRBool test_008(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *first; michael@0: const char *second; michael@0: const char *result; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, (const char *)0 }, michael@0: { (const char *)0, "xyz", (const char *)0 }, michael@0: { "", (const char *)0, "" }, michael@0: { "", "", "" }, michael@0: { "ab", "", "ab" }, michael@0: { "cd", "ef", "cdef" }, michael@0: { "gh\0X", "", "gh" }, michael@0: { "ij\0X", "kl", "ijkl" }, michael@0: { "mn\0X", "op\0X", "mnop" }, michael@0: { "qr", "st\0X", "qrst" }, michael@0: { "uv\0X", "wx\0X", "uvwx" } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 008 (PL_strcat) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char buffer[ 1024 ]; michael@0: int j; michael@0: char *rv; michael@0: michael@0: for( j = 0; j < sizeof(buffer); j++ ) michael@0: buffer[j] = '-'; michael@0: michael@0: if( (const char *)0 != array[i].first ) michael@0: (void)PL_strcpy(buffer, array[i].first); michael@0: michael@0: rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer, michael@0: array[i].second); michael@0: michael@0: if( (const char *)0 == array[i].result ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s -> %.32s, not zero\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s -> null, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: else michael@0: { michael@0: const char *a = array[i].result; michael@0: const char *b = (const char *)rv; michael@0: michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s+%s -> %.32s, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: rv, array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncat */ michael@0: PRBool test_009(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *first; michael@0: const char *second; michael@0: PRUint32 length; michael@0: PRBool nulled; michael@0: const char *result; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "", 0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "", 1, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "", 7, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 }, michael@0: { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 }, michael@0: { "", (const char *)0, 0, PR_TRUE, "" }, michael@0: { "", (const char *)0, 1, PR_TRUE, "" }, michael@0: { "", (const char *)0, 7, PR_TRUE, "" }, michael@0: { "", "", 0, PR_TRUE, "" }, michael@0: { "", "", 1, PR_TRUE, "" }, michael@0: { "", "", 7, PR_TRUE, "" }, michael@0: { "", "abcdefgh", 0, PR_TRUE, "" }, michael@0: { "", "abcdefgh", 1, PR_FALSE, "a" }, michael@0: { "", "abcdefgh", 7, PR_FALSE, "abcdefg" }, michael@0: { "xyz", (const char *)0, 0, PR_TRUE, "xyz" }, michael@0: { "xyz", (const char *)0, 1, PR_TRUE, "xyz" }, michael@0: { "xyz", (const char *)0, 7, PR_TRUE, "xyz" }, michael@0: { "xyz", "", 0, PR_TRUE, "xyz" }, michael@0: { "xyz", "", 1, PR_TRUE, "xyz" }, michael@0: { "xyz", "", 7, PR_TRUE, "xyz" }, michael@0: { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" }, michael@0: { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" }, michael@0: { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 009 (PL_strncat) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char buffer[ 1024 ]; michael@0: int j; michael@0: char *rv; michael@0: michael@0: for( j = 0; j < sizeof(buffer); j++ ) michael@0: buffer[j] = '-'; michael@0: michael@0: if( (const char *)0 != array[i].first ) michael@0: (void)PL_strcpy(buffer, array[i].first); michael@0: michael@0: rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer, michael@0: array[i].second, array[i].length); michael@0: michael@0: if( (const char *)0 == array[i].result ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: else michael@0: { michael@0: const char *a = array[i].result; michael@0: const char *b = (const char *)rv; michael@0: michael@0: while( *a ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, rv, array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: michael@0: if( array[i].nulled ) michael@0: { michael@0: if( (char)0 != *b ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> not nulled\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char)0 == *b ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> overrun\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcatn */ michael@0: PRBool test_010(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *first; michael@0: const char *second; michael@0: PRUint32 length; michael@0: const char *result; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0, (const char *)0 }, michael@0: { (const char *)0, (const char *)0, 1, (const char *)0 }, michael@0: { (const char *)0, (const char *)0, 7, (const char *)0 }, michael@0: { (const char *)0, "", 0, (const char *)0 }, michael@0: { (const char *)0, "", 1, (const char *)0 }, michael@0: { (const char *)0, "", 7, (const char *)0 }, michael@0: { (const char *)0, "stuff", 0, (const char *)0 }, michael@0: { (const char *)0, "stuff", 1, (const char *)0 }, michael@0: { (const char *)0, "stuff", 7, (const char *)0 }, michael@0: { "", (const char *)0, 0, "" }, michael@0: { "", (const char *)0, 1, "" }, michael@0: { "", (const char *)0, 7, "" }, michael@0: { "", "", 0, "" }, michael@0: { "", "", 1, "" }, michael@0: { "", "", 7, "" }, michael@0: { "", "abcdefgh", 0, "" }, michael@0: { "", "abcdefgh", 1, "" }, michael@0: { "", "abcdefgh", 7, "abcdef" }, michael@0: { "xyz", (const char *)0, 0, "xyz" }, michael@0: { "xyz", (const char *)0, 1, "xyz" }, michael@0: { "xyz", (const char *)0, 7, "xyz" }, michael@0: { "xyz", "", 0, "xyz" }, michael@0: { "xyz", "", 1, "xyz" }, michael@0: { "xyz", "", 7, "xyz" }, michael@0: { "xyz", "abcdefgh", 0, "xyz" }, michael@0: { "xyz", "abcdefgh", 1, "xyz" }, michael@0: { "xyz", "abcdefgh", 7, "xyzabc" } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 010 (PL_strcatn) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char buffer[ 1024 ]; michael@0: int j; michael@0: char *rv; michael@0: michael@0: for( j = 0; j < sizeof(buffer); j++ ) michael@0: buffer[j] = '-'; michael@0: michael@0: if( (const char *)0 != array[i].first ) michael@0: (void)PL_strcpy(buffer, array[i].first); michael@0: michael@0: rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer, michael@0: array[i].length, array[i].second); michael@0: michael@0: if( (const char *)0 == array[i].result ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: else michael@0: { michael@0: const char *a = array[i].result; michael@0: const char *b = (const char *)rv; michael@0: michael@0: while( 1 ) michael@0: { michael@0: if( *a != *b ) michael@0: { michael@0: printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i, michael@0: array[i].first ? array[i].first : "(null)", michael@0: array[i].second ? array[i].second : "(null)", michael@0: array[i].length, rv, array[i].result); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( (char)0 == *a ) break; michael@0: michael@0: a++; michael@0: b++; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcmp */ michael@0: PRBool test_011(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *one; michael@0: const char *two; michael@0: PRIntn sign; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0 }, michael@0: { (const char *)0, "word", -1 }, michael@0: { "word", (const char *)0, 1 }, michael@0: { "word", "word", 0 }, michael@0: { "aZYXVUT", "bZYXVUT", -1 }, michael@0: { "aZYXVUT", "bAAAAAA", -1 }, michael@0: { "a", "aa", -1 }, michael@0: { "a", "a", 0 }, michael@0: { "a", "A", 1 }, michael@0: { "aaaaa", "baaaa", -1 }, michael@0: { "aaaaa", "abaaa", -1 }, michael@0: { "aaaaa", "aabaa", -1 }, michael@0: { "aaaaa", "aaaba", -1 }, michael@0: { "aaaaa", "aaaab", -1 }, michael@0: { "bZYXVUT", "aZYXVUT", 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 1 }, michael@0: { "aa", "a", 1 }, michael@0: { "A", "a", -1 }, michael@0: { "baaaa", "aaaaa", 1 }, michael@0: { "abaaa", "aaaaa", 1 }, michael@0: { "aabaa", "aaaaa", 1 }, michael@0: { "aaaba", "aaaaa", 1 }, michael@0: { "aaaab", "aaaaa", 1 }, michael@0: { "word", "Word", 1 }, michael@0: { "word", "wOrd", 1 }, michael@0: { "word", "woRd", 1 }, michael@0: { "word", "worD", 1 }, michael@0: { "WORD", "wORD", -1 }, michael@0: { "WORD", "WoRD", -1 }, michael@0: { "WORD", "WOrD", -1 }, michael@0: { "WORD", "WORd", -1 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 011 (PL_strcmp) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: PRIntn rv = PL_strcmp(array[i].one, array[i].two); michael@0: michael@0: switch( array[i].sign ) michael@0: { michael@0: case -1: michael@0: if( rv < 0 ) continue; michael@0: break; michael@0: case 1: michael@0: if( rv > 0 ) continue; michael@0: break; michael@0: case 0: michael@0: if( 0 == rv ) continue; michael@0: break; michael@0: default: michael@0: PR_NOT_REACHED("static data inconsistancy"); michael@0: break; michael@0: } michael@0: michael@0: printf("FAIL %d: %s-%s -> %d, not %d\n", i, michael@0: array[i].one ? array[i].one : "(null)", michael@0: array[i].two ? array[i].two : "(null)", michael@0: rv, array[i].sign); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncmp */ michael@0: PRBool test_012(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *one; michael@0: const char *two; michael@0: PRUint32 max; michael@0: PRIntn sign; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0, 0 }, michael@0: { (const char *)0, (const char *)0, 1, 0 }, michael@0: { (const char *)0, (const char *)0, 4, 0 }, michael@0: { (const char *)0, "word", 0, -1 }, michael@0: { (const char *)0, "word", 1, -1 }, michael@0: { (const char *)0, "word", 4, -1 }, michael@0: { "word", (const char *)0, 0, 1 }, michael@0: { "word", (const char *)0, 1, 1 }, michael@0: { "word", (const char *)0, 4, 1 }, michael@0: { "word", "word", 0, 0 }, michael@0: { "word", "word", 1, 0 }, michael@0: { "word", "word", 3, 0 }, michael@0: { "word", "word", 5, 0 }, michael@0: { "aZYXVUT", "bZYXVUT", 0, 0 }, michael@0: { "aZYXVUT", "bZYXVUT", 1, -1 }, michael@0: { "aZYXVUT", "bZYXVUT", 4, -1 }, michael@0: { "aZYXVUT", "bZYXVUT", 9, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 0, 0 }, michael@0: { "aZYXVUT", "bAAAAAA", 1, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 4, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 5, -1 }, michael@0: { "a", "aa", 0, 0 }, michael@0: { "a", "aa", 1, 0 }, michael@0: { "a", "aa", 4, -1 }, michael@0: { "a", "a", 0, 0 }, michael@0: { "a", "a", 1, 0 }, michael@0: { "a", "a", 4, 0 }, michael@0: { "a", "A", 0, 0 }, michael@0: { "a", "A", 1, 1 }, michael@0: { "a", "A", 4, 1 }, michael@0: { "aaaaa", "baaaa", 0, 0 }, michael@0: { "aaaaa", "baaaa", 1, -1 }, michael@0: { "aaaaa", "baaaa", 4, -1 }, michael@0: { "aaaaa", "abaaa", 0, 0 }, michael@0: { "aaaaa", "abaaa", 1, 0 }, michael@0: { "aaaaa", "abaaa", 4, -1 }, michael@0: { "aaaaa", "aabaa", 0, 0 }, michael@0: { "aaaaa", "aabaa", 1, 0 }, michael@0: { "aaaaa", "aabaa", 4, -1 }, michael@0: { "aaaaa", "aaaba", 0, 0 }, michael@0: { "aaaaa", "aaaba", 1, 0 }, michael@0: { "aaaaa", "aaaba", 4, -1 }, michael@0: { "aaaaa", "aaaab", 0, 0 }, michael@0: { "aaaaa", "aaaab", 1, 0 }, michael@0: { "aaaaa", "aaaab", 4, 0 }, michael@0: { "bZYXVUT", "aZYXVUT", 0, 0 }, michael@0: { "bZYXVUT", "aZYXVUT", 1, 1 }, michael@0: { "bZYXVUT", "aZYXVUT", 4, 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 0, 0 }, michael@0: { "bAAAAAA", "aZYXVUT", 1, 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 4, 1 }, michael@0: { "aa", "a", 0, 0 }, michael@0: { "aa", "a", 1, 0 }, michael@0: { "aa", "a", 4, 1 }, michael@0: { "A", "a", 0, 0 }, michael@0: { "A", "a", 1, -1 }, michael@0: { "A", "a", 4, -1 }, michael@0: { "baaaa", "aaaaa", 0, 0 }, michael@0: { "baaaa", "aaaaa", 1, 1 }, michael@0: { "baaaa", "aaaaa", 4, 1 }, michael@0: { "abaaa", "aaaaa", 0, 0 }, michael@0: { "abaaa", "aaaaa", 1, 0 }, michael@0: { "abaaa", "aaaaa", 4, 1 }, michael@0: { "aabaa", "aaaaa", 0, 0 }, michael@0: { "aabaa", "aaaaa", 1, 0 }, michael@0: { "aabaa", "aaaaa", 4, 1 }, michael@0: { "aaaba", "aaaaa", 0, 0 }, michael@0: { "aaaba", "aaaaa", 1, 0 }, michael@0: { "aaaba", "aaaaa", 4, 1 }, michael@0: { "aaaab", "aaaaa", 0, 0 }, michael@0: { "aaaab", "aaaaa", 1, 0 }, michael@0: { "aaaab", "aaaaa", 4, 0 }, michael@0: { "word", "Word", 0, 0 }, michael@0: { "word", "Word", 1, 1 }, michael@0: { "word", "Word", 3, 1 }, michael@0: { "word", "wOrd", 0, 0 }, michael@0: { "word", "wOrd", 1, 0 }, michael@0: { "word", "wOrd", 3, 1 }, michael@0: { "word", "woRd", 0, 0 }, michael@0: { "word", "woRd", 1, 0 }, michael@0: { "word", "woRd", 3, 1 }, michael@0: { "word", "worD", 0, 0 }, michael@0: { "word", "worD", 1, 0 }, michael@0: { "word", "worD", 3, 0 }, michael@0: { "WORD", "wORD", 0, 0 }, michael@0: { "WORD", "wORD", 1, -1 }, michael@0: { "WORD", "wORD", 3, -1 }, michael@0: { "WORD", "WoRD", 0, 0 }, michael@0: { "WORD", "WoRD", 1, 0 }, michael@0: { "WORD", "WoRD", 3, -1 }, michael@0: { "WORD", "WOrD", 0, 0 }, michael@0: { "WORD", "WOrD", 1, 0 }, michael@0: { "WORD", "WOrD", 3, -1 }, michael@0: { "WORD", "WORd", 0, 0 }, michael@0: { "WORD", "WORd", 1, 0 }, michael@0: { "WORD", "WORd", 3, 0 } michael@0: michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 012 (PL_strncmp) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: PRIntn rv = PL_strncmp(array[i].one, array[i].two, array[i].max); michael@0: michael@0: switch( array[i].sign ) michael@0: { michael@0: case -1: michael@0: if( rv < 0 ) continue; michael@0: break; michael@0: case 1: michael@0: if( rv > 0 ) continue; michael@0: break; michael@0: case 0: michael@0: if( 0 == rv ) continue; michael@0: break; michael@0: default: michael@0: PR_NOT_REACHED("static data inconsistancy"); michael@0: break; michael@0: } michael@0: michael@0: printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i, michael@0: array[i].one ? array[i].one : "(null)", michael@0: array[i].two ? array[i].two : "(null)", michael@0: array[i].max, rv, array[i].sign); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcasecmp */ michael@0: PRBool test_013(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *one; michael@0: const char *two; michael@0: PRIntn sign; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0 }, michael@0: { (const char *)0, "word", -1 }, michael@0: { "word", (const char *)0, 1 }, michael@0: { "word", "word", 0 }, michael@0: { "aZYXVUT", "bZYXVUT", -1 }, michael@0: { "aZYXVUT", "bAAAAAA", -1 }, michael@0: { "a", "aa", -1 }, michael@0: { "a", "a", 0 }, michael@0: { "a", "A", 0 }, michael@0: { "aaaaa", "baaaa", -1 }, michael@0: { "aaaaa", "abaaa", -1 }, michael@0: { "aaaaa", "aabaa", -1 }, michael@0: { "aaaaa", "aaaba", -1 }, michael@0: { "aaaaa", "aaaab", -1 }, michael@0: { "bZYXVUT", "aZYXVUT", 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 1 }, michael@0: { "aa", "a", 1 }, michael@0: { "A", "a", 0 }, michael@0: { "baaaa", "aaaaa", 1 }, michael@0: { "abaaa", "aaaaa", 1 }, michael@0: { "aabaa", "aaaaa", 1 }, michael@0: { "aaaba", "aaaaa", 1 }, michael@0: { "aaaab", "aaaaa", 1 }, michael@0: { "word", "Word", 0 }, michael@0: { "word", "wOrd", 0 }, michael@0: { "word", "woRd", 0 }, michael@0: { "word", "worD", 0 }, michael@0: { "WORD", "wORD", 0 }, michael@0: { "WORD", "WoRD", 0 }, michael@0: { "WORD", "WOrD", 0 }, michael@0: { "WORD", "WORd", 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 013 (PL_strcasecmp) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: PRIntn rv = PL_strcasecmp(array[i].one, array[i].two); michael@0: michael@0: switch( array[i].sign ) michael@0: { michael@0: case -1: michael@0: if( rv < 0 ) continue; michael@0: break; michael@0: case 1: michael@0: if( rv > 0 ) continue; michael@0: break; michael@0: case 0: michael@0: if( 0 == rv ) continue; michael@0: break; michael@0: default: michael@0: PR_NOT_REACHED("static data inconsistancy"); michael@0: break; michael@0: } michael@0: michael@0: printf("FAIL %d: %s-%s -> %d, not %d\n", i, michael@0: array[i].one ? array[i].one : "(null)", michael@0: array[i].two ? array[i].two : "(null)", michael@0: rv, array[i].sign); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncasecmp */ michael@0: PRBool test_014(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *one; michael@0: const char *two; michael@0: PRUint32 max; michael@0: PRIntn sign; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 0, 0 }, michael@0: { (const char *)0, (const char *)0, 1, 0 }, michael@0: { (const char *)0, (const char *)0, 4, 0 }, michael@0: { (const char *)0, "word", 0, -1 }, michael@0: { (const char *)0, "word", 1, -1 }, michael@0: { (const char *)0, "word", 4, -1 }, michael@0: { "word", (const char *)0, 0, 1 }, michael@0: { "word", (const char *)0, 1, 1 }, michael@0: { "word", (const char *)0, 4, 1 }, michael@0: { "word", "word", 0, 0 }, michael@0: { "word", "word", 1, 0 }, michael@0: { "word", "word", 3, 0 }, michael@0: { "word", "word", 5, 0 }, michael@0: { "aZYXVUT", "bZYXVUT", 0, 0 }, michael@0: { "aZYXVUT", "bZYXVUT", 1, -1 }, michael@0: { "aZYXVUT", "bZYXVUT", 4, -1 }, michael@0: { "aZYXVUT", "bZYXVUT", 9, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 0, 0 }, michael@0: { "aZYXVUT", "bAAAAAA", 1, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 4, -1 }, michael@0: { "aZYXVUT", "bAAAAAA", 5, -1 }, michael@0: { "a", "aa", 0, 0 }, michael@0: { "a", "aa", 1, 0 }, michael@0: { "a", "aa", 4, -1 }, michael@0: { "a", "a", 0, 0 }, michael@0: { "a", "a", 1, 0 }, michael@0: { "a", "a", 4, 0 }, michael@0: { "a", "A", 0, 0 }, michael@0: { "a", "A", 1, 0 }, michael@0: { "a", "A", 4, 0 }, michael@0: { "aaaaa", "baaaa", 0, 0 }, michael@0: { "aaaaa", "baaaa", 1, -1 }, michael@0: { "aaaaa", "baaaa", 4, -1 }, michael@0: { "aaaaa", "abaaa", 0, 0 }, michael@0: { "aaaaa", "abaaa", 1, 0 }, michael@0: { "aaaaa", "abaaa", 4, -1 }, michael@0: { "aaaaa", "aabaa", 0, 0 }, michael@0: { "aaaaa", "aabaa", 1, 0 }, michael@0: { "aaaaa", "aabaa", 4, -1 }, michael@0: { "aaaaa", "aaaba", 0, 0 }, michael@0: { "aaaaa", "aaaba", 1, 0 }, michael@0: { "aaaaa", "aaaba", 4, -1 }, michael@0: { "aaaaa", "aaaab", 0, 0 }, michael@0: { "aaaaa", "aaaab", 1, 0 }, michael@0: { "aaaaa", "aaaab", 4, 0 }, michael@0: { "bZYXVUT", "aZYXVUT", 0, 0 }, michael@0: { "bZYXVUT", "aZYXVUT", 1, 1 }, michael@0: { "bZYXVUT", "aZYXVUT", 4, 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 0, 0 }, michael@0: { "bAAAAAA", "aZYXVUT", 1, 1 }, michael@0: { "bAAAAAA", "aZYXVUT", 4, 1 }, michael@0: { "aa", "a", 0, 0 }, michael@0: { "aa", "a", 1, 0 }, michael@0: { "aa", "a", 4, 1 }, michael@0: { "A", "a", 0, 0 }, michael@0: { "A", "a", 1, 0 }, michael@0: { "A", "a", 4, 0 }, michael@0: { "baaaa", "aaaaa", 0, 0 }, michael@0: { "baaaa", "aaaaa", 1, 1 }, michael@0: { "baaaa", "aaaaa", 4, 1 }, michael@0: { "abaaa", "aaaaa", 0, 0 }, michael@0: { "abaaa", "aaaaa", 1, 0 }, michael@0: { "abaaa", "aaaaa", 4, 1 }, michael@0: { "aabaa", "aaaaa", 0, 0 }, michael@0: { "aabaa", "aaaaa", 1, 0 }, michael@0: { "aabaa", "aaaaa", 4, 1 }, michael@0: { "aaaba", "aaaaa", 0, 0 }, michael@0: { "aaaba", "aaaaa", 1, 0 }, michael@0: { "aaaba", "aaaaa", 4, 1 }, michael@0: { "aaaab", "aaaaa", 0, 0 }, michael@0: { "aaaab", "aaaaa", 1, 0 }, michael@0: { "aaaab", "aaaaa", 4, 0 }, michael@0: { "word", "Word", 0, 0 }, michael@0: { "word", "Word", 1, 0 }, michael@0: { "word", "Word", 3, 0 }, michael@0: { "word", "wOrd", 0, 0 }, michael@0: { "word", "wOrd", 1, 0 }, michael@0: { "word", "wOrd", 3, 0 }, michael@0: { "word", "woRd", 0, 0 }, michael@0: { "word", "woRd", 1, 0 }, michael@0: { "word", "woRd", 3, 0 }, michael@0: { "word", "worD", 0, 0 }, michael@0: { "word", "worD", 1, 0 }, michael@0: { "word", "worD", 3, 0 }, michael@0: { "WORD", "wORD", 0, 0 }, michael@0: { "WORD", "wORD", 1, 0 }, michael@0: { "WORD", "wORD", 3, 0 }, michael@0: { "WORD", "WoRD", 0, 0 }, michael@0: { "WORD", "WoRD", 1, 0 }, michael@0: { "WORD", "WoRD", 3, 0 }, michael@0: { "WORD", "WOrD", 0, 0 }, michael@0: { "WORD", "WOrD", 1, 0 }, michael@0: { "WORD", "WOrD", 3, 0 }, michael@0: { "WORD", "WORd", 0, 0 }, michael@0: { "WORD", "WORd", 1, 0 }, michael@0: { "WORD", "WORd", 3, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max); michael@0: michael@0: switch( array[i].sign ) michael@0: { michael@0: case -1: michael@0: if( rv < 0 ) continue; michael@0: break; michael@0: case 1: michael@0: if( rv > 0 ) continue; michael@0: break; michael@0: case 0: michael@0: if( 0 == rv ) continue; michael@0: break; michael@0: default: michael@0: PR_NOT_REACHED("static data inconsistancy"); michael@0: break; michael@0: } michael@0: michael@0: printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i, michael@0: array[i].one ? array[i].one : "(null)", michael@0: array[i].two ? array[i].two : "(null)", michael@0: array[i].max, rv, array[i].sign); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strchr */ michael@0: PRBool test_015(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: char chr; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 'a', PR_FALSE, 0 }, michael@0: { (const char *)0, '\0', PR_FALSE, 0 }, michael@0: { "abcdefg", 'a', PR_TRUE, 0 }, michael@0: { "abcdefg", 'b', PR_TRUE, 1 }, michael@0: { "abcdefg", 'c', PR_TRUE, 2 }, michael@0: { "abcdefg", 'd', PR_TRUE, 3 }, michael@0: { "abcdefg", 'e', PR_TRUE, 4 }, michael@0: { "abcdefg", 'f', PR_TRUE, 5 }, michael@0: { "abcdefg", 'g', PR_TRUE, 6 }, michael@0: { "abcdefg", 'h', PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', PR_TRUE, 7 }, michael@0: { "abcdefg", 'A', PR_FALSE, 0 }, michael@0: { "abcdefg", 'B', PR_FALSE, 0 }, michael@0: { "abcdefg", 'C', PR_FALSE, 0 }, michael@0: { "abcdefg", 'D', PR_FALSE, 0 }, michael@0: { "abcdefg", 'E', PR_FALSE, 0 }, michael@0: { "abcdefg", 'F', PR_FALSE, 0 }, michael@0: { "abcdefg", 'G', PR_FALSE, 0 }, michael@0: { "abcdefg", 'H', PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", 'a', PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", 'b', PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", 'c', PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", 'd', PR_TRUE, 3 }, michael@0: { "abcdefgabcdefg", 'e', PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", 'f', PR_TRUE, 5 }, michael@0: { "abcdefgabcdefg", 'g', PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", 'h', PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', PR_TRUE, 14 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 015 (PL_strchr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strchr(array[i].str, array[i].chr); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str, michael@0: array[i].chr, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str, michael@0: array[i].chr, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strrchr */ michael@0: PRBool test_016(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: char chr; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 'a', PR_FALSE, 0 }, michael@0: { (const char *)0, '\0', PR_FALSE, 0 }, michael@0: { "abcdefg", 'a', PR_TRUE, 0 }, michael@0: { "abcdefg", 'b', PR_TRUE, 1 }, michael@0: { "abcdefg", 'c', PR_TRUE, 2 }, michael@0: { "abcdefg", 'd', PR_TRUE, 3 }, michael@0: { "abcdefg", 'e', PR_TRUE, 4 }, michael@0: { "abcdefg", 'f', PR_TRUE, 5 }, michael@0: { "abcdefg", 'g', PR_TRUE, 6 }, michael@0: { "abcdefg", 'h', PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', PR_TRUE, 7 }, michael@0: { "abcdefg", 'A', PR_FALSE, 0 }, michael@0: { "abcdefg", 'B', PR_FALSE, 0 }, michael@0: { "abcdefg", 'C', PR_FALSE, 0 }, michael@0: { "abcdefg", 'D', PR_FALSE, 0 }, michael@0: { "abcdefg", 'E', PR_FALSE, 0 }, michael@0: { "abcdefg", 'F', PR_FALSE, 0 }, michael@0: { "abcdefg", 'G', PR_FALSE, 0 }, michael@0: { "abcdefg", 'H', PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", 'a', PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", 'b', PR_TRUE, 8 }, michael@0: { "abcdefgabcdefg", 'c', PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", 'd', PR_TRUE, 10 }, michael@0: { "abcdefgabcdefg", 'e', PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", 'f', PR_TRUE, 12 }, michael@0: { "abcdefgabcdefg", 'g', PR_TRUE, 13 }, michael@0: { "abcdefgabcdefg", 'h', PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', PR_TRUE, 14 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 016 (PL_strrchr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strrchr(array[i].str, array[i].chr); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str, michael@0: array[i].chr, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str, michael@0: array[i].chr, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnchr */ michael@0: PRBool test_017(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: char chr; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 'a', 2, PR_FALSE, 0 }, michael@0: { (const char *)0, '\0', 2, PR_FALSE, 0 }, michael@0: { "abcdefg", 'a', 5, PR_TRUE, 0 }, michael@0: { "abcdefg", 'b', 5, PR_TRUE, 1 }, michael@0: { "abcdefg", 'c', 5, PR_TRUE, 2 }, michael@0: { "abcdefg", 'd', 5, PR_TRUE, 3 }, michael@0: { "abcdefg", 'e', 5, PR_TRUE, 4 }, michael@0: { "abcdefg", 'f', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'g', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'h', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', 15, PR_TRUE, 7 }, michael@0: { "abcdefg", 'A', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'B', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'C', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'D', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'E', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'F', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'G', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'H', 5, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 }, michael@0: { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 }, michael@0: { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 017 (PL_strnchr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str, michael@0: array[i].chr, array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].max, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnrchr */ michael@0: PRBool test_018(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: char chr; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, 'a', 2, PR_FALSE, 0 }, michael@0: { (const char *)0, '\0', 2, PR_FALSE, 0 }, michael@0: { "abcdefg", 'a', 5, PR_TRUE, 0 }, michael@0: { "abcdefg", 'b', 5, PR_TRUE, 1 }, michael@0: { "abcdefg", 'c', 5, PR_TRUE, 2 }, michael@0: { "abcdefg", 'd', 5, PR_TRUE, 3 }, michael@0: { "abcdefg", 'e', 5, PR_TRUE, 4 }, michael@0: { "abcdefg", 'f', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'g', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'h', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", '\0', 15, PR_TRUE, 7 }, michael@0: { "abcdefg", 'A', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'B', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'C', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'D', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'E', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'F', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'G', 5, PR_FALSE, 0 }, michael@0: { "abcdefg", 'H', 5, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 }, michael@0: { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 }, michael@0: { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 }, michael@0: { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 018 (PL_strnrchr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnrchr(array[i].str, array[i].chr, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str, michael@0: array[i].chr, array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].max, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str, michael@0: array[i].chr, array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strpbrk */ michael@0: PRBool test_019(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *chrs; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "abc", PR_FALSE, 0 }, michael@0: { "abc", (const char *)0, PR_FALSE, 0 }, michael@0: { "abcdefg", "", PR_FALSE, 0 }, michael@0: { "", "aeiou", PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", PR_TRUE, 0 }, michael@0: { "abcdefg", "ei", PR_TRUE, 4 }, michael@0: { "abcdefg", "io", PR_FALSE, 0 }, michael@0: { "abcdefg", "bcd", PR_TRUE, 1 }, michael@0: { "abcdefg", "cbd", PR_TRUE, 1 }, michael@0: { "abcdefg", "dbc", PR_TRUE, 1 }, michael@0: { "abcdefg", "ghi", PR_TRUE, 6 }, michael@0: { "abcdefg", "AE", PR_FALSE, 0 }, michael@0: { "abcdefg", "EI", PR_FALSE, 0 }, michael@0: { "abcdefg", "IO", PR_FALSE, 0 }, michael@0: { "abcdefg", "BCD", PR_FALSE, 0 }, michael@0: { "abcdefg", "CBD", PR_FALSE, 0 }, michael@0: { "abcdefg", "DBC", PR_FALSE, 0 }, michael@0: { "abcdefg", "GHI", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ae", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "ei", PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "io", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "bcd", PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "cbd", PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "dbc", PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "ghi", PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "AE", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "EI", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "IO", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "BCD", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "CBD", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "DBC", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "GHI", PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 019 (PL_strpbrk) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strpbrk(array[i].str, array[i].chrs); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not +%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strprbrk */ michael@0: PRBool test_020(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *chrs; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "abc", PR_FALSE, 0 }, michael@0: { "abc", (const char *)0, PR_FALSE, 0 }, michael@0: { "abcdefg", "", PR_FALSE, 0 }, michael@0: { "", "aeiou", PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", PR_TRUE, 4 }, michael@0: { "abcdefg", "ei", PR_TRUE, 4 }, michael@0: { "abcdefg", "io", PR_FALSE, 0 }, michael@0: { "abcdefg", "bcd", PR_TRUE, 3 }, michael@0: { "abcdefg", "cbd", PR_TRUE, 3 }, michael@0: { "abcdefg", "dbc", PR_TRUE, 3 }, michael@0: { "abcdefg", "ghi", PR_TRUE, 6 }, michael@0: { "abcdefg", "AE", PR_FALSE, 0 }, michael@0: { "abcdefg", "EI", PR_FALSE, 0 }, michael@0: { "abcdefg", "IO", PR_FALSE, 0 }, michael@0: { "abcdefg", "BCD", PR_FALSE, 0 }, michael@0: { "abcdefg", "CBD", PR_FALSE, 0 }, michael@0: { "abcdefg", "DBC", PR_FALSE, 0 }, michael@0: { "abcdefg", "GHI", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ae", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "ei", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "io", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "bcd", PR_TRUE, 10 }, michael@0: { "abcdefgabcdefg", "cbd", PR_TRUE, 10 }, michael@0: { "abcdefgabcdefg", "dbc", PR_TRUE, 10 }, michael@0: { "abcdefgabcdefg", "ghi", PR_TRUE, 13 }, michael@0: { "abcdefgabcdefg", "AE", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "EI", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "IO", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "BCD", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "CBD", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "DBC", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "GHI", PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 020 (PL_strprbrk) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strprbrk(array[i].str, array[i].chrs); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not +%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnpbrk */ michael@0: PRBool test_021(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *chrs; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 3, PR_FALSE, 0 }, michael@0: { (const char *)0, "abc", 3, PR_FALSE, 0 }, michael@0: { "abc", (const char *)0, 3, PR_FALSE, 0 }, michael@0: { "abcdefg", "", 3, PR_FALSE, 0 }, michael@0: { "", "aeiou", 3, PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", 0, PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", 1, PR_TRUE, 0 }, michael@0: { "abcdefg", "ae", 4, PR_TRUE, 0 }, michael@0: { "abcdefg", "ae", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "ae", 6, PR_TRUE, 0 }, michael@0: { "abcdefg", "ei", 4, PR_FALSE, 0 }, michael@0: { "abcdefg", "io", 10, PR_FALSE, 0 }, michael@0: { "abcdefg", "bcd", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "cbd", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "dbc", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "ghi", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "ghi", 7, PR_TRUE, 6 }, michael@0: { "abcdefg", "AE", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "EI", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "IO", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "BCD", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "CBD", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "DBC", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "GHI", 9, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 021 (PL_strnpbrk) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnpbrk(array[i].str, array[i].chrs, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnprbrk */ michael@0: PRBool test_022(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *chrs; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 3, PR_FALSE, 0 }, michael@0: { (const char *)0, "abc", 3, PR_FALSE, 0 }, michael@0: { "abc", (const char *)0, 3, PR_FALSE, 0 }, michael@0: { "abcdefg", "", 3, PR_FALSE, 0 }, michael@0: { "", "aeiou", 3, PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", 0, PR_FALSE, 0 }, michael@0: { "abcdefg", "ae", 1, PR_TRUE, 0 }, michael@0: { "abcdefg", "ae", 4, PR_TRUE, 0 }, michael@0: { "abcdefg", "ae", 5, PR_TRUE, 4 }, michael@0: { "abcdefg", "ae", 6, PR_TRUE, 4 }, michael@0: { "abcdefg", "ei", 4, PR_FALSE, 0 }, michael@0: { "abcdefg", "io", 10, PR_FALSE, 0 }, michael@0: { "abcdefg", "bcd", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "cbd", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "dbc", 2, PR_TRUE, 1 }, michael@0: { "abcdefg", "bcd", 3, PR_TRUE, 2 }, michael@0: { "abcdefg", "cbd", 3, PR_TRUE, 2 }, michael@0: { "abcdefg", "dbc", 3, PR_TRUE, 2 }, michael@0: { "abcdefg", "bcd", 5, PR_TRUE, 3 }, michael@0: { "abcdefg", "cbd", 5, PR_TRUE, 3 }, michael@0: { "abcdefg", "dbc", 5, PR_TRUE, 3 }, michael@0: { "abcdefg", "bcd", 15, PR_TRUE, 3 }, michael@0: { "abcdefg", "cbd", 15, PR_TRUE, 3 }, michael@0: { "abcdefg", "dbc", 15, PR_TRUE, 3 }, michael@0: { "abcdefg", "ghi", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "ghi", 7, PR_TRUE, 6 }, michael@0: { "abcdefg", "AE", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "EI", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "IO", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "BCD", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "CBD", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "DBC", 9, PR_FALSE, 0 }, michael@0: { "abcdefg", "GHI", 9, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 022 (PL_strnprbrk) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnprbrk(array[i].str, array[i].chrs, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].chrs ? array[i].chrs : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strstr */ michael@0: PRBool test_023(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", PR_TRUE, 0 }, michael@0: { "", "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", PR_FALSE, 0 }, michael@0: { "abcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", PR_TRUE, 1 }, michael@0: { "abcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "a", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "c", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "e", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "g", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "cd", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ef", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 023 (PL_strstr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strstr(array[i].str, array[i].sub); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strrstr */ michael@0: PRBool test_024(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", PR_TRUE, 8 }, michael@0: { "", "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", PR_FALSE, 0 }, michael@0: { "abcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", PR_TRUE, 5 }, michael@0: { "abcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "c", PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "e", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "g", PR_TRUE, 13 }, michael@0: { "abcdefgabcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "cd", PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "ef", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", PR_TRUE, 12 }, michael@0: { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 }, michael@0: { "ABCDEFG", "a", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "c", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "e", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "g", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "cd", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ef", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 024 (PL_strrstr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strrstr(array[i].str, array[i].sub); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnstr */ michael@0: PRBool test_025(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 12, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 2, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 3, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 4, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 5, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 12, PR_TRUE, 0 }, michael@0: { "", "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", 12, PR_FALSE, 0 }, michael@0: { "abcdefg", "a", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "c", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "e", 5, PR_TRUE, 4 }, michael@0: { "abcdefg", "g", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "i", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "gh", 5, PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 7, PR_TRUE, 1 }, michael@0: { "abcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "a", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "c", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "e", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "g", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "cd", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ef", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 6, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 7, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 7, PR_FALSE, }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 025 (PL_strnstr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnstr(array[i].str, array[i].sub, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strnrstr */ michael@0: PRBool test_026(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 12, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 2, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 3, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 4, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 5, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 11, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 12, PR_TRUE, 8 }, michael@0: { "blah-de-blah", "blah", 13, PR_TRUE, 8 }, michael@0: { "", "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", 12, PR_FALSE, 0 }, michael@0: { "abcdefg", "a", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "c", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "e", 5, PR_TRUE, 4 }, michael@0: { "abcdefg", "g", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "i", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "gh", 5, PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 7, PR_TRUE, 5 }, michael@0: { "abcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 }, michael@0: { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 }, michael@0: { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 }, michael@0: { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 }, michael@0: { "ABCDEFG", "a", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "c", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "e", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "g", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "cd", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ef", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 6, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 7, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 026 (PL_strnrstr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strnrstr(array[i].str, array[i].sub, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcasestr */ michael@0: PRBool test_027(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", PR_TRUE, 0 }, michael@0: { "", "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", PR_FALSE, 0 }, michael@0: { "abcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", PR_TRUE, 1 }, michael@0: { "abcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "a", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "c", PR_TRUE, 2 }, michael@0: { "ABCDEFG", "e", PR_TRUE, 4 }, michael@0: { "ABCDEFG", "g", PR_TRUE, 6 }, michael@0: { "ABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "cd", PR_TRUE, 2 }, michael@0: { "ABCDEFG", "ef", PR_TRUE, 4 }, michael@0: { "ABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", PR_TRUE, 1 }, michael@0: { "ABCDEFG", "abcdefg", PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 }, michael@0: { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 }, michael@0: { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 }, michael@0: { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 }, michael@0: { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 }, michael@0: { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", PR_TRUE, 1 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 027 (PL_strcasestr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strcasestr(array[i].str, array[i].sub); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strcaserstr */ michael@0: PRBool test_028(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", PR_TRUE, 8 }, michael@0: { "", "blah", PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", PR_FALSE, 0 }, michael@0: { "abcdefg", "a", PR_TRUE, 0 }, michael@0: { "abcdefg", "c", PR_TRUE, 2 }, michael@0: { "abcdefg", "e", PR_TRUE, 4 }, michael@0: { "abcdefg", "g", PR_TRUE, 6 }, michael@0: { "abcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", PR_TRUE, 4 }, michael@0: { "abcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", PR_TRUE, 5 }, michael@0: { "abcdefg", "abcdefg", PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "c", PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "e", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "g", PR_TRUE, 13 }, michael@0: { "abcdefgabcdefg", "i", PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "cd", PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "ef", PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "gh", PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", PR_TRUE, 12 }, michael@0: { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 }, michael@0: { "ABCDEFG", "a", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "c", PR_TRUE, 2 }, michael@0: { "ABCDEFG", "e", PR_TRUE, 4 }, michael@0: { "ABCDEFG", "g", PR_TRUE, 6 }, michael@0: { "ABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", PR_TRUE, 0 }, michael@0: { "ABCDEFG", "cd", PR_TRUE, 2 }, michael@0: { "ABCDEFG", "ef", PR_TRUE, 4 }, michael@0: { "ABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", PR_TRUE, 5 }, michael@0: { "ABCDEFG", "abcdefg", PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 }, michael@0: { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 }, michael@0: { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 }, michael@0: { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 }, michael@0: { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 }, michael@0: { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 }, michael@0: { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 }, michael@0: { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", PR_TRUE, 12 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 028 (PL_strcaserstr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strcaserstr(array[i].str, array[i].sub); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncasestr */ michael@0: PRBool test_029(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 12, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 2, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 3, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 4, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 5, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 12, PR_TRUE, 0 }, michael@0: { "", "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", 12, PR_FALSE, 0 }, michael@0: { "abcdefg", "a", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "c", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "e", 5, PR_TRUE, 4 }, michael@0: { "abcdefg", "g", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "i", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "gh", 5, PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 7, PR_TRUE, 1 }, michael@0: { "abcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 }, michael@0: { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 }, michael@0: { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "a", 5, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "c", 5, PR_TRUE, 2 }, michael@0: { "ABCDEFG", "e", 5, PR_TRUE, 4 }, michael@0: { "ABCDEFG", "g", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", 5, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "cd", 5, PR_TRUE, 2 }, michael@0: { "ABCDEFG", "ef", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 5, PR_TRUE, 1 }, michael@0: { "ABCDABC", "bc", 6, PR_TRUE, 1 }, michael@0: { "ABCDABC", "bc", 7, PR_TRUE, 1 }, michael@0: { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 }, michael@0: { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 }, michael@0: { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 }, michael@0: { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 }, michael@0: { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 }, michael@0: { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 }, michael@0: { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 }, michael@0: { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 029 (PL_strncasestr) ..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strncasestr(array[i].str, array[i].sub, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strncaserstr */ michael@0: PRBool test_030(void) michael@0: { michael@0: static struct michael@0: { michael@0: const char *str; michael@0: const char *sub; michael@0: PRUint32 max; michael@0: PRBool ret; michael@0: PRUint32 off; michael@0: } array[] = michael@0: { michael@0: { (const char *)0, (const char *)0, 12, PR_FALSE, 0 }, michael@0: { (const char *)0, "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 0, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 2, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 3, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "blah", 4, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 5, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 11, PR_TRUE, 0 }, michael@0: { "blah-de-blah", "blah", 12, PR_TRUE, 8 }, michael@0: { "blah-de-blah", "blah", 13, PR_TRUE, 8 }, michael@0: { "", "blah", 12, PR_FALSE, 0 }, michael@0: { "blah-de-blah", "", 12, PR_FALSE, 0 }, michael@0: { "abcdefg", "a", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "c", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "e", 5, PR_TRUE, 4 }, michael@0: { "abcdefg", "g", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "i", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "ab", 5, PR_TRUE, 0 }, michael@0: { "abcdefg", "cd", 5, PR_TRUE, 2 }, michael@0: { "abcdefg", "ef", 5, PR_FALSE, 0 }, michael@0: { "abcdefg", "gh", 5, PR_FALSE, 0 }, michael@0: { "abcdabc", "bc", 5, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 6, PR_TRUE, 1 }, michael@0: { "abcdabc", "bc", 7, PR_TRUE, 5 }, michael@0: { "abcdefg", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "abcdefg", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "abcdefg", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 }, michael@0: { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 }, michael@0: { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 }, michael@0: { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 }, michael@0: { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 }, michael@0: { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 }, michael@0: { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 }, michael@0: { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 }, michael@0: { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 }, michael@0: { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 }, michael@0: { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 }, michael@0: { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 }, michael@0: { "ABCDEFG", "a", 5, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "c", 5, PR_TRUE, 2 }, michael@0: { "ABCDEFG", "e", 5, PR_TRUE, 4 }, michael@0: { "ABCDEFG", "g", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "i", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "ab", 5, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "cd", 5, PR_TRUE, 2 }, michael@0: { "ABCDEFG", "ef", 5, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "gh", 5, PR_FALSE, 0 }, michael@0: { "ABCDABC", "bc", 5, PR_TRUE, 1 }, michael@0: { "ABCDABC", "bc", 6, PR_TRUE, 1 }, michael@0: { "ABCDABC", "bc", 7, PR_TRUE, 5 }, michael@0: { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 }, michael@0: { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 }, michael@0: { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 }, michael@0: { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 }, michael@0: { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 }, michael@0: { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 }, michael@0: { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 }, michael@0: { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 }, michael@0: { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 }, michael@0: { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 }, michael@0: { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 }, michael@0: { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 }, michael@0: { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 }, michael@0: { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 } michael@0: }; michael@0: michael@0: int i; michael@0: michael@0: printf("Test 030 (PL_strncaserstr)..."); fflush(stdout); michael@0: michael@0: for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ ) michael@0: { michael@0: char *rv = PL_strncaserstr(array[i].str, array[i].sub, array[i].max); michael@0: michael@0: if( PR_FALSE == array[i].ret ) michael@0: { michael@0: if( (char *)0 != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if( (char *)0 == rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: if( &array[i].str[ array[i].off ] != rv ) michael@0: { michael@0: printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, michael@0: array[i].str ? array[i].str : "(null)", michael@0: array[i].sub ? array[i].sub : "(null)", michael@0: array[i].max, rv, array[i].str, array[i].off); michael@0: return PR_FALSE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: /* PL_strtok_r */ michael@0: PRBool test_031(void) michael@0: { michael@0: static const char *tokens[] = { michael@0: "wtc", "relyea", "nelsonb", "jpierre", "nicolson", michael@0: "ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein" michael@0: }; michael@0: michael@0: static const char *seps[] = { michael@0: ", ", ",", " ", "\t", ",,,", " ,", " ", " \t\t", "," michael@0: }; michael@0: michael@0: static const char s2[] = ", \t"; michael@0: michael@0: char string[ 1024 ]; michael@0: char *s1; michael@0: char *token; michael@0: char *lasts; michael@0: unsigned int i; michael@0: michael@0: printf("Test 031 (PL_strtok_r) ..."); fflush(stdout); michael@0: michael@0: /* Build the string. */ michael@0: string[0] = '\0'; michael@0: for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ ) michael@0: { michael@0: PL_strcat(string, tokens[i]); michael@0: PL_strcat(string, seps[i]); michael@0: } michael@0: michael@0: /* Scan the string for tokens. */ michael@0: i = 0; michael@0: s1 = string; michael@0: while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL) michael@0: { michael@0: if( PL_strcmp(token, tokens[i]) != 0 ) michael@0: { michael@0: printf("FAIL wrong token scanned\n"); michael@0: return PR_FALSE; michael@0: } michael@0: i++; michael@0: s1 = NULL; michael@0: } michael@0: if( i != sizeof(tokens)/sizeof(tokens[0]) ) michael@0: { michael@0: printf("FAIL wrong number of tokens scanned\n"); michael@0: return PR_FALSE; michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return PR_TRUE; michael@0: } michael@0: michael@0: int michael@0: main michael@0: ( michael@0: int argc, michael@0: char *argv[] michael@0: ) michael@0: { michael@0: printf("Testing the Portable Library string functions:\n"); michael@0: michael@0: if( 1 michael@0: && test_001() michael@0: && test_001() michael@0: && test_002() michael@0: && test_003() michael@0: && test_004() michael@0: && test_005() michael@0: && test_006() michael@0: && test_007() michael@0: && test_008() michael@0: && test_009() michael@0: && test_010() michael@0: && test_011() michael@0: && test_012() michael@0: && test_013() michael@0: && test_014() michael@0: && test_015() michael@0: && test_016() michael@0: && test_017() michael@0: && test_018() michael@0: && test_019() michael@0: && test_020() michael@0: && test_021() michael@0: && test_022() michael@0: && test_023() michael@0: && test_024() michael@0: && test_025() michael@0: && test_026() michael@0: && test_027() michael@0: && test_028() michael@0: && test_029() michael@0: && test_030() michael@0: && test_031() michael@0: ) michael@0: { michael@0: printf("Suite passed.\n"); michael@0: return 0; michael@0: } michael@0: else michael@0: { michael@0: printf("Suite failed.\n"); michael@0: return 1; michael@0: } michael@0: michael@0: /*NOTREACHED*/ michael@0: }