diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 05d51585536..c98c309070e 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -3,6 +3,7 @@ list(APPEND SOURCE NtAllocateVirtualMemory.c NtFreeVirtualMemory.c RtlDetermineDosPathNameType.c + RtlDoesFileExists.c RtlGetFullPathName_U.c RtlGetFullPathName_Ustr.c RtlGetFullPathName_UstrEx.c diff --git a/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c b/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c index 492d8edbb79..d5c46a6c3b2 100644 --- a/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c +++ b/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c @@ -124,6 +124,7 @@ START_TEST(RtlDetermineDosPathNameType) { L"::", RtlPathTypeDriveRelative }, { L":::", RtlPathTypeDriveRelative }, { L"::::", RtlPathTypeDriveRelative }, + { L"::\\", RtlPathTypeDriveAbsolute }, { L"\\", RtlPathTypeRooted }, { L"\\:", RtlPathTypeRooted }, { L"\\C:", RtlPathTypeRooted }, @@ -175,6 +176,7 @@ START_TEST(RtlDetermineDosPathNameType) { L"/\\.", RtlPathTypeRootLocalDevice }, { L"//./", RtlPathTypeLocalDevice }, { L"//./C:/", RtlPathTypeLocalDevice }, + { L"%SystemRoot%", RtlPathTypeRelative }, }; ULONG i; PWSTR FileName; diff --git a/rostests/apitests/ntdll/RtlDoesFileExists.c b/rostests/apitests/ntdll/RtlDoesFileExists.c new file mode 100644 index 00000000000..8f2ccd22d20 --- /dev/null +++ b/rostests/apitests/ntdll/RtlDoesFileExists.c @@ -0,0 +1,273 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for RtlDoesFileExists_U* + * PROGRAMMER: Thomas Faber + */ + +#define WIN32_NO_STATUS +#define UNICODE +#include +#include +#include +#include + +#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_bool_file(value, expected, file) do { \ + if (expected) \ + ok(value == TRUE, "File '%ls' should exist, but does not\n", file); \ + else \ + ok(value == FALSE, "File '%ls' should not exist, but does\n", file);\ + } while (0) + +#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) + +/* +BOOLEAN +NTAPI +RtlDoesFileExists_U( + IN PCWSTR FileName +); + +BOOLEAN +NTAPI +RtlDoesFileExists_UEx( + IN PCWSTR FileName, + IN BOOLEAN SucceedIfBusy +); + +BOOLEAN +NTAPI +RtlDoesFileExists_UStr( + IN PUNICODE_STRING FileName +); + +BOOLEAN +NTAPI +RtlDoesFileExists_UstrEx( + IN PCUNICODE_STRING FileName, + IN BOOLEAN SucceedIfBusy +); +*/ + +static +BOOLEAN +(NTAPI +*RtlDoesFileExists_UEx)( + IN PCWSTR FileName, + IN BOOLEAN SucceedIfBusy +) +//= (PVOID)0x7c8187d0 // 2003 sp1 x86 +//= (PVOID)0x7769aeb2 // win7 sp1 wow64 +; + +static +BOOLEAN +(NTAPI +*RtlDoesFileExists_UStr)( + IN PUNICODE_STRING FileName +) +//= (PVOID)0x7c8474e5 // 2003 sp1 x86 +//= (PVOID)0x776ff304 // win7 sp1 wow64 +; + +static +BOOLEAN +(NTAPI +*RtlDoesFileExists_UstrEx)( + IN PCUNICODE_STRING FileName, + IN BOOLEAN SucceedIfBusy +) +//= (PVOID)0x7c830f89 // 2003 sp1 x86 +//= (PVOID)0x7769addb // win7 sp1 wow64 +; + +START_TEST(RtlDoesFileExists) +{ + NTSTATUS ExceptionStatus; + BOOLEAN Ret; + struct + { + PCWSTR FileName; + BOOLEAN Exists; + } Tests[] = + { + { L"", FALSE }, + { L"?", FALSE }, + { L"*", FALSE }, + { L":", FALSE }, + { L";", FALSE }, + { L"\"", FALSE }, + { L".", TRUE }, + { L"..", TRUE }, + { L"/", TRUE }, + { L"//", FALSE }, + { L"///", FALSE }, + { L"\\/", FALSE }, + { L"\\//", FALSE }, + { L"\\\\/", FALSE }, + { L"\\/\\", FALSE }, + { L"\\/\\\\", FALSE }, + { L"\\/\\/\\", FALSE }, + { L"\\", TRUE }, + { L"\\\\", FALSE }, + { L"\\\\\\", FALSE }, + { L"\\\\.", FALSE }, + { L"\\\\.\\", FALSE }, + { L"\\\\.\\GLOBAL??", FALSE }, + { L"\\\\.\\GLOBAL??\\", FALSE }, + { L"\\\\?", FALSE }, + { L"\\\\??", FALSE }, + { L"\\\\??\\", FALSE }, + { L"\\\\??\\C:\\", FALSE }, + { L"\\\\.", FALSE }, + { L"\\\\.\\", FALSE }, + { L"C:", TRUE }, + { L"C:/", TRUE }, + { L"C:/\\", TRUE }, + { L"C:\\/", TRUE }, + { L"C:\\/\\", TRUE }, + { L"C://", TRUE }, + { L"C:\\", TRUE }, + { L"C:\\\\", TRUE }, + { L"C:\\%ls", TRUE }, + { L"C:/%ls", TRUE }, + { L"C://%ls", TRUE }, + { L"C:\\/%ls", TRUE }, + { L"C:/\\%ls", TRUE }, + { L"C:\\/\\%ls", TRUE }, + { L"C:\\%ls\\", TRUE }, + { L"C:\\%ls\\ThisFolderExists", TRUE }, + { L"C:\\%ls\\ThisDoesntExist", FALSE }, + { L"C:\\\\%ls\\\\ThisFolderExists", TRUE }, + { L"C:\\%ls\\ThisFolderExists\\ThisFileExists", TRUE }, + { L"c:\\%ls\\thisfolderexists\\thisfileexists", TRUE }, + { L"C:\\%ls\\THISFOLDEREXISTS\\THISFILEEXISTS", TRUE }, + { L"C:\\%ls;C:\\", FALSE }, + { L"%%SystemRoot%%", FALSE }, + { L"%%SystemRoot%%\\", FALSE }, + { L"%%SystemRoot%%\\system32", FALSE }, + { L"NUL", FALSE }, + { L"CON", FALSE }, + { L"COM1", FALSE }, + }; + ULONG i; + WCHAR FileName[MAX_PATH]; + WCHAR CustomPath[MAX_PATH] = L"RtlDoesFileExists_U_TestPath"; + BOOL Success; + HANDLE Handle; + + StartSeh() + Ret = RtlDoesFileExists_U(NULL); + ok(Ret == FALSE, "NULL file exists?!\n"); + EndSeh(STATUS_SUCCESS); + + swprintf(FileName, L"C:\\%ls", CustomPath); + /* Make sure this directory doesn't exist */ + while (GetFileAttributes(FileName) != INVALID_FILE_ATTRIBUTES) + { + wcscat(CustomPath, L"X"); + swprintf(FileName, L"C:\\%ls", CustomPath); + } + Success = CreateDirectory(FileName, NULL); + ok(Success, "CreateDirectory failed, results might not be accurate\n"); + swprintf(FileName, L"C:\\%ls\\ThisFolderExists", CustomPath); + Success = CreateDirectory(FileName, NULL); + ok(Success, "CreateDirectory failed, results might not be accurate\n"); + swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath); + Handle = CreateFile(FileName, 0, 0, NULL, CREATE_NEW, 0, NULL); + ok(Handle != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n"); + if (Handle != INVALID_HANDLE_VALUE) + { + /* Check SucceedIfBusy behavior */ + if (RtlDoesFileExists_UEx) + { + Ret = RtlDoesFileExists_UEx(FileName, TRUE); + ok_bool_file(Ret, TRUE, FileName); + /* TODO: apparently we have to do something worse to make this fail */ + Ret = RtlDoesFileExists_UEx(FileName, FALSE); + ok_bool_file(Ret, TRUE, FileName); + } + if (RtlDoesFileExists_UstrEx) + { + UNICODE_STRING FileNameString; + UNICODE_STRING TempString; + RtlInitUnicodeString(&FileNameString, FileName); + TempString = FileNameString; + Ret = RtlDoesFileExists_UstrEx(&FileNameString, TRUE); + ok_eq_ustr(&FileNameString, &TempString); + ok_bool_file(Ret, TRUE, FileName); + /* TODO: apparently we have to do something worse to make this fail */ + Ret = RtlDoesFileExists_UstrEx(&FileNameString, FALSE); + ok_eq_ustr(&FileNameString, &TempString); + ok_bool_file(Ret, TRUE, FileName); + } + CloseHandle(Handle); + } + + for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++) + { + swprintf(FileName, Tests[i].FileName, CustomPath); + StartSeh() + Ret = RtlDoesFileExists_U(FileName); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + if (RtlDoesFileExists_UEx) + { + StartSeh() + Ret = RtlDoesFileExists_UEx(FileName, TRUE); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + StartSeh() + Ret = RtlDoesFileExists_UEx(FileName, FALSE); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + } + /* TODO: use guarded memory to make sure these don't touch the null terminator */ + if (RtlDoesFileExists_UStr) + { + UNICODE_STRING FileNameString; + UNICODE_STRING TempString; + RtlInitUnicodeString(&FileNameString, FileName); + TempString = FileNameString; + StartSeh() + Ret = RtlDoesFileExists_UStr(&FileNameString); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + ok_eq_ustr(&FileNameString, &TempString); + } + if (RtlDoesFileExists_UstrEx) + { + UNICODE_STRING FileNameString; + UNICODE_STRING TempString; + RtlInitUnicodeString(&FileNameString, FileName); + TempString = FileNameString; + StartSeh() + Ret = RtlDoesFileExists_UstrEx(&FileNameString, TRUE); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + ok_eq_ustr(&FileNameString, &TempString); + StartSeh() + Ret = RtlDoesFileExists_UstrEx(&FileNameString, FALSE); + ok_bool_file(Ret, Tests[i].Exists, FileName); + EndSeh(STATUS_SUCCESS); + ok_eq_ustr(&FileNameString, &TempString); + } + } + + swprintf(FileName, L"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath); + Success = DeleteFile(FileName); + ok(Success, "DeleteFile failed, test might leave stale file\n"); + swprintf(FileName, L"C:\\%ls\\ThisFolderExists", CustomPath); + Success = RemoveDirectory(FileName); + ok(Success, "RemoveDirectory failed, test might leave stale directory\n"); + swprintf(FileName, L"C:\\%ls", CustomPath); + Success = RemoveDirectory(FileName); + ok(Success, "RemoveDirectory failed, test might leave stale directory\n"); +} diff --git a/rostests/apitests/ntdll/RtlGetFullPathName_U.c b/rostests/apitests/ntdll/RtlGetFullPathName_U.c index 7154b8261dc..7f7936d7a64 100644 --- a/rostests/apitests/ntdll/RtlGetFullPathName_U.c +++ b/rostests/apitests/ntdll/RtlGetFullPathName_U.c @@ -91,7 +91,8 @@ static VOID RunTestCases(VOID) { - /* TODO: don't duplicate this here and in the RtlGetFullPathName_UstrEx test */ + /* TODO: don't duplicate this in the other tests */ + /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; diff --git a/rostests/apitests/ntdll/RtlGetFullPathName_Ustr.c b/rostests/apitests/ntdll/RtlGetFullPathName_Ustr.c index d954adee242..9b8d76d1745 100644 --- a/rostests/apitests/ntdll/RtlGetFullPathName_Ustr.c +++ b/rostests/apitests/ntdll/RtlGetFullPathName_Ustr.c @@ -39,7 +39,7 @@ ULONG IN PWSTR Buffer, OUT PCWSTR *ShortName, OUT PBOOLEAN InvalidName, - OUT PATH_TYPE_AND_UNKNOWN* PathType + OUT PATH_TYPE_AND_UNKNOWN *PathType ) //= (PVOID)0x7c83086c // 2003 sp1 x86 //= (PVOID)0x7769a3dd // win7 sp1 wow64 @@ -103,6 +103,25 @@ CheckStringBuffer( return Result; } +static +BOOLEAN +CheckBuffer( + PVOID Buffer, + SIZE_T Size, + UCHAR Value) +{ + PUCHAR Array = Buffer; + SIZE_T i; + + for (i = 0; i < Size; i++) + if (Array[i] != Value) + { + trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i); + return FALSE; + } + return TRUE; +} + #define RtlPathTypeNotSet 123 #define InvalidPointer ((PVOID)0x0123456789ABCDEFULL) @@ -122,7 +141,8 @@ static VOID RunTestCases(VOID) { - /* TODO: don't duplicate this here and in the RtlGetFullPathName_U test */ + /* TODO: don't duplicate this in the other tests */ + /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; @@ -283,6 +303,7 @@ START_TEST(RtlGetFullPathName_Ustr) UNICODE_STRING TempString; PCWSTR ShortName; BOOLEAN NameInvalid; + BOOLEAN NameInvalidArray[sizeof(ULONGLONG)]; PATH_TYPE_AND_UNKNOWN PathType; if (!RtlGetFullPathName_Ustr) @@ -312,10 +333,9 @@ START_TEST(RtlGetFullPathName_Ustr) StartSeh() RtlGetFullPathName_Ustr(NULL, 0, NULL, NULL, NULL, &PathType); EndSeh(STATUS_ACCESS_VIOLATION); - ok(PathType.Type == RtlPathTypeUnknown || - broken(PathType.Type == RtlPathTypeNotSet) /* Win7 */, "PathType = %d\n", PathType.Type); + ok(PathType.Type == RtlPathTypeUnknown, "PathType = %d\n", PathType.Type); ok(PathType.Unknown == 1234 || - broken(PathType.Unknown == 0) /* Win7 */, "Unknown = %d\n", PathType.Unknown); + broken(PathType.Unknown == 0) /* Win7 */, "Unknown = %d\n", PathType.Unknown); /* check what else is initialized before it crashes */ PathType.Type = RtlPathTypeNotSet; @@ -327,9 +347,8 @@ START_TEST(RtlGetFullPathName_Ustr) EndSeh(STATUS_ACCESS_VIOLATION); ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid); ok(ShortName == InvalidPointer || - broken(ShortName == NULL), "ShortName = %p\n", ShortName); - ok(PathType.Type == RtlPathTypeUnknown || - broken(PathType.Type == RtlPathTypeNotSet) /* Win7 */, "PathType = %d\n", PathType.Type); + broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName); + ok(PathType.Type == RtlPathTypeUnknown, "PathType = %d\n", PathType.Type); ok(PathType.Unknown == 1234 || broken(PathType.Unknown == 0) /* Win7 */, "Unknown = %d\n", PathType.Unknown); @@ -342,9 +361,8 @@ START_TEST(RtlGetFullPathName_Ustr) EndSeh(STATUS_ACCESS_VIOLATION); ok_eq_ustr(&FileName, &TempString); ok(ShortName == InvalidPointer || - broken(ShortName == NULL), "ShortName = %p\n", ShortName); - ok(NameInvalid == FALSE || - broken(NameInvalid == (BOOLEAN)-1) /* Win7 */, "NameInvalid = %u\n", NameInvalid); + broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName); + ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid); /* This is the first one that doesn't crash. FileName and PathType cannot be NULL */ RtlInitUnicodeString(&FileName, NULL); @@ -373,6 +391,23 @@ START_TEST(RtlGetFullPathName_Ustr) ok(PathType.Unknown == 1234 || broken(PathType.Unknown == 0) /* Win7 */, "Unknown = %d\n", PathType.Unknown); + /* Show that NameInvalid is indeed BOOLEAN */ + RtlInitUnicodeString(&FileName, L""); + TempString = FileName; + PathType.Type = RtlPathTypeNotSet; + PathType.Unknown = 1234; + RtlFillMemory(NameInvalidArray, sizeof(NameInvalidArray), 0x55); + StartSeh() + Length = RtlGetFullPathName_Ustr(&FileName, 0, NULL, NULL, NameInvalidArray, &PathType); + ok(Length == 0, "Length = %lu\n", Length); + EndSeh(STATUS_SUCCESS); + ok_eq_ustr(&FileName, &TempString); + ok(PathType.Type == RtlPathTypeUnknown, "PathType = %d\n", PathType.Type); + ok(PathType.Unknown == 1234 || + broken(PathType.Unknown == 0) /* Win7 */, "Unknown = %d\n", PathType.Unknown); + ok(NameInvalidArray[0] == FALSE, "NameInvalid = %u\n", NameInvalidArray[0]); + ok(CheckBuffer(NameInvalidArray + 1, sizeof(NameInvalidArray) - sizeof(NameInvalidArray[0]), 0x55), "CheckBuffer failed\n"); + /* Give it a valid path */ RtlInitUnicodeString(&FileName, L"C:\\test"); TempString = FileName; diff --git a/rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c b/rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c index b8d49f8f4e6..8ba69ad745c 100644 --- a/rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c +++ b/rostests/apitests/ntdll/RtlGetFullPathName_UstrEx.c @@ -81,6 +81,25 @@ CheckStringBuffer( return Result; } +static +BOOLEAN +CheckBuffer( + PVOID Buffer, + SIZE_T Size, + UCHAR Value) +{ + PUCHAR Array = Buffer; + SIZE_T i; + + for (i = 0; i < Size; i++) + if (Array[i] != Value) + { + trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i); + return FALSE; + } + return TRUE; +} + #define RtlPathTypeNotSet 123 #define InvalidPointer ((PVOID)0x0123456789ABCDEFULL) @@ -100,7 +119,8 @@ static VOID RunTestCases(VOID) { - /* TODO: don't duplicate this here and in the RtlGetFullPathName_U test */ + /* TODO: don't duplicate this in the other tests */ + /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; @@ -261,6 +281,7 @@ START_TEST(RtlGetFullPathName_UstrEx) PUNICODE_STRING StringUsed; SIZE_T FilePartSize; BOOLEAN NameInvalid; + BOOLEAN NameInvalidArray[sizeof(ULONGLONG)]; RTL_PATH_TYPE PathType; SIZE_T LengthNeeded; @@ -343,6 +364,20 @@ START_TEST(RtlGetFullPathName_UstrEx) ok_eq_ustr(&FileName, &TempString); ok(PathType == RtlPathTypeUnknown, "PathType = %d\n", PathType); + /* Show that NameInvalid is indeed BOOLEAN */ + RtlInitUnicodeString(&FileName, L""); + TempString = FileName; + PathType = RtlPathTypeNotSet; + RtlFillMemory(NameInvalidArray, sizeof(NameInvalidArray), 0x55); + StartSeh() + Status = RtlGetFullPathName_UstrEx(&FileName, NULL, NULL, NULL, NULL, NameInvalidArray, &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); + ok(NameInvalidArray[0] == FALSE, "NameInvalid = %u\n", NameInvalidArray[0]); + ok(CheckBuffer(NameInvalidArray + 1, sizeof(NameInvalidArray) - sizeof(NameInvalidArray[0]), 0x55), "CheckBuffer failed\n"); + /* Give it a valid path */ RtlInitUnicodeString(&FileName, L"C:\\test"); TempString = FileName; diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 89669b7dced..32d45d8f0b8 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -9,6 +9,7 @@ extern void func_NtAllocateVirtualMemory(void); extern void func_NtFreeVirtualMemory(void); extern void func_NtSystemInformation(void); extern void func_RtlDetermineDosPathNameType(void); +extern void func_RtlDoesFileExists(void); extern void func_RtlGetFullPathName_U(void); extern void func_RtlGetFullPathName_Ustr(void); extern void func_RtlGetFullPathName_UstrEx(void); @@ -22,6 +23,7 @@ const struct test winetest_testlist[] = { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, { "NtSystemInformation", func_NtSystemInformation }, { "RtlDetermineDosPathNameType", func_RtlDetermineDosPathNameType }, + { "RtlDoesFileExists", func_RtlDoesFileExists }, { "RtlGetFullPathName_U", func_RtlGetFullPathName_U }, { "RtlGetFullPathName_Ustr", func_RtlGetFullPathName_Ustr }, { "RtlGetFullPathName_UstrEx", func_RtlGetFullPathName_UstrEx },