Skip to content

Commit ef32601

Browse files
committed
add regression test for svg feature
1 parent b627474 commit ef32601

File tree

12 files changed

+1029
-2
lines changed

12 files changed

+1029
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="JUnit Tests">
6+
<attributes>
7+
<attribute name="test" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.swt.svg.tests</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
8+
org.eclipse.jdt.core.compiler.release=enabled
9+
org.eclipse.jdt.core.compiler.source=21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.eclipse.swt.svg.tests.junit;
2+
3+
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
4+
import static org.junit.Assert.fail;
5+
6+
import java.io.File;
7+
import java.net.URISyntaxException;
8+
import java.nio.file.Path;
9+
import org.eclipse.swt.SWT;
10+
import org.eclipse.swt.SWTException;
11+
import org.eclipse.swt.graphics.Image;
12+
import org.eclipse.swt.graphics.ImageData;
13+
import org.eclipse.swt.graphics.ImageDataProvider;
14+
import org.eclipse.swt.graphics.ImageFileNameProvider;
15+
import org.eclipse.swt.tests.junit.SwtTestUtil;
16+
import org.eclipse.swt.widgets.Display;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
import org.osgi.framework.FrameworkUtil;
20+
21+
public class Test_org_eclipse_swt_graphics_SVGRasterizer {
22+
23+
Display display;
24+
25+
ImageFileNameProvider imageFileNameProvider = zoom -> {
26+
String fileName = "collapseall.svg";
27+
return getPath(fileName);
28+
};
29+
30+
ImageDataProvider imageDataProvider = zoom -> {
31+
String fileName = "collapseall.svg";
32+
return new ImageData(getPath(fileName), zoom);
33+
};
34+
35+
@Before
36+
public void setUp() {
37+
display = Display.getDefault();
38+
}
39+
40+
String getPath(String fileName) {
41+
String urlPath = "";
42+
String pluginPath = System.getProperty("PLUGIN_PATH");
43+
if (pluginPath == null) {
44+
urlPath = Path.of("data/" + fileName).toAbsolutePath().toString();
45+
} else {
46+
urlPath = pluginPath + "/data/" + fileName;
47+
}
48+
if (File.separatorChar != '/')
49+
urlPath = urlPath.replace('/', File.separatorChar);
50+
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0)
51+
urlPath = urlPath.substring(1);
52+
urlPath = urlPath.replaceAll("%20", " ");
53+
return urlPath;
54+
}
55+
56+
@Test
57+
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
58+
// Valid provider
59+
Image image = new Image(display, imageFileNameProvider);
60+
image.dispose();
61+
// Corrupt Image provider
62+
ImageFileNameProvider provider = zoom -> {
63+
String fileName = "corrupt.svg";
64+
return getPath(fileName);
65+
};
66+
try {
67+
image = new Image(display, provider);
68+
image.dispose();
69+
fail("No exception thrown for corrupt image file.");
70+
} catch (SWTException e) {
71+
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
72+
}
73+
}
74+
75+
@Test
76+
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() {
77+
// Valid provider
78+
Image image = new Image(display, imageDataProvider);
79+
image.dispose();
80+
// Corrupt Image provider
81+
ImageDataProvider provider = zoom -> {
82+
String fileName = "corrupt.svg";
83+
return new ImageData(getPath(fileName), zoom);
84+
};
85+
try {
86+
image = new Image(display, provider);
87+
image.dispose();
88+
fail("No exception thrown for corrupt image file.");
89+
} catch (SWTException e) {
90+
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
91+
}
92+
}
93+
}
Lines changed: 223 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)