3 * 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 * esr changed the usleep calls to napms calls, 7 Nov 1995
8 * $Id: testcurs.c,v 1.14 1997/04/06 01:44:16 tom Exp $
11 #include <test.priv.h>
13 static void display_menu (int,int);
14 static int initTest (WINDOW **);
15 static void inputTest (WINDOW *);
16 static void introTest (WINDOW *);
17 static void outputTest (WINDOW *);
18 static void padTest (WINDOW *);
20 static void resizeTest (WINDOW *);
22 static void scrollTest (WINDOW *);
26 NCURSES_CONST char *text;
27 void (*function)(WINDOW *);
29 typedef struct commands COMMAND;
31 const COMMAND command[] =
33 {"Intro Test", introTest},
34 {"Pad Test", padTest},
36 {"Resize Test", resizeTest},
38 {"Scroll Test", scrollTest},
39 {"Input Test", inputTest},
40 {"Output Test", outputTest}
42 #define MAX_OPTIONS ((sizeof(command)/sizeof(command[0])))
49 char *argv[] GCC_UNUSED)
52 int key,old_option=(-1),new_option=0;
56 PDC_debug("testcurs started\n");
58 if (!initTest (&win)) return EXIT_FAILURE;
63 init_pair(1,COLOR_WHITE,COLOR_BLUE);
64 wattrset(win, COLOR_PAIR(1));
67 wattrset(win, A_REVERSE);
69 wattrset(win, A_REVERSE);
73 display_menu(old_option,new_option);
87 (*command[new_option].function)(win);
89 display_menu(old_option,new_option);
92 new_option = (new_option == 0) ? new_option : new_option-1;
93 display_menu(old_option,new_option);
96 new_option = (new_option == MAX_OPTIONS-1) ? new_option : new_option+1;
97 display_menu(old_option,new_option);
116 void Continue (WINDOW *win)
120 */ mvwaddstr(win, 10, 1, " Press any key to continue");
127 int initTest (WINDOW **win)
130 PDC_debug("initTest called\n");
132 #ifdef NCURSES_VERSION
133 trace(TRACE_MAXIMUM);
137 PDC_debug("after initscr()\n");
144 height = 13; /* Create a drawing window */
145 *win = newwin(height, width, (LINES-height)/2, (COLS-width)/2);
154 introTest (WINDOW *win)
159 box(win, ACS_VLINE, ACS_HLINE);
162 mvwaddstr(win, 1, 1, "You should have rectangle in the middle of the screen");
163 mvwaddstr(win, 2, 1, "You should have heard a beep");
169 scrollTest (WINDOW *win)
173 const char *Message = "The window will now scroll slowly";
176 mvwprintw (win, height - 2, 1, Message);
179 for (i = 1; i <= height; i++) {
185 getmaxyx (win, OldY, OldX);
186 mvwprintw (win, 6, 1, "The top of the window will scroll");
188 wsetscrreg (win, 0, 4);
189 box(win, ACS_VLINE, ACS_HLINE);
191 for (i = 1; i <= 5; i++) {
196 wsetscrreg (win, 0, --OldY);
201 inputTest (WINDOW *win)
203 int w, h, bx, by, sw, sh, i, c,num;
214 if((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
220 init_pair(2,COLOR_CYAN,COLOR_BLUE);
221 wattrset(subWin, COLOR_PAIR(2) | A_BOLD);
224 wattrset(subWin, A_BOLD);
226 wattrset(subWin, A_BOLD);
228 box(subWin, ACS_VLINE, ACS_HLINE);
232 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
233 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
236 for (i = 0; i < 5; i++) {
238 box(subWin, ACS_VLINE, ACS_HLINE);
239 mvwprintw (subWin, 1, 1, "Time = %d", i);
251 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
261 mvwaddstr(win, 4, 1, "The character should now have been deleted");
265 mvwaddstr(win, 2, 1, "Press a function key or an arrow key");
277 mvwaddstr(win, 3, 2, "The window should have moved");
278 mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key");
279 mvwprintw(win, 2, 2, "Keycode = %d", c);
280 mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space");
283 mvwscanw(win, 7, 6, "%d %s", &num,buffer);
284 mvwprintw(win, 8, 6, "String: %s Number: %d", buffer,num);
289 outputTest (WINDOW *win)
297 mvwaddstr(win, 1, 1, "You should now have a screen in the upper left corner, and this text should have wrapped");
302 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
303 mvwaddstr(win, 8, 1, "Press any key to continue");
307 win1 = newwin(10, 50, 15, 25);
315 init_pair(3,COLOR_BLUE,COLOR_WHITE);
316 wattrset(win1, COLOR_PAIR(3));
319 wattrset(win1, A_NORMAL);
321 wattrset(win1, A_NORMAL);
324 mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
325 copywin(win, win1,0,0,0,0,10,50,TRUE);
327 box(win1,ACS_VLINE,ACS_HLINE);
334 wattron(win1, A_BLINK);
335 mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window");
336 wattroff(win1, A_BLINK);
343 mvwaddstr(win, 6, 2, "This line shouldn't appear");
344 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
345 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
350 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
360 waddstr (win, "The next char should be l: ");
366 mvwaddstr(win, 5, 2, "The lines below should have moved down");
371 wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it");
372 mvwaddstr(win, 10, 1, "Enter a string: ");
376 wscanw (win, "%s", Buffer);
379 mvwaddstr(win, 10, 1, "Enter a string");
383 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
384 mvaddstr(10, 1, "Enter a string: ");
388 scanw ("%s", Buffer);
392 mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
397 mvwaddstr(win, 1, 1, "The cursor should have disappeared (invisible)");
402 mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
408 resizeTest(WINDOW *dummy GCC_UNUSED)
419 win1 = newwin(11, 50, 14, 25);
427 init_pair(3,COLOR_BLUE,COLOR_WHITE);
428 wattrset(win1, COLOR_PAIR(3));
433 mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
439 mvwaddstr(win1, 1, 1, "The screen should now be reset");
451 padTest(WINDOW *dummy GCC_UNUSED)
455 pad = newpad(50,100);
456 mvwaddstr(pad, 5, 2, "This is a new pad");
457 mvwaddstr(pad, 8, 0, "The end of this line should be truncated here:abcd");
458 mvwaddstr(pad,11, 1, "This line should not appear.");
461 mvwaddstr(pad, 10, 1, " Press any key to continue");
462 prefresh(pad,0,0,0,0,10,45);
467 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
468 mvwaddstr(pad, 40, 1, " Press any key to continue");
469 prefresh(pad,30,0,0,0,10,45);
478 display_menu(int old_option,int new_option)
483 mvaddstr(3,20,"PDCurses Test Program");
485 for (i=0;i<MAX_OPTIONS;i++)
486 mvaddstr(5+i,25,command[i].text);
487 if (old_option != (-1))
488 mvaddstr(5+old_option,25,command[old_option].text);
490 mvaddstr(5+new_option,25,command[new_option].text);
492 mvaddstr(13,3,"Use Up and Down Arrows to select - Enter to run - Q to quit");