msvcrt/tests: Add tests for fflush on input stream.
This commit is contained in:
parent
d59538f977
commit
09a7f8c196
|
@ -591,6 +591,58 @@ static void test_flsbuf( void )
|
||||||
free(tempf);
|
free(tempf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_fflush( void )
|
||||||
|
{
|
||||||
|
static const char obuf[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
|
char buf1[16], buf2[24];
|
||||||
|
char *tempf;
|
||||||
|
FILE *tempfh;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
tempf=_tempnam(".","wne");
|
||||||
|
|
||||||
|
/* Prepare the file. */
|
||||||
|
tempfh = fopen(tempf,"wb");
|
||||||
|
ok(tempfh != NULL, "Can't open test file.\n");
|
||||||
|
fwrite(obuf, 1, sizeof(obuf), tempfh);
|
||||||
|
fclose(tempfh);
|
||||||
|
|
||||||
|
/* Open the file for input. */
|
||||||
|
tempfh = fopen(tempf,"rb");
|
||||||
|
ok(tempfh != NULL, "Can't open test file.\n");
|
||||||
|
fread(buf1, 1, sizeof(buf1), tempfh);
|
||||||
|
|
||||||
|
/* Using fflush() on input stream is undefined in ANSI.
|
||||||
|
* But MSDN says that it clears input buffer. */
|
||||||
|
_lseek(_fileno(tempfh), 0, SEEK_SET);
|
||||||
|
ret = fflush(tempfh);
|
||||||
|
ok(ret == 0, "expected 0, got %d\n", ret);
|
||||||
|
memset(buf2, '?', sizeof(buf2));
|
||||||
|
fread(buf2, 1, sizeof(buf2), tempfh);
|
||||||
|
todo_wine ok(memcmp(buf1, buf2, sizeof(buf1)) == 0, "Got unexpected data (%c)\n", buf2[0]);
|
||||||
|
|
||||||
|
/* fflush(NULL) doesn't clear input buffer. */
|
||||||
|
_lseek(_fileno(tempfh), 0, SEEK_SET);
|
||||||
|
ret = fflush(NULL);
|
||||||
|
ok(ret == 0, "expected 0, got %d\n", ret);
|
||||||
|
memset(buf2, '?', sizeof(buf2));
|
||||||
|
fread(buf2, 1, sizeof(buf2), tempfh);
|
||||||
|
ok(memcmp(buf1, buf2, sizeof(buf1)) != 0, "Got unexpected data (%c)\n", buf2[0]);
|
||||||
|
|
||||||
|
/* _flushall() clears input buffer. */
|
||||||
|
_lseek(_fileno(tempfh), 0, SEEK_SET);
|
||||||
|
ret = _flushall();
|
||||||
|
ok(ret >= 0, "unexpected ret %d\n", ret);
|
||||||
|
memset(buf2, '?', sizeof(buf2));
|
||||||
|
fread(buf2, 1, sizeof(buf2), tempfh);
|
||||||
|
todo_wine ok(memcmp(buf1, buf2, sizeof(buf1)) == 0, "Got unexpected data (%c)\n", buf2[0]);
|
||||||
|
|
||||||
|
fclose(tempfh);
|
||||||
|
|
||||||
|
unlink(tempf);
|
||||||
|
free(tempf);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_fgetwc( void )
|
static void test_fgetwc( void )
|
||||||
{
|
{
|
||||||
#define LLEN 512
|
#define LLEN 512
|
||||||
|
@ -1582,6 +1634,7 @@ START_TEST(file)
|
||||||
test_fgetc();
|
test_fgetc();
|
||||||
test_fputc();
|
test_fputc();
|
||||||
test_flsbuf();
|
test_flsbuf();
|
||||||
|
test_fflush();
|
||||||
test_fgetwc();
|
test_fgetwc();
|
||||||
test_ctrlz();
|
test_ctrlz();
|
||||||
test_file_put_get();
|
test_file_put_get();
|
||||||
|
|
Loading…
Reference in New Issue