Skip to content

Commit 07f860c

Browse files
committed
add regression test for svg feature
1 parent f77c69b commit 07f860c

File tree

6 files changed

+960
-1
lines changed

6 files changed

+960
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public ImageData[] load(InputStream stream, int zoom) {
193193
}
194194
}
195195
} catch (IOException e) {
196-
//ignore.
196+
SWT.error(SWT.ERROR_INVALID_IMAGE);
197197
}
198198
}
199199
return loadDefault(stream);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.eclipse.swt.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.URL;
8+
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.widgets.Display;
16+
import org.junit.Before;
17+
import org.junit.Test;
18+
19+
public class Test_org_eclipse_swt_graphics_SVGRasterizer {
20+
Display display;
21+
22+
ImageFileNameProvider imageFileNameProvider = zoom -> {
23+
String fileName = "collapseall.svg";
24+
return getPath(fileName);
25+
};
26+
27+
ImageDataProvider imageDataProvider = zoom -> {
28+
String fileName = "collapseall.svg";
29+
return new ImageData(getPath(fileName), zoom);
30+
};
31+
32+
@Before
33+
public void setUp() {
34+
display = Display.getDefault();
35+
}
36+
37+
String getPath(String fileName) {
38+
String urlPath;
39+
String pluginPath = System.getProperty("PLUGIN_PATH");
40+
if (pluginPath == null) {
41+
URL url = getClass().getClassLoader().getResource(fileName);
42+
if (url == null) {
43+
fail("URL == null for file " + fileName);
44+
}
45+
urlPath = url.getFile();
46+
} else {
47+
urlPath = pluginPath + "/data/" + fileName;
48+
}
49+
50+
if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);
51+
if (SwtTestUtil.isWindows && urlPath.indexOf(File.separatorChar) == 0) 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)