tst: test case insensitivity

sys: FspFileNameIsValid: $DATA is case insensitive
This commit is contained in:
Bill Zissimopoulos
2016-10-15 19:49:56 -07:00
parent 5773c6eab7
commit 3ed7847d84
14 changed files with 239 additions and 90 deletions

View File

@ -64,12 +64,12 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
FileCount++;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(FileCount == wcslen(FindData.cFileName));
ASSERT(0 == wcsncmp(FindData.cFileName, L"..", FileCount));
ASSERT(0 == mywcscmp(FindData.cFileName, FileCount, L"..", FileCount));
continue;
}
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(0 == wcsncmp(FindData.cFileName, L"file", 4));
ASSERT(0 == mywcscmp(FindData.cFileName, 4, L"file", 4));
ul = wcstoul(FindData.cFileName + 4, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@ -100,7 +100,7 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
wchar_t *endp;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(0 == wcsncmp(FindData.cFileName, L"dir", 3));
ASSERT(0 == mywcscmp(FindData.cFileName, 3, L"dir", 3));
ul = wcstoul(FindData.cFileName + 3, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@ -132,7 +132,8 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
size_t wcscnt = sizeof "fileABCDEFGHIJKLMNOPQRSTUVXWYZfile" - 1/* count of wchar_t*/;
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(0 == wcsncmp(FindData.cFileName, L"fileABCDEFGHIJKLMNOPQRSTUVXWYZfile", wcscnt));
ASSERT(0 == mywcscmp(FindData.cFileName, (int)wcscnt,
L"fileABCDEFGHIJKLMNOPQRSTUVXWYZfile", (int)wcscnt));
ul = wcstoul(FindData.cFileName + wcscnt, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@ -413,7 +414,7 @@ static void dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, U
ASSERT(FILE_ACTION_ADDED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
ASSERT(0 == memcmp(L"file0", NotifyInfo->FileName, NotifyInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"file0", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
if (0 == NotifyInfo->NextEntryOffset)
{
@ -427,7 +428,7 @@ static void dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, U
ASSERT(FILE_ACTION_REMOVED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
ASSERT(0 == memcmp(L"file0", NotifyInfo->FileName, NotifyInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"file0", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
ASSERT(0 == NotifyInfo->NextEntryOffset);

View File

@ -1,34 +0,0 @@
#include <winfsp/winfsp.h>
HANDLE HookCreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
HANDLE h = CreateFileW(
lpFileName,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile);
DWORD LastError = GetLastError();
FspDebugLog("CreateFileW(\"%S\", %#lx, %#lx, %p, %#lx, %#lx, %p) = %p[%#lx]\n",
lpFileName,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile,
h, INVALID_HANDLE_VALUE != h ? 0 : LastError);
SetLastError(LastError);
return h;
}

View File

@ -84,11 +84,11 @@ void getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
ASSERT(0 == memcmp(L"\\file0", PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"\\file0", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);

View File

@ -13,8 +13,14 @@ void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout)
MEMFS *Memfs;
NTSTATUS Result;
Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024,
MemfsNet == Flags ? L"\\memfs\\share" : 0, 0, &Memfs);
Result = MemfsCreate(
(OptCaseInsensitive ? MemfsCaseInsensitive : 0) | Flags,
FileInfoTimeout,
1024,
1024 * 1024,
MemfsNet == Flags ? L"\\memfs\\share" : 0,
0,
&Memfs);
ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs);

View File

@ -213,7 +213,7 @@ void mount_volume_transact_dotest(PWSTR DeviceName, PWSTR Prefix)
ASSERT(!Request->Req.Create.CaseSensitive);
ASSERT(0 == Request->FileName.Offset);
ASSERT((wcslen((PVOID)Request->Buffer) + 1) * sizeof(WCHAR) == Request->FileName.Size);
ASSERT(0 == wcscmp((PVOID)Request->Buffer, L"\\file0"));
ASSERT(0 == mywcscmp((PVOID)Request->Buffer, -1, L"\\file0", -1));
}
ASSERT(FspFsctlTransactCanProduceResponse(Response, ResponseBufEnd));

View File

@ -876,11 +876,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
ASSERT(0 == memcmp(L"\\file0:foo", PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"\\file0:foo", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);
@ -963,11 +963,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
ASSERT(0 == memcmp(L"\\file0", PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"\\file0", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);
@ -1837,11 +1837,11 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
if (1 > FileCount)
{
FileCount++;
ASSERT(0 == wcscmp(FindData.cStreamName, L"::$DATA"));
ASSERT(0 == mywcscmp(FindData.cStreamName, -1, L"::$DATA", -1));
continue;
}
ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@ -1878,7 +1878,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
continue;
}
ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@ -1914,7 +1914,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
unsigned long ul;
wchar_t *endp;
ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@ -2048,7 +2048,7 @@ static void stream_dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTim
ASSERT(6/*FILE_ACTION_ADDED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
ASSERT(0 == memcmp(L"file0:foo", NotifyInfo->FileName, NotifyInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"file0:foo", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
/*
* NTFS never seems to send FILE_ACTION_REMOVED_STREAM notification. So don't do this test on it.
@ -2070,7 +2070,7 @@ static void stream_dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTim
ASSERT(7/*FILE_ACTION_REMOVED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
ASSERT(0 == memcmp(L"file0:foo", NotifyInfo->FileName, NotifyInfo->FileNameLength));
ASSERT(0 == mywcscmp(L"file0:foo", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
ASSERT(0 == NotifyInfo->NextEntryOffset);
}

View File

@ -1,4 +1,5 @@
#include <tlib/testsuite.h>
#include <time.h>
#include "winfsp-tests.h"
@ -6,6 +7,113 @@ int NtfsTests = 0;
int WinFspDiskTests = 1;
int WinFspNetTests = 1;
BOOLEAN OptCaseInsensitive = FALSE;
BOOLEAN OptCaseRandomize = FALSE;
int mywcscmp(PWSTR a, int alen, PWSTR b, int blen)
{
int len, res;
if (-1 == alen)
alen = (int)wcslen(a);
if (-1 == blen)
blen = (int)wcslen(b);
len = alen < blen ? alen : blen;
/* we should still be in the C locale */
if (OptCaseRandomize)
res = _wcsnicmp(a, b, len);
else
res = wcsncmp(a, b, len);
if (0 == res)
res = alen - blen;
return res;
}
#define testalpha(c) ('a' <= ((c) | 0x20) && ((c) | 0x20) <= 'z')
#define togglealpha(c) ((c) ^ 0x20)
#undef CreateFileW
static unsigned myrandseed = 1;
static int myrand(void)
{
/*
* This mimics MSVCRT rand(); we need our own version
* as to not interfere with the program's rand().
*/
myrandseed = myrandseed * 214013 + 2531011;
return (myrandseed >> 16) & RAND_MAX;
}
HANDLE HookCreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
static WCHAR DevicePrefix[] =
L"\\\\?\\GLOBALROOT\\Device\\Volume{01234567-0123-0123-0101-010101010101}\\";
static const TogglePercent = 25;
WCHAR FileNameBuf[1024];
PWSTR P, EndP;
wcscpy_s(FileNameBuf, sizeof FileNameBuf / sizeof(WCHAR), lpFileName);
if (OptCaseRandomize)
{
if (L'\\' == FileNameBuf[0] && L'\\' == FileNameBuf[1] &&
L'?' == FileNameBuf[2] && L'\\' == FileNameBuf[3] &&
testalpha(FileNameBuf[4]) && L':' == FileNameBuf[5] && L'\\' == FileNameBuf[6])
P = FileNameBuf + 7;
else if (0 == wcsncmp(FileNameBuf, DevicePrefix, wcschr(DevicePrefix, L'{') - DevicePrefix))
P = FileNameBuf + wcslen(DevicePrefix);
else if (L'\\' == FileNameBuf[0] && L'\\' == FileNameBuf[1])
P = FileNameBuf + 2;
else if (testalpha(FileNameBuf[0]) && L':' == FileNameBuf[1] && L'\\' == FileNameBuf[2])
P = FileNameBuf + 3;
else
abort();
for (EndP = P + wcslen(P); EndP > P; P++)
if (testalpha(*P) && myrand() <= (TogglePercent) * 0x7fff / 100)
*P = togglealpha(*P);
}
HANDLE h = CreateFileW(
FileNameBuf,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile);
#if 0
DWORD LastError = GetLastError();
FspDebugLog("CreateFileW(\"%S\", %#lx, %#lx, %p, %#lx, %#lx, %p) = %p[%#lx]\n",
FileNameBuf,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile,
h, INVALID_HANDLE_VALUE != h ? 0 : LastError);
SetLastError(LastError);
#endif
return h;
}
#define rmarg(argv, argc, argi) \
argc--,\
memmove(argv + argi, argv + argi + 1, (argc - argi) * sizeof(char *)),\
argi--,\
argv[argc] = 0
int main(int argc, char *argv[])
{
TESTSUITE(fuse_opt_tests);
@ -25,6 +133,27 @@ int main(int argc, char *argv[])
TESTSUITE(reparse_tests);
TESTSUITE(stream_tests);
for (int argi = 1; argc > argi; argi++)
{
const char *a = argv[argi];
if ('-' == a[0])
{
if (0 == strcmp("--case-insensitive", a))
{
OptCaseInsensitive = TRUE;
rmarg(argv, argc, argi);
}
else if (0 == strcmp("--case-randomize", a))
{
OptCaseRandomize = TRUE;
OptCaseInsensitive = TRUE;
rmarg(argv, argc, argi);
}
}
}
myrandseed = (unsigned)time(0);
tlib_run_tests(argc, argv);
return 0;
}

View File

@ -9,7 +9,12 @@ extern int NtfsTests;
extern int WinFspDiskTests;
extern int WinFspNetTests;
//#define CreateFileW HookCreateFileW
extern BOOLEAN OptCaseInsensitive;
extern BOOLEAN OptCaseRandomize;
int mywcscmp(PWSTR a, int alen, PWSTR b, int blen);
#define CreateFileW HookCreateFileW
HANDLE HookCreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,