summaryrefslogtreecommitdiff
path: root/tests/test_lifecycle.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
commit76073fe5fad8799e5850805f2f090af2cb62c741 (patch)
tree9658019babe4760a3634bdab4da0731a10e42e68 /tests/test_lifecycle.c
parentdd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff)
Simplify the public event and CPU API
Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_lifecycle.c')
-rw-r--r--tests/test_lifecycle.c91
1 files changed, 20 insertions, 71 deletions
diff --git a/tests/test_lifecycle.c b/tests/test_lifecycle.c
index 00d1264..a334fed 100644
--- a/tests/test_lifecycle.c
+++ b/tests/test_lifecycle.c
@@ -1,75 +1,24 @@
-#include "yasl/loop.h"
-#include "yasl/yasl.h"
+#include <yasl/yasl.h>
+#include <yasl/cpu.h>
+#include <yasl/gl.h>
+#include <yasl/desktop.h>
#include <assert.h>
-#include <poll.h>
-#include <stdio.h>
-#include <unistd.h>
-
-static void test_scaling(void)
-{
- assert(yasl_scale_to_device(10.0, 120) == 10);
- assert(yasl_scale_to_device(10.0, 240) == 20);
- assert(yasl_scale_to_logical(20, 240) == 10);
-}
-
-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_window_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_geometry(s).size;
- assert(sz.x > 0 && sz.y > 0);
-
- yasl_surface_schedule_redraw(s);
- yasl_display_flush(d);
- yasl_display_dispatch(d, 0);
-
- yasl_surface_destroy(s);
- yasl_display_close(d);
-}
-
int main(void)
{
- test_scaling();
- test_loop();
- test_display_lifecycle_standalone();
- printf("All YASL basic tests passed.\n");
- return 0;
+ yasl_shutdown(); yasl_wake();
+ yasl_event e={.type=YASL_EVENT_QUIT};
+ assert(yasl_wait_event(&e,0)==-1 && e.type==YASL_EVENT_NONE);
+ assert(yasl_get_error(NULL)==YASL_ERROR_NOT_INITIALIZED);
+ assert(!yasl_set_backend((enum yasl_backend)999));
+ assert(yasl_get_error(NULL)==YASL_ERROR_INVALID);
+ assert(!yasl_surface_create("bad",0,64,0));
+ assert(!yasl_surface_create("bad",64,64,16));
+ assert(yasl_set_app_id("org.yasl.api"));
+ assert(yasl_set_backend(YASL_BACKEND_AUTO));
+ yasl_surface_destroy(NULL);
+ assert(yasl_time_ns()>0);
+ const char *description=NULL;yasl_get_error(&description);assert(description);
+ int w=9,h=9;yasl_surface_get_size(NULL,&w,&h);assert(w==0&&h==0);
+ assert(yasl_executable_path(NULL,0)>0);
+ yasl_shutdown();return 0;
}