summaryrefslogtreecommitdiff
path: root/tests/cocoa
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-11 23:51:43 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-11 23:51:43 +0300
commite813252e685d761235ad45e170d97c9375f51958 (patch)
treee57bae545c0eb22aac4119a890b8344ee7cd09d2 /tests/cocoa
parent608b49052178ea74f593c925cdeedf352aa1c357 (diff)
parent6eac0a5f2c552728efca420b1129fae7d4fea773 (diff)
Merge branch 'backend-selection' into main
- Implement runtime backend selection (Wayland, X11, Cocoa) - Add native X11 backend with clipboard, keyboard, mouse, and placement - Integrate multi-backend integration tests running under Weston and Xwayland - Retain zero-hole struct packing, branchless ALU/LUT primitives, and paced event loop
Diffstat (limited to 'tests/cocoa')
-rw-r--r--tests/cocoa/test_native.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/cocoa/test_native.c b/tests/cocoa/test_native.c
new file mode 100644
index 0000000..03fde88
--- /dev/null
+++ b/tests/cocoa/test_native.c
@@ -0,0 +1,58 @@
+#define _POSIX_C_SOURCE 200809L
+#include "yasl/yasl.h"
+
+#include <assert.h>
+#include <time.h>
+
+struct state {
+ struct yasl_display *display;
+ struct yasl_surface *surface;
+ unsigned draws;
+};
+
+static void draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud)
+{
+ struct state *state = ud;
+ assert(surface == state->surface && frame->surface == surface);
+ assert(yasl_surface_display(surface) == state->display);
+ assert(frame->target.pixels);
+ struct yasl_vector2i size = yasl_surface_size(surface);
+ assert(size.x == frame->target.size.x && size.y == frame->target.size.y);
+ for (int i = 0; i < size.x * size.y; i++) frame->target.pixels[i] = 0xff4080c0;
+ struct yasl_damage_list damage = {.n = -1};
+ assert(yasl_surface_present(surface, &frame->target, &damage));
+ assert(!yasl_surface_present(surface, &frame->target, &damage));
+ state->draws++;
+ yasl_surface_destroy(surface);
+ state->surface = NULL;
+}
+
+static void test_window(enum yasl_backend request, bool null_spec)
+{
+ struct yasl_display_spec spec = {.backend = request};
+ struct state state = {.display = yasl_display_open(NULL, null_spec ? NULL : &spec)};
+ assert(state.display);
+ assert(yasl_display_backend(state.display) == YASL_BACKEND_COCOA);
+ struct yasl_surface_spec surface = {.title = "Native backend test", .size = {160, 100}};
+ state.surface = yasl_surface_create_toplevel(state.display, &surface);
+ assert(state.surface);
+ static const struct yasl_surface_cbs callbacks = {.draw = draw};
+ yasl_surface_set_callbacks(state.surface, &callbacks, &state);
+ yasl_surface_schedule_redraw(state.surface);
+ uint64_t deadline = yasl_loop_now_ns() + 3000000000ull;
+ while (!state.draws && yasl_loop_now_ns() < deadline) {
+ yasl_display_dispatch(state.display);
+ yasl_display_flush(state.display);
+ nanosleep(&(struct timespec){.tv_nsec = 1000000}, NULL);
+ }
+ assert(state.draws == 1 && !state.surface);
+ yasl_display_close(state.display);
+}
+
+int main(void)
+{
+ test_window(YASL_BACKEND_AUTO, true);
+ test_window(YASL_BACKEND_AUTO, false);
+ test_window(YASL_BACKEND_COCOA, false);
+ return 0;
+}