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.48 2013/05/18 22:05:06 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)
48 static int width, height;
53 char *argv[]GCC_UNUSED)
57 int old_option = (-1);
62 setlocale(LC_ALL, "");
65 PDC_debug("testcurs started\n");
68 ExitProgram(EXIT_FAILURE);
71 display_menu(old_option, new_option);
75 init_pair(1, COLOR_WHITE, COLOR_BLUE);
76 wbkgd(win, (chtype) COLOR_PAIR(1));
78 wbkgd(win, A_REVERSE);
80 wbkgd(win, A_REVERSE);
88 if (key < KEY_MIN && key > 0 && isalpha(key)) {
91 for (n = 0; n < MAX_OPTIONS; ++n) {
92 if (key == command[n].text[0]) {
93 display_menu(old_option, new_option = n);
105 (*command[new_option].function) (win);
107 display_menu(old_option, new_option);
110 new_option = ((new_option == 0)
113 display_menu(old_option, new_option);
116 new_option = ((new_option == (MAX_OPTIONS - 1))
119 display_menu(old_option, new_option);
141 ExitProgram(EXIT_SUCCESS);
145 Continue(WINDOW *win)
147 int y1 = getmaxy(win);
148 int x1 = getmaxx(win);
149 int y0 = y1 < 10 ? y1 : 10;
153 save = mvwinch(win, y0, x1 - 1);
155 MvWAddStr(win, y0, x0, " Press any key to continue");
159 MvWAddCh(win, y0, x1 - 1, save);
167 initTest(WINDOW **win)
170 PDC_debug("initTest called\n");
173 trace(TRACE_MAXIMUM);
177 PDC_debug("after initscr()\n");
184 height = 13; /* Create a drawing window */
185 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
194 introTest(WINDOW *win)
196 wmove(win, height / 2 - 5, width / 2);
197 wvline(win, ACS_VLINE, 10);
198 wmove(win, height / 2, width / 2 - 10);
199 whline(win, ACS_HLINE, 20);
205 box(win, ACS_VLINE, ACS_HLINE);
209 "You should have rectangle in the middle of the screen");
210 MvWAddStr(win, 2, 1, "You should have heard a beep");
216 scrollTest(WINDOW *win)
221 NCURSES_CONST char *Message = "The window will now scroll slowly";
226 MvWAddStr(win, OldY - 2, 1, Message);
229 for (i = 1; i <= OldY; i++) {
236 for (i = 1; i < OldY; i++) {
237 MvWPrintw(win, i, 1, "Line %d", i);
239 MvWPrintw(win, OldY - 2, 1, "The top of the window will scroll");
241 wsetscrreg(win, 0, half - 1);
242 box(win, ACS_VLINE, ACS_HLINE);
244 for (i = 1; i <= half; i++) {
247 box(win, ACS_VLINE, ACS_HLINE);
252 for (i = 1; i < OldY; i++) {
253 MvWPrintw(win, i, 1, "Line %d", i);
255 MvWPrintw(win, 1, 1, "The bottom of the window will scroll");
256 wmove(win, OldY - 2, 1);
257 wsetscrreg(win, half, --OldY);
258 box(win, ACS_VLINE, ACS_HLINE);
260 for (i = half; i <= OldY; i++) {
263 box(win, ACS_VLINE, ACS_HLINE);
266 wsetscrreg(win, 0, OldY);
270 inputTest(WINDOW *win)
274 int w, h, bx, by, sw, sh, i, c, num;
280 getbegyx(win, by, bx);
283 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
288 init_pair(2, COLOR_WHITE, COLOR_RED);
289 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
291 wbkgd(subWin, A_BOLD);
293 wbkgd(subWin, A_BOLD);
295 box(subWin, ACS_VLINE, ACS_HLINE);
299 MvWAddStr(win, 2, 1, "Press some keys for 5 seconds");
300 MvWAddStr(win, 1, 1, "Pressing ^C should do nothing");
304 box(subWin, ACS_VLINE, ACS_HLINE);
305 for (i = 0; i < 5; i++) {
306 MvWPrintw(subWin, 1, 1, "Time = %d", i);
318 MvWAddStr(win, 2, 1, "Press a key, followed by ENTER");
328 MvWAddStr(win, 4, 1, "The character should now have been deleted");
332 MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
333 MvWAddStr(win, 2, 1, "Press spacebar to finish");
344 #ifdef NCURSES_MOUSE_VERSION
345 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
347 #if defined(PDCURSES)
348 mouse_set(ALL_MOUSE_EVENTS);
356 wprintw(win, "Key Pressed: %s", keyname(c));
358 wprintw(win, "Key Pressed: %c", c);
360 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
362 if (c == KEY_MOUSE) {
363 #if defined(NCURSES_MOUSE_VERSION)
364 #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037))
365 #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED))
366 #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED))
367 #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED))
368 #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED))
373 if (ButtonChanged(1))
375 else if (ButtonChanged(2))
377 else if (ButtonChanged(3))
382 wprintw(win, "Button %d: ", button);
383 if (ButtonPressed(button))
384 wprintw(win, "pressed: ");
385 else if (ButtonDouble(button))
386 wprintw(win, "double: ");
387 else if (ButtonTriple(button))
388 wprintw(win, "triple: ");
390 wprintw(win, "released: ");
391 wprintw(win, " Position: Y: %d X: %d", event.y, event.x);
392 #elif defined(PDCURSES)
395 if (BUTTON_CHANGED(1))
397 else if (BUTTON_CHANGED(2))
399 else if (BUTTON_CHANGED(3))
404 wprintw(win, "Button %d: ", button);
406 wprintw(win, "moved: ");
407 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
408 wprintw(win, "pressed: ");
409 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
410 wprintw(win, "double: ");
412 wprintw(win, "released: ");
413 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
414 #endif /* NCURSES_VERSION vs PDCURSES */
416 #endif /* KEY_MOUSE */
426 #if defined(PDCURSES)
433 static const char *fmt[] =
440 const char *format = fmt[(unsigned) repeat % SIZEOF(fmt)];
443 MvWAddStr(win, 3, 2, "The window should have moved");
445 "This text should have appeared without you pressing a key");
447 "Scanning with format \"%s\"", format);
448 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
456 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
458 "String: %s Number: %d (%d values read)",
459 buffer, num, answered);
462 } while (answered > 0);
466 outputTest(WINDOW *win)
475 char tc_buffer[4096];
476 char tc_parsed[4096];
477 char *area_pointer = tc_parsed;
478 tgetent(tc_buffer, getenv("TERM"));
480 #define tgetstr(a,b) 0
482 #endif /* !HAVE_TIGETSTR */
487 "You should now have a screen in the upper left corner, and this text should have wrapped");
489 waddstr(win, "\nThis text should be down\n");
490 waddstr(win, "and broken into two here ^");
494 wattron(win, A_BOLD);
495 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
496 MvWAddStr(win, 8, 1, "Press any key to continue");
500 getbegyx(win, by, bx);
502 if (LINES < 24 || COLS < 75) {
504 "Some tests have been skipped as they require a");
505 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
508 win1 = newwin(10, 50, 14, 25);
515 init_pair(3, COLOR_BLUE, COLOR_WHITE);
516 wbkgd(win1, (chtype) COLOR_PAIR(3));
518 wbkgd(win1, A_NORMAL);
520 wbkgd(win1, A_NORMAL);
523 MvWAddStr(win1, 5, 1,
524 "This text should appear; using overlay option");
525 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
527 #if defined(PDCURSES) && !defined(XCURSES)
528 box(win1, 0xb3, 0xc4);
530 box(win1, ACS_VLINE, ACS_HLINE);
537 wattron(win1, A_BLINK);
538 MvWAddStr(win1, 4, 1,
539 "This blinking text should appear in only the second window");
540 wattroff(win1, A_BLINK);
553 MvWAddStr(win, 6, 2, "This line shouldn't appear");
554 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
555 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
560 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
570 waddstr(win, "The next char should be l: ");
575 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
581 MvWAddStr(win, 5, 2, "The lines below should have moved down");
586 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
588 MvWAddStr(win, 10, 1, "Enter a string: ");
593 wscanw(win, "%s", Buffer);
595 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
596 MvAddStr(10, 1, "Enter a string: ");
600 if (TIGETSTR("cvvis", "vs") != 0) {
603 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
607 if (TIGETSTR("civis", "vi") != 0) {
611 "The cursor should have disappeared (invisible)");
615 if (TIGETSTR("cnorm", "ve") != 0) {
618 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
624 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
626 init_pair(1, COLOR_RED, COLOR_WHITE);
634 MvWAddStr(win, 1, 1, "Information About Your Terminal");
635 MvWAddStr(win, 3, 1, termname());
636 MvWAddStr(win, 4, 1, longname());
637 if (termattrs() & A_BLINK)
638 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
640 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
643 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
646 (void) mvwinnstr(win, 7, 5, Buffer, 18);
647 MvAddStr(LINES - 2, 10, Buffer);
652 #if defined(PDCURSES) && !defined(XCURSES)
654 resizeTest(WINDOW *dummy GCC_UNUSED)
663 resize_term(50, 120);
668 win1 = newwin(10, 50, 14, 25);
675 init_pair(3, COLOR_BLUE, COLOR_WHITE);
676 wattrset(win1, COLOR_PAIR(3));
681 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
687 MvWAddStr(win1, 1, 1, "The screen should now be reset");
699 padTest(WINDOW *dummy GCC_UNUSED)
703 if ((pad = newpad(50, 100)) != 0) {
704 wattron(pad, A_REVERSE);
705 MvWAddStr(pad, 5, 2, "This is a new pad");
706 (void) wattrset(pad, A_NORMAL);
708 "The end of this line should be truncated here:except now");
709 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
712 MvWAddStr(pad, 10, 1, " Press any key to continue");
713 prefresh(pad, 0, 0, 0, 0, 10, 45);
718 if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) {
719 MvWAddStr(spad, 2, 2, "This is a new subpad");
723 prefresh(pad, 0, 0, 0, 0, 15, 75);
728 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
729 MvWAddStr(pad, 40, 1, " Press any key to continue");
730 prefresh(pad, 30, 0, 0, 0, 10, 45);
740 display_menu(int old_option, int new_option)
744 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
746 (void) attrset(A_NORMAL);
747 MvAddStr(3, 20, "PDCurses Test Program");
749 for (i = 0; i < (int) MAX_OPTIONS; i++)
750 MvAddStr(5 + i, 25, command[i].text);
752 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
753 MvAddStr(5 + old_option, 25, command[old_option].text);
755 (void) attrset(A_REVERSE);
756 MvAddStr(5 + new_option, 25, command[new_option].text);
757 (void) attrset(A_NORMAL);
759 "Use Up and Down Arrows to select - Enter to run - Q to quit");