Skip to content

Commit

Permalink
Fixed and improved tests with moving connections #604
Browse files Browse the repository at this point in the history
The SWTBot test methods
- checkIfConnectionRemainsAfterMovingBothFBsTogether()
- checkIfConnectionRemainsAfterMoving1FB()
were improved with new helping methods in class SWTBotFB

#604
  • Loading branch information
Andrearium authored and azoitl committed Nov 4, 2024
1 parent 5e09f5d commit abb683f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.application.editparts.FBEditPart;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -274,4 +276,36 @@ private static List<org.eclipse.draw2d.geometry.Point> getPositionOfSelectedElem
}).toList();
}

public void checkIfMovingFBWasCorrect(final SWTBot4diacGefEditor editor, final String fbName,
final Point originalPos, final Point translation) {
final Rectangle fbBounds = getBoundsOfFBWithTolerance(editor, fbName);
final int absPos2Fb2X = originalPos.x + translation.x;
final int absPos2Fb2Y = originalPos.y + translation.y;
assertTrue(fbBounds.contains(absPos2Fb2X, absPos2Fb2Y));
}

@SuppressWarnings("static-method")
public void checkIfMovingConnectionWasCorrect(final SWTBot4diacGefEditor editor,
final org.eclipse.draw2d.geometry.Point origStartPointConnection,
final org.eclipse.draw2d.geometry.Point origEndPointConnection, final ConnectionEditPart connection,
final Point translation) {

final PolylineConnection polyLineConnection = (PolylineConnection) connection.getFigure();

assertNotNull(connection);
final org.eclipse.draw2d.geometry.Point newStartPointConnection = polyLineConnection.getPoints()
.getFirstPoint();
final org.eclipse.draw2d.geometry.Point newEndPointConnection = polyLineConnection.getPoints().getLastPoint();

assertTrue(Math.abs(origStartPointConnection.x) - Math.abs(newStartPointConnection.x)
- Math.abs(translation.x) <= TOLERANCE_SNAP_TO_GRID);
assertTrue(Math.abs(origStartPointConnection.y) - Math.abs(newStartPointConnection.y)
- Math.abs(translation.y) <= TOLERANCE_SNAP_TO_GRID);
assertTrue(Math.abs(origEndPointConnection.x) - Math.abs(newEndPointConnection.x)
- Math.abs(translation.x) <= TOLERANCE_SNAP_TO_GRID);
assertTrue(Math.abs(origEndPointConnection.y) - Math.abs(newEndPointConnection.y)
- Math.abs(translation.y) <= TOLERANCE_SNAP_TO_GRID);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,13 @@ public void moveBothFBTogether() {
assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_FB));
assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB));

// move Fbs to new position by selecting them with a rectangle
// move FBs to new position by selecting them with a rectangle
final Point translation = new Point(130, -40);
fbBot.moveViaRectangle(editor, new Rectangle(50, 50, 400, 300), translation);

// check if translation was correct
final Rectangle fb1Bounds2 = fbBot.getBoundsOfFBWithTolerance(editor, UITestNamesHelper.E_CYCLE_FB);
final int absPos2Fb1X = absPos1Fb1.x + translation.x;
final int absPos2Fb1Y = absPos1Fb1.y + translation.y;
assertTrue(fb1Bounds2.contains(absPos2Fb1X, absPos2Fb1Y));

final Rectangle fb2Bounds2 = fbBot.getBoundsOfFBWithTolerance(editor, UITestNamesHelper.E_SR_FB);
final int absPos2Fb2X = absPos1Fb2.x + translation.x;
final int absPos2Fb2Y = absPos1Fb2.y + translation.y;
assertTrue(fb2Bounds2.contains(absPos2Fb2X, absPos2Fb2Y));
fbBot.checkIfMovingFBWasCorrect(editor, UITestNamesHelper.E_CYCLE_FB, absPos1Fb1, translation);
fbBot.checkIfMovingFBWasCorrect(editor, UITestNamesHelper.E_SR_FB, absPos1Fb2, translation);
}

/**
Expand Down Expand Up @@ -285,26 +278,18 @@ public void checkIfConnectionRemainsAfterMoving1FB() {

// get connection start and end point
final PolylineConnection polyLineConnection = (PolylineConnection) connection.getFigure();
final org.eclipse.draw2d.geometry.Point startPointConnection = polyLineConnection.getPoints().getFirstPoint();
final org.eclipse.draw2d.geometry.Point endPointConnection = polyLineConnection.getPoints().getLastPoint();
final org.eclipse.draw2d.geometry.Point origStartPointConnection = polyLineConnection.getPoints()
.getFirstPoint();
final org.eclipse.draw2d.geometry.Point origEndPointConnection = polyLineConnection.getPoints().getLastPoint();

// calculate deltas of translation
final Point pos2 = new Point(305, 245);
final int deltaX = pos2.x - pos1.x;
final int deltaY = pos2.y - pos1.y;
final Point translation = new Point(pos2.x - pos1.x, pos2.y - pos1.y);

// move E_CYCLE
editor.drag(fb1, pos2.x, pos2.y);
final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB);
assertTrue(fb1Bounds2.contains(pos2.x, pos2.y));
assertNotNull(connection);
final org.eclipse.draw2d.geometry.Point newStartPointConnection = polyLineConnection.getPoints()
.getFirstPoint();
final org.eclipse.draw2d.geometry.Point newEndPointConnection = polyLineConnection.getPoints().getLastPoint();

assertEquals(startPointConnection.x + (long) deltaX, newStartPointConnection.x);
assertEquals(startPointConnection.y + (long) deltaY, newStartPointConnection.y);
assertEquals(endPointConnection, newEndPointConnection);
fbBot.checkIfMovingConnectionWasCorrect(editor, origStartPointConnection, origEndPointConnection, connection,
translation);
}

/**
Expand Down Expand Up @@ -417,8 +402,9 @@ public void checkIfConnectionRemainsAfterMovingBothFBsTogether() {

// get connection start and end point
final PolylineConnection polyLineConnection = (PolylineConnection) connection.getFigure();
final org.eclipse.draw2d.geometry.Point startPointConnection = polyLineConnection.getPoints().getFirstPoint();
final org.eclipse.draw2d.geometry.Point endPointConnection = polyLineConnection.getPoints().getLastPoint();
final org.eclipse.draw2d.geometry.Point origStartPointConnection = polyLineConnection.getPoints()
.getFirstPoint();
final org.eclipse.draw2d.geometry.Point origEndPointConnection = polyLineConnection.getPoints().getLastPoint();

// drag rectangle over FBs, therefore FBs should be selected
editor.drag(30, 30, 400, 400);
Expand All @@ -440,20 +426,12 @@ public void checkIfConnectionRemainsAfterMovingBothFBsTogether() {
assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB));

// calculation of translation
final int translationX = pointTo.x - pointFrom.x;
final int translationY = pointTo.y - pointFrom.y;
final Point translation = new Point(pointTo.x - pointFrom.x, pointTo.y - pointFrom.y);

// check if connection has been moved
connection = connectBot.findConnection(UITestPinHelper.EO1, UITestPinHelper.R);
assertNotNull(connection);
final org.eclipse.draw2d.geometry.Point newStartPointConnection = polyLineConnection.getPoints()
.getFirstPoint();
final org.eclipse.draw2d.geometry.Point newEndPointConnection = polyLineConnection.getPoints().getLastPoint();

assertEquals(startPointConnection.x + (long) translationX, newStartPointConnection.x);
assertEquals(startPointConnection.y + (long) translationY, newStartPointConnection.y);
assertEquals(endPointConnection.x + (long) translationX, newEndPointConnection.x);
assertEquals(endPointConnection.y + (long) translationY, newEndPointConnection.y);
fbBot.checkIfMovingConnectionWasCorrect(editor, origStartPointConnection, origEndPointConnection, connection,
translation);

}
}

0 comments on commit abb683f

Please sign in to comment.