summaryrefslogtreecommitdiff
path: root/tests/cocoa
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 00:09:38 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 00:09:38 +0300
commit624d1371304a5ae4b3429ad5e4267aac7cd03dfd (patch)
tree32de069f6eec83686521fc4bf39cc9874b123e93 /tests/cocoa
parente813252e685d761235ad45e170d97c9375f51958 (diff)
missing impls and hardening
Diffstat (limited to 'tests/cocoa')
-rw-r--r--tests/cocoa/test_native.c14
-rw-r--r--tests/cocoa/test_ownership.m45
2 files changed, 57 insertions, 2 deletions
diff --git a/tests/cocoa/test_native.c b/tests/cocoa/test_native.c
index 03fde88..41df79a 100644
--- a/tests/cocoa/test_native.c
+++ b/tests/cocoa/test_native.c
@@ -19,7 +19,16 @@ static void draw(struct yasl_surface *surface, struct yasl_frame *frame, void *u
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};
+ struct yasl_damage_list damage = {.n = YASL_DAMAGE_MAX + 1};
+ assert(!yasl_surface_present(surface, &frame->target, &damage));
+ damage.n = -1;
+ struct yasl_framebuffer invalid = frame->target;
+ invalid.buffer++;
+ assert(!yasl_surface_present(surface, &invalid, &damage));
+ invalid = frame->target;
+ invalid.generation--;
+ assert(!yasl_surface_present(surface, &invalid, &damage));
+ assert(!yasl_surface_present(surface, &frame->target, NULL));
assert(yasl_surface_present(surface, &frame->target, &damage));
assert(!yasl_surface_present(surface, &frame->target, &damage));
state->draws++;
@@ -36,8 +45,9 @@ static void test_window(enum yasl_backend request, bool null_spec)
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};
+ struct yasl_surface_cbs callbacks = {.draw = draw};
yasl_surface_set_callbacks(state.surface, &callbacks, &state);
+ callbacks.draw = NULL;
yasl_surface_schedule_redraw(state.surface);
uint64_t deadline = yasl_loop_now_ns() + 3000000000ull;
while (!state.draws && yasl_loop_now_ns() < deadline) {
diff --git a/tests/cocoa/test_ownership.m b/tests/cocoa/test_ownership.m
new file mode 100644
index 0000000..aa75b1c
--- /dev/null
+++ b/tests/cocoa/test_ownership.m
@@ -0,0 +1,45 @@
+#import <AppKit/AppKit.h>
+#include "yasl/yasl.h"
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void)
+{
+ struct yasl_display *d = yasl_display_open(NULL, NULL);
+ assert(d);
+ struct yasl_surface_spec spec = {.title = "Ownership test", .size = {160, 100}};
+ struct yasl_surface *s = yasl_surface_create_toplevel(d, &spec);
+ assert(s);
+ struct yasl_input_event event;
+ while (yasl_surface_input_poll(s, &event)) {}
+ @autoreleasepool {
+ for (int i = 0; i < 600; i++) {
+ char text[32];
+ snprintf(text, sizeof(text), "paste-%d", i);
+ yasl_display_copy(d, YASL_CLIPBOARD, text);
+ yasl_display_paste(d, YASL_CLIPBOARD, s);
+ memset(text, 'x', sizeof(text));
+ }
+ }
+ /* All NSString/UTF8String temporaries have now expired. */
+ for (int i = 0; i < 600; i++) {
+ char text[32];
+ snprintf(text, sizeof(text), "paste-%d", i);
+ assert(yasl_surface_input_poll(s, &event));
+ assert(event.kind == YASL_INPUT_PASTE && strcmp(event.paste.text, text) == 0);
+ }
+ const char *last = event.paste.text;
+ assert(!yasl_surface_input_poll(s, &event));
+ @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, "new selection"); }
+ assert(strcmp(last, "paste-599") == 0);
+ @autoreleasepool {
+ yasl_display_copy(d, YASL_CLIPBOARD, "");
+ yasl_display_paste(d, YASL_CLIPBOARD, s);
+ }
+ assert(yasl_surface_input_poll(s, &event));
+ assert(event.kind == YASL_INPUT_PASTE && !event.paste.len && !event.paste.text[0]);
+ yasl_surface_destroy(s);
+ yasl_display_close(d);
+ return 0;
+}