+
+ /* make file handle inheritable */
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+ sprintf(cmdline, "%s file inherit 1", selfname);
+
+ /* init an empty Reserved2, which should not be recognized as inherit-block */
+ ZeroMemory(&startup, sizeof(STARTUPINFO));
+ startup.cb = sizeof(startup);
+ create_io_inherit_block( &startup, 0, NULL );
+ test_stdout_handle( &startup, cmdline, 0, FALSE, "empty block" );
+
+ /* test with valid inheritblock */
+ handles[0] = GetStdHandle( STD_INPUT_HANDLE );
+ handles[1] = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL );
+ handles[2] = GetStdHandle( STD_ERROR_HANDLE );
+ create_io_inherit_block( &startup, 3, handles );
+ test_stdout_handle( &startup, cmdline, handles[1], TRUE, "valid block" );
+ CloseHandle( handles[1] );
+ DeleteFile("fdopen.tst");
+
+ /* test inherit block starting with unsigned zero */
+ handles[1] = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL );
+ create_io_inherit_block( &startup, 3, handles );
+ *(unsigned int *)startup.lpReserved2 = 0;
+ test_stdout_handle( &startup, cmdline, handles[1], FALSE, "zero count block" );
+ CloseHandle( handles[1] );
+ DeleteFile("fdopen.tst");
+
+ /* test inherit block with smaller size */
+ handles[1] = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL );
+ create_io_inherit_block( &startup, 3, handles );
+ startup.cbReserved2 -= 3;
+ test_stdout_handle( &startup, cmdline, handles[1], TRUE, "small size block" );
+ CloseHandle( handles[1] );
+ DeleteFile("fdopen.tst");
+
+ /* test inherit block with even smaller size */
+ handles[1] = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL );
+ create_io_inherit_block( &startup, 3, handles );
+ startup.cbReserved2 = sizeof(unsigned int) + sizeof(HANDLE) + sizeof(char);
+ test_stdout_handle( &startup, cmdline, handles[1], FALSE, "smaller size block" );
+ CloseHandle( handles[1] );
+ DeleteFile("fdopen.tst");
+
+ /* test inherit block with larger size */
+ handles[1] = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL );
+ create_io_inherit_block( &startup, 3, handles );
+ startup.cbReserved2 += 7;
+ test_stdout_handle( &startup, cmdline, handles[1], TRUE, "large size block" );
+ CloseHandle( handles[1] );
+ DeleteFile("fdopen.tst");