|
11 | 11 | package org.eclipse.swt.tests.junit; |
12 | 12 |
|
13 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
14 | 15 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 16 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
15 | 17 | import static org.junit.jupiter.api.Assumptions.assumeFalse; |
16 | 18 | import static org.junit.jupiter.api.Assumptions.assumeTrue; |
17 | 19 |
|
| 20 | +import java.util.Arrays; |
18 | 21 | import java.util.List; |
19 | 22 | import java.util.concurrent.CompletableFuture; |
20 | 23 | import java.util.concurrent.atomic.AtomicBoolean; |
|
25 | 28 | import org.eclipse.swt.dnd.RTFTransfer; |
26 | 29 | import org.eclipse.swt.dnd.TextTransfer; |
27 | 30 | import org.eclipse.swt.dnd.Transfer; |
| 31 | +import org.eclipse.swt.dnd.TransferData; |
28 | 32 | import org.eclipse.swt.layout.RowLayout; |
29 | 33 | import org.eclipse.swt.widgets.Button; |
30 | 34 | import org.eclipse.swt.widgets.Display; |
@@ -353,4 +357,45 @@ public void test_getContentsAsync(int clipboardId) throws Exception { |
353 | 357 | }); |
354 | 358 | assertEquals(helloWorld, result[0]); |
355 | 359 | } |
| 360 | + |
| 361 | + @ParameterizedTest |
| 362 | + @MethodSource("supportedClipboardIds") |
| 363 | + public void test_getAvailableTypeNames(int clipboardId) throws Exception { |
| 364 | + openAndFocusRemote(); |
| 365 | + String helloWorld = getUniqueTestString(); |
| 366 | + remote.setContents(helloWorld, clipboardId); |
| 367 | + |
| 368 | + openAndFocusShell(false); |
| 369 | + String[] availableTypeNames = clipboard.getAvailableTypeNames(); |
| 370 | + // The actual contents of type names is platform specific, so we just |
| 371 | + // verify that we get something. |
| 372 | + assertNotNull(availableTypeNames); |
| 373 | + assertTrue(availableTypeNames.length > 0); |
| 374 | + } |
| 375 | + |
| 376 | + @ParameterizedTest |
| 377 | + @MethodSource("supportedClipboardIds") |
| 378 | + public void test_getAvailableTypes(int clipboardId) throws Exception { |
| 379 | + openAndFocusRemote(); |
| 380 | + String helloWorld = getUniqueTestString(); |
| 381 | + remote.setContents(helloWorld, clipboardId); |
| 382 | + |
| 383 | + openAndFocusShell(false); |
| 384 | + TransferData[] availableTypes = clipboard.getAvailableTypes(clipboardId); |
| 385 | + assertTrue(Arrays.stream(availableTypes).anyMatch(textTransfer::isSupportedType)); |
| 386 | + |
| 387 | + helloWorld = getUniqueTestString(); |
| 388 | + String helloWorldRtf = "{\\rtf1\\b\\i " + helloWorld + "}"; |
| 389 | + clipboard.setContents(new Object[] { helloWorld, helloWorldRtf }, new Transfer[] { textTransfer, rtfTransfer }, |
| 390 | + clipboardId); |
| 391 | + availableTypes = clipboard.getAvailableTypes(clipboardId); |
| 392 | + assertTrue(Arrays.stream(availableTypes).anyMatch(textTransfer::isSupportedType)); |
| 393 | + assertTrue(Arrays.stream(availableTypes).anyMatch(rtfTransfer::isSupportedType)); |
| 394 | + |
| 395 | + helloWorld = getUniqueTestString(); |
| 396 | + helloWorldRtf = "{\\rtf1\\b\\i " + helloWorld + "}"; |
| 397 | + clipboard.setContents(new Object[] { helloWorldRtf }, new Transfer[] { rtfTransfer }, clipboardId); |
| 398 | + availableTypes = clipboard.getAvailableTypes(clipboardId); |
| 399 | + assertTrue(Arrays.stream(availableTypes).anyMatch(rtfTransfer::isSupportedType)); |
| 400 | + } |
356 | 401 | } |
0 commit comments