1 /****************************************************************************
2 * Copyright (c) 2008-2010,2012 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.7 2012/11/18 00:37:58 tom Exp $
31 * test-driver for deleteln, wdeleteln, insdelln, winsdelln, insertln, winsertln
34 #include <test.priv.h>
36 #define SHOW(n) ((n) == ERR ? "ERR" : "OK")
37 #define COLOR_DEFAULT (-1)
55 color_params(unsigned state, int *pair)
63 { 0, COLOR_DEFAULT, COLOR_DEFAULT, "default" },
64 { 1, COLOR_RED, COLOR_BLACK, "red/black" },
65 { 2, COLOR_WHITE, COLOR_BLUE, "white/blue" },
69 static bool first = TRUE;
70 const char *result = 0;
77 for (n = 0; n < SIZEOF(table); ++n) {
78 init_pair(table[n].pair, table[n].fg, table[n].bg);
81 if (state < SIZEOF(table)) {
82 *pair = table[state].pair;
83 result = table[state].msg;
90 video_params(unsigned state, unsigned *attr)
97 { A_NORMAL, "normal" },
99 { A_REVERSE, "reverse" },
100 { A_UNDERLINE, "underline" },
101 { A_BLINK, "blink" },
105 const char *result = 0;
107 if (state < SIZEOF(table)) {
108 *attr = table[state].attr;
109 result = table[state].msg;
114 /* fill the window with a test-pattern */
116 fill_window(WINDOW *win)
119 int y0 = -1, x0 = -1;
123 while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
126 if (y1 == y0 && x1 == x0)
135 show_status(WINDOW *win, STATUS * sp)
141 wprintw(win, "Count %d", sp->count);
143 wprintw(win, " Video %s", sp->v_msg);
145 wprintw(win, " Color %s", sp->c_msg);
151 reshow_status(WINDOW *win, STATUS * sp)
154 show_status(win, sp);
158 do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
160 WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
161 sp->y_beg + 1, sp->x_beg + 1);
163 if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
164 WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
185 init_status(WINDOW *win, STATUS * sp)
187 memset(sp, 0, sizeof(*sp));
195 getbegyx(win, sp->y_beg, sp->x_beg);
196 getmaxyx(win, sp->y_max, sp->x_max);
200 show_help(WINDOW *win)
202 static const char *table[] =
205 ,"Use h/j/k/l or arrow keys to move the cursor."
206 ,"Set the count parameter for insert/delete by entering digits 0-9."
209 ,"space toggles through the set of video attributes and colors."
210 ,"t touches (forces repaint) of the current line."
211 ,"i calls insertln at the current position with the given count."
212 ,"d calls deleteln at the window beginning with the given count."
213 ,"I calls insdelln at the window beginning with the given count."
214 ,"D calls insdelln at the window beginning with the given -count."
215 ,"f refills the window with test-pattern using current attributes."
216 ,"w recur to test windows other than stdscr"
218 ,"= resets count to zero."
219 ,"? shows this help-window"
227 getmaxyx(win, y_max, x_max);
228 for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) {
229 MvWPrintw(win, row, 0, "%.*s", x_max, table[row]);
231 while (wgetch(win) != 'q')
236 update_status(WINDOW *win, STATUS * sp)
239 case ' ': /* next test-iteration */
241 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
242 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
243 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
244 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
248 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
249 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
253 show_status(win, sp);
258 wmove(win, sp->y_val, --(sp->x_val));
262 if (sp->y_val < sp->y_max)
263 wmove(win, ++(sp->y_val), sp->x_val);
268 wmove(win, --(sp->y_val), sp->x_val);
272 if (sp->x_val < sp->x_max)
273 wmove(win, sp->y_val, ++(sp->x_val));
276 touchline(win, sp->y_val, 1);
280 show_status(win, sp);
283 do_subwindow(win, sp, show_help);
286 if (isdigit(sp->ch)) {
287 sp->count = (sp->count * 10) + (sp->ch - '0');
288 show_status(win, sp);
297 test_winsdelln(WINDOW *win)
302 init_status(win, &st);
305 (void) wattrset(win, (int) (st.attr | (attr_t) COLOR_PAIR(st.pair)));
308 for (n = 0; n < st.count; ++n)
312 for (n = 0; n < st.count; ++n)
316 winsdelln(win, st.count);
319 winsdelln(win, -st.count);
323 reshow_status(win, &st);
326 do_subwindow(win, &st, test_winsdelln);
331 update_status(win, &st);
334 } while ((st.ch = wgetch(win)) != ERR);
343 init_status(stdscr, &st);
346 (void) attrset(st.attr | (attr_t) COLOR_PAIR(st.pair));
349 for (n = 0; n < st.count; ++n)
353 for (n = 0; n < st.count; ++n)
364 reshow_status(stdscr, &st);
367 do_subwindow(stdscr, &st, test_winsdelln);
372 update_status(stdscr, &st);
375 } while ((st.ch = getch()) != ERR);
379 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
388 ExitProgram(EXIT_SUCCESS);