aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_local_copy_paste.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-22 12:24:59 -0400
committerDavid Robillard <d@drobilla.net>2022-05-23 16:50:43 -0400
commit2501218801437ea413091007b535d7c097801713 (patch)
treecf938dd335f8aa9b547b458f97f05e7e18d8b9d3 /test/test_local_copy_paste.c
parent0093196a4c624da6d7f78a909a442f2e784c37aa (diff)
downloadpugl-2501218801437ea413091007b535d7c097801713.tar.gz
pugl-2501218801437ea413091007b535d7c097801713.tar.bz2
pugl-2501218801437ea413091007b535d7c097801713.zip
Add rich clipboard support
This implements a more powerful protocol for working with clipboards, which supports datatype negotiation, and fixes various issues by mapping more directly to how things work on X11.
Diffstat (limited to 'test/test_local_copy_paste.c')
-rw-r--r--test/test_local_copy_paste.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/test/test_local_copy_paste.c b/test/test_local_copy_paste.c
index f5c75c4..4a2f4d9 100644
--- a/test/test_local_copy_paste.c
+++ b/test/test_local_copy_paste.c
@@ -1,4 +1,4 @@
-// Copyright 2020-2021 David Robillard <d@drobilla.net>
+// Copyright 2020-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
// Tests copy and paste within the same view
@@ -21,6 +21,9 @@ static const uintptr_t timerId = 1u;
typedef enum {
START,
EXPOSED,
+ PASTED,
+ RECEIVED_OFFER,
+ RECEIVED_DATA,
FINISHED,
} State;
@@ -57,20 +60,55 @@ onEvent(PuglView* view, const PuglEvent* event)
puglSetClipboard(
view, "text/plain", "Copied Text", strlen("Copied Text") + 1);
+ // Check that the new type is available immediately
+ assert(puglGetNumClipboardTypes(view) >= 1);
+ assert(!strcmp(puglGetClipboardType(view, 0), "text/plain"));
+
+ size_t len = 0;
+ const char* text = (const char*)puglGetClipboard(view, 0, &len);
+
+ // Check that the new contents are available immediately
+ assert(text);
+ assert(!strcmp(text, "Copied Text"));
+
} else if (test->iteration == 1) {
- const char* type = NULL;
size_t len = 0;
- const char* text = (const char*)puglGetClipboard(view, &type, &len);
+ const char* text = (const char*)puglGetClipboard(view, 0, &len);
- assert(!strcmp(type, "text/plain"));
+ // Check that the contents we pasted last iteration are still there
+ assert(text);
assert(!strcmp(text, "Copied Text"));
- test->state = FINISHED;
+ } else if (test->iteration == 2) {
+ // Start a "proper" paste
+ test->state = PASTED;
+ assert(!puglPaste(view));
}
++test->iteration;
break;
+ case PUGL_DATA_OFFER:
+ if (test->state == PASTED) {
+ test->state = RECEIVED_OFFER;
+
+ assert(!puglAcceptOffer(view, &event->offer, 0));
+ }
+ break;
+
+ case PUGL_DATA:
+ if (test->state == RECEIVED_OFFER) {
+ size_t len = 0;
+ const char* text = (const char*)puglGetClipboard(view, 0, &len);
+
+ // Check that the offered data is what we copied earlier
+ assert(text);
+ assert(!strcmp(text, "Copied Text"));
+
+ test->state = FINISHED;
+ }
+ break;
+
default:
break;
}