Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d424f39

Browse files
Eric Pouechbylaws
Eric Pouech
authored andcommittedSep 6, 2024
msvcrt/tests: Add tests for check buffering state of standard streams.
Signed-off-by: Eric Pouech <[email protected]> (cherry picked from commit 417d25e) Link: ValveSoftware/wine#224
1 parent fd670ea commit d424f39

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
 

‎dlls/msvcrt/tests/file.c

+59
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,64 @@ static void test_ioinfo_flags(void)
30573057
free(tempf);
30583058
}
30593059

3060+
static void test_std_stream_buffering(void)
3061+
{
3062+
int dup_fd, ret, pos;
3063+
FILE *file;
3064+
char ch;
3065+
3066+
dup_fd = _dup(STDOUT_FILENO);
3067+
ok(dup_fd != -1, "_dup failed\n");
3068+
3069+
file = freopen("std_stream_test.tmp", "w", stdout);
3070+
ok(file != NULL, "freopen failed\n");
3071+
3072+
ret = fprintf(stdout, "test");
3073+
pos = _telli64(STDOUT_FILENO);
3074+
3075+
fflush(stdout);
3076+
_dup2(dup_fd, STDOUT_FILENO);
3077+
close(dup_fd);
3078+
setvbuf(stdout, NULL, _IONBF, 0);
3079+
3080+
ok(ret == 4, "fprintf(stdout) returned %d\n", ret);
3081+
ok(!pos, "expected stdout to be buffered\n");
3082+
3083+
dup_fd = _dup(STDERR_FILENO);
3084+
ok(dup_fd != -1, "_dup failed\n");
3085+
3086+
file = freopen("std_stream_test.tmp", "w", stderr);
3087+
ok(file != NULL, "freopen failed\n");
3088+
3089+
ret = fprintf(stderr, "test");
3090+
ok(ret == 4, "fprintf(stderr) returned %d\n", ret);
3091+
pos = _telli64(STDERR_FILENO);
3092+
ok(!pos, "expected stderr to be buffered\n");
3093+
3094+
fflush(stderr);
3095+
_dup2(dup_fd, STDERR_FILENO);
3096+
close(dup_fd);
3097+
3098+
dup_fd = _dup(STDIN_FILENO);
3099+
ok(dup_fd != -1, "_dup failed\n");
3100+
3101+
file = freopen("std_stream_test.tmp", "r", stdin);
3102+
ok(file != NULL, "freopen failed\n");
3103+
3104+
ch = 0;
3105+
ret = fscanf(stdin, "%c", &ch);
3106+
ok(ret == 1, "fscanf returned %d\n", ret);
3107+
ok(ch == 't', "ch = 0x%x\n", (unsigned char)ch);
3108+
pos = _telli64(STDIN_FILENO);
3109+
ok(pos == 4, "pos = %d\n", pos);
3110+
3111+
fflush(stdin);
3112+
_dup2(dup_fd, STDIN_FILENO);
3113+
close(dup_fd);
3114+
3115+
ok(DeleteFileA("std_stream_test.tmp"), "DeleteFile failed\n");
3116+
}
3117+
30603118
START_TEST(file)
30613119
{
30623120
int arg_c;
@@ -3133,6 +3191,7 @@ START_TEST(file)
31333191
test_fopen_hints();
31343192
test_open_hints();
31353193
test_ioinfo_flags();
3194+
test_std_stream_buffering();
31363195

31373196
/* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report
31383197
* file contains lines in the correct order

0 commit comments

Comments
 (0)
Please sign in to comment.