Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoratikhomirov2006-01-06 19:22:29 +0000
committeratikhomirov2006-01-06 19:22:29 +0000
commit5874d7d98a77c19a816e2b72277c752abd302282 (patch)
tree3f5bc6bde2cdce0e61b1313f6c06e7bb58948d2d /tests
parent136699f9f6899f4876594fa4126f9e118ea57534 (diff)
downloadorg.eclipse.gmf-tooling-5874d7d98a77c19a816e2b72277c752abd302282.tar.gz
org.eclipse.gmf-tooling-5874d7d98a77c19a816e2b72277c752abd302282.tar.xz
org.eclipse.gmf-tooling-5874d7d98a77c19a816e2b72277c752abd302282.zip
New plugin with IFigure codegeneration to support #114177 (graphical definition model) was added
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java6
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java186
3 files changed, 193 insertions, 2 deletions
diff --git a/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF
index 7871920d8..491bcd5ab 100644
--- a/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jface,
org.eclipse.gef,
org.eclipse.gmf.runtime.diagram.ui,
- org.eclipse.gmf.runtime.emf.commands.core
+ org.eclipse.gmf.runtime.emf.commands.core,
+ org.eclipse.gmf.graphdef.codegen
Bundle-Activator: org.eclipse.gmf.tests.Plugin
Eclipse-LazyStart: true
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
index 415938958..ece8f18db 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
@@ -19,6 +19,7 @@ import junit.framework.TestSuite;
import org.eclipse.gmf.tests.gef.DiagramNodeTest;
import org.eclipse.gmf.tests.gen.CompilationTest;
+import org.eclipse.gmf.tests.gen.FigureCodegenTest;
import org.eclipse.gmf.tests.gen.HandcodedImplTest;
import org.eclipse.gmf.tests.rt.LinkCreationConstraintsTest;
import org.eclipse.gmf.tests.setup.LinksSessionSetup;
@@ -30,7 +31,7 @@ import org.eclipse.gmf.tests.tr.GenModelTransformerBasicRTTest;
public class AllTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Tests for org.eclipse.gmf");
+ TestSuite suite = new TestSuite("Tests for org.eclipse.gmf, tooling side");
//$JUnit-BEGIN$
final SessionSetup sessionSetup = SessionSetup.newInstance();
@@ -40,6 +41,9 @@ public class AllTests {
suite.addTestSuite(TestSetupTest.class); // first, check sources/setups we use for rest of the tests
suite.addTest(feed(HandcodedImplTest.class, sessionSetup)); // then, check handcoded implementations are in place
+
+ suite.addTestSuite(FigureCodegenTest.class);
+ // fires new runtime workbench initialization
suite.addTestSuite(CompilationTest.class);
suite.addTest(feed(DiagramNodeTest.class, sessionSetup));
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java
new file mode 100644
index 000000000..ccb0fb345
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2005 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.gen;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.gmf.gmfgraph.ConnectionFigure;
+import org.eclipse.gmf.gmfgraph.CustomFigure;
+import org.eclipse.gmf.gmfgraph.Ellipse;
+import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
+import org.eclipse.gmf.gmfgraph.Label;
+import org.eclipse.gmf.gmfgraph.LineKind;
+import org.eclipse.gmf.gmfgraph.Point;
+import org.eclipse.gmf.gmfgraph.Polygon;
+import org.eclipse.gmf.gmfgraph.PolygonDecoration;
+import org.eclipse.gmf.gmfgraph.PolylineConnection;
+import org.eclipse.gmf.gmfgraph.Rectangle;
+import org.eclipse.gmf.gmfgraph.RoundedRectangle;
+import org.eclipse.gmf.graphdef.codegen.FigureGenerator;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+
+/**
+ * @author artem
+ *
+ */
+public class FigureCodegenTest extends TestCase {
+ private FigureGenerator figureGenerator;
+
+ public FigureCodegenTest(String name) {
+ super(name);
+ }
+
+ public void testGenPolylineConnection() {
+ performTests(ecoreContainmentRef());
+ }
+
+ public void testGenCustomFigure() {
+ performTests(figure1());
+ }
+
+ public void testGenSimpleShape() {
+ performTests(figure2());
+ }
+
+ public void testGenComplexShape() {
+ performTests(figure3());
+ }
+
+ public void testGenFigureWithoutPackageStmt() {
+ figureGenerator = new FigureGenerator(null);
+ testGenComplexShape();
+ }
+
+ private void performTests(Figure f) {
+ try {
+ String res = getGenerator().go(f);
+ assertNotNull("Generation should produce code", res);
+ ASTParser p = ASTParser.newParser(AST.JLS3);
+ p.setSource(res.toCharArray());
+ ASTNode astNode = p.createAST(null);
+ assertEquals("Generator is expected to produce cu", astNode.getNodeType(), ASTNode.COMPILATION_UNIT);
+ CompilationUnit cu = (CompilationUnit) astNode;
+ if (getGenerator().getPackageStatement() != null) {
+ assertNotNull("Generator initialized with packageName should produce package statement", cu.getPackage());
+ assertEquals("Package names are different", getGenerator().getPackageStatement(), cu.getPackage().getName().getFullyQualifiedName());
+ }
+ IProblem[] problems = cu.getProblems();
+ for (int i = 0; i < problems.length; i++) {
+ assertFalse(problems[i].getMessage() + ", line:" + problems[i].getSourceLineNumber() + ", pos:" + cu.getColumnNumber(problems[i].getSourceStart()), problems[i].isError());
+ }
+ } catch (JETException ex) {
+ fail(ex.getMessage());
+ }
+ }
+
+ // custom top-level, hierarchical children.
+ private Figure figure1() {
+ CustomFigure cf = GMFGraphFactory.eINSTANCE.createCustomFigure();
+ cf.setName("MyCylinder");
+ cf.setBundleName("org.eclipse.gmf.runtime.geoshapes");
+ cf.setQualifiedClassName("org.eclipse.gmf.runtime.geoshapes.internal.GeoShapeCylinder");
+ Point p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(1023);
+ p.setY(33);
+ cf.setSize(p);
+ cf.getChildren().add(figure2());
+ Ellipse e = GMFGraphFactory.eINSTANCE.createEllipse();
+ e.setName("Elli");
+ e.setFill(true);
+ cf.getChildren().add(e);
+ return cf;
+ }
+
+ // basic toplevel with plain list of children
+ private Figure figure2() {
+ Rectangle r = GMFGraphFactory.eINSTANCE.createRectangle();
+ r.setName("MyRect");
+ r.setFill(true);
+ r.setLineWidth(3);
+ r.setLineKind(LineKind.LINE_DASHDOT_LITERAL);
+ Label l1 = GMFGraphFactory.eINSTANCE.createLabel();
+ l1.setText("aaaaa");
+ l1.setName("L1");
+ Label l2 = GMFGraphFactory.eINSTANCE.createLabel();
+ l2.setText("bbbbb");
+ l2.setName("L2");
+ r.getChildren().add(l1);
+ r.getChildren().add(l2);
+ return r;
+ }
+
+ // basic toplebel with hierarhical list of children (one of them is custom, another is polygon)
+ private Figure figure3() {
+ RoundedRectangle r = GMFGraphFactory.eINSTANCE.createRoundedRectangle();
+ r.setName("Rounded1");
+ Polygon pg = GMFGraphFactory.eINSTANCE.createPolygon();
+ pg.setName("Polygon1");
+ Point p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(1);
+ p.setY(2);
+ pg.getTemplate().add(p);
+ p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(0);
+ p.setY(3);
+ pg.getTemplate().add(p);
+ p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(-2);
+ p.setY(-1);
+ pg.getTemplate().add(p);
+ r.getChildren().add(pg);
+ r.getChildren().add(figure1());
+ return r;
+ }
+
+ private ConnectionFigure ecoreContainmentRef() {
+ PolylineConnection cf = GMFGraphFactory.eINSTANCE.createPolylineConnection();
+ cf.setName("ContainmentRef");
+ PolygonDecoration df = createRhomb();
+ df.setFill(true);
+ cf.setSourceDecoration(df);
+ return cf;
+ }
+
+ private PolygonDecoration createRhomb() {
+ PolygonDecoration df = GMFGraphFactory.eINSTANCE.createPolygonDecoration();
+ Point p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(-1);
+ p.setY(1);
+ df.getTemplate().add(p);
+ p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(0);
+ p.setY(0);
+ df.getTemplate().add(p);
+ p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(-1);
+ p.setY(-1);
+ df.getTemplate().add(p);
+ p = GMFGraphFactory.eINSTANCE.createPoint();
+ p.setX(-2);
+ p.setY(0);
+ df.getTemplate().add(p);
+ return df;
+ }
+
+ private FigureGenerator getGenerator() {
+ if (figureGenerator == null) {
+ figureGenerator = new FigureGenerator("org.eclipse.gmf.tests.sample.figures");
+ }
+ return figureGenerator;
+ }
+}

Back to the top