Skip to content

Commit 1d66a9c

Browse files
committed
work on windows
1 parent 776b3ec commit 1d66a9c

File tree

8 files changed

+51
-39
lines changed

8 files changed

+51
-39
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ public static Comparator<ImageData> imageDataComparator() {
223223
.thenComparing((ImageData firstData, ImageData secondData) -> {
224224
for (int x = 0; x < firstData.width; x++) {
225225
for (int y = 0; y < firstData.height; y++) {
226-
if (firstData.getPixel(x, y) != secondData.getPixel(x, y)) {
226+
RGB first = firstData.palette.getRGB(firstData.getPixel(x, y));
227+
RGB second = secondData.palette.getRGB(secondData.getPixel(x, y));
228+
if (!first.equals(second)) {
227229
return -1;
228230
}
229231
if (firstData.getAlpha(x, y) != secondData.getAlpha(x, y)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public static class MyType {
215215
// the code in the ByteArrayTransfer javadoc
216216
public static class MyTypeTransfer extends ByteArrayTransfer {
217217

218-
private static final String MYTYPENAME = "application/my_type_name";
218+
private static final String MYTYPENAME = "my_type_name";
219219
private static final int MYTYPEID = registerType(MYTYPENAME);
220220
private static MyTypeTransfer _instance = new MyTypeTransfer();
221221

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,7 @@ public void test_javaToNative() throws Exception {
152152
setContents(test);
153153
openAndFocusRemote();
154154
String result = SwtTestUtil.runOperationInThread(() -> remote.getHtmlContents());
155-
// HtmlTransfer.javaToNative on GTK (as of this writing) purposely adds a \0
156-
// byte at the end of the stream. XXX: I don't think this is needed, and
157-
// in other transfers such as Text and RTF this is not done. However receiving
158-
// programs, such as LibreOffice Writer, do not seem negatively affected, so
159-
// this test is written permissively. This permissiveness also exists in the
160-
// implementation of HtmlTransfer.nativeToJava which trims the trailing \0
161-
// on incoming transfers.
162-
if (result.charAt(result.length() - 1) == '\0') {
163-
result = result.substring(0, result.length() - 1);
164-
}
155+
result = trimTrailingNulCharacter(result);
165156
assertEquals(test, result);
166157
}
167158
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void test_nativeToJava() throws Exception {
125125
String test = toRtf(getUniqueTestString());
126126

127127
openAndFocusRemote();
128-
remote.setRtfContents(test);
128+
remote.setRtfContents(addTrailingNulCharacter(test));
129129
openAndFocusShell(false);
130130
assertEquals(test, getContents());
131131
}
@@ -139,6 +139,7 @@ public void test_javaToNative() throws Exception {
139139
setContents(test);
140140
openAndFocusRemote();
141141
String result = SwtTestUtil.runOperationInThread(() -> remote.getRtfContents());
142+
result = trimTrailingNulCharacter(result);
142143
assertEquals(test, result);
143144
}
144145
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public void test_javaToNative(String name, String test) throws Exception {
145145
setContents(test);
146146
openAndFocusRemote();
147147
String result = SwtTestUtil.runOperationInThread(() -> remote.getStringContents());
148+
result = trimTrailingNulCharacter(result);
148149
assertEquals(test, result);
149150
}
150151
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public void test_nativeToJava() throws Exception {
128128
String test = getURLTransferString();
129129

130130
openAndFocusRemote();
131-
// This is an attempt to recreate the same bytestream that Firefox provides when
132-
// doing text/x-moz-url which appears to be this encoding (specifically no BOM)
131+
133132
byte[] bytes = test.getBytes(StandardCharsets.UTF_16LE);
134133
remote.setUrlContents(bytes);
135134
openAndFocusShell(false);
@@ -149,14 +148,7 @@ public void test_javaToNative() throws Exception {
149148
// This is an attempt to recreate the same bytestream that Firefox provides when
150149
// doing text/x-moz-url which appears to be this encoding (specifically no BOM)
151150
String result = new String(bytes, StandardCharsets.UTF_16LE);
152-
// HtmlTransfer.javaToNative on GTK (as of this writing) purposely adds a \0
153-
// char at the end of the stream. XXX: I don't think this is needed, and
154-
// in other transfers such as Text and RTF this is not done. This permissiveness
155-
// also exists in the implementation of HtmlTransfer.nativeToJava which trims
156-
// the trailing \0 on incoming transfers.
157-
if (result.charAt(result.length() - 1) == '\0') {
158-
result = result.substring(0, result.length() - 1);
159-
}
151+
result = trimTrailingNulCharacter(result);
160152
assertEquals(test, result);
161153
}
162154
}

tests/org.eclipse.swt.tests/data/clipboard/ClipboardTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ private static int getAvailablePort() throws IOException {
164164
try {
165165
RTF_InputStream = new DataFlavor("text/rtf;class=java.io.InputStream");
166166
HTML_InputStream = new DataFlavor("text/html;class=java.io.InputStream");
167-
URL_InputStream = new DataFlavor("text/x-moz-url;class=java.io.InputStream");
168-
MyType_InputStream = new DataFlavor("application/my_type_name;class=java.io.InputStream");
167+
URL_InputStream = new DataFlavor("application/x-uniform-resourcelocatorw;class=java.io.InputStream",
168+
"UniformResourceLocatorW");
169+
MyType_InputStream = new DataFlavor("application/x-my_type_name;class=java.io.InputStream", "my_type_name");
169170
} catch (ClassNotFoundException e) {
170171
throw new RuntimeException(e);
171172
}
@@ -225,26 +226,26 @@ static void registerUrlNatives() {
225226

226227
String os = System.getProperty("os.name", "").toLowerCase();
227228
if (os.contains("win")) {
228-
String nativeFmt = "HTML Format";
229-
map.addUnencodedNativeForFlavor(HTML_InputStream, nativeFmt);
230-
map.addFlavorForUnencodedNative(nativeFmt, HTML_InputStream);
229+
String nativeFmt = "UniformResourceLocatorW";
230+
map.addUnencodedNativeForFlavor(URL_InputStream, nativeFmt);
231+
map.addFlavorForUnencodedNative(nativeFmt, URL_InputStream);
231232
} else if (os.contains("mac")) {
232-
String nativeFmt = "public.html";
233-
map.addUnencodedNativeForFlavor(HTML_InputStream, nativeFmt);
234-
map.addFlavorForUnencodedNative(nativeFmt, HTML_InputStream);
233+
String nativeFmt = "public.url";
234+
map.addUnencodedNativeForFlavor(URL_InputStream, nativeFmt);
235+
map.addFlavorForUnencodedNative(nativeFmt, URL_InputStream);
235236
} else {
236237
// X11/Wayland
237-
for (String nativeFmt : List.of("text/html")) {
238-
map.addUnencodedNativeForFlavor(HTML_InputStream, nativeFmt);
239-
map.addFlavorForUnencodedNative(nativeFmt, HTML_InputStream);
240-
}
238+
String nativeFmt = "text/x-moz-url";
239+
map.addUnencodedNativeForFlavor(URL_InputStream, nativeFmt);
240+
map.addFlavorForUnencodedNative(nativeFmt, URL_InputStream);
241+
241242
}
242243
}
243244

244245
static void registerMyTypeNatives() {
245246
SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
246-
map.addUnencodedNativeForFlavor(URL_InputStream, "my_type_name");
247-
map.addFlavorForUnencodedNative("my_type_name", URL_InputStream);
247+
map.addUnencodedNativeForFlavor(MyType_InputStream, "my_type_name");
248+
map.addFlavorForUnencodedNative("my_type_name", MyType_InputStream);
248249
}
249250

250251
static class RtfSelection implements Transferable {
@@ -304,8 +305,8 @@ public Object getTransferData(DataFlavor f) throws UnsupportedFlavorException {
304305
static class UrlSelection implements Transferable {
305306
private final byte[] url;
306307

307-
UrlSelection(byte[] html) {
308-
this.url = html;
308+
UrlSelection(byte[] url) {
309+
this.url = url;
309310
}
310311

311312
@Override

0 commit comments

Comments
 (0)