diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/meson.build | 1 | ||||
| -rw-r--r-- | tests/test_lifecycle.c | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build index a78ae65..950f5f5 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -3,6 +3,7 @@ test_exe = executable( 'test_lifecycle.c', include_directories: inc, link_with: yasl_lib.get_static_lib(), + dependencies: deps, ) add_test_setup('asan') diff --git a/tests/test_lifecycle.c b/tests/test_lifecycle.c index a57e6b5..681e5fc 100644 --- a/tests/test_lifecycle.c +++ b/tests/test_lifecycle.c @@ -1,6 +1,8 @@ #include "yasl/yasl.h" #include <assert.h> +#include <poll.h> #include <stdio.h> +#include <unistd.h> static void test_scaling(void) { @@ -24,10 +26,65 @@ static void test_timing_clock(void) assert(stats.max_us == 500.0); } +static int dummy_cb(int fd, short revents, void *ud) +{ + (void)fd; (void)revents; (void)ud; + return 0; +} + +static void test_loop(void) +{ + struct yasl_loop *loop = yasl_loop_create(); + assert(loop != NULL); + + int p[2]; + assert(pipe(p) == 0); + int watch = yasl_loop_add_fd(loop, p[0], POLLIN, dummy_cb, NULL); + assert(watch > 0); + assert(yasl_loop_set_fd_events(loop, watch, POLLIN | POLLOUT) == 0); + + yasl_loop_kick(loop); + int n = yasl_loop_step(loop, 10); + assert(n >= 1); + + assert(yasl_loop_del_fd(loop, watch) == 0); + close(p[0]); + close(p[1]); + + yasl_loop_destroy(loop); +} + +static void test_display_lifecycle_standalone(void) +{ + struct yasl_display_spec spec = { .app_id = "org.yasl.test" }; + struct yasl_display *d = yasl_display_open(NULL, &spec); + if (!d) return; /* Headless CI without Wayland */ + + struct yasl_surface_spec sspec = { + .title = "Test Window", + .size = { .x = 320, .y = 240 }, + }; + struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + assert(s != NULL); + assert(yasl_surface_display(s) == d); + + struct yasl_vector2i sz = yasl_surface_size(s); + assert(sz.x > 0 && sz.y > 0); + + yasl_surface_schedule_redraw(s); + yasl_display_flush(d); + yasl_display_dispatch_timeout(d, 0); + + yasl_surface_destroy(s); + yasl_display_close(d); +} + int main(void) { test_scaling(); test_timing_clock(); + test_loop(); + test_display_lifecycle_standalone(); printf("All YASL basic tests passed.\n"); return 0; } |
