Add a few more experiments

This commit is contained in:
Ryan Prichard 2015-08-22 20:56:24 -07:00
parent 380828dee5
commit 95fe71a501
4 changed files with 170 additions and 51 deletions

76
misc/TestUtil.cc Executable file
View File

@ -0,0 +1,76 @@
// This file is included into test programs using #include
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <vector>
#include "../shared/DebugClient.h"
// Launch this test program again, in a new console that we will destroy.
static void startChildProcess(const wchar_t *arg) {
wchar_t program[1024];
wchar_t cmdline[1024];
GetModuleFileNameW(NULL, program, 1024);
swprintf(cmdline, L"\"%s\" %s", program, arg);
STARTUPINFOW sui;
PROCESS_INFORMATION pi;
memset(&sui, 0, sizeof(sui));
memset(&pi, 0, sizeof(pi));
sui.cb = sizeof(sui);
CreateProcessW(program, cmdline,
NULL, NULL,
/*bInheritHandles=*/FALSE,
/*dwCreationFlags=*/CREATE_NEW_CONSOLE,
NULL, NULL,
&sui, &pi);
}
static void setBufferSize(int x, int y) {
COORD size = { x, y };
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL success = SetConsoleScreenBufferSize(conout, size);
trace("setBufferSize: (%d,%d), result=%d", x, y, success);
}
static void setWindowPos(int x, int y, int w, int h) {
SMALL_RECT r = { x, y, x + w - 1, y + h - 1 };
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL success = SetConsoleWindowInfo(conout, /*bAbsolute=*/TRUE, &r);
trace("setWindowPos: (%d,%d,%d,%d), result=%d", x, y, w, h, success);
}
static void countDown(int sec) {
for (int i = sec; i > 0; --i) {
printf("%d.. ", i);
fflush(stdout);
Sleep(1000);
}
printf("\n");
}
static void fillBox(int x, int y, int w, int h, char ch, int attributes=7) {
CHAR_INFO info = { 0 };
info.Char.AsciiChar = ch;
info.Attributes = attributes;
std::vector<CHAR_INFO> buf(w * h, info);
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD bufSize = { w, h };
COORD bufCoord = { 0, 0 };
SMALL_RECT writeRegion = { x, y, x + w - 1, y + h - 1 };
WriteConsoleOutputA(conout, buf.data(), bufSize, bufCoord, &writeRegion);
}
static void setChar(int x, int y, char ch, int attributes=7) {
fillBox(x, y, 1, 1, ch, attributes);
}
static void repeatChar(int count, char ch) {
for (int i = 0; i < count; ++i) {
putchar(ch);
}
fflush(stdout);
}

View File

@ -15,55 +15,17 @@
#include <stdlib.h>
#include <wchar.h>
#include "../shared/DebugClient.cc"
#include "TestUtil.cc"
const int SC_CONSOLE_MARK = 0xFFF2;
const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
static void setBufferSize(int x, int y) {
COORD size = { x, y };
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL success = SetConsoleScreenBufferSize(conout, size);
trace("setBufferSize: (%d,%d), result=%d", x, y, success);
int main(int argc, char *argv[]) {
if (argc == 1) {
startChildProcess(L"CHILD");
return 0;
}
static void setWindowPos(int x, int y, int w, int h) {
SMALL_RECT r = { x, y, x + w - 1, y + h - 1 };
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL success = SetConsoleWindowInfo(conout, /*bAbsolute=*/TRUE, &r);
trace("setWindowPos: (%d,%d,%d,%d), result=%d", x, y, w, h, success);
}
static void countDown(int sec) {
for (int i = sec; i > 0; --i) {
printf("%d.. ", i);
fflush(stdout);
Sleep(1000);
}
printf("\n");
}
// Launch this test program again, in a new console that we will destroy.
static void startChildProcess() {
wchar_t program[1024];
wchar_t cmdline[1024];
GetModuleFileNameW(NULL, program, 1024);
swprintf(cmdline, L"\"%s\" CHILD", program);
STARTUPINFOW sui;
PROCESS_INFORMATION pi;
memset(&sui, 0, sizeof(sui));
memset(&pi, 0, sizeof(pi));
sui.cb = sizeof(sui);
CreateProcessW(program, cmdline,
NULL, NULL,
/*bInheritHandles=*/FALSE,
/*dwCreationFlags=*/CREATE_NEW_CONSOLE,
NULL, NULL,
&sui, &pi);
}
static void performTest() {
setWindowPos(0, 0, 1, 1);
setBufferSize(80, 25);
setWindowPos(0, 0, 80, 25);
@ -86,11 +48,3 @@ static void performTest() {
printf("Done...\n");
Sleep(2000);
}
int main(int argc, char *argv[]) {
if (argc == 1) {
startChildProcess();
} else {
performTest();
}
}

58
misc/Win10WrapTest1.cc Executable file
View File

@ -0,0 +1,58 @@
/*
* Demonstrates some wrapping behaviors of the new Windows 10 console.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "../shared/DebugClient.cc"
#include "TestUtil.cc"
int main(int argc, char *argv[]) {
if (argc == 1) {
startChildProcess(L"CHILD");
return 0;
}
setWindowPos(0, 0, 1, 1);
setBufferSize(40, 20);
setWindowPos(0, 0, 40, 20);
system("cls");
repeatChar(39, 'A'); repeatChar(1, ' ');
repeatChar(39, 'B'); repeatChar(1, ' ');
printf("\n");
repeatChar(39, 'C'); repeatChar(1, ' ');
repeatChar(39, 'D'); repeatChar(1, ' ');
printf("\n");
repeatChar(40, 'E');
repeatChar(40, 'F');
printf("\n");
repeatChar(39, 'G'); repeatChar(1, ' ');
repeatChar(39, 'H'); repeatChar(1, ' ');
printf("\n");
Sleep(2000);
setChar(39, 0, '*', 0x24);
setChar(39, 1, '*', 0x24);
setChar(39, 3, ' ', 0x24);
setChar(39, 4, ' ', 0x24);
setChar(38, 6, ' ', 0x24);
setChar(38, 7, ' ', 0x24);
Sleep(2000);
setWindowPos(0, 0, 35, 20);
setBufferSize(35, 20);
trace("DONE");
printf("Sleeping forever...\n");
while(true) { Sleep(1000); }
}

31
misc/Win10WrapTest2.cc Executable file
View File

@ -0,0 +1,31 @@
#include <windows.h>
#include "TestUtil.cc"
#include "../shared/DebugClient.cc"
int main(int argc, char *argv[]) {
if (argc == 1) {
startChildProcess(L"CHILD");
return 0;
}
const int WIDTH = 25;
setWindowPos(0, 0, 1, 1);
setBufferSize(WIDTH, 40);
setWindowPos(0, 0, WIDTH, 20);
system("cls");
for (int i = 0; i < 100; ++i) {
printf("FOO(%d)\n", i);
}
repeatChar(5, '\n');
repeatChar(WIDTH * 5, '.');
repeatChar(10, '\n');
setWindowPos(0, 20, WIDTH, 20);
fillBox(0, 5, 1, 10, '|');
Sleep(120000);
}