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 @@ -20,12 +20,10 @@
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.IOException;
import java.io.InputStream;
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;
Expand All @@ -50,6 +48,7 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.test.Screenshots;
import org.junit.rules.TemporaryFolder;

public class SwtTestUtil {
/**
Expand Down Expand Up @@ -582,26 +581,19 @@ 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) {
public static String getPath(String fileName, TemporaryFolder tempFolder) {
Path filePath = tempFolder.getRoot().toPath().resolve("image-resources").resolve(Path.of(fileName));
if (!Files.isRegularFile(filePath)) {
// Extract resource on the classpath to a temporary file to ensure it's
// available as plain file, even if this bundle is packed as jar
try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(fileName)) {
assertNotNull(inStream, "InputStream == null for file " + fileName);
Files.createDirectories(filePath.getParent());
Files.copy(inStream, filePath);
} catch (IOException 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();
return filePath.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


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 Down Expand Up @@ -49,7 +48,9 @@
import org.eclipse.swt.internal.DPIUtil;
import org.eclipse.swt.widgets.Display;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Automated Test Suite for class org.eclipse.swt.graphics.Image
Expand All @@ -58,6 +59,14 @@
*/
@SuppressWarnings("restriction")
public class Test_org_eclipse_swt_graphics_Image {

@ClassRule
public static TemporaryFolder tempFolder = new TemporaryFolder();

private static String getPath(String fileName) {
return SwtTestUtil.getPath(fileName, tempFolder);
}

ImageFileNameProvider imageFileNameProvider = zoom -> {
String fileName = switch (zoom) {
case 100 -> "collapseall.png";
Expand Down Expand Up @@ -319,11 +328,11 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String()

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
Exception e;
Exception e;

// Null provider
ImageFileNameProvider provider1 = null;
e = assertThrows(IllegalArgumentException.class, ()->new Image(display, provider1));
e = assertThrows(IllegalArgumentException.class, ()->new Image(display, provider1));
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_NULL_ARGUMENT, e);

// Invalid provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.swt.tests.junit;

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

import org.eclipse.swt.SWT;
Expand All @@ -23,7 +22,9 @@
import org.eclipse.swt.graphics.ImageDataProvider;
import org.eclipse.swt.graphics.ImageFileNameProvider;
import org.eclipse.swt.widgets.Display;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* When executed locally (outside Tycho build), this tests needs to be run as
Expand All @@ -32,6 +33,13 @@
*/
public class Test_org_eclipse_swt_internal_SVGRasterizer {

@ClassRule
public static TemporaryFolder tempFolder = new TemporaryFolder();

private static String getPath(String fileName) {
return SwtTestUtil.getPath(fileName, tempFolder);
}

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
ImageFileNameProvider validImageFileNameProvider = zoom -> getPath("collapseall.svg");
Expand Down
Loading