[1/3] msvcrt/tests: Add a test for fwrite flushing behavior.
Grazvydas Ignotas
notasas at gmail.com
Fri May 30 18:00:38 CDT 2014
---
IDA (latest paid version) breaks without early 4K write flushing.
dlls/msvcrt/tests/file.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index f6a1624..37e6816 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -2219,6 +2219,40 @@ static void test__open_osfhandle(void)
CloseHandle(tmp);
}
+static void test_write_flush(void)
+{
+ static const char outbuffer[BUFSIZ * 16] = "0,1,2,3,4,5,6,7,8,9";
+ char inbuffer[BUFSIZ];
+ char *tempf;
+ FILE *file;
+ size_t size;
+ int fd;
+
+ tempf = _tempnam(".","wne");
+ file = fopen(tempf, "wb+");
+ ok(file != NULL, "unable to create test file\n");
+ fd = fileno(file);
+ for (size = BUFSIZ; size <= sizeof(outbuffer); size += BUFSIZ)
+ {
+ rewind(file);
+ ok(fwrite(outbuffer, 1, size, file) == size, "write failed\n");
+ /* lseek() below intentionally redirects the write in fflush() to detect
+ * if fwrite() has already flushed the whole buffer or not.
+ */
+ lseek(fd, 1, SEEK_SET);
+ fflush(file);
+ fseek(file, 0, SEEK_SET);
+ ok(fread(inbuffer, 1, sizeof(inbuffer), file) == sizeof(inbuffer), "read failed\n");
+ if (size % 4096 == 0)
+ todo_wine ok(memcmp(outbuffer, inbuffer, sizeof(inbuffer)) == 0, "missing flush by %d byte write\n", size);
+ else
+ ok(memcmp(outbuffer, inbuffer, sizeof(inbuffer)) != 0, "unexpected flush by %d byte write\n", size);
+ }
+ fclose(file);
+ unlink(tempf);
+ free(tempf);
+}
+
START_TEST(file)
{
int arg_c;
@@ -2284,6 +2318,7 @@ START_TEST(file)
test_stdin();
test_mktemp();
test__open_osfhandle();
+ test_write_flush();
/* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report
* file contains lines in the correct order
--
1.7.9.5
More information about the wine-patches
mailing list