Skip to content

Commit 5cbf87b

Browse files
committed
Unify resource-read and clean-up test-resources in image related tests
1 parent 83257cc commit 5cbf87b

27 files changed

+32
-97
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertTrue;
2121
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2224

2325
import java.io.PrintStream;
26+
import java.net.URI;
27+
import java.net.URISyntaxException;
28+
import java.net.URL;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
2431
import java.util.concurrent.atomic.AtomicBoolean;
2532
import java.util.function.BooleanSupplier;
2633

@@ -574,4 +581,27 @@ public static boolean hasPixelNotMatching(Image image, Color nonMatchingColor, R
574581
}
575582
return false;
576583
}
584+
585+
public static String getPath(String fileName) {
586+
URI uri;
587+
String pluginPath = System.getProperty("PLUGIN_PATH");
588+
if (pluginPath == null) {
589+
URL url = SwtTestUtil.class.getResource(fileName);
590+
assertNotNull(url, "URL == null for file " + fileName);
591+
try {
592+
uri = url.toURI();
593+
} catch (URISyntaxException e) {
594+
throw new IllegalArgumentException(e);
595+
}
596+
} else {
597+
uri = URI.create(pluginPath + "/data/" + fileName);
598+
}
599+
// Fallback when test is locally executed as plug-in test
600+
Path path = Path.of(uri);
601+
if (!Files.exists(path)) {
602+
path = Path.of("data/" + fileName).toAbsolutePath();
603+
}
604+
assertTrue(Files.exists(path), "file not found: " + uri);
605+
return path.toString();
606+
}
577607
}

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
19+
import static org.eclipse.swt.tests.junit.SwtTestUtil.getPath;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNotNull;
@@ -26,10 +27,8 @@
2627
import static org.junit.Assume.assumeFalse;
2728
import static org.junit.Assume.assumeTrue;
2829

29-
import java.io.File;
3030
import java.io.IOException;
3131
import java.io.InputStream;
32-
import java.net.URL;
3332
import java.nio.file.Files;
3433
import java.nio.file.Path;
3534
import java.util.Comparator;
@@ -1167,26 +1166,7 @@ void getImageData2(int depth, PaletteData palette) {
11671166
gc.dispose();
11681167
image.dispose();
11691168
}
1170-
String getPath(String fileName) {
1171-
String urlPath;
1172-
1173-
String pluginPath = System.getProperty("PLUGIN_PATH");
1174-
if (pluginPath == null) {
1175-
URL url = getClass().getClassLoader().getResource(fileName);
1176-
if (url == null) {
1177-
fail("URL == null for file " + fileName);
1178-
}
1179-
urlPath = url.getFile();
1180-
} else {
1181-
urlPath = pluginPath + "/data/" + fileName;
1182-
}
11831169

1184-
if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);
1185-
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0) urlPath = urlPath.substring(1);
1186-
urlPath = urlPath.replaceAll("%20", " ");
1187-
1188-
return urlPath;
1189-
}
11901170
RGB getRealRGB(Color color) {
11911171
Image colorImage = new Image(display, 10, 10);
11921172
GC imageGc = new GC(colorImage);

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
package org.eclipse.swt.tests.junit;
1414

1515
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
16-
import static org.junit.Assert.fail;
16+
import static org.eclipse.swt.tests.junit.SwtTestUtil.getPath;
1717
import static org.junit.jupiter.api.Assertions.assertThrows;
18-
import static org.junit.jupiter.api.Assertions.assertTrue;
19-
20-
import java.io.File;
21-
import java.net.URL;
22-
import java.nio.file.Files;
23-
import java.nio.file.Path;
2418

2519
import org.eclipse.swt.SWT;
2620
import org.eclipse.swt.SWTException;
@@ -68,28 +62,4 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider()
6862
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
6963
}
7064

71-
String getPath(String fileName) {
72-
String urlPath = "";
73-
String pluginPath = System.getProperty("PLUGIN_PATH");
74-
if (pluginPath == null) {
75-
URL url = getClass().getClassLoader().getResource(fileName);
76-
if (url == null) {
77-
fail("URL == null for file " + fileName);
78-
}
79-
urlPath = url.getFile();
80-
} else {
81-
urlPath = pluginPath + "/data/" + fileName;
82-
}
83-
if (File.separatorChar != '/')
84-
urlPath = urlPath.replace('/', File.separatorChar);
85-
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0)
86-
urlPath = urlPath.substring(1);
87-
urlPath = urlPath.replaceAll("%20", " ");
88-
// Fallback when test is locally executed as plug-in test
89-
if (!Files.exists(Path.of(urlPath))) {
90-
urlPath = Path.of("data/" + fileName).toAbsolutePath().toString();
91-
}
92-
assertTrue(Files.exists(Path.of(urlPath)), "file not found: " + urlPath);
93-
return urlPath;
94-
}
9565
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/performance/SwtPerformanceTestCase.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,16 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit.performance;
1515

16-
17-
import static org.junit.Assert.fail;
18-
19-
import java.io.File;
20-
import java.net.URL;
21-
2216
import org.eclipse.swt.SWT;
2317
import org.eclipse.test.performance.Dimension;
2418
import org.eclipse.test.performance.Performance;
2519
import org.eclipse.test.performance.PerformanceMeter;
2620

27-
2821
public class SwtPerformanceTestCase {
29-
// used to specify verbose mode, if true unimplemented warning messages will
30-
// be written to System.out
31-
public static boolean verbose = false;
3222

3323
public final static boolean isGTK = SWT.getPlatform().equals("gtk");
3424
public final static boolean isWindows = SWT.getPlatform().startsWith("win32");
3525

36-
// allow specific image formats to be tested
37-
public static String[] imageFormats = new String[] {"bmp", "jpg", "gif", "png"};
38-
public static String[] imageFilenames = new String[] {"folder", "folderOpen", "target"};
39-
public static String[] transparentImageFilenames = new String[] {"transparent.png"};
40-
41-
4226
protected PerformanceMeter createMeter(String id) {
4327
Performance performance = Performance.getDefault();
4428
String scenarioId = "org.eclipse.swt.test." + id;
@@ -63,31 +47,4 @@ protected void disposeMeter(PerformanceMeter meter) {
6347
}
6448
}
6549

66-
protected String getPath(String fileName) {
67-
String urlPath;
68-
69-
String pluginPath = System.getProperty("PLUGIN_PATH");
70-
if (verbose) {
71-
System.out.println("PLUGIN_PATH <"+pluginPath+">");
72-
}
73-
if (pluginPath == null) {
74-
URL url = getClass().getClassLoader().getResource(fileName);
75-
if (url == null) {
76-
fail("URL == null for file " + fileName);
77-
}
78-
urlPath = url.getFile();
79-
} else {
80-
urlPath = pluginPath + "/data/" + fileName;
81-
}
82-
83-
if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);
84-
if (isWindows && urlPath.indexOf(File.separatorChar) == 0) urlPath = urlPath.substring(1);
85-
urlPath = urlPath.replaceAll("%20", " ");
86-
87-
if (verbose) {
88-
System.out.println("Resolved file name for " + fileName + " = " + urlPath);
89-
}
90-
return urlPath;
91-
}
92-
9350
}
-360 Bytes
Binary file not shown.
-551 Bytes
Binary file not shown.
-483 Bytes
Binary file not shown.
-1.41 KB
Binary file not shown.

tests/org.eclipse.swt.tests/data/corrupt.gif

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/org.eclipse.swt.tests/data/corrupt.jpg

Lines changed: 0 additions & 1 deletion
This file was deleted.
-9 Bytes
Binary file not shown.
Binary file not shown.

tests/org.eclipse.swt.tests/data/empty.txt

Whitespace-only changes.
-1.4 KB
Binary file not shown.
-898 Bytes
Binary file not shown.
-783 Bytes
Binary file not shown.
-921 Bytes
Binary file not shown.
-1.4 KB
Binary file not shown.
-905 Bytes
Binary file not shown.
-844 Bytes
Binary file not shown.
-937 Bytes
Binary file not shown.
-1.62 KB
Binary file not shown.
-972 Bytes
Binary file not shown.
-987 Bytes
Binary file not shown.
-980 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)