1 /****************************************************************************
2 * Copyright 2022 Thomas E. Dickey *
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 * $Id: test_delwin.c,v 1.4 2022/12/10 22:14:07 tom Exp $
32 #include <test.priv.h>
36 static SCREEN *my_screen;
39 show_rc(const char *what, const char *explain, int rc)
41 printw("%s : %d (%s)\n", what, rc, explain);
45 next_step(WINDOW *win)
48 if (ch == QUIT || ch == ESCAPE) {
50 /* use this to verify if delscreen frees all memory */
59 static const char *msg[] =
61 "Usage: test_delwin [options]"
67 for (n = 0; n < SIZEOF(msg); n++)
68 fprintf(stderr, "%s\n", msg[n]);
70 ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
77 main(int argc, char **argv)
79 WINDOW *parent, *child1;
83 while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
87 ExitProgram(EXIT_SUCCESS);
89 usage(ch == OPTS_USAGE);
96 if ((my_screen = newterm(NULL, stdout, stdin)) == NULL)
97 ExitProgram(EXIT_FAILURE);
103 wsetscrreg(stdscr, 0, STATUS - 1);
104 scrollok(stdscr, TRUE);
106 parent = newwin(0, 0, STATUS, 0);
111 printw("New window %p %s\n", (void *) parent, "Top window");
112 mvwprintw(parent, 1, 1, "Top window");
116 child1 = derwin(parent, LINES - STATUS - 4, COLS - 4, 2, 2);
118 mvwprintw(child1, 1, 1, "Sub window");
121 printw("Sub window %p %s\n", (void *) child1, "Hello world!");
124 show_rc("Deleted parent",
125 "should fail, it still has a subwindow",
126 rc = delwin(parent));
128 show_rc("Deleted child1",
130 rc = delwin(child1));
137 show_rc("Deleted parent",
138 "should succeed, it has no subwindow now",
139 rc = delwin(parent));
145 show_rc("Deleted parent",
146 "should fail, may dump core",
150 ExitProgram(EXIT_SUCCESS);