diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 13:04:32 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 13:04:32 +0300 |
| commit | bdaedce69b17b654bd0060579dd9b9ff120009b5 (patch) | |
| tree | 0e9cd8597652263a96c48ba678fb0b66e1fc131b /tests/snapshot_failure_test.c | |
| parent | ba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff) | |
| parent | dcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff) | |
Merge branch 'wt/rename' into api-hardening
# Conflicts:
# README.md
Diffstat (limited to 'tests/snapshot_failure_test.c')
| -rw-r--r-- | tests/snapshot_failure_test.c | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/tests/snapshot_failure_test.c b/tests/snapshot_failure_test.c index 7d4b139..bf4b694 100644 --- a/tests/snapshot_failure_test.c +++ b/tests/snapshot_failure_test.c @@ -1,4 +1,4 @@ -#include "term/term.h" +#include "wsap_vtcore/wsap_vtcore.h" #include <assert.h> #include <stdbool.h> @@ -49,18 +49,18 @@ void *__wrap_realloc(void *p, size_t size) /* A copy of everything a renderer can read from a snapshot. */ struct frame { - struct term_view view; - uint32_t palette[TERM_PALETTE_SIZE]; + struct wsap_vtcore_view view; + uint32_t palette[WSAP_VTCORE_PALETTE_SIZE]; int cols, rows; - struct term_cell *cells; /* rows * cols */ + struct wsap_vtcore_cell *cells; /* rows * cols */ uint32_t *cps; /* per cell: count, then code points */ uint64_t *keys; /* per row */ - struct term_span *sel; /* per row */ + struct wsap_vtcore_span *sel; /* per row */ }; -static void frame_capture(const struct term_snapshot *s, struct frame *f) +static void frame_capture(const struct wsap_vtcore_snapshot *s, struct frame *f) { - const struct term_view *v = term_snapshot_view(s); + const struct wsap_vtcore_view *v = wsap_vtcore_snapshot_view(s); f->view = *v; memcpy(f->palette, v->palette, sizeof(f->palette)); f->cols = v->size.x; @@ -72,17 +72,17 @@ static void frame_capture(const struct term_snapshot *s, struct frame *f) f->sel = calloc((size_t)f->rows + 1, sizeof(*f->sel)); assert(f->cells && f->cps && f->keys && f->sel); for (int y = 0; y < f->rows; y++) { - const struct term_cell *row = term_snapshot_row(s, y); + const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, y); assert(row); - f->keys[y] = term_snapshot_row_key(s, y); - f->sel[y] = term_snapshot_row_selection(s, y); + f->keys[y] = wsap_vtcore_snapshot_row_key(s, y); + f->sel[y] = wsap_vtcore_snapshot_row_selection(s, y); for (int x = 0; x < f->cols; x++) { size_t i = (size_t)y * f->cols + x; f->cells[i] = row[x]; uint32_t *cps = f->cps + i * CPS_SLOT; cps[0] = 0; - if (row[x].text & TERM_TEXT_CLUSTER) - cps[0] = (uint32_t)term_snapshot_cluster(s, row[x].text, cps + 1, CPS_MAX); + if (row[x].text & WSAP_VTCORE_TEXT_CLUSTER) + cps[0] = (uint32_t)wsap_vtcore_snapshot_cluster(s, row[x].text, cps + 1, CPS_MAX); } } } @@ -97,7 +97,7 @@ static void frame_free(struct frame *f) static bool same_view(const struct frame *a, const struct frame *b) { - const struct term_view *x = &a->view, *y = &b->view; + const struct wsap_vtcore_view *x = &a->view, *y = &b->view; return x->size.x == y->size.x && x->size.y == y->size.y && x->cursor.pos.x == y->cursor.pos.x && x->cursor.pos.y == y->cursor.pos.y && x->cursor.style == y->cursor.style && x->cursor.visible == y->cursor.visible && @@ -125,7 +125,7 @@ static bool frame_same(const struct frame *a, const struct frame *b) * between an incremental snapshot and a fresh one. */ static bool frame_shows_same(const struct frame *a, const struct frame *b) { - const struct term_view *x = &a->view, *y = &b->view; + const struct wsap_vtcore_view *x = &a->view, *y = &b->view; if (a->cols != b->cols || a->rows != b->rows || x->cursor.pos.x != y->cursor.pos.x || x->cursor.pos.y != y->cursor.pos.y || x->cursor.visible != y->cursor.visible || x->scroll_offset != y->scroll_offset || x->reverse_video != y->reverse_video || @@ -136,11 +136,11 @@ static bool frame_shows_same(const struct frame *a, const struct frame *b) return false; for (int c = 0; c < a->cols; c++) { size_t i = (size_t)r * a->cols + c; - const struct term_cell *p = &a->cells[i], *q = &b->cells[i]; + const struct wsap_vtcore_cell *p = &a->cells[i], *q = &b->cells[i]; const uint32_t *cp = a->cps + i * CPS_SLOT, *cq = b->cps + i * CPS_SLOT; if (p->fg != q->fg || p->bg != q->bg || p->attrs != q->attrs || p->width != q->width) return false; - if (p->text & TERM_TEXT_CLUSTER) { + if (p->text & WSAP_VTCORE_TEXT_CLUSTER) { if (cp[0] != cq[0] || memcmp(cp + 1, cq + 1, cp[0] * sizeof(*cp)) != 0) return false; } else if (p->text != q->text) { @@ -154,13 +154,13 @@ static bool frame_shows_same(const struct frame *a, const struct frame *b) /* One update with the k-th allocation failing, from the state the caller * built. A failed update must leave s as it was, and the retry must succeed. * Returns true when an allocation was failed. */ -static bool update_failing_at(struct term_snapshot *s, struct term *t, int k) +static bool update_failing_at(struct wsap_vtcore_snapshot *s, struct wsap_vtcore *t, int k) { struct frame before, after; frame_capture(s, &before); alloc_was_failed = false; alloc_countdown = k; - bool ok = term_snapshot_update(s, t); + bool ok = wsap_vtcore_snapshot_update(s, t); alloc_countdown = -1; bool injected = alloc_was_failed; if (!ok) { @@ -168,7 +168,7 @@ static bool update_failing_at(struct term_snapshot *s, struct term *t, int k) frame_capture(s, &after); assert(frame_same(&before, &after)); frame_free(&after); - assert(term_snapshot_update(s, t)); + assert(wsap_vtcore_snapshot_update(s, t)); } frame_free(&before); return injected; @@ -191,7 +191,7 @@ static int sweep(bool (*attempt)(int k)) * an update succeeds. Every failed attempt must leave s as it was. Progress * from earlier attempts stays, so this covers the later steps of a long run * rather than each site from one start. Returns the number of failures. */ -static int update_each_failure(struct term_snapshot *s, struct term *t) +static int update_each_failure(struct wsap_vtcore_snapshot *s, struct wsap_vtcore *t) { struct frame before, after; frame_capture(s, &before); @@ -201,7 +201,7 @@ static int update_each_failure(struct term_snapshot *s, struct term *t) assert(k < 1000); alloc_was_failed = false; alloc_countdown = k; - ok = term_snapshot_update(s, t); + ok = wsap_vtcore_snapshot_update(s, t); alloc_countdown = -1; if (ok) break; @@ -216,53 +216,53 @@ static int update_each_failure(struct term_snapshot *s, struct term *t) } /* A renderer sees the same picture as a fresh capture of t. */ -static void expect_matches_fresh(struct term *t, const struct term_snapshot *s) +static void expect_matches_fresh(struct wsap_vtcore *t, const struct wsap_vtcore_snapshot *s) { - struct term_snapshot *fresh = term_snapshot_new(); - assert(fresh && term_snapshot_update(fresh, t)); + struct wsap_vtcore_snapshot *fresh = wsap_vtcore_snapshot_new(); + assert(fresh && wsap_vtcore_snapshot_update(fresh, t)); struct frame a, b; frame_capture(s, &a); frame_capture(fresh, &b); assert(frame_shows_same(&a, &b)); frame_free(&a); frame_free(&b); - term_snapshot_free(fresh); + wsap_vtcore_snapshot_free(fresh); } /* A US flag and a ZWJ family: two regional indicators, and five code points. */ static const char flag_us[] = "\xf0\x9f\x87\xba\xf0\x9f\x87\xb8"; static const char family[] = "\xf0\x9f\x91\xa8\xe2\x80\x8d\xf0\x9f\x91\xa9\xe2\x80\x8d\xf0\x9f\x91\xa7"; -static uint32_t cluster_cps(const struct term_snapshot *s, const struct term_cell *cell, +static uint32_t cluster_cps(const struct wsap_vtcore_snapshot *s, const struct wsap_vtcore_cell *cell, uint32_t *cps, int cap) { - return (uint32_t)term_snapshot_cluster(s, cell->text, cps, cap); + return (uint32_t)wsap_vtcore_snapshot_cluster(s, cell->text, cps, cap); } /* A new terminal and an empty snapshot. The first update grows every buffer * and the arena, so each allocation site in the update is hit. */ static bool first_update_at(int k) { - struct term_options options = { .size = { 8, 3 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 8, 3 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); const char accented[] = "e\xcc\x81 "; - term_feed(t, accented, sizeof(accented) - 1, 0); - term_feed(t, flag_us, sizeof(flag_us) - 1, 0); + wsap_vtcore_feed(t, accented, sizeof(accented) - 1, 0); + wsap_vtcore_feed(t, flag_us, sizeof(flag_us) - 1, 0); bool injected = update_failing_at(s, t, k); - const struct term_cell *row = term_snapshot_row(s, 0); - assert(row && (row[0].text & TERM_TEXT_CLUSTER)); + const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, 0); + assert(row && (row[0].text & WSAP_VTCORE_TEXT_CLUSTER)); uint32_t cps[8]; assert(cluster_cps(s, &row[0], cps, 8) == 2 && cps[0] == 'e' && cps[1] == 0x301); assert(cluster_cps(s, &row[2], cps, 8) == 2 && cps[0] == 0x1F1FA && cps[1] == 0x1F1F8); expect_matches_fresh(t, s); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); return injected; } @@ -270,60 +270,60 @@ static bool first_update_at(int k) * 256 words, so the arena growth is one of the failing sites. */ static bool full_cluster_screen_at(int k) { - struct term_options options = { .size = { 32, 16 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 32, 16 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); for (int y = 0; y < 16; y++) { for (int i = 0; i < 16; i++) { if (y % 2) - term_feed(t, flag_us, sizeof(flag_us) - 1, 0); + wsap_vtcore_feed(t, flag_us, sizeof(flag_us) - 1, 0); else - term_feed(t, family, sizeof(family) - 1, 0); + wsap_vtcore_feed(t, family, sizeof(family) - 1, 0); } if (y < 15) - term_feed(t, "\r\n", 2, 0); + wsap_vtcore_feed(t, "\r\n", 2, 0); } bool injected = update_failing_at(s, t, k); uint32_t cps[8]; - const struct term_cell *row = term_snapshot_row(s, 0); + const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, 0); assert(cluster_cps(s, &row[0], cps, 8) == 5 && cps[0] == 0x1F468 && cps[1] == 0x200D); - row = term_snapshot_row(s, 1); + row = wsap_vtcore_snapshot_row(s, 1); assert(cluster_cps(s, &row[0], cps, 8) == 2 && cps[0] == 0x1F1FA); expect_matches_fresh(t, s); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); return injected; } /* The screen grows, so cells, keys, row clusters, and selection all reserve. */ static bool resize_at(int k) { - struct term_options options = { .size = { 8, 3 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 8, 3 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); - term_feed(t, "old", 3, 0); - assert(term_snapshot_update(s, t)); + wsap_vtcore_feed(t, "old", 3, 0); + assert(wsap_vtcore_snapshot_update(s, t)); - assert(term_resize(t, (struct term_vector2i){ 32, 16 })); - term_feed(t, "\x1b[H\x1b[2J", 7, 0); - term_feed(t, family, sizeof(family) - 1, 0); + assert(wsap_vtcore_resize(t, (struct wsap_vtcore_vector2i){ 32, 16 })); + wsap_vtcore_feed(t, "\x1b[H\x1b[2J", 7, 0); + wsap_vtcore_feed(t, family, sizeof(family) - 1, 0); bool injected = update_failing_at(s, t, k); - assert(term_snapshot_view(s)->size.x == 32 && term_snapshot_view(s)->size.y == 16); + assert(wsap_vtcore_snapshot_view(s)->size.x == 32 && wsap_vtcore_snapshot_view(s)->size.y == 16); uint32_t cps[8]; - const struct term_cell *row = term_snapshot_row(s, 0); + const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, 0); assert(cluster_cps(s, &row[0], cps, 8) == 5 && cps[0] == 0x1F468); expect_matches_fresh(t, s); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); return injected; } @@ -331,124 +331,124 @@ static bool resize_at(int k) * row list, off the stack. */ static bool tall_screen_at(int k) { - struct term_options options = { .size = { 8, 300 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 8, 300 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); for (int y = 0; y < 299; y++) - term_feed(t, "\r\n", 2, 0); - term_feed(t, "e\xcc\x81yes", 5, 0); - assert(term_select_start(t, (struct term_vector2i){ .x = 0, .y = 299 }, false, - TERM_SELECT_CELL)); - assert(term_select_extend(t, (struct term_vector2i){ .x = 3, .y = 299 }, true)); + wsap_vtcore_feed(t, "\r\n", 2, 0); + wsap_vtcore_feed(t, "e\xcc\x81yes", 5, 0); + assert(wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 0, .y = 299 }, false, + WSAP_VTCORE_SELECT_CELL)); + assert(wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 3, .y = 299 }, true)); bool injected = update_failing_at(s, t, k); - assert(term_snapshot_view(s)->size.y == 300); - const struct term_cell *row = term_snapshot_row(s, 299); + assert(wsap_vtcore_snapshot_view(s)->size.y == 300); + const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, 299); uint32_t cps[4]; assert(cluster_cps(s, &row[0], cps, 4) == 2 && cps[0] == 'e' && cps[1] == 0x301); - struct term_span span = term_snapshot_row_selection(s, 299); + struct wsap_vtcore_span span = wsap_vtcore_snapshot_row_selection(s, 299); assert(span.begin == 0 && span.end == 4); expect_matches_fresh(t, s); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); return injected; } /* Without failures, the selection of a tall screen reaches the last row. */ static void tall_selection_is_kept(void) { - struct term_options options = { .size = { 8, 300 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 8, 300 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); for (int y = 0; y < 299; y++) - term_feed(t, "\r\n", 2, 0); - term_feed(t, "e\xcc\x81yes", 5, 0); - term_select_start(t, (struct term_vector2i){ .x = 0, .y = 299 }, false, TERM_SELECT_CELL); - term_select_extend(t, (struct term_vector2i){ .x = 3, .y = 299 }, true); + wsap_vtcore_feed(t, "\r\n", 2, 0); + wsap_vtcore_feed(t, "e\xcc\x81yes", 5, 0); + wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 0, .y = 299 }, false, WSAP_VTCORE_SELECT_CELL); + wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 3, .y = 299 }, true); - assert(term_snapshot_update(s, t)); - struct term_span span = term_snapshot_row_selection(s, 299); + assert(wsap_vtcore_snapshot_update(s, t)); + struct wsap_vtcore_span span = wsap_vtcore_snapshot_row_selection(s, 299); assert(span.begin == 0 && span.end == 4); expect_matches_fresh(t, s); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); } /* On a screen taller than 256 rows, selecting needs memory. When none is * left, the call fails and the selection stays as it was. */ static void tall_selection_fails_cleanly(void) { - struct term_options options = { .size = { 8, 300 }, .scrollback = 5 }; - struct term *t = term_new(&options); + struct wsap_vtcore_options options = { .size = { 8, 300 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); assert(t); for (int y = 0; y < 299; y++) - term_feed(t, "\r\n", 2, 0); - term_feed(t, "yes", 3, 0); - assert(term_select_start(t, (struct term_vector2i){ .x = 0, .y = 299 }, false, - TERM_SELECT_CELL)); - assert(term_select_extend(t, (struct term_vector2i){ .x = 1, .y = 299 }, true)); - char *before = term_selection_text(t); + wsap_vtcore_feed(t, "\r\n", 2, 0); + wsap_vtcore_feed(t, "yes", 3, 0); + assert(wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 0, .y = 299 }, false, + WSAP_VTCORE_SELECT_CELL)); + assert(wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 1, .y = 299 }, true)); + char *before = wsap_vtcore_selection_text(t); assert(before && !strcmp(before, "ye")); alloc_was_failed = false; alloc_countdown = 0; - assert(!term_select_extend(t, (struct term_vector2i){ .x = 2, .y = 299 }, true)); + assert(!wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 2, .y = 299 }, true)); alloc_countdown = -1; assert(alloc_was_failed); alloc_was_failed = false; alloc_countdown = 0; - assert(!term_select_start(t, (struct term_vector2i){ .x = 2, .y = 299 }, false, - TERM_SELECT_WORD)); + assert(!wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 2, .y = 299 }, false, + WSAP_VTCORE_SELECT_WORD)); alloc_countdown = -1; assert(alloc_was_failed); - char *after = term_selection_text(t); + char *after = wsap_vtcore_selection_text(t); assert(after && !strcmp(after, before)); - term_text_free(before); - term_text_free(after); + wsap_vtcore_text_free(before); + wsap_vtcore_text_free(after); - assert(term_select_extend(t, (struct term_vector2i){ .x = 2, .y = 299 }, true)); - char *grown = term_selection_text(t); + assert(wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 2, .y = 299 }, true)); + char *grown = wsap_vtcore_selection_text(t); assert(grown && !strcmp(grown, "yes")); - term_text_free(grown); - term_free(t); + wsap_vtcore_text_free(grown); + wsap_vtcore_free(t); } /* Scroll with clusters in most lines. Each step fails every allocation in * turn, then retries, and must match a fresh capture. */ static void scrolling_fails_cleanly(void) { - struct term_options options = { .size = { 8, 3 }, .scrollback = 5 }; - struct term *t = term_new(&options); - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_options options = { .size = { 8, 3 }, .scrollback = 5 }; + struct wsap_vtcore *t = wsap_vtcore_new(&options); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); assert(t && s); int failures = 0; for (int i = 0; i < 300; i++) { - term_feed(t, "e\xcc\x81", 3, 0); + wsap_vtcore_feed(t, "e\xcc\x81", 3, 0); if (i % 3 == 0) - term_feed(t, flag_us, sizeof(flag_us) - 1, 0); + wsap_vtcore_feed(t, flag_us, sizeof(flag_us) - 1, 0); if (i % 5 == 0) - term_feed(t, family, sizeof(family) - 1, 0); - term_feed(t, "\r\n", 2, 0); + wsap_vtcore_feed(t, family, sizeof(family) - 1, 0); + wsap_vtcore_feed(t, "\r\n", 2, 0); if (i == 150) - term_select_start(t, (struct term_vector2i){ .x = 0, .y = 1 }, false, TERM_SELECT_CELL); + wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 0, .y = 1 }, false, WSAP_VTCORE_SELECT_CELL); if (i == 151) - term_select_extend(t, (struct term_vector2i){ .x = 4, .y = 2 }, true); + wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 4, .y = 2 }, true); failures += update_each_failure(s, t); expect_matches_fresh(t, s); } assert(failures > 0); - assert(term_history_rows(t) == 5); + assert(wsap_vtcore_history_rows(t) == 5); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); } int main(void) |
