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.50 2015/07/05 00:11:10 tom Exp $
12 #include <test.priv.h>
15 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 *);
23 static void padTest(WINDOW *);
24 static void scrollTest(WINDOW *);
25 #if defined(PDCURSES) && !defined(XCURSES)
26 static void resizeTest(WINDOW *);
30 NCURSES_CONST char *text;
31 void (*function) (WINDOW *);
33 typedef struct commands COMMAND;
35 static const COMMAND command[] =
37 {"General Test", introTest},
38 {"Pad Test", padTest},
39 #if defined(PDCURSES) && !defined(XCURSES)
40 {"Resize Test", resizeTest},
42 {"Scroll Test", scrollTest},
43 {"Input Test", inputTest},
44 {"Output Test", outputTest}
46 #define MAX_OPTIONS (int) SIZEOF(command)
48 static int width, height;
53 char *argv[]GCC_UNUSED)
57 int old_option = (-1);
62 setlocale(LC_ALL, "");
65 PDC_debug("testcurs started\n");
68 ExitProgram(EXIT_FAILURE);
71 display_menu(old_option, new_option);
75 init_pair(1, COLOR_WHITE, COLOR_BLUE);
76 wbkgd(win, (chtype) COLOR_PAIR(1));
78 wbkgd(win, A_REVERSE);
80 wbkgd(win, A_REVERSE);
88 if (key < KEY_MIN && key > 0 && isalpha(key)) {
91 for (n = 0; n < MAX_OPTIONS; ++n) {
92 if (key == command[n].text[0]) {
93 display_menu(old_option, new_option = n);
105 (*command[new_option].function) (win);
107 display_menu(old_option, new_option);
110 new_option = ((new_option == 0)
113 display_menu(old_option, new_option);
116 new_option = ((new_option == (MAX_OPTIONS - 1))
119 display_menu(old_option, new_option);
141 ExitProgram(EXIT_SUCCESS);
145 Continue(WINDOW *win)
147 int y1 = getmaxy(win);
148 int x1 = getmaxx(win);
149 int y0 = y1 < 10 ? y1 : 10;
153 save = mvwinch(win, y0, x1 - 1);
155 MvWAddStr(win, y0, x0, " Press any key to continue");
159 MvWAddCh(win, y0, x1 - 1, save);
167 initTest(WINDOW **win)
170 PDC_debug("initTest called\n");
173 trace(TRACE_MAXIMUM);
177 PDC_debug("after initscr()\n");
184 height = 13; /* Create a drawing window */
185 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
194 introTest(WINDOW *win)
196 wmove(win, height / 2 - 5, width / 2);
197 wvline(win, ACS_VLINE, 10);
198 wmove(win, height / 2, width / 2 - 10);
199 whline(win, ACS_HLINE, 20);
205 box(win, ACS_VLINE, ACS_HLINE);
209 "You should have rectangle in the middle of the screen");
210 MvWAddStr(win, 2, 1, "You should have heard a beep");
216 scrollTest(WINDOW *win)
221 NCURSES_CONST char *Message = "The window will now scroll slowly";
226 MvWAddStr(win, OldY - 2, 1, Message);
229 for (i = 1; i <= OldY; i++) {
236 for (i = 1; i < OldY; i++) {
237 MvWPrintw(win, i, 1, "Line %d", i);
239 MvWPrintw(win, OldY - 2, 1, "The top of the window will scroll");
241 wsetscrreg(win, 0, half - 1);
242 box(win, ACS_VLINE, ACS_HLINE);
244 for (i = 1; i <= half; i++) {
247 box(win, ACS_VLINE, ACS_HLINE);
252 for (i = 1; i < OldY; i++) {
253 MvWPrintw(win, i, 1, "Line %d", i);
255 MvWPrintw(win, 1, 1, "The bottom of the window will scroll");
256 wmove(win, OldY - 2, 1);
257 wsetscrreg(win, half, --OldY);
258 box(win, ACS_VLINE, ACS_HLINE);
260 for (i = half; i <= OldY; i++) {
263 box(win, ACS_VLINE, ACS_HLINE);
266 wsetscrreg(win, 0, OldY);
270 inputTest(WINDOW *win)
274 int w, h, bx, by, sw, sh, i, c, num;
280 getbegyx(win, by, bx);
283 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
288 init_pair(2, COLOR_WHITE, COLOR_RED);
289 wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD);
291 wbkgd(subWin, A_BOLD);
293 wbkgd(subWin, A_BOLD);
295 box(subWin, ACS_VLINE, ACS_HLINE);
299 MvWAddStr(win, 2, 1, "Press some keys for 5 seconds");
300 MvWAddStr(win, 1, 1, "Pressing ^C should do nothing");
304 box(subWin, ACS_VLINE, ACS_HLINE);
305 for (i = 0; i < 5; i++) {
306 MvWPrintw(subWin, 1, 1, "Time = %d", i);
318 MvWAddStr(win, 2, 1, "Press a key, followed by ENTER");
328 MvWAddStr(win, 4, 1, "The character should now have been deleted");
332 MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
333 MvWAddStr(win, 2, 1, "Press spacebar to finish");
344 #ifdef NCURSES_MOUSE_VERSION
345 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
347 #if defined(PDCURSES)
348 mouse_set(ALL_MOUSE_EVENTS);
356 wprintw(win, "Key Pressed: %s", keyname(c));
358 wprintw(win, "Key Pressed: %c", c);
360 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
362 if (c == KEY_MOUSE) {
363 #if defined(NCURSES_MOUSE_VERSION)
364 #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037))
365 #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED))
366 #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED))
367 #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED))
368 #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED))
373 if (ButtonChanged(1))
375 else if (ButtonChanged(2))
377 else if (ButtonChanged(3))
382 wprintw(win, "Button %d: ", button);
383 if (ButtonPressed(button))
384 wprintw(win, "pressed: ");
385 else if (ButtonDouble(button))
386 wprintw(win, "double: ");
387 else if (ButtonTriple(button))
388 wprintw(win, "triple: ");
390 wprintw(win, "released: ");
391 wprintw(win, " Position: Y: %d X: %d", event.y, event.x);
392 #elif defined(PDCURSES)
395 if (BUTTON_CHANGED(1))
397 else if (BUTTON_CHANGED(2))
399 else if (BUTTON_CHANGED(3))
404 wprintw(win, "Button %d: ", button);
406 wprintw(win, "moved: ");
407 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
408 wprintw(win, "pressed: ");
409 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
410 wprintw(win, "double: ");
412 wprintw(win, "released: ");
413 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
414 #endif /* NCURSES_VERSION vs PDCURSES */
416 #endif /* KEY_MOUSE */
426 #if defined(PDCURSES)
433 static const char *fmt[] =
440 char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]);
443 MvWAddStr(win, 3, 2, "The window should have moved");
445 "This text should have appeared without you pressing a key");
447 "Scanning with format \"%s\"", format);
448 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
456 answered = mvwscanw(win, 7, 6, format, &num, buffer);
458 "String: %s Number: %d (%d values read)",
459 buffer, num, answered);
463 } while (answered > 0);
467 outputTest(WINDOW *win)
476 char tc_buffer[4096];
477 char tc_parsed[4096];
478 char *area_pointer = tc_parsed;
479 tgetent(tc_buffer, getenv("TERM"));
481 #define tgetstr(a,b) 0
483 #endif /* !HAVE_TIGETSTR */
488 "You should now have a screen in the upper left corner, and this text should have wrapped");
490 waddstr(win, "\nThis text should be down\n");
491 waddstr(win, "and broken into two here ^");
495 wattron(win, A_BOLD);
496 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
497 MvWAddStr(win, 8, 1, "Press any key to continue");
501 getbegyx(win, by, bx);
503 if (LINES < 24 || COLS < 75) {
505 "Some tests have been skipped as they require a");
506 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
509 win1 = newwin(10, 50, 14, 25);
516 init_pair(3, COLOR_BLUE, COLOR_WHITE);
517 wbkgd(win1, (chtype) COLOR_PAIR(3));
519 wbkgd(win1, A_NORMAL);
521 wbkgd(win1, A_NORMAL);
524 MvWAddStr(win1, 5, 1,
525 "This text should appear; using overlay option");
526 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
528 #if defined(PDCURSES) && !defined(XCURSES)
529 box(win1, 0xb3, 0xc4);
531 box(win1, ACS_VLINE, ACS_HLINE);
538 wattron(win1, A_BLINK);
539 MvWAddStr(win1, 4, 1,
540 "This blinking text should appear in only the second window");
541 wattroff(win1, A_BLINK);
554 MvWAddStr(win, 6, 2, "This line shouldn't appear");
555 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
556 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
561 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
571 waddstr(win, "The next char should be l: ");
576 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
582 MvWAddStr(win, 5, 2, "The lines below should have moved down");
587 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
589 MvWAddStr(win, 10, 1, "Enter a string: ");
594 wscanw(win, "%s", Buffer);
596 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
597 MvAddStr(10, 1, "Enter a string: ");
601 if (TIGETSTR("cvvis", "vs") != 0) {
604 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
608 if (TIGETSTR("civis", "vi") != 0) {
612 "The cursor should have disappeared (invisible)");
616 if (TIGETSTR("cnorm", "ve") != 0) {
619 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
625 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
627 init_pair(1, COLOR_RED, COLOR_WHITE);
635 MvWAddStr(win, 1, 1, "Information About Your Terminal");
636 MvWAddStr(win, 3, 1, termname());
637 MvWAddStr(win, 4, 1, longname());
638 if (termattrs() & A_BLINK)
639 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
641 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
644 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
647 (void) mvwinnstr(win, 7, 5, Buffer, 18);
648 MvAddStr(LINES - 2, 10, Buffer);
653 #if defined(PDCURSES) && !defined(XCURSES)
655 resizeTest(WINDOW *dummy GCC_UNUSED)
664 resize_term(50, 120);
669 win1 = newwin(10, 50, 14, 25);
676 init_pair(3, COLOR_BLUE, COLOR_WHITE);
677 wattrset(win1, COLOR_PAIR(3));
682 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
688 MvWAddStr(win1, 1, 1, "The screen should now be reset");
700 padTest(WINDOW *dummy GCC_UNUSED)
704 if ((pad = newpad(50, 100)) != 0) {
705 wattron(pad, A_REVERSE);
706 MvWAddStr(pad, 5, 2, "This is a new pad");
707 (void) wattrset(pad, A_NORMAL);
709 "The end of this line should be truncated here:except now");
710 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
713 MvWAddStr(pad, 10, 1, " Press any key to continue");
714 prefresh(pad, 0, 0, 0, 0, 10, 45);
719 if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) {
720 MvWAddStr(spad, 2, 2, "This is a new subpad");
724 prefresh(pad, 0, 0, 0, 0, 15, 75);
729 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
730 MvWAddStr(pad, 40, 1, " Press any key to continue");
731 prefresh(pad, 30, 0, 0, 0, 10, 45);
741 display_menu(int old_option, int new_option)
745 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
747 (void) attrset(A_NORMAL);
748 MvAddStr(3, 20, "PDCurses Test Program");
750 for (i = 0; i < (int) MAX_OPTIONS; i++)
751 MvAddStr(5 + i, 25, command[i].text);
753 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
754 MvAddStr(5 + old_option, 25, command[old_option].text);
756 (void) attrset(A_REVERSE);
757 MvAddStr(5 + new_option, 25, command[new_option].text);
758 (void) attrset(A_NORMAL);
760 "Use Up and Down Arrows to select - Enter to run - Q to quit");