ICU-852 Added tests for the new u_mem* functions

X-SVN-Rev: 3822
This commit is contained in:
George Rhoten 2001-02-28 17:52:00 +00:00
parent 56ab25f37f
commit a2f174b977

View File

@ -133,7 +133,6 @@ static void TestUpperLower()
if(u_tolower(upper[i]) != lower[i]){
log_err("FAILED u_tolower() for %lx Expected %lx Got %lx\n", upper[i], lower[i], u_tolower(upper[i]));
}
}
log_verbose("testing upper lower\n");
for (i = 0; i < 21; i++) {
@ -150,7 +149,6 @@ static void TestUpperLower()
else if (upperTest[i] != u_tolower(lowerTest[i]))
{
log_err("Failed case conversion from %c To %c :\n", lowerTest[i], upperTest[i]);
}
else if (lowerTest[i] != u_toupper(upperTest[i]))
{
@ -180,7 +178,6 @@ static void TestLetterNumber()
if (!u_isalpha(i))
{
log_err("Failed isLetter test at %.4X\n", i);
}
}
for (i = 0x0660; i < 0x066A; i++) {
@ -188,7 +185,6 @@ static void TestLetterNumber()
if (u_isalpha(i))
{
log_err("Failed isLetter test with numbers at %.4X\n", i);
}
}
for (i = 0x0660; i < 0x066A; i++) {
@ -203,7 +199,6 @@ static void TestLetterNumber()
if (!u_isalnum(i))
{
log_err("Failed isAlNum test at %.4X\n", i);
}
}
for (i = 0x0660; i < 0x066A; i++) {
@ -669,6 +664,7 @@ static void TestStringFunctions()
{
int32_t i,j,k;
UChar temp[512];
UChar nullTemp[512];
char test[512];
char tempOut[512];
@ -678,20 +674,77 @@ static void TestStringFunctions()
if( u_strlen(dataTable[0][0])!= u_strlen(dataTable[0][3]) || u_strlen(dataTable[0][0]) == u_strlen(dataTable[0][2]))
log_err("There is an error in u_strlen()");
log_verbose("Testing u_memcpy() and u_memcmp()\n");
for(i=0;i<3;++i)
{
for(j=0;j<4;++j)
{
log_verbose("Testing %s\n", u_austrcpy(tempOut, dataTable[i][j]));
temp[0] = 0;
temp[7] = 0xA4; /* Mark the end */
u_memcpy(temp,dataTable[i][j], 7);
if(temp[7] != 0xA4)
log_err("an error occured in u_memcpy()\n");
if(u_memcmp(temp, dataTable[i][j], 7)!=0)
log_err("an error occured in u_memcpy() or u_memcmp()\n");
}
}
if(u_memcmp(dataTable[0][0], dataTable[1][1], 7)==0)
log_err("an error occured in u_memcmp()\n");
log_verbose("Testing u_memset()\n");
nullTemp[0] = 0;
nullTemp[7] = 0;
u_memset(nullTemp, 0xa4, 7);
for (i = 0; i < 7; i++) {
if(nullTemp[i] != 0xa4) {
log_err("an error occured in u_memset()\n");
}
}
if(nullTemp[7] != 0) {
log_err("u_memset() went too far\n");
}
u_memset(nullTemp, 0, 7);
nullTemp[7] = 0xa4;
temp[7] = 0;
u_memcpy(temp,nullTemp, 7);
if(u_memcmp(temp, nullTemp, 7)!=0 || temp[7]!=0)
log_err("an error occured in u_memcpy() or u_memcmp()\n");
log_verbose("Testing u_memmove()\n");
for (i = 0; i < 7; i++) {
temp[i] = (UChar)i;
}
u_memmove(temp + 1, temp, 7);
if(temp[0] != 0) {
log_err("an error occured in u_memmove()\n");
}
for (i = 1; i <= 7; i++) {
if(temp[i] != (i - 1)) {
log_err("an error occured in u_memmove()\n");
}
}
log_verbose("Testing u_strcpy() and u_strcmp()\n");
for(i=0;i<3;++i)
{
for(j=0;j<4;++j)
{
log_verbose("Testing %s \n", u_austrcpy(tempOut, dataTable[i][j]));
u_uastrcpy(temp, "");
log_verbose("Testing %s\n", u_austrcpy(tempOut, dataTable[i][j]));
temp[0] = 0;
u_strcpy(temp,dataTable[i][j]);
if(u_strcmp(temp,dataTable[i][j])!=0)
log_err("something threw an error in u_strcpy() or u_strcmp()\n");
}
}
if(u_strcmp(dataTable[0][0], dataTable[1][1])==0)
log_err("an error occured in u_memcmp()\n");
log_verbose("testing u_strcat()\n");
i=0;
@ -711,6 +764,8 @@ static void TestStringFunctions()
if(u_strncmp(dataTable[i][j],dataTable[i+2][j],k)!=0)
log_err("Something threw an error in u_strncmp\n");
}
if(u_strncmp(dataTable[0][0], dataTable[1][1], 7)==0)
log_err("an error occured in u_memcmp()\n");
log_verbose("Testing u_strncat\n");
@ -736,22 +791,57 @@ static void TestStringFunctions()
log_err("something threw an error in u_strncpy()\n");
}
log_verbose("Testing u_strchr()\n");
log_verbose("Testing u_strchr() and u_memchr()\n");
for(i=2,j=0;j<4;j++)
{
UChar saveVal = dataTable[i][j][0];
UChar *findPtr = u_strchr(dataTable[i][j], 0x005F);
int32_t dataSize = (int32_t)(u_strlen(dataTable[i][j]) + 1);
log_verbose("%s ", u_austrcpy(tempOut, findPtr));
if (findPtr == NULL || *findPtr != 0x005F) {
log_err("strchr can't find '_' in the string\n");
log_err("u_strchr can't find '_' in the string\n");
}
findPtr = u_strchr32(dataTable[i][j], 0x005F);
if (findPtr == NULL || *findPtr != 0x005F) {
log_err("u_strchr32 can't find '_' in the string\n");
}
findPtr = u_strchr(dataTable[i][j], 0);
if (findPtr != (&(dataTable[i][j][u_strlen(dataTable[i][j])]))) {
log_err("strchr can't find NULL in the string\n");
if (findPtr != (&(dataTable[i][j][dataSize - 1]))) {
log_err("u_strchr can't find NULL in the string\n");
}
findPtr = u_strchr32(dataTable[i][j], 0);
if (findPtr != (&(dataTable[i][j][dataSize - 1]))) {
log_err("u_strchr32 can't find NULL in the string\n");
}
findPtr = u_memchr(dataTable[i][j], 0, dataSize);
if (findPtr != (&(dataTable[i][j][dataSize - 1]))) {
log_err("u_memchr can't find NULL in the string\n");
}
findPtr = u_memchr32(dataTable[i][j], 0, dataSize);
if (findPtr != (&(dataTable[i][j][dataSize - 1]))) {
log_err("u_memchr32 can't find NULL in the string\n");
}
dataTable[i][j][0] = 0;
/* Make sure we skip over the NULL termination */
findPtr = u_memchr(dataTable[i][j], 0x005F, dataSize);
if (findPtr == NULL || *findPtr != 0x005F) {
log_err("u_memchr can't find '_' in the string\n");
}
findPtr = u_memchr32(dataTable[i][j], 0x005F, dataSize);
if (findPtr == NULL || *findPtr != 0x005F) {
log_err("u_memchr32 can't find '_' in the string\n");
}
dataTable[i][j][0] = saveVal; /* Put it back for the other tests */
}
@ -1043,10 +1133,10 @@ static void TestStringCopy()
log_err("u_uastrncpy wrote past it's bounds. Expected undisturbed byte at 3\n");
}
charOut[0] = (char)0xFB; /* load garbage into it */
charOut[1] = (char)0xFB;
charOut[2] = (char)0xFB;
charOut[3] = (char)0xFB;
charOut[0] = (char)0x7B; /* load garbage into it */
charOut[1] = (char)0x7B;
charOut[2] = (char)0x7B;
charOut[3] = (char)0x7B;
temp[0] = 'a'; /* load codepage specific string into it */
temp[1] = 'b';
@ -1060,7 +1150,7 @@ static void TestStringCopy()
if(strncmp(chars, charOut, 3) != 0){
log_err("There is an error in u_austrncpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
}
if(charOut[3] != (char)0xFB) {
if(charOut[3] != (char)0x7B) {
log_err("u_austrncpy wrote past it's bounds. Expected undisturbed byte at 3\n");
}