msvcr90/tests: Test ioinfo structure.

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2022-04-04 18:52:20 +03:00 committed by Alexandre Julliard
parent 1c9e9ec360
commit 7ebba96a95
1 changed files with 92 additions and 0 deletions

View File

@ -33,6 +33,33 @@
#include <errno.h>
#include "wine/test.h"
#define WX_OPEN 0x01
#define WX_ATEOF 0x02
#define WX_READNL 0x04
#define WX_PIPE 0x08
#define WX_DONTINHERIT 0x10
#define WX_APPEND 0x20
#define WX_TTY 0x40
#define WX_TEXT 0x80
#define MSVCRT_FD_BLOCK_SIZE 32
typedef struct {
HANDLE handle;
unsigned char wxflag;
char lookahead[3];
int exflag;
CRITICAL_SECTION crit;
char textmode : 7;
char unicode : 1;
char pipech2[2];
__int64 startpos;
BOOL utf8translations;
char dbcsBuffer;
BOOL dbcsBufferUsed;
} ioinfo;
static ioinfo **__pioinfo;
#define DEFINE_EXPECT(func) \
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
@ -84,6 +111,9 @@ static int (__cdecl *p_controlfp_s)(unsigned int *, unsigned int, unsigned int);
static int (__cdecl *p_tmpfile_s)(FILE**);
static int (__cdecl *p_atoflt)(_CRT_FLOAT *, char *);
static unsigned int (__cdecl *p_set_abort_behavior)(unsigned int, unsigned int);
static int (__cdecl *p__open)(const char *, int, ...);
static int (__cdecl *p__close)(int);
static intptr_t (__cdecl *p__get_osfhandle)(int);
static int (__cdecl *p_sopen_s)(int*, const char*, int, int, int);
static int (__cdecl *p_wsopen_s)(int*, const wchar_t*, int, int, int);
static void* (__cdecl *p_realloc_crt)(void*, size_t);
@ -362,6 +392,7 @@ static BOOL init(void)
ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
"Invalid parameter handler was already set\n");
SET(__pioinfo, "__pioinfo");
SET(p_initterm_e, "_initterm_e");
SET(p_encode_pointer, "_encode_pointer");
SET(p_decode_pointer, "_decode_pointer");
@ -382,6 +413,9 @@ static BOOL init(void)
SET(p_set_abort_behavior, "_set_abort_behavior");
SET(p_sopen_s, "_sopen_s");
SET(p_wsopen_s, "_wsopen_s");
SET(p__open,"_open");
SET(p__close,"_close");
SET(p__get_osfhandle, "_get_osfhandle");
SET(p_realloc_crt, "_realloc_crt");
SET(p_malloc, "malloc");
SET(p_free, "free");
@ -2350,6 +2384,63 @@ static void test__get_current_locale(void)
p_setlocale(LC_ALL, "C");
}
static void test_ioinfo_flags(void)
{
HANDLE handle;
ioinfo *info;
char *tempf;
int tempfd;
tempf = _tempnam(".","wne");
tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_WTEXT, _S_IWRITE);
ok(tempfd != -1, "_open failed with error: %d\n", errno);
handle = (HANDLE)p__get_osfhandle(tempfd);
info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
ok(!!info, "NULL info.\n");
ok(info->handle == handle, "Unexpected handle %p, expected %p.\n", info->handle, handle);
ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
ok(info->unicode, "Unicode is not set.\n");
ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
p__close(tempfd);
ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
ok(info->unicode, "Unicode is not set.\n");
ok(!info->wxflag, "Unexpected wxflag %#x.\n", info->wxflag);
ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
info = &__pioinfo[(tempfd + 4) / MSVCRT_FD_BLOCK_SIZE][(tempfd + 4) % MSVCRT_FD_BLOCK_SIZE];
ok(!!info, "NULL info.\n");
ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
ok(!info->exflag, "Unexpected exflag %#x.\n", info->exflag);
ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_TEXT, _S_IWRITE);
ok(tempfd != -1, "_open failed with error: %d\n", errno);
info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
ok(!!info, "NULL info.\n");
ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
ok(!info->unicode, "Unicode is not set.\n");
ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
p__close(tempfd);
tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_U8TEXT, _S_IWRITE);
ok(tempfd != -1, "_open failed with error: %d\n", errno);
info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
ok(!!info, "NULL info.\n");
ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
ok(!info->unicode, "Unicode is not set.\n");
ok(info->textmode == 1, "Unexpected textmode %d.\n", info->textmode);
p__close(tempfd);
unlink(tempf);
free(tempf);
}
START_TEST(msvcr90)
{
if(!init())
@ -2391,4 +2482,5 @@ START_TEST(msvcr90)
test_swscanf();
test____mb_cur_max_l_func();
test__get_current_locale();
test_ioinfo_flags();
}