📄 rtlstr.c
字号:
"pRtlInitUnicodeString(&uni, 0) changes Buffer"); uni.Length = 12345; uni.MaximumLength = 12345; uni.Buffer = (void *) 0xdeadbeef; result = pRtlInitUnicodeStringEx(&uni, 0); ok(result == STATUS_SUCCESS, "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x", result, STATUS_SUCCESS); ok(uni.Length == 0, "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u", uni.Length, 0); ok(uni.MaximumLength == 0, "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u", uni.MaximumLength, 0); ok(uni.Buffer == NULL, "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p", uni.Buffer, NULL); uni.Length = 12345; uni.MaximumLength = 12345; uni.Buffer = (void *) 0xdeadbeef; pRtlInitUnicodeString(&uni, 0); ok(uni.Length == 0, "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u", uni.Length, 0); ok(uni.MaximumLength == 0, "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u", uni.MaximumLength, 0); ok(uni.Buffer == NULL, "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p", uni.Buffer, NULL);}typedef struct { int add_nul; int source_Length; int source_MaximumLength; int source_buf_size; const char *source_buf; int dest_Length; int dest_MaximumLength; int dest_buf_size; const char *dest_buf; int res_Length; int res_MaximumLength; int res_buf_size; const char *res_buf; NTSTATUS result;} dupl_ustr_t;static const dupl_ustr_t dupl_ustr[] = { { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS}, { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS}, { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS}, { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS}, { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 1, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 1, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS}, { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 0, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 0, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 0, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 0, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 0, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 0, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 1, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS}, { 1, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 1, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS}, { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 0, 2, 2, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 0, 0, 0, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 2, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 2, 0, 0, 0, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS}, { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS}, { 3, 0, 2, 2, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS}, { 3, 0, 0, 0, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS}, { 3, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER}, { 3, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS}, { 3, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 3, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},};#define NB_DUPL_USTR (sizeof(dupl_ustr)/sizeof(*dupl_ustr))static void test_RtlDuplicateUnicodeString(void){ size_t pos; WCHAR source_buf[257]; WCHAR dest_buf[257]; WCHAR res_buf[257]; UNICODE_STRING source_str; UNICODE_STRING dest_str; UNICODE_STRING res_str; CHAR dest_ansi_buf[257]; STRING dest_ansi_str; NTSTATUS result; size_t test_num; for (test_num = 0; test_num < NB_DUPL_USTR; test_num++) { source_str.Length = dupl_ustr[test_num].source_Length; source_str.MaximumLength = dupl_ustr[test_num].source_MaximumLength; if (dupl_ustr[test_num].source_buf != NULL) { for (pos = 0; pos < dupl_ustr[test_num].source_buf_size/sizeof(WCHAR); pos++) { source_buf[pos] = dupl_ustr[test_num].source_buf[pos]; } /* for */ source_str.Buffer = source_buf; } else { source_str.Buffer = NULL; } /* if */ dest_str.Length = dupl_ustr[test_num].dest_Length; dest_str.MaximumLength = dupl_ustr[test_num].dest_MaximumLength; if (dupl_ustr[test_num].dest_buf != NULL) { for (pos = 0; pos < dupl_ustr[test_num].dest_buf_size/sizeof(WCHAR); pos++) { dest_buf[pos] = dupl_ustr[test_num].dest_buf[pos]; } /* for */ dest_str.Buffer = dest_buf; } else { dest_str.Buffer = NULL; } /* if */ res_str.Length = dupl_ustr[test_num].res_Length; res_str.MaximumLength = dupl_ustr[test_num].res_MaximumLength; if (dupl_ustr[test_num].res_buf != NULL) { for (pos = 0; pos < dupl_ustr[test_num].res_buf_size/sizeof(WCHAR); pos++) { res_buf[pos] = dupl_ustr[test_num].res_buf[pos]; } /* for */ res_str.Buffer = res_buf; } else { res_str.Buffer = NULL; } /* if */ result = pRtlDuplicateUnicodeString(dupl_ustr[test_num].add_nul, &source_str, &dest_str); dest_ansi_str.Length = dest_str.Length / sizeof(WCHAR); dest_ansi_str.MaximumLength = dest_ansi_str.Length + 1; for (pos = 0; pos < dest_ansi_str.Length; pos++) { dest_ansi_buf[pos] = (char)dest_buf[pos]; } /* for */ dest_ansi_buf[dest_ansi_str.Length] = '\0'; dest_ansi_str.Buffer = dest_ansi_buf; ok(result == dupl_ustr[test_num].result, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %lx, expected %lx", test_num, dupl_ustr[test_num].add_nul, result, dupl_ustr[test_num].result); ok(dest_str.Length == dupl_ustr[test_num].res_Length, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d", test_num, dupl_ustr[test_num].add_nul, dest_str.Length, dupl_ustr[test_num].res_Length); ok(dest_str.MaximumLength == dupl_ustr[test_num].res_MaximumLength, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d", test_num, dupl_ustr[test_num].add_nul, dest_str.MaximumLength, dupl_ustr[test_num].res_MaximumLength); if (result == STATUS_INVALID_PARAMETER) { ok((dest_str.Buffer == NULL && res_str.Buffer == NULL) || dest_str.Buffer == dest_buf, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p", test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dest_buf); } else { ok(dest_str.Buffer != dest_buf, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p", test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer); } /* if */ if (dest_str.Buffer != NULL && dupl_ustr[test_num].res_buf != NULL) { ok(memcmp(dest_str.Buffer, res_str.Buffer, dupl_ustr[test_num].res_buf_size) == 0, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"", test_num, dupl_ustr[test_num].add_nul, dest_ansi_str.Buffer, dupl_ustr[test_num].res_buf); } else { ok(dest_str.Buffer == NULL && dupl_ustr[test_num].res_buf == NULL, "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p", test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dupl_ustr[test_num].res_buf); } /* if */ } /* for */}static void test_RtlCopyString(void){ static const char teststring[] = "Some Wild String"; static char deststring[] = " "; STRING str; STRING deststr; pRtlInitString(&str, teststring); pRtlInitString(&deststr, deststring); pRtlCopyString(&deststr, &str); ok(strncmp(str.Buffer, deststring, str.Length) == 0, "String not copied");}static void test_RtlUpperChar(void){ int ch; int upper_ch; int expected_upper_ch; int byte_ch; for (ch = -1; ch <= 1024; ch++) { upper_ch = pRtlUpperChar(ch); byte_ch = ch & 0xff; if (byte_ch >= 'a' && byte_ch <= 'z') { expected_upper_ch = (CHAR) (byte_ch - 'a' + 'A'); } else { expected_upper_ch = (CHAR) byte_ch; } /* if */ ok(upper_ch == expected_upper_ch, "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]", ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch); } /* for */}static void test_RtlUpperString(void){ int i; CHAR ch; CHAR upper_ch; char ascii_buf[257]; char result_buf[257]; char upper_buf[257];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -