Skip to content

Unify resource-read and clean-up test-resources in image related tests #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -19,8 +19,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;

Expand Down Expand Up @@ -574,4 +581,27 @@ public static boolean hasPixelNotMatching(Image image, Color nonMatchingColor, R
}
return false;
}

public static String getPath(String fileName) {
URI uri;
String pluginPath = System.getProperty("PLUGIN_PATH");
if (pluginPath == null) {
URL url = SwtTestUtil.class.getResource(fileName);
assertNotNull(url, "URL == null for file " + fileName);
try {
uri = url.toURI();
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
} else {
uri = URI.create(pluginPath + "/data/" + fileName);
}
// Fallback when test is locally executed as plug-in test
Path path = Path.of(uri);
if (!Files.exists(path)) {
path = Path.of("data/" + fileName).toAbsolutePath();
}
assertTrue(Files.exists(path), "file not found: " + uri);
return path.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
import static org.eclipse.swt.tests.junit.SwtTestUtil.getPath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -26,10 +27,8 @@
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
Expand Down Expand Up @@ -1167,26 +1166,7 @@ void getImageData2(int depth, PaletteData palette) {
gc.dispose();
image.dispose();
}
String getPath(String fileName) {
String urlPath;

String pluginPath = System.getProperty("PLUGIN_PATH");
if (pluginPath == null) {
URL url = getClass().getClassLoader().getResource(fileName);
if (url == null) {
fail("URL == null for file " + fileName);
}
urlPath = url.getFile();
} else {
urlPath = pluginPath + "/data/" + fileName;
}

if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0) urlPath = urlPath.substring(1);
urlPath = urlPath.replaceAll("%20", " ");

return urlPath;
}
RGB getRealRGB(Color color) {
Image colorImage = new Image(display, 10, 10);
GC imageGc = new GC(colorImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
package org.eclipse.swt.tests.junit;

import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
import static org.junit.Assert.fail;
import static org.eclipse.swt.tests.junit.SwtTestUtil.getPath;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

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

String getPath(String fileName) {
String urlPath = "";
String pluginPath = System.getProperty("PLUGIN_PATH");
if (pluginPath == null) {
URL url = getClass().getClassLoader().getResource(fileName);
if (url == null) {
fail("URL == null for file " + fileName);
}
urlPath = url.getFile();
} else {
urlPath = pluginPath + "/data/" + fileName;
}
if (File.separatorChar != '/')
urlPath = urlPath.replace('/', File.separatorChar);
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0)
urlPath = urlPath.substring(1);
urlPath = urlPath.replaceAll("%20", " ");
// Fallback when test is locally executed as plug-in test
if (!Files.exists(Path.of(urlPath))) {
urlPath = Path.of("data/" + fileName).toAbsolutePath().toString();
}
assertTrue(Files.exists(Path.of(urlPath)), "file not found: " + urlPath);
return urlPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,16 @@
*******************************************************************************/
package org.eclipse.swt.tests.junit.performance;


import static org.junit.Assert.fail;

import java.io.File;
import java.net.URL;

import org.eclipse.swt.SWT;
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;


public class SwtPerformanceTestCase {
// used to specify verbose mode, if true unimplemented warning messages will
// be written to System.out
public static boolean verbose = false;

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

// allow specific image formats to be tested
public static String[] imageFormats = new String[] {"bmp", "jpg", "gif", "png"};
public static String[] imageFilenames = new String[] {"folder", "folderOpen", "target"};
public static String[] transparentImageFilenames = new String[] {"transparent.png"};


protected PerformanceMeter createMeter(String id) {
Performance performance = Performance.getDefault();
String scenarioId = "org.eclipse.swt.test." + id;
Expand All @@ -63,31 +47,4 @@ protected void disposeMeter(PerformanceMeter meter) {
}
}

protected String getPath(String fileName) {
String urlPath;

String pluginPath = System.getProperty("PLUGIN_PATH");
if (verbose) {
System.out.println("PLUGIN_PATH <"+pluginPath+">");
}
if (pluginPath == null) {
URL url = getClass().getClassLoader().getResource(fileName);
if (url == null) {
fail("URL == null for file " + fileName);
}
urlPath = url.getFile();
} else {
urlPath = pluginPath + "/data/" + fileName;
}

if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);
if (isWindows && urlPath.indexOf(File.separatorChar) == 0) urlPath = urlPath.substring(1);
urlPath = urlPath.replaceAll("%20", " ");

if (verbose) {
System.out.println("Resolved file name for " + fileName + " = " + urlPath);
}
return urlPath;
}

}
Binary file removed tests/org.eclipse.swt.tests/data/collapseall.png
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/[email protected]
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/[email protected]
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/corrupt.bmp
Binary file not shown.
1 change: 0 additions & 1 deletion tests/org.eclipse.swt.tests/data/corrupt.gif

This file was deleted.

1 change: 0 additions & 1 deletion tests/org.eclipse.swt.tests/data/corrupt.jpg

This file was deleted.

Binary file removed tests/org.eclipse.swt.tests/data/corrupt.png
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/corruptBadBitDepth.png
Binary file not shown.
Empty file.
Binary file removed tests/org.eclipse.swt.tests/data/folder.bmp
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folder.gif
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folder.jpg
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folder.png
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folderOpen.bmp
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folderOpen.gif
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folderOpen.jpg
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/folderOpen.png
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/target.bmp
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/target.gif
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/target.jpg
Binary file not shown.
Binary file removed tests/org.eclipse.swt.tests/data/target.png
Binary file not shown.
Loading