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.32 2002/10/19 22:11:24 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 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 */
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");
349 #if defined(PDCURSES)
350 mouse_set(ALL_MOUSE_EVENTS);
357 wprintw(win, "Key Pressed: %s", keyname(c));
359 wprintw(win, "Key Pressed: %c", c);
361 wprintw(win, "Key Pressed: %s", unctrl(c));
362 #if defined(PDCURSES)
363 if (c == KEY_MOUSE) {
366 if (BUTTON_CHANGED(1))
368 else if (BUTTON_CHANGED(2))
370 else if (BUTTON_CHANGED(3))
375 wprintw(win, "Button %d: ", button);
377 wprintw(win, "moved: ");
378 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
379 wprintw(win, "pressed: ");
380 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
381 wprintw(win, "double: ");
383 wprintw(win, "released: ");
384 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
396 #if defined(PDCURSES)
403 static const char *fmt[] = {
409 const char *format = fmt[repeat % SIZEOF(fmt)];
412 mvwaddstr(win, 3, 2, "The window should have moved");
414 "This text should have appeared without you pressing a key");
416 "Scanning with format \"%s\"", format);
417 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
425 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
427 "String: %s Number: %d (%d values read)",
428 buffer, num, answered);
431 } while (answered > 0);
435 outputTest(WINDOW *win)
445 "You should now have a screen in the upper left corner, and this text should have wrapped");
447 waddstr(win, "\nThis text should be down\n");
448 waddstr(win, "and broken into two here ^");
452 wattron(win, A_BOLD);
453 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
454 mvwaddstr(win, 8, 1, "Press any key to continue");
458 getbegyx(win, by, bx);
460 if (LINES < 24 || COLS < 75) {
462 "Some tests have been skipped as they require a");
463 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
466 win1 = newwin(10, 50, 14, 25);
473 init_pair(3, COLOR_BLUE, COLOR_WHITE);
474 wbkgd(win1, COLOR_PAIR(3));
476 wbkgd(win1, A_NORMAL);
478 wbkgd(win1, A_NORMAL);
481 mvwaddstr(win1, 5, 1,
482 "This text should appear; using overlay option");
483 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
485 #if defined(PDCURSES) && !defined(XCURSES)
486 box(win1, 0xb3, 0xc4);
488 box(win1, ACS_VLINE, ACS_HLINE);
495 wattron(win1, A_BLINK);
496 mvwaddstr(win1, 4, 1,
497 "This blinking text should appear in only the second window");
498 wattroff(win1, A_BLINK);
511 mvwaddstr(win, 6, 2, "This line shouldn't appear");
512 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
513 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
518 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
528 waddstr(win, "The next char should be l: ");
532 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
537 mvwaddstr(win, 5, 2, "The lines below should have moved down");
542 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
544 mvwaddstr(win, 10, 1, "Enter a string: ");
549 wscanw(win, "%s", Buffer);
551 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
552 mvaddstr(10, 1, "Enter a string: ");
556 if (tigetstr("cvvis") != 0) {
559 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
563 if (tigetstr("civis") != 0) {
567 "The cursor should have disappeared (invisible)");
571 if (tigetstr("cnorm") != 0) {
574 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
580 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
582 init_pair(1, COLOR_RED, COLOR_WHITE);
588 mvwaddstr(win, 1, 1, "Information About Your Terminal");
589 mvwaddstr(win, 3, 1, termname());
590 mvwaddstr(win, 4, 1, longname());
591 if (termattrs() & A_BLINK)
592 mvwaddstr(win, 5, 1, "This terminal supports blinking.");
594 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
596 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
599 mvwinnstr(win, 7, 5, Buffer, 18);
600 mvaddstr(LINES - 2, 10, Buffer);
605 #if defined(PDCURSES) && !defined(XCURSES)
607 resizeTest(WINDOW *dummy GCC_UNUSED)
616 resize_term(50, 120);
621 win1 = newwin(10, 50, 14, 25);
628 init_pair(3, COLOR_BLUE, COLOR_WHITE);
629 wattrset(win1, COLOR_PAIR(3));
634 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
640 mvwaddstr(win1, 1, 1, "The screen should now be reset");
652 padTest(WINDOW *dummy GCC_UNUSED)
656 pad = newpad(50, 100);
657 wattron(pad, A_REVERSE);
658 mvwaddstr(pad, 5, 2, "This is a new pad");
659 wattrset(pad, A_NORMAL);
661 "The end of this line should be truncated here:except now");
662 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
665 mvwaddstr(pad, 10, 1, " Press any key to continue");
666 prefresh(pad, 0, 0, 0, 0, 10, 45);
671 spad = subpad(pad, 12, 25, 6, 52);
672 mvwaddstr(spad, 2, 2, "This is a new subpad");
674 prefresh(pad, 0, 0, 0, 0, 15, 75);
679 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
680 mvwaddstr(pad, 40, 1, " Press any key to continue");
681 prefresh(pad, 30, 0, 0, 0, 10, 45);
690 display_menu(int old_option, int new_option)
695 mvaddstr(3, 20, "PDCurses Test Program");
697 for (i = 0; i < MAX_OPTIONS; i++)
698 mvaddstr(5 + i, 25, command[i].text);
699 if (old_option != (-1))
700 mvaddstr(5 + old_option, 25, command[old_option].text);
702 mvaddstr(5 + new_option, 25, command[new_option].text);
705 "Use Up and Down Arrows to select - Enter to run - Q to quit");