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.55 2019/12/14 23:25:29 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, c, 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);
245 wprintw(win, "Key Pressed: %s", keyname(c));
247 wprintw(win, "Key Pressed: %c", c);
249 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
251 if (c == KEY_MOUSE) {
252 #if defined(NCURSES_MOUSE_VERSION)
253 #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037))
254 #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED))
255 #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED))
256 #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED))
257 #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED))
262 if (ButtonChanged(1))
264 else if (ButtonChanged(2))
266 else if (ButtonChanged(3))
271 wprintw(win, "Button %d: ", button);
272 if (ButtonPressed(button))
273 wprintw(win, "pressed: ");
274 else if (ButtonDouble(button))
275 wprintw(win, "double: ");
276 else if (ButtonTriple(button))
277 wprintw(win, "triple: ");
279 wprintw(win, "released: ");
280 wprintw(win, " Position: Y: %d X: %d", event.y, event.x);
281 #elif defined(PDCURSES)
284 if (BUTTON_CHANGED(1))
286 else if (BUTTON_CHANGED(2))
288 else if (BUTTON_CHANGED(3))
293 wprintw(win, "Button %d: ", button);
295 wprintw(win, "moved: ");
296 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
297 wprintw(win, "pressed: ");
298 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
299 wprintw(win, "double: ");
301 wprintw(win, "released: ");
302 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
303 #endif /* NCURSES_VERSION vs PDCURSES */
305 #endif /* KEY_MOUSE */
315 #if defined(PDCURSES)
322 static const char *fmt[] =
329 char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]);
332 MvWAddStr(win, 3, 2, "The window should have moved");
334 "This text should have appeared without you pressing a key");
336 "Scanning with format \"%s\"", format);
337 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
345 answered = mvwscanw(win, 7, 6, format, &num, buffer);
347 "String: %s Number: %d (%d values read)",
348 buffer, num, answered);
352 } while (answered > 0);
356 outputTest(WINDOW *win)
365 char tc_buffer[4096];
366 char tc_parsed[4096];
367 char *area_pointer = tc_parsed;
368 tgetent(tc_buffer, getenv("TERM"));
370 #define tgetstr(a,b) 0
372 #endif /* !HAVE_TIGETSTR */
377 "You should now have a screen in the upper left corner, and this text should have wrapped");
379 waddstr(win, "\nThis text should be down\n");
380 waddstr(win, "and broken into two here ^");
384 wattron(win, A_BOLD);
385 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
386 MvWAddStr(win, 8, 1, "Press any key to continue");
390 getbegyx(win, by, bx);
392 if (LINES < 24 || COLS < 75) {
394 "Some tests have been skipped as they require a");
395 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
398 win1 = newwin(10, 50, 14, 25);
405 init_pair(3, COLOR_BLUE, COLOR_WHITE);
406 wbkgd(win1, (chtype) COLOR_PAIR(3));
408 wbkgd(win1, A_NORMAL);
410 wbkgd(win1, A_NORMAL);
413 MvWAddStr(win1, 5, 1,
414 "This text should appear; using overlay option");
415 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
417 #if defined(PDCURSES) && !defined(XCURSES)
418 box(win1, 0xb3, 0xc4);
420 box(win1, ACS_VLINE, ACS_HLINE);
427 wattron(win1, A_BLINK);
428 MvWAddStr(win1, 4, 1,
429 "This blinking text should appear in only the second window");
430 wattroff(win1, A_BLINK);
443 MvWAddStr(win, 6, 2, "This line shouldn't appear");
444 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
445 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
450 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
460 waddstr(win, "The next char should be l: ");
465 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
471 MvWAddStr(win, 5, 2, "The lines below should have moved down");
476 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
478 MvWAddStr(win, 10, 1, "Enter a string: ");
483 wscanw(win, "%s", Buffer);
485 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
486 MvAddStr(10, 1, "Enter a string: ");
490 if (TIGETSTR("cvvis", "vs") != 0) {
493 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
497 if (TIGETSTR("civis", "vi") != 0) {
501 "The cursor should have disappeared (invisible)");
505 if (TIGETSTR("cnorm", "ve") != 0) {
508 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
514 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
516 init_pair(1, COLOR_RED, COLOR_WHITE);
524 MvWAddStr(win, 1, 1, "Information About Your Terminal");
525 MvWAddStr(win, 3, 1, termname());
526 MvWAddStr(win, 4, 1, longname());
527 if (termattrs() & A_BLINK)
528 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
530 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
533 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
536 (void) mvwinnstr(win, 7, 5, Buffer, 18);
537 MvAddStr(LINES - 2, 10, Buffer);
542 #if defined(PDCURSES) && !defined(XCURSES)
544 resizeTest(WINDOW *dummy GCC_UNUSED)
553 resize_term(50, 120);
558 win1 = newwin(10, 50, 14, 25);
565 init_pair(3, COLOR_BLUE, COLOR_WHITE);
566 wattrset(win1, COLOR_PAIR(3));
571 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
577 MvWAddStr(win1, 1, 1, "The screen should now be reset");
590 padTest(WINDOW *dummy GCC_UNUSED)
594 if ((pad = newpad(50, 100)) != 0) {
595 wattron(pad, A_REVERSE);
596 MvWAddStr(pad, 5, 2, "This is a new pad");
597 (void) wattrset(pad, A_NORMAL);
599 "The end of this line should be truncated here:except now");
600 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
603 MvWAddStr(pad, 10, 1, " Press any key to continue");
604 prefresh(pad, 0, 0, 0, 0, 10, 45);
609 if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) {
610 MvWAddStr(spad, 2, 2, "This is a new subpad");
614 prefresh(pad, 0, 0, 0, 0, 15, 75);
619 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
620 MvWAddStr(pad, 40, 1, " Press any key to continue");
621 prefresh(pad, 30, 0, 0, 0, 10, 45);
629 #endif /* HAVE_NEWPAD */
632 NCURSES_CONST char *text;
633 void (*function) (WINDOW *);
635 typedef struct commands COMMAND;
637 static const COMMAND command[] =
639 {"General Test", introTest},
641 {"Pad Test", padTest},
643 #if defined(PDCURSES) && !defined(XCURSES)
644 {"Resize Test", resizeTest},
646 {"Scroll Test", scrollTest},
647 {"Input Test", inputTest},
648 {"Output Test", outputTest}
650 #define MAX_OPTIONS (int) SIZEOF(command)
653 display_menu(int old_option, int new_option)
657 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
659 (void) attrset(A_NORMAL);
660 MvAddStr(3, 20, "PDCurses Test Program");
662 for (i = 0; i < (int) MAX_OPTIONS; i++)
663 MvAddStr(5 + i, 25, command[i].text);
665 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
666 MvAddStr(5 + old_option, 25, command[old_option].text);
668 (void) attrset(A_REVERSE);
669 MvAddStr(5 + new_option, 25, command[new_option].text);
670 (void) attrset(A_NORMAL);
672 "Use Up and Down Arrows to select - Enter to run - Q to quit");
679 char *argv[]GCC_UNUSED)
683 int old_option = (-1);
688 setlocale(LC_ALL, "");
691 PDC_debug("testcurs started\n");
694 ExitProgram(EXIT_FAILURE);
697 display_menu(old_option, new_option);
701 init_pair(1, COLOR_WHITE, COLOR_BLUE);
702 wbkgd(win, (chtype) COLOR_PAIR(1));
704 wbkgd(win, A_REVERSE);
706 wbkgd(win, A_REVERSE);
711 keypad(stdscr, TRUE);
714 if (key < KEY_MIN && key > 0 && isalpha(key)) {
717 for (n = 0; n < MAX_OPTIONS; ++n) {
718 if (key == command[n].text[0]) {
719 display_menu(old_option, new_option = n);
731 (*command[new_option].function) (win);
733 display_menu(old_option, new_option);
736 new_option = ((new_option == 0)
739 display_menu(old_option, new_option);
742 new_option = ((new_option == (MAX_OPTIONS - 1))
745 display_menu(old_option, new_option);
767 ExitProgram(EXIT_SUCCESS);