3 * This is a test program for the PDCurses screen package for IBM PC type
6 * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz)
7 * wrs(5/28/93) -- modified to be consistent (perform identically) with either
8 * PDCurses or under Unix System V, R4
10 * $Id: testcurs.c,v 1.40 2009/08/29 18:47:26 tom Exp $
13 #include <test.priv.h>
16 char *XCursesProgramName = "testcurs";
19 static int initTest(WINDOW **);
20 static void display_menu(int, int);
21 static void inputTest(WINDOW *);
22 static void introTest(WINDOW *);
23 static void outputTest(WINDOW *);
24 static void padTest(WINDOW *);
25 static void scrollTest(WINDOW *);
26 #if defined(PDCURSES) && !defined(XCURSES)
27 static void resizeTest(WINDOW *);
31 NCURSES_CONST char *text;
32 void (*function) (WINDOW *);
34 typedef struct commands COMMAND;
36 static const COMMAND command[] =
38 {"General Test", introTest},
39 {"Pad Test", padTest},
40 #if defined(PDCURSES) && !defined(XCURSES)
41 {"Resize Test", resizeTest},
43 {"Scroll Test", scrollTest},
44 {"Input Test", inputTest},
45 {"Output Test", outputTest}
47 #define MAX_OPTIONS (int) SIZEOF(command)
50 #define strdup my_strdup
54 char *p = typeMalloc(char, strlen(s) + 1);
59 #endif /* not HAVE_STRDUP */
61 static int width, height;
66 char *argv[]GCC_UNUSED)
70 int old_option = (-1);
75 setlocale(LC_ALL, "");
78 PDC_debug("testcurs started\n");
81 ExitProgram(EXIT_FAILURE);
84 display_menu(old_option, new_option);
88 init_pair(1, COLOR_WHITE, COLOR_BLUE);
89 wbkgd(win, COLOR_PAIR(1));
91 wbkgd(win, A_REVERSE);
93 wbkgd(win, A_REVERSE);
101 if (key < KEY_MIN && key > 0 && isalpha(key)) {
104 for (n = 0; n < MAX_OPTIONS; ++n) {
105 if (key == command[n].text[0]) {
106 display_menu(old_option, new_option = n);
118 (*command[new_option].function) (win);
120 display_menu(old_option, new_option);
123 new_option = ((new_option == 0)
126 display_menu(old_option, new_option);
129 new_option = ((new_option == (MAX_OPTIONS - 1))
132 display_menu(old_option, new_option);
154 ExitProgram(EXIT_SUCCESS);
158 Continue(WINDOW *win)
160 int y1 = getmaxy(win);
161 int x1 = getmaxx(win);
162 int y0 = y1 < 10 ? y1 : 10;
166 save = mvwinch(win, y0, x1 - 1);
168 mvwaddstr(win, y0, x0, " Press any key to continue");
172 mvwaddch(win, y0, x1 - 1, save);
180 initTest(WINDOW **win)
183 PDC_debug("initTest called\n");
186 trace(TRACE_MAXIMUM);
190 PDC_debug("after initscr()\n");
197 height = 13; /* Create a drawing window */
198 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
207 introTest(WINDOW *win)
209 wmove(win, height / 2 - 5, width / 2);
210 wvline(win, ACS_VLINE, 10);
211 wmove(win, height / 2, width / 2 - 10);
212 whline(win, ACS_HLINE, 20);
218 box(win, ACS_VLINE, ACS_HLINE);
222 "You should have rectangle in the middle of the screen");
223 mvwaddstr(win, 2, 1, "You should have heard a beep");
229 scrollTest(WINDOW *win)
234 NCURSES_CONST char *Message = "The window will now scroll slowly";
239 mvwprintw(win, OldY - 2, 1, Message);
242 for (i = 1; i <= OldY; i++) {
249 for (i = 1; i < OldY; i++) {
250 mvwprintw(win, i, 1, "Line %d", i);
252 mvwprintw(win, OldY - 2, 1, "The top of the window will scroll");
254 wsetscrreg(win, 0, half - 1);
255 box(win, ACS_VLINE, ACS_HLINE);
257 for (i = 1; i <= half; i++) {
260 box(win, ACS_VLINE, ACS_HLINE);
265 for (i = 1; i < OldY; i++) {
266 mvwprintw(win, i, 1, "Line %d", i);
268 mvwprintw(win, 1, 1, "The bottom of the window will scroll");
269 wmove(win, OldY - 2, 1);
270 wsetscrreg(win, half, --OldY);
271 box(win, ACS_VLINE, ACS_HLINE);
273 for (i = half; i <= OldY; i++) {
276 box(win, ACS_VLINE, ACS_HLINE);
279 wsetscrreg(win, 0, OldY);
283 inputTest(WINDOW *win)
287 int w, h, bx, by, sw, sh, i, c, num;
293 getbegyx(win, by, bx);
296 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
301 init_pair(2, COLOR_WHITE, COLOR_RED);
302 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
304 wbkgd(subWin, A_BOLD);
306 wbkgd(subWin, A_BOLD);
308 box(subWin, ACS_VLINE, ACS_HLINE);
312 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
313 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
317 box(subWin, ACS_VLINE, ACS_HLINE);
318 for (i = 0; i < 5; i++) {
319 mvwprintw(subWin, 1, 1, "Time = %d", i);
331 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
341 mvwaddstr(win, 4, 1, "The character should now have been deleted");
345 mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
346 mvwaddstr(win, 2, 1, "Press spacebar to finish");
357 #if defined(PDCURSES)
358 mouse_set(ALL_MOUSE_EVENTS);
366 wprintw(win, "Key Pressed: %s", keyname(c));
368 wprintw(win, "Key Pressed: %c", c);
370 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
371 #if defined(PDCURSES)
372 if (c == KEY_MOUSE) {
375 if (BUTTON_CHANGED(1))
377 else if (BUTTON_CHANGED(2))
379 else if (BUTTON_CHANGED(3))
384 wprintw(win, "Button %d: ", button);
386 wprintw(win, "moved: ");
387 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
388 wprintw(win, "pressed: ");
389 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
390 wprintw(win, "double: ");
392 wprintw(win, "released: ");
393 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
405 #if defined(PDCURSES)
412 static const char *fmt[] =
419 const char *format = fmt[repeat % SIZEOF(fmt)];
422 mvwaddstr(win, 3, 2, "The window should have moved");
424 "This text should have appeared without you pressing a key");
426 "Scanning with format \"%s\"", format);
427 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
435 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
437 "String: %s Number: %d (%d values read)",
438 buffer, num, answered);
441 } while (answered > 0);
445 outputTest(WINDOW *win)
454 char tc_buffer[4096];
455 char tc_parsed[4096];
456 char *area_pointer = tc_parsed;
457 tgetent(tc_buffer, getenv("TERM"));
459 #define tgetstr(a,b) 0
461 #endif /* !HAVE_TIGETSTR */
466 "You should now have a screen in the upper left corner, and this text should have wrapped");
468 waddstr(win, "\nThis text should be down\n");
469 waddstr(win, "and broken into two here ^");
473 wattron(win, A_BOLD);
474 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
475 mvwaddstr(win, 8, 1, "Press any key to continue");
479 getbegyx(win, by, bx);
481 if (LINES < 24 || COLS < 75) {
483 "Some tests have been skipped as they require a");
484 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
487 win1 = newwin(10, 50, 14, 25);
494 init_pair(3, COLOR_BLUE, COLOR_WHITE);
495 wbkgd(win1, COLOR_PAIR(3));
497 wbkgd(win1, A_NORMAL);
499 wbkgd(win1, A_NORMAL);
502 mvwaddstr(win1, 5, 1,
503 "This text should appear; using overlay option");
504 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
506 #if defined(PDCURSES) && !defined(XCURSES)
507 box(win1, 0xb3, 0xc4);
509 box(win1, ACS_VLINE, ACS_HLINE);
516 wattron(win1, A_BLINK);
517 mvwaddstr(win1, 4, 1,
518 "This blinking text should appear in only the second window");
519 wattroff(win1, A_BLINK);
532 mvwaddstr(win, 6, 2, "This line shouldn't appear");
533 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
534 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
539 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
549 waddstr(win, "The next char should be l: ");
554 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
560 mvwaddstr(win, 5, 2, "The lines below should have moved down");
565 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
567 mvwaddstr(win, 10, 1, "Enter a string: ");
572 wscanw(win, "%s", Buffer);
574 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
575 mvaddstr(10, 1, "Enter a string: ");
579 if (TIGETSTR("cvvis", "vs") != 0) {
582 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
586 if (TIGETSTR("civis", "vi") != 0) {
590 "The cursor should have disappeared (invisible)");
594 if (TIGETSTR("cnorm", "ve") != 0) {
597 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
603 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
605 init_pair(1, COLOR_RED, COLOR_WHITE);
613 mvwaddstr(win, 1, 1, "Information About Your Terminal");
614 mvwaddstr(win, 3, 1, termname());
615 mvwaddstr(win, 4, 1, longname());
616 if (termattrs() & A_BLINK)
617 mvwaddstr(win, 5, 1, "This terminal supports blinking.");
619 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
622 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
625 mvwinnstr(win, 7, 5, Buffer, 18);
626 mvaddstr(LINES - 2, 10, Buffer);
631 #if defined(PDCURSES) && !defined(XCURSES)
633 resizeTest(WINDOW *dummy GCC_UNUSED)
642 resize_term(50, 120);
647 win1 = newwin(10, 50, 14, 25);
654 init_pair(3, COLOR_BLUE, COLOR_WHITE);
655 wattrset(win1, COLOR_PAIR(3));
660 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
666 mvwaddstr(win1, 1, 1, "The screen should now be reset");
678 padTest(WINDOW *dummy GCC_UNUSED)
682 if ((pad = newpad(50, 100)) != 0) {
683 wattron(pad, A_REVERSE);
684 mvwaddstr(pad, 5, 2, "This is a new pad");
685 (void) wattrset(pad, A_NORMAL);
687 "The end of this line should be truncated here:except now");
688 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
691 mvwaddstr(pad, 10, 1, " Press any key to continue");
692 prefresh(pad, 0, 0, 0, 0, 10, 45);
697 spad = subpad(pad, 12, 25, 6, 52);
698 mvwaddstr(spad, 2, 2, "This is a new subpad");
700 prefresh(pad, 0, 0, 0, 0, 15, 75);
705 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
706 mvwaddstr(pad, 40, 1, " Press any key to continue");
707 prefresh(pad, 30, 0, 0, 0, 10, 45);
717 display_menu(int old_option, int new_option)
721 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
723 (void) attrset(A_NORMAL);
724 mvaddstr(3, 20, "PDCurses Test Program");
726 for (i = 0; i < (int) MAX_OPTIONS; i++)
727 mvaddstr(5 + i, 25, command[i].text);
729 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
730 mvaddstr(5 + old_option, 25, command[old_option].text);
732 (void) attrset(A_REVERSE);
733 mvaddstr(5 + new_option, 25, command[new_option].text);
734 (void) attrset(A_NORMAL);
736 "Use Up and Down Arrows to select - Enter to run - Q to quit");