diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 21:23:03 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 21:23:03 +0300 |
| commit | dd1775a9927922c14f8679ccbc4d3ca8d5917e20 (patch) | |
| tree | 3acc442bb4a3470364b74aa82ff67cb84d555c45 /tests/cocoa/test_ownership.m | |
| parent | ecb81aeea4c0c880b3a60a0dc8418c4bf2a7cf85 (diff) | |
public api refactor
Diffstat (limited to 'tests/cocoa/test_ownership.m')
| -rw-r--r-- | tests/cocoa/test_ownership.m | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/tests/cocoa/test_ownership.m b/tests/cocoa/test_ownership.m index 5fd5cbf..6d69907 100644 --- a/tests/cocoa/test_ownership.m +++ b/tests/cocoa/test_ownership.m @@ -3,6 +3,7 @@ #import <AppKit/AppKit.h> #include "yasl/yasl.h" #include <assert.h> +#include <errno.h> #include <stdio.h> #include <string.h> @@ -20,13 +21,49 @@ int main(void) assert(yasl_cocoa_surface_get_view(s) == window.contentView); assert([window isKindOfClass:[NSWindow class]] && window.contentView); struct yasl_event event; - while (yasl_surface_poll_event(s, &event)) {} + while (yasl_display_poll_event(d, &event)) {} + + assert(yasl_surface_set_size(s, (struct yasl_vector2i){180, 110})); + assert(yasl_surface_set_fullscreen(s, false)); + assert(yasl_surface_set_maximized(s, false)); + assert(!yasl_surface_set_size(s, (struct yasl_vector2i){0, 100})); + assert(errno == EINVAL); + struct yasl_popup_spec popup_spec = { + .size = {80, 40}, .anchor = {10, 10, 2, 2}, + }; + struct yasl_surface *popup = yasl_surface_create_popup(s, &popup_spec); + assert(popup); + assert(!yasl_surface_set_size(popup, (struct yasl_vector2i){80, 40})); + assert(errno == EINVAL); + assert(!yasl_surface_set_fullscreen(popup, true) && errno == EINVAL); + assert(!yasl_surface_set_maximized(popup, true) && errno == EINVAL); + assert(!yasl_surface_minimize(popup) && errno == EINVAL); + yasl_surface_destroy(popup); + while (yasl_display_poll_event(d, &event)) {} + + id<NSTextInputClient> text_input = (id<NSTextInputClient>)yasl_cocoa_surface_get_view(s); + [text_input setMarkedText:@"é漢" selectedRange:NSMakeRange(1, 1) + replacementRange:NSMakeRange(NSNotFound, 0)]; + assert(strcmp(yasl_surface_ime_preedit(s), "é漢") == 0); + [text_input unmarkText]; + assert(yasl_surface_ime_preedit(s) == NULL); + assert(yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_COMPOSITION && event.composition.active); + assert(strcmp(event.composition.data, "é漢") == 0); + assert(event.composition.begin == 2 && event.composition.end == 5); + assert(yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_COMPOSITION && !event.composition.active); + assert(event.composition.begin == -1 && event.composition.end == -1); + while (yasl_display_poll_event(d, &event)) {} + + uint64_t request_ids[600]; @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); + assert(yasl_clipboard_set(d, YASL_CLIPBOARD, text)); + request_ids[i] = yasl_clipboard_request(s, YASL_CLIPBOARD); + assert(request_ids[i] != 0); memset(text, 'x', sizeof(text)); } } @@ -34,19 +71,31 @@ int main(void) for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); - assert(yasl_surface_poll_event(s, &event)); - assert(event.type == YASL_EVENT_PASTE && strcmp(event.text.data, text) == 0); + assert(yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == request_ids[i]); + assert(event.paste.status == YASL_TRANSFER_OK && strcmp(event.paste.data, text) == 0); } - const char *last = event.text.data; - assert(!yasl_surface_poll_event(s, &event)); + const char *last = event.paste.data; + assert(!yasl_display_poll_event(d, &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_poll_event(s, &event)); - assert(event.type == YASL_EVENT_PASTE && !event.text.len && !event.text.data[0]); + assert(!yasl_clipboard_set(d, YASL_CLIPBOARD, "\xc3")); + assert(errno == EILSEQ); + assert(yasl_clipboard_set(d, YASL_CLIPBOARD, "")); + uint64_t empty_id = yasl_clipboard_request(s, YASL_CLIPBOARD); + assert(empty_id && yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == empty_id); + assert(event.paste.status == YASL_TRANSFER_OK && !event.paste.len && !event.paste.data[0]); + [NSPasteboard.generalPasteboard clearContents]; + uint64_t unavailable_id = yasl_clipboard_request(s, YASL_CLIPBOARD); + assert(unavailable_id && yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == unavailable_id); + assert(event.paste.status == YASL_TRANSFER_UNAVAILABLE && !event.paste.len); + yasl_display_copy(d, YASL_CLIPBOARD, "legacy paste"); + yasl_display_paste(d, YASL_CLIPBOARD, s); + assert(yasl_display_poll_event(d, &event)); + assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == 0); + assert(event.paste.status == YASL_TRANSFER_OK && strcmp(event.text.data, "legacy paste") == 0); yasl_surface_destroy(s); yasl_display_close(d); return 0; |
