1
/****************************************************************************
2
* Copyright (c) 2008 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.1 2008/12/20 22:06:52 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)
122
while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
128
show_status(WINDOW *win, STATUS * sp)
134
wprintw(win, "Count %d", sp->count);
136
wprintw(win, " Video %s", sp->v_msg);
138
wprintw(win, " Color %s", sp->c_msg);
144
reshow_status(WINDOW *win, STATUS * sp)
147
show_status(win, sp);
151
do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
153
WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
154
sp->y_beg + 1, sp->x_beg + 1);
156
if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
157
WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
176
init_status(WINDOW *win, STATUS * sp)
178
memset(sp, 0, sizeof(*sp));
186
getbegyx(win, sp->y_beg, sp->x_beg);
187
getmaxyx(win, sp->y_max, sp->x_max);
191
show_help(WINDOW *win)
193
static const char *table[] =
196
,"Use h/j/k/l or arrow keys to move the cursor."
197
,"Set the count parameter for insert/delete by entering digits 0-9."
200
,"space toggles through the set of video attributes and colors."
201
,"t touches (forces repaint) of the current line."
202
,"i calls insertln at the current position with the given count."
203
,"d calls deleteln at the window beginning with the given count."
204
,"I calls insdelln at the window beginning with the given count."
205
,"D calls insdelln at the window beginning with the given -count."
206
,"f refills the window with test-pattern using current attributes."
207
,"w recur to test windows other than stdscr"
209
,"= resets count to zero."
210
,"? shows this help-window"
218
getmaxyx(win, y_max, x_max);
219
for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) {
220
mvwprintw(win, row, 0, "%.*s", x_max, table[row]);
222
while (wgetch(win) != 'q')
227
update_status(WINDOW *win, STATUS * sp)
230
case ' ': /* next test-iteration */
232
if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
233
sp->c_msg = color_params(sp->c = 0, &(sp->pair));
234
if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
235
sp->v_msg = video_params(sp->v = 0, &(sp->attr));
239
if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
240
sp->v_msg = video_params(sp->v = 0, &(sp->attr));
244
show_status(win, sp);
249
wmove(win, sp->y_val, --(sp->x_val));
253
if (sp->y_val < sp->y_max)
254
wmove(win, ++(sp->y_val), sp->x_val);
259
wmove(win, --(sp->y_val), sp->x_val);
263
if (sp->x_val < sp->x_max)
264
wmove(win, sp->y_val, ++(sp->x_val));
267
touchline(win, sp->y_val, 1);
271
show_status(win, sp);
274
do_subwindow(win, sp, show_help);
277
if (isdigit(sp->ch)) {
278
sp->count = (sp->count * 10) + (sp->ch - '0');
279
show_status(win, sp);
288
test_winsdelln(WINDOW *win)
293
init_status(win, &st);
296
wattrset(win, st.attr | COLOR_PAIR(st.pair));
299
for (n = 0; n < st.count; ++n)
303
for (n = 0; n < st.count; ++n)
307
winsdelln(win, st.count);
310
winsdelln(win, -st.count);
314
reshow_status(win, &st);
317
do_subwindow(win, &st, test_winsdelln);
322
update_status(win, &st);
325
} while ((st.ch = wgetch(win)) != ERR);
334
init_status(stdscr, &st);
337
attrset(st.attr | COLOR_PAIR(st.pair));
340
for (n = 0; n < st.count; ++n)
344
for (n = 0; n < st.count; ++n)
355
reshow_status(stdscr, &st);
358
do_subwindow(stdscr, &st, test_winsdelln);
363
update_status(stdscr, &st);
366
} while ((st.ch = getch()) != ERR);
370
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
379
ExitProgram(EXIT_SUCCESS);