Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ public static Comparator<ImageData> imageDataComparator() {
.thenComparing((ImageData firstData, ImageData secondData) -> {
for (int x = 0; x < firstData.width; x++) {
for (int y = 0; y < firstData.height; y++) {
if (firstData.getPixel(x, y) != secondData.getPixel(x, y)) {
RGB first = firstData.palette.getRGB(firstData.getPixel(x, y));
RGB second = secondData.palette.getRGB(secondData.getPixel(x, y));
if (!first.equals(second)) {
return -1;
}
if (firstData.getAlpha(x, y) != secondData.getAlpha(x, y)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
Test_org_eclipse_swt_accessibility_AccessibleControlEvent.class, //
Test_org_eclipse_swt_accessibility_AccessibleEvent.class, //
Test_org_eclipse_swt_accessibility_AccessibleTextEvent.class, //
Test_org_eclipse_swt_dnd_Clipboard.class,
Test_org_eclipse_swt_dnd_ByteArrayTransfer.class, //
Test_org_eclipse_swt_dnd_Clipboard.class, //
Test_org_eclipse_swt_dnd_FileTransfer.class, //
Test_org_eclipse_swt_dnd_HTMLTransfer.class, //
Test_org_eclipse_swt_dnd_ImageTransfer.class, //
Test_org_eclipse_swt_dnd_RTFTransfer.class, //
Test_org_eclipse_swt_dnd_TextTransfer.class, //
Test_org_eclipse_swt_dnd_URLTransfer.class, //
Test_org_eclipse_swt_events_ArmEvent.class, //
Test_org_eclipse_swt_events_ControlEvent.class, //
Test_org_eclipse_swt_events_DisposeEvent.class, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import clipboard.ClipboardTest;

/**
* Base class for tests that test clipboard and transfer types
*/
Expand Down Expand Up @@ -168,6 +170,7 @@ public void tearDown() throws Exception {
}
} finally {
if (clipboard != null) {
supportedClipboardIds().forEach(clipboard::clearContents);
clipboard.dispose();
}
if (shell != null) {
Expand All @@ -177,6 +180,28 @@ public void tearDown() throws Exception {
}
}

protected String addTrailingNulCharacter(String result) {
return result + '\0';
}

/**
* Trim trailing nul character - some transfer types require a trailing nul when
* copied to the clipboard, so use this method to remove it for tests that
* obtain bytes from the {@link ClipboardTest} app.
*
* @param result to trim terminating nul character from
* @return string with the nul character trimmed, or null if result was null.
*/
protected String trimTrailingNulCharacter(String result) {
if (result == null) {
return null;
}
if (result.charAt(result.length() - 1) == '\0') {
result = result.substring(0, result.length() - 1);
}
return result;
}

/**
* Make sure to always copy/paste unique strings - this ensures that tests run
* under {@link RepeatedTest}s don't false pass because of clipboard value on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,19 @@
import clipboard.ClipboardCommands;

public class RemoteClipboard implements ClipboardCommands {
/**
* Set to true to manually launch the ClipboardTest. This is useful so you can
* debug the Swing side.
*/
private static boolean DEBUG_REMOTE = false;
private ClipboardCommands remote;
private Process remoteClipboardProcess;
private Path remoteClipboardTempDir;

public void start() throws Exception {
assertNull(remote, "Create a new instance to restart");
/*
* The below copy using getPath may be redundant (i.e. it may be possible to run
* the class files from where they currently reside in the bin folder or the
* jar), but this method of setting up the class files is very simple and is
* done the same way that other files are extracted for tests.
*
* If the ClipboardTest starts to get more complicated, or other tests want to
* replicate this design element, then refactoring this is an option.
*/
remoteClipboardTempDir = Files.createTempDirectory("swt-test-Clipboard");
List.of( //
"ClipboardTest", //
"ClipboardCommands", //
"ClipboardCommandsImpl", //
"ClipboardTest$LocalHostOnlySocketFactory" //
).forEach((f) -> {
// extract the files and put them in the temp directory
SwtTestUtil.copyFile("/clipboard/" + f + ".class",
remoteClipboardTempDir.resolve("clipboard/" + f + ".class"));
});

String javaHome = System.getProperty("java.home");
String javaExe = javaHome + "/bin/java" + (SwtTestUtil.isWindowsOS ? ".exe" : "");
assertTrue(Files.exists(Path.of(javaExe)));

ProcessBuilder pb = new ProcessBuilder(javaExe, "clipboard.ClipboardTest")
.directory(remoteClipboardTempDir.toFile());
pb.inheritIO();
pb.redirectOutput(Redirect.PIPE);
remoteClipboardProcess = pb.start();

// Read server output to find the port
int port = SwtTestUtil.runOperationInThread(() -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(remoteClipboardProcess.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith(ClipboardCommands.PORT_MESSAGE)) {
String[] parts = line.split(":");
return Integer.parseInt(parts[1].trim());
}
}
throw new RuntimeException("Failed to get port");
});
assertNotEquals(0, port);
int port = DEBUG_REMOTE ? ClipboardCommands.DEFAULT_PORT : launchRemote();
try {
Registry reg = LocateRegistry.getRegistry("127.0.0.1", port);
long stopTime = System.currentTimeMillis() + 10000;
Expand Down Expand Up @@ -128,8 +91,65 @@ public void start() throws Exception {
remote.waitUntilReady();
}

private int launchRemote() throws IOException {
/*
* The below copy using getPath may be redundant (i.e. it may be possible to run
* the class files from where they currently reside in the bin folder or the
* jar), but this method of setting up the class files is very simple and is
* done the same way that other files are extracted for tests.
*
* If the ClipboardTest starts to get more complicated, or other tests want to
* replicate this design element, then refactoring this is an option.
*/
remoteClipboardTempDir = Files.createTempDirectory("swt-test-Clipboard");
List.of( //
"ClipboardTest", //
"ClipboardCommands", //
"ClipboardCommandsImpl", //
"ClipboardTest$LocalHostOnlySocketFactory", //
"FileListSelection", //
"HtmlSelection", //
"ImageSelection", //
"MyTypeSelection", //
"RtfSelection", //
"UrlSelection" //
).forEach((f) -> {
// extract the files and put them in the temp directory
SwtTestUtil.copyFile("/clipboard/" + f + ".class",
remoteClipboardTempDir.resolve("clipboard/" + f + ".class"));
});

String javaHome = System.getProperty("java.home");
String javaExe = javaHome + "/bin/java" + (SwtTestUtil.isWindowsOS ? ".exe" : "");
assertTrue(Files.exists(Path.of(javaExe)));

ProcessBuilder pb = new ProcessBuilder(javaExe, "clipboard.ClipboardTest", "-autoport")
.directory(remoteClipboardTempDir.toFile());
pb.inheritIO();
pb.redirectOutput(Redirect.PIPE);
remoteClipboardProcess = pb.start();

// Read server output to find the port
int port = SwtTestUtil.runOperationInThread(() -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(remoteClipboardProcess.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith(ClipboardCommands.PORT_MESSAGE)) {
String[] parts = line.split(":");
return Integer.parseInt(parts[1].trim());
}
}
throw new RuntimeException("Failed to get port");
});
assertNotEquals(0, port);
return port;
}

@Override
public void stop() throws RemoteException {
if (DEBUG_REMOTE) {
return;
}
try {
stopProcess();
} catch (InterruptedException e) {
Expand Down Expand Up @@ -186,6 +206,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
}

@Override
public void setContents(String string) throws RemoteException {
setContents(string, CLIPBOARD);
}

@Override
public void setContents(String string, int clipboardId) throws RemoteException {
remote.setContents(string, clipboardId);
Expand All @@ -196,6 +221,11 @@ public void setFocus() throws RemoteException {
remote.setFocus();
}

@Override
public String getStringContents() throws RemoteException {
return getStringContents(CLIPBOARD);
}

@Override
public String getStringContents(int clipboardId) throws RemoteException {
return remote.getStringContents(clipboardId);
Expand All @@ -207,7 +237,68 @@ public void waitUntilReady() throws RemoteException {
}

@Override
public void waitForButtonPress() throws RemoteException {
public void waitForButtonPress() throws RemoteException {
remote.waitForButtonPress();
}
}

@Override
public void setRtfContents(String test) throws RemoteException {
remote.setRtfContents(test);
}

@Override
public String getRtfContents() throws RemoteException {
return remote.getRtfContents();
}

@Override
public void setHtmlContents(String test) throws RemoteException {
remote.setHtmlContents(test);
}

@Override
public String getHtmlContents() throws RemoteException {
return remote.getHtmlContents();
}

@Override
public void setUrlContents(byte[] test) throws RemoteException {
remote.setUrlContents(test);
}

@Override
public byte[] getUrlContents() throws RemoteException {
return remote.getUrlContents();
}

@Override
public void setImageContents(byte[] imageContents) throws RemoteException {
remote.setImageContents(imageContents);
}

@Override
public byte[] getImageContents() throws RemoteException {
return remote.getImageContents();
}

@Override
public void setFileListContents(String[] fileList) throws RemoteException {
remote.setFileListContents(fileList);
}

@Override
public String[] getFileListContents() throws RemoteException {
return remote.getFileListContents();
}

@Override
public void setMyTypeContents(byte[] bytes) throws RemoteException {
remote.setMyTypeContents(bytes);
}

@Override
public byte[] getMyTypeContents() throws RemoteException {
return remote.getMyTypeContents();
}

}
Loading
Loading