Skip to content

Commit

Permalink
[359] Add corresponding tests
Browse files Browse the repository at this point in the history
This commit changes the CheckBoundsCondition to also be able to consider
the HandleBounds figure and the scrollbars.

A rounding problem has been detected in GraphicalHelper and fixed during
these tests.

Bug: #359
  • Loading branch information
lredor committed Apr 25, 2024
1 parent e4e79bd commit f108941
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2011, 2024 THALES GLOBAL SERVICES and others.
* 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
Expand Down Expand Up @@ -184,7 +184,7 @@ public static Point getScrollSize(GraphicalEditPart part) {
* an edit part on the view
* @return the scroll size
*/
protected static Point getContainerScrollSize(GraphicalEditPart part) {
protected static PrecisionPoint getContainerScrollSize(GraphicalEditPart part) {
Objects.requireNonNull(part);
Point result = new Point(0, 0);
Point diagramScrollSize = new Point(0, 0);
Expand All @@ -200,7 +200,7 @@ protected static Point getContainerScrollSize(GraphicalEditPart part) {
current = current.getParent();
}
result.translate(diagramScrollSize.negate());
return result;
return new PrecisionPoint(result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2011, 2017 THALES GLOBAL SERVICES and others.
* Copyright (c) 2011, 2024 THALES GLOBAL SERVICES and others.
* 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
Expand All @@ -12,8 +12,10 @@
*/
package org.eclipse.sirius.tests.swtbot.support.api.condition;

import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.junit.ComparisonFailure;

Expand Down Expand Up @@ -44,6 +46,12 @@ public class CheckBoundsCondition extends DefaultCondition {
*/
private final Rectangle expectedBounds;

/**
* True to compute bounds with
* {@link GraphicalHelper#getAbsoluteBoundsIn100Percent(org.eclipse.gef.GraphicalEditPart)}
*/
private boolean useGraphicalHelperAbsoluteBoundsIn100Percent;

/**
* Constructor.
*
Expand Down Expand Up @@ -76,14 +84,40 @@ public CheckBoundsCondition(IGraphicalEditPart editPartToWaitForSelection, Recta
this.checkHeight = checkHeight;
}

/**
* Constructor.
*
* @param editPartToWaitForSelection
* the edit part to wait for its bounds.
* @param expectedAbsoluteBounds
* expected bounds in absolute coordinate
* @param checkWidth
* True if the width of the bounds must be checked.
* @param checkHeight
* True if the height of the bounds must be checked.
* @param useGraphicalHelperAbsoluteBoundsIn100Percent
* true to use GraphicalHelper to compute bounds
*/
public CheckBoundsCondition(IGraphicalEditPart editPartToWaitForSelection, Rectangle expectedAbsoluteBounds, boolean checkWidth, boolean checkHeight,
boolean useGraphicalHelperAbsoluteBoundsIn100Percent) {
this.editPartToWaitFor = editPartToWaitForSelection;
this.expectedBounds = expectedAbsoluteBounds;
this.checkWidth = checkWidth;
this.checkHeight = checkHeight;
this.useGraphicalHelperAbsoluteBoundsIn100Percent = useGraphicalHelperAbsoluteBoundsIn100Percent;
}

@Override
public boolean test() throws Exception {
boolean result = false;
if (editPartToWaitFor != null) {
// Only compare round "int" values and not precise double values here
PrecisionRectangle preciseCurrentBounds = (PrecisionRectangle) getCurrentAbsoluteBounds();
Rectangle currentBounds = new Rectangle(Math.toIntExact(Math.round(preciseCurrentBounds.preciseX())), Math.toIntExact(Math.round(preciseCurrentBounds.preciseY())),
Math.toIntExact(Math.round(preciseCurrentBounds.preciseWidth())), Math.toIntExact(Math.round(preciseCurrentBounds.preciseHeight())));
if (checkHeight && checkWidth) {
result = getCurrentAbsoluteBounds().equals(expectedBounds);
result = currentBounds.equals(expectedBounds);
} else {
Rectangle currentBounds = getCurrentAbsoluteBounds();
if (checkWidth) {
result = currentBounds.width == expectedBounds.width;
} else if (checkHeight) {
Expand All @@ -109,6 +143,7 @@ public String getFailureMessage() {
} else {
result = new ComparisonFailure("The expected location is not reached.", expectedBounds.getLocation().toString(), getCurrentAbsoluteBounds().getLocation().toString()).getMessage();
}

return result;
}

Expand All @@ -118,8 +153,12 @@ public String getFailureMessage() {
* @return The absolute bounds.
*/
protected Rectangle getCurrentAbsoluteBounds() {
Rectangle bounds = editPartToWaitFor.getFigure().getBounds().getCopy();
editPartToWaitFor.getFigure().translateToAbsolute(bounds);
return bounds;
if (useGraphicalHelperAbsoluteBoundsIn100Percent) {
return GraphicalHelper.getAbsoluteBoundsIn100Percent(editPartToWaitFor, true);
} else {
Rectangle bounds = new PrecisionRectangle(editPartToWaitFor.getFigure().getBounds());
editPartToWaitFor.getFigure().translateToAbsolute(bounds);
return bounds;
}
}
}
Loading

0 comments on commit f108941

Please sign in to comment.