Skip to content

Commit f27bbb6

Browse files
committed
Add Clipboard tests for getAvailableTypeNames and getAvailableTypes
Part of #2126
1 parent ba112f0 commit f27bbb6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_dnd_Clipboard.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
package org.eclipse.swt.tests.junit;
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1415
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1517
import static org.junit.jupiter.api.Assumptions.assumeFalse;
1618
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1719

20+
import java.util.Arrays;
1821
import java.util.List;
1922
import java.util.concurrent.CompletableFuture;
2023
import java.util.concurrent.atomic.AtomicBoolean;
@@ -25,6 +28,7 @@
2528
import org.eclipse.swt.dnd.RTFTransfer;
2629
import org.eclipse.swt.dnd.TextTransfer;
2730
import org.eclipse.swt.dnd.Transfer;
31+
import org.eclipse.swt.dnd.TransferData;
2832
import org.eclipse.swt.layout.RowLayout;
2933
import org.eclipse.swt.widgets.Button;
3034
import org.eclipse.swt.widgets.Display;
@@ -353,4 +357,45 @@ public void test_getContentsAsync(int clipboardId) throws Exception {
353357
});
354358
assertEquals(helloWorld, result[0]);
355359
}
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+
}
356401
}

0 commit comments

Comments
 (0)