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.22 2000/06/17 23:23:34 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 {"Intro 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)/sizeof(command[0])))
55 char *argv[]GCC_UNUSED)
58 int key, old_option = (-1), new_option = 0;
62 PDC_debug("testcurs started\n");
68 display_menu(old_option, new_option);
72 init_pair(1, COLOR_WHITE, COLOR_BLUE);
73 wbkgd(win, COLOR_PAIR(1));
75 wbkgd(win, A_REVERSE);
77 wbkgd(win, A_REVERSE);
91 (*command[new_option].function) (win);
93 display_menu(old_option, new_option);
96 new_option = (new_option == 0) ? new_option : new_option - 1;
97 display_menu(old_option, new_option);
100 new_option = (new_option == MAX_OPTIONS - 1) ? new_option :
102 display_menu(old_option, new_option);
125 Continue(WINDOW *win)
127 int y1 = getmaxy(win);
128 int x1 = getmaxx(win);
129 int y0 = y1 < 10 ? y1 : 10;
133 save = mvwinch(win, y0, x1 - 1);
135 mvwaddstr(win, y0, x0, " Press any key to continue");
139 mvwaddch(win, y0, x1 - 1, save);
147 initTest(WINDOW **win)
150 PDC_debug("initTest called\n");
153 trace(TRACE_MAXIMUM);
157 PDC_debug("after initscr()\n");
164 height = 13; /* Create a drawing window */
165 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
174 introTest(WINDOW *win)
176 wmove(win, height / 2 - 5, width / 2);
177 wvline(win, ACS_VLINE, 10);
178 wmove(win, height / 2, width / 2 - 10);
179 whline(win, ACS_HLINE, 20);
185 box(win, ACS_VLINE, ACS_HLINE);
189 "You should have rectangle in the middle of the screen");
190 mvwaddstr(win, 2, 1, "You should have heard a beep");
196 scrollTest(WINDOW *win)
201 NCURSES_CONST char *Message = "The window will now scroll slowly";
204 getmaxyx(win, OldY, OldX);
206 mvwprintw(win, OldY - 2, 1, Message);
209 for (i = 1; i <= OldY; i++) {
216 for (i = 1; i < OldY; i++) {
217 mvwprintw(win, i, 1, "Line %d", i);
219 mvwprintw(win, OldY - 2, 1, "The top of the window will scroll");
221 wsetscrreg(win, 0, half - 1);
222 box(win, ACS_VLINE, ACS_HLINE);
224 for (i = 1; i <= half; i++) {
227 box(win, ACS_VLINE, ACS_HLINE);
232 for (i = 1; i < OldY; i++) {
233 mvwprintw(win, i, 1, "Line %d", i);
235 mvwprintw(win, 1, 1, "The bottom of the window will scroll");
236 wmove(win, OldY - 2, 1);
237 wsetscrreg(win, half, --OldY);
238 box(win, ACS_VLINE, ACS_HLINE);
240 for (i = half; i <= OldY; i++) {
243 box(win, ACS_VLINE, ACS_HLINE);
246 wsetscrreg(win, 0, OldY);
250 inputTest(WINDOW *win)
252 int w, h, bx, by, sw, sh, i, c, num;
258 getbegyx(win, by, bx);
261 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
266 init_pair(2, COLOR_WHITE, COLOR_RED);
267 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
269 wbkgd(subWin, A_BOLD);
271 wbkgd(subWin, A_BOLD);
273 box(subWin, ACS_VLINE, ACS_HLINE);
277 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
278 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
282 box(subWin, ACS_VLINE, ACS_HLINE);
283 for (i = 0; i < 5; i++) {
284 mvwprintw(subWin, 1, 1, "Time = %d", i);
296 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
306 mvwaddstr(win, 4, 1, "The character should now have been deleted");
310 mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
311 mvwaddstr(win, 2, 1, "Press spacebar to finish");
317 #if defined(PDCURSES)
318 mouse_set(ALL_MOUSE_EVENTS);
325 wprintw(win, "Key Pressed: %s", keyname(c));
327 wprintw(win, "Key Pressed: %c", c);
329 wprintw(win, "Key Pressed: %s", unctrl(c));
330 #if defined(PDCURSES)
331 if (c == KEY_MOUSE) {
334 if (BUTTON_CHANGED(1))
336 else if (BUTTON_CHANGED(2))
338 else if (BUTTON_CHANGED(3))
343 wprintw(win, "Button %d: ", button);
345 wprintw(win, "moved: ");
346 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
347 wprintw(win, "pressed: ");
348 else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
349 wprintw(win, "double: ");
351 wprintw(win, "released: ");
352 wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
364 #if defined(PDCURSES)
369 mvwaddstr(win, 3, 2, "The window should have moved");
371 "This text should have appeared without you pressing a key");
372 mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
379 mvwscanw(win, 7, 6, "%d %s", &num, buffer);
380 mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num);
385 outputTest(WINDOW *win)
395 "You should now have a screen in the upper left corner, and this text should have wrapped");
397 waddstr(win, "\nThis text should be down\n");
398 waddstr(win, "and broken into two here ^");
402 wattron(win, A_BOLD);
403 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
404 mvwaddstr(win, 8, 1, "Press any key to continue");
408 getbegyx(win, by, bx);
410 if (LINES < 24 || COLS < 75) {
412 "Some tests have been skipped as they require a");
413 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
416 win1 = newwin(10, 50, 14, 25);
423 init_pair(3, COLOR_BLUE, COLOR_WHITE);
424 wbkgd(win1, COLOR_PAIR(3));
426 wbkgd(win1, A_NORMAL);
428 wbkgd(win1, A_NORMAL);
431 mvwaddstr(win1, 5, 1,
432 "This text should appear; using overlay option");
433 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
435 #if defined(PDCURSES) && !defined(XCURSES)
436 box(win1, 0xb3, 0xc4);
438 box(win1, ACS_VLINE, ACS_HLINE);
445 wattron(win1, A_BLINK);
446 mvwaddstr(win1, 4, 1,
447 "This blinking text should appear in only the second window");
448 wattroff(win1, A_BLINK);
461 mvwaddstr(win, 6, 2, "This line shouldn't appear");
462 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
463 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
468 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
478 waddstr(win, "The next char should be l: ");
482 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
487 mvwaddstr(win, 5, 2, "The lines below should have moved down");
492 wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
494 mvwaddstr(win, 10, 1, "Enter a string: ");
499 wscanw(win, "%s", Buffer);
501 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
502 mvaddstr(10, 1, "Enter a string: ");
506 if (tigetstr("cvvis") != 0) {
509 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
513 if (tigetstr("civis") != 0) {
517 "The cursor should have disappeared (invisible)");
521 if (tigetstr("cnorm") != 0) {
524 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
530 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
532 init_pair(1, COLOR_RED, COLOR_WHITE);
538 mvwaddstr(win, 1, 1, "Information About Your Terminal");
539 mvwaddstr(win, 3, 1, termname());
540 mvwaddstr(win, 4, 1, longname());
541 if (termattrs() & A_BLINK)
542 mvwaddstr(win, 5, 1, "This terminal supports blinking.");
544 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
546 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
549 mvwinnstr(win, 7, 5, Buffer, 18);
550 mvaddstr(LINES - 2, 10, Buffer);
555 #if defined(PDCURSES) && !defined(XCURSES)
557 resizeTest(WINDOW *dummy GCC_UNUSED)
566 resize_term(50, 120);
571 win1 = newwin(10, 50, 14, 25);
578 init_pair(3, COLOR_BLUE, COLOR_WHITE);
579 wattrset(win1, COLOR_PAIR(3));
584 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
590 mvwaddstr(win1, 1, 1, "The screen should now be reset");
602 padTest(WINDOW *dummy GCC_UNUSED)
606 pad = newpad(50, 100);
607 wattron(pad, A_REVERSE);
608 mvwaddstr(pad, 5, 2, "This is a new pad");
609 wattrset(pad, A_NORMAL);
611 "The end of this line should be truncated here:except now");
612 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
615 mvwaddstr(pad, 10, 1, " Press any key to continue");
616 prefresh(pad, 0, 0, 0, 0, 10, 45);
621 spad = subpad(pad, 12, 25, 6, 52);
622 mvwaddstr(spad, 2, 2, "This is a new subpad");
624 prefresh(pad, 0, 0, 0, 0, 15, 75);
629 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
630 mvwaddstr(pad, 40, 1, " Press any key to continue");
631 prefresh(pad, 30, 0, 0, 0, 10, 45);
640 display_menu(int old_option, int new_option)
645 mvaddstr(3, 20, "PDCurses Test Program");
647 for (i = 0; i < MAX_OPTIONS; i++)
648 mvaddstr(5 + i, 25, command[i].text);
649 if (old_option != (-1))
650 mvaddstr(5 + old_option, 25, command[old_option].text);
652 mvaddstr(5 + new_option, 25, command[new_option].text);
655 "Use Up and Down Arrows to select - Enter to run - Q to quit");