ICU-829 Added u_strspn, u_strcspn and u_strpbrk. Moved string copy testing to another function.

X-SVN-Rev: 3492
This commit is contained in:
George Rhoten 2001-01-30 03:25:05 +00:00
parent 970daeceb9
commit 3b3a5e58c9
2 changed files with 273 additions and 87 deletions

View File

@ -111,7 +111,9 @@ void addUnicodeTest(TestNode** root)
addTest(root, &TestControlPrint, "tsutil/cucdtst/TestControlPrint");
addTest(root, &TestIdentifier, "tsutil/cucdtst/TestIdentifier");
addTest(root, &TestUnicodeData, "tsutil/cucdtst/TestUnicodeData");
addTest(root, &TestStringCopy, "tsutil/cucdtst/TestStringCopy");
addTest(root, &TestStringFunctions, "tsutil/cucdtst/TestStringFunctions");
addTest(root, &TestStringSearching, "tsutil/cucdtst/TestStringSearching");
addTest(root, &TestCharNames, "tsutil/cucdtst/TestCharNames");
addTest(root, &TestMirroring, "tsutil/cucdtst/TestMirroring");
addTest(root, &TestUnescape, "tsutil/cucdtst/TestUnescape");
@ -673,6 +675,7 @@ static void TestStringFunctions()
int32_t i,j,k;
UChar temp[40];
char test[40];
char tempOut[40];
setUpDataTable();
@ -715,7 +718,7 @@ static void TestStringFunctions()
}
log_verbose("Testing u_strncat \n");
log_verbose("Testing u_strncat\n");
for(i=0,j=0;j<4; ++j)
{
k=u_strlen(dataTable[i][j]);
@ -738,12 +741,13 @@ static void TestStringFunctions()
log_err("something threw an error in u_strncpy()\n");
}
log_verbose("Testing if u_strchr() works fine\n");
log_verbose("Testing u_strchr()\n");
for(i=2,j=0;j<4;j++)
{
UChar *findPtr = u_strchr(dataTable[i][j],'_');
log_verbose("%s ", austrdup(findPtr));
log_verbose("%s ", u_austrcpy(tempOut, findPtr));
if (findPtr == NULL || *findPtr != '_') {
log_err("strchr can't find '_' in the string\n");
@ -762,11 +766,211 @@ static void TestStringFunctions()
log_err("There is an error in u_austrcpy()");
log_verbose("Testing u_uastrncpy() and u_uastrcpy()");
cleanUpDataTable();
}
static void TestStringSearching()
{
UChar ucharBuf[255];
const UChar testString[] = {0x0061, 0x0062, 0x0063, 0x0064, 0x0064, 0x0061, 0x0000};
const UChar testSurrogateString[] = {0xdbff, 0x0061, 0x0062, 0xdbff, 0xdfff, 0x0063, 0x0064, 0x0064, 0xdbff, 0xdfff, 0xdb00, 0xdf00, 0x0061, 0x0000};
const UChar surrMatchSet1[] = {0xdbff, 0xdfff, 0x0000};
const UChar surrMatchSet2[] = {0x0061, 0x0062, 0xdbff, 0xdfff, 0x0000};
const UChar surrMatchSet3[] = {0xdb00, 0xdf00, 0xdbff, 0xdfff, 0x0000};
const UChar surrMatchSet4[] = {0x0000};
log_verbose("Testing u_strpbrk()");
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "a")) != &testString[0]) {
log_err("u_strpbrk couldn't find first letter a.\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "dc")) != &testString[2]) {
log_err("u_strpbrk couldn't find d or c.\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "cd")) != &testString[2]) {
log_err("u_strpbrk couldn't find c or d.\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "cdh")) != &testString[2]) {
log_err("u_strpbrk couldn't find c, d or h.\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "f")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"f\".\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "fg")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"fg\".\n");
}
if (u_strpbrk(testString, u_uastrcpy(ucharBuf, "gf")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"gf\".\n");
}
log_verbose("Testing u_strpbrk() with surrogates");
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "a")) != &testSurrogateString[1]) {
log_err("u_strpbrk couldn't find first letter a.\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "dc")) != &testSurrogateString[5]) {
log_err("u_strpbrk couldn't find d or c.\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "cd")) != &testSurrogateString[5]) {
log_err("u_strpbrk couldn't find c or d.\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "cdh")) != &testSurrogateString[5]) {
log_err("u_strpbrk couldn't find c, d or h.\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "f")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"f\".\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "fg")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"fg\".\n");
}
if (u_strpbrk(testSurrogateString, u_uastrcpy(ucharBuf, "gf")) != NULL) {
log_err("u_strpbrk didn't return NULL for \"gf\".\n");
}
if (u_strpbrk(testSurrogateString, surrMatchSet1) != &testSurrogateString[3]) {
log_err("u_strpbrk couldn't find \"0xdbff, 0xdfff\".\n");
}
if (u_strpbrk(testSurrogateString, surrMatchSet2) != &testSurrogateString[1]) {
log_err("u_strpbrk couldn't find \"a, b, 0xdbff, 0xdfff\".\n");
}
if (u_strpbrk(testSurrogateString, surrMatchSet3) != &testSurrogateString[3]) {
log_err("u_strpbrk couldn't find \"0xdb00, 0xdf00, 0xdbff, 0xdfff\".\n");
}
if (u_strpbrk(testSurrogateString, surrMatchSet4) != NULL) {
log_err("u_strpbrk should have returned NULL for empty string.\n");
}
log_verbose("Testing u_strcspn()");
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "a")) != 0) {
log_err("u_strcspn couldn't find first letter a.\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "dc")) != 2) {
log_err("u_strcspn couldn't find d or c.\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "cd")) != 2) {
log_err("u_strcspn couldn't find c or d.\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "cdh")) != 2) {
log_err("u_strcspn couldn't find c, d or h.\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "f")) != u_strlen(testString)) {
log_err("u_strcspn didn't return NULL for \"f\".\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "fg")) != u_strlen(testString)) {
log_err("u_strcspn didn't return NULL for \"fg\".\n");
}
if (u_strcspn(testString, u_uastrcpy(ucharBuf, "gf")) != u_strlen(testString)) {
log_err("u_strcspn didn't return NULL for \"gf\".\n");
}
log_verbose("Testing u_strcspn() with surrogates");
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "a")) != 1) {
log_err("u_strcspn couldn't find first letter a.\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "dc")) != 5) {
log_err("u_strcspn couldn't find d or c.\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "cd")) != 5) {
log_err("u_strcspn couldn't find c or d.\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "cdh")) != 5) {
log_err("u_strcspn couldn't find c, d or h.\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "f")) != u_strlen(testSurrogateString)) {
log_err("u_strcspn didn't return NULL for \"f\".\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "fg")) != u_strlen(testSurrogateString)) {
log_err("u_strcspn didn't return NULL for \"fg\".\n");
}
if (u_strcspn(testSurrogateString, u_uastrcpy(ucharBuf, "gf")) != u_strlen(testSurrogateString)) {
log_err("u_strcspn didn't return NULL for \"gf\".\n");
}
if (u_strcspn(testSurrogateString, surrMatchSet1) != 3) {
log_err("u_strcspn couldn't find \"0xdbff, 0xdfff\".\n");
}
if (u_strcspn(testSurrogateString, surrMatchSet2) != 1) {
log_err("u_strcspn couldn't find \"a, b, 0xdbff, 0xdfff\".\n");
}
if (u_strcspn(testSurrogateString, surrMatchSet3) != 3) {
log_err("u_strcspn couldn't find \"0xdb00, 0xdf00, 0xdbff, 0xdfff\".\n");
}
if (u_strcspn(testSurrogateString, surrMatchSet4) != u_strlen(testSurrogateString)) {
log_err("u_strcspn should have returned strlen for empty string.\n");
}
log_verbose("Testing u_strspn()");
if (u_strspn(testString, u_uastrcpy(ucharBuf, "a")) != 1) {
log_err("u_strspn couldn't skip first letter a.\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "ab")) != 2) {
log_err("u_strspn couldn't skip a or b.\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "ba")) != 2) {
log_err("u_strspn couldn't skip a or b.\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "f")) != 0) {
log_err("u_strspn didn't return 0 for \"f\".\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "dc")) != 0) {
log_err("u_strspn couldn't find first letter a (skip d or c).\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "abcd")) != u_strlen(testString)) {
log_err("u_strspn couldn't skip over the whole string.\n");
}
if (u_strspn(testString, u_uastrcpy(ucharBuf, "")) != 0) {
log_err("u_strspn should have returned 0 for empty string.\n");
}
log_verbose("Testing u_strspn() with surrogates");
{
const UChar surrogateStringWithoutIllegal[] = {0x0061, 0x0062, 0xdbff, 0xdfff, 0x0063, 0x0064, 0x0064, 0xdbff, 0xdfff, 0xdb00, 0xdf00, 0x0061, 0x0000};
const UChar skip1[] = {0x0061, 0x0062, 0xdbff, 0xdfff, 0x0000};
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "a")) != 1) {
log_err("u_strspn couldn't skip first letter a.\n");
}
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "ab")) != 2) {
log_err("u_strspn couldn't skip 0xdbff or a.\n");
}
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "ba")) != 2) {
log_err("u_strspn couldn't skip 0xdbff or a.\n");
}
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "f")) != 0) {
log_err("u_strspn couldn't skip d or c (skip first letter).\n");
}
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "dc")) != 0) {
log_err("u_strspn couldn't skip d or c (skip first letter).\n");
}
if (u_strspn(surrogateStringWithoutIllegal, u_uastrcpy(ucharBuf, "cd")) != 0) {
log_err("u_strspn couldn't skip d or c (skip first letter).\n");
}
if (u_strspn(surrogateStringWithoutIllegal, surrogateStringWithoutIllegal) != u_strlen(surrogateStringWithoutIllegal)) {
log_err("u_strspn couldn't skip whole string.\n");
}
if (u_strspn(surrogateStringWithoutIllegal, surrMatchSet1) != 0) {
log_err("u_strspn couldn't skip \"0xdbff, 0xdfff\" (get first letter).\n");
}
if (u_strspn(surrogateStringWithoutIllegal, surrMatchSet2) != 4) {
log_err("u_strspn couldn't skip \"a, b, 0xdbff, 0xdfff\".\n");
}
if (u_strspn(surrogateStringWithoutIllegal, surrMatchSet4) != 0) {
log_err("u_strspn should have returned 0 for empty string.\n");
}
}
}
static void TestStringCopy()
{
UChar temp[40];
UChar *result=0;
UChar subString[5];
UChar uchars[]={0x61, 0x62, 0x63, 0x00};
log_verbose("Testing u_uastrncpy() and u_uastrcpy()");
u_uastrcpy(temp, "abc");
if(u_strcmp(temp, uchars) != 0) {
log_err("There is an error in u_uastrcpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
@ -831,29 +1035,9 @@ static void TestStringFunctions()
log_err("There is an error in u_strchr32() Expected match at position 5 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
}
cleanUpDataTable();
/* test u_strcmpCodePointOrder() */
{
/* these strings are in ascending order */
static const UChar strings[5][3]={
{ 0x61, 0 }, /* U+0061 */
{ 0x20ac, 0 }, /* U+20ac */
{ 0xff61, 0 }, /* U+ff61 */
{ 0xd800, 0xdc02, 0 }, /* U+10002 */
{ 0xd84d, 0xdc56, 0 } /* U+23456 */
};
for(i=0; i<4; ++i) {
if(u_strcmpCodePointOrder(strings[i], strings[i+1])>=0) {
log_err("error: u_strcmpCodePointOrder() fails for string %d and the following one\n", i);
}
}
}
}
/* test u_charName() -------------------------------------------------------- */
static const struct {

View File

@ -27,7 +27,9 @@ static void TestMisc(void);
static void TestControlPrint(void);
static void TestIdentifier(void);
static void TestUnicodeData(void);
static void TestStringCopy(void);
static void TestStringFunctions(void);
static void TestStringSearching(void);
/* internal methods used */
static int32_t MakeProp(char* str);