msvcrt: Use newer ioinfo structure for _MSVC_VER >= 80.
[wine.git] / dlls / msvcr80 / tests / msvcr80.c
blobc74cd8b93a2a1918271fa25b21d29b587f4acac0
1 /*
2 * Copyright 2022 Paul Gofman for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <share.h>
24 #include <sys/stat.h>
26 #include <windef.h>
27 #include <winbase.h>
28 #include <errno.h>
29 #include "wine/test.h"
31 #define WX_OPEN 0x01
32 #define WX_ATEOF 0x02
33 #define WX_READNL 0x04
34 #define WX_PIPE 0x08
35 #define WX_DONTINHERIT 0x10
36 #define WX_APPEND 0x20
37 #define WX_TTY 0x40
38 #define WX_TEXT 0x80
40 #define MSVCRT_FD_BLOCK_SIZE 32
42 typedef struct
44 HANDLE handle;
45 unsigned char wxflag;
46 char lookahead[3];
47 int exflag;
48 CRITICAL_SECTION crit;
49 char textmode : 7;
50 char unicode : 1;
51 char pipech2[2];
52 __int64 startpos;
53 BOOL utf8translations;
54 char dbcsBuffer;
55 BOOL dbcsBufferUsed;
56 } ioinfo;
58 static ioinfo **__pioinfo;
60 static int (__cdecl *p__open)(const char *, int, ...);
61 static int (__cdecl *p__close)(int);
62 static intptr_t (__cdecl *p__get_osfhandle)(int);
64 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
65 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
66 static BOOL init(void)
68 HMODULE hcrt;
70 SetLastError(0xdeadbeef);
71 hcrt = LoadLibraryA("msvcr80.dll");
72 if (!hcrt) {
73 win_skip("msvcr80.dll not installed (got %ld)\n", GetLastError());
74 return FALSE;
77 SET(__pioinfo, "__pioinfo");
78 SET(p__open,"_open");
79 SET(p__close,"_close");
80 SET(p__get_osfhandle, "_get_osfhandle");
82 return TRUE;
85 static void test_ioinfo_flags(void)
87 HANDLE handle;
88 ioinfo *info;
89 char *tempf;
90 int tempfd;
92 tempf = _tempnam(".","wne");
94 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_WTEXT, _S_IWRITE);
95 ok(tempfd != -1, "_open failed with error: %d\n", errno);
96 handle = (HANDLE)p__get_osfhandle(tempfd);
97 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
98 ok(!!info, "NULL info.\n");
99 ok(info->handle == handle, "Unexpected handle %p, expected %p.\n", info->handle, handle);
100 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
101 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
102 ok(info->unicode, "Unicode is not set.\n");
103 ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
104 p__close(tempfd);
106 ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
107 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
108 ok(info->unicode, "Unicode is not set.\n");
109 ok(!info->wxflag, "Unexpected wxflag %#x.\n", info->wxflag);
110 ok(info->textmode == 2, "Unexpected textmode %d.\n", info->textmode);
112 info = &__pioinfo[(tempfd + 4) / MSVCRT_FD_BLOCK_SIZE][(tempfd + 4) % MSVCRT_FD_BLOCK_SIZE];
113 ok(!!info, "NULL info.\n");
114 ok(info->handle == INVALID_HANDLE_VALUE, "Unexpected handle %p.\n", info->handle);
115 ok(!info->exflag, "Unexpected exflag %#x.\n", info->exflag);
116 ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
118 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_TEXT, _S_IWRITE);
119 ok(tempfd != -1, "_open failed with error: %d\n", errno);
120 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
121 ok(!!info, "NULL info.\n");
122 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
123 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
124 ok(!info->unicode, "Unicode is not set.\n");
125 ok(!info->textmode, "Unexpected textmode %d.\n", info->textmode);
126 p__close(tempfd);
128 tempfd = p__open(tempf, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_U8TEXT, _S_IWRITE);
129 ok(tempfd != -1, "_open failed with error: %d\n", errno);
130 info = &__pioinfo[tempfd / MSVCRT_FD_BLOCK_SIZE][tempfd % MSVCRT_FD_BLOCK_SIZE];
131 ok(!!info, "NULL info.\n");
132 ok(info->exflag == 1, "Unexpected exflag %#x.\n", info->exflag);
133 ok(info->wxflag == (WX_TEXT | WX_OPEN), "Unexpected wxflag %#x.\n", info->wxflag);
134 ok(!info->unicode, "Unicode is not set.\n");
135 ok(info->textmode == 1, "Unexpected textmode %d.\n", info->textmode);
136 p__close(tempfd);
138 unlink(tempf);
139 free(tempf);
142 START_TEST(msvcr80)
144 if(!init())
145 return;
147 test_ioinfo_flags();