kernel/tests: Check that we successfully open the console.
[wine/multimedia.git] / dlls / kernel / tests / console.c
blobedd1effeb522270d8d1e58f7105c7d49e84594c0
1 /*
2 * Unit tests for console API
4 * Copyright (c) 2003,2004 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
22 #include <windows.h>
23 #include <stdio.h>
25 /* DEFAULT_ATTRIB is used for all initial filling of the console.
26 * all modifications are made with TEST_ATTRIB so that we could check
27 * what has to be modified or not
29 #define TEST_ATTRIB (BACKGROUND_BLUE | FOREGROUND_GREEN)
30 #define DEFAULT_ATTRIB (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED)
31 /* when filling the screen with non-blank chars, this macro defines
32 * what character should be at position 'c'
34 #define CONTENT(c) ('A' + (((c).Y * 17 + (c).X) % 23))
36 #define okCURSOR(hCon, c) do { \
37 CONSOLE_SCREEN_BUFFER_INFO __sbi; \
38 BOOL expect = GetConsoleScreenBufferInfo((hCon), &__sbi) && \
39 __sbi.dwCursorPosition.X == (c).X && __sbi.dwCursorPosition.Y == (c).Y; \
40 ok(expect, "Expected cursor at (%d,%d), got (%d,%d)\n", \
41 (c).X, (c).Y, __sbi.dwCursorPosition.X, __sbi.dwCursorPosition.Y); \
42 } while (0)
44 #define okCHAR(hCon, c, ch, attr) do { \
45 char __ch; WORD __attr; DWORD __len; BOOL expect; \
46 expect = ReadConsoleOutputCharacter((hCon), &__ch, 1, (c), &__len) == 1 && __len == 1 && __ch == (ch); \
47 ok(expect, "At (%d,%d): expecting char '%c'/%02x got '%c'/%02x\n", (c).X, (c).Y, (ch), (ch), __ch, __ch); \
48 expect = ReadConsoleOutputAttribute((hCon), &__attr, 1, (c), &__len) == 1 && __len == 1 && __attr == (attr); \
49 ok(expect, "At (%d,%d): expecting attr %04x got %04x\n", (c).X, (c).Y, (attr), __attr); \
50 } while (0)
52 /* FIXME: this could be optimized on a speed point of view */
53 static void resetContent(HANDLE hCon, COORD sbSize, BOOL content)
55 COORD c;
56 WORD attr = DEFAULT_ATTRIB;
57 char ch;
58 DWORD len;
60 for (c.X = 0; c.X < sbSize.X; c.X++)
62 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
64 ch = (content) ? CONTENT(c) : ' ';
65 WriteConsoleOutputAttribute(hCon, &attr, 1, c, &len);
66 WriteConsoleOutputCharacterA(hCon, &ch, 1, c, &len);
71 static void testCursor(HANDLE hCon, COORD sbSize)
73 COORD c;
75 c.X = c.Y = 0;
76 ok(SetConsoleCursorPosition(0, c) == 0, "No handle\n");
77 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError: expecting %u got %lu\n",
78 ERROR_INVALID_HANDLE, GetLastError());
80 c.X = c.Y = 0;
81 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
82 okCURSOR(hCon, c);
84 c.X = sbSize.X - 1;
85 c.Y = sbSize.Y - 1;
86 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in lower-right\n");
87 okCURSOR(hCon, c);
89 c.X = sbSize.X;
90 c.Y = sbSize.Y - 1;
91 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
92 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
93 ERROR_INVALID_PARAMETER, GetLastError());
95 c.X = sbSize.X - 1;
96 c.Y = sbSize.Y;
97 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
98 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
99 ERROR_INVALID_PARAMETER, GetLastError());
101 c.X = -1;
102 c.Y = 0;
103 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
104 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
105 ERROR_INVALID_PARAMETER, GetLastError());
107 c.X = 0;
108 c.Y = -1;
109 ok(SetConsoleCursorPosition(hCon, c) == 0, "Cursor is outside\n");
110 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError: expecting %u got %lu\n",
111 ERROR_INVALID_PARAMETER, GetLastError());
114 static void testWriteSimple(HANDLE hCon, COORD sbSize)
116 COORD c;
117 DWORD len;
118 const char* mytest = "abcdefg";
119 const int mylen = strlen(mytest);
121 /* single line write */
122 c.X = c.Y = 0;
123 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
125 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
126 c.Y = 0;
127 for (c.X = 0; c.X < mylen; c.X++)
129 okCHAR(hCon, c, mytest[c.X], TEST_ATTRIB);
132 okCURSOR(hCon, c);
133 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
136 static void testWriteNotWrappedNotProcessed(HANDLE hCon, COORD sbSize)
138 COORD c;
139 DWORD len, mode;
140 const char* mytest = "123";
141 const int mylen = strlen(mytest);
142 int ret;
143 int p;
145 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode & ~(ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT)),
146 "clearing wrap at EOL & processed output\n");
148 /* write line, wrapping disabled, buffer exceeds sb width */
149 c.X = sbSize.X - 3; c.Y = 0;
150 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
152 ret = WriteConsole(hCon, mytest, mylen, &len, NULL);
153 ok(ret != 0 && len == mylen, "Couldn't write, ret = %d, len = %ld\n", ret, len);
154 c.Y = 0;
155 for (p = mylen - 3; p < mylen; p++)
157 c.X = sbSize.X - 3 + p % 3;
158 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
161 c.X = 0; c.Y = 1;
162 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
164 p = sbSize.X - 3 + mylen % 3;
165 c.X = p; c.Y = 0;
167 /* write line, wrapping disabled, strings end on end of line */
168 c.X = sbSize.X - mylen; c.Y = 0;
169 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
171 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
174 static void testWriteNotWrappedProcessed(HANDLE hCon, COORD sbSize)
176 COORD c;
177 DWORD len, mode;
178 const char* mytest = "abcd\nf\tg";
179 const int mylen = strlen(mytest);
180 const int mylen2 = strchr(mytest, '\n') - mytest;
181 int p;
183 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, (mode | ENABLE_PROCESSED_OUTPUT) & ~ENABLE_WRAP_AT_EOL_OUTPUT),
184 "clearing wrap at EOL & setting processed output\n");
186 /* write line, wrapping disabled, buffer exceeds sb width */
187 c.X = sbSize.X - 5; c.Y = 0;
188 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-5\n");
190 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
191 c.Y = 0;
192 for (c.X = sbSize.X - 5; c.X < sbSize.X - 1; c.X++)
194 okCHAR(hCon, c, mytest[c.X - sbSize.X + 5], TEST_ATTRIB);
196 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
198 c.X = 0; c.Y++;
199 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
200 for (c.X = 1; c.X < 8; c.X++)
201 okCHAR(hCon, c, ' ', TEST_ATTRIB);
202 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
203 c.X++;
204 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
206 okCURSOR(hCon, c);
208 /* write line, wrapping disabled, strings end on end of line */
209 c.X = sbSize.X - 4; c.Y = 0;
210 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
212 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
213 c.Y = 0;
214 for (c.X = sbSize.X - 4; c.X < sbSize.X; c.X++)
216 okCHAR(hCon, c, mytest[c.X - sbSize.X + 4], TEST_ATTRIB);
218 c.X = 0; c.Y++;
219 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
220 for (c.X = 1; c.X < 8; c.X++)
221 okCHAR(hCon, c, ' ', TEST_ATTRIB);
222 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
223 c.X++;
224 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
226 okCURSOR(hCon, c);
228 /* write line, wrapping disabled, strings end after end of line */
229 c.X = sbSize.X - 3; c.Y = 0;
230 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-4\n");
232 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
233 c.Y = 0;
234 for (p = mylen2 - 3; p < mylen2; p++)
236 c.X = sbSize.X - 3 + p % 3;
237 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
239 c.X = 0; c.Y = 1;
240 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
241 for (c.X = 1; c.X < 8; c.X++)
242 okCHAR(hCon, c, ' ', TEST_ATTRIB);
243 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
244 c.X++;
245 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
247 okCURSOR(hCon, c);
250 static void testWriteWrappedNotProcessed(HANDLE hCon, COORD sbSize)
252 COORD c;
253 DWORD len, mode;
254 const char* mytest = "abcd\nf\tg";
255 const int mylen = strlen(mytest);
256 int p;
258 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon,(mode | ENABLE_WRAP_AT_EOL_OUTPUT) & ~(ENABLE_PROCESSED_OUTPUT)),
259 "setting wrap at EOL & clearing processed output\n");
261 /* write line, wrapping enabled, buffer doesn't exceed sb width */
262 c.X = sbSize.X - 9; c.Y = 0;
263 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
265 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
266 c.Y = 0;
267 for (p = 0; p < mylen; p++)
269 c.X = sbSize.X - 9 + p;
270 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
272 c.X = sbSize.X - 9 + mylen;
273 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
274 c.X = 0; c.Y = 1;
275 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
277 /* write line, wrapping enabled, buffer does exceed sb width */
278 c.X = sbSize.X - 3; c.Y = 0;
279 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
281 c.Y = 1;
282 c.X = mylen - 3;
283 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
286 static void testWriteWrappedProcessed(HANDLE hCon, COORD sbSize)
288 COORD c;
289 DWORD len, mode;
290 const char* mytest = "abcd\nf\tg";
291 const int mylen = strlen(mytest);
292 int p;
294 ok(GetConsoleMode(hCon, &mode) && SetConsoleMode(hCon, mode | (ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT)),
295 "setting wrap at EOL & processed output\n");
297 /* write line, wrapping enabled, buffer doesn't exceed sb width */
298 c.X = sbSize.X - 9; c.Y = 0;
299 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-9\n");
301 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
302 for (p = 0; p < 4; p++)
304 c.X = sbSize.X - 9 + p;
305 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
307 c.X = sbSize.X - 9 + p;
308 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
309 c.X = 0; c.Y++;
310 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
311 for (c.X = 1; c.X < 8; c.X++)
312 okCHAR(hCon, c, ' ', TEST_ATTRIB);
313 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
314 c.X++;
315 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
316 okCURSOR(hCon, c);
318 /* write line, wrapping enabled, buffer does exceed sb width */
319 c.X = sbSize.X - 3; c.Y = 2;
320 ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left-3\n");
322 ok(WriteConsole(hCon, mytest, mylen, &len, NULL) != 0 && len == mylen, "WriteConsole\n");
323 for (p = 0; p < 3; p++)
325 c.X = sbSize.X - 3 + p;
326 okCHAR(hCon, c, mytest[p], TEST_ATTRIB);
328 c.X = 0; c.Y++;
329 okCHAR(hCon, c, mytest[3], TEST_ATTRIB);
330 c.X++;
331 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
333 c.X = 0; c.Y++;
334 okCHAR(hCon, c, mytest[5], TEST_ATTRIB);
335 for (c.X = 1; c.X < 8; c.X++)
336 okCHAR(hCon, c, ' ', TEST_ATTRIB);
337 okCHAR(hCon, c, mytest[7], TEST_ATTRIB);
338 c.X++;
339 okCHAR(hCon, c, ' ', DEFAULT_ATTRIB);
340 okCURSOR(hCon, c);
343 static void testWrite(HANDLE hCon, COORD sbSize)
345 /* FIXME: should in fact insure that the sb is at least 10 character wide */
346 ok(SetConsoleTextAttribute(hCon, TEST_ATTRIB), "Setting default text color\n");
347 resetContent(hCon, sbSize, FALSE);
348 testWriteSimple(hCon, sbSize);
349 resetContent(hCon, sbSize, FALSE);
350 testWriteNotWrappedNotProcessed(hCon, sbSize);
351 resetContent(hCon, sbSize, FALSE);
352 testWriteNotWrappedProcessed(hCon, sbSize);
353 resetContent(hCon, sbSize, FALSE);
354 testWriteWrappedNotProcessed(hCon, sbSize);
355 resetContent(hCon, sbSize, FALSE);
356 testWriteWrappedProcessed(hCon, sbSize);
359 static void testScroll(HANDLE hCon, COORD sbSize)
361 SMALL_RECT scroll, clip;
362 COORD dst, c, tc;
363 CHAR_INFO ci;
365 #define W 11
366 #define H 7
368 #define IN_SRECT(r,c) ((r).Left <= (c).X && (c).X <= (r).Right && (r).Top <= (c).Y && (c).Y <= (r).Bottom)
369 #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)
371 /* no clipping, src & dst rect don't overlap */
372 resetContent(hCon, sbSize, TRUE);
374 scroll.Left = 0;
375 scroll.Right = W - 1;
376 scroll.Top = 0;
377 scroll.Bottom = H - 1;
378 dst.X = W + 3;
379 dst.Y = H + 3;
380 ci.Char.UnicodeChar = '#';
381 ci.Attributes = TEST_ATTRIB;
383 clip.Left = 0;
384 clip.Right = sbSize.X - 1;
385 clip.Top = 0;
386 clip.Bottom = sbSize.Y - 1;
388 ok(ScrollConsoleScreenBuffer(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
390 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
392 for (c.X = 0; c.X < sbSize.X; c.X++)
394 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
396 tc.X = c.X - dst.X;
397 tc.Y = c.Y - dst.Y;
398 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
400 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
401 okCHAR(hCon, c, '#', TEST_ATTRIB);
402 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
406 /* no clipping, src & dst rect do overlap */
407 resetContent(hCon, sbSize, TRUE);
409 scroll.Left = 0;
410 scroll.Right = W - 1;
411 scroll.Top = 0;
412 scroll.Bottom = H - 1;
413 dst.X = W /2;
414 dst.Y = H / 2;
415 ci.Char.UnicodeChar = '#';
416 ci.Attributes = TEST_ATTRIB;
418 clip.Left = 0;
419 clip.Right = sbSize.X - 1;
420 clip.Top = 0;
421 clip.Bottom = sbSize.Y - 1;
423 ok(ScrollConsoleScreenBuffer(hCon, &scroll, NULL, dst, &ci), "Scrolling SB\n");
425 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
427 for (c.X = 0; c.X < sbSize.X; c.X++)
429 if (dst.X <= c.X && c.X < dst.X + W && dst.Y <= c.Y && c.Y < dst.Y + H)
431 tc.X = c.X - dst.X;
432 tc.Y = c.Y - dst.Y;
433 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
435 else if (c.X < W && c.Y < H) okCHAR(hCon, c, '#', TEST_ATTRIB);
436 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
440 /* clipping, src & dst rect don't overlap */
441 resetContent(hCon, sbSize, TRUE);
443 scroll.Left = 0;
444 scroll.Right = W - 1;
445 scroll.Top = 0;
446 scroll.Bottom = H - 1;
447 dst.X = W + 3;
448 dst.Y = H + 3;
449 ci.Char.UnicodeChar = '#';
450 ci.Attributes = TEST_ATTRIB;
452 clip.Left = W / 2;
453 clip.Right = min(W + W / 2, sbSize.X - 1);
454 clip.Top = H / 2;
455 clip.Bottom = min(H + H / 2, sbSize.Y - 1);
457 ok(ScrollConsoleScreenBuffer(hCon, &scroll, &clip, dst, &ci), "Scrolling SB\n");
459 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
461 for (c.X = 0; c.X < sbSize.X; c.X++)
463 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
465 tc.X = c.X - dst.X;
466 tc.Y = c.Y - dst.Y;
467 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
469 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
470 okCHAR(hCon, c, '#', TEST_ATTRIB);
471 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
475 /* clipping, src & dst rect do overlap */
476 resetContent(hCon, sbSize, TRUE);
478 scroll.Left = 0;
479 scroll.Right = W - 1;
480 scroll.Top = 0;
481 scroll.Bottom = H - 1;
482 dst.X = W / 2 - 3;
483 dst.Y = H / 2 - 3;
484 ci.Char.UnicodeChar = '#';
485 ci.Attributes = TEST_ATTRIB;
487 clip.Left = W / 2;
488 clip.Right = min(W + W / 2, sbSize.X - 1);
489 clip.Top = H / 2;
490 clip.Bottom = min(H + H / 2, sbSize.Y - 1);
492 ok(ScrollConsoleScreenBuffer(hCon, &scroll, &clip, dst, &ci), "Scrolling SB\n");
494 for (c.Y = 0; c.Y < sbSize.Y; c.Y++)
496 for (c.X = 0; c.X < sbSize.X; c.X++)
498 if (IN_SRECT2(scroll, dst, c) && IN_SRECT(clip, c))
500 tc.X = c.X - dst.X;
501 tc.Y = c.Y - dst.Y;
502 okCHAR(hCon, c, CONTENT(tc), DEFAULT_ATTRIB);
504 else if (IN_SRECT(scroll, c) && IN_SRECT(clip, c))
505 okCHAR(hCon, c, '#', TEST_ATTRIB);
506 else okCHAR(hCon, c, CONTENT(c), DEFAULT_ATTRIB);
511 static int mch_count;
512 /* we need the event as Wine console event generation isn't synchronous
513 * (ie GenerateConsoleCtrlEvent returns before all ctrl-handlers in all
514 * processes have been called).
516 static HANDLE mch_event;
517 static BOOL WINAPI mch(DWORD event)
519 mch_count++;
520 SetEvent(mch_event);
521 return TRUE;
524 static void testCtrlHandler(void)
526 ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
527 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %lu\n", GetLastError());
528 ok(SetConsoleCtrlHandler(mch, TRUE), "Couldn't set handler\n");
529 /* wine requires the event for the test, as we cannot insure, so far, that event
530 * are processed synchronously in GenerateConsoleCtrlEvent()
532 mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
533 mch_count = 0;
534 ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
535 #if 0 /* FIXME: it isn't synchronous on wine but it can still happen before we test */
536 todo_wine ok(mch_count == 1, "Event isn't synchronous\n");
537 #endif
538 ok(WaitForSingleObject(mch_event, 3000) == WAIT_OBJECT_0, "event sending didn't work\n");
539 CloseHandle(mch_event);
541 /* Turning off ctrl-c handling doesn't work on win9x such way ... */
542 ok(SetConsoleCtrlHandler(NULL, TRUE), "Couldn't turn off ctrl-c handling\n");
543 mch_event = CreateEventA(NULL, TRUE, FALSE, NULL);
544 mch_count = 0;
545 if(!(GetVersion() & 0x80000000))
546 /* ... and next line leads to an unhandled exception on 9x. Avoid it on 9x. */
547 ok(GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0), "Couldn't send ctrl-c event\n");
548 ok(WaitForSingleObject(mch_event, 3000) == WAIT_TIMEOUT && mch_count == 0, "Event shouldn't have been sent\n");
549 CloseHandle(mch_event);
550 ok(SetConsoleCtrlHandler(mch, FALSE), "Couldn't remove handler\n");
551 ok(!SetConsoleCtrlHandler(mch, FALSE), "Shouldn't succeed\n");
552 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Bad error %lu\n", GetLastError());
555 START_TEST(console)
557 HANDLE hConIn, hConOut;
558 BOOL ret;
559 CONSOLE_SCREEN_BUFFER_INFO sbi;
561 /* be sure we have a clean console (and that's our own)
562 * FIXME: this will make the test fail (currently) if we don't run
563 * under X11
564 * Another solution would be to rerun the test under wineconsole with
565 * the curses backend
568 /* first, we detach and open a fresh console to play with */
569 FreeConsole();
570 ok(AllocConsole(), "Couldn't alloc console\n");
571 hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
572 hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
574 /* now verify everything's ok */
575 ok(hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
576 ok(hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
578 ok(ret = GetConsoleScreenBufferInfo(hConOut, &sbi), "Getting sb info\n");
579 if (!ret) return;
581 /* Non interactive tests */
582 testCursor(hConOut, sbi.dwSize);
583 /* will test wrapped (on/off) & processed (on/off) strings output */
584 testWrite(hConOut, sbi.dwSize);
585 /* will test line scrolling at the bottom of the screen */
586 /* testBottomScroll(); */
587 /* will test all the scrolling operations */
588 testScroll(hConOut, sbi.dwSize);
589 /* will test sb creation / modification... */
590 /* testScreenBuffer() */
591 testCtrlHandler();
592 /* still to be done: access rights & access on objects */