📄 string.c
字号:
const char *Buffer;
int mask; /* ntdll/msvcrt: 0x01=i64toa, 0x02=ui64toa, 0x04=wrong _i64toa try next example */
/* 0x10=i64tow, 0x20=ui64tow, 0x40=wrong _i64tow try next example */
} ulonglong2str_t;
static const ulonglong2str_t ulonglong2str[] = {
{10, 123, "123\0---------------------------------------------------------------", 0x33},
{ 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x33},
{ 2, -2147483647, "1111111111111111111111111111111110000000000000000000000000000001\0--", 0x33},
{ 2, -65537, "1111111111111111111111111111111111111111111111101111111111111111\0--", 0x33},
{ 2, -65536, "1111111111111111111111111111111111111111111111110000000000000000\0--", 0x33},
{ 2, -65535, "1111111111111111111111111111111111111111111111110000000000000001\0--", 0x33},
{ 2, -32768, "1111111111111111111111111111111111111111111111111000000000000000\0--", 0x33},
{ 2, -32767, "1111111111111111111111111111111111111111111111111000000000000001\0--", 0x33},
{ 2, -2, "1111111111111111111111111111111111111111111111111111111111111110\0--", 0x33},
{ 2, -1, "1111111111111111111111111111111111111111111111111111111111111111\0--", 0x33},
{ 2, 0, "0\0-----------------------------------------------------------------", 0x33},
{ 2, 1, "1\0-----------------------------------------------------------------", 0x33},
{ 2, 10, "1010\0--------------------------------------------------------------", 0x33},
{ 2, 100, "1100100\0-----------------------------------------------------------", 0x33},
{ 2, 1000, "1111101000\0--------------------------------------------------------", 0x33},
{ 2, 10000, "10011100010000\0----------------------------------------------------", 0x33},
{ 2, 32767, "111111111111111\0---------------------------------------------------", 0x33},
{ 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
{ 2, 65535, "1111111111111111\0--------------------------------------------------", 0x33},
{ 2, 100000, "11000011010100000\0-------------------------------------------------", 0x33},
{ 2, 234567, "111001010001000111\0------------------------------------------------", 0x33},
{ 2, 300000, "1001001001111100000\0-----------------------------------------------", 0x33},
{ 2, 524287, "1111111111111111111\0-----------------------------------------------", 0x33},
{ 2, 524288, "10000000000000000000\0----------------------------------------------", 0x33},
{ 2, 1000000, "11110100001001000000\0----------------------------------------------", 0x33},
{ 2, 10000000, "100110001001011010000000\0------------------------------------------", 0x33},
{ 2, 100000000, "101111101011110000100000000\0---------------------------------------", 0x33},
{ 2, 1000000000, "111011100110101100101000000000\0------------------------------------", 0x33},
{ 2, 1073741823, "111111111111111111111111111111\0------------------------------------", 0x33},
{ 2, 2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x33},
{ 2, 2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x33},
{ 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x33},
{ 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x33},
{ 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x33},
{ 2, 0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x33},
{ 2, ULL(0x1,0xffffffff), "111111111111111111111111111111111\0---------------------------------", 0x33},
{ 2, ((ULONGLONG)100000)*100000, "1001010100000010111110010000000000\0--------------------------------", 0x33},
{ 2, ULL(0x3,0xffffffff), "1111111111111111111111111111111111\0--------------------------------", 0x33},
{ 2, ULL(0x7,0xffffffff), "11111111111111111111111111111111111\0-------------------------------", 0x33},
{ 2, ULL(0xf,0xffffffff), "111111111111111111111111111111111111\0------------------------------", 0x33},
{ 2, ((ULONGLONG)100000)*1000000, "1011101001000011101101110100000000000\0-----------------------------", 0x33},
{ 2, ULL(0x1f,0xffffffff), "1111111111111111111111111111111111111\0-----------------------------", 0x33},
{ 2, ULL(0x3f,0xffffffff), "11111111111111111111111111111111111111\0----------------------------", 0x33},
{ 2, ULL(0x7f,0xffffffff), "111111111111111111111111111111111111111\0---------------------------", 0x33},
{ 2, ULL(0xff,0xffffffff), "1111111111111111111111111111111111111111\0--------------------------", 0x33},
{ 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x33},
{ 8, -2147483647, "1777777777760000000001\0--------------------------------------------", 0x33},
{ 8, -2, "1777777777777777777776\0--------------------------------------------", 0x33},
{ 8, -1, "1777777777777777777777\0--------------------------------------------", 0x33},
{ 8, 0, "0\0-----------------------------------------------------------------", 0x33},
{ 8, 1, "1\0-----------------------------------------------------------------", 0x33},
{ 8, 2147483646, "17777777776\0-------------------------------------------------------", 0x33},
{ 8, 2147483647, "17777777777\0-------------------------------------------------------", 0x33},
{ 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x33},
{ 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x33},
{ 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x33},
{ 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x33},
{10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x33},
{10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x55},
{10, -2147483647, "-18446744071562067969\0---------------------------------------------", 0x00},
{10, -2147483647, "18446744071562067969\0----------------------------------------------", 0x22},
{10, -2, "-2\0----------------------------------------------------------------", 0x55},
{10, -2, "-18446744073709551614\0---------------------------------------------", 0x00},
{10, -2, "18446744073709551614\0----------------------------------------------", 0x22},
{10, -1, "-1\0----------------------------------------------------------------", 0x55},
{10, -1, "-18446744073709551615\0---------------------------------------------", 0x00},
{10, -1, "18446744073709551615\0----------------------------------------------", 0x22},
{10, 0, "0\0-----------------------------------------------------------------", 0x33},
{10, 1, "1\0-----------------------------------------------------------------", 0x33},
{10, 12, "12\0----------------------------------------------------------------", 0x33},
{10, 123, "123\0---------------------------------------------------------------", 0x33},
{10, 1234, "1234\0--------------------------------------------------------------", 0x33},
{10, 12345, "12345\0-------------------------------------------------------------", 0x33},
{10, 123456, "123456\0------------------------------------------------------------", 0x33},
{10, 1234567, "1234567\0-----------------------------------------------------------", 0x33},
{10, 12345678, "12345678\0----------------------------------------------------------", 0x33},
{10, 123456789, "123456789\0---------------------------------------------------------", 0x33},
{10, 2147483646, "2147483646\0--------------------------------------------------------", 0x33},
{10, 2147483647, "2147483647\0--------------------------------------------------------", 0x33},
{10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x33},
{10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x33},
{10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x33},
{10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x33},
{10, ULL(0x2,0xdfdc1c35), "12345678901\0-------------------------------------------------------", 0x33},
{10, ULL(0xe5,0xf4c8f374), "987654321012\0------------------------------------------------------", 0x33},
{10, ULL(0x1c0,0xfc161e3e), "1928374656574\0-----------------------------------------------------", 0x33},
{10, ULL(0xbad,0xcafeface), "12841062955726\0----------------------------------------------------", 0x33},
{10, ULL(0x5bad,0xcafeface), "100801993177806\0---------------------------------------------------", 0x33},
{10, ULL(0xaface,0xbeefcafe), "3090515640699646\0--------------------------------------------------", 0x33},
{10, ULL(0xa5beef,0xabcdcafe), "46653307746110206\0-------------------------------------------------", 0x33},
{10, ULL(0x1f8cf9b,0xf2df3af1), "142091656963767025\0------------------------------------------------", 0x33},
{10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33},
{10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33},
{10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11},
{10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22},
{10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55},
{10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00},
{10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22},
{10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55},
{10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00},
{10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22},
{10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55},
{10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00},
{10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22},
{10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55},
{10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00},
{10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22},
{16, 0, "0\0-----------------------------------------------------------------", 0x33},
{16, 1, "1\0-----------------------------------------------------------------", 0x33},
{16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33},
{16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33},
{16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33},
{16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33},
{16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33},
{16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33},
{16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33},
{16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33},
{16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33},
{16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33},
{16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33},
{16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33},
{16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33},
{ 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33},
{ 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33},
{ 2, 131072, "100000000000000000\0------------------------------------------------", 0x33},
{16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33},
{16, 0xa, "a\0-----------------------------------------------------------------", 0x33},
{16, 0, "0\0-----------------------------------------------------------------", 0x33},
{20, 3368421, "111111\0------------------------------------------------------------", 0x33},
{36, 62193781, "111111\0------------------------------------------------------------", 0x33},
{37, 71270178, "111111\0------------------------------------------------------------", 0x33},
{99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},
};
#define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))
static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
{
LPSTR result;
char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
ok(result == dest_str,
"(test %d): _i64toa(%Lu, [out], %d) has result %p, expected: %p\n",
test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
if (ulonglong2str->mask & 0x04) {
if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) {
ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
"(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
} /* if */
} /* if */
} else {
ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
"(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
} /* if */
}
static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str)
{
LPSTR result;
char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base);
ok(result == dest_str,
"(test %d): _ui64toa(%Lu, [out], %d) has result %p, expected: %p\n",
test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str);
ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
"(test %d): _ui64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"\n",
test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);
}
static void test_ulonglongtoa(void)
{
int test_num;
for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) {
if (ulonglong2str[test_num].mask & 0x01) {
one_i64toa_test(test_num, &ulonglong2str[test_num]);
} /* if */
if (p_ui64toa != NULL) {
if (ulonglong2str[test_num].mask & 0x02) {
one_ui64toa_test(test_num, &ulonglong2str[test_num]);
} /* if */
} /* if */
} /* for */
}
static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str)
{
int pos;
WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1];
UNICODE_STRING unicode_string;
STRING ansi_str;
LPWSTR result;
for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
expected_wstr[pos] = ulonglong2str->Buffer[pos];
} /* for */
expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -