From 1ab3e5a123109704789c2768e11a4f9af515821d Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 13:13:52 +0300 Subject: Redefine public and rendering APIs with explicit contracts --- tests/common/test_gl.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'tests/common/test_gl.c') diff --git a/tests/common/test_gl.c b/tests/common/test_gl.c index cd51575..0e4597b 100644 --- a/tests/common/test_gl.c +++ b/tests/common/test_gl.c @@ -27,9 +27,10 @@ static yasl_surface *cpu; static void fail(const char *message, int line) { const char *description = NULL; - enum yasl_error error = yasl_get_error(&description); + int error = errno; + description = strerror(error); fprintf(stderr, "GL integration failure at line %d: %s (YASL error %d: %s, native error %d)\n", - line, message, error, description ? description : "none", yasl_get_native_error()); + line, message, error, description ? description : "none", errno); (void)yasl_gl_make_current(NULL); if (cpu) yasl_surface_destroy(cpu); if (shared) yasl_surface_destroy(shared); @@ -74,13 +75,13 @@ static void wait_for_size(yasl_surface *surface, int width, int height) int main(int argc, char **argv) { REQUIRE(argc == 2, "expected backend argument: wayland or x11"); - if (!strcmp(argv[1], "wayland")) REQUIRE(yasl_set_backend(YASL_BACKEND_WAYLAND), "select Wayland backend"); - else if (!strcmp(argv[1], "x11")) REQUIRE(yasl_set_backend(YASL_BACKEND_X11), "select X11 backend"); + if (!strcmp(argv[1], "wayland")) REQUIRE((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_WAYLAND}) == 0), "select Wayland backend"); + else if (!strcmp(argv[1], "x11")) REQUIRE((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_X11}) == 0), "select X11 backend"); else REQUIRE(false, "backend must be wayland or x11"); - primary = yasl_gl_surface_create("YASL GL test", 320, 240, 0, NULL, NULL); + primary = yasl_gl_surface_create(&(struct yasl_surface_options){.title="YASL GL test", .width=320, .height=240, .type=YASL_SURFACE_NATIVE, .flags=0}, NULL); REQUIRE(primary != NULL, "create default OpenGL 3.2 surface"); - REQUIRE(yasl_gl_make_current(primary), "make first GL context current"); + REQUIRE((yasl_gl_make_current(primary) == 0), "make first GL context current"); get_string_fn get_string = NULL; clear_color_fn clear_color = NULL; @@ -114,22 +115,24 @@ int main(int argc, char **argv) REQUIRE(abs((int)pixel[0] - 51) <= 3 && abs((int)pixel[1] - 102) <= 3 && abs((int)pixel[2] - 204) <= 3 && pixel[3] >= 250, "read rendered pixel from the native GL framebuffer"); - REQUIRE(yasl_gl_swap_interval(primary, 0), "disable swap interval"); - REQUIRE(yasl_gl_swap_buffers(primary), "swap first GL surface"); + REQUIRE((yasl_gl_set_swap_interval(primary, 0) == 0), "disable swap interval"); + REQUIRE((yasl_gl_present(primary) == 0), "swap first GL surface"); unsigned texture = 0; gen_textures(1, &texture); bind_texture(GL_TEXTURE_2D_, texture); REQUIRE(is_texture(texture), "create a shareable GL texture"); - shared = yasl_gl_surface_create("YASL GL shared context", 160, 120, 0, NULL, primary); + struct yasl_gl_options sharing = YASL_GL_OPTIONS_INIT; + sharing.share = primary; + shared = yasl_gl_surface_create(&(struct yasl_surface_options){.title="YASL GL shared context", .width=160, .height=120, .type=YASL_SURFACE_NATIVE, .flags=0}, &sharing); REQUIRE(shared != NULL, "create shared GL context"); - REQUIRE(yasl_gl_make_current(shared), "make shared context current"); + REQUIRE((yasl_gl_make_current(shared) == 0), "make shared context current"); REQUIRE(is_texture(texture), "verify context shares GL objects"); delete_textures(1, &texture); - REQUIRE(yasl_gl_make_current(primary), "restore primary GL context"); + REQUIRE((yasl_gl_make_current(primary) == 0), "restore primary GL context"); - REQUIRE(yasl_surface_request_size(primary, 400, 300), "request surface resize"); + REQUIRE((yasl_surface_request_size(primary, 400, 300) == 0), "request surface resize"); wait_for_size(primary, 400, 300); yasl_surface_get_framebuffer_size(primary, &pixel_width, &pixel_height); double scale = yasl_surface_get_scale(primary); @@ -138,18 +141,19 @@ int main(int argc, char **argv) "query resized framebuffer dimensions"); clear_color(0.7f, 0.1f, 0.3f, 1.0f); clear(GL_COLOR_BUFFER_BIT_); - REQUIRE(yasl_gl_swap_buffers(primary), "swap resized GL surface"); + REQUIRE((yasl_gl_present(primary) == 0), "swap resized GL surface"); - const int invalid_attributes[] = {0x7fff, 1, YASL_GL_END}; - REQUIRE(yasl_gl_surface_create("invalid attrs", 100, 100, 0, invalid_attributes, NULL) == NULL, - "reject unknown GL context attributes"); - REQUIRE(yasl_gl_surface_create("invalid CPU GL", 100, 100, YASL_SURFACE_CPU, NULL, NULL) == NULL, + struct yasl_gl_options invalid_options = YASL_GL_OPTIONS_INIT; + invalid_options.major = -1; + REQUIRE(yasl_gl_surface_create(&(struct yasl_surface_options){.title="invalid attrs", .width=100, .height=100, .type=YASL_SURFACE_NATIVE, .flags=0}, &invalid_options) == NULL, + "reject invalid GL context options"); + REQUIRE(yasl_gl_surface_create(&(struct yasl_surface_options){.title="invalid CPU GL", .width=100, .height=100, .type=YASL_SURFACE_CPU, .flags=0}, NULL) == NULL, "reject CPU flag on GL surface creation"); - cpu = yasl_surface_create("CPU surface", 100, 100, YASL_SURFACE_CPU); + cpu = yasl_surface_create(&(struct yasl_surface_options){.title="CPU surface", .width=100, .height=100, .type=YASL_SURFACE_CPU, .flags=0}); REQUIRE(cpu != NULL, "create CPU surface for incompatibility check"); - REQUIRE(!yasl_gl_make_current(cpu), "reject CPU surface as a GL context"); + REQUIRE((yasl_gl_make_current(cpu) < 0), "reject CPU surface as a GL context"); - REQUIRE(yasl_gl_make_current(NULL), "detach GL context before destruction"); + REQUIRE((yasl_gl_make_current(NULL) == 0), "detach GL context before destruction"); yasl_surface_destroy(cpu); cpu = NULL; yasl_surface_destroy(shared); shared = NULL; yasl_surface_destroy(primary); primary = NULL; -- cgit v1.2.3