https://git.reactos.org/?p=reactos.git;a=commitdiff;h=64b6327dd78d2e145e9bc…
commit 64b6327dd78d2e145e9bc67681f52800177887ad
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu May 2 12:07:46 2019 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu May 2 12:09:34 2019 +0200
[NTDLL_APITEST] Add tests for alignment for NtWriteFile
This mimics the usage of WriteFile which is done in rosautotest.
CORE-15973
---
modules/rostests/apitests/ntdll/NtWriteFile.c | 84 +++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/modules/rostests/apitests/ntdll/NtWriteFile.c
b/modules/rostests/apitests/ntdll/NtWriteFile.c
index f9f1e70236..1383e4e71c 100644
--- a/modules/rostests/apitests/ntdll/NtWriteFile.c
+++ b/modules/rostests/apitests/ntdll/NtWriteFile.c
@@ -211,4 +211,88 @@ START_TEST(NtWriteFile)
&BufferSize,
MEM_RELEASE);
ok_hex(Status, STATUS_SUCCESS);
+
+ /* Now, testing aligned/non aligned writes */
+ BufferSize = 4096; /* We assume max sector size */
+ Status = NtAllocateVirtualMemory(NtCurrentProcess(),
+ &Buffer,
+ 0,
+ &BufferSize,
+ MEM_RESERVE | MEM_COMMIT,
+ PAGE_READONLY);
+ if (!NT_SUCCESS(Status))
+ {
+ skip("Failed to allocate memory, status %lx\n", Status);
+ return;
+ }
+
+ Status = NtCreateFile(&FileHandle,
+ FILE_WRITE_DATA | DELETE | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatus,
+ NULL,
+ 0,
+ 0,
+ FILE_SUPERSEDE,
+ FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT |
+ FILE_NO_INTERMEDIATE_BUFFERING |
+ FILE_WRITE_THROUGH,
+ NULL,
+ 0);
+ ok_hex(Status, STATUS_SUCCESS);
+
+ /* non-cached, broken length -- fails with invalid parameter */
+ ByteOffset.QuadPart = 0;
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatus,
+ Buffer,
+ 4,
+ &ByteOffset,
+ NULL);
+ ok_hex(Status, STATUS_INVALID_PARAMETER);
+
+ /* non-cached, broken offset -- fails with invalid parameter */
+ ByteOffset.QuadPart = 4;
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatus,
+ Buffer,
+ BufferSize,
+ &ByteOffset,
+ NULL);
+ ok_hex(Status, STATUS_INVALID_PARAMETER);
+
+ /* non-cached, good length and offset -- succeeds */
+ ByteOffset.QuadPart = 0;
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatus,
+ Buffer,
+ BufferSize,
+ &ByteOffset,
+ NULL);
+ ok_hex(Status, STATUS_SUCCESS);
+
+ DispositionInfo.DeleteFile = TRUE;
+ Status = NtSetInformationFile(FileHandle,
+ &IoStatus,
+ &DispositionInfo,
+ sizeof(DispositionInfo),
+ FileDispositionInformation);
+ ok_hex(Status, STATUS_SUCCESS);
+ Status = NtClose(FileHandle);
+ ok_hex(Status, STATUS_SUCCESS);
+
+ Status = NtFreeVirtualMemory(NtCurrentProcess(),
+ &Buffer,
+ &BufferSize,
+ MEM_RELEASE);
+ ok_hex(Status, STATUS_SUCCESS);
}