1 /****************************************************************************
2 * Copyright (c) 2015,2016 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.9 2016/06/18 23:54:35 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)
101 rc = restartterm(name, 0, f_opt ? NULL : &err);
104 rc = setupterm(name, 0, f_opt ? NULL : &err);
105 test_rc(name, rc, err);
111 static const char *msg[] =
113 "Usage: test_setupterm [options] [terminal]",
115 "Demonstrate error-checking for setupterm and restartterm.",
118 " -a automatic test for each success/error code",
119 " -f treat errors as fatal",
120 " -n set environment to disable terminfo database, assuming",
121 " the compiled-in paths for database also fail",
123 " -r test restartterm rather than setupterm",
127 for (n = 0; n < SIZEOF(msg); ++n) {
128 fprintf(stderr, "%s\n", msg[n]);
130 ExitProgram(EXIT_FAILURE);
134 main(int argc, char *argv[])
138 while ((n = getopt(argc, argv, "afnr")) != -1) {
161 static char none[][25] =
168 * We can turn this off, but not on again, because ncurses caches the
169 * directory locations.
171 printf("** without database\n");
172 for (n = 0; n < 3; ++n)
175 printf("** with database\n");
179 * The restartterm relies on an existing screen, so we make one here.
182 newterm("ansi", stdout, stdin);
187 static char predef[][9] =
188 {"vt100", "dumb", "lpr", "unknown", "none-such"};
192 for (n = 0; n < 4; ++n) {
193 test_setupterm(predef[n]);
197 for (n = optind; n < argc; ++n) {
198 test_setupterm(argv[n]);
201 test_setupterm(NULL);
205 ExitProgram(EXIT_SUCCESS);
208 #else /* !HAVE_TIGETSTR */
210 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
212 printf("This program requires the terminfo functions such as tigetstr\n");
213 ExitProgram(EXIT_FAILURE);
215 #endif /* HAVE_TIGETSTR */