2 * This is a test program for the PDCurses screen package for IBM PC type
5 * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz)
6 * wrs(5/28/93) -- modified to be consistent (perform identically) with either
7 * PDCurses or under Unix System V, R4
9 * $Id: testcurs.c,v 1.56 2021/03/27 22:39:50 tom Exp $
12 #include <test.priv.h>
15 const char *XCursesProgramName = "testcurs";
18 static int initTest(WINDOW **);
19 static void display_menu(int, int);
20 static void inputTest(WINDOW *);
21 static void introTest(WINDOW *);
22 static void outputTest(WINDOW *);
24 static void padTest(WINDOW *);
26 static void scrollTest(WINDOW *);
27 #if defined(PDCURSES) && !defined(XCURSES)
28 static void resizeTest(WINDOW *);
31 static int width, height;
36 int y1 = getmaxy(win);
37 int x1 = getmaxx(win);
38 int y0 = y1 < 10 ? y1 : 10;
42 save = mvwinch(win, y0, x1 - 1);
44 MvWAddStr(win, y0, x0, " Press any key to continue");
48 MvWAddCh(win, y0, x1 - 1, save);
56 initTest(WINDOW **win)
59 PDC_debug("initTest called\n");
62 curses_trace(TRACE_MAXIMUM);
66 PDC_debug("after initscr()\n");
73 height = 13; /* Create a drawing window */
74 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
83 introTest(WINDOW *win)
85 wmove(win, height / 2 - 5, width / 2);
86 wvline(win, ACS_VLINE, 10);
87 wmove(win, height / 2, width / 2 - 10);
88 whline(win, ACS_HLINE, 20);
94 box(win, ACS_VLINE, ACS_HLINE);
98 "You should have rectangle in the middle of the screen");
99 MvWAddStr(win, 2, 1, "You should have heard a beep");
105 scrollTest(WINDOW *win)
110 NCURSES_CONST char *Message = "The window will now scroll slowly";
115 MvWAddStr(win, OldY - 2, 1, Message);
118 for (i = 1; i <= OldY; i++) {
125 for (i = 1; i < OldY; i++) {
126 MvWPrintw(win, i, 1, "Line %d", i);
128 MvWPrintw(win, OldY - 2, 1, "The top of the window will scroll");
130 wsetscrreg(win, 0, half - 1);
131 box(win, ACS_VLINE, ACS_HLINE);
133 for (i = 1; i <= half; i++) {
136 box(win, ACS_VLINE, ACS_HLINE);
141 for (i = 1; i < OldY; i++) {
142 MvWPrintw(win, i, 1, "Line %d", i);
144 MvWPrintw(win, 1, 1, "The bottom of the window will scroll");
145 wmove(win, OldY - 2, 1);
146 wsetscrreg(win, half, --OldY);
147 box(win, ACS_VLINE, ACS_HLINE);
149 for (i = half; i <= OldY; i++) {
152 box(win, ACS_VLINE, ACS_HLINE);
155 wsetscrreg(win, 0, OldY);
159 inputTest(WINDOW *win)
163 int w, h, bx, by, sw, sh, i, num;
169 getbegyx(win, by, bx);
172 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
177 init_pair(2, COLOR_WHITE, COLOR_RED);
178 wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD);
180 wbkgd(subWin, A_BOLD);
182 wbkgd(subWin, A_BOLD);
184 box(subWin, ACS_VLINE, ACS_HLINE);
188 MvWAddStr(win, 2, 1, "Press some keys for 5 seconds");
189 MvWAddStr(win, 1, 1, "Pressing ^C should do nothing");
193 box(subWin, ACS_VLINE, ACS_HLINE);
194 for (i = 0; i < 5; i++) {
195 MvWPrintw(subWin, 1, 1, "Time = %d", i);
207 MvWAddStr(win, 2, 1, "Press a key, followed by ENTER");
217 MvWAddStr(win, 4, 1, "The character should now have been deleted");
221 MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
222 MvWAddStr(win, 2, 1, "Press spacebar to finish");
233 #ifdef NCURSES_MOUSE_VERSION
234 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
236 #if defined(PDCURSES)
237 mouse_set(ALL_MOUSE_EVENTS);
247 wprintw(win, "Key Pressed: %s", keyname(c));
249 wprintw(win, "Key Pressed: %c", c);
251 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
253 if (c == KEY_MOUSE) {
254 #if defined(NCURSES_MOUSE_VERSION)
255 #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037))
256 #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED))
257 #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED))
258 #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED))
259 #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED))
264 if (ButtonChanged(1))
266 else if (ButtonChanged(2))
268 else if (ButtonChanged(3))
273 wprintw(win, "Button %d: ", button);
274 if (ButtonPressed(button))
275 wprintw(win, "pressed: ");
276 else if (ButtonDouble(button))
277 wprintw(win, "double: ");
278 else if (ButtonTriple(button))
279 wprintw(win, "triple: ");
281 wprintw(win, "released: ");
282 wprintw(win, " Position: Y: %d X: %d", event.y, event.x);
283 #elif defined(PDCURSES)
286 if (BUTTON_CHANGED(1))
288 else if (BUTTON_CHANGED(2))
290 else if (BUTTON_CHANGED(3))
295 wprintw(win, "Button %d: ", button);
297 wprintw(win, "moved: ");
298 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
299 wprintw(win, "pressed: ");
300 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
301 wprintw(win, "double: ");
303 wprintw(win, "released: ");
304 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
305 #endif /* NCURSES_VERSION vs PDCURSES */
307 #endif /* KEY_MOUSE */
317 #if defined(PDCURSES)
324 static const char *fmt[] =
331 char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]);
334 MvWAddStr(win, 3, 2, "The window should have moved");
336 "This text should have appeared without you pressing a key");
338 "Scanning with format \"%s\"", format);
339 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
347 answered = mvwscanw(win, 7, 6, format, &num, buffer);
349 "String: %s Number: %d (%d values read)",
350 buffer, num, answered);
354 } while (answered > 0);
358 outputTest(WINDOW *win)
366 char tc_buffer[4096];
367 char tc_parsed[4096];
368 char *area_pointer = tc_parsed;
369 tgetent(tc_buffer, getenv("TERM"));
371 #define tgetstr(a,b) 0
373 #endif /* !HAVE_TIGETSTR */
378 "You should now have a screen in the upper left corner, and this text should have wrapped");
380 waddstr(win, "\nThis text should be down\n");
381 waddstr(win, "and broken into two here ^");
385 wattron(win, A_BOLD);
386 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
387 MvWAddStr(win, 8, 1, "Press any key to continue");
391 getbegyx(win, by, bx);
393 if (LINES < 24 || COLS < 75) {
395 "Some tests have been skipped as they require a");
396 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
399 WINDOW *win1 = newwin(10, 50, 14, 25);
406 init_pair(3, COLOR_BLUE, COLOR_WHITE);
407 wbkgd(win1, (chtype) COLOR_PAIR(3));
409 wbkgd(win1, A_NORMAL);
411 wbkgd(win1, A_NORMAL);
414 MvWAddStr(win1, 5, 1,
415 "This text should appear; using overlay option");
416 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
418 #if defined(PDCURSES) && !defined(XCURSES)
419 box(win1, 0xb3, 0xc4);
421 box(win1, ACS_VLINE, ACS_HLINE);
428 wattron(win1, A_BLINK);
429 MvWAddStr(win1, 4, 1,
430 "This blinking text should appear in only the second window");
431 wattroff(win1, A_BLINK);
444 MvWAddStr(win, 6, 2, "This line shouldn't appear");
445 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
446 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
451 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
461 waddstr(win, "The next char should be l: ");
466 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
472 MvWAddStr(win, 5, 2, "The lines below should have moved down");
477 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
479 MvWAddStr(win, 10, 1, "Enter a string: ");
484 wscanw(win, "%s", Buffer);
486 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
487 MvAddStr(10, 1, "Enter a string: ");
491 if (TIGETSTR("cvvis", "vs") != 0) {
494 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
498 if (TIGETSTR("civis", "vi") != 0) {
502 "The cursor should have disappeared (invisible)");
506 if (TIGETSTR("cnorm", "ve") != 0) {
509 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
515 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
517 init_pair(1, COLOR_RED, COLOR_WHITE);
525 MvWAddStr(win, 1, 1, "Information About Your Terminal");
526 MvWAddStr(win, 3, 1, termname());
527 MvWAddStr(win, 4, 1, longname());
528 if (termattrs() & A_BLINK)
529 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
531 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
534 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
537 (void) mvwinnstr(win, 7, 5, Buffer, 18);
538 MvAddStr(LINES - 2, 10, Buffer);
543 #if defined(PDCURSES) && !defined(XCURSES)
545 resizeTest(WINDOW *dummy GCC_UNUSED)
554 resize_term(50, 120);
559 win1 = newwin(10, 50, 14, 25);
566 init_pair(3, COLOR_BLUE, COLOR_WHITE);
567 wattrset(win1, COLOR_PAIR(3));
572 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
578 MvWAddStr(win1, 1, 1, "The screen should now be reset");
591 padTest(WINDOW *dummy GCC_UNUSED)
595 if ((pad = newpad(50, 100)) != 0) {
598 wattron(pad, A_REVERSE);
599 MvWAddStr(pad, 5, 2, "This is a new pad");
600 (void) wattrset(pad, A_NORMAL);
602 "The end of this line should be truncated here:except now");
603 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
606 MvWAddStr(pad, 10, 1, " Press any key to continue");
607 prefresh(pad, 0, 0, 0, 0, 10, 45);
612 if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) {
613 MvWAddStr(spad, 2, 2, "This is a new subpad");
617 prefresh(pad, 0, 0, 0, 0, 15, 75);
622 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
623 MvWAddStr(pad, 40, 1, " Press any key to continue");
624 prefresh(pad, 30, 0, 0, 0, 10, 45);
632 #endif /* HAVE_NEWPAD */
635 NCURSES_CONST char *text;
636 void (*function) (WINDOW *);
638 typedef struct commands COMMAND;
640 static const COMMAND command[] =
642 {"General Test", introTest},
644 {"Pad Test", padTest},
646 #if defined(PDCURSES) && !defined(XCURSES)
647 {"Resize Test", resizeTest},
649 {"Scroll Test", scrollTest},
650 {"Input Test", inputTest},
651 {"Output Test", outputTest}
653 #define MAX_OPTIONS (int) SIZEOF(command)
656 display_menu(int old_option, int new_option)
660 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
662 (void) attrset(A_NORMAL);
663 MvAddStr(3, 20, "PDCurses Test Program");
665 for (i = 0; i < (int) MAX_OPTIONS; i++)
666 MvAddStr(5 + i, 25, command[i].text);
668 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
669 MvAddStr(5 + old_option, 25, command[old_option].text);
671 (void) attrset(A_REVERSE);
672 MvAddStr(5 + new_option, 25, command[new_option].text);
673 (void) attrset(A_NORMAL);
675 "Use Up and Down Arrows to select - Enter to run - Q to quit");
682 char *argv[]GCC_UNUSED)
685 int old_option = (-1);
690 setlocale(LC_ALL, "");
693 PDC_debug("testcurs started\n");
696 ExitProgram(EXIT_FAILURE);
699 display_menu(old_option, new_option);
706 init_pair(1, COLOR_WHITE, COLOR_BLUE);
707 wbkgd(win, (chtype) COLOR_PAIR(1));
709 wbkgd(win, A_REVERSE);
711 wbkgd(win, A_REVERSE);
716 keypad(stdscr, TRUE);
719 if (key < KEY_MIN && key > 0 && isalpha(key)) {
722 for (n = 0; n < MAX_OPTIONS; ++n) {
723 if (key == command[n].text[0]) {
724 display_menu(old_option, new_option = n);
736 (*command[new_option].function) (win);
738 display_menu(old_option, new_option);
741 new_option = ((new_option == 0)
744 display_menu(old_option, new_option);
747 new_option = ((new_option == (MAX_OPTIONS - 1))
750 display_menu(old_option, new_option);
772 ExitProgram(EXIT_SUCCESS);