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.46 2012/11/24 19:38:20 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 #if defined(PDCURSES)
345 mouse_set(ALL_MOUSE_EVENTS);
353 wprintw(win, "Key Pressed: %s", keyname(c));
355 wprintw(win, "Key Pressed: %c", c);
357 wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
358 #if defined(PDCURSES)
359 if (c == KEY_MOUSE) {
362 if (BUTTON_CHANGED(1))
364 else if (BUTTON_CHANGED(2))
366 else if (BUTTON_CHANGED(3))
371 wprintw(win, "Button %d: ", button);
373 wprintw(win, "moved: ");
374 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
375 wprintw(win, "pressed: ");
376 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
377 wprintw(win, "double: ");
379 wprintw(win, "released: ");
380 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
392 #if defined(PDCURSES)
399 static const char *fmt[] =
406 const char *format = fmt[(unsigned) repeat % SIZEOF(fmt)];
409 MvWAddStr(win, 3, 2, "The window should have moved");
411 "This text should have appeared without you pressing a key");
413 "Scanning with format \"%s\"", format);
414 mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
422 answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer);
424 "String: %s Number: %d (%d values read)",
425 buffer, num, answered);
428 } while (answered > 0);
432 outputTest(WINDOW *win)
441 char tc_buffer[4096];
442 char tc_parsed[4096];
443 char *area_pointer = tc_parsed;
444 tgetent(tc_buffer, getenv("TERM"));
446 #define tgetstr(a,b) 0
448 #endif /* !HAVE_TIGETSTR */
453 "You should now have a screen in the upper left corner, and this text should have wrapped");
455 waddstr(win, "\nThis text should be down\n");
456 waddstr(win, "and broken into two here ^");
460 wattron(win, A_BOLD);
461 MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
462 MvWAddStr(win, 8, 1, "Press any key to continue");
466 getbegyx(win, by, bx);
468 if (LINES < 24 || COLS < 75) {
470 "Some tests have been skipped as they require a");
471 MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
474 win1 = newwin(10, 50, 14, 25);
481 init_pair(3, COLOR_BLUE, COLOR_WHITE);
482 wbkgd(win1, (chtype) COLOR_PAIR(3));
484 wbkgd(win1, A_NORMAL);
486 wbkgd(win1, A_NORMAL);
489 MvWAddStr(win1, 5, 1,
490 "This text should appear; using overlay option");
491 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
493 #if defined(PDCURSES) && !defined(XCURSES)
494 box(win1, 0xb3, 0xc4);
496 box(win1, ACS_VLINE, ACS_HLINE);
503 wattron(win1, A_BLINK);
504 MvWAddStr(win1, 4, 1,
505 "This blinking text should appear in only the second window");
506 wattroff(win1, A_BLINK);
519 MvWAddStr(win, 6, 2, "This line shouldn't appear");
520 MvWAddStr(win, 4, 2, "Only half of the next line is visible");
521 MvWAddStr(win, 5, 2, "Only half of the next line is visible");
526 MvWAddStr(win, 8, 2, "This line also shouldn't appear");
536 waddstr(win, "The next char should be l: ");
541 (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
547 MvWAddStr(win, 5, 2, "The lines below should have moved down");
552 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
554 MvWAddStr(win, 10, 1, "Enter a string: ");
559 wscanw(win, "%s", Buffer);
561 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
562 MvAddStr(10, 1, "Enter a string: ");
566 if (TIGETSTR("cvvis", "vs") != 0) {
569 MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
573 if (TIGETSTR("civis", "vi") != 0) {
577 "The cursor should have disappeared (invisible)");
581 if (TIGETSTR("cnorm", "ve") != 0) {
584 MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
590 MvWAddStr(win, 1, 1, "Colors should change after you press a key");
592 init_pair(1, COLOR_RED, COLOR_WHITE);
600 MvWAddStr(win, 1, 1, "Information About Your Terminal");
601 MvWAddStr(win, 3, 1, termname());
602 MvWAddStr(win, 4, 1, longname());
603 if (termattrs() & A_BLINK)
604 MvWAddStr(win, 5, 1, "This terminal supports blinking.");
606 MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
609 (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
612 (void) mvwinnstr(win, 7, 5, Buffer, 18);
613 MvAddStr(LINES - 2, 10, Buffer);
618 #if defined(PDCURSES) && !defined(XCURSES)
620 resizeTest(WINDOW *dummy GCC_UNUSED)
629 resize_term(50, 120);
634 win1 = newwin(10, 50, 14, 25);
641 init_pair(3, COLOR_BLUE, COLOR_WHITE);
642 wattrset(win1, COLOR_PAIR(3));
647 MvWAddStr(win1, 1, 1, "The screen may now have 50 lines");
653 MvWAddStr(win1, 1, 1, "The screen should now be reset");
665 padTest(WINDOW *dummy GCC_UNUSED)
669 if ((pad = newpad(50, 100)) != 0) {
670 wattron(pad, A_REVERSE);
671 MvWAddStr(pad, 5, 2, "This is a new pad");
672 (void) wattrset(pad, A_NORMAL);
674 "The end of this line should be truncated here:except now");
675 MvWAddStr(pad, 11, 1, "This line should not appear.It will now");
678 MvWAddStr(pad, 10, 1, " Press any key to continue");
679 prefresh(pad, 0, 0, 0, 0, 10, 45);
684 if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) {
685 MvWAddStr(spad, 2, 2, "This is a new subpad");
689 prefresh(pad, 0, 0, 0, 0, 15, 75);
694 MvWAddStr(pad, 35, 2, "This is displayed at line 35 in the pad");
695 MvWAddStr(pad, 40, 1, " Press any key to continue");
696 prefresh(pad, 30, 0, 0, 0, 10, 45);
706 display_menu(int old_option, int new_option)
710 assert((new_option >= 0) && (new_option < MAX_OPTIONS));
712 (void) attrset(A_NORMAL);
713 MvAddStr(3, 20, "PDCurses Test Program");
715 for (i = 0; i < (int) MAX_OPTIONS; i++)
716 MvAddStr(5 + i, 25, command[i].text);
718 if ((old_option >= 0) && (old_option < MAX_OPTIONS))
719 MvAddStr(5 + old_option, 25, command[old_option].text);
721 (void) attrset(A_REVERSE);
722 MvAddStr(5 + new_option, 25, command[new_option].text);
723 (void) attrset(A_NORMAL);
725 "Use Up and Down Arrows to select - Enter to run - Q to quit");