1 /****************************************************************************
2 * Copyright (c) 2008-2014,2017 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.10 2017/04/15 17:40:11 tom Exp $
31 * test-driver for deleteln, wdeleteln, insdelln, winsdelln, insertln, winsertln
34 #include <test.priv.h>
35 #include <popup_msg.h>
37 #define SHOW(n) ((n) == ERR ? "ERR" : "OK")
38 #define COLOR_DEFAULT (-1)
56 color_params(unsigned state, int *pair)
64 { 0, COLOR_DEFAULT, COLOR_DEFAULT, "default" },
65 { 1, COLOR_RED, COLOR_BLACK, "red/black" },
66 { 2, COLOR_WHITE, COLOR_BLUE, "white/blue" },
70 static bool first = TRUE;
71 const char *result = 0;
78 for (n = 0; n < SIZEOF(table); ++n) {
79 init_pair(table[n].pair, table[n].fg, table[n].bg);
82 if (state < SIZEOF(table)) {
83 *pair = table[state].pair;
84 result = table[state].msg;
91 video_params(unsigned state, unsigned *attr)
98 { A_NORMAL, "normal" },
100 { A_REVERSE, "reverse" },
101 { A_UNDERLINE, "underline" },
102 { A_BLINK, "blink" },
106 const char *result = 0;
108 if (state < SIZEOF(table)) {
109 *attr = table[state].attr;
110 result = table[state].msg;
115 /* fill the window with a test-pattern */
117 fill_window(WINDOW *win)
120 int y0 = -1, x0 = -1;
124 while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
127 if (y1 == y0 && x1 == x0)
136 show_status(WINDOW *win, STATUS * sp)
142 wprintw(win, "Count %d", sp->count);
144 wprintw(win, " Video %s", sp->v_msg);
146 wprintw(win, " Color %s", sp->c_msg);
152 reshow_status(WINDOW *win, STATUS * sp)
155 show_status(win, sp);
159 do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
161 WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
162 sp->y_beg + 1, sp->x_beg + 1);
164 if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
165 WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
186 init_status(WINDOW *win, STATUS * sp)
188 memset(sp, 0, sizeof(*sp));
196 getbegyx(win, sp->y_beg, sp->x_beg);
197 getmaxyx(win, sp->y_max, sp->x_max);
201 show_help(WINDOW *win)
203 static const char *table[] =
206 ,"Use h/j/k/l or arrow keys to move the cursor."
207 ,"Set the count parameter for insert/delete by entering digits 0-9."
210 ,"space toggles through the set of video attributes and colors."
211 ,"t touches (forces repaint) of the current line."
212 ,"i calls insertln at the current position with the given count."
213 ,"d calls deleteln at the window beginning with the given count."
214 ,"I calls insdelln at the window beginning with the given count."
215 ,"D calls insdelln at the window beginning with the given -count."
216 ,"f refills the window with test-pattern using current attributes."
217 ,"w recur to test windows other than stdscr"
219 ,"= resets count to zero."
220 ,"? shows this help-window"
224 popup_msg(win, table);
228 update_status(WINDOW *win, STATUS * sp)
231 case ' ': /* next test-iteration */
233 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
234 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
235 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
236 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
240 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
241 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
245 show_status(win, sp);
250 wmove(win, sp->y_val, --(sp->x_val));
254 if (sp->y_val < sp->y_max)
255 wmove(win, ++(sp->y_val), sp->x_val);
260 wmove(win, --(sp->y_val), sp->x_val);
264 if (sp->x_val < sp->x_max)
265 wmove(win, sp->y_val, ++(sp->x_val));
268 touchline(win, sp->y_val, 1);
272 show_status(win, sp);
278 if (isdigit(sp->ch)) {
279 sp->count = (sp->count * 10) + (sp->ch - '0');
280 show_status(win, sp);
289 test_winsdelln(WINDOW *win)
294 init_status(win, &st);
297 (void) wattrset(win, AttrArg(COLOR_PAIR(st.pair), st.attr));
300 for (n = 0; n < st.count; ++n)
304 for (n = 0; n < st.count; ++n)
308 winsdelln(win, st.count);
311 winsdelln(win, -st.count);
315 reshow_status(win, &st);
318 do_subwindow(win, &st, test_winsdelln);
323 update_status(win, &st);
326 } while ((st.ch = wgetch(win)) != ERR);
335 init_status(stdscr, &st);
338 (void) attrset(AttrArg(COLOR_PAIR(st.pair), st.attr));
341 for (n = 0; n < st.count; ++n)
345 for (n = 0; n < st.count; ++n)
356 reshow_status(stdscr, &st);
359 do_subwindow(stdscr, &st, test_winsdelln);
364 update_status(stdscr, &st);
367 } while ((st.ch = getch()) != ERR);
371 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
380 ExitProgram(EXIT_SUCCESS);