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.31 2002/09/14 22:45:15 tom Exp $
13 #include <test.priv.h>
17 char *XCursesProgramName = "testcurs";
20 static int initTest(WINDOW **);
21 static void display_menu(int, int);
22 static void inputTest(WINDOW *);
23 static void introTest(WINDOW *);
24 static void outputTest(WINDOW *);
25 static void padTest(WINDOW *);
26 static void scrollTest(WINDOW *);
27 #if defined(PDCURSES) && !defined(XCURSES)
28 static void resizeTest(WINDOW *);
32 NCURSES_CONST char *text;
33 void (*function) (WINDOW *);
35 typedef struct commands COMMAND;
37 const COMMAND command[] =
39 {"General Test", introTest},
40 {"Pad Test", padTest},
41 #if defined(PDCURSES) && !defined(XCURSES)
42 {"Resize Test", resizeTest},
44 {"Scroll Test", scrollTest},
45 {"Input Test", inputTest},
46 {"Output Test", outputTest}
48 #define MAX_OPTIONS SIZEOF(command)
51 #define strdup my_strdup
55 char *p = (char *) malloc(strlen(s) + 1);
60 #endif /* not HAVE_STRDUP */
67 char *argv[]GCC_UNUSED)
71 int old_option = (-1);
76 setlocale(LC_ALL, "");
79 PDC_debug("testcurs started\n");
82 ExitProgram(EXIT_FAILURE);
85 display_menu(old_option, new_option);
89 init_pair(1, COLOR_WHITE, COLOR_BLUE);
90 wbkgd(win, COLOR_PAIR(1));
92 wbkgd(win, A_REVERSE);
94 wbkgd(win, A_REVERSE);
102 if (key < KEY_MIN && key > 0 && isalpha(key)) {
105 for (n = 0; n < MAX_OPTIONS; ++n) {
106 if (key == command[n].text[0]) {
107 display_menu(old_option, new_option = n);
119 (*command[new_option].function) (win);
121 display_menu(old_option, new_option);
124 new_option = (new_option == 0) ? new_option : new_option - 1;
125 display_menu(old_option, new_option);
128 new_option = (new_option == MAX_OPTIONS - 1) ? new_option :
130 display_menu(old_option, new_option);
152 ExitProgram(EXIT_SUCCESS);
156 Continue(WINDOW *win)
158 int y1 = getmaxy(win);
159 int x1 = getmaxx(win);
160 int y0 = y1 < 10 ? y1 : 10;
164 save = mvwinch(win, y0, x1 - 1);
166 mvwaddstr(win, y0, x0, " Press any key to continue");
170 mvwaddch(win, y0, x1 - 1, save);
178 initTest(WINDOW **win)
181 PDC_debug("initTest called\n");
184 trace(TRACE_MAXIMUM);
188 PDC_debug("after initscr()\n");
195 height = 13; /* Create a drawing window */
196 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
205 introTest(WINDOW *win)
207 wmove(win, height / 2 - 5, width / 2);
208 wvline(win, ACS_VLINE, 10);
209 wmove(win, height / 2, width / 2 - 10);
210 whline(win, ACS_HLINE, 20);
216 box(win, ACS_VLINE, ACS_HLINE);
220 "You should have rectangle in the middle of the screen");
221 mvwaddstr(win, 2, 1, "You should have heard a beep");
227 scrollTest(WINDOW *win)
232 NCURSES_CONST char *Message = "The window will now scroll slowly";
237 mvwprintw(win, OldY - 2, 1, Message);
240 for (i = 1; i <= OldY; i++) {
247 for (i = 1; i < OldY; i++) {
248 mvwprintw(win, i, 1, "Line %d", i);
250 mvwprintw(win, OldY - 2, 1, "The top of the window will scroll");
252 wsetscrreg(win, 0, half - 1);
253 box(win, ACS_VLINE, ACS_HLINE);
255 for (i = 1; i <= half; i++) {
258 box(win, ACS_VLINE, ACS_HLINE);
263 for (i = 1; i < OldY; i++) {
264 mvwprintw(win, i, 1, "Line %d", i);
266 mvwprintw(win, 1, 1, "The bottom of the window will scroll");
267 wmove(win, OldY - 2, 1);
268 wsetscrreg(win, half, --OldY);
269 box(win, ACS_VLINE, ACS_HLINE);
271 for (i = half; i <= OldY; i++) {
274 box(win, ACS_VLINE, ACS_HLINE);
277 wsetscrreg(win, 0, OldY);
281 inputTest(WINDOW *win)
285 int w, h, bx, by, sw, sh, i, c, num;
291 getbegyx(win, by, bx);
294 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
299 init_pair(2, COLOR_WHITE, COLOR_RED);
300 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
302 wbkgd(subWin, A_BOLD);
304 wbkgd(subWin, A_BOLD);
306 box(subWin, ACS_VLINE, ACS_HLINE);
310 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
311 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
315 box(subWin, ACS_VLINE, ACS_HLINE);
316 for (i = 0; i < 5; i++) {
317 mvwprintw(subWin, 1, 1, "Time = %d", i);
329 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
339 mvwaddstr(win, 4, 1, "The character should now have been deleted");
343 mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
344 mvwaddstr(win, 2, 1, "Press spacebar to finish");
350 #if defined(PDCURSES)
351 mouse_set(ALL_MOUSE_EVENTS);
358 wprintw(win, "Key Pressed: %s", keyname(c));
360 wprintw(win, "Key Pressed: %c", c);
362 wprintw(win, "Key Pressed: %s", unctrl(c));
363 #if defined(PDCURSES)
364 if (c == KEY_MOUSE) {
367 if (BUTTON_CHANGED(1))
369 else if (BUTTON_CHANGED(2))
371 else if (BUTTON_CHANGED(3))
376 wprintw(win, "Button %d: ", button);
378 wprintw(win, "moved: ");
379 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
380 wprintw(win, "pressed: ");
381 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
382 wprintw(win, "double: ");
384 wprintw(win, "released: ");
385 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
397 #if defined(PDCURSES)
404 static const char *fmt[] = {
410 const char *format = fmt[repeat % SIZEOF(fmt)];
413 mvwaddstr(win, 3, 2, "The window should have moved");
415 "This text should have appeared without you pressing a key");
417 "Scanning with format \"%s\"", format);
418 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
426 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
428 "String: %s Number: %d (%d values read)",
429 buffer, num, answered);
432 } while (answered > 0);
436 outputTest(WINDOW *win)
446 "You should now have a screen in the upper left corner, and this text should have wrapped");
448 waddstr(win, "\nThis text should be down\n");
449 waddstr(win, "and broken into two here ^");
453 wattron(win, A_BOLD);
454 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
455 mvwaddstr(win, 8, 1, "Press any key to continue");
459 getbegyx(win, by, bx);
461 if (LINES < 24 || COLS < 75) {
463 "Some tests have been skipped as they require a");
464 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
467 win1 = newwin(10, 50, 14, 25);
474 init_pair(3, COLOR_BLUE, COLOR_WHITE);
475 wbkgd(win1, COLOR_PAIR(3));
477 wbkgd(win1, A_NORMAL);
479 wbkgd(win1, A_NORMAL);
482 mvwaddstr(win1, 5, 1,
483 "This text should appear; using overlay option");
484 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
486 #if defined(PDCURSES) && !defined(XCURSES)
487 box(win1, 0xb3, 0xc4);
489 box(win1, ACS_VLINE, ACS_HLINE);
496 wattron(win1, A_BLINK);
497 mvwaddstr(win1, 4, 1,
498 "This blinking text should appear in only the second window");
499 wattroff(win1, A_BLINK);
512 mvwaddstr(win, 6, 2, "This line shouldn't appear");
513 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
514 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
519 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
529 waddstr(win, "The next char should be l: ");
533 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
538 mvwaddstr(win, 5, 2, "The lines below should have moved down");
543 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
545 mvwaddstr(win, 10, 1, "Enter a string: ");
550 wscanw(win, "%s", Buffer);
552 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
553 mvaddstr(10, 1, "Enter a string: ");
557 if (tigetstr("cvvis") != 0) {
560 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
564 if (tigetstr("civis") != 0) {
568 "The cursor should have disappeared (invisible)");
572 if (tigetstr("cnorm") != 0) {
575 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
581 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
583 init_pair(1, COLOR_RED, COLOR_WHITE);
589 mvwaddstr(win, 1, 1, "Information About Your Terminal");
590 mvwaddstr(win, 3, 1, termname());
591 mvwaddstr(win, 4, 1, longname());
592 if (termattrs() & A_BLINK)
593 mvwaddstr(win, 5, 1, "This terminal supports blinking.");
595 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
597 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
600 mvwinnstr(win, 7, 5, Buffer, 18);
601 mvaddstr(LINES - 2, 10, Buffer);
606 #if defined(PDCURSES) && !defined(XCURSES)
608 resizeTest(WINDOW *dummy GCC_UNUSED)
617 resize_term(50, 120);
622 win1 = newwin(10, 50, 14, 25);
629 init_pair(3, COLOR_BLUE, COLOR_WHITE);
630 wattrset(win1, COLOR_PAIR(3));
635 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
641 mvwaddstr(win1, 1, 1, "The screen should now be reset");
653 padTest(WINDOW *dummy GCC_UNUSED)
657 pad = newpad(50, 100);
658 wattron(pad, A_REVERSE);
659 mvwaddstr(pad, 5, 2, "This is a new pad");
660 wattrset(pad, A_NORMAL);
662 "The end of this line should be truncated here:except now");
663 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
666 mvwaddstr(pad, 10, 1, " Press any key to continue");
667 prefresh(pad, 0, 0, 0, 0, 10, 45);
672 spad = subpad(pad, 12, 25, 6, 52);
673 mvwaddstr(spad, 2, 2, "This is a new subpad");
675 prefresh(pad, 0, 0, 0, 0, 15, 75);
680 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
681 mvwaddstr(pad, 40, 1, " Press any key to continue");
682 prefresh(pad, 30, 0, 0, 0, 10, 45);
691 display_menu(int old_option, int new_option)
696 mvaddstr(3, 20, "PDCurses Test Program");
698 for (i = 0; i < MAX_OPTIONS; i++)
699 mvaddstr(5 + i, 25, command[i].text);
700 if (old_option != (-1))
701 mvaddstr(5 + old_option, 25, command[old_option].text);
703 mvaddstr(5 + new_option, 25, command[new_option].text);
706 "Use Up and Down Arrows to select - Enter to run - Q to quit");