mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-26 02:12:45 -05:00
tst: winfsp-tests: stream testing
This commit is contained in:
parent
8e1512c067
commit
75012d1301
@ -595,6 +595,218 @@ static void stream_create_share_test(void)
|
|||||||
stream_create_share_dotest(MemfsNet, L"\\\\memfs\\share");
|
stream_create_share_dotest(MemfsNet, L"\\\\memfs\\share");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
||||||
|
{
|
||||||
|
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
HANDLE Handle;
|
||||||
|
BOOL Success;
|
||||||
|
WCHAR FilePath[MAX_PATH];
|
||||||
|
FILE_ATTRIBUTE_TAG_INFO AttributeTagInfo;
|
||||||
|
FILE_BASIC_INFO BasicInfo;
|
||||||
|
FILE_STANDARD_INFO StandardInfo;
|
||||||
|
PUINT8 NameInfoBuf[sizeof(FILE_NAME_INFO) + MAX_PATH];
|
||||||
|
PFILE_NAME_INFO PNameInfo = (PVOID)NameInfoBuf;
|
||||||
|
BY_HANDLE_FILE_INFORMATION FileInfo;
|
||||||
|
FILETIME FileTime;
|
||||||
|
LONGLONG TimeLo, TimeHi;
|
||||||
|
|
||||||
|
GetSystemTimeAsFileTime(&FileTime);
|
||||||
|
TimeLo = ((PLARGE_INTEGER)&FileTime)->QuadPart;
|
||||||
|
TimeHi = TimeLo + 10000 * 10000/* 10 seconds */;
|
||||||
|
|
||||||
|
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
|
||||||
|
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||||
|
|
||||||
|
Handle = CreateFileW(FilePath,
|
||||||
|
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||||
|
CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
|
||||||
|
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandleEx(Handle, FileAttributeTagInfo, &AttributeTagInfo, sizeof AttributeTagInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == AttributeTagInfo.FileAttributes);
|
||||||
|
ASSERT(0 == AttributeTagInfo.ReparseTag);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandleEx(Handle, FileBasicInfo, &BasicInfo, sizeof BasicInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == BasicInfo.FileAttributes);
|
||||||
|
if (-1 != Flags)
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= BasicInfo.CreationTime.QuadPart &&
|
||||||
|
TimeHi > BasicInfo.CreationTime.QuadPart);
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= BasicInfo.LastAccessTime.QuadPart &&
|
||||||
|
TimeHi > BasicInfo.LastAccessTime.QuadPart);
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= BasicInfo.LastWriteTime.QuadPart &&
|
||||||
|
TimeHi > BasicInfo.LastWriteTime.QuadPart);
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= BasicInfo.ChangeTime.QuadPart &&
|
||||||
|
TimeHi > BasicInfo.ChangeTime.QuadPart);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandleEx(Handle, FileStandardInfo, &StandardInfo, sizeof StandardInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(0 == StandardInfo.AllocationSize.QuadPart);
|
||||||
|
ASSERT(0 == StandardInfo.EndOfFile.QuadPart);
|
||||||
|
ASSERT(1 == StandardInfo.NumberOfLinks);
|
||||||
|
ASSERT(!StandardInfo.DeletePending);
|
||||||
|
ASSERT(!StandardInfo.Directory);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandleEx(Handle, FileNameInfo, PNameInfo, sizeof *PNameInfo);
|
||||||
|
ASSERT(!Success);
|
||||||
|
ASSERT(ERROR_MORE_DATA == GetLastError());
|
||||||
|
if (-1 == Flags)
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 6) * sizeof(WCHAR));
|
||||||
|
else if (0 == Prefix)
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(L"\\file0") * sizeof(WCHAR));
|
||||||
|
else
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
|
||||||
|
ASSERT(L'\\' == PNameInfo->FileName[0]);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandleEx(Handle, FileNameInfo, PNameInfo, sizeof NameInfoBuf);
|
||||||
|
ASSERT(Success);
|
||||||
|
if (-1 == Flags)
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 6) * sizeof(WCHAR));
|
||||||
|
else if (0 == Prefix)
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(L"\\file0") * sizeof(WCHAR));
|
||||||
|
else
|
||||||
|
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
|
||||||
|
if (-1 == Flags)
|
||||||
|
ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
|
||||||
|
else if (0 == Prefix)
|
||||||
|
ASSERT(0 == memcmp(L"\\file0", PNameInfo->FileName, PNameInfo->FileNameLength));
|
||||||
|
else
|
||||||
|
ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == FileInfo.dwFileAttributes);
|
||||||
|
if (-1 != Flags)
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= ((PLARGE_INTEGER)&FileInfo.ftCreationTime)->QuadPart &&
|
||||||
|
TimeHi > ((PLARGE_INTEGER)&FileInfo.ftCreationTime)->QuadPart);
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= ((PLARGE_INTEGER)&FileInfo.ftLastAccessTime)->QuadPart &&
|
||||||
|
TimeHi > ((PLARGE_INTEGER)&FileInfo.ftLastAccessTime)->QuadPart);
|
||||||
|
ASSERT(
|
||||||
|
TimeLo <= ((PLARGE_INTEGER)&FileInfo.ftLastWriteTime)->QuadPart &&
|
||||||
|
TimeHi > ((PLARGE_INTEGER)&FileInfo.ftLastWriteTime)->QuadPart);
|
||||||
|
ASSERT(0 == FileInfo.nFileSizeLow && 0 == FileInfo.nFileSizeHigh);
|
||||||
|
ASSERT(1 == FileInfo.nNumberOfLinks);
|
||||||
|
|
||||||
|
CloseHandle(Handle);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memfs_stop(memfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stream_getfileinfo_test(void)
|
||||||
|
{
|
||||||
|
if (NtfsTests)
|
||||||
|
{
|
||||||
|
WCHAR DirBuf[MAX_PATH] = L"\\\\?\\";
|
||||||
|
GetCurrentDirectoryW(MAX_PATH - 4, DirBuf + 4);
|
||||||
|
stream_getfileinfo_dotest(-1, DirBuf, 0);
|
||||||
|
}
|
||||||
|
if (WinFspDiskTests)
|
||||||
|
{
|
||||||
|
stream_getfileinfo_dotest(MemfsDisk, 0, 0);
|
||||||
|
stream_getfileinfo_dotest(MemfsDisk, 0, 1000);
|
||||||
|
}
|
||||||
|
if (WinFspNetTests)
|
||||||
|
{
|
||||||
|
stream_getfileinfo_dotest(MemfsNet, L"\\\\memfs\\share", 0);
|
||||||
|
stream_getfileinfo_dotest(MemfsNet, L"\\\\memfs\\share", 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stream_setfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
||||||
|
{
|
||||||
|
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
HANDLE Handle;
|
||||||
|
BOOL Success;
|
||||||
|
WCHAR FilePath[MAX_PATH];
|
||||||
|
BY_HANDLE_FILE_INFORMATION FileInfo0, FileInfo;
|
||||||
|
FILETIME FileTime;
|
||||||
|
DWORD Offset;
|
||||||
|
|
||||||
|
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
|
||||||
|
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||||
|
|
||||||
|
Handle = CreateFileW(FilePath,
|
||||||
|
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||||
|
CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
|
||||||
|
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo0);
|
||||||
|
ASSERT(Success);
|
||||||
|
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == FileInfo0.dwFileAttributes);
|
||||||
|
|
||||||
|
Success = SetFileAttributesW(FilePath, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(FILE_ATTRIBUTE_HIDDEN == FileInfo.dwFileAttributes);
|
||||||
|
|
||||||
|
*(PUINT64)&FileTime = 0x4200000042ULL;
|
||||||
|
Success = SetFileTime(Handle, 0, &FileTime, &FileTime);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(*(PUINT64)&FileInfo0.ftCreationTime == *(PUINT64)&FileInfo.ftCreationTime);
|
||||||
|
ASSERT(0x4200000042ULL == *(PUINT64)&FileInfo.ftLastAccessTime);
|
||||||
|
ASSERT(0x4200000042ULL == *(PUINT64)&FileInfo.ftLastWriteTime);
|
||||||
|
|
||||||
|
Success = SetFileTime(Handle, &FileTime, 0, 0);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(0x4200000042ULL == *(PUINT64)&FileInfo.ftCreationTime);
|
||||||
|
|
||||||
|
Offset = SetFilePointer(Handle, 42, 0, 0);
|
||||||
|
ASSERT(42 == Offset);
|
||||||
|
|
||||||
|
Success = SetEndOfFile(Handle);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = GetFileInformationByHandle(Handle, &FileInfo);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(42 == FileInfo.nFileSizeLow);
|
||||||
|
ASSERT(0 == FileInfo.nFileSizeHigh);
|
||||||
|
|
||||||
|
CloseHandle(Handle);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memfs_stop(memfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stream_setfileinfo_test(void)
|
||||||
|
{
|
||||||
|
if (NtfsTests)
|
||||||
|
{
|
||||||
|
WCHAR DirBuf[MAX_PATH] = L"\\\\?\\";
|
||||||
|
GetCurrentDirectoryW(MAX_PATH - 4, DirBuf + 4);
|
||||||
|
stream_setfileinfo_dotest(-1, DirBuf, 0);
|
||||||
|
}
|
||||||
|
if (WinFspDiskTests)
|
||||||
|
{
|
||||||
|
stream_setfileinfo_dotest(MemfsDisk, 0, 0);
|
||||||
|
stream_setfileinfo_dotest(MemfsDisk, 0, 1000);
|
||||||
|
}
|
||||||
|
if (WinFspNetTests)
|
||||||
|
{
|
||||||
|
stream_setfileinfo_dotest(MemfsNet, L"\\\\memfs\\share", 0);
|
||||||
|
stream_setfileinfo_dotest(MemfsNet, L"\\\\memfs\\share", 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void stream_getsecurity_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
static void stream_getsecurity_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
||||||
{
|
{
|
||||||
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
||||||
@ -841,6 +1053,8 @@ void stream_tests(void)
|
|||||||
TEST(stream_create_test);
|
TEST(stream_create_test);
|
||||||
TEST(stream_create_sd_test);
|
TEST(stream_create_sd_test);
|
||||||
TEST(stream_create_share_test);
|
TEST(stream_create_share_test);
|
||||||
|
TEST(stream_getfileinfo_test);
|
||||||
|
TEST(stream_setfileinfo_test);
|
||||||
TEST(stream_getsecurity_test);
|
TEST(stream_getsecurity_test);
|
||||||
TEST(stream_setsecurity_test);
|
TEST(stream_setsecurity_test);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user