📄 rtlstr.c
字号:
{ 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS}, { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS}, { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},/* In the following test the native function writes beyond MaximumLength * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS}, */ { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS}, { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL}, { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS}, { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS}, { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS}, { 4, 14, 14, NULL, 0, 0, 8, NULL, 4, 14, 14, NULL, STATUS_SUCCESS}, { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS},};#define NB_APP_USTR2STR (sizeof(app_ustr2str)/sizeof(*app_ustr2str))static void test_RtlAppendUnicodeStringToString(void){ WCHAR dest_buf[257]; WCHAR src_buf[257]; UNICODE_STRING dest_str; UNICODE_STRING src_str; NTSTATUS result; size_t test_num; for (test_num = 0; test_num < NB_APP_USTR2STR; test_num++) { dest_str.Length = app_ustr2str[test_num].dest_Length; dest_str.MaximumLength = app_ustr2str[test_num].dest_MaximumLength; if (app_ustr2str[test_num].dest_buf != NULL) { memcpy(dest_buf, app_ustr2str[test_num].dest_buf, app_ustr2str[test_num].dest_buf_size); dest_buf[app_ustr2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0'; dest_str.Buffer = dest_buf; } else { dest_str.Buffer = NULL; } /* if */ src_str.Length = app_ustr2str[test_num].src_Length; src_str.MaximumLength = app_ustr2str[test_num].src_MaximumLength; if (app_ustr2str[test_num].src_buf != NULL) { memcpy(src_buf, app_ustr2str[test_num].src_buf, app_ustr2str[test_num].src_buf_size); src_buf[app_ustr2str[test_num].src_buf_size/sizeof(WCHAR)] = '\0'; src_str.Buffer = src_buf; } else { src_str.Buffer = NULL; } /* if */ result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); ok(result == app_ustr2str[test_num].result, "(test %d): RtlAppendStringToString(dest, src) has result %lx, expected %lx", test_num, result, app_ustr2str[test_num].result); ok(dest_str.Length == app_ustr2str[test_num].res_Length, "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d", test_num, dest_str.Length, app_ustr2str[test_num].res_Length); ok(dest_str.MaximumLength == app_ustr2str[test_num].res_MaximumLength, "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d", test_num, dest_str.MaximumLength, app_ustr2str[test_num].res_MaximumLength); if (dest_str.Buffer == dest_buf) { ok(memcmp(dest_buf, app_ustr2str[test_num].res_buf, app_ustr2str[test_num].res_buf_size) == 0, "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"", test_num, (char *) dest_buf, app_ustr2str[test_num].res_buf); } else { ok(dest_str.Buffer == (WCHAR *) app_ustr2str[test_num].res_buf, "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p", test_num, dest_str.Buffer, app_ustr2str[test_num].res_buf); } /* if */ } /* for */}typedef struct { int flags; const char *main_str; const char *search_chars; USHORT pos; NTSTATUS result;} find_ch_in_ustr_t;static const find_ch_in_ustr_t find_ch_in_ustr[] = { { 0, "Some Wild String", "S", 2, STATUS_SUCCESS}, { 0, "This is a String", "String", 6, STATUS_SUCCESS}, { 1, "This is a String", "String", 30, STATUS_SUCCESS}, { 2, "This is a String", "String", 2, STATUS_SUCCESS}, { 3, "This is a String", "String", 18, STATUS_SUCCESS}, { 0, "This is a String", "Wild", 6, STATUS_SUCCESS}, { 1, "This is a String", "Wild", 26, STATUS_SUCCESS}, { 2, "This is a String", "Wild", 2, STATUS_SUCCESS}, { 3, "This is a String", "Wild", 30, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND}, { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND}, { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS}, { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS}, { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS}, { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND}, { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS}, { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS}, { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS}, { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS}, { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS}, { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS}, { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS}, { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS}, { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS}, { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS}, { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS}, { 0, NULL, "abc", 0, STATUS_NOT_FOUND}, { 1, NULL, "abc", 0, STATUS_NOT_FOUND}, { 2, NULL, "abc", 0, STATUS_NOT_FOUND}, { 3, NULL, "abc", 0, STATUS_NOT_FOUND}, { 0, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND}, { 1, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND}, { 2, "abcdefghijklmnopqrstuvwxyz", NULL, 2, STATUS_SUCCESS}, { 3, "abcdefghijklmnopqrstuvwxyz", NULL, 50, STATUS_SUCCESS}, { 0, NULL, NULL, 0, STATUS_NOT_FOUND}, { 1, NULL, NULL, 0, STATUS_NOT_FOUND}, { 2, NULL, NULL, 0, STATUS_NOT_FOUND}, { 3, NULL, NULL, 0, STATUS_NOT_FOUND}, { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS}, { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS}, { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND}, { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},};#define NB_FIND_CH_IN_USTR (sizeof(find_ch_in_ustr)/sizeof(*find_ch_in_ustr))static void test_RtlFindCharInUnicodeString(void){ WCHAR main_str_buf[257]; WCHAR search_chars_buf[257]; UNICODE_STRING main_str; UNICODE_STRING search_chars; USHORT pos; NTSTATUS result; size_t idx; size_t test_num; for (test_num = 0; test_num < NB_FIND_CH_IN_USTR; test_num++) { if (find_ch_in_ustr[test_num].main_str != NULL) { main_str.Length = strlen(find_ch_in_ustr[test_num].main_str) * sizeof(WCHAR); main_str.MaximumLength = main_str.Length + sizeof(WCHAR); for (idx = 0; idx < main_str.Length / sizeof(WCHAR); idx++) { main_str_buf[idx] = find_ch_in_ustr[test_num].main_str[idx]; } /* for */ main_str.Buffer = main_str_buf; } else { main_str.Length = 0; main_str.MaximumLength = 0; main_str.Buffer = NULL; } /* if */ if (find_ch_in_ustr[test_num].search_chars != NULL) { search_chars.Length = strlen(find_ch_in_ustr[test_num].search_chars) * sizeof(WCHAR); search_chars.MaximumLength = search_chars.Length + sizeof(WCHAR); for (idx = 0; idx < search_chars.Length / sizeof(WCHAR); idx++) { search_chars_buf[idx] = find_ch_in_ustr[test_num].search_chars[idx]; } /* for */ search_chars.Buffer = search_chars_buf; } else { search_chars.Length = 0; search_chars.MaximumLength = 0; search_chars.Buffer = NULL; } /* if */ pos = 12345; result = pRtlFindCharInUnicodeString(find_ch_in_ustr[test_num].flags, &main_str, &search_chars, &pos); ok(result == find_ch_in_ustr[test_num].result, "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %lx, expected %lx", test_num, find_ch_in_ustr[test_num].flags, find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars, result, find_ch_in_ustr[test_num].result); ok(pos == find_ch_in_ustr[test_num].pos, "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d", test_num, find_ch_in_ustr[test_num].flags, find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars, pos, find_ch_in_ustr[test_num].pos); } /* for */}typedef struct { int base; const char *str; int value; NTSTATUS result;} str2int_t;static const str2int_t str2int[] = { { 0, "1011101100", 1011101100, STATUS_SUCCESS}, { 0, "1234567", 1234567, STATUS_SUCCESS}, { 0, "-214", -214, STATUS_SUCCESS}, { 0, "+214", 214, STATUS_SUCCESS}, /* The + sign is allowed also */ { 0, "--214", 0, STATUS_SUCCESS}, /* Do not accept more than one sign */ { 0, "-+214", 0, STATUS_SUCCESS}, { 0, "++214", 0, STATUS_SUCCESS}, { 0, "+-214", 0, STATUS_SUCCESS}, { 0, "\001\002\003\00411", 11, STATUS_SUCCESS}, /* whitespace char 1 to 4 */ { 0, "\005\006\007\01012", 12, STATUS_SUCCESS}, /* whitespace char 5 to 8 */ { 0, "\011\012\013\01413", 13, STATUS_SUCCESS}, /* whitespace char 9 to 12 */ { 0, "\015\016\017\02014", 14, STATUS_SUCCESS}, /* whitespace char 13 to 16 */ { 0, "\021\022\023\02415", 15, STATUS_SUCCESS}, /* whitespace char 17 to 20 */ { 0, "\025\026\027\03016", 16, STATUS_SUCCESS}, /* whitespace char 21 to 24 */ { 0, "\031\032\033\03417", 17, STATUS_SUCCESS}, /* whitespace char 25 to 28 */ { 0, "\035\036\037\04018", 18, STATUS_SUCCESS}, /* whitespace char 29 to 32 */ { 0, " \n \r \t214", 214, STATUS_SUCCESS}, { 0, " \n \r \t+214", 214, STATUS_SUCCESS}, /* Signs can be used after whitespace */ { 0, " \n \r \t-214", -214, STATUS_SUCCESS}, { 0, "+214 0", 214, STATUS_SUCCESS}, /* Space terminates the number */ { 0, " 214.01", 214, STATUS_SUCCESS}, /* Decimal point not accepted */ { 0, " 214,01", 214, STATUS_SUCCESS}, /* Decimal comma not accepted */ { 0, "f81", 0, STATUS_SUCCESS}, { 0, "0x12345", 0x12345, STATUS_SUCCESS}, /* Hex */ { 0, "00x12345", 0, STATUS_SUCCESS}, { 0, "0xx12345", 0, STATUS_SUCCESS}, { 0, "1x34", 1, STATUS_SUCCESS}, { 0, "-9999999999", -1410065407, STATUS_SUCCESS}, /* Big negative integer */ { 0, "-2147483649", 2147483647, STATUS_SUCCESS}, /* Too small to fit in 32 Bits */ { 0, "-2147483648", 0x80000000L, STATUS_SUCCESS}, /* Smallest negative integer */ { 0, "-2147483647", -2147483647, STATUS_SUCCESS}, { 0, "-1", -1, STATUS_SUCCESS}, { 0, "0", 0, STATUS_SUCCESS}, { 0, "1", 1, STATUS_SUCCESS}, { 0, "2147483646", 2147483646, STATUS_SUCCESS}, { 0, "2147483647", 2147483647, STATUS_SUCCESS}, /* Largest signed positive integer */ { 0, "2147483648", 0x80000000L, STATUS_SUCCESS}, /* Positive int equal to smallest negative int */ { 0, "2147483649", -2147483647, STATUS_SUCCESS}, { 0, "4294967294", -2, STATUS_SUCCESS}, { 0, "4294967295", -1, STATUS_SUCCESS}, /* Largest unsigned integer */ { 0, "4294967296", 0, STATUS_SUCCESS}, /* Too big to fit in 32 Bits */ { 0, "9999999999", 1410065407, STATUS_SUCCESS}, /* Big positive integer */ { 0, "056789", 56789, STATUS_SUCCESS}, /* Leading zero and still decimal */ { 0, "b1011101100", 0, STATUS_SUCCESS}, /* Binary (b-notation) */ { 0, "-b1011101100", 0, STATUS_SUCCESS}, /* Negative Binary (b-notation) */ { 0, "b10123456789", 0, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */ { 0, "0b1011101100", 748, STATUS_SUCCESS}, /* Binary (0b-notation) */ { 0, "-0b1011101100", -748, STATUS_SUCCESS}, /* Negative binary (0b-notation) */ { 0, "0b10123456789", 5, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */ { 0, "-0b10123456789", -5, STATUS_SUCCESS}, /* Negative binary with nonbinary digits (2-9) */ { 0, "0b1", 1, STATUS_SUCCESS}, /* one digit binary */ { 0, "0b2", 0, STATUS_SUCCESS}, /* empty binary */ { 0, "0b", 0, STATUS_SUCCESS}, /* empty binary */ { 0, "o1234567", 0, STATUS_SUCCESS}, /* Octal (o-notation) */ { 0, "-o1234567", 0, STATUS_SUCCESS}, /* Negative Octal (o-notation) */ { 0, "o56789", 0, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */ { 0, "0o1234567", 01234567, STATUS_SUCCESS}, /* Octal (0o-notation) */ { 0, "-0o1234567", -01234567, STATUS_SUCCESS}, /* Negative octal (0o-notation) */ { 0, "0o56789", 0567, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */ { 0, "-0o56789", -0567, STATUS_SUCCESS}, /* Negative octal with nonoctal digits (8 and 9) */ { 0, "0o7", 7, STATUS_SUCCESS}, /* one digit octal */ { 0, "0o8", 0, STATUS_SUCCESS}, /* empty octal */ { 0, "0o", 0, STATUS_SUCCESS}, /* empty octal */ { 0, "0d1011101100", 0, STATUS_SUCCESS}, /* explizit decimal with 0d */ { 0, "x89abcdef", 0, STATUS_SUCCESS}, /* Hex with lower case digits a-f (x-notation) */ { 0, "xFEDCBA00", 0, STATUS_SUCCESS}, /* Hex with upper case digits A-F (x-notation) */ { 0, "-xFEDCBA00", 0, STATUS_SUCCESS}, /* Negative Hexadecimal (x-notation) */ { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS}, /* Hex with lower case digits a-f (0x-notation) */ { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS}, /* Hex with upper case digits A-F (0x-notation) */ { 0, "-0xFEDCBA00", 19088896, STATUS_SUCCESS}, /* Negative Hexadecimal (0x-notation) */ { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS}, /* Hex with illegal lower case digit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -