1 /****************************************************************************
2 * Copyright (c) 2015 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 ****************************************************************************/
30 * Author: Thomas E. Dickey
32 * $Id: test_setupterm.c,v 1.8 2015/06/28 00:53:46 tom Exp $
34 * A simple demo of setupterm/restartterm.
36 #include <test.priv.h>
40 static bool a_opt
= FALSE
;
41 static bool f_opt
= FALSE
;
42 static bool n_opt
= FALSE
;
43 static bool r_opt
= FALSE
;
46 test_rc(NCURSES_CONST
char *name
, int actual_rc
, int actual_err
)
52 name
= getenv("TERM");
57 case 'v': /* vt100 is normal */
58 case 'd': /* dumb has no special flags */
62 case 'l': /* lpr is hardcopy */
65 case 'u': /* unknown is generic */
76 ((actual_rc
== expect_rc
&& actual_err
== expect_err
)
79 printf(" '%s'", name
);
80 if (actual_rc
== expect_rc
) {
81 printf(" rc=%d", actual_rc
);
83 printf(" rc=%d (%d)", actual_rc
, expect_rc
);
85 if (actual_err
== expect_err
) {
86 printf(" err=%d", actual_err
);
88 printf(" err=%d (%d)", actual_err
, expect_err
);
94 test_setupterm(NCURSES_CONST
char *name
)
100 rc
= restartterm(name
, 0, f_opt
? NULL
: &err
);
102 rc
= setupterm(name
, 0, f_opt
? NULL
: &err
);
104 test_rc(name
, rc
, err
);
110 static const char *msg
[] =
112 "Usage: test_setupterm [options] [terminal]",
114 "Demonstrate error-checking for setupterm and restartterm.",
117 " -a automatic test for each success/error code",
118 " -f treat errors as fatal",
119 " -n set environment to disable terminfo database, assuming",
120 " the compiled-in paths for database also fail",
121 " -r test restartterm rather than setupterm",
124 for (n
= 0; n
< SIZEOF(msg
); ++n
) {
125 fprintf(stderr
, "%s\n", msg
[n
]);
127 ExitProgram(EXIT_FAILURE
);
131 main(int argc
, char *argv
[])
135 while ((n
= getopt(argc
, argv
, "afnr")) != -1) {
156 static char none
[][25] =
163 * We can turn this off, but not on again, because ncurses caches the
164 * directory locations.
166 printf("** without database\n");
167 for (n
= 0; n
< 3; ++n
)
170 printf("** with database\n");
174 * The restartterm relies on an existing screen, so we make one here.
177 newterm("ansi", stdout
, stdin
);
182 static char predef
[][9] =
183 {"vt100", "dumb", "lpr", "unknown", "none-such"};
187 for (n
= 0; n
< 4; ++n
) {
188 test_setupterm(predef
[n
]);
192 for (n
= optind
; n
< argc
; ++n
) {
193 test_setupterm(argv
[n
]);
196 test_setupterm(NULL
);
200 ExitProgram(EXIT_SUCCESS
);
203 #else /* !HAVE_TIGETSTR */
205 main(int argc GCC_UNUSED
, char *argv
[]GCC_UNUSED
)
207 printf("This program requires the terminfo functions such as tigetstr\n");
208 ExitProgram(EXIT_FAILURE
);
210 #endif /* HAVE_TIGETSTR */