msvcrt: Added tests in fileops with different buffer management modes.
This commit is contained in:
parent
0b9ddd1ce4
commit
dc9904a338
|
@ -106,54 +106,70 @@ static void test_fileops( void )
|
|||
int fd;
|
||||
FILE *file;
|
||||
fpos_t pos;
|
||||
int i, c;
|
||||
int i, c, bufmode;
|
||||
static const int bufmodes[] = {_IOFBF,_IONBF};
|
||||
|
||||
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE);
|
||||
write (fd, outbuffer, sizeof (outbuffer));
|
||||
close (fd);
|
||||
|
||||
fd = open ("fdopen.tst", O_RDONLY | O_BINARY);
|
||||
file = fdopen (fd, "rb");
|
||||
ok(strlen(outbuffer) == (sizeof(outbuffer)-1),"strlen/sizeof error\n");
|
||||
ok(fgets(buffer,sizeof(buffer),file) !=0,"fgets failed unexpected\n");
|
||||
ok(fgets(buffer,sizeof(buffer),file) ==0,"fgets didn't signal EOF\n");
|
||||
ok(feof(file) !=0,"feof doesn't signal EOF\n");
|
||||
rewind(file);
|
||||
ok(fgets(buffer,strlen(outbuffer),file) !=0,"fgets failed unexpected\n");
|
||||
ok(lstrlenA(buffer) == lstrlenA(outbuffer) -1,"fgets didn't read right size\n");
|
||||
ok(fgets(buffer,sizeof(outbuffer),file) !=0,"fgets failed unexpected\n");
|
||||
ok(strlen(buffer) == 1,"fgets dropped chars\n");
|
||||
ok(buffer[0] == outbuffer[strlen(outbuffer)-1],"fgets exchanged chars\n");
|
||||
|
||||
rewind(file);
|
||||
for (i = 0, c = EOF; i < sizeof(outbuffer); i++)
|
||||
for (bufmode=0; bufmode < sizeof(bufmodes)/sizeof(bufmodes[0]); bufmode++)
|
||||
{
|
||||
ok((c = fgetc(file)) == outbuffer[i], "fgetc returned wrong data\n");
|
||||
fd = open ("fdopen.tst", O_RDONLY | O_BINARY);
|
||||
file = fdopen (fd, "rb");
|
||||
setvbuf(file,NULL,bufmodes[bufmode],2048);
|
||||
ok(strlen(outbuffer) == (sizeof(outbuffer)-1),"strlen/sizeof error for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(fgets(buffer,sizeof(buffer),file) !=0,"fgets failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(fgets(buffer,sizeof(buffer),file) ==0,"fgets didn't signal EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(feof(file) !=0,"feof doesn't signal EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
rewind(file);
|
||||
ok(fgets(buffer,strlen(outbuffer),file) !=0,"fgets failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(lstrlenA(buffer) == lstrlenA(outbuffer) -1,"fgets didn't read right size for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(fgets(buffer,sizeof(outbuffer),file) !=0,"fgets failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(strlen(buffer) == 1,"fgets dropped chars for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(buffer[0] == outbuffer[strlen(outbuffer)-1],"fgets exchanged chars for bufmode=%x\n", bufmodes[bufmode]);
|
||||
|
||||
rewind(file);
|
||||
for (i = 0, c = EOF; i < sizeof(outbuffer); i++)
|
||||
{
|
||||
ok((c = fgetc(file)) == outbuffer[i], "fgetc returned wrong data for bufmode=%x\n", bufmodes[bufmode]);
|
||||
}
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(feof(file), "feof did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(ungetc(c, file) == EOF, "ungetc(EOF) did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(feof(file), "feof after ungetc(EOF) did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
c = outbuffer[sizeof(outbuffer) - 1];
|
||||
if (bufmodes[bufmode] == _IONBF) todo_wine {
|
||||
ok(ungetc(c, file) == c, "ungetc did not return its input for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(!feof(file), "feof after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok((c = fgetc(file)) != EOF, "getc after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(c == outbuffer[sizeof(outbuffer) - 1],
|
||||
"getc did not return ungetc'd data for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(!feof(file), "feof after getc returned EOF prematurely for bufmode=%x\n", bufmodes[bufmode]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok(ungetc(c, file) == c, "ungetc did not return its input for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(!feof(file), "feof after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok((c = fgetc(file)) != EOF, "getc after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(c == outbuffer[sizeof(outbuffer) - 1],
|
||||
"getc did not return ungetc'd data for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(!feof(file), "feof after getc returned EOF prematurely for bufmode=%x\n", bufmodes[bufmode]);
|
||||
}
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(feof(file), "feof after getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
|
||||
|
||||
rewind(file);
|
||||
ok(fgetpos(file,&pos) == 0, "fgetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(pos == 0, "Unexpected result of fgetpos %x%08x for bufmode=%x\n", (DWORD)(pos >> 32), (DWORD)pos, bufmodes[bufmode]);
|
||||
pos = sizeof (outbuffer);
|
||||
ok(fsetpos(file, &pos) == 0, "fsetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(fgetpos(file,&pos) == 0, "fgetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
|
||||
ok(pos == sizeof (outbuffer), "Unexpected result of fgetpos %x%08x for bufmode=%x\n", (DWORD)(pos >> 32), (DWORD)pos, bufmodes[bufmode]);
|
||||
|
||||
fclose (file);
|
||||
}
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
ok(feof(file), "feof did not return EOF\n");
|
||||
ok(ungetc(c, file) == EOF, "ungetc(EOF) did not return EOF\n");
|
||||
ok(feof(file), "feof after ungetc(EOF) did not return EOF\n");
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
c = outbuffer[sizeof(outbuffer) - 1];
|
||||
ok(ungetc(c, file) == c, "ungetc did not return its input\n");
|
||||
ok(!feof(file), "feof after ungetc returned EOF\n");
|
||||
ok((c = fgetc(file)) != EOF, "getc after ungetc returned EOF\n");
|
||||
ok(c == outbuffer[sizeof(outbuffer) - 1],
|
||||
"getc did not return ungetc'd data\n");
|
||||
ok(!feof(file), "feof after getc returned EOF prematurely\n");
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
ok(feof(file), "feof after getc did not return EOF\n");
|
||||
|
||||
rewind(file);
|
||||
ok(fgetpos(file,&pos) == 0, "fgetpos failed unexpected\n");
|
||||
ok(pos == 0, "Unexpected result of fgetpos %x%08x\n", (DWORD)(pos >> 32), (DWORD)pos);
|
||||
pos = sizeof (outbuffer);
|
||||
ok(fsetpos(file, &pos) == 0, "fsetpos failed unexpected\n");
|
||||
ok(fgetpos(file,&pos) == 0, "fgetpos failed unexpected\n");
|
||||
ok(pos == sizeof (outbuffer), "Unexpected result of fgetpos %x%08x\n", (DWORD)(pos >> 32), (DWORD)pos);
|
||||
|
||||
fclose (file);
|
||||
fd = open ("fdopen.tst", O_RDONLY | O_TEXT);
|
||||
file = fdopen (fd, "rt"); /* open in TEXT mode */
|
||||
ok(fgetws(wbuffer,sizeof(wbuffer)/sizeof(wbuffer[0]),file) !=0,"fgetws failed unexpected\n");
|
||||
|
|
Loading…
Reference in New Issue