diff options
Diffstat (limited to 'tests/cocoa/test_ownership.m')
| -rw-r--r-- | tests/cocoa/test_ownership.m | 45 |
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; +} |
