_swab failed if src == dest, plus some testcases.
This commit is contained in:
parent
c1cd0d22e0
commit
8f8ec2adcc
|
@ -106,9 +106,11 @@ void MSVCRT__swab(char* src, char* dst, int len)
|
|||
len = (unsigned)len >> 1;
|
||||
|
||||
while (len--) {
|
||||
*dst++ = src[1];
|
||||
*dst++ = *src++;
|
||||
src++;
|
||||
char s0 = src[0];
|
||||
char s1 = src[1];
|
||||
*dst++ = s1;
|
||||
*dst++ = s0;
|
||||
src = src + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,50 @@ static int* (*pmemcmp)(void *, const void *, size_t n);
|
|||
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
|
||||
#define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
|
||||
|
||||
static void test_swab( void ) {
|
||||
char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
|
||||
char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
|
||||
char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
|
||||
char expected3[] = "$";
|
||||
|
||||
char from[30];
|
||||
char to[30];
|
||||
|
||||
int testsize;
|
||||
|
||||
/* Test 1 - normal even case */
|
||||
memset(to,'$', sizeof(to));
|
||||
memset(from,'@', sizeof(from));
|
||||
testsize = 26;
|
||||
memcpy(from, original, testsize);
|
||||
_swab( from, to, testsize );
|
||||
ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
||||
|
||||
/* Test 2 - uneven case */
|
||||
memset(to,'$', sizeof(to));
|
||||
memset(from,'@', sizeof(from));
|
||||
testsize = 25;
|
||||
memcpy(from, original, testsize);
|
||||
_swab( from, to, testsize );
|
||||
ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
||||
|
||||
/* Test 3 - from = to */
|
||||
memset(to,'$', sizeof(to));
|
||||
memset(from,'@', sizeof(from));
|
||||
testsize = 26;
|
||||
memcpy(to, original, testsize);
|
||||
_swab( to, to, testsize );
|
||||
ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
||||
|
||||
/* Test 4 - 1 bytes */
|
||||
memset(to,'$', sizeof(to));
|
||||
memset(from,'@', sizeof(from));
|
||||
testsize = 1;
|
||||
memcpy(from, original, testsize);
|
||||
_swab( from, to, testsize );
|
||||
ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
||||
}
|
||||
|
||||
|
||||
START_TEST(string)
|
||||
{
|
||||
|
@ -48,4 +92,7 @@ START_TEST(string)
|
|||
pmemcpy((char*)mem+5, mem,nLen+1);
|
||||
ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0,
|
||||
"Got result %s\n",(char*)mem+5);
|
||||
|
||||
/* Test _swab function */
|
||||
test_swab();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue