1 /****************************************************************************
2 * Copyright (c) 2008,2009 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.3 2009/08/29 18:47:26 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);
183 init_status(WINDOW *win, STATUS * sp)
185 memset(sp, 0, sizeof(*sp));
193 getbegyx(win, sp->y_beg, sp->x_beg);
194 getmaxyx(win, sp->y_max, sp->x_max);
198 show_help(WINDOW *win)
200 static const char *table[] =
203 ,"Use h/j/k/l or arrow keys to move the cursor."
204 ,"Set the count parameter for insert/delete by entering digits 0-9."
207 ,"space toggles through the set of video attributes and colors."
208 ,"t touches (forces repaint) of the current line."
209 ,"i calls insertln at the current position with the given count."
210 ,"d calls deleteln at the window beginning with the given count."
211 ,"I calls insdelln at the window beginning with the given count."
212 ,"D calls insdelln at the window beginning with the given -count."
213 ,"f refills the window with test-pattern using current attributes."
214 ,"w recur to test windows other than stdscr"
216 ,"= resets count to zero."
217 ,"? shows this help-window"
225 getmaxyx(win, y_max, x_max);
226 for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) {
227 mvwprintw(win, row, 0, "%.*s", x_max, table[row]);
229 while (wgetch(win) != 'q')
234 update_status(WINDOW *win, STATUS * sp)
237 case ' ': /* next test-iteration */
239 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
240 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
241 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
242 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
246 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
247 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
251 show_status(win, sp);
256 wmove(win, sp->y_val, --(sp->x_val));
260 if (sp->y_val < sp->y_max)
261 wmove(win, ++(sp->y_val), sp->x_val);
266 wmove(win, --(sp->y_val), sp->x_val);
270 if (sp->x_val < sp->x_max)
271 wmove(win, sp->y_val, ++(sp->x_val));
274 touchline(win, sp->y_val, 1);
278 show_status(win, sp);
281 do_subwindow(win, sp, show_help);
284 if (isdigit(sp->ch)) {
285 sp->count = (sp->count * 10) + (sp->ch - '0');
286 show_status(win, sp);
295 test_winsdelln(WINDOW *win)
300 init_status(win, &st);
303 (void) wattrset(win, st.attr | COLOR_PAIR(st.pair));
306 for (n = 0; n < st.count; ++n)
310 for (n = 0; n < st.count; ++n)
314 winsdelln(win, st.count);
317 winsdelln(win, -st.count);
321 reshow_status(win, &st);
324 do_subwindow(win, &st, test_winsdelln);
329 update_status(win, &st);
332 } while ((st.ch = wgetch(win)) != ERR);
341 init_status(stdscr, &st);
344 (void) attrset(st.attr | COLOR_PAIR(st.pair));
347 for (n = 0; n < st.count; ++n)
351 for (n = 0; n < st.count; ++n)
362 reshow_status(stdscr, &st);
365 do_subwindow(stdscr, &st, test_winsdelln);
370 update_status(stdscr, &st);
373 } while ((st.ch = getch()) != ERR);
377 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
386 ExitProgram(EXIT_SUCCESS);