tst: fscrash: WIP

This commit is contained in:
Bill Zissimopoulos 2016-11-03 20:39:28 -07:00
parent fd439add27
commit ab0c2fc25c

View File

@ -31,19 +31,21 @@
VOID Test(PWSTR Prefix) VOID Test(PWSTR Prefix)
{ {
static WCHAR *Sddl = L"D:P(A;;GA;;;WD)"; static PWSTR Sddl = L"D:P(A;;GA;;;SY)(A;;GA;;;BA)(A;;GA;;;WD)";
static const GUID ReparseGuid = static const GUID ReparseGuid =
{ 0x2cf25cfa, 0x41af, 0x4796, { 0xb5, 0xef, 0xac, 0xa3, 0x85, 0x3, 0xe2, 0xd8 } }; { 0x2cf25cfa, 0x41af, 0x4796, { 0xb5, 0xef, 0xac, 0xa3, 0x85, 0x3, 0xe2, 0xd8 } };
WCHAR FileName[1024]; WCHAR FileName[1024];
PSECURITY_DESCRIPTOR SecurityDescriptor; PSECURITY_DESCRIPTOR SecurityDescriptor;
HANDLE Handle; HANDLE Handle;
BOOL Success; BOOL Success;
UINT8 RdBuffer[512], WrBuffer[] = "Buffer"; UINT8 RdBuffer[4096], WrBuffer[4096];
REPARSE_GUID_DATA_BUFFER ReparseDataBuf; REPARSE_GUID_DATA_BUFFER ReparseDataBuf;
DWORD BytesTransferred; DWORD BytesTransferred, Offset;
WIN32_FIND_DATAW FindData; WIN32_FIND_DATAW FindData;
WIN32_FIND_STREAM_DATA FindStreamData; WIN32_FIND_STREAM_DATA FindStreamData;
memset(WrBuffer, 'B', sizeof WrBuffer);
Success = ConvertStringSecurityDescriptorToSecurityDescriptorW( Success = ConvertStringSecurityDescriptorToSecurityDescriptorW(
Sddl, SDDL_REVISION_1, &SecurityDescriptor, 0); Sddl, SDDL_REVISION_1, &SecurityDescriptor, 0);
ASSERT(Success); ASSERT(Success);
@ -54,32 +56,32 @@ VOID Test(PWSTR Prefix)
wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix); wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix);
Handle = CreateFileW(FileName, Handle = CreateFileW(FileName,
GENERIC_READ | GENERIC_WRITE, 0, 0, GENERIC_ALL, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, 0); CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, 0);
ASSERT(INVALID_HANDLE_VALUE != Handle); ASSERT(INVALID_HANDLE_VALUE != Handle);
Success = WriteFile(Handle, WrBuffer, sizeof WrBuffer, &BytesTransferred, 0); Success = WriteFile(Handle, WrBuffer, sizeof WrBuffer, &BytesTransferred, 0);
ASSERT(Success); ASSERT(Success);
ASSERT(0 != BytesTransferred); ASSERT(sizeof WrBuffer == BytesTransferred);
Success = FlushFileBuffers(Handle); Success = FlushFileBuffers(Handle);
ASSERT(Success); ASSERT(Success);
Success = SetFilePointer(Handle, 0, 0, FILE_BEGIN); Offset = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
ASSERT(Success); ASSERT(0 == Offset);
Success = ReadFile(Handle, RdBuffer, sizeof RdBuffer, &BytesTransferred, 0); Success = ReadFile(Handle, RdBuffer, sizeof RdBuffer, &BytesTransferred, 0);
ASSERT(Success); ASSERT(Success);
ASSERT(sizeof WrBuffer == BytesTransferred); ASSERT(sizeof WrBuffer == BytesTransferred);
Success = SetFilePointer(Handle, 42, 0, FILE_BEGIN); Offset = SetFilePointer(Handle, 0, 0, FILE_BEGIN);
ASSERT(Success); ASSERT(0 == Offset);
Success = SetEndOfFile(Handle); Success = SetEndOfFile(Handle);
ASSERT(Success); ASSERT(Success);
BytesTransferred = GetFileSize(Handle, 0); Offset = GetFileSize(Handle, 0);
ASSERT(42 == BytesTransferred); ASSERT(0 == Offset);
Success = LockFile(Handle, 0, 0, 1, 0); Success = LockFile(Handle, 0, 0, 1, 0);
ASSERT(Success); ASSERT(Success);
@ -94,9 +96,6 @@ VOID Test(PWSTR Prefix)
ASSERT(!Success); ASSERT(!Success);
ASSERT(ERROR_INSUFFICIENT_BUFFER == GetLastError()); ASSERT(ERROR_INSUFFICIENT_BUFFER == GetLastError());
Success = CloseHandle(Handle);
ASSERT(Success);
ReparseDataBuf.ReparseTag = 0x1234; ReparseDataBuf.ReparseTag = 0x1234;
ReparseDataBuf.ReparseDataLength = 0; ReparseDataBuf.ReparseDataLength = 0;
ReparseDataBuf.Reserved = 0; ReparseDataBuf.Reserved = 0;
@ -108,6 +107,9 @@ VOID Test(PWSTR Prefix)
&BytesTransferred, 0); &BytesTransferred, 0);
ASSERT(Success); ASSERT(Success);
Success = CloseHandle(Handle);
ASSERT(Success);
wsprintfW(FileName, L"%s\\fscrash\\*", Prefix); wsprintfW(FileName, L"%s\\fscrash\\*", Prefix);
Handle = FindFirstFileW(FileName, &FindData); Handle = FindFirstFileW(FileName, &FindData);
ASSERT(INVALID_HANDLE_VALUE != Handle); ASSERT(INVALID_HANDLE_VALUE != Handle);
@ -115,6 +117,8 @@ VOID Test(PWSTR Prefix)
{ {
} while (FindNextFileW(Handle, &FindData)); } while (FindNextFileW(Handle, &FindData));
ASSERT(ERROR_NO_MORE_FILES == GetLastError()); ASSERT(ERROR_NO_MORE_FILES == GetLastError());
Success = FindClose(Handle);
ASSERT(Success);
wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix); wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix);
Handle = FindFirstStreamW(FileName, FindStreamInfoStandard, &FindStreamData, 0); Handle = FindFirstStreamW(FileName, FindStreamInfoStandard, &FindStreamData, 0);
@ -123,6 +127,8 @@ VOID Test(PWSTR Prefix)
{ {
} while (FindNextStreamW(Handle, &FindStreamData)); } while (FindNextStreamW(Handle, &FindStreamData));
ASSERT(ERROR_HANDLE_EOF == GetLastError()); ASSERT(ERROR_HANDLE_EOF == GetLastError());
Success = FindClose(Handle);
ASSERT(Success);
wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix); wsprintfW(FileName, L"%s\\fscrash\\file0", Prefix);
Success = DeleteFileW(FileName); Success = DeleteFileW(FileName);