2 * Demonstrates that console clearing sets each cell's character to SP, not
3 * NUL, and it sets the attribute of each cell to the current text attribute.
5 * This confirms the MSDN instruction in the "Clearing the Screen" article.
6 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms682022(v=vs.85).aspx
7 * It advises using GetConsoleScreenBufferInfo to get the current text
8 * attribute, then FillConsoleOutputCharacter and FillConsoleOutputAttribute to
9 * write to the console buffer.
18 #include "TestUtil.cc"
20 int main(int argc, char *argv[]) {
22 startChildProcess(L"CHILD");
26 const HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
28 SetConsoleTextAttribute(conout, 0x24);
31 setWindowPos(0, 0, 1, 1);
32 setBufferSize(80, 25);
33 setWindowPos(0, 0, 80, 25);
36 COORD bufSize = { 1, 1 };
37 COORD bufCoord = { 0, 0 };
38 SMALL_RECT rect = { 5, 5, 5, 5 };
41 COORD writeCoord = { 5, 5 };
43 // After cls, each cell's character is a space, and its attributes are the
44 // default text attributes.
45 ret = ReadConsoleOutputW(conout, &buf, bufSize, bufCoord, &rect);
46 assert(ret && buf.Char.UnicodeChar == L' ' && buf.Attributes == 0x24);
48 // Nevertheless, it is possible to change a cell to NUL.
49 ret = FillConsoleOutputCharacterW(conout, L'\0', 1, writeCoord, &actual);
50 assert(ret && actual == 1);
51 ret = ReadConsoleOutputW(conout, &buf, bufSize, bufCoord, &rect);
52 assert(ret && buf.Char.UnicodeChar == L'\0' && buf.Attributes == 0x24);
54 // As well as a 0 attribute. (As one would expect, the cell is
56 ret = FillConsoleOutputAttribute(conout, 0, 1, writeCoord, &actual);
57 assert(ret && actual == 1);
58 ret = ReadConsoleOutputW(conout, &buf, bufSize, bufCoord, &rect);
59 assert(ret && buf.Char.UnicodeChar == L'\0' && buf.Attributes == 0);
60 ret = FillConsoleOutputCharacterW(conout, L'X', 1, writeCoord, &actual);
61 assert(ret && actual == 1);
62 ret = ReadConsoleOutputW(conout, &buf, bufSize, bufCoord, &rect);
63 assert(ret && buf.Char.UnicodeChar == L'X' && buf.Attributes == 0);
65 // The 'X' is invisible.
68 ret = FillConsoleOutputAttribute(conout, 0x42, 1, writeCoord, &actual);
69 assert(ret && actual == 1);