summaryrefslogtreecommitdiff
path: root/tests/common/test_contracts.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
commit482f799d356a8fbb8f585c4de7cc0992b8dc6fd3 (patch)
tree85551a69e3c356da7b9b514224e25a6c2f8d29b9 /tests/common/test_contracts.c
parent537b2d768b31deb0f95c5122e0d562e4406ae9a0 (diff)
Migrate tests to the unified event API
Port backend, input, tablet and app tests from yasl_input_event and YASL_INPUT_* to struct yasl_event and YASL_EVENT_*. The input allocation test links input.c on its own, so it stubs yasl_loop_now_ns() for the new event timestamps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/common/test_contracts.c')
-rw-r--r--tests/common/test_contracts.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c
index ee6fe61..7c1ab06 100644
--- a/tests/common/test_contracts.c
+++ b/tests/common/test_contracts.c
@@ -37,31 +37,27 @@ static void test_queue(void)
{
struct input_queue q = {0};
struct yasl_surface surface = {0};
- const enum yasl_input_kind kinds[] = {
- YASL_INPUT_TEXT, YASL_INPUT_PASTE, YASL_INPUT_DROP_FILES,
+ const enum yasl_event_type kinds[] = {
+ YASL_EVENT_TEXT, YASL_EVENT_PASTE, YASL_EVENT_DROP,
};
for (size_t k = 0; k < sizeof(kinds) / sizeof(kinds[0]); k++) {
char *source = malloc(4);
assert(source);
memcpy(source, "a\0b", 4);
- struct yasl_input_event in = {.surface = &surface, .kind = kinds[k]};
- if (in.kind == YASL_INPUT_TEXT) { in.text.text = source; in.text.len = 3; }
- if (in.kind == YASL_INPUT_PASTE) { in.paste.text = source; in.paste.len = 3; }
- if (in.kind == YASL_INPUT_DROP_FILES) { in.drop_files.files = source; in.drop_files.len = 3; }
+ struct yasl_event in = {.surface = &surface, .type = kinds[k], .text = {.data = source, .len = 3}};
assert(input_queue_push(&q, &in));
memset(source, 'x', 4);
free(source);
- struct yasl_input_event out;
+ struct yasl_event out;
assert(input_queue_pop(&q, &out));
- const char *payload = out.kind == YASL_INPUT_TEXT ? out.text.text :
- out.kind == YASL_INPUT_PASTE ? out.paste.text : out.drop_files.files;
- assert(out.surface == &surface && out.kind == kinds[k]);
+ const char *payload = out.text.data;
+ assert(out.surface == &surface && out.type == kinds[k]);
assert(memcmp(payload, "a\0b", 4) == 0);
assert(!input_queue_pop(&q, &out));
assert(memcmp(payload, "a\0b", 4) == 0);
/* Growth/wraparound must not invalidate a previously polled payload. */
for (unsigned i = 0; i < 4096; i++) {
- in = (struct yasl_input_event){.kind = YASL_INPUT_KEY, .key.key = i};
+ in = (struct yasl_event){.type = YASL_EVENT_KEY, .key.key = i};
assert(input_queue_push(&q, &in));
}
assert(memcmp(payload, "a\0b", 4) == 0);
@@ -79,28 +75,28 @@ static void test_queue(void)
}
assert(!input_queue_pop(&q, &out));
}
- struct yasl_input_event empty = {.surface = &surface, .kind = YASL_INPUT_PASTE};
- struct yasl_input_event out;
+ struct yasl_event empty = {.surface = &surface, .type = YASL_EVENT_PASTE};
+ struct yasl_event out;
assert(input_queue_push(&q, &empty));
assert(input_queue_pop(&q, &out));
- assert(out.paste.text && !out.paste.len && out.paste.text[0] == '\0');
- struct yasl_input_event in = {.surface = &surface, .kind = YASL_INPUT_TEXT,
+ assert(out.text.data && !out.text.len && out.text.data[0] == '\0');
+ struct yasl_event in = {.surface = &surface, .type = YASL_EVENT_TEXT,
.text = {"owned", 5}};
assert(input_queue_push(&q, &in));
assert(input_queue_pop(&q, &out));
- const char *last = out.text.text;
+ const char *last = out.text.data;
assert(input_queue_push(&q, &in));
/* Exercise the allocation-failure reset path without allocating huge RAM. */
in.text.len = SIZE_MAX;
assert(!input_queue_push(&q, &in));
assert(strcmp(last, "owned") == 0);
- in = (struct yasl_input_event){.surface = &surface, .kind = YASL_INPUT_KEY};
+ in = (struct yasl_event){.surface = &surface, .type = YASL_EVENT_KEY};
assert(input_queue_push(&q, &in));
- assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_RESET);
+ assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_INPUT_RESET);
assert(out.surface == &surface);
- assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_KEY);
+ assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_KEY);
assert(!input_queue_pop(&q, &out));
- in = (struct yasl_input_event){.kind = YASL_INPUT_PASTE, .paste = {"pending", 7}};
+ in = (struct yasl_event){.type = YASL_EVENT_PASTE, .text = {"pending", 7}};
assert(input_queue_push(&q, &in));
input_queue_clear(&q);
input_queue_clear(&q);