⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtlstr.c

📁 Wine-20031016
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Unit test suite for Rtl string functions * * Copyright 2002 Robert Shearman * Copyright 2003 Thomas Mertes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * NOTES * We use function pointers here as there is no import library for NTDLL on * windows. */#include <stdarg.h>#include <stdlib.h>#include "ntstatus.h"#include "windef.h"#include "winbase.h"#include "wine/test.h"#include "winnt.h"#include "winnls.h"#include "winreg.h"#include "winternl.h"/* Function ptrs for ntdll calls */static HMODULE hntdll = 0;static NTSTATUS (WINAPI *pRtlAnsiStringToUnicodeString)(PUNICODE_STRING, PCANSI_STRING, BOOLEAN);static NTSTATUS (WINAPI *pRtlAppendAsciizToString)(STRING *, LPCSTR);static NTSTATUS (WINAPI *pRtlAppendStringToString)(STRING *, const STRING *);static NTSTATUS (WINAPI *pRtlAppendUnicodeStringToString)(UNICODE_STRING *, const UNICODE_STRING *);static NTSTATUS (WINAPI *pRtlAppendUnicodeToString)(UNICODE_STRING *, LPCWSTR);static NTSTATUS (WINAPI *pRtlCharToInteger)(PCSZ, ULONG, int *);static VOID     (WINAPI *pRtlCopyString)(STRING *, const STRING *);static BOOLEAN  (WINAPI *pRtlCreateUnicodeString)(PUNICODE_STRING, LPCWSTR);static BOOLEAN  (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, LPCSTR);static NTSTATUS (WINAPI *pRtlDowncaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);static NTSTATUS (WINAPI *pRtlDuplicateUnicodeString)(long, UNICODE_STRING *, UNICODE_STRING *);static BOOLEAN  (WINAPI *pRtlEqualUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);static NTSTATUS (WINAPI *pRtlFindCharInUnicodeString)(int, const UNICODE_STRING *, const UNICODE_STRING *, USHORT *);static VOID     (WINAPI *pRtlFreeAnsiString)(PSTRING);static VOID     (WINAPI *pRtlInitAnsiString)(PSTRING, LPCSTR);static VOID     (WINAPI *pRtlInitString)(PSTRING, LPCSTR);static VOID     (WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING, LPCWSTR);static NTSTATUS (WINAPI *pRtlInitUnicodeStringEx)(PUNICODE_STRING, LPCWSTR);static NTSTATUS (WINAPI *pRtlIntegerToChar)(ULONG, ULONG, ULONG, PCHAR);static NTSTATUS (WINAPI *pRtlIntegerToUnicodeString)(ULONG, ULONG, UNICODE_STRING *);static NTSTATUS (WINAPI *pRtlMultiAppendUnicodeStringBuffer)(UNICODE_STRING *, long, UNICODE_STRING *);static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);static NTSTATUS (WINAPI *pRtlUnicodeStringToInteger)(const UNICODE_STRING *, int, int *);static WCHAR    (WINAPI *pRtlUpcaseUnicodeChar)(WCHAR);static NTSTATUS (WINAPI *pRtlUpcaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);static CHAR     (WINAPI *pRtlUpperChar)(CHAR);static NTSTATUS (WINAPI *pRtlUpperString)(STRING *, const STRING *);static NTSTATUS (WINAPI *pRtlValidateUnicodeString)(long, UNICODE_STRING *);/*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*//*static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);*//*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*//*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*//*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*//*static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING *,const UNICODE_STRING *,BOOLEAN);*//*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*//*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*//*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*//*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*//*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*//*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*//*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*//*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*//*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*//*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*//*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*//*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*//*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*//*static DWORD (WINAPI *pRtlIsTextUnicode)(LPVOID, DWORD, DWORD *);*/static WCHAR* AtoW( const char* p ){    WCHAR* buffer;    DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );    buffer = malloc( len * sizeof(WCHAR) );    MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len );    return buffer;}static void InitFunctionPtrs(void){    hntdll = LoadLibraryA("ntdll.dll");    ok(hntdll != 0, "LoadLibrary failed");    if (hntdll) {	pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");	pRtlAppendAsciizToString = (void *)GetProcAddress(hntdll, "RtlAppendAsciizToString");	pRtlAppendStringToString = (void *)GetProcAddress(hntdll, "RtlAppendStringToString");	pRtlAppendUnicodeStringToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeStringToString");	pRtlAppendUnicodeToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeToString");	pRtlCharToInteger = (void *)GetProcAddress(hntdll, "RtlCharToInteger");	pRtlCopyString = (void *)GetProcAddress(hntdll, "RtlCopyString");	pRtlCreateUnicodeString = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeString");	pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");	pRtlDowncaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlDowncaseUnicodeString");	pRtlDuplicateUnicodeString = (void *)GetProcAddress(hntdll, "RtlDuplicateUnicodeString");	pRtlEqualUnicodeString = (void *)GetProcAddress(hntdll, "RtlEqualUnicodeString");	pRtlFindCharInUnicodeString = (void *)GetProcAddress(hntdll, "RtlFindCharInUnicodeString");	pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");	pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");	pRtlInitString = (void *)GetProcAddress(hntdll, "RtlInitString");	pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");	pRtlInitUnicodeStringEx = (void *)GetProcAddress(hntdll, "RtlInitUnicodeStringEx");	pRtlIntegerToChar = (void *)GetProcAddress(hntdll, "RtlIntegerToChar");	pRtlIntegerToUnicodeString = (void *)GetProcAddress(hntdll, "RtlIntegerToUnicodeString");	pRtlMultiAppendUnicodeStringBuffer = (void *)GetProcAddress(hntdll, "RtlMultiAppendUnicodeStringBuffer");	pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");	pRtlUnicodeStringToInteger = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToInteger");	pRtlUpcaseUnicodeChar = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeChar");	pRtlUpcaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeString");	pRtlUpperChar = (void *)GetProcAddress(hntdll, "RtlUpperChar");	pRtlUpperString = (void *)GetProcAddress(hntdll, "RtlUpperString");	pRtlValidateUnicodeString = (void *)GetProcAddress(hntdll, "RtlValidateUnicodeString");    } /* if */}static void test_RtlInitString(void){    static const char teststring[] = "Some Wild String";    STRING str;    str.Length = 0;    str.MaximumLength = 0;    str.Buffer = (void *)0xdeadbeef;    pRtlInitString(&str, teststring);    ok(str.Length == sizeof(teststring) - sizeof(char), "Length uninitialized");    ok(str.MaximumLength == sizeof(teststring), "MaximumLength uninitialized");    ok(str.Buffer == teststring, "Buffer not equal to teststring");    ok(strcmp(str.Buffer, "Some Wild String") == 0, "Buffer written to");    pRtlInitString(&str, NULL);    ok(str.Length == 0, "Length uninitialized");    ok(str.MaximumLength == 0, "MaximumLength uninitialized");    ok(str.Buffer == NULL, "Buffer not equal to NULL");/*  pRtlInitString(NULL, teststring); */}static void test_RtlInitUnicodeString(void){#define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}    static const WCHAR teststring[] = STRINGW;    static const WCHAR originalstring[] = STRINGW;#undef STRINGW    UNICODE_STRING uni;    uni.Length = 0;    uni.MaximumLength = 0;    uni.Buffer = (void *)0xdeadbeef;    pRtlInitUnicodeString(&uni, teststring);    ok(uni.Length == sizeof(teststring) - sizeof(WCHAR), "Length uninitialized");    ok(uni.MaximumLength == sizeof(teststring), "MaximumLength uninitialized");    ok(uni.Buffer == teststring, "Buffer not equal to teststring");    ok(lstrcmpW(uni.Buffer, originalstring) == 0, "Buffer written to");    pRtlInitUnicodeString(&uni, NULL);    ok(uni.Length == 0, "Length uninitialized");    ok(uni.MaximumLength == 0, "MaximumLength uninitialized");    ok(uni.Buffer == NULL, "Buffer not equal to NULL");/*  pRtlInitUnicodeString(NULL, teststring); */}#define TESTSTRING2_LEN 1000000/* #define TESTSTRING2_LEN 32766 */static void test_RtlInitUnicodeStringEx(void){    WCHAR teststring[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};    WCHAR *teststring2;    UNICODE_STRING uni;    NTSTATUS result;    teststring2 = (WCHAR *) malloc((TESTSTRING2_LEN + 1) * sizeof(WCHAR));    memset(teststring2, 'X', TESTSTRING2_LEN * sizeof(WCHAR));    teststring2[TESTSTRING2_LEN] = '\0';    uni.Length = 12345;    uni.MaximumLength = 12345;    uni.Buffer = (void *) 0xdeadbeef;    result = pRtlInitUnicodeStringEx(&uni, teststring);    ok(result == STATUS_SUCCESS,       "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x",       result, STATUS_SUCCESS);    ok(uni.Length == 32,       "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u",       uni.Length, 32);    ok(uni.MaximumLength == 34,       "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u",       uni.MaximumLength, 34);    ok(uni.Buffer == teststring,       "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p",       uni.Buffer, teststring);    uni.Length = 12345;    uni.MaximumLength = 12345;    uni.Buffer = (void *) 0xdeadbeef;    pRtlInitUnicodeString(&uni, teststring);    ok(uni.Length == 32,       "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u",       uni.Length, 32);    ok(uni.MaximumLength == 34,       "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u",       uni.MaximumLength, 34);    ok(uni.Buffer == teststring,       "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p",       uni.Buffer, teststring);    uni.Length = 12345;    uni.MaximumLength = 12345;    uni.Buffer = (void *) 0xdeadbeef;    result = pRtlInitUnicodeStringEx(&uni, teststring2);    ok(result == STATUS_NAME_TOO_LONG,       "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x",       result, STATUS_NAME_TOO_LONG);    ok(uni.Length == 12345,       "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u",       uni.Length, 12345);    ok(uni.MaximumLength == 12345,       "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u",       uni.MaximumLength, 12345);    ok(uni.Buffer == (void *) 0xdeadbeef,       "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x",       uni.Buffer, 0xdeadbeef);    uni.Length = 12345;    uni.MaximumLength = 12345;    uni.Buffer = (void *) 0xdeadbeef;    pRtlInitUnicodeString(&uni, teststring2);    ok(uni.Length == 33920,       "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u",       uni.Length, 33920);    ok(uni.MaximumLength == 33922,       "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u",       uni.MaximumLength, 33922);    ok(uni.Buffer == teststring2,       "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p",       uni.Buffer, teststring2);    ok(memcmp(uni.Buffer, teststring2, (TESTSTRING2_LEN + 1) * sizeof(WCHAR)) == 0,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -