blob: c66c2b8511c3170bab7115655588970a70c3f0bd [file] [log] [blame]
Steve Kondikae271bc2015-11-15 02:50:53 +01001/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2022 Thomas E. Dickey *
3 * Copyright 1998-2010,2017 Free Software Foundation, Inc. *
Steve Kondikae271bc2015-11-15 02:50:53 +01004 * *
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 *
micky3879b9f5e72025-07-08 18:04:53 -040033 * $Id: firstlast.c,v 1.10 2022/12/10 23:31:31 tom Exp $
Steve Kondikae271bc2015-11-15 02:50:53 +010034 */
35
36#include <test.priv.h>
37
38static void
39fill(WINDOW *w, const char *str)
40{
41 const char *s;
42 int x0 = -1, y0 = -1;
43 int x1, y1;
micky3879b9f5e72025-07-08 18:04:53 -040044 int maxx, maxy, limit;
45
46 getmaxyx(w, maxy, maxx);
47 wmove(w, 0, 0);
48 limit = maxy * maxx;
Steve Kondikae271bc2015-11-15 02:50:53 +010049
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 }
micky3879b9f5e72025-07-08 18:04:53 -040058 /* 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 }
Steve Kondikae271bc2015-11-15 02:50:53 +010068 x0 = x1;
69 y0 = y1;
70 }
71 }
72}
73
micky3879b9f5e72025-07-08 18:04:53 -040074static void
75usage(int ok)
76{
77 static const char *msg[] =
78 {
79 "Usage: firstlast [options]"
80 ,""
81 ,USAGE_COMMON
82 };
83 size_t n;
84
85 for (n = 0; n < SIZEOF(msg); n++)
86 fprintf(stderr, "%s\n", msg[n]);
87
88 ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
89}
90/* *INDENT-OFF* */
91VERSION_COMMON()
92/* *INDENT-ON* */
93
Steve Kondikae271bc2015-11-15 02:50:53 +010094int
micky3879b9f5e72025-07-08 18:04:53 -040095main(int argc, char *argv[])
Steve Kondikae271bc2015-11-15 02:50:53 +010096{
97 WINDOW *large, *small;
micky3879b9f5e72025-07-08 18:04:53 -040098 int ch;
99
100 while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
101 switch (ch) {
102 case OPTS_VERSION:
103 show_version(argv);
104 ExitProgram(EXIT_SUCCESS);
105 default:
106 usage(ch == OPTS_USAGE);
107 /* NOTREACHED */
108 }
109 }
110 if (optind < argc)
111 usage(FALSE);
112
Steve Kondikae271bc2015-11-15 02:50:53 +0100113 initscr();
114 noecho();
115
116 large = newwin(20, 60, 2, 10);
117 small = newwin(10, 30, 7, 25);
118
119 /* test 1 - addch */
120 fill(large, "LargeWindow");
121
122 refresh();
123 wrefresh(large);
124 wrefresh(small);
125
126 MvWAddStr(small, 5, 5, " Test <place to change> String ");
127 wrefresh(small);
128 getch();
129
130 touchwin(large);
131 wrefresh(large);
132
133 MvWAddStr(small, 5, 5, " Test <***************> String ");
134 wrefresh(small);
135
136 /* DIFFERENCE! */
137 getch();
138
139 /* test 2: erase */
140 erase();
141 refresh();
142 getch();
143
144 /* test 3: clrtoeol */
145 werase(small);
146 wrefresh(small);
147 touchwin(large);
148 wrefresh(large);
149 wmove(small, 5, 0);
150 waddstr(small, " clrtoeol>");
151 wclrtoeol(small);
152 wrefresh(small);
153
154 /* DIFFERENCE! */ ;
155 getch();
156
157 /* test 4: clrtobot */
158 werase(small);
159 wrefresh(small);
160 touchwin(large);
161 wrefresh(large);
162 wmove(small, 5, 3);
163 waddstr(small, " clrtobot>");
164 wclrtobot(small);
165 wrefresh(small);
166
167 /* DIFFERENCE! */
168 getch();
169
170 endwin();
171
172 ExitProgram(EXIT_SUCCESS);
173}