summaryrefslogtreecommitdiff
path: root/tests/cocoa/test_ownership.m
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/test_ownership.m
parente813252e685d761235ad45e170d97c9375f51958 (diff)
missing impls and hardening
Diffstat (limited to 'tests/cocoa/test_ownership.m')
-rw-r--r--tests/cocoa/test_ownership.m45
1 files changed, 45 insertions, 0 deletions
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;
+}