mirror of
https://github.com/reactos/reactos.git
synced 2024-11-09 16:20:37 +00:00
9375945c22
- Fix -Wformat warnings and enable -Wformat where possible svn path=/trunk/; revision=62568
275 lines
9.5 KiB
C
275 lines
9.5 KiB
C
/*
|
|
* PROJECT: ReactOS api tests
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
* PURPOSE: Test for RtlGetFullPathName_U
|
|
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
|
|
*/
|
|
|
|
#include <apitest.h>
|
|
|
|
#define WIN32_NO_STATUS
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
/*
|
|
ULONG
|
|
NTAPI
|
|
RtlGetFullPathName_U(
|
|
IN PCWSTR FileName,
|
|
IN ULONG Size,
|
|
IN PWSTR Buffer,
|
|
OUT PWSTR *ShortName
|
|
);
|
|
*/
|
|
|
|
static
|
|
BOOLEAN
|
|
CheckStringBuffer(
|
|
PCWSTR Buffer,
|
|
SIZE_T Length,
|
|
SIZE_T MaximumLength,
|
|
PCWSTR Expected)
|
|
{
|
|
SIZE_T ExpectedLength = wcslen(Expected) * sizeof(WCHAR);
|
|
SIZE_T EqualLength;
|
|
BOOLEAN Result = TRUE;
|
|
SIZE_T i;
|
|
|
|
if (Length != ExpectedLength)
|
|
{
|
|
ok(0, "String length is %lu, expected %lu\n", (ULONG)Length, (ULONG)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;
|
|
}
|
|
|
|
/* 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 in the other tests */
|
|
/* TODO: Drive Relative tests don't work yet if the current drive isn't C: */
|
|
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\\" },
|
|
};
|
|
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;
|
|
BOOLEAN Okay;
|
|
|
|
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("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);
|
|
|
|
Okay = CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName);
|
|
ok(Okay, "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer, ExpectedPathName);
|
|
|
|
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("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)
|
|
{
|
|
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();
|
|
}
|