kernel32/tests: Allow more last errors from win8.
[wine/multimedia.git] / dlls / kernel32 / tests / console.c
blob7c4366374c8b086c24d994ec68efd888f84bafd5
1 /*
2 * Unit tests for console API
4 * Copyright (c) 2003,2004 Eric Pouech
5 * Copyright (c) 2007 Kirill K. Smirnov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
23 #include <windows.h>
24 #include <stdio.h>
26 static BOOL (WINAPI *pGetConsoleInputExeNameA)(DWORD, LPSTR);
27 static DWORD (WINAPI *pGetConsoleProcessList)(LPDWORD, DWORD);
28 static HANDLE (WINAPI *pOpenConsoleW)(LPCWSTR,DWORD,BOOL,DWORD);
29 static BOOL (WINAPI *pSetConsoleInputExeNameA)(LPCSTR);
30 static BOOL (WINAPI *pVerifyConsoleIoHandle)(HANDLE handle);
32 /* DEFAULT_ATTRIB is used for all initial filling of the console.
33 * all modifications are made with TEST_ATTRIB so that we could check
34 * what has to be modified or not
36 #define TEST_ATTRIB (BACKGROUND_BLUE | FOREGROUND_GREEN)
37 #define DEFAULT_ATTRIB (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)
38 /* when filling the screen with non-blank chars, this macro defines
39 * what character should be at position 'c'
41 #define CONTENT(c) ('A' + (((c).Y * 17 + (c).X) % 23))
43 #define okCURSOR(hCon, c) do { \
44 CONSOLE_SCREEN_BUFFER_INFO __sbi; \
45 BOOL expect = GetConsoleScreenBufferInfo((hCon), &__sbi) && \
46 __sbi.dwCursorPosition.X == (c).X && __sbi.dwCursorPosition.Y == (c).Y; \
47 ok(expect, "Expected cursor at (%d,%d), got (%d,%d)\n", \
48 (c).X, (c).Y, __sbi.dwCursorPosition.X, __sbi.dwCursorPosition.Y); \
49 } while (0)
51 #define okCHAR(hCon, c, ch, attr) do { \
52 char __ch; WORD __attr; DWORD __len; BOOL expect; \
53 expect = ReadConsoleOutputCharacterA((hCon), &__ch, 1, (c), &__len) == 1 && __len == 1 && __ch == (ch); \
54 ok(expect, "At (%d,%d): expecting char '%c'/%02x got '%c'/%02x\n", (c).X, (c).Y, (ch), (ch), __ch, __ch); \
55 expect = ReadConsoleOutputAttribute((hCon), &__attr, 1, (c), &__len) == 1 && __len == 1 && __attr == (attr); \
56 ok(expect, "At (%d,%d): expecting attr %04x got %04x\n", (c).X, (c).Y, (attr), __attr); \
57 } while (0)
59 static void init_function_pointers(void)
61 HMODULE hKernel32;
63 #define KERNEL32_GET_PROC(func) \
64 p##func = (void *)GetProcAddress(hKernel32, #func); \
65 if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
67 hKernel32 = GetModuleHandleA("kernel32.dll");
68 KERNEL32_GET_PROC(GetConsoleInputExeNameA);
69 KERNEL32_GET_PROC(GetConsoleProcessList);
70 KERNEL32_GET_PROC(OpenConsoleW);
71 KERNEL32_GET_PROC(SetConsoleInputExeNameA);
72 KERNEL32_GET_PROC(VerifyConsoleIoHandle);
74 #undef KERNEL32_GET_PROC
77 /* FIXME: this could be optimized on a speed point of view */
78 static void resetContent(HANDLE hCon, COORD sbSize, BOOL content)
80 COORD c;
81 WORD attr = DEFAULT_ATTRIB;
82 char ch;
83 DWORD len;
85 for (c.X = 0; c.X < sbSize.X; c.X++)
87 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
89 ch = (content) ? CONTENT(c) : ' ';
90 WriteConsoleOutputAttribute(hCon, &attr, 1, c, &len);
91 WriteConsoleOutputCharacterA(hCon, &ch, 1, c, &len);
96 static void testCursor(HANDLE hCon, COORD sbSize)
98 COORD c;
100 c.X = c.Y = 0;
101 ok(SetConsoleCursorPosition(0, c) == 0, "No handle\n");
102 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %u\n",
103 ERROR_INVALID_HANDLE, GetLastError());
105 c.X = c.Y = 0;
106 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
107 okCURSOR(hCon, c);
109 c.X = sbSize.X - 1;
110 c.Y = sbSize.Y - 1;
111 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in lower-right\n");
112 okCURSOR(hCon, c);
114 c.X = sbSize.X;
115 c.Y = sbSize.Y - 1;
116 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
117 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\n",
118 ERROR_INVALID_PARAMETER, GetLastError());
120 c.X = sbSize.X - 1;
121 c.Y = sbSize.Y;
122 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
123 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\n",
124 ERROR_INVALID_PARAMETER, GetLastError());
126 c.X = -1;
127 c.Y = 0;
128 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
129 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\n",
130 ERROR_INVALID_PARAMETER, GetLastError());
132 c.X = 0;
133 c.Y = -1;
134 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
135 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %u\n",
136 ERROR_INVALID_PARAMETER, GetLastError());
139 static void testCursorInfo(HANDLE hCon)
141 BOOL ret;
142 CONSOLE_CURSOR_INFO info;
144 SetLastError(0xdeadbeef);
145 ret = GetConsoleCursorInfo(NULL, NULL);
146 ok(!ret, "Expected failure\n");
147 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %u\n",
148 ERROR_INVALID_HANDLE, GetLastError());
150 SetLastError(0xdeadbeef);
151 info.dwSize = -1;
152 ret = GetConsoleCursorInfo(NULL, &info);
153 ok(!ret, "Expected failure\n");
154 ok(info.dwSize == -1, "Expected no change for dwSize\n");
155 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %u\n",
156 ERROR_INVALID_HANDLE, GetLastError());
158 /* Test the correct call first to distinguish between win9x and the rest */
159 SetLastError(0xdeadbeef);
160 ret = GetConsoleCursorInfo(hCon, &info);
161 ok(ret, "Expected success\n");
162 ok(info.dwSize == 25 ||
163 info.dwSize == 12 /* win9x */,
164 "Expected 12 or 25, got %d\n", info.dwSize);
165 ok(info.bVisible, "Expected the cursor to be visible\n");
166 ok(GetLastError() == 0xdeadbeef, "GetLastError: expecting %u got %u\n",
167 0xdeadbeef, GetLastError());
169 /* Don't test NULL CONSOLE_CURSOR_INFO, it crashes on win9x and win7 */
172 static void testEmptyWrite(HANDLE hCon)
174 static const char emptybuf[16];
175 COORD c;
176 DWORD len;
178 c.X = c.Y = 0;
179 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
181 len = -1;
182 ok(WriteConsoleA(hCon, NULL, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
183 okCURSOR(hCon, c);
185 /* Passing a NULL lpBuffer with sufficiently large non-zero length succeeds
186 * on native Windows and result in memory-like contents being written to
187 * the console. Calling WriteConsoleW like this will crash on Wine. */
188 if (0)
190 len = -1;
191 ok(!WriteConsoleA(hCon, NULL, 16, &len, NULL) && len == -1, "WriteConsole\n");
192 okCURSOR(hCon, c);
194 /* Cursor advances for this call. */
195 len = -1;
196 ok(WriteConsoleA(hCon, NULL, 128, &len, NULL) != 0 && len == 128, "WriteConsole\n");
199 len = -1;
200 ok(WriteConsoleA(hCon, emptybuf, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
201 okCURSOR(hCon, c);
203 /* WriteConsole does not halt on a null terminator and is happy to write
204 * memory contents beyond the actual size of the buffer. */
205 len = -1;
206 ok(WriteConsoleA(hCon, emptybuf, 16, &len, NULL) != 0 && len == 16, "WriteConsole\n");
207 c.X += 16;
208 okCURSOR(hCon, c);
211 static void testWriteSimple(HANDLE hCon)
213 COORD c;
214 DWORD len;
215 const char* mytest = "abcdefg";
216 const int mylen = strlen(mytest);
218 /* single line write */
219 c.X = c.Y = 0;
220 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
222 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
223 c.Y = 0;
224 for (c.X = 0; c.X < mylen; c.X++)
226 okCHAR(hCon, c, mytest[c.X], TEST_ATTRIB);
229 okCURSOR(hCon, c);
230 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
233 static void testWriteNotWrappedNotProcessed(HANDLE hCon, COORD sbSize)
235 COORD c;
236 DWORD len, mode;
237 const char* mytest = "123";
238 const int mylen = strlen(mytest);
239 int ret;
240 int p;
242 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode & ~(ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT)),
243 "clearing wrap at EOL & processed output\n");
245 /* write line, wrapping disabled, buffer exceeds sb width */
246 c.X = sbSize.X - 3; c.Y = 0;
247 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
249 ret = WriteConsoleA(hCon, mytest, mylen, &len, NULL);
250 ok(ret != 0 && len == mylen, "Couldn't write, ret = %d, len = %d\n", ret, len);
251 c.Y = 0;
252 for (p = mylen - 3; p < mylen; p++)
254 c.X = sbSize.X - 3 + p % 3;
255 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
258 c.X = 0; c.Y = 1;
259 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
261 p = sbSize.X - 3 + mylen % 3;
262 c.X = p; c.Y = 0;
264 /* write line, wrapping disabled, strings end on end of line */
265 c.X = sbSize.X - mylen; c.Y = 0;
266 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
268 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
271 static void testWriteNotWrappedProcessed(HANDLE hCon, COORD sbSize)
273 COORD c;
274 DWORD len, mode;
275 const char* mytest = "abcd\nf\tg";
276 const int mylen = strlen(mytest);
277 const int mylen2 = strchr(mytest, '\n') - mytest;
278 int p;
279 WORD attr;
281 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, (mode | ENABLE_PROCESSED_OUTPUT) & ~ENABLE_WRAP_AT_EOL_OUTPUT),
282 "clearing wrap at EOL & setting processed output\n");
284 /* write line, wrapping disabled, buffer exceeds sb width */
285 c.X = sbSize.X - 5; c.Y = 0;
286 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-5\n");
288 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
289 c.Y = 0;
290 for (c.X = sbSize.X - 5; c.X < sbSize.X - 1; c.X++)
292 okCHAR(hCon, c, mytest[c.X - sbSize.X + 5], TEST_ATTRIB);
295 ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
296 /* Win9x and WinMe change the attribs for '\n' up to 'f' */
297 if (attr == TEST_ATTRIB)
299 win_skip("Win9x/WinMe don't respect ~ENABLE_WRAP_AT_EOL_OUTPUT\n");
300 return;
303 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
305 c.X = 0; c.Y++;
306 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
307 for (c.X = 1; c.X < 8; c.X++)
308 okCHAR(hCon, c, ' ', TEST_ATTRIB);
309 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
310 c.X++;
311 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
313 okCURSOR(hCon, c);
315 /* write line, wrapping disabled, strings end on end of line */
316 c.X = sbSize.X - 4; c.Y = 0;
317 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
319 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
320 c.Y = 0;
321 for (c.X = sbSize.X - 4; c.X < sbSize.X; c.X++)
323 okCHAR(hCon, c, mytest[c.X - sbSize.X + 4], TEST_ATTRIB);
325 c.X = 0; c.Y++;
326 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
327 for (c.X = 1; c.X < 8; c.X++)
328 okCHAR(hCon, c, ' ', TEST_ATTRIB);
329 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
330 c.X++;
331 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
333 okCURSOR(hCon, c);
335 /* write line, wrapping disabled, strings end after end of line */
336 c.X = sbSize.X - 3; c.Y = 0;
337 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
339 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
340 c.Y = 0;
341 for (p = mylen2 - 3; p < mylen2; p++)
343 c.X = sbSize.X - 3 + p % 3;
344 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
346 c.X = 0; c.Y = 1;
347 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
348 for (c.X = 1; c.X < 8; c.X++)
349 okCHAR(hCon, c, ' ', TEST_ATTRIB);
350 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
351 c.X++;
352 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
354 okCURSOR(hCon, c);
357 static void testWriteWrappedNotProcessed(HANDLE hCon, COORD sbSize)
359 COORD c;
360 DWORD len, mode;
361 const char* mytest = "abcd\nf\tg";
362 const int mylen = strlen(mytest);
363 int p;
365 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon,(mode | ENABLE_WRAP_AT_EOL_OUTPUT) & ~(ENABLE_PROCESSED_OUTPUT)),
366 "setting wrap at EOL & clearing processed output\n");
368 /* write line, wrapping enabled, buffer doesn't exceed sb width */
369 c.X = sbSize.X - 9; c.Y = 0;
370 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
372 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
373 c.Y = 0;
374 for (p = 0; p < mylen; p++)
376 c.X = sbSize.X - 9 + p;
377 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
379 c.X = sbSize.X - 9 + mylen;
380 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
381 c.X = 0; c.Y = 1;
382 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
384 /* write line, wrapping enabled, buffer does exceed sb width */
385 c.X = sbSize.X - 3; c.Y = 0;
386 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
388 c.Y = 1;
389 c.X = mylen - 3;
390 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
393 static void testWriteWrappedProcessed(HANDLE hCon, COORD sbSize)
395 COORD c;
396 DWORD len, mode;
397 const char* mytest = "abcd\nf\tg";
398 const int mylen = strlen(mytest);
399 int p;
400 WORD attr;
402 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode | (ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT)),
403 "setting wrap at EOL & processed output\n");
405 /* write line, wrapping enabled, buffer doesn't exceed sb width */
406 c.X = sbSize.X - 9; c.Y = 0;
407 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
409 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
410 for (p = 0; p < 4; p++)
412 c.X = sbSize.X - 9 + p;
413 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
415 c.X = sbSize.X - 9 + p;
416 ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
417 if (attr == TEST_ATTRIB)
418 win_skip("Win9x/WinMe changes attribs for '\\n' up to 'f'\n");
419 else
420 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
421 c.X = 0; c.Y++;
422 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
423 for (c.X = 1; c.X < 8; c.X++)
424 okCHAR(hCon, c, ' ', TEST_ATTRIB);
425 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
426 c.X++;
427 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
428 okCURSOR(hCon, c);
430 /* write line, wrapping enabled, buffer does exceed sb width */
431 c.X = sbSize.X - 3; c.Y = 2;
432 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
434 ok(WriteConsoleA(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
435 for (p = 0; p < 3; p++)
437 c.X = sbSize.X - 3 + p;
438 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
440 c.X = 0; c.Y++;
441 okCHAR(hCon, c, mytest[3], TEST_ATTRIB);
442 c.X++;
443 ReadConsoleOutputAttribute(hCon, &attr, 1, c, &len);
444 if (attr == TEST_ATTRIB)
445 win_skip("Win9x/WinMe changes attribs for '\\n' up to 'f'\n");
446 else
447 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
449 c.X = 0; c.Y++;
450 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
451 for (c.X = 1; c.X < 8; c.X++)
452 okCHAR(hCon, c, ' ', TEST_ATTRIB);
453 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
454 c.X++;
455 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
456 okCURSOR(hCon, c);
459 static void testWrite(HANDLE hCon, COORD sbSize)
461 /* FIXME: should in fact ensure that the sb is at least 10 characters wide */
462 ok(SetConsoleTextAttribute(hCon, TEST_ATTRIB), "Setting default text color\n");
463 resetContent(hCon, sbSize, FALSE);
464 testEmptyWrite(hCon);
465 resetContent(hCon, sbSize, FALSE);
466 testWriteSimple(hCon);
467 resetContent(hCon, sbSize, FALSE);
468 testWriteNotWrappedNotProcessed(hCon, sbSize);
469 resetContent(hCon, sbSize, FALSE);
470 testWriteNotWrappedProcessed(hCon, sbSize);
471 resetContent(hCon, sbSize, FALSE);
472 testWriteWrappedNotProcessed(hCon, sbSize);
473 resetContent(hCon, sbSize, FALSE);
474 testWriteWrappedProcessed(hCon, sbSize);
477 static void testScroll(HANDLE hCon, COORD sbSize)
479 SMALL_RECT scroll, clip;
480 COORD dst, c, tc;
481 CHAR_INFO ci;
482 BOOL ret;
484 #define W 11
485 #define H 7
487 #define IN_SRECT(r,c) ((r).Left <= (c).X && (c).X <= (r).Right && (r).Top <= (c).Y && (c).Y <= (r).Bottom)
488 #define IN_SRECT2(r,d,c) ((d).X <= (c).X && (c).X <= (d).X + (r).Right - (r).Left && (d).Y <= (c).Y && (c).Y <= (d).Y + (r).Bottom - (r).Top)
490 /* no clipping, src & dst rect don't overlap */
491 resetContent(hCon, sbSize, TRUE);
493 scroll.Left = 0;
494 scroll.Right = W - 1;
495 scroll.Top = 0;
496 scroll.Bottom = H - 1;
497 dst.X = W + 3;
498 dst.Y = H + 3;
499 ci.Char.UnicodeChar = '#';
500 ci.Attributes = TEST_ATTRIB;
502 clip.Left = 0;
503 clip.Right = sbSize.X - 1;
504 clip.Top = 0;
505 clip.Bottom = sbSize.Y - 1;
507 ok(ScrollConsoleScreenBufferA(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
509 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
511 for (c.X = 0; c.X < sbSize.X; c.X++)
513 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
515 tc.X = c.X - dst.X;
516 tc.Y = c.Y - dst.Y;
517 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
519 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
520 okCHAR(hCon, c, '#', TEST_ATTRIB);
521 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
525 /* no clipping, src & dst rect do overlap */
526 resetContent(hCon, sbSize, TRUE);
528 scroll.Left = 0;
529 scroll.Right = W - 1;
530 scroll.Top = 0;
531 scroll.Bottom = H - 1;
532 dst.X = W /2;
533 dst.Y = H / 2;
534 ci.Char.UnicodeChar = '#';
535 ci.Attributes = TEST_ATTRIB;
537 clip.Left = 0;
538 clip.Right = sbSize.X - 1;
539 clip.Top = 0;
540 clip.Bottom = sbSize.Y - 1;
542 ok(ScrollConsoleScreenBufferA(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
544 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
546 for (c.X = 0; c.X < sbSize.X; c.X++)
548 if (dst.X <= c.X && c.X < dst.X + W && dst.Y <= c.Y && c.Y < dst.Y + H)
550 tc.X = c.X - dst.X;
551 tc.Y = c.Y - dst.Y;
552 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
554 else if (c.X < W && c.Y < H) okCHAR(hCon, c, '#', TEST_ATTRIB);
555 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
559 /* clipping, src & dst rect don't overlap */
560 resetContent(hCon, sbSize, TRUE);
562 scroll.Left = 0;
563 scroll.Right = W - 1;
564 scroll.Top = 0;
565 scroll.Bottom = H - 1;
566 dst.X = W + 3;
567 dst.Y = H + 3;
568 ci.Char.UnicodeChar = '#';
569 ci.Attributes = TEST_ATTRIB;
571 clip.Left = W / 2;
572 clip.Right = min(W + W / 2, sbSize.X - 1);
573 clip.Top = H / 2;
574 clip.Bottom = min(H + H / 2, sbSize.Y - 1);
576 SetLastError(0xdeadbeef);
577 ret = ScrollConsoleScreenBufferA(hCon, &scroll, &clip, dst, &ci);
578 if (ret)
580 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
582 for (c.X = 0; c.X < sbSize.X; c.X++)
584 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
586 tc.X = c.X - dst.X;
587 tc.Y = c.Y - dst.Y;
588 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
590 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
591 okCHAR(hCon, c, '#', TEST_ATTRIB);
592 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
596 else
598 /* Win9x will fail, Only accept ERROR_NOT_ENOUGH_MEMORY */
599 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
600 "Expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
603 /* clipping, src & dst rect do overlap */
604 resetContent(hCon, sbSize, TRUE);
606 scroll.Left = 0;
607 scroll.Right = W - 1;
608 scroll.Top = 0;
609 scroll.Bottom = H - 1;
610 dst.X = W / 2 - 3;
611 dst.Y = H / 2 - 3;
612 ci.Char.UnicodeChar = '#';
613 ci.Attributes = TEST_ATTRIB;
615 clip.Left = W / 2;
616 clip.Right = min(W + W / 2, sbSize.X - 1);
617 clip.Top = H / 2;
618 clip.Bottom = min(H + H / 2, sbSize.Y - 1);
620 ok(ScrollConsoleScreenBufferA(hCon, &scroll, &clip, dst, &ci), "Scrolling SB\n");
622 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
624 for (c.X = 0; c.X < sbSize.X; c.X++)
626 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
628 tc.X = c.X - dst.X;
629 tc.Y = c.Y - dst.Y;
630 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
632 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
633 okCHAR(hCon, c, '#', TEST_ATTRIB);
634 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
639 static int mch_count;
640 /* we need the event as Wine console event generation isn't synchronous
641 * (ie GenerateConsoleCtrlEvent returns before all ctrl-handlers in all
642 * processes have been called).
644 static HANDLE mch_event;
645 static BOOL WINAPI mch(DWORD event)
647 mch_count++;
648 SetEvent(mch_event);
649 return TRUE;
652 static void testCtrlHandler(void)
654 ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
655 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %u\n", GetLastError());
656 ok(SetConsoleCtrlHandler(mch, TRUE), "Couldn't set handler\n");
657 /* wine requires the event for the test, as we cannot ensure, so far, that
658 * events are processed synchronously in GenerateConsoleCtrlEvent()
660 mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
661 mch_count = 0;
662 ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
663 /* FIXME: it isn't synchronous on wine but it can still happen before we test */
664 if (0) ok(mch_count == 1, "Event isn't synchronous\n");
665 ok(WaitForSingleObject(mch_event, 3000) == WAIT_OBJECT_0, "event sending didn't work\n");
666 CloseHandle(mch_event);
668 /* Turning off ctrl-c handling doesn't work on win9x such way ... */
669 ok(SetConsoleCtrlHandler(NULL, TRUE), "Couldn't turn off ctrl-c handling\n");
670 mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
671 mch_count = 0;
672 if(!(GetVersion() & 0x80000000))
673 /* ... and next line leads to an unhandled exception on 9x. Avoid it on 9x. */
674 ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
675 ok(WaitForSingleObject(mch_event, 3000) == WAIT_TIMEOUT && mch_count == 0, "Event shouldn't have been sent\n");
676 CloseHandle(mch_event);
677 ok(SetConsoleCtrlHandler(mch, FALSE), "Couldn't remove handler\n");
678 ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
679 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %u\n", GetLastError());
683 * Test console screen buffer:
684 * 1) Try to set invalid handle.
685 * 2) Try to set non-console handles.
686 * 3) Use CONOUT$ file as active SB.
687 * 4) Test cursor.
688 * 5) Test output codepage to show it is not a property of SB.
689 * 6) Test switching to old SB if we close all handles to current SB - works
690 * in Windows, TODO in wine.
692 * What is not tested but should be:
693 * 1) ScreenBufferInfo
695 static void testScreenBuffer(HANDLE hConOut)
697 HANDLE hConOutRW, hConOutRO, hConOutWT;
698 HANDLE hFileOutRW, hFileOutRO, hFileOutWT;
699 HANDLE hConOutNew;
700 char test_str1[] = "Test for SB1";
701 char test_str2[] = "Test for SB2";
702 char test_cp866[] = {0xe2, 0xa5, 0xe1, 0xe2, 0};
703 char test_cp1251[] = {0xf2, 0xe5, 0xf1, 0xf2, 0};
704 WCHAR test_unicode[] = {0x0442, 0x0435, 0x0441, 0x0442, 0};
705 WCHAR str_wbuf[20];
706 char str_buf[20];
707 DWORD len, error;
708 COORD c;
709 BOOL ret;
710 DWORD oldcp;
712 if (!IsValidCodePage(866))
714 skip("Codepage 866 not available\n");
715 return;
718 /* In the beginning set output codepage to 866 */
719 oldcp = GetConsoleOutputCP();
720 SetLastError(0xdeadbeef);
721 ret = SetConsoleOutputCP(866);
722 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
724 win_skip("SetConsoleOutputCP is not implemented\n");
725 return;
727 ok(ret, "Cannot set output codepage to 866\n");
729 hConOutRW = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
730 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
731 CONSOLE_TEXTMODE_BUFFER, NULL);
732 ok(hConOutRW != INVALID_HANDLE_VALUE,
733 "Cannot create a new screen buffer for ReadWrite\n");
734 hConOutRO = CreateConsoleScreenBuffer(GENERIC_READ,
735 FILE_SHARE_READ, NULL,
736 CONSOLE_TEXTMODE_BUFFER, NULL);
737 ok(hConOutRO != INVALID_HANDLE_VALUE,
738 "Cannot create a new screen buffer for ReadOnly\n");
739 hConOutWT = CreateConsoleScreenBuffer(GENERIC_WRITE,
740 FILE_SHARE_WRITE, NULL,
741 CONSOLE_TEXTMODE_BUFFER, NULL);
742 ok(hConOutWT != INVALID_HANDLE_VALUE,
743 "Cannot create a new screen buffer for WriteOnly\n");
745 hFileOutRW = CreateFileA("NUL", GENERIC_READ | GENERIC_WRITE,
746 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
747 OPEN_EXISTING, 0, NULL);
748 ok(hFileOutRW != INVALID_HANDLE_VALUE, "Cannot open NUL for ReadWrite\n");
749 hFileOutRO = CreateFileA("NUL", GENERIC_READ, FILE_SHARE_READ,
750 NULL, OPEN_EXISTING, 0, NULL);
751 ok(hFileOutRO != INVALID_HANDLE_VALUE, "Cannot open NUL for ReadOnly\n");
752 hFileOutWT = CreateFileA("NUL", GENERIC_WRITE, FILE_SHARE_WRITE,
753 NULL, OPEN_EXISTING, 0, NULL);
754 ok(hFileOutWT != INVALID_HANDLE_VALUE, "Cannot open NUL for WriteOnly\n");
756 /* Trying to set invalid handle */
757 SetLastError(0);
758 ok(!SetConsoleActiveScreenBuffer(INVALID_HANDLE_VALUE),
759 "Shouldn't succeed\n");
760 ok(GetLastError() == ERROR_INVALID_HANDLE,
761 "GetLastError: expecting %u got %u\n",
762 ERROR_INVALID_HANDLE, GetLastError());
764 /* Trying to set non-console handles */
765 SetLastError(0);
766 ok(!SetConsoleActiveScreenBuffer(hFileOutRW), "Shouldn't succeed\n");
767 ok(GetLastError() == ERROR_INVALID_HANDLE,
768 "GetLastError: expecting %u got %u\n",
769 ERROR_INVALID_HANDLE, GetLastError());
771 SetLastError(0);
772 ok(!SetConsoleActiveScreenBuffer(hFileOutRO), "Shouldn't succeed\n");
773 ok(GetLastError() == ERROR_INVALID_HANDLE,
774 "GetLastError: expecting %u got %u\n",
775 ERROR_INVALID_HANDLE, GetLastError());
777 SetLastError(0);
778 ok(!SetConsoleActiveScreenBuffer(hFileOutWT), "Shouldn't succeed\n");
779 ok(GetLastError() == ERROR_INVALID_HANDLE,
780 "GetLastError: expecting %u got %u\n",
781 ERROR_INVALID_HANDLE, GetLastError());
783 /* trying to write non-console handle */
784 SetLastError(0xdeadbeef);
785 ret = WriteConsoleA(hFileOutRW, test_str1, lstrlenA(test_str1), &len, NULL);
786 error = GetLastError();
787 ok(!ret, "Shouldn't succeed\n");
788 ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
789 "GetLastError: got %u\n", error);
791 SetLastError(0xdeadbeef);
792 ret = WriteConsoleA(hFileOutRO, test_str1, lstrlenA(test_str1), &len, NULL);
793 error = GetLastError();
794 ok(!ret, "Shouldn't succeed\n");
795 ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
796 "GetLastError: got %u\n", error);
798 SetLastError(0xdeadbeef);
799 ret = WriteConsoleA(hFileOutWT, test_str1, lstrlenA(test_str1), &len, NULL);
800 error = GetLastError();
801 ok(!ret, "Shouldn't succeed\n");
802 todo_wine ok(error == ERROR_INVALID_HANDLE || error == ERROR_INVALID_FUNCTION,
803 "GetLastError: got %u\n", error);
805 CloseHandle(hFileOutRW);
806 CloseHandle(hFileOutRO);
807 CloseHandle(hFileOutWT);
809 /* Trying to set SB handles with various access modes */
810 SetLastError(0);
811 ok(!SetConsoleActiveScreenBuffer(hConOutRO), "Shouldn't succeed\n");
812 ok(GetLastError() == ERROR_INVALID_HANDLE,
813 "GetLastError: expecting %u got %u\n",
814 ERROR_INVALID_HANDLE, GetLastError());
816 ok(SetConsoleActiveScreenBuffer(hConOutWT), "Couldn't set new WriteOnly SB\n");
818 ok(SetConsoleActiveScreenBuffer(hConOutRW), "Couldn't set new ReadWrite SB\n");
820 CloseHandle(hConOutWT);
821 CloseHandle(hConOutRO);
823 /* Now we have two ReadWrite SB, active must be hConOutRW */
824 /* Open current SB via CONOUT$ */
825 hConOutNew = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0,
826 NULL, OPEN_EXISTING, 0, 0);
827 ok(hConOutNew != INVALID_HANDLE_VALUE, "CONOUT$ is not opened\n");
830 /* test cursor */
831 c.X = c.Y = 10;
832 SetConsoleCursorPosition(hConOut, c);
833 c.X = c.Y = 5;
834 SetConsoleCursorPosition(hConOutRW, c);
835 okCURSOR(hConOutNew, c);
836 c.X = c.Y = 10;
837 okCURSOR(hConOut, c);
840 c.X = c.Y = 0;
842 /* Write using hConOutNew... */
843 SetConsoleCursorPosition(hConOutNew, c);
844 ret = WriteConsoleA(hConOutNew, test_str2, lstrlenA(test_str2), &len, NULL);
845 ok (ret && len == lstrlenA(test_str2), "WriteConsoleA failed\n");
846 /* ... and read it back via hConOutRW */
847 ret = ReadConsoleOutputCharacterA(hConOutRW, str_buf, lstrlenA(test_str2), c, &len);
848 ok(ret && len == lstrlenA(test_str2), "ReadConsoleOutputCharacterA failed\n");
849 str_buf[lstrlenA(test_str2)] = 0;
850 ok(!lstrcmpA(str_buf, test_str2), "got '%s' expected '%s'\n", str_buf, test_str2);
853 /* Now test output codepage handling. Current is 866 as we set earlier. */
854 SetConsoleCursorPosition(hConOutRW, c);
855 ret = WriteConsoleA(hConOutRW, test_cp866, lstrlenA(test_cp866), &len, NULL);
856 ok(ret && len == lstrlenA(test_cp866), "WriteConsoleA failed\n");
857 ret = ReadConsoleOutputCharacterW(hConOutRW, str_wbuf, lstrlenA(test_cp866), c, &len);
858 ok(ret && len == lstrlenA(test_cp866), "ReadConsoleOutputCharacterW failed\n");
859 str_wbuf[lstrlenA(test_cp866)] = 0;
860 ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
863 * cp866 is OK, let's switch to cp1251.
864 * We expect that this codepage will be used in every SB - active and not.
866 ok(SetConsoleOutputCP(1251), "Cannot set output cp to 1251\n");
867 SetConsoleCursorPosition(hConOutRW, c);
868 ret = WriteConsoleA(hConOutRW, test_cp1251, lstrlenA(test_cp1251), &len, NULL);
869 ok(ret && len == lstrlenA(test_cp1251), "WriteConsoleA failed\n");
870 ret = ReadConsoleOutputCharacterW(hConOutRW, str_wbuf, lstrlenA(test_cp1251), c, &len);
871 ok(ret && len == lstrlenA(test_cp1251), "ReadConsoleOutputCharacterW failed\n");
872 str_wbuf[lstrlenA(test_cp1251)] = 0;
873 ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
875 /* Check what has happened to hConOut. */
876 SetConsoleCursorPosition(hConOut, c);
877 ret = WriteConsoleA(hConOut, test_cp1251, lstrlenA(test_cp1251), &len, NULL);
878 ok(ret && len == lstrlenA(test_cp1251), "WriteConsoleA failed\n");
879 ret = ReadConsoleOutputCharacterW(hConOut, str_wbuf, lstrlenA(test_cp1251), c, &len);
880 ok(ret && len == lstrlenA(test_cp1251), "ReadConsoleOutputCharacterW failed\n");
881 str_wbuf[lstrlenA(test_cp1251)] = 0;
882 ok(!lstrcmpW(str_wbuf, test_unicode), "string does not match the pattern\n");
884 /* Close all handles of current console SB */
885 CloseHandle(hConOutNew);
886 CloseHandle(hConOutRW);
888 /* Now active SB should be hConOut */
889 hConOutNew = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0,
890 NULL, OPEN_EXISTING, 0, 0);
891 ok(hConOutNew != INVALID_HANDLE_VALUE, "CONOUT$ is not opened\n");
893 /* Write using hConOutNew... */
894 SetConsoleCursorPosition(hConOutNew, c);
895 ret = WriteConsoleA(hConOutNew, test_str1, lstrlenA(test_str1), &len, NULL);
896 ok (ret && len == lstrlenA(test_str1), "WriteConsoleA failed\n");
897 /* ... and read it back via hConOut */
898 ret = ReadConsoleOutputCharacterA(hConOut, str_buf, lstrlenA(test_str1), c, &len);
899 ok(ret && len == lstrlenA(test_str1), "ReadConsoleOutputCharacterA failed\n");
900 str_buf[lstrlenA(test_str1)] = 0;
901 todo_wine ok(!lstrcmpA(str_buf, test_str1), "got '%s' expected '%s'\n", str_buf, test_str1);
902 CloseHandle(hConOutNew);
904 /* This is not really needed under Windows */
905 SetConsoleActiveScreenBuffer(hConOut);
907 /* restore codepage */
908 SetConsoleOutputCP(oldcp);
911 static void test_GetSetConsoleInputExeName(void)
913 BOOL ret;
914 DWORD error;
915 char buffer[MAX_PATH], module[MAX_PATH], *p;
916 static char input_exe[MAX_PATH] = "winetest.exe";
918 SetLastError(0xdeadbeef);
919 ret = pGetConsoleInputExeNameA(0, NULL);
920 error = GetLastError();
921 ok(ret, "GetConsoleInputExeNameA failed\n");
922 ok(error == ERROR_BUFFER_OVERFLOW, "got %u expected ERROR_BUFFER_OVERFLOW\n", error);
924 SetLastError(0xdeadbeef);
925 ret = pGetConsoleInputExeNameA(0, buffer);
926 error = GetLastError();
927 ok(ret, "GetConsoleInputExeNameA failed\n");
928 ok(error == ERROR_BUFFER_OVERFLOW, "got %u expected ERROR_BUFFER_OVERFLOW\n", error);
930 GetModuleFileNameA(GetModuleHandleA(NULL), module, sizeof(module));
931 p = strrchr(module, '\\') + 1;
933 ret = pGetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer);
934 ok(ret, "GetConsoleInputExeNameA failed\n");
935 todo_wine ok(!lstrcmpA(buffer, p), "got %s expected %s\n", buffer, p);
937 SetLastError(0xdeadbeef);
938 ret = pSetConsoleInputExeNameA(NULL);
939 error = GetLastError();
940 ok(!ret, "SetConsoleInputExeNameA failed\n");
941 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
943 SetLastError(0xdeadbeef);
944 ret = pSetConsoleInputExeNameA("");
945 error = GetLastError();
946 ok(!ret, "SetConsoleInputExeNameA failed\n");
947 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
949 ret = pSetConsoleInputExeNameA(input_exe);
950 ok(ret, "SetConsoleInputExeNameA failed\n");
952 ret = pGetConsoleInputExeNameA(sizeof(buffer)/sizeof(buffer[0]), buffer);
953 ok(ret, "GetConsoleInputExeNameA failed\n");
954 ok(!lstrcmpA(buffer, input_exe), "got %s expected %s\n", buffer, input_exe);
957 static void test_GetConsoleProcessList(void)
959 DWORD ret, *list = NULL;
961 if (!pGetConsoleProcessList)
963 win_skip("GetConsoleProcessList is not available\n");
964 return;
967 SetLastError(0xdeadbeef);
968 ret = pGetConsoleProcessList(NULL, 0);
969 ok(ret == 0, "Expected failure\n");
970 ok(GetLastError() == ERROR_INVALID_PARAMETER,
971 "Expected ERROR_INVALID_PARAMETER, got %d\n",
972 GetLastError());
974 SetLastError(0xdeadbeef);
975 ret = pGetConsoleProcessList(NULL, 1);
976 ok(ret == 0, "Expected failure\n");
977 ok(GetLastError() == ERROR_INVALID_PARAMETER,
978 "Expected ERROR_INVALID_PARAMETER, got %d\n",
979 GetLastError());
981 /* We should only have 1 process but only for these specific unit tests as
982 * we created our own console. An AttachConsole(ATTACH_PARENT_PROCESS) would
983 * give us two processes for example.
985 list = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
987 SetLastError(0xdeadbeef);
988 ret = pGetConsoleProcessList(list, 0);
989 ok(ret == 0, "Expected failure\n");
990 ok(GetLastError() == ERROR_INVALID_PARAMETER,
991 "Expected ERROR_INVALID_PARAMETER, got %d\n",
992 GetLastError());
994 SetLastError(0xdeadbeef);
995 ret = pGetConsoleProcessList(list, 1);
996 todo_wine
997 ok(ret == 1, "Expected 1, got %d\n", ret);
999 HeapFree(GetProcessHeap(), 0, list);
1001 list = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(DWORD));
1003 SetLastError(0xdeadbeef);
1004 ret = pGetConsoleProcessList(list, ret);
1005 todo_wine
1006 ok(ret == 1, "Expected 1, got %d\n", ret);
1008 if (ret == 1)
1010 DWORD pid = GetCurrentProcessId();
1011 ok(list[0] == pid, "Expected %d, got %d\n", pid, list[0]);
1014 HeapFree(GetProcessHeap(), 0, list);
1017 static void test_OpenCON(void)
1019 static const WCHAR conW[] = {'C','O','N',0};
1020 static const DWORD accesses[] = {CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING,
1021 OPEN_ALWAYS, TRUNCATE_EXISTING};
1022 unsigned i;
1023 HANDLE h;
1025 for (i = 0; i < sizeof(accesses) / sizeof(accesses[0]); i++)
1027 h = CreateFileW(conW, GENERIC_WRITE, 0, NULL, accesses[i], 0, NULL);
1028 ok(h != INVALID_HANDLE_VALUE || broken(accesses[i] == TRUNCATE_EXISTING /* Win8 */),
1029 "Expected to open the CON device on write (%x)\n", accesses[i]);
1030 CloseHandle(h);
1032 h = CreateFileW(conW, GENERIC_READ, 0, NULL, accesses[i], 0, NULL);
1033 /* Windows versions differ here:
1034 * MSDN states in CreateFile that TRUNCATE_EXISTING requires GENERIC_WRITE
1035 * NT, XP, Vista comply, but Win7 doesn't and allows opening CON with TRUNCATE_EXISTING
1036 * So don't test when disposition is TRUNCATE_EXISTING
1038 ok(h != INVALID_HANDLE_VALUE || broken(accesses[i] == TRUNCATE_EXISTING /* Win7+ */),
1039 "Expected to open the CON device on read (%x)\n", accesses[i]);
1040 CloseHandle(h);
1041 h = CreateFileW(conW, GENERIC_READ|GENERIC_WRITE, 0, NULL, accesses[i], 0, NULL);
1042 ok(h == INVALID_HANDLE_VALUE, "Expected not to open the CON device on read-write (%x)\n", accesses[i]);
1043 ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
1044 "Unexpected error %x\n", GetLastError());
1048 static void test_OpenConsoleW(void)
1050 static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
1051 static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
1052 static const WCHAR emptyW[] = {0};
1053 static const WCHAR invalidW[] = {'I','N','V','A','L','I','D',0};
1054 DWORD gle;
1056 static const struct
1058 LPCWSTR name;
1059 DWORD access;
1060 BOOL inherit;
1061 DWORD creation;
1062 DWORD gle, gle2;
1063 } invalid_table[] = {
1064 {NULL, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1065 {NULL, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1066 {NULL, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1067 {NULL, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1068 {NULL, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1069 {NULL, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1070 {NULL, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1071 {NULL, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1072 {emptyW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1073 {emptyW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1074 {emptyW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1075 {emptyW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1076 {emptyW, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1077 {emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1078 {emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1079 {emptyW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_PATH_NOT_FOUND},
1080 {invalidW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1081 {invalidW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1082 {invalidW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1083 {invalidW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1084 {invalidW, 0, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1085 {invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1086 {invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1087 {invalidW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING, ERROR_INVALID_PARAMETER, ERROR_FILE_NOT_FOUND},
1088 {coninW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1089 {coninW, 0xdeadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_ACCESS_DENIED},
1090 {coninW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1091 {conoutW, 0, FALSE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1092 {conoutW, 0xceadbeef, FALSE, 0, ERROR_INVALID_PARAMETER, ERROR_ACCESS_DENIED},
1093 {conoutW, 0xdeadbeef, TRUE, 0xdeadbeef, ERROR_INVALID_PARAMETER, 0},
1095 static const struct
1097 LPCWSTR name;
1098 DWORD access;
1099 BOOL inherit;
1100 DWORD creation;
1101 } valid_table[] = {
1102 {coninW, 0, FALSE, 0 },
1103 {coninW, 0, TRUE, 0 },
1104 {coninW, GENERIC_EXECUTE, TRUE, 0 },
1105 {coninW, GENERIC_ALL, TRUE, 0 },
1106 {coninW, 0, FALSE, OPEN_ALWAYS },
1107 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, 0 },
1108 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW },
1109 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS },
1110 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS },
1111 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, TRUNCATE_EXISTING},
1112 {conoutW, 0, FALSE, 0 },
1113 {conoutW, 0, FALSE, OPEN_ALWAYS },
1114 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, 0 },
1115 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, },
1116 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS },
1117 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS },
1118 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, TRUNCATE_EXISTING},
1121 int index;
1122 HANDLE ret;
1124 if (!pOpenConsoleW)
1126 win_skip("OpenConsoleW is not available\n");
1127 return;
1130 for (index = 0; index < sizeof(invalid_table)/sizeof(invalid_table[0]); index++)
1132 SetLastError(0xdeadbeef);
1133 ret = pOpenConsoleW(invalid_table[index].name, invalid_table[index].access,
1134 invalid_table[index].inherit, invalid_table[index].creation);
1135 gle = GetLastError();
1136 ok(ret == INVALID_HANDLE_VALUE,
1137 "Expected OpenConsoleW to return INVALID_HANDLE_VALUE for index %d, got %p\n",
1138 index, ret);
1139 ok(gle == invalid_table[index].gle || (gle != 0 && gle == invalid_table[index].gle2),
1140 "Expected GetLastError() to return %u/%u for index %d, got %u\n",
1141 invalid_table[index].gle, invalid_table[index].gle2, index, gle);
1144 for (index = 0; index < sizeof(valid_table)/sizeof(valid_table[0]); index++)
1146 ret = pOpenConsoleW(valid_table[index].name, valid_table[index].access,
1147 valid_table[index].inherit, valid_table[index].creation);
1148 todo_wine
1149 ok(ret != INVALID_HANDLE_VALUE || broken(ret == INVALID_HANDLE_VALUE /* until Win7 */),
1150 "Expected OpenConsoleW to succeed for index %d, got %p\n", index, ret);
1151 if (ret != INVALID_HANDLE_VALUE)
1152 CloseHandle(ret);
1155 /* OpenConsoleW should not touch the last error on success. */
1156 SetLastError(0xdeadbeef);
1157 ret = pOpenConsoleW(coninW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING);
1158 ok(ret != INVALID_HANDLE_VALUE,
1159 "Expected OpenConsoleW to return a valid handle\n");
1160 ok(GetLastError() == 0xdeadbeef,
1161 "Expected the last error to be untouched, got %u\n", GetLastError());
1162 if (ret != INVALID_HANDLE_VALUE)
1163 CloseHandle(ret);
1165 SetLastError(0xdeadbeef);
1166 ret = pOpenConsoleW(conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_EXISTING);
1167 ok(ret != INVALID_HANDLE_VALUE,
1168 "Expected OpenConsoleW to return a valid handle\n");
1169 ok(GetLastError() == 0xdeadbeef,
1170 "Expected the last error to be untouched, got %u\n", GetLastError());
1171 if (ret != INVALID_HANDLE_VALUE)
1172 CloseHandle(ret);
1175 static void test_CreateFileW(void)
1177 static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
1178 static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
1180 static const struct
1182 LPCWSTR name;
1183 DWORD access;
1184 BOOL inherit;
1185 DWORD creation;
1186 DWORD gle;
1187 BOOL is_broken;
1188 } cf_table[] = {
1189 {coninW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
1190 {coninW, 0, FALSE, OPEN_ALWAYS, 0, FALSE},
1191 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
1192 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, 0, FALSE},
1193 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS, 0, FALSE},
1194 {coninW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, 0, FALSE},
1195 {conoutW, 0, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
1196 {conoutW, 0, FALSE, OPEN_ALWAYS, 0, FALSE},
1197 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, 0, ERROR_INVALID_PARAMETER, TRUE},
1198 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_NEW, 0, FALSE},
1199 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, CREATE_ALWAYS, 0, FALSE},
1200 {conoutW, GENERIC_READ | GENERIC_WRITE, FALSE, OPEN_ALWAYS, 0, FALSE},
1201 /* TRUNCATE_EXISTING is forbidden starting with Windows 8 */
1204 int index;
1205 HANDLE ret;
1206 SECURITY_ATTRIBUTES sa;
1208 for (index = 0; index < sizeof(cf_table)/sizeof(cf_table[0]); index++)
1210 SetLastError(0xdeadbeef);
1212 sa.nLength = sizeof(sa);
1213 sa.lpSecurityDescriptor = NULL;
1214 sa.bInheritHandle = cf_table[index].inherit;
1216 ret = CreateFileW(cf_table[index].name, cf_table[index].access,
1217 FILE_SHARE_READ|FILE_SHARE_WRITE, &sa,
1218 cf_table[index].creation, FILE_ATTRIBUTE_NORMAL, NULL);
1219 if (ret == INVALID_HANDLE_VALUE)
1221 ok(cf_table[index].gle,
1222 "Expected CreateFileW not to return INVALID_HANDLE_VALUE for index %d\n", index);
1223 ok(GetLastError() == cf_table[index].gle,
1224 "Expected GetLastError() to return %u for index %d, got %u\n",
1225 cf_table[index].gle, index, GetLastError());
1227 else
1229 ok(!cf_table[index].gle || broken(cf_table[index].is_broken) /* Win7 */,
1230 "Expected CreateFileW to succeed for index %d\n", index);
1231 CloseHandle(ret);
1236 static void test_VerifyConsoleIoHandle( HANDLE handle )
1238 BOOL ret;
1239 DWORD error;
1241 if (!pVerifyConsoleIoHandle)
1243 win_skip("VerifyConsoleIoHandle is not available\n");
1244 return;
1247 /* invalid handle */
1248 SetLastError(0xdeadbeef);
1249 ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee0);
1250 error = GetLastError();
1251 ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
1252 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1254 /* invalid handle + 1 */
1255 SetLastError(0xdeadbeef);
1256 ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee1);
1257 error = GetLastError();
1258 ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
1259 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1261 /* invalid handle + 2 */
1262 SetLastError(0xdeadbeef);
1263 ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee2);
1264 error = GetLastError();
1265 ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
1266 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1268 /* invalid handle + 3 */
1269 SetLastError(0xdeadbeef);
1270 ret = pVerifyConsoleIoHandle((HANDLE)0xdeadbee3);
1271 error = GetLastError();
1272 ok(!ret, "expected VerifyConsoleIoHandle to fail\n");
1273 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1275 /* valid handle */
1276 SetLastError(0xdeadbeef);
1277 ret = pVerifyConsoleIoHandle(handle);
1278 error = GetLastError();
1279 ok(ret, "expected VerifyConsoleIoHandle to succeed\n");
1280 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1283 static void test_GetSetStdHandle(void)
1285 HANDLE handle;
1286 DWORD error;
1287 BOOL ret;
1289 /* get invalid std handle */
1290 SetLastError(0xdeadbeef);
1291 handle = GetStdHandle(42);
1292 error = GetLastError();
1293 ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
1294 "wrong GetLastError() %d\n", error);
1295 ok(handle == INVALID_HANDLE_VALUE, "expected INVALID_HANDLE_VALUE\n");
1297 /* get valid */
1298 SetLastError(0xdeadbeef);
1299 handle = GetStdHandle(STD_INPUT_HANDLE);
1300 error = GetLastError();
1301 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1303 /* set invalid std handle */
1304 SetLastError(0xdeadbeef);
1305 ret = SetStdHandle(42, handle);
1306 error = GetLastError();
1307 ok(!ret, "expected SetStdHandle to fail\n");
1308 ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
1309 "wrong GetLastError() %d\n", error);
1311 /* set valid (restore old value) */
1312 SetLastError(0xdeadbeef);
1313 ret = SetStdHandle(STD_INPUT_HANDLE, handle);
1314 error = GetLastError();
1315 ok(ret, "expected SetStdHandle to succeed\n");
1316 ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
1319 static void test_GetNumberOfConsoleInputEvents(HANDLE input_handle)
1321 DWORD count;
1322 BOOL ret;
1323 int i;
1325 const struct
1327 HANDLE handle;
1328 LPDWORD nrofevents;
1329 DWORD last_error;
1330 } invalid_table[] =
1332 {NULL, NULL, ERROR_INVALID_HANDLE},
1333 {NULL, &count, ERROR_INVALID_HANDLE},
1334 {INVALID_HANDLE_VALUE, NULL, ERROR_INVALID_HANDLE},
1335 {INVALID_HANDLE_VALUE, &count, ERROR_INVALID_HANDLE},
1338 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
1340 SetLastError(0xdeadbeef);
1341 if (invalid_table[i].nrofevents) count = 0xdeadbeef;
1342 ret = GetNumberOfConsoleInputEvents(invalid_table[i].handle,
1343 invalid_table[i].nrofevents);
1344 ok(!ret, "[%d] Expected GetNumberOfConsoleInputEvents to return FALSE, got %d\n", i, ret);
1345 if (invalid_table[i].nrofevents)
1347 ok(count == 0xdeadbeef,
1348 "[%d] Expected output count to be unmodified, got %u\n", i, count);
1350 ok(GetLastError() == invalid_table[i].last_error,
1351 "[%d] Expected last error to be %u, got %u\n",
1352 i, invalid_table[i].last_error, GetLastError());
1355 /* Test crashes on Windows 7. */
1356 if (0)
1358 SetLastError(0xdeadbeef);
1359 ret = GetNumberOfConsoleInputEvents(input_handle, NULL);
1360 ok(!ret, "Expected GetNumberOfConsoleInputEvents to return FALSE, got %d\n", ret);
1361 ok(GetLastError() == ERROR_INVALID_ACCESS,
1362 "Expected last error to be ERROR_INVALID_ACCESS, got %u\n",
1363 GetLastError());
1366 count = 0xdeadbeef;
1367 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1368 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1369 ok(count != 0xdeadbeef, "Expected output count to initialized\n");
1372 static void test_WriteConsoleInputA(HANDLE input_handle)
1374 INPUT_RECORD event;
1375 INPUT_RECORD event_list[5];
1376 MOUSE_EVENT_RECORD mouse_event = { {0, 0}, 0, 0, MOUSE_MOVED };
1377 KEY_EVENT_RECORD key_event;
1378 DWORD count, console_mode, gle;
1379 BOOL ret;
1380 int i;
1382 const struct
1384 HANDLE handle;
1385 const INPUT_RECORD *buffer;
1386 DWORD count;
1387 LPDWORD written;
1388 DWORD expected_count;
1389 DWORD gle, gle2;
1390 int win_crash;
1391 } invalid_table[] =
1393 {NULL, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1394 {NULL, NULL, 0, &count, 0, ERROR_INVALID_HANDLE},
1395 {NULL, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1396 {NULL, NULL, 1, &count, 0xdeadbeef, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
1397 {NULL, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1398 {NULL, &event, 0, &count, 0, ERROR_INVALID_HANDLE},
1399 {NULL, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1400 {NULL, &event, 1, &count, 0, ERROR_INVALID_HANDLE},
1401 {INVALID_HANDLE_VALUE, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1402 {INVALID_HANDLE_VALUE, NULL, 0, &count, 0, ERROR_INVALID_HANDLE},
1403 {INVALID_HANDLE_VALUE, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1404 {INVALID_HANDLE_VALUE, NULL, 1, &count, 0xdeadbeef, ERROR_INVALID_ACCESS},
1405 {INVALID_HANDLE_VALUE, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1406 {INVALID_HANDLE_VALUE, &event, 0, &count, 0, ERROR_INVALID_HANDLE},
1407 {INVALID_HANDLE_VALUE, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1408 {INVALID_HANDLE_VALUE, &event, 1, &count, 0, ERROR_INVALID_HANDLE},
1409 {input_handle, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1410 {input_handle, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1411 {input_handle, NULL, 1, &count, 0xdeadbeef, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
1412 {input_handle, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1413 {input_handle, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1416 /* Suppress external sources of input events for the duration of the test. */
1417 ret = GetConsoleMode(input_handle, &console_mode);
1418 ok(ret == TRUE, "Expected GetConsoleMode to return TRUE, got %d\n", ret);
1419 if (!ret)
1421 skip("GetConsoleMode failed with last error %u\n", GetLastError());
1422 return;
1425 ret = SetConsoleMode(input_handle, console_mode & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
1426 ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
1427 if (!ret)
1429 skip("SetConsoleMode failed with last error %u\n", GetLastError());
1430 return;
1433 /* Discard any events queued before the tests. */
1434 ret = FlushConsoleInputBuffer(input_handle);
1435 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1437 event.EventType = MOUSE_EVENT;
1438 event.Event.MouseEvent = mouse_event;
1440 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
1442 if (invalid_table[i].win_crash)
1443 continue;
1445 SetLastError(0xdeadbeef);
1446 if (invalid_table[i].written) count = 0xdeadbeef;
1447 ret = WriteConsoleInputA(invalid_table[i].handle,
1448 invalid_table[i].buffer,
1449 invalid_table[i].count,
1450 invalid_table[i].written);
1451 ok(!ret, "[%d] Expected WriteConsoleInputA to return FALSE, got %d\n", i, ret);
1452 if (invalid_table[i].written)
1454 ok(count == invalid_table[i].expected_count,
1455 "[%d] Expected output count to be %u, got %u\n",
1456 i, invalid_table[i].expected_count, count);
1458 gle = GetLastError();
1459 ok(gle == invalid_table[i].gle || (gle != 0 && gle == invalid_table[i].gle2),
1460 "[%d] Expected last error to be %u or %u, got %u\n",
1461 i, invalid_table[i].gle, invalid_table[i].gle2, gle);
1464 count = 0xdeadbeef;
1465 ret = WriteConsoleInputA(input_handle, NULL, 0, &count);
1466 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1467 ok(count == 0, "Expected count to be 0, got %u\n", count);
1469 count = 0xdeadbeef;
1470 ret = WriteConsoleInputA(input_handle, &event, 0, &count);
1471 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1472 ok(count == 0, "Expected count to be 0, got %u\n", count);
1474 count = 0xdeadbeef;
1475 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1476 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1477 ok(count == 1, "Expected count to be 1, got %u\n", count);
1479 ret = FlushConsoleInputBuffer(input_handle);
1480 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1482 /* Writing a single mouse event doesn't seem to affect the count if an adjacent mouse event is already queued. */
1483 event.EventType = MOUSE_EVENT;
1484 event.Event.MouseEvent = mouse_event;
1486 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1487 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1488 ok(count == 1, "Expected count to be 1, got %u\n", count);
1490 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1491 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1492 ok(count == 1, "Expected count to be 1, got %u\n", count);
1494 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1495 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1496 ok(count == 1, "Expected count to be 1, got %u\n", count);
1498 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1499 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1500 todo_wine
1501 ok(count == 1, "Expected count to be 1, got %u\n", count);
1503 ret = FlushConsoleInputBuffer(input_handle);
1504 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1506 for (i = 0; i < sizeof(event_list)/sizeof(event_list[0]); i++)
1508 event_list[i].EventType = MOUSE_EVENT;
1509 event_list[i].Event.MouseEvent = mouse_event;
1512 /* Writing consecutive chunks of mouse events appears to work. */
1513 ret = WriteConsoleInputA(input_handle, event_list, sizeof(event_list)/sizeof(event_list[0]), &count);
1514 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1515 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1516 "Expected count to be event list length, got %u\n", count);
1518 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1519 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1520 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1521 "Expected count to be event list length, got %u\n", count);
1523 ret = WriteConsoleInputA(input_handle, event_list, sizeof(event_list)/sizeof(event_list[0]), &count);
1524 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1525 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1526 "Expected count to be event list length, got %u\n", count);
1528 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1529 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1530 ok(count == 2*sizeof(event_list)/sizeof(event_list[0]),
1531 "Expected count to be twice event list length, got %u\n", count);
1533 /* Again, writing a single mouse event with adjacent mouse events queued doesn't appear to affect the count. */
1534 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1535 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1536 ok(count == 1, "Expected count to be 1, got %u\n", count);
1538 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1539 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1540 todo_wine
1541 ok(count == 2*sizeof(event_list)/sizeof(event_list[0]),
1542 "Expected count to be twice event list length, got %u\n", count);
1544 ret = FlushConsoleInputBuffer(input_handle);
1545 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1547 key_event.bKeyDown = FALSE;
1548 key_event.wRepeatCount = 0;
1549 key_event.wVirtualKeyCode = VK_SPACE;
1550 key_event.wVirtualScanCode = VK_SPACE;
1551 key_event.uChar.AsciiChar = ' ';
1552 key_event.dwControlKeyState = 0;
1554 event.EventType = KEY_EVENT;
1555 event.Event.KeyEvent = key_event;
1557 /* Key events don't exhibit the same behavior as mouse events. */
1558 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1559 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1560 ok(count == 1, "Expected count to be 1, got %u\n", count);
1562 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1563 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1564 ok(count == 1, "Expected count to be 1, got %u\n", count);
1566 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1567 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1568 ok(count == 1, "Expected count to be 1, got %u\n", count);
1570 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1571 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1572 ok(count == 2, "Expected count to be 2, got %u\n", count);
1574 ret = FlushConsoleInputBuffer(input_handle);
1575 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1577 /* Try interleaving mouse and key events. */
1578 event.EventType = MOUSE_EVENT;
1579 event.Event.MouseEvent = mouse_event;
1581 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1582 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1583 ok(count == 1, "Expected count to be 1, got %u\n", count);
1585 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1586 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1587 ok(count == 1, "Expected count to be 1, got %u\n", count);
1589 event.EventType = KEY_EVENT;
1590 event.Event.KeyEvent = key_event;
1592 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1593 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1594 ok(count == 1, "Expected count to be 1, got %u\n", count);
1596 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1597 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1598 ok(count == 2, "Expected count to be 2, got %u\n", count);
1600 event.EventType = MOUSE_EVENT;
1601 event.Event.MouseEvent = mouse_event;
1603 ret = WriteConsoleInputA(input_handle, &event, 1, &count);
1604 ok(ret == TRUE, "Expected WriteConsoleInputA to return TRUE, got %d\n", ret);
1605 ok(count == 1, "Expected count to be 1, got %u\n", count);
1607 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1608 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1609 ok(count == 3, "Expected count to be 3, got %u\n", count);
1611 /* Restore the old console mode. */
1612 ret = SetConsoleMode(input_handle, console_mode);
1613 ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
1616 static void test_WriteConsoleInputW(HANDLE input_handle)
1618 INPUT_RECORD event;
1619 INPUT_RECORD event_list[5];
1620 MOUSE_EVENT_RECORD mouse_event = { {0, 0}, 0, 0, MOUSE_MOVED };
1621 KEY_EVENT_RECORD key_event;
1622 DWORD count, console_mode, gle;
1623 BOOL ret;
1624 int i;
1626 const struct
1628 HANDLE handle;
1629 const INPUT_RECORD *buffer;
1630 DWORD count;
1631 LPDWORD written;
1632 DWORD expected_count;
1633 DWORD gle, gle2;
1634 int win_crash;
1635 } invalid_table[] =
1637 {NULL, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1638 {NULL, NULL, 0, &count, 0, ERROR_INVALID_HANDLE},
1639 {NULL, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1640 {NULL, NULL, 1, &count, 0xdeadbeef, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
1641 {NULL, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1642 {NULL, &event, 0, &count, 0, ERROR_INVALID_HANDLE},
1643 {NULL, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1644 {NULL, &event, 1, &count, 0, ERROR_INVALID_HANDLE},
1645 {INVALID_HANDLE_VALUE, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1646 {INVALID_HANDLE_VALUE, NULL, 0, &count, 0, ERROR_INVALID_HANDLE},
1647 {INVALID_HANDLE_VALUE, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1648 {INVALID_HANDLE_VALUE, NULL, 1, &count, 0xdeadbeef, ERROR_INVALID_ACCESS},
1649 {INVALID_HANDLE_VALUE, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1650 {INVALID_HANDLE_VALUE, &event, 0, &count, 0, ERROR_INVALID_HANDLE},
1651 {INVALID_HANDLE_VALUE, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1652 {INVALID_HANDLE_VALUE, &event, 1, &count, 0, ERROR_INVALID_HANDLE},
1653 {input_handle, NULL, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1654 {input_handle, NULL, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1655 {input_handle, NULL, 1, &count, 0xdeadbeef, ERROR_NOACCESS, ERROR_INVALID_ACCESS},
1656 {input_handle, &event, 0, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1657 {input_handle, &event, 1, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 0, 1},
1660 /* Suppress external sources of input events for the duration of the test. */
1661 ret = GetConsoleMode(input_handle, &console_mode);
1662 ok(ret == TRUE, "Expected GetConsoleMode to return TRUE, got %d\n", ret);
1663 if (!ret)
1665 skip("GetConsoleMode failed with last error %u\n", GetLastError());
1666 return;
1669 ret = SetConsoleMode(input_handle, console_mode & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
1670 ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
1671 if (!ret)
1673 skip("SetConsoleMode failed with last error %u\n", GetLastError());
1674 return;
1677 /* Discard any events queued before the tests. */
1678 ret = FlushConsoleInputBuffer(input_handle);
1679 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1681 event.EventType = MOUSE_EVENT;
1682 event.Event.MouseEvent = mouse_event;
1684 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
1686 if (invalid_table[i].win_crash)
1687 continue;
1689 SetLastError(0xdeadbeef);
1690 if (invalid_table[i].written) count = 0xdeadbeef;
1691 ret = WriteConsoleInputW(invalid_table[i].handle,
1692 invalid_table[i].buffer,
1693 invalid_table[i].count,
1694 invalid_table[i].written);
1695 ok(!ret, "[%d] Expected WriteConsoleInputW to return FALSE, got %d\n", i, ret);
1696 if (invalid_table[i].written)
1698 ok(count == invalid_table[i].expected_count,
1699 "[%d] Expected output count to be %u, got %u\n",
1700 i, invalid_table[i].expected_count, count);
1702 gle = GetLastError();
1703 ok(gle == invalid_table[i].gle || (gle != 0 && gle == invalid_table[i].gle2),
1704 "[%d] Expected last error to be %u or %u, got %u\n",
1705 i, invalid_table[i].gle, invalid_table[i].gle2, gle);
1708 count = 0xdeadbeef;
1709 ret = WriteConsoleInputW(input_handle, NULL, 0, &count);
1710 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1711 ok(count == 0, "Expected count to be 0, got %u\n", count);
1713 count = 0xdeadbeef;
1714 ret = WriteConsoleInputW(input_handle, &event, 0, &count);
1715 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1716 ok(count == 0, "Expected count to be 0, got %u\n", count);
1718 count = 0xdeadbeef;
1719 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1720 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1721 ok(count == 1, "Expected count to be 1, got %u\n", count);
1723 ret = FlushConsoleInputBuffer(input_handle);
1724 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1726 /* Writing a single mouse event doesn't seem to affect the count if an adjacent mouse event is already queued. */
1727 event.EventType = MOUSE_EVENT;
1728 event.Event.MouseEvent = mouse_event;
1730 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1731 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1732 ok(count == 1, "Expected count to be 1, got %u\n", count);
1734 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1735 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1736 ok(count == 1, "Expected count to be 1, got %u\n", count);
1738 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1739 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1740 ok(count == 1, "Expected count to be 1, got %u\n", count);
1742 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1743 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1744 todo_wine
1745 ok(count == 1, "Expected count to be 1, got %u\n", count);
1747 ret = FlushConsoleInputBuffer(input_handle);
1748 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1750 for (i = 0; i < sizeof(event_list)/sizeof(event_list[0]); i++)
1752 event_list[i].EventType = MOUSE_EVENT;
1753 event_list[i].Event.MouseEvent = mouse_event;
1756 /* Writing consecutive chunks of mouse events appears to work. */
1757 ret = WriteConsoleInputW(input_handle, event_list, sizeof(event_list)/sizeof(event_list[0]), &count);
1758 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1759 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1760 "Expected count to be event list length, got %u\n", count);
1762 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1763 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1764 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1765 "Expected count to be event list length, got %u\n", count);
1767 ret = WriteConsoleInputW(input_handle, event_list, sizeof(event_list)/sizeof(event_list[0]), &count);
1768 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1769 ok(count == sizeof(event_list)/sizeof(event_list[0]),
1770 "Expected count to be event list length, got %u\n", count);
1772 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1773 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1774 ok(count == 2*sizeof(event_list)/sizeof(event_list[0]),
1775 "Expected count to be twice event list length, got %u\n", count);
1777 /* Again, writing a single mouse event with adjacent mouse events queued doesn't appear to affect the count. */
1778 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1779 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1780 ok(count == 1, "Expected count to be 1, got %u\n", count);
1782 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1783 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1784 todo_wine
1785 ok(count == 2*sizeof(event_list)/sizeof(event_list[0]),
1786 "Expected count to be twice event list length, got %u\n", count);
1788 ret = FlushConsoleInputBuffer(input_handle);
1789 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1791 key_event.bKeyDown = FALSE;
1792 key_event.wRepeatCount = 0;
1793 key_event.wVirtualKeyCode = VK_SPACE;
1794 key_event.wVirtualScanCode = VK_SPACE;
1795 key_event.uChar.UnicodeChar = ' ';
1796 key_event.dwControlKeyState = 0;
1798 event.EventType = KEY_EVENT;
1799 event.Event.KeyEvent = key_event;
1801 /* Key events don't exhibit the same behavior as mouse events. */
1802 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1803 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1804 ok(count == 1, "Expected count to be 1, got %u\n", count);
1806 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1807 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1808 ok(count == 1, "Expected count to be 1, got %u\n", count);
1810 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1811 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1812 ok(count == 1, "Expected count to be 1, got %u\n", count);
1814 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1815 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1816 ok(count == 2, "Expected count to be 2, got %u\n", count);
1818 ret = FlushConsoleInputBuffer(input_handle);
1819 ok(ret == TRUE, "Expected FlushConsoleInputBuffer to return TRUE, got %d\n", ret);
1821 /* Try interleaving mouse and key events. */
1822 event.EventType = MOUSE_EVENT;
1823 event.Event.MouseEvent = mouse_event;
1825 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1826 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1827 ok(count == 1, "Expected count to be 1, got %u\n", count);
1829 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1830 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1831 ok(count == 1, "Expected count to be 1, got %u\n", count);
1833 event.EventType = KEY_EVENT;
1834 event.Event.KeyEvent = key_event;
1836 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1837 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1838 ok(count == 1, "Expected count to be 1, got %u\n", count);
1840 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1841 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1842 ok(count == 2, "Expected count to be 2, got %u\n", count);
1844 event.EventType = MOUSE_EVENT;
1845 event.Event.MouseEvent = mouse_event;
1847 ret = WriteConsoleInputW(input_handle, &event, 1, &count);
1848 ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret);
1849 ok(count == 1, "Expected count to be 1, got %u\n", count);
1851 ret = GetNumberOfConsoleInputEvents(input_handle, &count);
1852 ok(ret == TRUE, "Expected GetNumberOfConsoleInputEvents to return TRUE, got %d\n", ret);
1853 ok(count == 3, "Expected count to be 3, got %u\n", count);
1855 /* Restore the old console mode. */
1856 ret = SetConsoleMode(input_handle, console_mode);
1857 ok(ret == TRUE, "Expected SetConsoleMode to return TRUE, got %d\n", ret);
1860 static void test_WriteConsoleOutputCharacterA(HANDLE output_handle)
1862 static const char output[] = {'a', 0};
1864 COORD origin = {0, 0};
1865 DWORD count;
1866 BOOL ret;
1867 int i;
1869 const struct
1871 HANDLE hConsoleOutput;
1872 LPCSTR str;
1873 DWORD length;
1874 COORD coord;
1875 LPDWORD lpNumCharsWritten;
1876 DWORD expected_count;
1877 DWORD last_error;
1878 int win7_crash;
1879 } invalid_table[] =
1881 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1882 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1883 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1884 {NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1885 {NULL, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1886 {NULL, output, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1887 {NULL, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1888 {NULL, output, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1889 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1890 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1891 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1892 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1893 {INVALID_HANDLE_VALUE, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1894 {INVALID_HANDLE_VALUE, output, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1895 {INVALID_HANDLE_VALUE, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1896 {INVALID_HANDLE_VALUE, output, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1897 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1898 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1899 {output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1900 {output_handle, output, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1901 {output_handle, output, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1904 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
1906 if (invalid_table[i].win7_crash)
1907 continue;
1909 SetLastError(0xdeadbeef);
1910 if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
1911 ret = WriteConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
1912 invalid_table[i].str,
1913 invalid_table[i].length,
1914 invalid_table[i].coord,
1915 invalid_table[i].lpNumCharsWritten);
1916 ok(!ret, "[%d] Expected WriteConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
1917 if (invalid_table[i].lpNumCharsWritten)
1919 ok(count == invalid_table[i].expected_count,
1920 "[%d] Expected count to be %u, got %u\n",
1921 i, invalid_table[i].expected_count, count);
1923 ok(GetLastError() == invalid_table[i].last_error,
1924 "[%d] Expected last error to be %u, got %u\n",
1925 i, invalid_table[i].last_error, GetLastError());
1928 count = 0xdeadbeef;
1929 ret = WriteConsoleOutputCharacterA(output_handle, NULL, 0, origin, &count);
1930 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
1931 ok(count == 0, "Expected count to be 0, got %u\n", count);
1933 count = 0xdeadbeef;
1934 ret = WriteConsoleOutputCharacterA(output_handle, output, 0, origin, &count);
1935 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
1936 ok(count == 0, "Expected count to be 0, got %u\n", count);
1938 count = 0xdeadbeef;
1939 ret = WriteConsoleOutputCharacterA(output_handle, output, 1, origin, &count);
1940 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterA to return TRUE, got %d\n", ret);
1941 ok(count == 1, "Expected count to be 1, got %u\n", count);
1944 static void test_WriteConsoleOutputCharacterW(HANDLE output_handle)
1946 static const WCHAR outputW[] = {'a',0};
1948 COORD origin = {0, 0};
1949 DWORD count;
1950 BOOL ret;
1951 int i;
1953 const struct
1955 HANDLE hConsoleOutput;
1956 LPCWSTR str;
1957 DWORD length;
1958 COORD coord;
1959 LPDWORD lpNumCharsWritten;
1960 DWORD expected_count;
1961 DWORD last_error;
1962 int win7_crash;
1963 } invalid_table[] =
1965 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1966 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1967 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1968 {NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1969 {NULL, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1970 {NULL, outputW, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1971 {NULL, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1972 {NULL, outputW, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1973 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1974 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1975 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1976 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1977 {INVALID_HANDLE_VALUE, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1978 {INVALID_HANDLE_VALUE, outputW, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1979 {INVALID_HANDLE_VALUE, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1980 {INVALID_HANDLE_VALUE, outputW, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
1981 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1982 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1983 {output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1984 {output_handle, outputW, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1985 {output_handle, outputW, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
1988 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
1990 if (invalid_table[i].win7_crash)
1991 continue;
1993 SetLastError(0xdeadbeef);
1994 if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
1995 ret = WriteConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
1996 invalid_table[i].str,
1997 invalid_table[i].length,
1998 invalid_table[i].coord,
1999 invalid_table[i].lpNumCharsWritten);
2000 ok(!ret, "[%d] Expected WriteConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
2001 if (invalid_table[i].lpNumCharsWritten)
2003 ok(count == invalid_table[i].expected_count,
2004 "[%d] Expected count to be %u, got %u\n",
2005 i, invalid_table[i].expected_count, count);
2007 ok(GetLastError() == invalid_table[i].last_error,
2008 "[%d] Expected last error to be %u, got %u\n",
2009 i, invalid_table[i].last_error, GetLastError());
2012 count = 0xdeadbeef;
2013 ret = WriteConsoleOutputCharacterW(output_handle, NULL, 0, origin, &count);
2014 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2015 ok(count == 0, "Expected count to be 0, got %u\n", count);
2017 count = 0xdeadbeef;
2018 ret = WriteConsoleOutputCharacterW(output_handle, outputW, 0, origin, &count);
2019 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2020 ok(count == 0, "Expected count to be 0, got %u\n", count);
2022 count = 0xdeadbeef;
2023 ret = WriteConsoleOutputCharacterW(output_handle, outputW, 1, origin, &count);
2024 ok(ret == TRUE, "Expected WriteConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2025 ok(count == 1, "Expected count to be 1, got %u\n", count);
2028 static void test_WriteConsoleOutputAttribute(HANDLE output_handle)
2030 WORD attr = FOREGROUND_BLUE;
2031 COORD origin = {0, 0};
2032 DWORD count;
2033 BOOL ret;
2034 int i;
2036 const struct
2038 HANDLE hConsoleOutput;
2039 const WORD *attr;
2040 DWORD length;
2041 COORD coord;
2042 LPDWORD lpNumAttrsWritten;
2043 DWORD expected_count;
2044 DWORD last_error;
2045 int win7_crash;
2046 } invalid_table[] =
2048 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2049 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2050 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2051 {NULL, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2052 {NULL, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2053 {NULL, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2054 {NULL, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2055 {NULL, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2056 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2057 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2058 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2059 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2060 {INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2061 {INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2062 {INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2063 {INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2064 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2065 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2066 {output_handle, NULL, 1, {0, 0}, &count, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2067 {output_handle, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2068 {output_handle, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2071 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2073 if (invalid_table[i].win7_crash)
2074 continue;
2076 SetLastError(0xdeadbeef);
2077 if (invalid_table[i].lpNumAttrsWritten) count = 0xdeadbeef;
2078 ret = WriteConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
2079 invalid_table[i].attr,
2080 invalid_table[i].length,
2081 invalid_table[i].coord,
2082 invalid_table[i].lpNumAttrsWritten);
2083 ok(!ret, "[%d] Expected WriteConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
2084 if (invalid_table[i].lpNumAttrsWritten)
2086 ok(count == invalid_table[i].expected_count,
2087 "[%d] Expected count to be %u, got %u\n",
2088 i, invalid_table[i].expected_count, count);
2090 ok(GetLastError() == invalid_table[i].last_error,
2091 "[%d] Expected last error to be %u, got %u\n",
2092 i, invalid_table[i].last_error, GetLastError());
2095 count = 0xdeadbeef;
2096 ret = WriteConsoleOutputAttribute(output_handle, NULL, 0, origin, &count);
2097 ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
2098 ok(count == 0, "Expected count to be 0, got %u\n", count);
2100 count = 0xdeadbeef;
2101 ret = WriteConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
2102 ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
2103 ok(count == 0, "Expected count to be 0, got %u\n", count);
2105 count = 0xdeadbeef;
2106 ret = WriteConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
2107 ok(ret == TRUE, "Expected WriteConsoleOutputAttribute to return TRUE, got %d\n", ret);
2108 ok(count == 1, "Expected count to be 1, got %u\n", count);
2111 static void test_FillConsoleOutputCharacterA(HANDLE output_handle)
2113 COORD origin = {0, 0};
2114 DWORD count;
2115 BOOL ret;
2116 int i;
2118 const struct
2120 HANDLE hConsoleOutput;
2121 CHAR ch;
2122 DWORD length;
2123 COORD coord;
2124 LPDWORD lpNumCharsWritten;
2125 DWORD expected_count;
2126 DWORD last_error;
2127 int win7_crash;
2128 } invalid_table[] =
2130 {NULL, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2131 {NULL, 'a', 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2132 {NULL, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2133 {NULL, 'a', 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2134 {INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2135 {INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2136 {INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2137 {INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2138 {output_handle, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2139 {output_handle, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2142 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2144 if (invalid_table[i].win7_crash)
2145 continue;
2147 SetLastError(0xdeadbeef);
2148 if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
2149 ret = FillConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
2150 invalid_table[i].ch,
2151 invalid_table[i].length,
2152 invalid_table[i].coord,
2153 invalid_table[i].lpNumCharsWritten);
2154 ok(!ret, "[%d] Expected FillConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
2155 if (invalid_table[i].lpNumCharsWritten)
2157 ok(count == invalid_table[i].expected_count,
2158 "[%d] Expected count to be %u, got %u\n",
2159 i, invalid_table[i].expected_count, count);
2161 ok(GetLastError() == invalid_table[i].last_error,
2162 "[%d] Expected last error to be %u, got %u\n",
2163 i, invalid_table[i].last_error, GetLastError());
2166 count = 0xdeadbeef;
2167 ret = FillConsoleOutputCharacterA(output_handle, 'a', 0, origin, &count);
2168 ok(ret == TRUE, "Expected FillConsoleOutputCharacterA to return TRUE, got %d\n", ret);
2169 ok(count == 0, "Expected count to be 0, got %u\n", count);
2171 count = 0xdeadbeef;
2172 ret = FillConsoleOutputCharacterA(output_handle, 'a', 1, origin, &count);
2173 ok(ret == TRUE, "Expected FillConsoleOutputCharacterA to return TRUE, got %d\n", ret);
2174 ok(count == 1, "Expected count to be 1, got %u\n", count);
2177 static void test_FillConsoleOutputCharacterW(HANDLE output_handle)
2179 COORD origin = {0, 0};
2180 DWORD count;
2181 BOOL ret;
2182 int i;
2184 const struct
2186 HANDLE hConsoleOutput;
2187 WCHAR ch;
2188 DWORD length;
2189 COORD coord;
2190 LPDWORD lpNumCharsWritten;
2191 DWORD expected_count;
2192 DWORD last_error;
2193 int win7_crash;
2194 } invalid_table[] =
2196 {NULL, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2197 {NULL, 'a', 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2198 {NULL, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2199 {NULL, 'a', 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2200 {INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2201 {INVALID_HANDLE_VALUE, 'a', 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2202 {INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2203 {INVALID_HANDLE_VALUE, 'a', 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2204 {output_handle, 'a', 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2205 {output_handle, 'a', 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2208 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2210 if (invalid_table[i].win7_crash)
2211 continue;
2213 SetLastError(0xdeadbeef);
2214 if (invalid_table[i].lpNumCharsWritten) count = 0xdeadbeef;
2215 ret = FillConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
2216 invalid_table[i].ch,
2217 invalid_table[i].length,
2218 invalid_table[i].coord,
2219 invalid_table[i].lpNumCharsWritten);
2220 ok(!ret, "[%d] Expected FillConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
2221 if (invalid_table[i].lpNumCharsWritten)
2223 ok(count == invalid_table[i].expected_count,
2224 "[%d] Expected count to be %u, got %u\n",
2225 i, invalid_table[i].expected_count, count);
2227 ok(GetLastError() == invalid_table[i].last_error,
2228 "[%d] Expected last error to be %u, got %u\n",
2229 i, invalid_table[i].last_error, GetLastError());
2232 count = 0xdeadbeef;
2233 ret = FillConsoleOutputCharacterW(output_handle, 'a', 0, origin, &count);
2234 ok(ret == TRUE, "Expected FillConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2235 ok(count == 0, "Expected count to be 0, got %u\n", count);
2237 count = 0xdeadbeef;
2238 ret = FillConsoleOutputCharacterW(output_handle, 'a', 1, origin, &count);
2239 ok(ret == TRUE, "Expected FillConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2240 ok(count == 1, "Expected count to be 1, got %u\n", count);
2243 static void test_FillConsoleOutputAttribute(HANDLE output_handle)
2245 COORD origin = {0, 0};
2246 DWORD count;
2247 BOOL ret;
2248 int i;
2250 const struct
2252 HANDLE hConsoleOutput;
2253 WORD attr;
2254 DWORD length;
2255 COORD coord;
2256 LPDWORD lpNumAttrsWritten;
2257 DWORD expected_count;
2258 DWORD last_error;
2259 int win7_crash;
2260 } invalid_table[] =
2262 {NULL, FOREGROUND_BLUE, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2263 {NULL, FOREGROUND_BLUE, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2264 {NULL, FOREGROUND_BLUE, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2265 {NULL, FOREGROUND_BLUE, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2266 {INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2267 {INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2268 {INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2269 {INVALID_HANDLE_VALUE, FOREGROUND_BLUE, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2270 {output_handle, FOREGROUND_BLUE, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2271 {output_handle, FOREGROUND_BLUE, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2274 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2276 if (invalid_table[i].win7_crash)
2277 continue;
2279 SetLastError(0xdeadbeef);
2280 if (invalid_table[i].lpNumAttrsWritten) count = 0xdeadbeef;
2281 ret = FillConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
2282 invalid_table[i].attr,
2283 invalid_table[i].length,
2284 invalid_table[i].coord,
2285 invalid_table[i].lpNumAttrsWritten);
2286 ok(!ret, "[%d] Expected FillConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
2287 if (invalid_table[i].lpNumAttrsWritten)
2289 ok(count == invalid_table[i].expected_count,
2290 "[%d] Expected count to be %u, got %u\n",
2291 i, invalid_table[i].expected_count, count);
2293 ok(GetLastError() == invalid_table[i].last_error,
2294 "[%d] Expected last error to be %u, got %u\n",
2295 i, invalid_table[i].last_error, GetLastError());
2298 count = 0xdeadbeef;
2299 ret = FillConsoleOutputAttribute(output_handle, FOREGROUND_BLUE, 0, origin, &count);
2300 ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
2301 ok(count == 0, "Expected count to be 0, got %u\n", count);
2303 count = 0xdeadbeef;
2304 ret = FillConsoleOutputAttribute(output_handle, FOREGROUND_BLUE, 1, origin, &count);
2305 ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
2306 ok(count == 1, "Expected count to be 1, got %u\n", count);
2308 count = 0xdeadbeef;
2309 ret = FillConsoleOutputAttribute(output_handle, ~0, 1, origin, &count);
2310 ok(ret == TRUE, "Expected FillConsoleOutputAttribute to return TRUE, got %d\n", ret);
2311 ok(count == 1, "Expected count to be 1, got %u\n", count);
2314 static void test_ReadConsoleOutputCharacterA(HANDLE output_handle)
2316 CHAR read;
2317 COORD origin = {0, 0};
2318 DWORD count;
2319 BOOL ret;
2320 int i;
2322 const struct
2324 HANDLE hConsoleOutput;
2325 LPSTR lpstr;
2326 DWORD length;
2327 COORD coord;
2328 LPDWORD read_count;
2329 DWORD expected_count;
2330 DWORD last_error;
2331 int win7_crash;
2332 } invalid_table[] =
2334 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2335 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2336 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2337 {NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2338 {NULL, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2339 {NULL, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2340 {NULL, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2341 {NULL, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2342 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2343 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2344 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2345 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2346 {INVALID_HANDLE_VALUE, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2347 {INVALID_HANDLE_VALUE, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2348 {INVALID_HANDLE_VALUE, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2349 {INVALID_HANDLE_VALUE, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2350 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2351 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2352 {output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
2353 {output_handle, NULL, 10, {0, 0}, &count, 10, ERROR_INVALID_ACCESS, 1},
2354 {output_handle, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2355 {output_handle, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2358 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2360 if (invalid_table[i].win7_crash)
2361 continue;
2363 SetLastError(0xdeadbeef);
2364 if (invalid_table[i].read_count) count = 0xdeadbeef;
2365 ret = ReadConsoleOutputCharacterA(invalid_table[i].hConsoleOutput,
2366 invalid_table[i].lpstr,
2367 invalid_table[i].length,
2368 invalid_table[i].coord,
2369 invalid_table[i].read_count);
2370 ok(!ret, "[%d] Expected ReadConsoleOutputCharacterA to return FALSE, got %d\n", i, ret);
2371 if (invalid_table[i].read_count)
2373 ok(count == invalid_table[i].expected_count,
2374 "[%d] Expected count to be %u, got %u\n",
2375 i, invalid_table[i].expected_count, count);
2377 ok(GetLastError() == invalid_table[i].last_error,
2378 "[%d] Expected last error to be %u, got %u\n",
2379 i, invalid_table[i].last_error, GetLastError());
2382 count = 0xdeadbeef;
2383 ret = ReadConsoleOutputCharacterA(output_handle, NULL, 0, origin, &count);
2384 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
2385 ok(count == 0, "Expected count to be 0, got %u\n", count);
2387 count = 0xdeadbeef;
2388 ret = ReadConsoleOutputCharacterA(output_handle, &read, 0, origin, &count);
2389 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
2390 ok(count == 0, "Expected count to be 0, got %u\n", count);
2392 count = 0xdeadbeef;
2393 ret = ReadConsoleOutputCharacterA(output_handle, &read, 1, origin, &count);
2394 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterA to return TRUE, got %d\n", ret);
2395 ok(count == 1, "Expected count to be 1, got %u\n", count);
2398 static void test_ReadConsoleOutputCharacterW(HANDLE output_handle)
2400 WCHAR read;
2401 COORD origin = {0, 0};
2402 DWORD count;
2403 BOOL ret;
2404 int i;
2406 const struct
2408 HANDLE hConsoleOutput;
2409 LPWSTR buffer;
2410 DWORD length;
2411 COORD coord;
2412 LPDWORD read_count;
2413 DWORD expected_count;
2414 DWORD last_error;
2415 int win7_crash;
2416 } invalid_table[] =
2418 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2419 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2420 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2421 {NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2422 {NULL, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2423 {NULL, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2424 {NULL, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2425 {NULL, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2426 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2427 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2428 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2429 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2430 {INVALID_HANDLE_VALUE, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2431 {INVALID_HANDLE_VALUE, &read, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2432 {INVALID_HANDLE_VALUE, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2433 {INVALID_HANDLE_VALUE, &read, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2434 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2435 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2436 {output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
2437 {output_handle, NULL, 10, {0, 0}, &count, 10, ERROR_INVALID_ACCESS, 1},
2438 {output_handle, &read, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2439 {output_handle, &read, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2442 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2444 if (invalid_table[i].win7_crash)
2445 continue;
2447 SetLastError(0xdeadbeef);
2448 if (invalid_table[i].read_count) count = 0xdeadbeef;
2449 ret = ReadConsoleOutputCharacterW(invalid_table[i].hConsoleOutput,
2450 invalid_table[i].buffer,
2451 invalid_table[i].length,
2452 invalid_table[i].coord,
2453 invalid_table[i].read_count);
2454 ok(!ret, "[%d] Expected ReadConsoleOutputCharacterW to return FALSE, got %d\n", i, ret);
2455 if (invalid_table[i].read_count)
2457 ok(count == invalid_table[i].expected_count,
2458 "[%d] Expected count to be %u, got %u\n",
2459 i, invalid_table[i].expected_count, count);
2461 ok(GetLastError() == invalid_table[i].last_error,
2462 "[%d] Expected last error to be %u, got %u\n",
2463 i, invalid_table[i].last_error, GetLastError());
2466 count = 0xdeadbeef;
2467 ret = ReadConsoleOutputCharacterW(output_handle, NULL, 0, origin, &count);
2468 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2469 ok(count == 0, "Expected count to be 0, got %u\n", count);
2471 count = 0xdeadbeef;
2472 ret = ReadConsoleOutputCharacterW(output_handle, &read, 0, origin, &count);
2473 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2474 ok(count == 0, "Expected count to be 0, got %u\n", count);
2476 count = 0xdeadbeef;
2477 ret = ReadConsoleOutputCharacterW(output_handle, &read, 1, origin, &count);
2478 ok(ret == TRUE, "Expected ReadConsoleOutputCharacterW to return TRUE, got %d\n", ret);
2479 ok(count == 1, "Expected count to be 1, got %u\n", count);
2482 static void test_ReadConsoleOutputAttribute(HANDLE output_handle)
2484 WORD attr;
2485 COORD origin = {0, 0};
2486 DWORD count;
2487 BOOL ret;
2488 int i;
2490 const struct
2492 HANDLE hConsoleOutput;
2493 LPWORD lpAttribute;
2494 DWORD length;
2495 COORD coord;
2496 LPDWORD read_count;
2497 DWORD expected_count;
2498 DWORD last_error;
2499 int win7_crash;
2500 } invalid_table[] =
2502 {NULL, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2503 {NULL, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2504 {NULL, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2505 {NULL, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2506 {NULL, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2507 {NULL, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2508 {NULL, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2509 {NULL, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2510 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2511 {INVALID_HANDLE_VALUE, NULL, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2512 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2513 {INVALID_HANDLE_VALUE, NULL, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE, 1},
2514 {INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2515 {INVALID_HANDLE_VALUE, &attr, 0, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2516 {INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2517 {INVALID_HANDLE_VALUE, &attr, 1, {0, 0}, &count, 0, ERROR_INVALID_HANDLE},
2518 {output_handle, NULL, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2519 {output_handle, NULL, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2520 {output_handle, NULL, 1, {0, 0}, &count, 1, ERROR_INVALID_ACCESS, 1},
2521 {output_handle, &attr, 0, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2522 {output_handle, &attr, 1, {0, 0}, NULL, 0xdeadbeef, ERROR_INVALID_ACCESS, 1},
2525 for (i = 0; i < sizeof(invalid_table)/sizeof(invalid_table[0]); i++)
2527 if (invalid_table[i].win7_crash)
2528 continue;
2530 SetLastError(0xdeadbeef);
2531 if (invalid_table[i].read_count) count = 0xdeadbeef;
2532 ret = ReadConsoleOutputAttribute(invalid_table[i].hConsoleOutput,
2533 invalid_table[i].lpAttribute,
2534 invalid_table[i].length,
2535 invalid_table[i].coord,
2536 invalid_table[i].read_count);
2537 ok(!ret, "[%d] Expected ReadConsoleOutputAttribute to return FALSE, got %d\n", i, ret);
2538 if (invalid_table[i].read_count)
2540 ok(count == invalid_table[i].expected_count,
2541 "[%d] Expected count to be %u, got %u\n",
2542 i, invalid_table[i].expected_count, count);
2544 ok(GetLastError() == invalid_table[i].last_error,
2545 "[%d] Expected last error to be %u, got %u\n",
2546 i, invalid_table[i].last_error, GetLastError());
2549 count = 0xdeadbeef;
2550 ret = ReadConsoleOutputAttribute(output_handle, NULL, 0, origin, &count);
2551 ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
2552 ok(count == 0, "Expected count to be 0, got %u\n", count);
2554 count = 0xdeadbeef;
2555 ret = ReadConsoleOutputAttribute(output_handle, &attr, 0, origin, &count);
2556 ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
2557 ok(count == 0, "Expected count to be 0, got %u\n", count);
2559 count = 0xdeadbeef;
2560 ret = ReadConsoleOutputAttribute(output_handle, &attr, 1, origin, &count);
2561 ok(ret == TRUE, "Expected ReadConsoleOutputAttribute to return TRUE, got %d\n", ret);
2562 ok(count == 1, "Expected count to be 1, got %u\n", count);
2565 START_TEST(console)
2567 static const char font_name[] = "Lucida Console";
2568 HANDLE hConIn, hConOut;
2569 BOOL ret;
2570 CONSOLE_SCREEN_BUFFER_INFO sbi;
2571 LONG err;
2572 HKEY console_key;
2573 char old_font[LF_FACESIZE];
2574 BOOL delete = FALSE;
2575 DWORD size;
2577 init_function_pointers();
2579 /* be sure we have a clean console (and that's our own)
2580 * FIXME: this will make the test fail (currently) if we don't run
2581 * under X11
2582 * Another solution would be to rerun the test under wineconsole with
2583 * the curses backend
2586 /* ReadConsoleOutputW doesn't retrieve characters from the output buffer
2587 * correctly for characters that don't have a glyph in the console font. So,
2588 * we first set the console font to Lucida Console (which has a wider
2589 * selection of glyphs available than the default raster fonts). We want
2590 * to be able to restore the original font afterwards, so don't change
2591 * if we can't read the original font.
2593 err = RegOpenKeyExA(HKEY_CURRENT_USER, "Console", 0,
2594 KEY_QUERY_VALUE | KEY_SET_VALUE, &console_key);
2595 if (err == ERROR_SUCCESS)
2597 size = sizeof(old_font);
2598 err = RegQueryValueExA(console_key, "FaceName", NULL, NULL,
2599 (LPBYTE) old_font, &size);
2600 if (err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND)
2602 delete = (err == ERROR_FILE_NOT_FOUND);
2603 err = RegSetValueExA(console_key, "FaceName", 0, REG_SZ,
2604 (const BYTE *) font_name, sizeof(font_name));
2605 if (err != ERROR_SUCCESS)
2606 trace("Unable to change default console font, error %d\n", err);
2608 else
2610 trace("Unable to query default console font, error %d\n", err);
2611 RegCloseKey(console_key);
2612 console_key = NULL;
2615 else
2617 trace("Unable to open HKCU\\Console, error %d\n", err);
2618 console_key = NULL;
2621 /* Now detach and open a fresh console to play with */
2622 FreeConsole();
2623 ok(AllocConsole(), "Couldn't alloc console\n");
2625 /* Restore default console font if needed */
2626 if (console_key != NULL)
2628 if (delete)
2629 err = RegDeleteValueA(console_key, "FaceName");
2630 else
2631 err = RegSetValueExA(console_key, "FaceName", 0, REG_SZ,
2632 (const BYTE *) old_font, strlen(old_font) + 1);
2633 ok(err == ERROR_SUCCESS, "Unable to restore default console font, error %d\n", err);
2635 hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
2636 hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
2638 /* now verify everything's ok */
2639 ok(hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
2640 ok(hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
2642 ret = GetConsoleScreenBufferInfo(hConOut, &sbi);
2643 ok(ret, "Getting sb info\n");
2644 if (!ret) return;
2646 /* Reduce the size of the buffer to the visible area plus 3 lines to speed
2647 * up the tests.
2649 trace("Visible area: %dx%d - %dx%d Buffer size: %dx%d\n", sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom, sbi.dwSize.X, sbi.dwSize.Y);
2650 sbi.dwSize.Y = size = (sbi.srWindow.Bottom + 1) + 3;
2651 ret = SetConsoleScreenBufferSize(hConOut, sbi.dwSize);
2652 ok(ret, "Setting sb info\n");
2653 ret = GetConsoleScreenBufferInfo(hConOut, &sbi);
2654 ok(ret, "Getting sb info\n");
2655 ok(sbi.dwSize.Y == size, "Unexpected buffer size: %d instead of %d\n", sbi.dwSize.Y, size);
2656 if (!ret) return;
2658 /* Non interactive tests */
2659 testCursor(hConOut, sbi.dwSize);
2660 /* test parameters (FIXME: test functionality) */
2661 testCursorInfo(hConOut);
2662 /* will test wrapped (on/off) & processed (on/off) strings output */
2663 testWrite(hConOut, sbi.dwSize);
2664 /* will test line scrolling at the bottom of the screen */
2665 /* testBottomScroll(); */
2666 /* will test all the scrolling operations */
2667 testScroll(hConOut, sbi.dwSize);
2668 /* will test sb creation / modification / codepage handling */
2669 testScreenBuffer(hConOut);
2670 testCtrlHandler();
2671 /* still to be done: access rights & access on objects */
2673 if (!pGetConsoleInputExeNameA || !pSetConsoleInputExeNameA)
2674 win_skip("GetConsoleInputExeNameA and/or SetConsoleInputExeNameA is not available\n");
2675 else
2676 test_GetSetConsoleInputExeName();
2678 test_GetConsoleProcessList();
2679 test_OpenConsoleW();
2680 test_CreateFileW();
2681 test_OpenCON();
2682 test_VerifyConsoleIoHandle(hConOut);
2683 test_GetSetStdHandle();
2684 test_GetNumberOfConsoleInputEvents(hConIn);
2685 test_WriteConsoleInputA(hConIn);
2686 test_WriteConsoleInputW(hConIn);
2687 test_WriteConsoleOutputCharacterA(hConOut);
2688 test_WriteConsoleOutputCharacterW(hConOut);
2689 test_WriteConsoleOutputAttribute(hConOut);
2690 test_FillConsoleOutputCharacterA(hConOut);
2691 test_FillConsoleOutputCharacterW(hConOut);
2692 test_FillConsoleOutputAttribute(hConOut);
2693 test_ReadConsoleOutputCharacterA(hConOut);
2694 test_ReadConsoleOutputCharacterW(hConOut);
2695 test_ReadConsoleOutputAttribute(hConOut);