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.44 2012/06/09 19:10:45 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)
49 #define strdup my_strdup
53 char *p = typeMalloc(char, strlen(s) + 1);
58 #endif /* not HAVE_STRDUP */
60 static int width, height;
65 char *argv[]GCC_UNUSED)
69 int old_option = (-1);
74 setlocale(LC_ALL, "");
77 PDC_debug("testcurs started\n");
80 ExitProgram(EXIT_FAILURE);
83 display_menu(old_option, new_option);
87 init_pair(1, COLOR_WHITE, COLOR_BLUE);
88 wbkgd(win, (chtype) COLOR_PAIR(1));
90 wbkgd(win, A_REVERSE);
92 wbkgd(win, A_REVERSE);
100 if (key < KEY_MIN && key > 0 && isalpha(key)) {
103 for (n = 0; n < MAX_OPTIONS; ++n) {
104 if (key == command[n].text[0]) {
105 display_menu(old_option, new_option = n);
117 (*command[new_option].function) (win);
119 display_menu(old_option, new_option);
122 new_option = ((new_option == 0)
125 display_menu(old_option, new_option);
128 new_option = ((new_option == (MAX_OPTIONS - 1))
131 display_menu(old_option, new_option);
153 ExitProgram(EXIT_SUCCESS);
157 Continue(WINDOW *win)
159 int y1 = getmaxy(win);
160 int x1 = getmaxx(win);
161 int y0 = y1 < 10 ? y1 : 10;
165 save = mvwinch(win, y0, x1 - 1);
167 MvWAddStr(win, y0, x0, " Press any key to continue");
171 MvWAddCh(win, y0, x1 - 1, save);
179 initTest(WINDOW **win)
182 PDC_debug("initTest called\n");
185 trace(TRACE_MAXIMUM);
189 PDC_debug("after initscr()\n");
196 height = 13; /* Create a drawing window */
197 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
206 introTest(WINDOW *win)
208 wmove(win, height / 2 - 5, width / 2);
209 wvline(win, ACS_VLINE, 10);
210 wmove(win, height / 2, width / 2 - 10);
211 whline(win, ACS_HLINE, 20);
217 box(win, ACS_VLINE, ACS_HLINE);
221 "You should have rectangle in the middle of the screen");
222 MvWAddStr(win, 2, 1, "You should have heard a beep");
228 scrollTest(WINDOW *win)
233 NCURSES_CONST char *Message = "The window will now scroll slowly";
238 MvWAddStr(win, OldY - 2, 1, Message);
241 for (i = 1; i <= OldY; i++) {
248 for (i = 1; i < OldY; i++) {
249 MvWPrintw(win, i, 1, "Line %d", i);
251 MvWPrintw(win, OldY - 2, 1, "The top of the window will scroll");
253 wsetscrreg(win, 0, half - 1);
254 box(win, ACS_VLINE, ACS_HLINE);
256 for (i = 1; i <= half; i++) {
259 box(win, ACS_VLINE, ACS_HLINE);
264 for (i = 1; i < OldY; i++) {
265 MvWPrintw(win, i, 1, "Line %d", i);
267 MvWPrintw(win, 1, 1, "The bottom of the window will scroll");
268 wmove(win, OldY - 2, 1);
269 wsetscrreg(win, half, --OldY);
270 box(win, ACS_VLINE, ACS_HLINE);
272 for (i = half; i <= OldY; i++) {
275 box(win, ACS_VLINE, ACS_HLINE);
278 wsetscrreg(win, 0, OldY);
282 inputTest(WINDOW *win)
286 int w, h, bx, by, sw, sh, i, c, num;
292 getbegyx(win, by, bx);
295 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
300 init_pair(2, COLOR_WHITE, COLOR_RED);
301 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
303 wbkgd(subWin, A_BOLD);
305 wbkgd(subWin, A_BOLD);
307 box(subWin, ACS_VLINE, ACS_HLINE);
311 MvWAddStr(win, 2, 1, "Press some keys for 5 seconds");
312 MvWAddStr(win, 1, 1, "Pressing ^C should do nothing");
316 box(subWin, ACS_VLINE, ACS_HLINE);
317 for (i = 0; i < 5; i++) {
318 MvWPrintw(subWin, 1, 1, "Time = %d", i);
330 MvWAddStr(win, 2, 1, "Press a key, followed by ENTER");
340 MvWAddStr(win, 4, 1, "The character should now have been deleted");
344 MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
345 MvWAddStr(win, 2, 1, "Press spacebar to finish");
356 #if defined(PDCURSES)
357 mouse_set(ALL_MOUSE_EVENTS);
365 wprintw(win, "Key Pressed: %s", keyname(c));
367 wprintw(win, "Key Pressed: %c", c);
369 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
370 #if defined(PDCURSES)
371 if (c == KEY_MOUSE) {
374 if (BUTTON_CHANGED(1))
376 else if (BUTTON_CHANGED(2))
378 else if (BUTTON_CHANGED(3))
383 wprintw(win, "Button %d: ", button);
385 wprintw(win, "moved: ");
386 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
387 wprintw(win, "pressed: ");
388 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
389 wprintw(win, "double: ");
391 wprintw(win, "released: ");
392 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
404 #if defined(PDCURSES)
411 static const char *fmt[] =
418 const char *format = fmt[(unsigned) repeat % SIZEOF(fmt)];
421 MvWAddStr(win, 3, 2, "The window should have moved");
423 "This text should have appeared without you pressing a key");
425 "Scanning with format \"%s\"", format);
426 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
434 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
436 "String: %s Number: %d (%d values read)",
437 buffer, num, answered);
440 } while (answered > 0);
444 outputTest(WINDOW *win)
453 char tc_buffer[4096];
454 char tc_parsed[4096];
455 char *area_pointer = tc_parsed;
456 tgetent(tc_buffer, getenv("TERM"));
458 #define tgetstr(a,b) 0
460 #endif /* !HAVE_TIGETSTR */
465 "You should now have a screen in the upper left corner, and this text should have wrapped");
467 waddstr(win, "\nThis text should be down\n");
468 waddstr(win, "and broken into two here ^");
472 wattron(win, A_BOLD);
473 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
474 MvWAddStr(win, 8, 1, "Press any key to continue");
478 getbegyx(win, by, bx);
480 if (LINES < 24 || COLS < 75) {
482 "Some tests have been skipped as they require a");
483 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
486 win1 = newwin(10, 50, 14, 25);
493 init_pair(3, COLOR_BLUE, COLOR_WHITE);
494 wbkgd(win1, (chtype) COLOR_PAIR(3));
496 wbkgd(win1, A_NORMAL);
498 wbkgd(win1, A_NORMAL);
501 MvWAddStr(win1, 5, 1,
502 "This text should appear; using overlay option");
503 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
505 #if defined(PDCURSES) && !defined(XCURSES)
506 box(win1, 0xb3, 0xc4);
508 box(win1, ACS_VLINE, ACS_HLINE);
515 wattron(win1, A_BLINK);
516 MvWAddStr(win1, 4, 1,
517 "This blinking text should appear in only the second window");
518 wattroff(win1, A_BLINK);
531 MvWAddStr(win, 6, 2, "This line shouldn't appear");
532 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
533 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
538 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
548 waddstr(win, "The next char should be l: ");
553 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
559 MvWAddStr(win, 5, 2, "The lines below should have moved down");
564 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
566 MvWAddStr(win, 10, 1, "Enter a string: ");
571 wscanw(win, "%s", Buffer);
573 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
574 MvAddStr(10, 1, "Enter a string: ");
578 if (TIGETSTR("cvvis", "vs") != 0) {
581 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
585 if (TIGETSTR("civis", "vi") != 0) {
589 "The cursor should have disappeared (invisible)");
593 if (TIGETSTR("cnorm", "ve") != 0) {
596 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
602 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
604 init_pair(1, COLOR_RED, COLOR_WHITE);
612 MvWAddStr(win, 1, 1, "Information About Your Terminal");
613 MvWAddStr(win, 3, 1, termname());
614 MvWAddStr(win, 4, 1, longname());
615 if (termattrs() & A_BLINK)
616 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
618 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
621 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
624 (void) mvwinnstr(win, 7, 5, Buffer, 18);
625 MvAddStr(LINES - 2, 10, Buffer);
630 #if defined(PDCURSES) && !defined(XCURSES)
632 resizeTest(WINDOW *dummy GCC_UNUSED)
641 resize_term(50, 120);
646 win1 = newwin(10, 50, 14, 25);
653 init_pair(3, COLOR_BLUE, COLOR_WHITE);
654 wattrset(win1, COLOR_PAIR(3));
659 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
665 MvWAddStr(win1, 1, 1, "The screen should now be reset");
677 padTest(WINDOW *dummy GCC_UNUSED)
681 if ((pad = newpad(50, 100)) != 0) {
682 wattron(pad, A_REVERSE);
683 MvWAddStr(pad, 5, 2, "This is a new pad");
684 (void) wattrset(pad, A_NORMAL);
686 "The end of this line should be truncated here:except now");
687 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
690 MvWAddStr(pad, 10, 1, " Press any key to continue");
691 prefresh(pad, 0, 0, 0, 0, 10, 45);
696 spad = subpad(pad, 12, 25, 6, 52);
697 MvWAddStr(spad, 2, 2, "This is a new subpad");
699 prefresh(pad, 0, 0, 0, 0, 15, 75);
704 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
705 MvWAddStr(pad, 40, 1, " Press any key to continue");
706 prefresh(pad, 30, 0, 0, 0, 10, 45);
716 display_menu(int old_option, int new_option)
720 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
722 (void) attrset(A_NORMAL);
723 MvAddStr(3, 20, "PDCurses Test Program");
725 for (i = 0; i < (int) MAX_OPTIONS; i++)
726 MvAddStr(5 + i, 25, command[i].text);
728 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
729 MvAddStr(5 + old_option, 25, command[old_option].text);
731 (void) attrset(A_REVERSE);
732 MvAddStr(5 + new_option, 25, command[new_option].text);
733 (void) attrset(A_NORMAL);
735 "Use Up and Down Arrows to select - Enter to run - Q to quit");