Skip to content

Commit 7c742fc

Browse files
committed
Add tests for all DND transfer types
The individual Transfer types had no automatic testing, so this commit provides tests for all the transfer types and ensures copy/paste to external to SWT works too by implementing flavors for all types in the Swing remote clipboard test app. Part of #2126
1 parent d8fa1d5 commit 7c742fc

13 files changed

+1854
-12
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/graphics/ImageDataTestHelper.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package org.eclipse.swt.tests.graphics;
1616

1717
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
20+
import static org.junit.jupiter.api.Assertions.fail;
1821

1922
import java.lang.reflect.InvocationTargetException;
2023
import java.lang.reflect.Method;
@@ -226,4 +229,35 @@ public static void assertImageDataEqual(ImageData source, ImageData actual, Imag
226229

227230
assertArrayEquals(actual.data, expected.data);
228231
}
232+
233+
/**
234+
* Compares ImageData, allows for change in things like bit depth by comparing pixel values rather
235+
*/
236+
public static void assertImageDataEqualPixelValues(ImageData expected, ImageData actual) {
237+
if (expected == null) {
238+
assertNull(actual);
239+
}
240+
241+
if (TEST_BLIT_SHOW_IMAGES) {
242+
Image[] images = new Image[2];
243+
images[0] = new Image(Display.getCurrent(), expected);
244+
images[1] = new Image(Display.getCurrent(), actual);
245+
SwtTestUtil.debugDisplayImages(images, 2);
246+
images[0].dispose();
247+
images[1].dispose();
248+
}
249+
250+
assertEquals(expected.width, actual.width);
251+
assertEquals(expected.height, actual.height);
252+
if (expected.getRGBs() != null || actual.getRGBs() != null) {
253+
fail("We don't have code yet for comparing palettized image datas");
254+
}
255+
for (int x = 0; x < expected.width; x++) {
256+
for (int y = 0; y < expected.width; y++) {
257+
assertEquals(expected.getPixel(x, y), actual.getPixel(x, y));
258+
assertEquals(expected.getAlpha(x, y), actual.getAlpha(x, y));
259+
}
260+
}
261+
assertEquals(expected.transparentPixel, actual.transparentPixel);
262+
}
229263
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@
4343
Test_org_eclipse_swt_accessibility_AccessibleControlEvent.class, //
4444
Test_org_eclipse_swt_accessibility_AccessibleEvent.class, //
4545
Test_org_eclipse_swt_accessibility_AccessibleTextEvent.class, //
46-
Test_org_eclipse_swt_dnd_Clipboard.class,
46+
Test_org_eclipse_swt_dnd_ByteArrayTransfer.class, //
47+
Test_org_eclipse_swt_dnd_Clipboard.class, //
48+
Test_org_eclipse_swt_dnd_FileTransfer.class, //
49+
Test_org_eclipse_swt_dnd_HTMLTransfer.class, //
50+
Test_org_eclipse_swt_dnd_ImageTransfer.class, //
51+
Test_org_eclipse_swt_dnd_RTFTransfer.class, //
52+
Test_org_eclipse_swt_dnd_TextTransfer.class, //
53+
Test_org_eclipse_swt_dnd_URLTransfer.class, //
4754
Test_org_eclipse_swt_events_ArmEvent.class, //
4855
Test_org_eclipse_swt_events_ControlEvent.class, //
4956
Test_org_eclipse_swt_events_DisposeEvent.class, //

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

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public void start() throws Exception {
5555
"ClipboardTest", //
5656
"ClipboardCommands", //
5757
"ClipboardCommandsImpl", //
58-
"ClipboardTest$LocalHostOnlySocketFactory" //
58+
"ClipboardTest$FileListSelection", //
59+
"ClipboardTest$HtmlSelection", //
60+
"ClipboardTest$ImageSelection", //
61+
"ClipboardTest$LocalHostOnlySocketFactory", //
62+
"ClipboardTest$MyTypeSelection", //
63+
"ClipboardTest$RtfSelection", //
64+
"ClipboardTest$UrlSelection" //
5965
).forEach((f) -> {
6066
// extract the files and put them in the temp directory
6167
SwtTestUtil.copyFile("/clipboard/" + f + ".class",
@@ -85,6 +91,7 @@ public void start() throws Exception {
8591
throw new RuntimeException("Failed to get port");
8692
});
8793
assertNotEquals(0, port);
94+
8895
try {
8996
Registry reg = LocateRegistry.getRegistry("127.0.0.1", port);
9097
long stopTime = System.currentTimeMillis() + 10000;
@@ -186,6 +193,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
186193
}
187194
}
188195

196+
@Override
197+
public void setContents(String string) throws RemoteException {
198+
setContents(string, CLIPBOARD);
199+
}
200+
189201
@Override
190202
public void setContents(String string, int clipboardId) throws RemoteException {
191203
remote.setContents(string, clipboardId);
@@ -196,6 +208,11 @@ public void setFocus() throws RemoteException {
196208
remote.setFocus();
197209
}
198210

211+
@Override
212+
public String getStringContents() throws RemoteException {
213+
return getStringContents(CLIPBOARD);
214+
}
215+
199216
@Override
200217
public String getStringContents(int clipboardId) throws RemoteException {
201218
return remote.getStringContents(clipboardId);
@@ -207,7 +224,68 @@ public void waitUntilReady() throws RemoteException {
207224
}
208225

209226
@Override
210-
public void waitForButtonPress() throws RemoteException {
227+
public void waitForButtonPress() throws RemoteException {
211228
remote.waitForButtonPress();
212229
}
230+
231+
@Override
232+
public void setRtfContents(String test) throws RemoteException {
233+
remote.setRtfContents(test);
234+
}
235+
236+
@Override
237+
public String getRtfContents() throws RemoteException {
238+
return remote.getRtfContents();
239+
}
240+
241+
@Override
242+
public void setHtmlContents(String test) throws RemoteException {
243+
remote.setHtmlContents(test);
244+
}
245+
246+
@Override
247+
public String getHtmlContents() throws RemoteException {
248+
return remote.getHtmlContents();
249+
}
250+
251+
@Override
252+
public void setUrlContents(byte[] test) throws RemoteException {
253+
remote.setUrlContents(test);
254+
}
255+
256+
@Override
257+
public byte[] getUrlContents() throws RemoteException {
258+
return remote.getUrlContents();
259+
}
260+
261+
@Override
262+
public void setImageContents(byte[] imageContents) throws RemoteException {
263+
remote.setImageContents(imageContents);
264+
}
265+
266+
@Override
267+
public byte[] getImageContents() throws RemoteException {
268+
return remote.getImageContents();
269+
}
270+
271+
@Override
272+
public void setFileListContents(String[] fileList) throws RemoteException {
273+
remote.setFileListContents(fileList);
274+
}
275+
276+
@Override
277+
public String[] getFileListContents() throws RemoteException {
278+
return remote.getFileListContents();
279+
}
280+
281+
@Override
282+
public void setMyTypeContents(byte[] bytes) throws RemoteException {
283+
remote.setMyTypeContents(bytes);
284+
}
285+
286+
@Override
287+
public byte[] getMyTypeContents() throws RemoteException {
288+
return remote.getMyTypeContents();
289+
}
290+
213291
}

0 commit comments

Comments
 (0)