Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/org.eclipse.gmf.tests.lite/META-INF/MANIFEST.MF3
-rwxr-xr-xtests/org.eclipse.gmf.tests.lite/images/box.svg20
-rw-r--r--tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java4
-rw-r--r--tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/rt/svg/SVGFigureTest.java151
4 files changed, 175 insertions, 3 deletions
diff --git a/tests/org.eclipse.gmf.tests.lite/META-INF/MANIFEST.MF b/tests/org.eclipse.gmf.tests.lite/META-INF/MANIFEST.MF
index be4971ac4..5513379c7 100644
--- a/tests/org.eclipse.gmf.tests.lite/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.gmf.tests.lite/META-INF/MANIFEST.MF
@@ -25,6 +25,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui.views;bundle-version="[3.2.0,4.0.0)",
org.eclipse.gmf.runtime.lite;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.emf.common.ui;bundle-version="[2.3.0,3.0.0)"
+ org.eclipse.emf.common.ui;bundle-version="[2.3.0,3.0.0)",
+ org.eclipse.gmf.runtime.lite.svg;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/org.eclipse.gmf.tests.lite/images/box.svg b/tests/org.eclipse.gmf.tests.lite/images/box.svg
new file mode 100755
index 000000000..c33ef31ba
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests.lite/images/box.svg
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg
+ version="1.0"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ contentScriptType="text/ecmascript"
+ contentStyleType="text/css"
+ width="50.0px"
+ height="50.0px"
+ zoomAndPan="magnify"
+ preserveAspectRatio="xMidYMid meet">
+ <rect x="0" y="0" width="49" height="49" stroke="#000000" fill="#663300"/>
+ <line fill="none" x1="0" x2="49" y1="10" y2="10" stroke="#000000"/>
+ <line fill="none" x1="0" x2="49" y1="40" y2="40" stroke="#000000"/>
+ <line fill="none" x1="10" x2="10" y1="10" y2="40" stroke="#000000"/>
+ <line fill="none" x1="20" x2="20" y1="10" y2="40" stroke="#000000"/>
+ <line fill="none" x1="30" x2="30" y1="10" y2="40" stroke="#000000"/>
+ <line fill="none" x1="40" x2="40" y1="10" y2="40" stroke="#000000"/>
+</svg>
diff --git a/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java b/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java
index 5ebb0fc4a..d799290a5 100644
--- a/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java
+++ b/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java
@@ -28,6 +28,7 @@ import org.eclipse.gmf.tests.lite.gef.NotationRefreshTest;
import org.eclipse.gmf.tests.lite.gen.LiteCompilationTestWithImportConflicts;
import org.eclipse.gmf.tests.lite.multi.ShortcutCreationTest;
import org.eclipse.gmf.tests.lite.rt.ElementInitializerTest;
+import org.eclipse.gmf.tests.lite.rt.svg.SVGFigureTest;
import org.eclipse.gmf.tests.lite.setup.LibraryConstrainedSetup;
import org.eclipse.gmf.tests.lite.setup.LiteLinksSessionSetup;
import org.eclipse.gmf.tests.lite.setup.LiteSessionSetup;
@@ -60,9 +61,8 @@ public class AllTests {
suite.addTest(feed(ElementInitializerTest.class, sessionSetup2));
suite.addTest(feed(LinkCreationConstraintsTest.class, sessionSetup2));
suite.addTest(feed(NotationRefreshTest.class, sessionSetup3));
-
suite.addTest(feed(ShortcutCreationTest.class, multiSetup));
-
+ suite.addTestSuite(SVGFigureTest.class);
suite.addTest(new CleanupTest("testCleanup") {
protected void performCleanup() throws Exception {
sessionSetup.cleanup();
diff --git a/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/rt/svg/SVGFigureTest.java b/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/rt/svg/SVGFigureTest.java
new file mode 100644
index 000000000..3188a37f6
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/rt/svg/SVGFigureTest.java
@@ -0,0 +1,151 @@
+package org.eclipse.gmf.tests.lite.rt.svg;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.FlowLayout;
+import org.eclipse.draw2d.LightweightSystem;
+import org.eclipse.draw2d.RectangleFigure;
+import org.eclipse.gmf.runtime.lite.svg.SVGFigure;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+public class SVGFigureTest extends TestCase {
+
+ protected FigureCanvas canvas;
+
+ public SVGFigureTest() {
+ super("SVGFigure");
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay(), SWT.NO_TRIM);
+ shell.setSize(200, 200);
+ StackLayout layout = new StackLayout();
+ shell.setLayout(layout);
+ canvas = new FigureCanvas(shell, SWT.DOUBLE_BUFFERED, new LightweightSystem() {
+
+ @Override
+ public void paint(GC gc) {
+ gc.setAntialias(SWT.OFF);
+ super.paint(gc);
+ }
+ });
+ canvas.setContents(new RectangleFigure());
+ canvas.getContents().setLayoutManager(new FlowLayout());
+ canvas.getContents().setBackgroundColor(ColorConstants.yellow);
+ canvas.getContents().setForegroundColor(ColorConstants.green);
+ layout.topControl = canvas;
+ shell.open();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ canvas.getShell().close();
+ }
+
+ /**
+ * Revalidates and repaints the canvas. Should be called after changes to it and before content tests.
+ */
+ protected void flushCanvas() {
+ canvas.getLightweightSystem().getUpdateManager().performUpdate();
+ }
+
+ /**
+ * Saves canvas screenshot in workspace root for postmortem inspection.
+ */
+ protected void dumpCanvas(String filePrefix) {
+ Point size = canvas.getSize();
+ Image image = new Image(canvas.getDisplay(), size.x, size.y);
+ try {
+ GC gc = new GC(canvas);
+ gc.setAntialias(SWT.OFF);
+ try {
+ gc.copyArea(image, 0, 0);
+ } finally {
+ gc.dispose();
+ }
+ String fileName = filePrefix + ".png";
+ IPath root = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ if (root != null) {
+ fileName = root.append(fileName).toString();
+ }
+ ImageLoader loader = new ImageLoader();
+ loader.data = new ImageData[] { image.getImageData() };
+ loader.save(fileName, SWT.IMAGE_PNG);
+ } finally {
+ image.dispose();
+ }
+ }
+
+ /**
+ * Check that canvas has the specified color at the (x,y).
+ */
+ protected void assertColor(int x, int y, RGB expectedColor) {
+ RGB currentColor;
+ Image image = new Image(canvas.getDisplay(), 1, 1);
+ try {
+ GC gc = new GC(canvas);
+ gc.setAntialias(SWT.OFF);
+ try {
+ gc.copyArea(image, x, y);
+ } finally {
+ gc.dispose();
+ }
+ ImageData data = image.getImageData();
+ int pixel = data.getPixel(0, 0);
+ currentColor = data.palette.getRGB(pixel);
+ } finally {
+ image.dispose();
+ }
+ assertEquals(expectedColor, currentColor);
+ }
+
+ /**
+ * Check that test canvas is available.
+ */
+ public void testCanvasSetup() {
+ flushCanvas();
+ Point size = canvas.getSize();
+ assertEquals(size.x, 200);
+ assertEquals(size.y, 200);
+ assertColor(0, 0, ColorConstants.green.getRGB());
+ assertColor(1, 1, ColorConstants.yellow.getRGB());
+ assertColor(100, 100, ColorConstants.yellow.getRGB());
+ assertColor(198, 198, ColorConstants.yellow.getRGB());
+ assertColor(199, 199, ColorConstants.green.getRGB());
+ }
+
+ /**
+ * Check that SVGFigure loads documents.
+ */
+ public void testDocumentLoading() {
+ SVGFigure f = new SVGFigure();
+ f.setURI("platform:/plugin/org.eclipse.gmf.tests.lite/images/box.svg");
+ assertTrue(f.checkContentAvailable());
+ }
+
+ /**
+ * Check that SVGFigure renders documents.
+ */
+ public void testRendering() {
+ SVGFigure f = new SVGFigure();
+ f.setURI("platform:/plugin/org.eclipse.gmf.tests.lite/images/box.svg");
+ f.setPreferredSize(50, 50); // TODO : infer from doc; see #243051
+ canvas.getContents().add(f);
+ flushCanvas();
+ assertColor(0, 0, new RGB(0, 0, 0));
+ }
+}

Back to the top