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.37 2005/12/31 20:23:09 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 SIZEOF(command)
50 #define strdup my_strdup
54 char *p = (char *) malloc(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) ? new_option : new_option - 1;
124 display_menu(old_option, new_option);
127 new_option = (new_option == MAX_OPTIONS - 1) ? new_option :
129 display_menu(old_option, new_option);
151 ExitProgram(EXIT_SUCCESS);
155 Continue(WINDOW *win)
157 int y1 = getmaxy(win);
158 int x1 = getmaxx(win);
159 int y0 = y1 < 10 ? y1 : 10;
163 save = mvwinch(win, y0, x1 - 1);
165 mvwaddstr(win, y0, x0, " Press any key to continue");
169 mvwaddch(win, y0, x1 - 1, save);
177 initTest(WINDOW **win)
180 PDC_debug("initTest called\n");
183 trace(TRACE_MAXIMUM);
187 PDC_debug("after initscr()\n");
194 height = 13; /* Create a drawing window */
195 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
204 introTest(WINDOW *win)
206 wmove(win, height / 2 - 5, width / 2);
207 wvline(win, ACS_VLINE, 10);
208 wmove(win, height / 2, width / 2 - 10);
209 whline(win, ACS_HLINE, 20);
215 box(win, ACS_VLINE, ACS_HLINE);
219 "You should have rectangle in the middle of the screen");
220 mvwaddstr(win, 2, 1, "You should have heard a beep");
226 scrollTest(WINDOW *win)
231 NCURSES_CONST char *Message = "The window will now scroll slowly";
236 mvwprintw(win, OldY - 2, 1, Message);
239 for (i = 1; i <= OldY; i++) {
246 for (i = 1; i < OldY; i++) {
247 mvwprintw(win, i, 1, "Line %d", i);
249 mvwprintw(win, OldY - 2, 1, "The top of the window will scroll");
251 wsetscrreg(win, 0, half - 1);
252 box(win, ACS_VLINE, ACS_HLINE);
254 for (i = 1; i <= half; i++) {
257 box(win, ACS_VLINE, ACS_HLINE);
262 for (i = 1; i < OldY; i++) {
263 mvwprintw(win, i, 1, "Line %d", i);
265 mvwprintw(win, 1, 1, "The bottom of the window will scroll");
266 wmove(win, OldY - 2, 1);
267 wsetscrreg(win, half, --OldY);
268 box(win, ACS_VLINE, ACS_HLINE);
270 for (i = half; i <= OldY; i++) {
273 box(win, ACS_VLINE, ACS_HLINE);
276 wsetscrreg(win, 0, OldY);
280 inputTest(WINDOW *win)
284 int w, h, bx, by, sw, sh, i, c, num;
290 getbegyx(win, by, bx);
293 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
298 init_pair(2, COLOR_WHITE, COLOR_RED);
299 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
301 wbkgd(subWin, A_BOLD);
303 wbkgd(subWin, A_BOLD);
305 box(subWin, ACS_VLINE, ACS_HLINE);
309 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
310 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
314 box(subWin, ACS_VLINE, ACS_HLINE);
315 for (i = 0; i < 5; i++) {
316 mvwprintw(subWin, 1, 1, "Time = %d", i);
328 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
338 mvwaddstr(win, 4, 1, "The character should now have been deleted");
342 mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
343 mvwaddstr(win, 2, 1, "Press spacebar to finish");
354 #if defined(PDCURSES)
355 mouse_set(ALL_MOUSE_EVENTS);
363 wprintw(win, "Key Pressed: %s", keyname(c));
365 wprintw(win, "Key Pressed: %c", c);
367 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
368 #if defined(PDCURSES)
369 if (c == KEY_MOUSE) {
372 if (BUTTON_CHANGED(1))
374 else if (BUTTON_CHANGED(2))
376 else if (BUTTON_CHANGED(3))
381 wprintw(win, "Button %d: ", button);
383 wprintw(win, "moved: ");
384 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
385 wprintw(win, "pressed: ");
386 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
387 wprintw(win, "double: ");
389 wprintw(win, "released: ");
390 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
402 #if defined(PDCURSES)
409 static const char *fmt[] =
416 const char *format = fmt[repeat % SIZEOF(fmt)];
419 mvwaddstr(win, 3, 2, "The window should have moved");
421 "This text should have appeared without you pressing a key");
423 "Scanning with format \"%s\"", format);
424 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
432 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
434 "String: %s Number: %d (%d values read)",
435 buffer, num, answered);
438 } while (answered > 0);
442 outputTest(WINDOW *win)
451 char tc_buffer[4096];
452 char tc_parsed[4096];
453 char *area_pointer = tc_parsed;
454 tgetent(tc_buffer, getenv("TERM"));
456 #define tgetstr(a,b) 0
458 #endif /* !HAVE_TIGETSTR */
463 "You should now have a screen in the upper left corner, and this text should have wrapped");
465 waddstr(win, "\nThis text should be down\n");
466 waddstr(win, "and broken into two here ^");
470 wattron(win, A_BOLD);
471 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
472 mvwaddstr(win, 8, 1, "Press any key to continue");
476 getbegyx(win, by, bx);
478 if (LINES < 24 || COLS < 75) {
480 "Some tests have been skipped as they require a");
481 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
484 win1 = newwin(10, 50, 14, 25);
491 init_pair(3, COLOR_BLUE, COLOR_WHITE);
492 wbkgd(win1, COLOR_PAIR(3));
494 wbkgd(win1, A_NORMAL);
496 wbkgd(win1, A_NORMAL);
499 mvwaddstr(win1, 5, 1,
500 "This text should appear; using overlay option");
501 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
503 #if defined(PDCURSES) && !defined(XCURSES)
504 box(win1, 0xb3, 0xc4);
506 box(win1, ACS_VLINE, ACS_HLINE);
513 wattron(win1, A_BLINK);
514 mvwaddstr(win1, 4, 1,
515 "This blinking text should appear in only the second window");
516 wattroff(win1, A_BLINK);
529 mvwaddstr(win, 6, 2, "This line shouldn't appear");
530 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
531 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
536 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
546 waddstr(win, "The next char should be l: ");
551 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
557 mvwaddstr(win, 5, 2, "The lines below should have moved down");
562 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
564 mvwaddstr(win, 10, 1, "Enter a string: ");
569 wscanw(win, "%s", Buffer);
571 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
572 mvaddstr(10, 1, "Enter a string: ");
576 if (TIGETSTR("cvvis", "vs") != 0) {
579 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
583 if (TIGETSTR("civis", "vi") != 0) {
587 "The cursor should have disappeared (invisible)");
591 if (TIGETSTR("cnorm", "ve") != 0) {
594 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
600 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
602 init_pair(1, COLOR_RED, COLOR_WHITE);
610 mvwaddstr(win, 1, 1, "Information About Your Terminal");
611 mvwaddstr(win, 3, 1, termname());
612 mvwaddstr(win, 4, 1, longname());
613 if (termattrs() & A_BLINK)
614 mvwaddstr(win, 5, 1, "This terminal supports blinking.");
616 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
619 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
622 mvwinnstr(win, 7, 5, Buffer, 18);
623 mvaddstr(LINES - 2, 10, Buffer);
628 #if defined(PDCURSES) && !defined(XCURSES)
630 resizeTest(WINDOW *dummy GCC_UNUSED)
639 resize_term(50, 120);
644 win1 = newwin(10, 50, 14, 25);
651 init_pair(3, COLOR_BLUE, COLOR_WHITE);
652 wattrset(win1, COLOR_PAIR(3));
657 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
663 mvwaddstr(win1, 1, 1, "The screen should now be reset");
675 padTest(WINDOW *dummy GCC_UNUSED)
679 pad = newpad(50, 100);
680 wattron(pad, A_REVERSE);
681 mvwaddstr(pad, 5, 2, "This is a new pad");
682 wattrset(pad, A_NORMAL);
684 "The end of this line should be truncated here:except now");
685 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
688 mvwaddstr(pad, 10, 1, " Press any key to continue");
689 prefresh(pad, 0, 0, 0, 0, 10, 45);
694 spad = subpad(pad, 12, 25, 6, 52);
695 mvwaddstr(spad, 2, 2, "This is a new subpad");
697 prefresh(pad, 0, 0, 0, 0, 15, 75);
702 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
703 mvwaddstr(pad, 40, 1, " Press any key to continue");
704 prefresh(pad, 30, 0, 0, 0, 10, 45);
713 display_menu(int old_option, int new_option)
718 mvaddstr(3, 20, "PDCurses Test Program");
720 for (i = 0; i < (int) MAX_OPTIONS; i++)
721 mvaddstr(5 + i, 25, command[i].text);
722 if (old_option != (-1))
723 mvaddstr(5 + old_option, 25, command[old_option].text);
725 mvaddstr(5 + new_option, 25, command[new_option].text);
728 "Use Up and Down Arrows to select - Enter to run - Q to quit");