📄 string.c
字号:
{
int test_num;
UNICODE_STRING uni;
int result;
for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
result = p_wtoi(uni.Buffer);
ok(result == str2long[test_num].value,
"(test %d): call failed: _wtoi(\"%s\") has result %d, expected: %ld\n",
test_num, str2long[test_num].str, result, str2long[test_num].value);
pRtlFreeUnicodeString(&uni);
} /* for */
}
static void test_wtol(void)
{
int test_num;
UNICODE_STRING uni;
LONG result;
for (test_num = 0; test_num < NB_STR2LONG; test_num++) {
pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str);
result = p_wtol(uni.Buffer);
ok(result == str2long[test_num].value,
"(test %d): call failed: _wtol(\"%s\") has result %ld, expected: %ld\n",
test_num, str2long[test_num].str, result, str2long[test_num].value);
pRtlFreeUnicodeString(&uni);
} /* for */
}
typedef struct {
const char *str;
LONGLONG value;
} str2longlong_t;
static const str2longlong_t str2longlong[] = {
{ "1011101100", 1011101100 },
{ "1234567", 1234567 },
{ "-214", -214 },
{ "+214", 214 }, /* The + sign is allowed also */
{ "--214", 0 }, /* Do not accept more than one sign */
{ "-+214", 0 },
{ "++214", 0 },
{ "+-214", 0 },
{ "\00141", 0 }, /* not whitespace char 1 */
{ "\00242", 0 }, /* not whitespace char 2 */
{ "\00343", 0 }, /* not whitespace char 3 */
{ "\00444", 0 }, /* not whitespace char 4 */
{ "\00545", 0 }, /* not whitespace char 5 */
{ "\00646", 0 }, /* not whitespace char 6 */
{ "\00747", 0 }, /* not whitespace char 7 */
{ "\01050", 0 }, /* not whitespace char 8 */
{ "\01151", 51 }, /* is whitespace char 9 (tab) */
{ "\01252", 52 }, /* is whitespace char 10 (lf) */
{ "\01353", 53 }, /* is whitespace char 11 (vt) */
{ "\01454", 54 }, /* is whitespace char 12 (ff) */
{ "\01555", 55 }, /* is whitespace char 13 (cr) */
{ "\01656", 0 }, /* not whitespace char 14 */
{ "\01757", 0 }, /* not whitespace char 15 */
{ "\02060", 0 }, /* not whitespace char 16 */
{ "\02161", 0 }, /* not whitespace char 17 */
{ "\02262", 0 }, /* not whitespace char 18 */
{ "\02363", 0 }, /* not whitespace char 19 */
{ "\02464", 0 }, /* not whitespace char 20 */
{ "\02565", 0 }, /* not whitespace char 21 */
{ "\02666", 0 }, /* not whitespace char 22 */
{ "\02767", 0 }, /* not whitespace char 23 */
{ "\03070", 0 }, /* not whitespace char 24 */
{ "\03171", 0 }, /* not whitespace char 25 */
{ "\03272", 0 }, /* not whitespace char 26 */
{ "\03373", 0 }, /* not whitespace char 27 */
{ "\03474", 0 }, /* not whitespace char 28 */
{ "\03575", 0 }, /* not whitespace char 29 */
{ "\03676", 0 }, /* not whitespace char 30 */
{ "\03777", 0 }, /* not whitespace char 31 */
{ "\04080", 80 }, /* is whitespace char 32 (space) */
{ " \n \r \t214", 214 },
{ " \n \r \t+214", 214 }, /* Signs can be used after whitespace */
{ " \n \r \t-214", -214 },
{ "+214 0", 214 }, /* Space terminates the number */
{ " 214.01", 214 }, /* Decimal point not accepted */
{ " 214,01", 214 }, /* Decimal comma not accepted */
{ "f81", 0 },
{ "0x12345", 0 }, /* Hex not accepted */
{ "00x12345", 0 },
{ "0xx12345", 0 },
{ "1x34", 1 },
{ "-99999999999999999999", -ULL(0x6bc75e2d,0x630fffff) }, /* Big negative integer */
{ "-9223372036854775809", ULL(0x7fffffff,0xffffffff) }, /* Too small to fit in 64 bits */
{ "-9223372036854775808", ULL(0x80000000,0x00000000) }, /* Smallest negative 64 bit integer */
{ "-9223372036854775807", -ULL(0x7fffffff,0xffffffff) },
{ "-9999999999", -ULL(0x00000002,0x540be3ff) },
{ "-2147483649", -ULL(0x00000000,0x80000001) }, /* Too small to fit in 32 bits */
{ "-2147483648", -ULL(0x00000000,0x80000000) }, /* Smallest 32 bits negative integer */
{ "-2147483647", -2147483647 },
{ "-1", -1 },
{ "0", 0 },
{ "1", 1 },
{ "2147483646", 2147483646 },
{ "2147483647", 2147483647 }, /* Largest signed positive 32 bit integer */
{ "2147483648", ULL(0x00000000,0x80000000) }, /* Pos int equal to smallest neg 32 bit int */
{ "2147483649", ULL(0x00000000,0x80000001) },
{ "4294967294", ULL(0x00000000,0xfffffffe) },
{ "4294967295", ULL(0x00000000,0xffffffff) }, /* Largest unsigned 32 bit integer */
{ "4294967296", ULL(0x00000001,0x00000000) }, /* Too big to fit in 32 Bits */
{ "9999999999", ULL(0x00000002,0x540be3ff) },
{ "9223372036854775806", ULL(0x7fffffff,0xfffffffe) },
{ "9223372036854775807", ULL(0x7fffffff,0xffffffff) }, /* Largest signed positive 64 bit integer */
{ "9223372036854775808", ULL(0x80000000,0x00000000) }, /* Pos int equal to smallest neg 64 bit int */
{ "9223372036854775809", ULL(0x80000000,0x00000001) },
{ "18446744073709551614", ULL(0xffffffff,0xfffffffe) },
{ "18446744073709551615", ULL(0xffffffff,0xffffffff) }, /* Largest unsigned 64 bit integer */
{ "18446744073709551616", 0 }, /* Too big to fit in 64 bits */
{ "99999999999999999999", ULL(0x6bc75e2d,0x630fffff) }, /* Big positive integer */
{ "056789", 56789 }, /* Leading zero and still decimal */
{ "b1011101100", 0 }, /* Binary (b-notation) */
{ "-b1011101100", 0 }, /* Negative Binary (b-notation) */
{ "b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
{ "0b1011101100", 0 }, /* Binary (0b-notation) */
{ "-0b1011101100", 0 }, /* Negative binary (0b-notation) */
{ "0b10123456789", 0 }, /* Binary with nonbinary digits (2-9) */
{ "-0b10123456789", 0 }, /* Negative binary with nonbinary digits (2-9) */
{ "0b1", 0 }, /* one digit binary */
{ "0b2", 0 }, /* empty binary */
{ "0b", 0 }, /* empty binary */
{ "o1234567", 0 }, /* Octal (o-notation) */
{ "-o1234567", 0 }, /* Negative Octal (o-notation) */
{ "o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
{ "0o1234567", 0 }, /* Octal (0o-notation) */
{ "-0o1234567", 0 }, /* Negative octal (0o-notation) */
{ "0o56789", 0 }, /* Octal with nonoctal digits (8 and 9) */
{ "-0o56789", 0 }, /* Negative octal with nonoctal digits (8 and 9) */
{ "0o7", 0 }, /* one digit octal */
{ "0o8", 0 }, /* empty octal */
{ "0o", 0 }, /* empty octal */
{ "0d1011101100", 0 }, /* explizit decimal with 0d */
{ "x89abcdef", 0 }, /* Hex with lower case digits a-f (x-notation) */
{ "xFEDCBA00", 0 }, /* Hex with upper case digits A-F (x-notation) */
{ "-xFEDCBA00", 0 }, /* Negative Hexadecimal (x-notation) */
{ "0x89abcdef", 0 }, /* Hex with lower case digits a-f (0x-notation) */
{ "0xFEDCBA00", 0 }, /* Hex with upper case digits A-F (0x-notation) */
{ "-0xFEDCBA00", 0 }, /* Negative Hexadecimal (0x-notation) */
{ "0xabcdefgh", 0 }, /* Hex with illegal lower case digits (g-z) */
{ "0xABCDEFGH", 0 }, /* Hex with illegal upper case digits (G-Z) */
{ "0xF", 0 }, /* one digit hexadecimal */
{ "0xG", 0 }, /* empty hexadecimal */
{ "0x", 0 }, /* empty hexadecimal */
{ "", 0 }, /* empty string */
/* { NULL, 0 }, */ /* NULL as string */
};
#define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong))
static void test_atoi64(void)
{
int test_num;
LONGLONG result;
for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
result = p_atoi64(str2longlong[test_num].str);
ok(result == str2longlong[test_num].value,
"(test %d): call failed: _atoi64(\"%s\") has result %lld, expected: %lld\n",
test_num, str2longlong[test_num].str, result, str2longlong[test_num].value);
} /* for */
}
static void test_wtoi64(void)
{
int test_num;
UNICODE_STRING uni;
LONGLONG result;
for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) {
pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str);
result = p_wtoi64(uni.Buffer);
ok(result == str2longlong[test_num].value,
"(test %d): call failed: _wtoi64(\"%s\") has result %lld, expected: %lld\n",
test_num, str2longlong[test_num].str, result, str2longlong[test_num].value);
pRtlFreeUnicodeString(&uni);
} /* for */
}
static void test_wcsfuncs(void)
{
static const WCHAR testing[] = {'T','e','s','t','i','n','g',0};
ok (p_wcschr(testing,0)!=NULL, "wcschr Not finding terminating character\n");
ok (p_wcsrchr(testing,0)!=NULL, "wcsrchr Not finding terminating character\n");
}
START_TEST(string)
{
InitFunctionPtrs();
if (p_ultoa)
test_ulongtoa();
if (p_ui64toa)
test_ulonglongtoa();
if (p_atoi64)
test_atoi64();
if (p_ultow)
test_ulongtow();
if (p_ui64tow)
test_ulonglongtow();
if (p_wtoi)
test_wtoi();
if (p_wtol)
test_wtol();
if (p_wtoi64)
test_wtoi64();
if (p_wcschr && p_wcsrchr)
test_wcsfuncs();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -