mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
winfsp-tests: dirctl-test.c
This commit is contained in:
parent
1dc68eec57
commit
9d3b2d6a84
@ -181,6 +181,7 @@
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">TurnOffAllWarnings</WarningLevel>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\create-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\dirctl-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\info-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs.cpp" />
|
||||
|
@ -43,6 +43,9 @@
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c">
|
||||
<Filter>Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\dirctl-test.c">
|
||||
<Filter>Source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
||||
|
201
tst/winfsp-tests/dirctl-test.c
Normal file
201
tst/winfsp-tests/dirctl-test.c
Normal file
@ -0,0 +1,201 @@
|
||||
#include <winfsp/winfsp.h>
|
||||
#include <tlib/testsuite.h>
|
||||
#include <sddl.h>
|
||||
#include <strsafe.h>
|
||||
#include "memfs.h"
|
||||
|
||||
void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout);
|
||||
void *memfs_start(ULONG Flags);
|
||||
void memfs_stop(void *data);
|
||||
PWSTR memfs_volumename(void *data);
|
||||
|
||||
extern int NtfsTests;
|
||||
extern int WinFspDiskTests;
|
||||
extern int WinFspNetTests;
|
||||
|
||||
void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
||||
{
|
||||
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
||||
|
||||
HANDLE Handle;
|
||||
BOOL Success;
|
||||
WCHAR FilePath[MAX_PATH];
|
||||
WIN32_FIND_DATAW FindData;
|
||||
ULONG FileCount, FileTotal;
|
||||
|
||||
for (int i = 1; 10 >= i; i++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), i);
|
||||
Success = CreateDirectoryW(FilePath, 0);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
for (int j = 1; 100 >= j; j++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\fileABCDEFGHIJKLMNOPQRSTUVXWYZfile%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
|
||||
Handle = CreateFileW(FilePath, GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||
Success = CloseHandle(Handle);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
for (int j = 1; 100 >= j; j++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\file%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
|
||||
Handle = CreateFileW(FilePath, GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||
Success = CloseHandle(Handle);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\*",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
Handle = FindFirstFileW(FilePath, &FindData);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||
|
||||
FileCount = FileTotal = 0;
|
||||
do
|
||||
{
|
||||
unsigned long ul;
|
||||
wchar_t *endp;
|
||||
|
||||
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
|
||||
ASSERT(0 == wcsncmp(FindData.cFileName, L"file", 4));
|
||||
ul = wcstoul(FindData.cFileName + 4, &endp, 10);
|
||||
ASSERT(0 != ul);
|
||||
ASSERT(L'\0' == *endp);
|
||||
|
||||
FileCount++;
|
||||
FileTotal += ul;
|
||||
} while (FindNextFileW(Handle, &FindData));
|
||||
ASSERT(ERROR_NO_MORE_FILES == GetLastError());
|
||||
|
||||
ASSERT(100 == FileCount);
|
||||
ASSERT(101 * 100 / 2 == FileTotal);
|
||||
|
||||
Success = FindClose(Handle);
|
||||
ASSERT(Success);
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir*",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
Handle = FindFirstFileW(FilePath, &FindData);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||
|
||||
FileCount = FileTotal = 0;
|
||||
do
|
||||
{
|
||||
unsigned long ul;
|
||||
wchar_t *endp;
|
||||
|
||||
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
|
||||
ASSERT(0 == wcsncmp(FindData.cFileName, L"dir", 3));
|
||||
ul = wcstoul(FindData.cFileName + 3, &endp, 10);
|
||||
ASSERT(0 != ul);
|
||||
ASSERT(L'\0' == *endp);
|
||||
|
||||
FileCount++;
|
||||
FileTotal += ul;
|
||||
} while (FindNextFileW(Handle, &FindData));
|
||||
ASSERT(ERROR_NO_MORE_FILES == GetLastError());
|
||||
|
||||
ASSERT(100 == FileCount);
|
||||
ASSERT(101 * 100 / 2 == FileTotal);
|
||||
|
||||
Success = FindClose(Handle);
|
||||
ASSERT(Success);
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file*",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
Handle = FindFirstFileW(FilePath, &FindData);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||
|
||||
FileCount = FileTotal = 0;
|
||||
do
|
||||
{
|
||||
unsigned long ul;
|
||||
wchar_t *endp;
|
||||
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));
|
||||
ul = wcstoul(FindData.cFileName + wcscnt, &endp, 10);
|
||||
ASSERT(0 != ul);
|
||||
ASSERT(L'\0' == *endp);
|
||||
|
||||
FileCount++;
|
||||
FileTotal += ul;
|
||||
} while (FindNextFileW(Handle, &FindData));
|
||||
ASSERT(ERROR_NO_MORE_FILES == GetLastError());
|
||||
|
||||
ASSERT(100 == FileCount);
|
||||
ASSERT(101 * 100 / 2 == FileTotal);
|
||||
|
||||
Success = FindClose(Handle);
|
||||
ASSERT(Success);
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\DOES-NOT-EXIST",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
Handle = FindFirstFileW(FilePath, &FindData);
|
||||
ASSERT(INVALID_HANDLE_VALUE == Handle);
|
||||
ASSERT(ERROR_FILE_NOT_FOUND == GetLastError());
|
||||
|
||||
for (int j = 1; 100 >= j; j++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\file%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
|
||||
Success = DeleteFileW(FilePath);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
for (int j = 1; 100 >= j; j++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\fileABCDEFGHIJKLMNOPQRSTUVXWYZfile%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
|
||||
Success = DeleteFileW(FilePath);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
for (int i = 1; 10 >= i; i++)
|
||||
{
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir%d",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), i);
|
||||
Success = RemoveDirectoryW(FilePath);
|
||||
ASSERT(Success);
|
||||
}
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file*",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
Handle = FindFirstFileW(FilePath, &FindData);
|
||||
ASSERT(INVALID_HANDLE_VALUE == Handle);
|
||||
ASSERT(ERROR_FILE_NOT_FOUND == GetLastError());
|
||||
|
||||
memfs_stop(memfs);
|
||||
}
|
||||
|
||||
void querydir_test(void)
|
||||
{
|
||||
if (NtfsTests)
|
||||
{
|
||||
WCHAR DirBuf[MAX_PATH] = L"\\\\?\\";
|
||||
GetCurrentDirectoryW(MAX_PATH - 4, DirBuf + 4);
|
||||
querydir_dotest(-1, DirBuf, 0);
|
||||
}
|
||||
if (WinFspDiskTests)
|
||||
{
|
||||
querydir_dotest(MemfsDisk, 0, 0);
|
||||
querydir_dotest(MemfsDisk, 0, 1000);
|
||||
}
|
||||
if (WinFspNetTests)
|
||||
{
|
||||
querydir_dotest(MemfsNet, L"\\\\memfs\\share", 0);
|
||||
querydir_dotest(MemfsNet, L"\\\\memfs\\share", 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void dirctl_tests(void)
|
||||
{
|
||||
TEST(querydir_test);
|
||||
}
|
@ -14,6 +14,7 @@ int main(int argc, char *argv[])
|
||||
TESTSUITE(info_tests);
|
||||
TESTSUITE(security_tests);
|
||||
TESTSUITE(rdwr_tests);
|
||||
TESTSUITE(dirctl_tests);
|
||||
|
||||
tlib_run_tests(argc, argv);
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user