1 /****************************************************************************
2 * Copyright (c) 2008-2017,2019 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: insdelln.c,v 1.13 2019/08/24 23:11:01 tom Exp $
31 * test-driver for deleteln, wdeleteln, insdelln, winsdelln, insertln, winsertln
34 #include <test.priv.h>
38 #include <popup_msg.h>
40 #define SHOW(n) ((n) == ERR ? "ERR" : "OK")
41 #define COLOR_DEFAULT (-1)
59 color_params(unsigned state, int *pair)
67 { 0, COLOR_DEFAULT, COLOR_DEFAULT, "default" },
68 { 1, COLOR_RED, COLOR_BLACK, "red/black" },
69 { 2, COLOR_WHITE, COLOR_BLUE, "white/blue" },
73 const char *result = 0;
76 static bool first = TRUE;
81 for (n = 0; n < SIZEOF(table); ++n) {
82 init_pair(table[n].pair, table[n].fg, table[n].bg);
85 if (state < SIZEOF(table)) {
86 *pair = table[state].pair;
87 result = table[state].msg;
94 video_params(unsigned state, unsigned *attr)
101 { A_NORMAL, "normal" },
103 { A_REVERSE, "reverse" },
104 { A_UNDERLINE, "underline" },
105 { A_BLINK, "blink" },
109 const char *result = 0;
111 if (state < SIZEOF(table)) {
112 *attr = table[state].attr;
113 result = table[state].msg;
118 /* fill the window with a test-pattern */
120 fill_window(WINDOW *win)
123 int y0 = -1, x0 = -1;
127 while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
130 if (y1 == y0 && x1 == x0)
139 show_status(WINDOW *win, STATUS * sp)
145 wprintw(win, "Count %d", sp->count);
147 wprintw(win, " Video %s", sp->v_msg);
149 wprintw(win, " Color %s", sp->c_msg);
155 reshow_status(WINDOW *win, STATUS * sp)
158 show_status(win, sp);
162 do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
164 WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
165 sp->y_beg + 1, sp->x_beg + 1);
167 if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
168 WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
189 init_status(WINDOW *win, STATUS * sp)
191 memset(sp, 0, sizeof(*sp));
199 getbegyx(win, sp->y_beg, sp->x_beg);
200 getmaxyx(win, sp->y_max, sp->x_max);
204 show_help(WINDOW *win)
206 static const char *table[] =
209 ,"Use h/j/k/l or arrow keys to move the cursor."
210 ,"Set the count parameter for insert/delete by entering digits 0-9."
213 ,"space toggles through the set of video attributes and colors."
214 ,"t touches (forces repaint) of the current line."
215 ,"i calls insertln at the current position with the given count."
216 ,"d calls deleteln at the window beginning with the given count."
217 ,"I calls insdelln at the window beginning with the given count."
218 ,"D calls insdelln at the window beginning with the given -count."
219 ,"f refills the window with test-pattern using current attributes."
220 ,"w recur to test windows other than stdscr"
222 ,"= resets count to zero."
223 ,"? shows this help-window"
227 popup_msg(win, table);
231 update_status(WINDOW *win, STATUS * sp)
234 case ' ': /* next test-iteration */
236 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
237 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
238 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
239 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
243 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
244 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
248 show_status(win, sp);
253 wmove(win, sp->y_val, --(sp->x_val));
257 if (sp->y_val < sp->y_max)
258 wmove(win, ++(sp->y_val), sp->x_val);
263 wmove(win, --(sp->y_val), sp->x_val);
267 if (sp->x_val < sp->x_max)
268 wmove(win, sp->y_val, ++(sp->x_val));
271 touchline(win, sp->y_val, 1);
275 show_status(win, sp);
281 if (isdigit(sp->ch)) {
282 sp->count = (sp->count * 10) + (sp->ch - '0');
283 show_status(win, sp);
292 test_winsdelln(WINDOW *win)
297 init_status(win, &st);
300 (void) wattrset(win, AttrArg(COLOR_PAIR(st.pair), st.attr));
303 for (n = 0; n < st.count; ++n)
307 for (n = 0; n < st.count; ++n)
311 winsdelln(win, st.count);
314 winsdelln(win, -st.count);
318 reshow_status(win, &st);
321 do_subwindow(win, &st, test_winsdelln);
326 update_status(win, &st);
329 } while ((st.ch = wgetch(win)) != ERR);
338 init_status(stdscr, &st);
341 (void) attrset(AttrArg(COLOR_PAIR(st.pair), st.attr));
344 for (n = 0; n < st.count; ++n)
348 for (n = 0; n < st.count; ++n)
359 reshow_status(stdscr, &st);
362 do_subwindow(stdscr, &st, test_winsdelln);
367 update_status(stdscr, &st);
370 } while ((st.ch = getch()) != ERR);
374 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
383 ExitProgram(EXIT_SUCCESS);
390 printf("This program requires the curses winsdelln function\n");
391 ExitProgram(EXIT_FAILURE);