]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/firstlast.c
ncurses 6.2 - patch 20200516
[ncurses.git] / test / firstlast.c
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 /*
30  * This test was written by Alexander V. Lukyanov to demonstrate difference
31  * between ncurses 4.1 and SVR4 curses
32  *
33  * $Id: firstlast.c,v 1.9 2020/02/02 23:34:34 tom Exp $
34  */
35
36 #include <test.priv.h>
37
38 static void
39 fill(WINDOW *w, const char *str)
40 {
41     const char *s;
42     int x0 = -1, y0 = -1;
43     int x1, y1;
44     int maxx, maxy, limit;
45
46     getmaxyx(w, maxy, maxx);
47     wmove(w, 0, 0);
48     limit = maxy * maxx;
49
50     for (;;) {
51         for (s = str; *s; s++) {
52             getyx(w, y1, x1);
53             if (waddch(w, UChar(*s)) == ERR
54                 || (x1 == x0 && y1 == y0)) {
55                 wmove(w, 0, 0);
56                 return;
57             }
58             /* waddch() should return ERR at the lower-right corner */
59             if (--limit < 0) {
60                 beep();
61                 if (*str == '?')
62                     return;
63                 napms(500);
64                 wmove(w, maxy - 1, 0);
65                 str = "?";
66                 limit = maxx + 1;
67             }
68             x0 = x1;
69             y0 = y1;
70         }
71     }
72 }
73
74 int
75 main(int argc GCC_UNUSED,
76      char *argv[]GCC_UNUSED)
77 {
78     WINDOW *large, *small;
79     initscr();
80     noecho();
81
82     large = newwin(20, 60, 2, 10);
83     small = newwin(10, 30, 7, 25);
84
85     /* test 1 - addch */
86     fill(large, "LargeWindow");
87
88     refresh();
89     wrefresh(large);
90     wrefresh(small);
91
92     MvWAddStr(small, 5, 5, "   Test <place to change> String   ");
93     wrefresh(small);
94     getch();
95
96     touchwin(large);
97     wrefresh(large);
98
99     MvWAddStr(small, 5, 5, "   Test <***************> String   ");
100     wrefresh(small);
101
102     /* DIFFERENCE! */
103     getch();
104
105     /* test 2: erase */
106     erase();
107     refresh();
108     getch();
109
110     /* test 3: clrtoeol */
111     werase(small);
112     wrefresh(small);
113     touchwin(large);
114     wrefresh(large);
115     wmove(small, 5, 0);
116     waddstr(small, " clrtoeol>");
117     wclrtoeol(small);
118     wrefresh(small);
119
120     /* DIFFERENCE! */ ;
121     getch();
122
123     /* test 4: clrtobot */
124     werase(small);
125     wrefresh(small);
126     touchwin(large);
127     wrefresh(large);
128     wmove(small, 5, 3);
129     waddstr(small, " clrtobot>");
130     wclrtobot(small);
131     wrefresh(small);
132
133     /* DIFFERENCE! */
134     getch();
135
136     endwin();
137
138     ExitProgram(EXIT_SUCCESS);
139 }