installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / misc / FreezePerfTest.cc
1 #include <windows.h>
2
3 #include "TestUtil.cc"
4
5 const int SC_CONSOLE_MARK = 0xFFF2;
6 const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
7
8 int main(int argc, char *argv[0]) {
9
10     if (argc != 2) {
11         printf("Usage: %s (mark|selectall|read)\n", argv[0]);
12         return 1;
13     }
14
15     enum class Test { Mark, SelectAll, Read } test;
16     if (!strcmp(argv[1], "mark")) {
17         test = Test::Mark;
18     } else if (!strcmp(argv[1], "selectall")) {
19         test = Test::SelectAll;
20     } else if (!strcmp(argv[1], "read")) {
21         test = Test::Read;
22     } else {
23         printf("Invalid test: %s\n", argv[1]);
24         return 1;
25     }
26
27     HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
28     TimeMeasurement tm;
29     HWND hwnd = GetConsoleWindow();
30
31     setWindowPos(0, 0, 1, 1);
32     setBufferSize(100, 3000);
33     system("cls");
34     setWindowPos(0, 2975, 100, 25);
35     setCursorPos(0, 2999);
36
37     ShowWindow(hwnd, SW_HIDE);
38
39     for (int i = 0; i < 1000; ++i) {
40         // CONSOLE_SCREEN_BUFFER_INFO info = {};
41         // GetConsoleScreenBufferInfo(conout, &info);
42
43         if (test == Test::Mark) {
44             SendMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_MARK, 0);
45             SendMessage(hwnd, WM_CHAR, 27, 0x00010001);
46         } else if (test == Test::SelectAll) {
47             SendMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_SELECT_ALL, 0);
48             SendMessage(hwnd, WM_CHAR, 27, 0x00010001);
49         } else if (test == Test::Read) {
50             static CHAR_INFO buffer[100 * 3000];
51             const SMALL_RECT readRegion = {0, 0, 99, 2999};
52             SMALL_RECT tmp = readRegion;
53             BOOL ret = ReadConsoleOutput(conout, buffer, {100, 3000}, {0, 0}, &tmp);
54             ASSERT(ret && !memcmp(&tmp, &readRegion, sizeof(tmp)));
55         }
56     }
57
58     ShowWindow(hwnd, SW_SHOW);
59
60     printf("elapsed: %f\n", tm.elapsed());
61     return 0;
62 }