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.17 1997/09/20 17:45:04 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 *);
33 NCURSES_CONST char *text;
34 void (*function)(WINDOW *);
36 typedef struct commands COMMAND;
38 const COMMAND command[] =
40 {"Intro Test", introTest},
41 {"Pad Test", padTest},
42 # if defined(PDCURSES) && !defined(XCURSES)
43 {"Resize Test", resizeTest},
45 {"Scroll Test", scrollTest},
46 {"Input Test", inputTest},
47 {"Output Test", outputTest}
49 #define MAX_OPTIONS ((sizeof(command)/sizeof(command[0])))
56 char *argv[] GCC_UNUSED)
59 int key,old_option=(-1),new_option=0;
63 PDC_debug("testcurs started\n");
65 if (!initTest (&win)) return EXIT_FAILURE;
70 init_pair(1,COLOR_WHITE,COLOR_BLUE);
71 wbkgd(win, COLOR_PAIR(1));
74 wbkgd(win, A_REVERSE);
76 wbkgd(win, A_REVERSE);
80 display_menu(old_option,new_option);
94 (*command[new_option].function)(win);
96 display_menu(old_option,new_option);
99 new_option = (new_option == 0) ? new_option : new_option-1;
100 display_menu(old_option,new_option);
103 new_option = (new_option == MAX_OPTIONS-1) ? new_option : new_option+1;
104 display_menu(old_option,new_option);
126 void Continue (WINDOW *win)
130 mvwaddstr(win, 10, 1, " Press any key to continue");
137 initTest (WINDOW **win)
140 PDC_debug("initTest called\n");
142 #ifdef NCURSES_VERSION
143 trace(TRACE_MAXIMUM);
147 PDC_debug("after initscr()\n");
154 height = 13; /* Create a drawing window */
155 *win = newwin(height, width, (LINES-height)/2, (COLS-width)/2);
165 introTest (WINDOW *win)
167 wmove( win, height/2-5, width/2 );
168 wvline( win, ACS_VLINE, 10 );
169 wmove( win, height/2, width/2-10 );
170 whline( win, ACS_HLINE, 20 );
176 box(win, ACS_VLINE, ACS_HLINE);
179 mvwaddstr(win, 1, 1, "You should have rectangle in the middle of the screen");
180 mvwaddstr(win, 2, 1, "You should have heard a beep");
186 scrollTest (WINDOW *win)
190 const char *Message = "The window will now scroll slowly";
193 mvwprintw (win, height - 2, 1, Message);
196 for (i = 1; i <= height; i++) {
202 getmaxyx (win, OldY, OldX);
203 mvwprintw (win, 6, 1, "The top of the window will scroll");
205 wsetscrreg (win, 0, 4);
206 box(win, ACS_VLINE, ACS_HLINE);
208 for (i = 1; i <= 5; i++) {
214 mvwprintw (win, 3, 1, "The bottom of the window will scroll");
216 wsetscrreg (win, 5, --OldY);
217 box(win, ACS_VLINE, ACS_HLINE);
219 for (i = 5; i <= OldY; i++) {
224 wsetscrreg (win, 0, OldY);
229 inputTest (WINDOW *win)
231 int w, h, bx, by, sw, sh, i, c,num;
237 getbegyx(win, by, bx);
240 if((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
246 init_pair(2,COLOR_WHITE,COLOR_RED);
247 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
250 wbkgd(subWin, A_BOLD);
252 wbkgd(subWin, A_BOLD);
254 box(subWin, ACS_VLINE, ACS_HLINE);
258 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
259 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
263 box(subWin, ACS_VLINE, ACS_HLINE);
264 for (i = 0; i < 5; i++) {
265 mvwprintw (subWin, 1, 1, "Time = %d", i);
277 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
287 mvwaddstr(win, 4, 1, "The character should now have been deleted");
291 mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
292 mvwaddstr(win, 2, 1, "Press spacebar to finish");
298 #if defined(PDCURSES)
299 mouse_set(ALL_MOUSE_EVENTS);
306 wprintw(win,"Key Pressed: %s", keyname(c));
309 wprintw(win,"Key Pressed: %c", c);
311 wprintw(win,"Key Pressed: %s", unctrl(c));
312 #if defined(PDCURSES)
313 if (c == KEY_MOUSE) {
316 if (BUTTON_CHANGED(1))
319 if (BUTTON_CHANGED(2))
322 if (BUTTON_CHANGED(3))
327 wprintw(win,"Button %d: ",button);
329 wprintw(win,"moved: ");
331 if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
332 wprintw(win,"pressed: ");
334 if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
335 wprintw(win,"double: ");
337 wprintw(win,"released: ");
338 wprintw(win," Position: Y: %d X: %d",MOUSE_Y_POS,MOUSE_X_POS);
350 #if defined(PDCURSES)
355 mvwaddstr(win, 3, 2, "The window should have moved");
356 mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key");
357 mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
362 mvwscanw(win, 7, 6, "%d %s", &num,buffer);
363 mvwprintw(win, 8, 6, "String: %s Number: %d", buffer,num);
368 outputTest (WINDOW *win)
377 mvwaddstr(win, 1, 1, "You should now have a screen in the upper left corner, and this text should have wrapped");
379 waddstr(win,"\nThis text should be down\n");
380 waddstr(win, "and broken into two here ^");
384 wattron(win, A_BOLD);
385 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
386 mvwaddstr(win, 8, 1, "Press any key to continue");
390 getbegyx(win, by, bx);
392 if (LINES < 24 || COLS < 75) {
393 mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a");
394 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
397 win1 = newwin(10, 50, 14, 25);
406 init_pair(3,COLOR_BLUE,COLOR_WHITE);
407 wbkgd(win1, COLOR_PAIR(3));
410 wbkgd(win1, A_NORMAL);
412 wbkgd(win1, A_NORMAL);
415 mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
416 copywin(win, win1,0,0,0,0,9,49,TRUE);
418 #if defined(PDCURSES) && !defined(XCURSES)
421 box(win1,ACS_VLINE,ACS_HLINE);
428 wattron(win1, A_BLINK);
429 mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window");
430 wattroff(win1, A_BLINK);
443 mvwaddstr(win, 6, 2, "This line shouldn't appear");
444 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
445 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
450 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
460 waddstr (win, "The next char should be l: ");
464 mvwinsstr( win, 6, 2, "A1B2C3D4E5" );
469 mvwaddstr(win, 5, 2, "The lines below should have moved down");
474 wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it");
475 mvwaddstr(win, 10, 1, "Enter a string: ");
479 wscanw (win, "%s", Buffer);
481 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
482 mvaddstr(10, 1, "Enter a string: ");
483 scanw ("%s", Buffer);
485 if (tigetstr("cvvis") != 0) {
488 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
492 if (tigetstr("civis") != 0) {
495 mvwaddstr(win, 1, 1, "The cursor should have disappeared (invisible)");
499 if (tigetstr("cnorm") != 0) {
502 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
507 if ( has_colors() ) {
509 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
511 init_pair(1, COLOR_RED, COLOR_WHITE);
517 mvwaddstr(win, 1, 1, "Information About Your Terminal");
518 mvwaddstr(win, 3, 1, termname());
519 mvwaddstr(win, 4, 1, longname());
520 if ( termattrs() & A_BLINK )
521 mvwaddstr(win,5, 1, "This terminal supports blinking.");
523 mvwaddstr(win,5, 1, "This terminal does NOT support blinking.");
525 mvwaddnstr( win, 7,5, "Have a nice day!ok", 16 );
528 mvwinnstr( win, 7,5, Buffer, 18 );
529 mvaddstr( LINES-2, 10, Buffer );
534 #if defined(PDCURSES) && !defined(XCURSES)
536 resizeTest(WINDOW *dummy GCC_UNUSED)
550 win1 = newwin(10, 50, 14, 25);
558 init_pair(3,COLOR_BLUE,COLOR_WHITE);
559 wattrset(win1, COLOR_PAIR(3));
564 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
570 mvwaddstr(win1, 1, 1, "The screen should now be reset");
582 padTest(WINDOW *dummy GCC_UNUSED)
586 pad = newpad(50,100);
587 wattron(pad, A_REVERSE);
588 mvwaddstr(pad, 5, 2, "This is a new pad");
589 wattrset(pad,A_NORMAL);
590 mvwaddstr(pad, 8, 0, "The end of this line should be truncated here:except now");
591 mvwaddstr(pad,11, 1, "This line should not appear.It will now");
594 mvwaddstr(pad, 10, 1, " Press any key to continue");
595 prefresh(pad,0,0,0,0,10,45);
600 spad = subpad(pad,12,25,6,52);
601 mvwaddstr(spad, 2, 2, "This is a new subpad");
603 prefresh(pad,0,0,0,0,15,75);
608 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
609 mvwaddstr(pad, 40, 1, " Press any key to continue");
610 prefresh(pad,30,0,0,0,10,45);
619 display_menu(int old_option,int new_option)
624 mvaddstr(3,20,"PDCurses Test Program");
626 for (i=0;i<MAX_OPTIONS;i++)
627 mvaddstr(5+i,25,command[i].text);
628 if (old_option != (-1))
629 mvaddstr(5+old_option,25,command[old_option].text);
631 mvaddstr(5+new_option,25,command[new_option].text);
633 mvaddstr(13,3,"Use Up and Down Arrows to select - Enter to run - Q to quit");