[NTDLL_WINETEST]

- Fix running RtlGetFullPathName_UstrEx test from drive root
- Add a test for RtlGetFullPathName_U based on the same test cases

svn path=/trunk/; revision=56230
This commit is contained in:
Thomas Faber 2012-03-25 21:24:05 +00:00
parent 1c4bc49902
commit 5c2322f0f8
4 changed files with 304 additions and 5 deletions

View file

@ -2,6 +2,7 @@
list(APPEND SOURCE
NtAllocateVirtualMemory.c
NtFreeVirtualMemory.c
RtlGetFullPathName_U.c
RtlGetFullPathName_UstrEx.c
RtlInitializeBitMap.c
SystemInfo.c

View file

@ -0,0 +1,283 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPLv2+ - See COPYING in the top level directory
* PURPOSE: Test for RtlGetFullPathName_U
* PROGRAMMER: Thomas Faber <thfabba@gmx.de>
*/
#define WIN32_NO_STATUS
#include <wine/test.h>
#include <pseh/pseh2.h>
#include <ndk/rtlfuncs.h>
/*
ULONG
NTAPI
RtlGetFullPathName_U(
IN PCWSTR FileName,
IN ULONG Size,
IN PWSTR Buffer,
OUT PWSTR *ShortName
);
*/
#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)
static
BOOLEAN
CheckStringBuffer(
PCWSTR Buffer,
ULONG Length,
SIZE_T MaximumLength,
PCWSTR Expected)
{
USHORT ExpectedLength = wcslen(Expected) * sizeof(WCHAR);
SIZE_T EqualLength;
BOOLEAN Result = TRUE;
SIZE_T i;
if (Length != ExpectedLength)
{
ok(0, "String length is %u, expected %u\n", Length, ExpectedLength);
Result = FALSE;
}
EqualLength = RtlCompareMemory(Buffer, Expected, Length);
if (EqualLength != Length)
{
ok(0, "String is '%S', expected '%S'\n", Buffer, Expected);
Result = FALSE;
}
if (Buffer[Length / sizeof(WCHAR)] != UNICODE_NULL)
{
ok(0, "Not null terminated\n");
Result = FALSE;
}
/* the function nulls the rest of the buffer! */
for (i = Length + sizeof(UNICODE_NULL); i < MaximumLength; i++)
{
UCHAR Char = ((PUCHAR)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 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)
{
/* TODO: don't duplicate this here and in the RtlGetFullPathName_UstrEx test */
struct
{
PCWSTR FileName;
PREFIX_TYPE PrefixType;
PCWSTR FullPathName;
PREFIX_TYPE FilePartPrefixType;
SIZE_T FilePartSize;
} TestCases[] =
{
{ L"C:", PrefixCurrentPath, L"", PrefixCurrentPathWithoutLastPart },
{ L"C:\\", PrefixNone, L"C:\\" },
{ L"C:\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
{ L"C:\\test\\", PrefixNone, L"C:\\test\\" },
{ L"C:/test/", PrefixNone, L"C:\\test\\" },
{ L"C:\\\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
{ L"test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
{ L"\\test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
{ L"/test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
{ L".\\test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
{ L"\\.", PrefixCurrentDrive, L"" },
{ L"\\.\\", PrefixCurrentDrive, L"" },
{ L"\\\\.", PrefixNone, L"\\\\.\\" },
{ L"\\\\.\\", PrefixNone, L"\\\\.\\" },
{ L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\" },
{ L"\\??\\", PrefixCurrentDrive, L"??\\" },
{ L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", PrefixCurrentDrive, 3 * sizeof(WCHAR) },
{ L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\" },
{ L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", PrefixCurrentDrive, 6 * sizeof(WCHAR) },
{ L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\" },
{ L"\\\\??\\", PrefixNone, L"\\\\??\\" },
{ L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:" },
{ L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\" },
{ L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", PrefixNone, sizeof(L"\\\\??\\C:\\") },
{ L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\" },
};
NTSTATUS ExceptionStatus;
WCHAR FullPathNameBuffer[MAX_PATH];
PWSTR ShortName;
SIZE_T Length;
WCHAR ExpectedPathName[MAX_PATH];
SIZE_T FilePartSize;
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:
Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
if (Length == 3 && TestCases[i].FullPathName[0])
ExpectedPathName[2] = UNICODE_NULL;
break;
default:
skip(0, "Invalid test!\n");
continue;
}
wcscat(ExpectedPathName, TestCases[i].FullPathName);
RtlFillMemory(FullPathNameBuffer, sizeof(FullPathNameBuffer), 0xAA);
Length = 0;
StartSeh()
Length = RtlGetFullPathName_U(TestCases[i].FileName,
sizeof(FullPathNameBuffer),
FullPathNameBuffer,
&ShortName);
EndSeh(STATUS_SUCCESS);
/* TODO: remove SEH here */
StartSeh()
ok(CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName),
"Wrong path name '%S', expected '%S'\n", FullPathNameBuffer, ExpectedPathName);
EndSeh(STATUS_SUCCESS);
if (!ShortName)
FilePartSize = 0;
else
FilePartSize = ShortName - FullPathNameBuffer;
switch (TestCases[i].FilePartPrefixType)
{
case PrefixNone:
ExpectedFilePartSize = 0;
break;
case PrefixCurrentDrive:
ExpectedFilePartSize = sizeof(L"C:\\");
break;
case PrefixCurrentPath:
ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR);
if (ExpectedFilePartSize == sizeof(L"C:\\"))
ExpectedFilePartSize -= sizeof(WCHAR);
break;
case PrefixCurrentPathWithoutLastPart:
{
WCHAR CurrentPath[MAX_PATH];
PCWSTR BackSlash;
ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
if (ExpectedFilePartSize == sizeof(L"C:\\"))
ExpectedFilePartSize = 0;
else
{
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);
}
}
START_TEST(RtlGetFullPathName_U)
{
NTSTATUS ExceptionStatus;
PCWSTR FileName;
PWSTR ShortName;
ULONG Length;
/* Parameter checks */
StartSeh()
Length = RtlGetFullPathName_U(NULL, 0, NULL, NULL);
ok(Length == 0, "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
StartSeh()
Length = RtlGetFullPathName_U(L"", 0, NULL, NULL);
ok(Length == 0, "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
ShortName = InvalidPointer;
StartSeh()
Length = RtlGetFullPathName_U(NULL, 0, NULL, &ShortName);
ok(Length == 0, "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
ok(ShortName == InvalidPointer ||
broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
StartSeh()
Length = RtlGetFullPathName_U(L"", 0, NULL, NULL);
ok(Length == 0, "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
ShortName = InvalidPointer;
StartSeh()
Length = RtlGetFullPathName_U(L"", 0, NULL, &ShortName);
ok(Length == 0, "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
ok(ShortName == InvalidPointer ||
broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
StartSeh()
Length = RtlGetFullPathName_U(L"C:\\test", 0, NULL, NULL);
ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
FileName = L"C:\\test";
ShortName = InvalidPointer;
StartSeh()
Length = RtlGetFullPathName_U(FileName, 0, NULL, &ShortName);
ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
EndSeh(STATUS_SUCCESS);
ok(ShortName == InvalidPointer ||
broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
/* check the actual functionality with different paths */
RunTestCases();
}

View file

@ -98,6 +98,7 @@ static
VOID
RunTestCases(VOID)
{
/* TODO: don't duplicate this here and in the RtlGetFullPathName_U test */
struct
{
PCWSTR FileName;
@ -166,8 +167,13 @@ RunTestCases(VOID)
ExpectedPathName[3] = UNICODE_NULL;
break;
case PrefixCurrentPath:
GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
{
ULONG Length;
Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
if (Length == 3 && TestCases[i].FullPathName[0])
ExpectedPathName[2] = UNICODE_NULL;
break;
}
default:
skip(0, "Invalid test!\n");
continue;
@ -212,17 +218,24 @@ RunTestCases(VOID)
break;
case PrefixCurrentPath:
ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR);
if (ExpectedFilePartSize == sizeof(L"C:\\"))
ExpectedFilePartSize -= 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);
if (ExpectedFilePartSize == sizeof(L"C:\\"))
ExpectedFilePartSize = 0;
else
ok(0, "GetCurrentDirectory returned %S\n", CurrentPath);
{
BackSlash = wcsrchr(CurrentPath, L'\\');
if (BackSlash)
ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR);
else
ok(0, "GetCurrentDirectory returned %S\n", CurrentPath);
}
break;
}
default:

View file

@ -8,6 +8,7 @@
extern void func_NtAllocateVirtualMemory(void);
extern void func_NtFreeVirtualMemory(void);
extern void func_NtSystemInformation(void);
extern void func_RtlGetFullPathName_U(void);
extern void func_RtlGetFullPathName_UstrEx(void);
extern void func_RtlInitializeBitMap(void);
extern void func_ZwContinue(void);
@ -17,6 +18,7 @@ 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 },