Skip to content

Commit 8a57687

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 8826ca1 commit 8a57687

19 files changed

+1947
-15
lines changed

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/ClipboardBase.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.junit.jupiter.params.ParameterizedTest;
3232
import org.junit.jupiter.params.provider.MethodSource;
3333

34+
import clipboard.ClipboardTest;
35+
3436
/**
3537
* Base class for tests that test clipboard and transfer types
3638
*/
@@ -178,6 +180,28 @@ public void tearDown() throws Exception {
178180
}
179181
}
180182

183+
protected String addTrailingNulCharacter(String result) {
184+
return result + '\0';
185+
}
186+
187+
/**
188+
* Trim trailing nul character - some transfer types require a trailing nul when
189+
* copied to the clipboard, so use this method to remove it for tests that
190+
* obtain bytes from the {@link ClipboardTest} app.
191+
*
192+
* @param result to trim terminating nul character from
193+
* @return string with the nul character trimmed, or null if result was null.
194+
*/
195+
protected String trimTrailingNulCharacter(String result) {
196+
if (result == null) {
197+
return null;
198+
}
199+
if (result.charAt(result.length() - 1) == '\0') {
200+
result = result.substring(0, result.length() - 1);
201+
}
202+
return result;
203+
}
204+
181205
/**
182206
* Make sure to always copy/paste unique strings - this ensures that tests run
183207
* under {@link RepeatedTest}s don't false pass because of clipboard value on

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ private int launchRemote() throws IOException {
106106
"ClipboardTest", //
107107
"ClipboardCommands", //
108108
"ClipboardCommandsImpl", //
109-
"ClipboardTest$LocalHostOnlySocketFactory" //
109+
"ClipboardTest$LocalHostOnlySocketFactory", //
110+
"FileListSelection", //
111+
"HtmlSelection", //
112+
"ImageSelection", //
113+
"MyTypeSelection", //
114+
"RtfSelection", //
115+
"UrlSelection" //
110116
).forEach((f) -> {
111117
// extract the files and put them in the temp directory
112118
SwtTestUtil.copyFile("/clipboard/" + f + ".class",
@@ -141,6 +147,9 @@ private int launchRemote() throws IOException {
141147

142148
@Override
143149
public void stop() throws RemoteException {
150+
if (DEBUG_REMOTE) {
151+
return;
152+
}
144153
try {
145154
stopProcess();
146155
} catch (InterruptedException e) {
@@ -197,6 +206,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
197206
}
198207
}
199208

209+
@Override
210+
public void setContents(String string) throws RemoteException {
211+
setContents(string, CLIPBOARD);
212+
}
213+
200214
@Override
201215
public void setContents(String string, int clipboardId) throws RemoteException {
202216
remote.setContents(string, clipboardId);
@@ -207,6 +221,11 @@ public void setFocus() throws RemoteException {
207221
remote.setFocus();
208222
}
209223

224+
@Override
225+
public String getStringContents() throws RemoteException {
226+
return getStringContents(CLIPBOARD);
227+
}
228+
210229
@Override
211230
public String getStringContents(int clipboardId) throws RemoteException {
212231
return remote.getStringContents(clipboardId);
@@ -221,4 +240,65 @@ public void waitUntilReady() throws RemoteException {
221240
public void waitForButtonPress() throws RemoteException {
222241
remote.waitForButtonPress();
223242
}
224-
}
243+
244+
@Override
245+
public void setRtfContents(String test) throws RemoteException {
246+
remote.setRtfContents(test);
247+
}
248+
249+
@Override
250+
public String getRtfContents() throws RemoteException {
251+
return remote.getRtfContents();
252+
}
253+
254+
@Override
255+
public void setHtmlContents(String test) throws RemoteException {
256+
remote.setHtmlContents(test);
257+
}
258+
259+
@Override
260+
public String getHtmlContents() throws RemoteException {
261+
return remote.getHtmlContents();
262+
}
263+
264+
@Override
265+
public void setUrlContents(byte[] test) throws RemoteException {
266+
remote.setUrlContents(test);
267+
}
268+
269+
@Override
270+
public byte[] getUrlContents() throws RemoteException {
271+
return remote.getUrlContents();
272+
}
273+
274+
@Override
275+
public void setImageContents(byte[] imageContents) throws RemoteException {
276+
remote.setImageContents(imageContents);
277+
}
278+
279+
@Override
280+
public byte[] getImageContents() throws RemoteException {
281+
return remote.getImageContents();
282+
}
283+
284+
@Override
285+
public void setFileListContents(String[] fileList) throws RemoteException {
286+
remote.setFileListContents(fileList);
287+
}
288+
289+
@Override
290+
public String[] getFileListContents() throws RemoteException {
291+
return remote.getFileListContents();
292+
}
293+
294+
@Override
295+
public void setMyTypeContents(byte[] bytes) throws RemoteException {
296+
remote.setMyTypeContents(bytes);
297+
}
298+
299+
@Override
300+
public byte[] getMyTypeContents() throws RemoteException {
301+
return remote.getMyTypeContents();
302+
}
303+
304+
}

0 commit comments

Comments
 (0)