summaryrefslogtreecommitdiff
path: root/tests/model_test.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
commitbdaedce69b17b654bd0060579dd9b9ff120009b5 (patch)
tree0e9cd8597652263a96c48ba678fb0b66e1fc131b /tests/model_test.c
parentba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff)
parentdcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff)
Merge branch 'wt/rename' into api-hardening
# Conflicts: # README.md
Diffstat (limited to 'tests/model_test.c')
-rw-r--r--tests/model_test.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/tests/model_test.c b/tests/model_test.c
index d3988c6..4f58914 100644
--- a/tests/model_test.c
+++ b/tests/model_test.c
@@ -17,7 +17,7 @@
*/
#include "model.h"
#include "fuzz_gen.h"
-#include "term/term.h"
+#include "wsap_vtcore/wsap_vtcore.h"
#include <stdio.h>
#include <limits.h>
@@ -33,11 +33,11 @@ struct event {
char *bytes; /* NULL for a resize */
size_t len;
unsigned flags;
- struct term_vector2i size;
+ struct wsap_vtcore_vector2i size;
};
struct script {
- struct term_vector2i size;
+ struct wsap_vtcore_vector2i size;
int history;
struct event *ev;
int n, cap;
@@ -107,10 +107,10 @@ static char glyph(uint32_t cp)
}
/* Print every retained row of both, side by side. */
-static void dump_all(struct model *m, struct term *t, struct term_snapshot *snap, FILE *log)
+static void dump_all(struct model *m, struct wsap_vtcore *t, struct wsap_vtcore_snapshot *snap, FILE *log)
{
- int total = term_scrollback(t).total, mtotal = model_history(m);
- struct term_vector2i size = term_size(t), msize = model_size(m);
+ int total = wsap_vtcore_scrollback(t).total, mtotal = model_history(m);
+ struct wsap_vtcore_vector2i size = wsap_vtcore_size(t), msize = model_size(m);
int rows = total + size.y > mtotal + msize.y ? total + size.y : mtotal + msize.y;
fprintf(log, " term (history %d)%*s model (history %d)\n", total, size.x > 8 ? size.x - 8 : 0,
"", mtotal);
@@ -118,12 +118,12 @@ static void dump_all(struct model *m, struct term *t, struct term_snapshot *snap
fprintf(log, " %3d |", r);
if (r < total + size.y) {
int offset = r < total ? total - r : 0;
- term_scroll_to(t, offset);
- term_snapshot_update(snap, t);
- const struct term_cell *row = term_snapshot_row(snap, r < total ? 0 : r - total);
+ wsap_vtcore_scroll_to(t, offset);
+ wsap_vtcore_snapshot_update(snap, t);
+ const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(snap, r < total ? 0 : r - total);
for (int x = 0; x < size.x; x++) {
- uint32_t cp[TERM_GRAPHEME_MAX_LEN] = {0};
- if (row[x].text) term_snapshot_cluster(snap, row[x].text, cp, TERM_GRAPHEME_MAX_LEN);
+ uint32_t cp[WSAP_VTCORE_GRAPHEME_MAX_LEN] = {0};
+ if (row[x].text) wsap_vtcore_snapshot_cluster(snap, row[x].text, cp, WSAP_VTCORE_GRAPHEME_MAX_LEN);
fputc(glyph(cp[0]), log);
}
} else {
@@ -136,14 +136,14 @@ static void dump_all(struct model *m, struct term *t, struct term_snapshot *snap
}
fprintf(log, "|\n");
}
- term_scroll_to(t, 0);
- struct term_cursor c = term_cursor(t), mc = model_cursor(m);
+ wsap_vtcore_scroll_to(t, 0);
+ struct wsap_vtcore_cursor c = wsap_vtcore_cursor(t), mc = model_cursor(m);
fprintf(log, " cursor term %d,%d model %d,%d\n", c.pos.x, c.pos.y, mc.pos.x, mc.pos.y);
}
/* Returns NULL when the terminal matches the model, else a description.
* Details go to log when it is not NULL. */
-static const char *compare(struct model *m, struct term *t, struct term_snapshot *snap,
+static const char *compare(struct model *m, struct wsap_vtcore *t, struct wsap_vtcore_snapshot *snap,
struct replies *got, char *why, size_t cap, FILE *log)
{
size_t want_len;
@@ -159,12 +159,12 @@ static const char *compare(struct model *m, struct term *t, struct term_snapshot
snprintf(why, cap, "replies differ");
return why;
}
- struct term_vector2i size = term_size(t), msize = model_size(m);
+ struct wsap_vtcore_vector2i size = wsap_vtcore_size(t), msize = model_size(m);
if (size.x != msize.x || size.y != msize.y) {
snprintf(why, cap, "size %dx%d, model %dx%d", size.x, size.y, msize.x, msize.y);
return why;
}
- struct term_cursor c = term_cursor(t), mc = model_cursor(m);
+ struct wsap_vtcore_cursor c = wsap_vtcore_cursor(t), mc = model_cursor(m);
if (c.pos.x != mc.pos.x || c.pos.y != mc.pos.y || c.style != mc.style ||
c.visible != mc.visible || c.blink != mc.blink) {
snprintf(why, cap, "cursor %d,%d style %d visible %d blink %d; model %d,%d %d %d %d",
@@ -172,7 +172,7 @@ static const char *compare(struct model *m, struct term *t, struct term_snapshot
mc.pos.x, mc.pos.y, mc.style, mc.visible, mc.blink);
return why;
}
- struct term_modes md = term_modes(t), mm = model_modes(m);
+ struct wsap_vtcore_modes md = wsap_vtcore_modes(t), mm = model_modes(m);
if (md.keyboard != mm.keyboard || md.mouse != mm.mouse ||
md.mouse_encoding != mm.mouse_encoding || md.app_cursor != mm.app_cursor ||
md.app_keypad != mm.app_keypad || md.backarrow_bs != mm.backarrow_bs ||
@@ -186,24 +186,24 @@ static const char *compare(struct model *m, struct term *t, struct term_snapshot
}
/* Visit each retained row. Wide-line totals can start as estimates. */
int total = model_history(m);
- term_scroll_to(t, 0);
- term_scroll(t, INT_MAX);
+ wsap_vtcore_scroll_to(t, 0);
+ wsap_vtcore_scroll(t, INT_MAX);
for (int offset = total;; offset = offset > size.y ? offset - size.y : 0) {
if (!offset)
- term_scroll_to(t, 0);
- if (!term_snapshot_update(snap, t)) {
+ wsap_vtcore_scroll_to(t, 0);
+ if (!wsap_vtcore_snapshot_update(snap, t)) {
snprintf(why, cap, "snapshot update failed");
return why;
}
for (int y = 0; y < size.y; y++) {
- const struct term_cell *row = term_snapshot_row(snap, y);
+ const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(snap, y);
int retained = total - offset + y;
const struct model_cell *want_row = model_row(m, retained);
for (int x = 0; x < size.x; x++) {
const struct model_cell *e = &want_row[x];
- uint32_t cps[TERM_GRAPHEME_MAX_LEN] = {0};
- int n = row[x].text ? term_snapshot_cluster(snap, row[x].text, cps,
- TERM_GRAPHEME_MAX_LEN) : 0;
+ uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN] = {0};
+ int n = row[x].text ? wsap_vtcore_snapshot_cluster(snap, row[x].text, cps,
+ WSAP_VTCORE_GRAPHEME_MAX_LEN) : 0;
if (n == e->n && row[x].width == e->width && row[x].attrs == e->attrs &&
row[x].fg == e->fg && row[x].bg == e->bg &&
!memcmp(cps, e->cp, (size_t)n * sizeof(*cps)))
@@ -211,9 +211,9 @@ static const char *compare(struct model *m, struct term *t, struct term_snapshot
if (log) {
fprintf(log, "retained row %d (offset %d):\n term: ", retained, offset);
for (int k = 0; k < size.x; k++) {
- uint32_t cp[TERM_GRAPHEME_MAX_LEN] = {0};
+ uint32_t cp[WSAP_VTCORE_GRAPHEME_MAX_LEN] = {0};
if (row[k].text)
- term_snapshot_cluster(snap, row[k].text, cp, TERM_GRAPHEME_MAX_LEN);
+ wsap_vtcore_snapshot_cluster(snap, row[k].text, cp, WSAP_VTCORE_GRAPHEME_MAX_LEN);
fputc(glyph(cp[0]), log);
}
fprintf(log, "\n model: ");
@@ -228,19 +228,19 @@ static const char *compare(struct model *m, struct term *t, struct term_snapshot
"model U+%04X (%u cps) w%u attrs %#x fg %#x bg %#x",
x, y, cps[0], n, row[x].width, row[x].attrs, row[x].fg, row[x].bg,
e->cp[0], e->n, e->width, e->attrs, e->fg, e->bg);
- term_scroll_to(t, 0);
+ wsap_vtcore_scroll_to(t, 0);
return why;
}
}
if (!offset) break;
- term_scroll(t, -(offset > size.y ? size.y : offset));
+ wsap_vtcore_scroll(t, -(offset > size.y ? size.y : offset));
}
- int observed_total = term_scrollback(t).total;
+ int observed_total = wsap_vtcore_scrollback(t).total;
if (observed_total != total) {
snprintf(why, cap, "visited history %d rows, model %d", observed_total, total);
return why;
}
- term_scroll_to(t, 0);
+ wsap_vtcore_scroll_to(t, 0);
return NULL;
}
@@ -251,13 +251,13 @@ static int run(const struct script *s, enum chunking chunks, uint64_t chunk_seed
char *why, size_t cap, bool verbose)
{
struct replies got = {0};
- struct term_options opt = {
+ struct wsap_vtcore_options opt = {
.size = s->size, .scrollback = s->history,
.callbacks = { .ud = &got, .reply = on_reply },
};
- struct term *t = term_new(&opt);
+ struct wsap_vtcore *t = wsap_vtcore_new(&opt);
struct model *m = model_new(s->size, s->history, NULL);
- struct term_snapshot *snap = term_snapshot_new();
+ struct wsap_vtcore_snapshot *snap = wsap_vtcore_snapshot_new();
if (!t || !snap) abort();
uint64_t saved_rng = rng;
rng = chunk_seed | 1;
@@ -270,12 +270,12 @@ static int run(const struct script *s, enum chunking chunks, uint64_t chunk_seed
size_t n = chunks == CHUNK_WHOLE ? e->len - k
: chunks == CHUNK_BYTES ? 1
: 1 + (size_t)rn((int)(e->len - k));
- term_feed(t, e->bytes + k, n, e->flags);
+ wsap_vtcore_feed(t, e->bytes + k, n, e->flags);
k += n;
}
} else {
bool a = model_resize(m, e->size);
- bool b = term_resize(t, e->size);
+ bool b = wsap_vtcore_resize(t, e->size);
if (a != b) {
snprintf(why, cap, "resize result differs");
bad = i;
@@ -291,9 +291,9 @@ static int run(const struct script *s, enum chunking chunks, uint64_t chunk_seed
}
rng = saved_rng;
free(got.s);
- term_snapshot_free(snap);
+ wsap_vtcore_snapshot_free(snap);
model_free(m);
- term_free(t);
+ wsap_vtcore_free(t);
return bad;
}
@@ -378,7 +378,7 @@ static int fixed_cases(void)
{ 8, 3, 5, "abcdefgh\033[3;4H\033[31;1m\0337\033[0m\033[H\0338X" },
{ 6, 2, 5, "abcdef\xe3\x80z\xed\xa0\x80\x80" },
};
- static const struct term_vector2i sizes[] = {
+ static const struct wsap_vtcore_vector2i sizes[] = {
{ .x = 5, .y = 3 }, { .x = 16, .y = 4 }, { .x = 7, .y = 3 }, { .x = 20, .y = 5 },
{ .x = 1, .y = 2 }, { .x = 3, .y = 6 },
};
@@ -419,16 +419,16 @@ int main(int argc, char **argv)
.size = { .x = 4 + rn(37), .y = 2 + rn(11) },
.history = limits[rn(4)],
};
- struct term_vector2i size = s.size;
+ struct wsap_vtcore_vector2i size = s.size;
for (int step = 0; step < 4; step++) {
blen = 0;
gen(10 + rn(30), size.x, size.y);
put(probe);
- unsigned flags = rn(5) == 0 ? TERM_FEED_ONLCR : 0;
+ unsigned flags = rn(5) == 0 ? WSAP_VTCORE_FEED_ONLCR : 0;
script_add(&s, (struct event){ .bytes = dup_bytes(buf, blen), .len = blen,
.flags = flags });
if (rn(4) == 0) {
- size = (struct term_vector2i){ .x = 1 + rn(44), .y = 1 + rn(14) };
+ size = (struct wsap_vtcore_vector2i){ .x = 1 + rn(44), .y = 1 + rn(14) };
script_add(&s, (struct event){ .size = size });
}
}