Skip to content

Commit

Permalink
'del_test' (test of deleting windows and sub-windows) crashes on many…
Browse files Browse the repository at this point in the history
… systems; you need getch( ) delays so you can see the exact point of failure. Also, the description of what's happening was not very good.
  • Loading branch information
Bill-Gray committed Jul 15, 2024
1 parent f557531 commit 21d190b
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions tests/del_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,56 @@ to crash the second time 'win' is deleted.
We were not clear as to what is 'supposed' to be done here
according to the X/Open and SVr4 standards. But in actual practice,
it's clearly dangerous to do either of the things described in the
two questions above.
PDCursesMod will assert() if you delete a window with a parent.
(It maintains a list of active windows, and will also assert() if
you attempt to 're-delete' a window, or more generally, pass in
a pointer to delwin() that isn't actually a current window.) */
two questions above. Portable curses code should delete windows
only once, and should never delete a window with a subwindow.
PDCursesMod will assert() if you attempt to do either of these.
More generally, it maintains a list of "current" windows and will
assert() if you pass a pointer to delwin() that isn't actually a
valid window. */

int main( void)
{
WINDOW *win, *sub;
SCREEN *screen = newterm( NULL, NULL, NULL);
char buff[90];
int line = 1;

noecho();
mvaddstr( line++, 1, "Code to test deleting windows. References :");
mvaddstr( line++, 1, "https://www.invisible-island.net/ncurses/man/curs_window.3x.html");
mvprintw( line++, 1, "https://lists.gnu.org/archive/html/bug-ncurses/2022-08/msg00006.html");
mvprintw( line++, 1, "Source code for this program (del_test.c)");
line++;
win = newwin( 0, 0, 0, 0);
move( 1, 1);
snprintf( buff, sizeof( buff), "New window %p %s", (void *)win, longname( ));
addstr( buff);
move( 2, 1);
snprintf( buff, sizeof( buff), "Allocated new window %p %s", (void *)win, longname( ));
mvaddstr( line++, 1, buff);
sub = subwin( win, 10, 10, 10, 10);
snprintf( buff, sizeof( buff), "Sub window %p %s", (void *)sub, curses_version( ));
mvaddstr( 2, 1, buff);
snprintf( buff, sizeof( buff), "Deleted win : %d (should fail, it still has a subwindow)", delwin( win));
mvaddstr( 4, 1, buff);
mvaddstr( line++, 1, buff);
mvaddstr( line++, 1, "Next step will attempt to delete the window. Should fail, since");
mvaddstr( line++, 1, "it has a subwindow. Hit any key :");
getch( );
snprintf( buff, sizeof( buff), "Window deleted with return value %d", delwin( win));
mvaddstr( line++, 1, buff);
line++;
mvaddstr( line++, 1, "Will now attempt to delete the sub-window.");
mvaddstr( line++, 1, "That ought to succeed. Hit any key :");
getch( );
snprintf( buff, sizeof( buff), "Deleted sub : %d (should succeed)", delwin( sub));
mvaddstr( 5, 1, buff);
snprintf( buff, sizeof( buff), "Deleted win : %d (should succeed, it doesn't have a subwin now)", delwin( win));
mvaddstr( 6, 1, buff);
snprintf( buff, sizeof( buff), "Deleted win : %d (should fail, it'd be a re-deletion)", delwin( win));
mvaddstr( 7, 1, buff);

mvaddstr( 9, 1, "References :");
mvaddstr( 10, 1, "https://www.invisible-island.net/ncurses/man/curs_window.3x.html");
mvprintw( 11, 1, "https://lists.gnu.org/archive/html/bug-ncurses/2022-08/msg00006.html");
mvaddstr( 12, 1, "Hit the any key:");
mvaddstr( line++, 1, buff);
line++;
mvaddstr( line++, 1, "Will now attempt to delete the parent window. This should succeed,");
mvaddstr( line++, 1, "since it no longer has a sub-window. Hit any key :");
getch( );
snprintf( buff, sizeof( buff), "Deleted win : %d", delwin( win));
mvaddstr( line++, 1, buff);
line++;
mvaddstr( line++, 1, "Now we'll delete that window again, which should fail.");
mvaddstr( line++, 1, "Hit any key :");
getch( );
snprintf( buff, sizeof( buff), "Deleted win : %d", delwin( win));
mvaddstr( line++, 1, buff);
mvaddstr( line++, 1, "And we're done. Hit any key to exit :");
getch( );
endwin( );
delscreen( screen);
Expand Down

0 comments on commit 21d190b

Please sign in to comment.