]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/testcurs.c
ncurses 4.2
[ncurses.git] / test / testcurs.c
index 3e6b49f7fd7e8347fb187d9a585595687c9733ee..7f40fffa6473231428af8aa52d019920743b99cc 100644 (file)
@@ -2,24 +2,31 @@
  *
  * This is a test program for the PDCurses screen package for IBM PC type
  * machines.
+ *
  * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz)
- * esr changed the usleep calls to napms calls, 7 Nov 1995
+ *  wrs(5/28/93) -- modified to be consistent (perform identically) with either
+ *                  PDCurses or under Unix System V, R4
  *
- * $Id: testcurs.c,v 1.14 1997/04/06 01:44:16 tom Exp $
+ * $Id: testcurs.c,v 1.17 1997/09/20 17:45:04 tom Exp $
  */
 
 #include <test.priv.h>
+#include <ctype.h>
+
+#if defined(XCURSES)
+char *XCursesProgramName = "testcurs";
+#endif
 
-static void display_menu (int,int);
 static int  initTest (WINDOW **);
+static void display_menu (int,int);
 static void inputTest (WINDOW *);
 static void introTest (WINDOW *);
 static void outputTest (WINDOW *);
 static void padTest (WINDOW *);
-#ifdef __PDCURSES__
+static void scrollTest (WINDOW *);
+#  if defined(PDCURSES) && !defined(XCURSES)
 static void resizeTest (WINDOW *);
 #endif
-static void scrollTest (WINDOW *);
 
 struct commands
 {
@@ -32,7 +39,7 @@ const COMMAND command[] =
 {
  {"Intro Test",  introTest},
  {"Pad Test",    padTest},
-#ifdef __PDCURSES__
+#  if defined(PDCURSES) && !defined(XCURSES)
  {"Resize Test", resizeTest},
 #endif
  {"Scroll Test", scrollTest},
@@ -45,15 +52,15 @@ 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;
 bool quit=FALSE;
 
 #ifdef PDCDEBUG
-       PDC_debug("testcurs started\n");
+        PDC_debug("testcurs started\n");
 #endif
     if (!initTest (&win)) return EXIT_FAILURE;
 
@@ -61,12 +68,12 @@ bool quit=FALSE;
     if (has_colors())
       {
        init_pair(1,COLOR_WHITE,COLOR_BLUE);
-       wattrset(win, COLOR_PAIR(1));
+       wbkgd(win, COLOR_PAIR(1));
       }
     else
-       wattrset(win, A_REVERSE);
+       wbkgd(win, A_REVERSE);
 #else
-    wattrset(win, A_REVERSE);
+    wbkgd(win, A_REVERSE);
 #endif
 
     erase();
@@ -109,6 +116,9 @@ bool quit=FALSE;
     delwin (win);
 
     endwin();
+#ifdef XCURSES
+    XCursesExit();
+#endif
     return EXIT_SUCCESS;
 }
 
@@ -116,25 +126,25 @@ static
 void Continue (WINDOW *win)
 {
     wmove(win, 10, 1);
-/*    wclrtoeol(win);
-*/    mvwaddstr(win, 10, 1, " Press any key to continue");
+    wclrtoeol(win);
+    mvwaddstr(win, 10, 1, " Press any key to continue");
     wrefresh(win);
     raw();
     wgetch(win);
 }
 
-static
-int initTest (WINDOW **win)
+static int
+initTest (WINDOW **win)
 {
 #ifdef PDCDEBUG
-       PDC_debug("initTest called\n");
+    PDC_debug("initTest called\n");
 #endif
 #ifdef NCURSES_VERSION
-       trace(TRACE_MAXIMUM);
+    trace(TRACE_MAXIMUM);
 #endif
     initscr();
 #ifdef PDCDEBUG
-       PDC_debug("after initscr()\n");
+    PDC_debug("after initscr()\n");
 #endif
 #ifdef A_COLOR
     if (has_colors())
@@ -144,7 +154,8 @@ int initTest (WINDOW **win)
     height = 13;                /* Create a drawing window */
     *win = newwin(height, width, (LINES-height)/2, (COLS-width)/2);
     if(*win == NULL)
-    {   endwin();
+    {
+        endwin();
         return 0;
     }
     return 1;
@@ -153,6 +164,12 @@ int initTest (WINDOW **win)
 static void
 introTest (WINDOW *win)
 {
+    wmove(  win, height/2-5, width/2 );
+    wvline( win, ACS_VLINE,  10 );
+    wmove(  win, height/2,   width/2-10 );
+    whline( win, ACS_HLINE,  20 );
+    Continue(win);
+
     beep ();
     werase(win);
 
@@ -180,7 +197,7 @@ scrollTest (WINDOW *win)
       napms(250);
       scroll(win);
       wrefresh (win);
-    };
+    }
 
     getmaxyx (win, OldY, OldX);
     mvwprintw (win, 6, 1, "The top of the window will scroll");
@@ -192,8 +209,19 @@ scrollTest (WINDOW *win)
       napms(500);
       scroll(win);
       wrefresh (win);
-    };
-    wsetscrreg (win, 0, --OldY);
+    }
+
+    mvwprintw (win, 3, 1, "The bottom of the window will scroll");
+    wmove (win, 8, 1);
+    wsetscrreg (win, 5, --OldY);
+    box(win, ACS_VLINE, ACS_HLINE);
+    wrefresh (win);
+    for (i = 5; i <= OldY; i++) {
+       napms (300);
+       wscrl(win,-1);
+       wrefresh (win);
+    }
+    wsetscrreg (win, 0, OldY);
 
 }
 
@@ -205,10 +233,8 @@ inputTest (WINDOW *win)
     WINDOW *subWin;
     wclear (win);
 
-    w  = win->_maxx;
-    h  = win->_maxy;
-    bx = win->_begx;
-    by = win->_begy;
+    getmaxyx(win, h,  w);
+    getbegyx(win, by, bx);
     sw = w / 3;
     sh = h / 3;
     if((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
@@ -217,13 +243,13 @@ inputTest (WINDOW *win)
 #ifdef A_COLOR
     if (has_colors())
       {
-       init_pair(2,COLOR_CYAN,COLOR_BLUE);
-       wattrset(subWin, COLOR_PAIR(2) | A_BOLD);
+       init_pair(2,COLOR_WHITE,COLOR_RED);
+       wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
       }
     else
-       wattrset(subWin, A_BOLD);
+      wbkgd(subWin, A_BOLD);
 #else
-    wattrset(subWin, A_BOLD);
+    wbkgd(subWin, A_BOLD);
 #endif
     box(subWin, ACS_VLINE, ACS_HLINE);
     wrefresh(win);
@@ -233,9 +259,9 @@ inputTest (WINDOW *win)
     mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
     wrefresh(win);
 
+    werase (subWin);
+    box(subWin, ACS_VLINE, ACS_HLINE);
     for (i = 0; i < 5; i++) {
-      werase (subWin);
-      box(subWin, ACS_VLINE, ACS_HLINE);
       mvwprintw (subWin, 1, 1, "Time = %d", i);
       wrefresh(subWin);
       napms(1000);
@@ -262,22 +288,75 @@ inputTest (WINDOW *win)
     Continue(win);
 
     wclear (win);
-    mvwaddstr(win, 2, 1, "Press a function key or an arrow key");
+    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();
-    c = wgetch(win);
-
+    noecho();
+    typeahead(-1);
+#if defined(PDCURSES)
+    mouse_set(ALL_MOUSE_EVENTS);
+#endif
+    while(1) {
+      wmove(win,3,5);
+      c = wgetch(win);
+      wclrtobot(win);
+      if (c >= KEY_MIN)
+        wprintw(win,"Key Pressed: %s", keyname(c));
+      else
+        if (isprint(c))
+          wprintw(win,"Key Pressed: %c", c);
+        else
+          wprintw(win,"Key Pressed: %s", unctrl(c));
+#if defined(PDCURSES)
+      if (c == KEY_MOUSE) {
+         int button=0;
+         request_mouse_pos();
+         if (BUTTON_CHANGED(1))
+            button = 1;
+          else
+            if (BUTTON_CHANGED(2))
+              button = 2;
+            else
+              if (BUTTON_CHANGED(3))
+                button = 3;
+              else
+                button = 0;
+         wmove(win,4,18);
+         wprintw(win,"Button %d: ",button);
+         if (MOUSE_MOVED)
+           wprintw(win,"moved: ");
+         else
+           if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
+             wprintw(win,"pressed: ");
+           else
+             if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
+               wprintw(win,"double: ");
+             else
+               wprintw(win,"released: ");
+         wprintw(win," Position: Y: %d X: %d",MOUSE_Y_POS,MOUSE_X_POS);
+      }
+#endif
+      wrefresh(win);
+      if (c == ' ')
+        break;
+    }
+#if 0
     nodelay(win, TRUE);
     wgetch(win);
     nodelay(win, FALSE);
-
+#endif
+#if defined(PDCURSES)
+    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");
-    mvwprintw(win, 2, 2, "Keycode = %d", c);
-    mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space");
+    mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
+    mvwin(win, 2, 1);
+    wrefresh(win);
     echo();
     noraw();
     mvwscanw(win, 7, 6, "%d %s", &num,buffer);
@@ -291,53 +370,74 @@ outputTest (WINDOW *win)
     WINDOW *win1;
     char Buffer [80];
     chtype ch;
+    int by, bx;
 
     nl ();
     wclear (win);
     mvwaddstr(win, 1, 1, "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 ^");
     Continue(win);
 
     wclear(win);
+    wattron(win, A_BOLD);
     mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
     mvwaddstr(win, 8, 1, "Press any key to continue");
     wrefresh(win);
     wgetch(win);
 
-    win1 = newwin(10, 50, 15, 25);
-    if(win1 == NULL)
-    {   endwin();
-        return;
-    }
-#ifdef A_COLOR
-    if (has_colors())
+    getbegyx(win, by, bx);
+
+    if (LINES < 24 || COLS < 75) {
+       mvwaddstr(win, 5, 1, "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 {
+      win1 = newwin(10, 50, 14, 25);
+      if(win1 == NULL)
       {
-       init_pair(3,COLOR_BLUE,COLOR_WHITE);
-       wattrset(win1, COLOR_PAIR(3));
+          endwin();
+          return;
       }
-    else
-       wattrset(win1, A_NORMAL);
+#ifdef A_COLOR
+      if (has_colors())
+        {
+         init_pair(3,COLOR_BLUE,COLOR_WHITE);
+         wbkgd(win1, COLOR_PAIR(3));
+        }
+      else
+        wbkgd(win1, A_NORMAL);
 #else
-    wattrset(win1, A_NORMAL);
+      wbkgd(win1, A_NORMAL);
 #endif
-    wclear (win1);
-    mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
-    copywin(win, win1,0,0,0,0,10,50,TRUE);
+      wclear (win1);
+      mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
+      copywin(win, win1,0,0,0,0,9,49,TRUE);
 
-    box(win1,ACS_VLINE,ACS_HLINE);
-
-    wmove(win1, 8, 26);
-    wrefresh(win1);
-    wgetch(win1);
-
-    wclear(win1);
-    wattron(win1, A_BLINK);
-    mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window");
-    wattroff(win1, A_BLINK);
-    wrefresh(win1);
-    wgetch(win1);
-    delwin(win1);
+#if defined(PDCURSES) && !defined(XCURSES)
+      box(win1,0xb3,0xc4);
+#else
+      box(win1,ACS_VLINE,ACS_HLINE);
+#endif
+      wmove(win1, 8, 26);
+      wrefresh(win1);
+      wgetch(win1);
+
+      wclear(win1);
+      wattron(win1, A_BLINK);
+      mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window");
+      wattroff(win1, A_BLINK);
+      mvwin(win1, by, bx);
+      overlay(win, win1);
+      mvwin(win1,14,25);
+      wmove(win1, 8, 26);
+      wrefresh(win1);
+      wgetch(win1);
+      delwin(win1);
+    }
 
+    clear();
     wclear(win);
     wrefresh(win);
     mvwaddstr(win, 6, 2, "This line shouldn't appear");
@@ -361,6 +461,9 @@ outputTest (WINDOW *win)
     winsch (win, ch);
     Continue(win);
 
+    mvwinsstr( win, 6, 2, "A1B2C3D4E5" );
+    Continue(win);
+
     wmove(win, 5, 1);
     winsertln (win);
     mvwaddstr(win, 5, 2, "The lines below should have moved down");
@@ -375,35 +478,60 @@ outputTest (WINDOW *win)
     echo();
     wscanw (win, "%s", Buffer);
 
-    wclear(win);
-    mvwaddstr(win, 10, 1, "Enter a string");
-    wrefresh(win);
-    clear();
-    move(0,0);
     printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
     mvaddstr(10, 1, "Enter a string: ");
-    refresh();
-    noraw();
-    echo();
     scanw ("%s", Buffer);
 
-    wclear(win);
-    curs_set(2);
-    mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
-    Continue(win);
+    if (tigetstr("cvvis") != 0) {
+        wclear(win);
+        curs_set(2);
+        mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
+        Continue(win);
+    }
 
-    wclear(win);
-    curs_set(0);
-    mvwaddstr(win, 1, 1, "The cursor should have disappeared (invisible)");
-    Continue(win);
+    if (tigetstr("civis") != 0) {
+        wclear(win);
+        curs_set(0);
+        mvwaddstr(win, 1, 1, "The cursor should have disappeared (invisible)");
+        Continue(win);
+    }
 
-    wclear(win);
-    curs_set(1);
-    mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
+    if (tigetstr("cnorm") != 0) {
+        wclear(win);
+        curs_set(1);
+        mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
+        Continue(win);
+    }
+
+#ifdef A_COLOR
+    if ( has_colors() ) {
+       wclear(win);
+       mvwaddstr(win, 1, 1, "Colors should change after you press a key");
+       Continue(win);
+       init_pair(1, COLOR_RED, COLOR_WHITE);
+       wrefresh(win);
+    }
+#endif
+
+    werase(win);
+    mvwaddstr(win, 1, 1, "Information About Your Terminal");
+    mvwaddstr(win, 3, 1, termname());
+    mvwaddstr(win, 4, 1, longname());
+    if ( termattrs() & A_BLINK )
+       mvwaddstr(win,5, 1, "This terminal supports blinking.");
+    else
+       mvwaddstr(win,5, 1, "This terminal does NOT support blinking.");
+
+    mvwaddnstr( win, 7,5, "Have a nice day!ok", 16 );
+    wrefresh(win);
+
+    mvwinnstr( win, 7,5, Buffer, 18 );
+    mvaddstr( LINES-2, 10, Buffer );
+    refresh();
     Continue(win);
 }
 
-#ifdef __PDCURSES__
+#if defined(PDCURSES) && !defined(XCURSES)
 static void
 resizeTest(WINDOW *dummy GCC_UNUSED)
 {
@@ -413,10 +541,13 @@ resizeTest(WINDOW *dummy GCC_UNUSED)
 
     clear();
     refresh();
-    resize(50);
+#  if defined(OS2)
+    resize_term(50,120);
+#  else
+    resize_term(50,80);
+#  endif
 
-
-    win1 = newwin(11, 50, 14, 25);
+    win1 = newwin(10, 50, 14, 25);
     if(win1 == NULL)
     {   endwin();
         return;
@@ -433,9 +564,9 @@ resizeTest(WINDOW *dummy GCC_UNUSED)
     mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
     Continue(win1);
 
+    wclear (win1);
     resetty ();
 
-    wclear (win1);
     mvwaddstr(win1, 1, 1, "The screen should now be reset");
     Continue(win1);
 
@@ -450,12 +581,14 @@ resizeTest(WINDOW *dummy GCC_UNUSED)
 static void
 padTest(WINDOW *dummy GCC_UNUSED)
 {
-WINDOW *pad;
+WINDOW *pad, *spad;
 
  pad = newpad(50,100);
+ wattron(pad, A_REVERSE);
  mvwaddstr(pad, 5, 2, "This is a new pad");
- mvwaddstr(pad, 8, 0, "The end of this line should be truncated here:abcd");
- mvwaddstr(pad,11, 1, "This line should not appear.");
+ 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");
@@ -464,6 +597,14 @@ WINDOW *pad;
  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);