summaryrefslogtreecommitdiff
path: root/tests/resize_failure_test.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 11:31:50 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 11:31:50 +0300
commitacd338ea33de36d223cc6d301712eed4a9501e6c (patch)
treed93c46a97e2ed4e8a86e3402de5f847cdc144ec8 /tests/resize_failure_test.c
parentf97c3a585e2efc1d0a4bc10e6ac04b96ee6428ea (diff)
Fix snapshot storage and allocation failure correctness
Account for cluster records discarded by snapshot scrolling, propagate snapshot allocation failures with an empty retryable view, and allocate resized screens before mutating visible state. Add bounded-memory and allocation-failure regressions, and update the saved diagnostic and audit report.
Diffstat (limited to 'tests/resize_failure_test.c')
-rw-r--r--tests/resize_failure_test.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/resize_failure_test.c b/tests/resize_failure_test.c
index 5d7e63c..fbfa38d 100644
--- a/tests/resize_failure_test.c
+++ b/tests/resize_failure_test.c
@@ -146,6 +146,57 @@ int main(void)
assert(tt_cols(term) == 10);
term_free(term);
+ /* A failed same-width height shrink must not scroll rows into history or
+ * move the cursor. The same resize must succeed when allocation recovers. */
+ term = tt_new(8, 4);
+ assert(term);
+ const char four_rows[] = "A\r\nB\r\nC\r\nD";
+ tt_write(term, four_rows, sizeof four_rows - 1);
+ assert(tt_cursor_y(term) == 3);
+ assert(tt_history(term) == 0);
+
+ fail_next_calloc = true;
+ resized = tt_resize(term, 8, 2);
+ assert(!fail_next_calloc);
+ assert(!resized);
+ assert(tt_cols(term) == 8 && tt_rows(term) == 4);
+ assert(tt_cell(term, 0, 0)->text == 'A');
+ assert(tt_cell(term, 0, 1)->text == 'B');
+ assert(tt_cell(term, 0, 2)->text == 'C');
+ assert(tt_cell(term, 0, 3)->text == 'D');
+ assert(tt_cursor_y(term) == 3);
+ assert(tt_history(term) == 0);
+
+ resized = tt_resize(term, 8, 2);
+ assert(resized);
+ assert(tt_cols(term) == 8 && tt_rows(term) == 2);
+ assert(tt_cell(term, 0, 0)->text == 'C');
+ assert(tt_cell(term, 0, 1)->text == 'D');
+ assert(tt_cursor_y(term) == 1);
+ assert(tt_history(term) == 2);
+ term_free(term);
+
+ /* The alternate screen uses the same allocation-before-scroll path. */
+ term = tt_new(8, 4);
+ assert(term);
+ tt_write(term, "\033[?1049h", 8);
+ tt_write(term, four_rows, sizeof four_rows - 1);
+ assert(term_modes(term).alternate);
+ assert(tt_cursor_y(term) == 3);
+ fail_next_calloc = true;
+ resized = tt_resize(term, 8, 2);
+ assert(!fail_next_calloc);
+ assert(!resized);
+ assert(tt_rows(term) == 4 && tt_cursor_y(term) == 3);
+ assert(tt_cell(term, 0, 0)->text == 'A');
+ assert(tt_cell(term, 0, 3)->text == 'D');
+ resized = tt_resize(term, 8, 2);
+ assert(resized);
+ assert(tt_rows(term) == 2 && tt_cursor_y(term) == 1);
+ assert(tt_cell(term, 0, 0)->text == 'C');
+ assert(tt_cell(term, 0, 1)->text == 'D');
+ term_free(term);
+
puts("lazy screen allocation failures preserve observable terminal state");
return 0;
#endif