msvcrt/tests: Add close tests on file descriptors that use the same HANDLE.

Based on Qian Hong patch.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2016-02-19 18:43:31 +01:00 committed by Alexandre Julliard
parent 781b069ed8
commit 96d476584e
1 changed files with 59 additions and 0 deletions

View File

@ -2327,6 +2327,64 @@ static void test_write_flush(void)
free(tempf);
}
static void test_close(void)
{
ioinfo *stdout_info, stdout_copy, *stderr_info, stderr_copy;
int fd1, fd2, ret1, ret2, ret3, ret4;
DWORD flags;
HANDLE h;
/* test close on fds that use the same handle */
h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
ok(h != INVALID_HANDLE_VALUE, "error opening fdopen.tst file\n");
fd1 = _open_osfhandle((intptr_t)h, 0);
ok(fd1 != -1, "_open_osfhandle failed (%d)\n", errno);
fd2 = _open_osfhandle((intptr_t)h, 0);
ok(fd2 != -1, "_open_osfhandle failed (%d)\n", errno);
ok(fd1 != fd2, "fd1 == fd2\n");
ok((HANDLE)_get_osfhandle(fd1) == h, "handles mismatch (%p != %p)\n",
(HANDLE)_get_osfhandle(fd1), h);
ok((HANDLE)_get_osfhandle(fd2) == h, "handles mismatch (%p != %p)\n",
(HANDLE)_get_osfhandle(fd2), h);
ok(!close(fd1), "close(fd1) failed (%d)\n", errno);
ok(!GetHandleInformation(h, &flags), "GetHandleInformation succeeded\n");
ok(close(fd2), "close(fd2) succeeded\n");
/* test close on stdout and stderr that use the same handle */
h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
ok(h != INVALID_HANDLE_VALUE, "error opening fdopen.tst file\n");
/* tests output will not be visible from now on */
stdout_info = &__pioinfo[STDOUT_FILENO/MSVCRT_FD_BLOCK_SIZE][STDOUT_FILENO%MSVCRT_FD_BLOCK_SIZE];
stderr_info = &__pioinfo[STDERR_FILENO/MSVCRT_FD_BLOCK_SIZE][STDERR_FILENO%MSVCRT_FD_BLOCK_SIZE];
stdout_copy = *stdout_info;
stderr_copy = *stderr_info;
stdout_info->handle = h;
stderr_info->handle = h;
ret1 = close(STDOUT_FILENO);
ret2 = GetHandleInformation(h, &flags);
ret3 = close(STDERR_FILENO);
ret4 = GetHandleInformation(h, &flags);
*stdout_info = stdout_copy;
*stderr_info = stderr_copy;
SetStdHandle(STD_OUTPUT_HANDLE, stdout_info->handle);
SetStdHandle(STD_ERROR_HANDLE, stderr_info->handle);
/* stdout and stderr restored */
ok(!ret1, "close(STDOUT_FILENO) failed\n");
ok(ret2, "GetHandleInformation failed\n");
ok(!ret3, "close(STDERR_FILENO) failed\n");
ok(!ret4, "GetHandleInformation succeeded\n");
DeleteFileA( "fdopen.tst" );
}
START_TEST(file)
{
int arg_c;
@ -2393,6 +2451,7 @@ START_TEST(file)
test_mktemp();
test__open_osfhandle();
test_write_flush();
test_close();
/* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report
* file contains lines in the correct order