diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_local_copy_paste.c | 48 | ||||
-rw-r--r-- | test/test_remote_copy_paste.c | 28 | ||||
-rw-r--r-- | test/test_utils.h | 6 |
3 files changed, 70 insertions, 12 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; } diff --git a/test/test_remote_copy_paste.c b/test/test_remote_copy_paste.c index 2ee90f7..07e75d9 100644 --- a/test/test_remote_copy_paste.c +++ b/test/test_remote_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 from one view to another @@ -23,6 +23,8 @@ typedef enum { START, EXPOSED, COPIED, + PASTED, + RECEIVED_OFFER, FINISHED, } State; @@ -60,6 +62,7 @@ onCopierEvent(PuglView* const view, const PuglEvent* const event) if (test->state < COPIED) { puglSetClipboard( view, "text/plain", "Copied Text", strlen("Copied Text") + 1); + test->state = COPIED; } @@ -92,18 +95,31 @@ onPasterEvent(PuglView* const view, const PuglEvent* const event) case PUGL_TIMER: assert(event->timer.id == pasterTimerId); - if (test->state == COPIED) { - const char* type = NULL; + test->state = PASTED; + assert(!puglPaste(view)); + } + 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, &type, &len); + const char* text = (const char*)puglGetClipboard(view, 0, &len); - assert(!strcmp(type, "text/plain")); + // Check that the offered data is what we copied earlier + assert(text); assert(!strcmp(text, "Copied Text")); test->state = FINISHED; } - break; default: diff --git a/test/test_utils.h b/test/test_utils.h index 2597537..b7a8f42 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -1,4 +1,4 @@ -// Copyright 2012-2020 David Robillard <d@drobilla.net> +// Copyright 2012-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC #ifndef TEST_TEST_UTILS_H @@ -170,6 +170,10 @@ printEvent(const PuglEvent* event, const char* prefix, const bool verbose) return PRINT("%sLoop enter\n", prefix); case PUGL_LOOP_LEAVE: return PRINT("%sLoop leave\n", prefix); + case PUGL_DATA_OFFER: + return PRINT("%sData offer\n", prefix); + case PUGL_DATA: + return PRINT("%sData\n", prefix); default: break; } |