diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.ecore b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.ecore new file mode 100644 index 0000000000..b73e2e827b --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.ecore @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.odesign new file mode 100644 index 0000000000..0426e57db3 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/My.odesign @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/representations.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/representations.aird new file mode 100644 index 0000000000..766a3922da --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/edgeLabelLocationZoom/representations.aird @@ -0,0 +1,645 @@ + + + + My.ecore + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + labelSize + labelFormat + labelColor + hideLabelByDefault + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + hideLabelByDefault + labelColor + labelFormat + labelSize + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + size + centered + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + labelSize + labelFormat + labelColor + hideLabelByDefault + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + hideLabelByDefault + labelColor + labelFormat + labelSize + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + size + centered + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + labelSize + labelFormat + labelColor + hideLabelByDefault + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + workspacePath + hideLabelByDefault + labelColor + labelFormat + labelSize + bold + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + size + centered + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeLabelLocationZoomTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeLabelLocationZoomTest.java new file mode 100644 index 0000000000..592cb09a6b --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeLabelLocationZoomTest.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2024 THALES GLOBAL SERVICES. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.swtbot; + +import java.util.Arrays; +import java.util.Collection; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeNameEditPart; +import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; +import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation; +import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation.ZoomLevel; +import org.eclipse.sirius.tests.swtbot.support.api.business.UILocalSession; +import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource; +import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * This test verifies that an edge label is always at the same position, whatever the zoom and shape of the edge. In + * particular, for a borderline case with the shape of the edge. + * + * @author scosta + */ +@RunWith(Parameterized.class) +public class EdgeLabelLocationZoomTest extends AbstractSiriusSwtBotGefTestCase { + + private static final String MODEL = "My.ecore"; + + private static final String SESSION_FILE = "representations.aird"; + + private static final String VSM_FILE = "My.odesign"; + + private static final String DATA_UNIT_DIR = "data/unit/edgeLabelLocationZoom/"; + + private static final String REPRESENTATION_DESCRIPTION_NAME = "DTestBugLabelEdge"; + + private String representationName; + + private ZoomLevel zoom; + + private UIResource sessionAirdResource; + + private UILocalSession localSession; + + /** + * Current diagram. + */ + protected UIDiagramRepresentation diagram; + + public EdgeLabelLocationZoomTest(String testName, String representationName, ZoomLevel zoom) { + this.representationName = representationName; + this.zoom = zoom; + setName("testEdgeLabelLocationWithZoom." + representationName + "." + zoom); + } + + @Parameterized.Parameters(name = "{0}") + public static Collection getParameters() { + String[] representations = { "testLabelZoomBugLimitCase1", "testLabelZoomBugLimitCase2", "testLabelZoomNormalCase" }; + ZoomLevel[] zooms = ZoomLevel.values(); + var x = Arrays.stream(representations).flatMap((String representation) -> { + return Arrays.stream(zooms).map(zoom -> { + String testName = "diagram '" + representation + "' with zoom" + zoom.getLevel(); + return new Object[] { testName, representation, zoom }; + }); + }).toList(); + return x; + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onSetUpBeforeClosingWelcomePage() throws Exception { + copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, MODEL, SESSION_FILE, VSM_FILE); + + } + + /** + * {@inheritDoc} + */ + @Override + protected void onSetUpAfterOpeningDesignerPerspective() throws Exception { + sessionAirdResource = new UIResource(designerProject, "/", SESSION_FILE); + localSession = designerPerspective.openSessionFromFile(sessionAirdResource); + } + + private void assertBoundsEquals(String message, Rectangle expected, Rectangle actual, double delta) { + boolean xCheck = Math.abs(expected.preciseX() - actual.preciseX()) <= delta; + boolean yCheck = Math.abs(expected.preciseY() - actual.preciseY()) <= delta; + boolean wCheck = Math.abs(expected.preciseWidth() - actual.preciseWidth()) <= delta; + boolean hCheck = Math.abs(expected.preciseHeight() - actual.preciseHeight()) <= delta; + if (!xCheck || !yCheck || !wCheck || !hCheck) { + failNotEquals(message, expected, actual); + } + } + + @Test + public void testEdgeLabelLocationWithZoom() throws Exception { + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_DESCRIPTION_NAME, representationName, DDiagram.class); + DEdgeNameEditPart labelEditPart = (DEdgeNameEditPart) editor.getEditPart("newEReference1", DEdgeNameEditPart.class).part(); + + editor.zoom(zoom); + Rectangle labelBounds = labelEditPart.getFigure().getBounds(); + + assertBoundsEquals("The label has invalid bounds", new Rectangle(1372, 1055, 135, 23), labelBounds, 2.); + } + + @After + @Override + public void tearDown() throws Exception { + sessionAirdResource = null; + localSession = null; + editor = null; + diagram = null; + super.tearDown(); + } +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java index a6e5233c24..4518ccd1fb 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java @@ -502,6 +502,7 @@ public static void addPart2(TestSuite suite) { suite.addTestSuite(RemoveBendpointsRectilinearNoteAttachmentTest.class); suite.addTestSuite(RectilinearNoteAttachmentWithOneBendpointTest.class); suite.addTestSuite(LinkedBorderNodeLocationTest.class); + suite.addTest(new JUnit4TestAdapter(EdgeLabelLocationZoomTest.class)); } /**