diff options
author | atikhomirov | 2006-04-21 17:44:54 +0000 |
---|---|---|
committer | atikhomirov | 2006-04-21 17:44:54 +0000 |
commit | 8d768fa51c93c82e6cedaa88d86f1441f88c1e63 (patch) | |
tree | 0c3bfcf10c5eefc702765fe2fc39b5424319b04f | |
parent | cabb22db66b75980a70749a2d0f652a3507cefd6 (diff) | |
download | org.eclipse.gmf-tooling-8d768fa51c93c82e6cedaa88d86f1441f88c1e63.tar.gz org.eclipse.gmf-tooling-8d768fa51c93c82e6cedaa88d86f1441f88c1e63.tar.xz org.eclipse.gmf-tooling-8d768fa51c93c82e6cedaa88d86f1441f88c1e63.zip |
[mgolubev] Tests for #137840 uncompiliable code if CustomFigure contains Label.
-rw-r--r-- | tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java | 2 | ||||
-rw-r--r-- | tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java | 94 |
2 files changed, 96 insertions, 0 deletions
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 1927062ae..c2efed87c 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 @@ -27,6 +27,7 @@ import org.eclipse.gmf.tests.gen.FigureCodegenTest; import org.eclipse.gmf.tests.gen.FigureLayoutTest; import org.eclipse.gmf.tests.gen.HandcodedGraphDefTest; import org.eclipse.gmf.tests.gen.HandcodedImplTest; +import org.eclipse.gmf.tests.gen.LabelSupportTest; import org.eclipse.gmf.tests.gen.MapModeStrategyTest; import org.eclipse.gmf.tests.gen.RTFigureTest; import org.eclipse.gmf.tests.gen.ShapePropertiesTest; @@ -66,6 +67,7 @@ public class AllTests { suite.addTestSuite(HistoryTest.class); suite.addTestSuite(FigureCodegenTest.class); + suite.addTestSuite(LabelSupportTest.class); suite.addTestSuite(ShapePropertiesTest.class); suite.addTestSuite(FigureLayoutTest.class); suite.addTestSuite(StandaloneMapModeTest.class); diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java new file mode 100644 index 000000000..05abb84e9 --- /dev/null +++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2006 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: + * Michael Golubev (Borland) - initial API and implementation + */ + +package org.eclipse.gmf.tests.gen; + +import java.lang.reflect.Method; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.emf.codegen.util.CodeGenUtil; +import org.eclipse.gmf.gmfgraph.CustomFigure; +import org.eclipse.gmf.gmfgraph.Dimension; +import org.eclipse.gmf.gmfgraph.Figure; +import org.eclipse.gmf.gmfgraph.GMFGraphFactory; +import org.eclipse.gmf.gmfgraph.Label; +import org.eclipse.gmf.gmfgraph.LabeledContainer; +import org.eclipse.gmf.gmfgraph.Rectangle; + +public class LabelSupportTest extends FigureCodegenTestBase { + private static final String LABEL_NAME = "Typename"; + + public LabelSupportTest(String name) { + super(name); + } + + public void testCustomFugureWithLabel(){ + CustomFigure custom = GMFGraphFactory.eINSTANCE.createCustomFigure(); + custom.setBundleName(DRAW2D); + custom.setQualifiedClassName(RectangleFigure.class.getName()); + + performChecks(custom, "CustomParent", LABEL_NAME); + } + + public void testRectangleWithLabel(){ + Rectangle simple = GMFGraphFactory.eINSTANCE.createRectangle(); + performChecks(simple, "SimpleParent", LABEL_NAME); + } + + public void testLabeledContainer(){ + LabeledContainer labeledContainer = GMFGraphFactory.eINSTANCE.createLabeledContainer(); + performChecks(labeledContainer, "LabeledContainerAlreadyHasLabel_DoesItNeedOneMore", LABEL_NAME); + } + + private void performChecks(Figure parent, String parentName, String labelName){ + parent.setName(parentName); + + Dimension prefSize = GMFGraphFactory.eINSTANCE.createDimension(); + prefSize.setDx(60); + prefSize.setDy(60); + parent.setPreferredSize(prefSize); + + Label label = GMFGraphFactory.eINSTANCE.createLabel(); + label.setName(labelName); + + parent.getChildren().add(label); + + performTests(parent, combineChecks(new GenericFigureCheck(parent), new LabelAccessorCheck(LABEL_NAME))); + } + + private static class LabelAccessorCheck extends FigureCheck { + private final String myLabelName; + private static final Class[] NO_PARAMS = new Class[0]; + + public LabelAccessorCheck(String labelName){ + myLabelName = labelName; + } + + public void checkFigure(IFigure figure) { + assertNotNull(figure); + assertTrue("NodeEditPart requires this method in the inner figure class", + hasMethod(figure, "getFigure" + CodeGenUtil.capName(myLabelName), NO_PARAMS)); + } + + private boolean hasMethod(Object instance, String methodName, Class[] params) { + try { + Method method = instance.getClass().getMethod(methodName, params); + return method != null; + } catch (SecurityException e) { + return false; + } catch (NoSuchMethodException e) { + return false; + } + } + } +} |