ucrtbase/tests: Add FILE structure tests.

This commit is contained in:
Shengdun Wang 2024-06-06 13:54:38 +02:00 committed by Alexandre Julliard
parent fc8121d05f
commit f19676b321

View file

@ -81,7 +81,60 @@ static void test_std_stream_buffering(void)
ok(DeleteFileA("std_stream_test.tmp"), "DeleteFile failed\n");
}
int CDECL _get_stream_buffer_pointers(FILE*,char***,char***,int**);
static void test_iobuf_layout(void)
{
union
{
FILE *f;
struct
{
char* _ptr;
char* _base;
int _cnt;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
CRITICAL_SECTION _crit;
} *iobuf;
} fp;
char *tempf, *ptr, **file_ptr, **file_base;
int cnt, r, *file_cnt;
tempf = _tempnam(".","wne");
fp.f = fopen(tempf, "wb");
ok(fp.f != NULL, "fopen failed with error: %d\n", errno);
ok(!(fp.iobuf->_flag & 0x40), "fp.iobuf->_flag = %x\n", fp.iobuf->_flag);
r = fprintf(fp.f, "%s", "init");
ok(r == 4, "fprintf returned %d\n", r);
todo_wine ok(fp.iobuf->_flag & 0x40, "fp.iobuf->_flag = %x\n", fp.iobuf->_flag);
ok(fp.iobuf->_cnt + 4 == fp.iobuf->_bufsiz, "_cnt = %d, _bufsiz = %d\n",
fp.iobuf->_cnt, fp.iobuf->_bufsiz);
ptr = fp.iobuf->_ptr;
cnt = fp.iobuf->_cnt;
r = fprintf(fp.f, "%s", "hello");
ok(r == 5, "fprintf returned %d\n", r);
ok(ptr + 5 == fp.iobuf->_ptr, "fp.iobuf->_ptr = %p, expected %p\n", fp.iobuf->_ptr, ptr + 5);
ok(cnt - 5 == fp.iobuf->_cnt, "fp.iobuf->_cnt = %d, expected %d\n", fp.iobuf->_cnt, cnt - 5);
ok(fp.iobuf->_ptr + fp.iobuf->_cnt == fp.iobuf->_base + fp.iobuf->_bufsiz,
"_ptr = %p, _cnt = %d, _base = %p, _bufsiz = %d\n",
fp.iobuf->_ptr, fp.iobuf->_cnt, fp.iobuf->_base, fp.iobuf->_bufsiz);
_get_stream_buffer_pointers(fp.f, &file_base, &file_ptr, &file_cnt);
ok(file_base == &fp.iobuf->_base, "_base = %p, expected %p\n", file_base, &fp.iobuf->_base);
ok(file_ptr == &fp.iobuf->_ptr, "_ptr = %p, expected %p\n", file_ptr, &fp.iobuf->_ptr);
ok(file_cnt == &fp.iobuf->_cnt, "_cnt = %p, expected %p\n", file_cnt, &fp.iobuf->_cnt);
fclose(fp.f);
unlink(tempf);
}
START_TEST(file)
{
test_std_stream_buffering();
test_iobuf_layout();
}