X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Ftestcurs.c;h=255bb4cb228ccaf2f03a5420a81557a067b724b2;hp=5fa054a943a51b2cb7c6724074b142910593ce2e;hb=59108c98bda25ae50b3a319e2bcb7f4b9a174024;hpb=b1f61d9f3aa244512045a6b02e759825d7049d34 diff --git a/test/testcurs.c b/test/testcurs.c index 5fa054a9..255bb4cb 100644 --- a/test/testcurs.c +++ b/test/testcurs.c @@ -7,11 +7,10 @@ * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * - * $Id: testcurs.c,v 1.22 2000/06/17 23:23:34 tom Exp $ + * $Id: testcurs.c,v 1.40 2009/08/29 18:47:26 tom Exp $ */ #include -#include #if defined(XCURSES) char *XCursesProgramName = "testcurs"; @@ -34,9 +33,9 @@ struct commands { }; typedef struct commands COMMAND; -const COMMAND command[] = +static const COMMAND command[] = { - {"Intro Test", introTest}, + {"General Test", introTest}, {"Pad Test", padTest}, #if defined(PDCURSES) && !defined(XCURSES) {"Resize Test", resizeTest}, @@ -45,28 +44,45 @@ const COMMAND command[] = {"Input Test", inputTest}, {"Output Test", outputTest} }; -#define MAX_OPTIONS ((sizeof(command)/sizeof(command[0]))) +#define MAX_OPTIONS (int) SIZEOF(command) -int width, height; +#if !HAVE_STRDUP +#define strdup my_strdup +static char * +strdup(char *s) +{ + char *p = typeMalloc(char, strlen(s) + 1); + if (p) + strcpy(p, s); + return (p); +} +#endif /* not HAVE_STRDUP */ + +static int width, height; int main( - int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) + int argc GCC_UNUSED, + char *argv[]GCC_UNUSED) { WINDOW *win; - int key, old_option = (-1), new_option = 0; + int key; + int old_option = (-1); + int new_option = 0; bool quit = FALSE; + int n; + + setlocale(LC_ALL, ""); #ifdef PDCDEBUG PDC_debug("testcurs started\n"); #endif if (!initTest(&win)) - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); erase(); display_menu(old_option, new_option); - while (1) { + for (;;) { #ifdef A_COLOR if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); @@ -82,6 +98,17 @@ main( keypad(stdscr, TRUE); raw(); key = getch(); + if (key < KEY_MIN && key > 0 && isalpha(key)) { + if (islower(key)) + key = toupper(key); + for (n = 0; n < MAX_OPTIONS; ++n) { + if (key == command[n].text[0]) { + display_menu(old_option, new_option = n); + key = ' '; + break; + } + } + } switch (key) { case 10: case 13: @@ -93,12 +120,15 @@ main( display_menu(old_option, new_option); break; case KEY_UP: - new_option = (new_option == 0) ? new_option : new_option - 1; + new_option = ((new_option == 0) + ? new_option + : new_option - 1); display_menu(old_option, new_option); break; case KEY_DOWN: - new_option = (new_option == MAX_OPTIONS - 1) ? new_option : - new_option + 1; + new_option = ((new_option == (MAX_OPTIONS - 1)) + ? new_option + : new_option + 1); display_menu(old_option, new_option); break; case 'Q': @@ -106,6 +136,9 @@ main( quit = TRUE; break; default: + beep(); + break; + case ' ': break; } if (quit == TRUE) @@ -118,7 +151,7 @@ main( #ifdef XCURSES XCursesExit(); #endif - return EXIT_SUCCESS; + ExitProgram(EXIT_SUCCESS); } static void @@ -128,7 +161,7 @@ Continue(WINDOW *win) int x1 = getmaxx(win); int y0 = y1 < 10 ? y1 : 10; int x0 = 1; - long save; + chtype save; save = mvwinch(win, y0, x1 - 1); @@ -186,7 +219,7 @@ introTest(WINDOW *win) wrefresh(win); cbreak(); mvwaddstr(win, 1, 1, - "You should have rectangle in the middle of the screen"); + "You should have rectangle in the middle of the screen"); mvwaddstr(win, 2, 1, "You should have heard a beep"); Continue(win); return; @@ -197,11 +230,11 @@ scrollTest(WINDOW *win) { int i; int half; - int OldX, OldY; + int OldY; NCURSES_CONST char *Message = "The window will now scroll slowly"; wclear(win); - getmaxyx(win, OldY, OldX); + OldY = getmaxy(win); half = OldY / 2; mvwprintw(win, OldY - 2, 1, Message); wrefresh(win); @@ -249,6 +282,8 @@ scrollTest(WINDOW *win) static void inputTest(WINDOW *win) { + int answered; + int repeat; int w, h, bx, by, sw, sh, i, c, num; char buffer[80]; WINDOW *subWin; @@ -310,14 +345,20 @@ inputTest(WINDOW *win) mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); + keypad(win, TRUE); raw(); noecho(); + +#if HAVE_TYPEAHEAD typeahead(-1); +#endif + #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif - while (1) { + + for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win); @@ -326,7 +367,7 @@ inputTest(WINDOW *win) else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else - wprintw(win, "Key Pressed: %s", unctrl(c)); + wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #if defined(PDCURSES) if (c == KEY_MOUSE) { int button = 0; @@ -365,20 +406,39 @@ inputTest(WINDOW *win) mouse_set(0L); #endif refresh(); - wclear(win); - mvwaddstr(win, 3, 2, "The window should have moved"); - mvwaddstr(win, 4, 2, - "This text should have appeared without you pressing a key"); - mvwaddstr(win, 6, 2, "Enter a number then a string separated by space"); - mvwin(win, 2, 1); - wrefresh(win); - echo(); - noraw(); - num = 0; - *buffer = 0; - mvwscanw(win, 7, 6, "%d %s", &num, buffer); - mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); - Continue(win); + + repeat = 0; + do { + static const char *fmt[] = + { + "%d %10s", + "%d %[a-zA-Z]s", + "%d %[][a-zA-Z]s", + "%d %[^0-9]" + }; + const char *format = fmt[repeat % SIZEOF(fmt)]; + + wclear(win); + mvwaddstr(win, 3, 2, "The window should have moved"); + mvwaddstr(win, 4, 2, + "This text should have appeared without you pressing a key"); + mvwprintw(win, 6, 2, + "Scanning with format \"%s\"", format); + mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); + erase(); + refresh(); + wrefresh(win); + echo(); + noraw(); + num = 0; + *buffer = 0; + answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer); + mvwprintw(win, 8, 6, + "String: %s Number: %d (%d values read)", + buffer, num, answered); + Continue(win); + ++repeat; + } while (answered > 0); } static void @@ -389,10 +449,21 @@ outputTest(WINDOW *win) chtype ch; int by, bx; +#if !HAVE_TIGETSTR +#if HAVE_TGETENT + char tc_buffer[4096]; + char tc_parsed[4096]; + char *area_pointer = tc_parsed; + tgetent(tc_buffer, getenv("TERM")); +#else +#define tgetstr(a,b) 0 +#endif +#endif /* !HAVE_TIGETSTR */ + nl(); wclear(win); mvwaddstr(win, 1, 1, - "You should now have a screen in the upper left corner, and this text should have wrapped"); + "You should now have a screen in the upper left corner, and this text should have wrapped"); mvwin(win, 2, 1); waddstr(win, "\nThis text should be down\n"); waddstr(win, "and broken into two here ^"); @@ -409,7 +480,7 @@ outputTest(WINDOW *win) if (LINES < 24 || COLS < 75) { mvwaddstr(win, 5, 1, - "Some tests have been skipped as they require a"); + "Some tests have been skipped as they require a"); mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS"); Continue(win); } else { @@ -429,7 +500,7 @@ outputTest(WINDOW *win) #endif wclear(win1); mvwaddstr(win1, 5, 1, - "This text should appear; using overlay option"); + "This text should appear; using overlay option"); copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); #if defined(PDCURSES) && !defined(XCURSES) @@ -444,7 +515,7 @@ outputTest(WINDOW *win) wclear(win1); wattron(win1, A_BLINK); mvwaddstr(win1, 4, 1, - "This blinking text should appear in only the second window"); + "This blinking text should appear in only the second window"); wattroff(win1, A_BLINK); mvwin(win1, by, bx); overlay(win, win1); @@ -479,8 +550,10 @@ outputTest(WINDOW *win) winsch(win, ch); Continue(win); +#if HAVE_WINSSTR mvwinsstr(win, 6, 2, "A1B2C3D4E5"); Continue(win); +#endif wmove(win, 5, 1); winsertln(win); @@ -490,7 +563,7 @@ outputTest(WINDOW *win) wclear(win); wmove(win, 2, 2); wprintw(win, "This is a formatted string in a window: %d %s\n", 42, - "is it"); + "is it"); mvwaddstr(win, 10, 1, "Enter a string: "); wrefresh(win); noraw(); @@ -503,22 +576,22 @@ outputTest(WINDOW *win) *Buffer = 0; scanw("%s", Buffer); - if (tigetstr("cvvis") != 0) { + if (TIGETSTR("cvvis", "vs") != 0) { wclear(win); curs_set(2); mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)"); Continue(win); } - if (tigetstr("civis") != 0) { + if (TIGETSTR("civis", "vi") != 0) { wclear(win); curs_set(0); mvwaddstr(win, 1, 1, - "The cursor should have disappeared (invisible)"); + "The cursor should have disappeared (invisible)"); Continue(win); } - if (tigetstr("cnorm") != 0) { + if (TIGETSTR("cnorm", "ve") != 0) { wclear(win); curs_set(1); mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)"); @@ -535,6 +608,8 @@ outputTest(WINDOW *win) #endif werase(win); + +#if HAVE_TERMNAME mvwaddstr(win, 1, 1, "Information About Your Terminal"); mvwaddstr(win, 3, 1, termname()); mvwaddstr(win, 4, 1, longname()); @@ -542,6 +617,7 @@ outputTest(WINDOW *win) mvwaddstr(win, 5, 1, "This terminal supports blinking."); else mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); +#endif mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); wrefresh(win); @@ -603,55 +679,60 @@ padTest(WINDOW *dummy GCC_UNUSED) { WINDOW *pad, *spad; - pad = newpad(50, 100); - wattron(pad, A_REVERSE); - mvwaddstr(pad, 5, 2, "This is a new pad"); - wattrset(pad, A_NORMAL); - mvwaddstr(pad, 8, 0, - "The end of this line should be truncated here:except now"); - mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); - wmove(pad, 10, 1); - wclrtoeol(pad); - mvwaddstr(pad, 10, 1, " Press any key to continue"); - prefresh(pad, 0, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + if ((pad = newpad(50, 100)) != 0) { + wattron(pad, A_REVERSE); + mvwaddstr(pad, 5, 2, "This is a new pad"); + (void) wattrset(pad, A_NORMAL); + mvwaddstr(pad, 8, 0, + "The end of this line should be truncated here:except now"); + mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); + wmove(pad, 10, 1); + wclrtoeol(pad); + mvwaddstr(pad, 10, 1, " Press any key to continue"); + prefresh(pad, 0, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - spad = subpad(pad, 12, 25, 6, 52); - mvwaddstr(spad, 2, 2, "This is a new subpad"); - box(spad, 0, 0); - prefresh(pad, 0, 0, 0, 0, 15, 75); - keypad(pad, TRUE); - raw(); - wgetch(pad); + spad = subpad(pad, 12, 25, 6, 52); + mvwaddstr(spad, 2, 2, "This is a new subpad"); + box(spad, 0, 0); + prefresh(pad, 0, 0, 0, 0, 15, 75); + keypad(pad, TRUE); + raw(); + wgetch(pad); - mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); - mvwaddstr(pad, 40, 1, " Press any key to continue"); - prefresh(pad, 30, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); + mvwaddstr(pad, 40, 1, " Press any key to continue"); + prefresh(pad, 30, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - delwin(pad); + delwin(pad); + } } static void display_menu(int old_option, int new_option) { - register size_t i; + int i; + + assert((new_option >= 0) && (new_option < MAX_OPTIONS)); - attrset(A_NORMAL); + (void) attrset(A_NORMAL); mvaddstr(3, 20, "PDCurses Test Program"); - for (i = 0; i < MAX_OPTIONS; i++) + for (i = 0; i < (int) MAX_OPTIONS; i++) mvaddstr(5 + i, 25, command[i].text); - if (old_option != (-1)) + + if ((old_option >= 0) && (old_option < MAX_OPTIONS)) mvaddstr(5 + old_option, 25, command[old_option].text); - attrset(A_REVERSE); + + (void) attrset(A_REVERSE); mvaddstr(5 + new_option, 25, command[new_option].text); - attrset(A_NORMAL); + (void) attrset(A_NORMAL); mvaddstr(13, 3, - "Use Up and Down Arrows to select - Enter to run - Q to quit"); + "Use Up and Down Arrows to select - Enter to run - Q to quit"); refresh(); }