mirror of
https://github.com/reactos/reactos.git
synced 2024-12-31 19:42:51 +00:00
[NTDLL_APITEST]
- Add a test for RtlGetFullPathName_UstrEx svn path=/trunk/; revision=56229
This commit is contained in:
parent
26eb754f31
commit
1c4bc49902
3 changed files with 355 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
list(APPEND SOURCE
|
||||
NtAllocateVirtualMemory.c
|
||||
NtFreeVirtualMemory.c
|
||||
RtlGetFullPathName_UstrEx.c
|
||||
RtlInitializeBitMap.c
|
||||
SystemInfo.c
|
||||
ZwContinue.c
|
||||
|
@ -12,7 +13,14 @@ if(ARCH MATCHES i386)
|
|||
endif()
|
||||
|
||||
add_executable(ntdll_apitest ${SOURCE})
|
||||
target_link_libraries(ntdll_apitest wine)
|
||||
target_link_libraries(ntdll_apitest wine ${PSEH_LIB})
|
||||
set_module_type(ntdll_apitest win32cui)
|
||||
add_importlibs(ntdll_apitest msvcrt advapi32 kernel32 ntdll)
|
||||
|
||||
if(NOT MSVC)
|
||||
# FIXME: http://www.cmake.org/Bug/view.php?id=12998
|
||||
#add_target_compile_flags(ntdll_apitest "-Wno-format")
|
||||
set_source_files_properties(${SOURCE} PROPERTIES COMPILE_FLAGS "-Wno-format")
|
||||
endif()
|
||||
|
||||
add_cd_file(TARGET ntdll_apitest DESTINATION reactos/bin FOR all)
|
||||
|
|
344
rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c
Normal file
344
rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c
Normal file
|
@ -0,0 +1,344 @@
|
|||
/*
|
||||
* PROJECT: ReactOS api tests
|
||||
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
||||
* PURPOSE: Test for RtlGetFullPathName_UstrEx
|
||||
* PROGRAMMER: Thomas Faber <thfabba@gmx.de>
|
||||
*/
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <wine/test.h>
|
||||
#include <pseh/pseh2.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
/*
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
|
||||
IN PUNICODE_STRING StaticString,
|
||||
IN PUNICODE_STRING DynamicString,
|
||||
IN PUNICODE_STRING *StringUsed,
|
||||
IN PSIZE_T FilePartSize OPTIONAL,
|
||||
OUT PBOOLEAN NameInvalid,
|
||||
OUT RTL_PATH_TYPE* PathType,
|
||||
OUT PSIZE_T LengthNeeded OPTIONAL);
|
||||
*/
|
||||
|
||||
#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)
|
||||
|
||||
#define ok_eq_ustr(str1, str2) do { \
|
||||
ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
|
||||
ok((str1)->Length == (str2)->Length, "Length modified\n"); \
|
||||
ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
|
||||
} while (0)
|
||||
|
||||
static
|
||||
BOOLEAN
|
||||
CheckStringBuffer(
|
||||
PCUNICODE_STRING String,
|
||||
PCWSTR Expected)
|
||||
{
|
||||
USHORT Length = wcslen(Expected) * sizeof(WCHAR);
|
||||
SIZE_T EqualLength;
|
||||
BOOLEAN Result = TRUE;
|
||||
SIZE_T i;
|
||||
|
||||
if (String->Length != Length)
|
||||
{
|
||||
ok(0, "String length is %u, expected %u\n", String->Length, Length);
|
||||
Result = FALSE;
|
||||
}
|
||||
|
||||
EqualLength = RtlCompareMemory(String->Buffer, Expected, Length);
|
||||
if (EqualLength != Length)
|
||||
{
|
||||
ok(0, "String is '%wZ', expected '%S'\n", String, Expected);
|
||||
Result = FALSE;
|
||||
}
|
||||
|
||||
if (String->Buffer[String->Length / sizeof(WCHAR)] != UNICODE_NULL)
|
||||
{
|
||||
ok(0, "Not null terminated\n");
|
||||
Result = FALSE;
|
||||
}
|
||||
|
||||
/* the function nulls the rest of the buffer! */
|
||||
for (i = String->Length + sizeof(UNICODE_NULL); i < String->MaximumLength; i++)
|
||||
{
|
||||
UCHAR Char = ((PUCHAR)String->Buffer)[i];
|
||||
if (Char != 0)
|
||||
{
|
||||
ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char, (ULONG)i, 0);
|
||||
/* don't count this as a failure unless the string was actually wrong */
|
||||
//Result = FALSE;
|
||||
/* don't flood the log */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
#define RtlPathTypeNotSet 123
|
||||
#define InvalidPointer ((PVOID)0x1234)
|
||||
|
||||
/* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
|
||||
#undef broken
|
||||
#define broken(x) 0
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PrefixNone,
|
||||
PrefixCurrentDrive,
|
||||
PrefixCurrentPath,
|
||||
PrefixCurrentPathWithoutLastPart
|
||||
} PREFIX_TYPE;
|
||||
|
||||
static
|
||||
VOID
|
||||
RunTestCases(VOID)
|
||||
{
|
||||
struct
|
||||
{
|
||||
PCWSTR FileName;
|
||||
PREFIX_TYPE PrefixType;
|
||||
PCWSTR FullPathName;
|
||||
RTL_PATH_TYPE PathType;
|
||||
PREFIX_TYPE FilePartPrefixType;
|
||||
SIZE_T FilePartSize;
|
||||
} TestCases[] =
|
||||
{
|
||||
{ L"C:", PrefixCurrentPath, L"", RtlPathTypeDriveRelative, PrefixCurrentPathWithoutLastPart },
|
||||
{ L"C:\\", PrefixNone, L"C:\\", RtlPathTypeDriveAbsolute },
|
||||
{ L"C:\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive },
|
||||
{ L"C:\\test\\", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute },
|
||||
{ L"C:/test/", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute },
|
||||
|
||||
{ L"C:\\\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive },
|
||||
{ L"test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) },
|
||||
{ L"\\test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive },
|
||||
{ L"/test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive },
|
||||
{ L".\\test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) },
|
||||
|
||||
{ L"\\.", PrefixCurrentDrive, L"", RtlPathTypeRooted },
|
||||
{ L"\\.\\", PrefixCurrentDrive, L"", RtlPathTypeRooted },
|
||||
{ L"\\\\.", PrefixNone, L"\\\\.\\", RtlPathTypeRootLocalDevice },
|
||||
{ L"\\\\.\\", PrefixNone, L"\\\\.\\", RtlPathTypeLocalDevice },
|
||||
{ L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\", RtlPathTypeLocalDevice },
|
||||
|
||||
{ L"\\??\\", PrefixCurrentDrive, L"??\\", RtlPathTypeRooted },
|
||||
{ L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", RtlPathTypeRooted, PrefixCurrentDrive, 3 * sizeof(WCHAR) },
|
||||
{ L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\", RtlPathTypeRooted },
|
||||
{ L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", RtlPathTypeRooted, PrefixCurrentDrive, 6 * sizeof(WCHAR) },
|
||||
{ L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\", RtlPathTypeRooted },
|
||||
|
||||
{ L"\\\\??\\", PrefixNone, L"\\\\??\\", RtlPathTypeUncAbsolute },
|
||||
{ L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:", RtlPathTypeUncAbsolute },
|
||||
{ L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\", RtlPathTypeUncAbsolute },
|
||||
{ L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", RtlPathTypeUncAbsolute, PrefixNone, sizeof(L"\\\\??\\C:\\") },
|
||||
{ L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\", RtlPathTypeUncAbsolute },
|
||||
};
|
||||
NTSTATUS Status, ExceptionStatus;
|
||||
UNICODE_STRING FileName;
|
||||
UNICODE_STRING FullPathName;
|
||||
WCHAR FullPathNameBuffer[MAX_PATH];
|
||||
UNICODE_STRING TempString;
|
||||
PUNICODE_STRING StringUsed;
|
||||
SIZE_T FilePartSize;
|
||||
BOOLEAN NameInvalid;
|
||||
RTL_PATH_TYPE PathType;
|
||||
SIZE_T LengthNeeded;
|
||||
WCHAR ExpectedPathName[MAX_PATH];
|
||||
SIZE_T ExpectedFilePartSize;
|
||||
const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]);
|
||||
INT i;
|
||||
|
||||
for (i = 0; i < TestCount; i++)
|
||||
{
|
||||
trace("i = %d\n", i);
|
||||
switch (TestCases[i].PrefixType)
|
||||
{
|
||||
case PrefixNone:
|
||||
ExpectedPathName[0] = UNICODE_NULL;
|
||||
break;
|
||||
case PrefixCurrentDrive:
|
||||
GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
|
||||
ExpectedPathName[3] = UNICODE_NULL;
|
||||
break;
|
||||
case PrefixCurrentPath:
|
||||
GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
|
||||
break;
|
||||
default:
|
||||
skip(0, "Invalid test!\n");
|
||||
continue;
|
||||
}
|
||||
wcscat(ExpectedPathName, TestCases[i].FullPathName);
|
||||
RtlInitUnicodeString(&FileName, TestCases[i].FileName);
|
||||
RtlInitEmptyUnicodeString(&FullPathName, FullPathNameBuffer, sizeof(FullPathNameBuffer));
|
||||
RtlFillMemory(FullPathName.Buffer, FullPathName.MaximumLength, 0xAA);
|
||||
TempString = FileName;
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StringUsed = InvalidPointer;
|
||||
FilePartSize = 1234;
|
||||
NameInvalid = (BOOLEAN)-1;
|
||||
LengthNeeded = 1234;
|
||||
StartSeh()
|
||||
Status = RtlGetFullPathName_UstrEx(&FileName,
|
||||
&FullPathName,
|
||||
NULL,
|
||||
&StringUsed,
|
||||
&FilePartSize,
|
||||
&NameInvalid,
|
||||
&PathType,
|
||||
&LengthNeeded);
|
||||
ok(Status == STATUS_SUCCESS, "status = %lx\n", Status);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
ok(FullPathName.Buffer == FullPathNameBuffer, "Buffer modified\n");
|
||||
ok(FullPathName.MaximumLength == sizeof(FullPathNameBuffer), "MaximumLength modified\n");
|
||||
/* TODO: remove SEH here */
|
||||
StartSeh()
|
||||
ok(CheckStringBuffer(&FullPathName, ExpectedPathName),
|
||||
"Wrong path name '%wZ', expected '%S'\n", &FullPathName, ExpectedPathName);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
ok(StringUsed == &FullPathName, "StringUsed = %p, expected %p\n", StringUsed, &FullPathName);
|
||||
switch (TestCases[i].FilePartPrefixType)
|
||||
{
|
||||
case PrefixNone:
|
||||
ExpectedFilePartSize = 0;
|
||||
break;
|
||||
case PrefixCurrentDrive:
|
||||
ExpectedFilePartSize = sizeof(L"C:\\");
|
||||
break;
|
||||
case PrefixCurrentPath:
|
||||
ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR);
|
||||
break;
|
||||
case PrefixCurrentPathWithoutLastPart:
|
||||
{
|
||||
WCHAR CurrentPath[MAX_PATH];
|
||||
PCWSTR BackSlash;
|
||||
ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
|
||||
BackSlash = wcsrchr(CurrentPath, L'\\');
|
||||
if (BackSlash)
|
||||
ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR);
|
||||
else
|
||||
ok(0, "GetCurrentDirectory returned %S\n", CurrentPath);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
skip(0, "Invalid test!\n");
|
||||
continue;
|
||||
}
|
||||
ExpectedFilePartSize += TestCases[i].FilePartSize;
|
||||
if (ExpectedFilePartSize != 0)
|
||||
ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR);
|
||||
ok(FilePartSize == ExpectedFilePartSize,
|
||||
"FilePartSize = %lu, expected %lu\n", (ULONG)FilePartSize, (ULONG)ExpectedFilePartSize);
|
||||
ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid);
|
||||
ok(PathType == TestCases[i].PathType, "PathType = %d, expected %d\n", PathType, TestCases[i].PathType);
|
||||
ok(LengthNeeded == 0, "LengthNeeded = %lu\n", (ULONG)LengthNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(RtlGetFullPathName_UstrEx)
|
||||
{
|
||||
NTSTATUS Status, ExceptionStatus;
|
||||
UNICODE_STRING FileName;
|
||||
UNICODE_STRING TempString;
|
||||
UNICODE_STRING StaticString;
|
||||
PUNICODE_STRING StringUsed;
|
||||
SIZE_T FilePartSize;
|
||||
BOOLEAN NameInvalid;
|
||||
RTL_PATH_TYPE PathType;
|
||||
SIZE_T LengthNeeded;
|
||||
|
||||
/* NULL parameters */
|
||||
StartSeh()
|
||||
RtlGetFullPathName_UstrEx(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
|
||||
RtlInitUnicodeString(&FileName, L"");
|
||||
TempString = FileName;
|
||||
StartSeh()
|
||||
RtlGetFullPathName_UstrEx(&FileName, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StartSeh()
|
||||
RtlGetFullPathName_UstrEx(NULL, NULL, NULL, NULL, NULL, NULL, &PathType, NULL);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
ok(PathType == RtlPathTypeUnknown ||
|
||||
broken(PathType == RtlPathTypeNotSet) /* Win7 */, "PathType = %d\n", PathType);
|
||||
|
||||
/* check what else is initialized before it crashes */
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StringUsed = InvalidPointer;
|
||||
FilePartSize = 1234;
|
||||
NameInvalid = (BOOLEAN)-1;
|
||||
LengthNeeded = 1234;
|
||||
StartSeh()
|
||||
RtlGetFullPathName_UstrEx(NULL, NULL, NULL, &StringUsed, &FilePartSize, &NameInvalid, &PathType, &LengthNeeded);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
ok(StringUsed == NULL, "StringUsed = %p\n", StringUsed);
|
||||
ok(FilePartSize == 0, "FilePartSize = %lu\n", (ULONG)FilePartSize);
|
||||
ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid);
|
||||
ok(PathType == RtlPathTypeUnknown ||
|
||||
broken(PathType == RtlPathTypeNotSet) /* Win7 */, "PathType = %d\n", PathType);
|
||||
ok(LengthNeeded == 0, "LengthNeeded = %lu\n", (ULONG)LengthNeeded);
|
||||
|
||||
RtlInitUnicodeString(&FileName, L"");
|
||||
TempString = FileName;
|
||||
StringUsed = InvalidPointer;
|
||||
FilePartSize = 1234;
|
||||
NameInvalid = (BOOLEAN)-1;
|
||||
LengthNeeded = 1234;
|
||||
StartSeh()
|
||||
RtlGetFullPathName_UstrEx(&FileName, NULL, NULL, &StringUsed, &FilePartSize, &NameInvalid, NULL, &LengthNeeded);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
ok(StringUsed == NULL, "StringUsed = %p\n", StringUsed);
|
||||
ok(FilePartSize == 0, "FilePartSize = %lu\n", (ULONG)FilePartSize);
|
||||
ok(NameInvalid == FALSE ||
|
||||
broken(NameInvalid == (BOOLEAN)-1) /* Win7 */, "NameInvalid = %u\n", NameInvalid);
|
||||
ok(LengthNeeded == 0, "LengthNeeded = %lu\n", (ULONG)LengthNeeded);
|
||||
|
||||
/* This is the first one that doesn't crash. FileName and PathType cannot be NULL */
|
||||
RtlInitUnicodeString(&FileName, L"");
|
||||
TempString = FileName;
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StartSeh()
|
||||
Status = RtlGetFullPathName_UstrEx(&FileName, NULL, NULL, NULL, NULL, NULL, &PathType, NULL);
|
||||
ok(Status == STATUS_OBJECT_NAME_INVALID, "status = %lx\n", Status);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
ok(PathType == RtlPathTypeUnknown, "PathType = %d\n", PathType);
|
||||
|
||||
/* Give it a valid path */
|
||||
RtlInitUnicodeString(&FileName, L"C:\\test");
|
||||
TempString = FileName;
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StartSeh()
|
||||
Status = RtlGetFullPathName_UstrEx(&FileName, NULL, NULL, NULL, NULL, NULL, &PathType, NULL);
|
||||
ok(Status == STATUS_BUFFER_TOO_SMALL, "status = %lx\n", Status);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
ok(PathType == RtlPathTypeDriveAbsolute, "PathType = %d\n", PathType);
|
||||
|
||||
/* Zero-length static string */
|
||||
RtlInitUnicodeString(&FileName, L"C:\\test");
|
||||
TempString = FileName;
|
||||
RtlInitUnicodeString(&StaticString, NULL);
|
||||
PathType = RtlPathTypeNotSet;
|
||||
StartSeh()
|
||||
Status = RtlGetFullPathName_UstrEx(&FileName, &StaticString, NULL, NULL, NULL, NULL, &PathType, NULL);
|
||||
ok(Status == STATUS_BUFFER_TOO_SMALL, "status = %lx\n", Status);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
ok_eq_ustr(&FileName, &TempString);
|
||||
ok(PathType == RtlPathTypeDriveAbsolute, "PathType = %d\n", PathType);
|
||||
|
||||
/* TODO: play around with StaticString and DynamicString */
|
||||
|
||||
/* check the actual functionality with different paths */
|
||||
RunTestCases();
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
extern void func_NtAllocateVirtualMemory(void);
|
||||
extern void func_NtFreeVirtualMemory(void);
|
||||
extern void func_NtSystemInformation(void);
|
||||
extern void func_RtlGetFullPathName_UstrEx(void);
|
||||
extern void func_RtlInitializeBitMap(void);
|
||||
extern void func_ZwContinue(void);
|
||||
|
||||
|
@ -16,9 +17,9 @@ const struct test winetest_testlist[] =
|
|||
{ "NtAllocateVirtualMemory", func_NtAllocateVirtualMemory },
|
||||
{ "NtFreeVirtualMemory", func_NtFreeVirtualMemory },
|
||||
{ "NtSystemInformation", func_NtSystemInformation },
|
||||
{ "RtlGetFullPathName_UstrEx", func_RtlGetFullPathName_UstrEx },
|
||||
{ "RtlInitializeBitMap", func_RtlInitializeBitMap },
|
||||
{ "ZwContinue", func_ZwContinue },
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue