From fb43dc26f7090a7489b466be7ea262a6d7fed0db Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Wed, 25 Apr 2012 07:43:33 +0000 Subject: [PATCH] [NTDLL_APITEST] - Add test for RtlGetLongestNtPathLength - Add test for RtlDetermineDosPathNameType_U (and RtlDetermineDosPathNameType_Ustr, if address is known) svn path=/trunk/; revision=56411 --- rostests/apitests/ntdll/CMakeLists.txt | 2 + .../ntdll/RtlDetermineDosPathNameType.c | 203 ++++++++++++++++++ .../ntdll/RtlGetLongestNtPathLength.c | 24 +++ rostests/apitests/ntdll/testlist.c | 18 +- 4 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 rostests/apitests/ntdll/RtlDetermineDosPathNameType.c create mode 100644 rostests/apitests/ntdll/RtlGetLongestNtPathLength.c diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 32caae5ff5f..ad5d2e6ce08 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -2,8 +2,10 @@ list(APPEND SOURCE NtAllocateVirtualMemory.c NtFreeVirtualMemory.c + RtlDetermineDosPathNameType.c RtlGetFullPathName_U.c RtlGetFullPathName_UstrEx.c + RtlGetLongestNtPathLength.c RtlInitializeBitMap.c SystemInfo.c ZwContinue.c diff --git a/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c b/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c new file mode 100644 index 00000000000..5dee20057e4 --- /dev/null +++ b/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c @@ -0,0 +1,203 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for RtlDetermineDosPathNameType_U/RtlDetermineDosPathNameType_Ustr + * PROGRAMMER: Thomas Faber + */ + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +/* +ULONG +NTAPI +RtlDetermineDosPathNameType_U( + IN PCWSTR Path +); + +ULONG +NTAPI +RtlDetermineDosPathNameType_Ustr( + IN PCUNICODE_STRING Path +); +*/ + +static +ULONG +(NTAPI +*RtlDetermineDosPathNameType_Ustr)( + IN PCUNICODE_STRING Path +) +//= (PVOID)0x7c830669; +; + +static +PVOID +AllocateGuarded( + SIZE_T SizeRequested) +{ + NTSTATUS Status; + SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); + PVOID VirtualMemory = NULL; + PCHAR StartOfBuffer; + + Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); + + if (!NT_SUCCESS(Status)) + return NULL; + + Size -= PAGE_SIZE; + if (Size) + { + Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); + if (!NT_SUCCESS(Status)) + { + Size = 0; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); + ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); + return NULL; + } + } + + StartOfBuffer = VirtualMemory; + StartOfBuffer += Size - SizeRequested; + + return StartOfBuffer; +} + +static +VOID +FreeGuarded( + PVOID Pointer) +{ + NTSTATUS Status; + PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); + SIZE_T Size = 0; + + Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); + ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); +} + +#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY { +#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus) + +START_TEST(RtlDetermineDosPathNameType) +{ + NTSTATUS ExceptionStatus; + RTL_PATH_TYPE PathType; + struct + { + PCWSTR FileName; + RTL_PATH_TYPE PathType; + } Tests[] = + { + { L"", RtlPathTypeRelative }, + { L"xyz", RtlPathTypeRelative }, + { L"CON", RtlPathTypeRelative }, + { L"NUL", RtlPathTypeRelative }, + { L":", RtlPathTypeRelative }, + { L"::", RtlPathTypeDriveRelative }, + { L":::", RtlPathTypeDriveRelative }, + { L"::::", RtlPathTypeDriveRelative }, + { L"\\", RtlPathTypeRooted }, + { L"\\:", RtlPathTypeRooted }, + { L"\\C:", RtlPathTypeRooted }, + { L"\\C:\\", RtlPathTypeRooted }, + { L"/", RtlPathTypeRooted }, + { L"/:", RtlPathTypeRooted }, + { L"/C:", RtlPathTypeRooted }, + { L"/C:/", RtlPathTypeRooted }, + { L"C", RtlPathTypeRelative }, + { L"C:", RtlPathTypeDriveRelative }, + { L"C:a", RtlPathTypeDriveRelative }, + { L"C:a\\", RtlPathTypeDriveRelative }, + { L"C:\\", RtlPathTypeDriveAbsolute }, + { L"C:/", RtlPathTypeDriveAbsolute }, + { L"C:\\a", RtlPathTypeDriveAbsolute }, + { L"C:/a", RtlPathTypeDriveAbsolute }, + { L"C:\\\\", RtlPathTypeDriveAbsolute }, + { L"\\\\", RtlPathTypeUncAbsolute }, + { L"\\\\\\", RtlPathTypeUncAbsolute }, + { L"\\\\;", RtlPathTypeUncAbsolute }, + { L"\\??\\", RtlPathTypeRooted }, + { L"\\??\\UNC", RtlPathTypeRooted }, + { L"\\??\\UNC\\", RtlPathTypeRooted }, + { L"\\?", RtlPathTypeRooted }, + { L"\\?\\", RtlPathTypeRooted }, + { L"\\?\\UNC", RtlPathTypeRooted }, + { L"\\?\\UNC\\", RtlPathTypeRooted }, + { L"\\\\?\\UNC\\", RtlPathTypeLocalDevice }, + { L"\\\\?", RtlPathTypeRootLocalDevice }, + { L"\\\\??", RtlPathTypeUncAbsolute }, + { L"\\\\??\\", RtlPathTypeUncAbsolute }, + { L"\\\\??\\C:\\", RtlPathTypeUncAbsolute }, + { L"\\\\.", RtlPathTypeRootLocalDevice }, + { L"\\\\.\\", RtlPathTypeLocalDevice }, + { L"\\\\.\\C:\\", RtlPathTypeLocalDevice }, + { L"\\/", RtlPathTypeUncAbsolute }, + { L"/\\", RtlPathTypeUncAbsolute }, + { L"//", RtlPathTypeUncAbsolute }, + { L"///", RtlPathTypeUncAbsolute }, + { L"//;", RtlPathTypeUncAbsolute }, + { L"//?", RtlPathTypeRootLocalDevice }, + { L"/\\?", RtlPathTypeRootLocalDevice }, + { L"\\/?", RtlPathTypeRootLocalDevice }, + { L"//??", RtlPathTypeUncAbsolute }, + { L"//??/", RtlPathTypeUncAbsolute }, + { L"//??/C:/", RtlPathTypeUncAbsolute }, + { L"//.", RtlPathTypeRootLocalDevice }, + { L"\\/.", RtlPathTypeRootLocalDevice }, + { L"/\\.", RtlPathTypeRootLocalDevice }, + { L"//./", RtlPathTypeLocalDevice }, + { L"//./C:/", RtlPathTypeLocalDevice }, + }; + ULONG i; + PWSTR FileName; + USHORT Length; + + if (!RtlDetermineDosPathNameType_Ustr) + skip(0, "RtlDetermineDosPathNameType_Ustr unavailable\n"); + + StartSeh() RtlDetermineDosPathNameType_U(NULL); EndSeh(STATUS_ACCESS_VIOLATION); + + if (RtlDetermineDosPathNameType_Ustr) + { + UNICODE_STRING PathString; + StartSeh() RtlDetermineDosPathNameType_Ustr(NULL); EndSeh(STATUS_ACCESS_VIOLATION); + + RtlInitEmptyUnicodeString(&PathString, NULL, MAXUSHORT); + PathType = RtlDetermineDosPathNameType_Ustr(&PathString); + ok(PathType == RtlPathTypeRelative, "PathType = %d\n", PathType); + } + + for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++) + { + Length = (USHORT)wcslen(Tests[i].FileName) * sizeof(WCHAR); + FileName = AllocateGuarded(Length + sizeof(UNICODE_NULL)); + RtlCopyMemory(FileName, Tests[i].FileName, Length + sizeof(UNICODE_NULL)); + StartSeh() + PathType = RtlDetermineDosPathNameType_U(FileName); + EndSeh(STATUS_SUCCESS); + ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName); + FreeGuarded(FileName); + + if (RtlDetermineDosPathNameType_Ustr) + { + UNICODE_STRING PathString; + + FileName = AllocateGuarded(Length); + RtlCopyMemory(FileName, Tests[i].FileName, Length); + PathString.Buffer = FileName; + PathString.Length = Length; + PathString.MaximumLength = MAXUSHORT; + StartSeh() + PathType = RtlDetermineDosPathNameType_Ustr(&PathString); + EndSeh(STATUS_SUCCESS); + ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName); + FreeGuarded(FileName); + } + } +} diff --git a/rostests/apitests/ntdll/RtlGetLongestNtPathLength.c b/rostests/apitests/ntdll/RtlGetLongestNtPathLength.c new file mode 100644 index 00000000000..8dc34d6632e --- /dev/null +++ b/rostests/apitests/ntdll/RtlGetLongestNtPathLength.c @@ -0,0 +1,24 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for RtlGetLongestNtPathLength + * PROGRAMMER: Thomas Faber + */ + +#define WIN32_NO_STATUS +#include +#include + +/* +ULONG +NTAPI +RtlGetLongestNtPathLength(VOID); +*/ + +START_TEST(RtlGetLongestNtPathLength) +{ + ULONG Length; + + Length = RtlGetLongestNtPathLength(); + ok(Length == 269, "Length = %lu\n", Length); +} diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 0cc186662bf..1a714b21d71 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -8,20 +8,24 @@ extern void func_NtAllocateVirtualMemory(void); extern void func_NtFreeVirtualMemory(void); extern void func_NtSystemInformation(void); +extern void func_RtlDetermineDosPathNameType(void); extern void func_RtlGetFullPathName_U(void); extern void func_RtlGetFullPathName_UstrEx(void); +extern void func_RtlGetLongestNtPathLength(void); extern void func_RtlInitializeBitMap(void); extern void func_ZwContinue(void); const struct test winetest_testlist[] = { - { "NtAllocateVirtualMemory", func_NtAllocateVirtualMemory }, - { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, - { "NtSystemInformation", func_NtSystemInformation }, - { "RtlGetFullPathName_U", func_RtlGetFullPathName_U }, - { "RtlGetFullPathName_UstrEx", func_RtlGetFullPathName_UstrEx }, - { "RtlInitializeBitMap", func_RtlInitializeBitMap }, - { "ZwContinue", func_ZwContinue }, + { "NtAllocateVirtualMemory", func_NtAllocateVirtualMemory }, + { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, + { "NtSystemInformation", func_NtSystemInformation }, + { "RtlDetermineDosPathNameType", func_RtlDetermineDosPathNameType }, + { "RtlGetFullPathName_U", func_RtlGetFullPathName_U }, + { "RtlGetFullPathName_UstrEx", func_RtlGetFullPathName_UstrEx }, + { "RtlGetLongestNtPathLength", func_RtlGetLongestNtPathLength }, + { "RtlInitializeBitMap", func_RtlInitializeBitMap }, + { "ZwContinue", func_ZwContinue }, { 0, 0 } }; -- 2.17.1