From: Ben Soares Date: Fri, 26 Apr 2024 17:23:04 +0000 (+0100) Subject: JAL-4397 Test all fixed on linux. Given leeway to some tests, platform dependent... X-Git-Tag: Release_2_11_4_0~28^2~35^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5db005745240445acdd3b140372aa74adbc3bc46;p=jalview.git JAL-4397 Test all fixed on linux. Given leeway to some tests, platform dependent expected values on some tests, HiDPI dependent expected values on some tests. Still to test on macOS. --- diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index c9e4d8c..eefe950 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -274,12 +274,15 @@ public class AlignmentPanelTest @Test(groups = { "Functional", "Not-bamboo" }) public void testGetVisibleWidth() { + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); /* * width for onscreen rendering is IDPanel width */ int w = af.alignPanel.getVisibleIdWidth(true); assertEquals(w, af.alignPanel.getIdPanel().getWidth()); - assertEquals(w, 115); + + // different scaling (1.0, 2.0) gives different results + assertEquals(w, scaling == 1.0 ? 112 : 107); /* * width for offscreen rendering is the same @@ -299,12 +302,17 @@ public class AlignmentPanelTest * preference for auto id width overrides fixed width */ Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString()); - assertEquals(115, af.alignPanel.getVisibleIdWidth(false)); + w = af.alignPanel.getVisibleIdWidth(false); + // allow some leeway for different OS renderings + assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + assertEquals(w, scaling == 1.0 ? 112 : 107); } @Test(groups = { "Functional", "Not-bamboo" }) public void testresetIdWidth() { + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); /* * width for onscreen rendering is IDPanel width */ @@ -313,6 +321,8 @@ public class AlignmentPanelTest assertEquals(w, actual); // allow some leeway for different OS renderings assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + assertEquals(w, scaling == 1.0 ? 112 : 107); // manually adjust af.viewport.setIdWidth(200); @@ -341,6 +351,8 @@ public class AlignmentPanelTest // to optimal id width // allow some leeway for different OS renderings assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + assertEquals(w, scaling == 1.0 ? 112 : 107); } @Test(groups = "Functional") diff --git a/test/jalview/gui/AnnotationLabelsTest2.java b/test/jalview/gui/AnnotationLabelsTest2.java index ad97e8b..54c6f34 100644 --- a/test/jalview/gui/AnnotationLabelsTest2.java +++ b/test/jalview/gui/AnnotationLabelsTest2.java @@ -43,6 +43,8 @@ import jalview.structure.StructureImportSettings.TFType; public class AnnotationLabelsTest2 { + private static double scaling; + @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { @@ -55,6 +57,8 @@ public class AnnotationLabelsTest2 */ Cache.loadProperties("test/jalview/io/testProps.jvprops"); Jalview.main(new String[] { "--nonews", "--nosplash", }); + + scaling = JvSwingUtilsTest.getScaling(Desktop.instance); } @AfterMethod(alwaysRun = true) @@ -95,6 +99,7 @@ public class AnnotationLabelsTest2 { AlignFrame af = new FileLoader() .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE); + try { Thread.sleep(200); // to allow alignment annotations to open @@ -147,9 +152,9 @@ public class AnnotationLabelsTest2 // idWidth = ap.getIdPanel().getWidth(); idWidth = av.getIdWidth(); - assertTrue(idWidth > idWidth2min, + assertTrue(idWidth >= idWidth2min, "idWidth (" + idWidth + ") is not greater than " + idWidth2min); - assertTrue(idWidth < idWidth2max, + assertTrue(idWidth <= idWidth2max, "idWidth (" + idWidth + ") is not narrower than" + idWidth2max); } @@ -176,7 +181,6 @@ public class AnnotationLabelsTest2 AlignViewport av = af.getCurrentView(); int idWidth = 0; - idWidth = av.getIdWidth(); assertTrue(idWidth > idWidth1min, "idWidth (" + idWidth + ") is not greater than " + idWidth1min); @@ -231,6 +235,9 @@ public class AnnotationLabelsTest2 int idWidth2min, int idWidth2max, */ + int idWidth2min = scaling == 1.0 ? 114 : 108; + int idWidth2max = scaling == 1.0 ? 114 : 114; // was 130 + return new Object[][] { // /* @@ -239,12 +246,12 @@ public class AnnotationLabelsTest2 100, "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb", "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json", - true, TFType.PLDDT, null, 115, 130 }, + true, TFType.PLDDT, null, idWidth2min, idWidth2max }, { "./test/files/annotation_label_width/sample.a2m", true, 50, 70, 100, "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb", "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json", - true, TFType.PLDDT, null, 115, 130 }, + true, TFType.PLDDT, null, idWidth2min, idWidth2max }, /* */ }; diff --git a/test/jalview/gui/JvSwingUtilsTest.java b/test/jalview/gui/JvSwingUtilsTest.java index e6f4041..8a9a428 100644 --- a/test/jalview/gui/JvSwingUtilsTest.java +++ b/test/jalview/gui/JvSwingUtilsTest.java @@ -23,6 +23,10 @@ package jalview.gui; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; +import java.awt.Component; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + import javax.swing.JScrollBar; import org.testng.annotations.BeforeClass; @@ -119,4 +123,17 @@ public class JvSwingUtilsTest JvSwingUtils.wrapTooltip(true, tip)); assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip)); } + + public static double getScaling(Component c) + { + Graphics2D g = (Graphics2D) c.getGraphics(); + if (g == null) + { + return 0.0; + } + AffineTransform t = g.getTransform(); + double scaling = t.getScaleX(); // Assuming square pixels :P + return scaling; + } + } diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index aa50301..46c2201 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -20,25 +20,24 @@ */ package jalview.gui; -import java.awt.Font; -import java.awt.FontMetrics; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import java.awt.Font; +import java.awt.FontMetrics; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.io.DataSourceType; -import jalview.io.DataSourceType; import jalview.io.FileLoader; - import junit.extensions.PA; public class SeqCanvasTest @@ -76,7 +75,8 @@ public class SeqCanvasTest av.setScaleRightWrapped(true); FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; - assertEquals(labelWidth, 39); // 3 x 9 + charWidth + // some leeway for different OS rendering of text + assertTrue(labelWidth >= 36 && labelWidth <= 39); /* * width 400 pixels leaves (400 - 2*labelWidth) for residue columns @@ -152,7 +152,9 @@ public class SeqCanvasTest av.setScaleLeftWrapped(false); wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 23); + // some leeway for different OS rendering of text + assertTrue(wrappedWidth >= 22 && wrappedWidth <= 23); + int difference = wrappedWidth - 23; /* * add 10 pixels to width to fit in another whole residue column @@ -164,7 +166,7 @@ public class SeqCanvasTest canvasWidth += 1; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 24); + assertEquals(wrappedWidth, 24 + difference); /* * turn off East scale to gain 39 more pixels (3 columns remainder 3) @@ -172,7 +174,7 @@ public class SeqCanvasTest av.setScaleRightWrapped(false); wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 27); + assertEquals(wrappedWidth, 27 + difference); /* * add 9 pixels to width to gain a residue column @@ -184,7 +186,7 @@ public class SeqCanvasTest canvasWidth += 1; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 28); // 9px is enough + assertEquals(wrappedWidth, 28 + difference); // 9px is enough /* * now West but not East scale - lose 39 pixels or 4 columns @@ -204,7 +206,7 @@ public class SeqCanvasTest canvasWidth += 1; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 25); // 3px is enough + assertEquals(wrappedWidth, 25 + difference); // 3px is enough /* * turn off scales left and right, make width exactly 157 columns @@ -246,7 +248,8 @@ public class SeqCanvasTest av.setScaleRightWrapped(true); FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; - assertEquals(labelWidth, 39); // 3 x 9 + charWidth + // some leeway for different OS rendering of text + assertTrue(labelWidth >= 36 && labelWidth <= 39); int annotationHeight = testee.getAnnotationHeight(); /* diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index 649c78a..4f07314 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -950,9 +950,12 @@ public class SeqPanelTest assertEquals(charHeight, 17); assertEquals(charWidth, 12); + double scaling = JvSwingUtilsTest.getScaling(alignFrame.alignPanel); + FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("00000") + charWidth; - assertEquals(labelWidth, 57); // 5 x 9 + charWidth + // some leeway for different OS rendering of text + assertTrue(labelWidth >= 52 && labelWidth <= 57); assertEquals(testee.seqCanvas.getLabelWidthWest(), labelWidth); int x = 0; diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index dcf8feb..98fa627 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -32,7 +32,6 @@ import java.awt.Color; import java.awt.Rectangle; import java.io.File; import java.io.IOException; -import java.math.BigInteger; import java.util.ArrayList; import java.util.BitSet; import java.util.HashMap; @@ -252,8 +251,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase boolean diffseqcols = false, diffgseqcols = false; SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray(); - for (int p = 0, pSize = af.getViewport().getAlignment() - .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++) + for (int p = 0, + pSize = af.getViewport().getAlignment().getWidth(); p < pSize + && (!diffseqcols || !diffgseqcols); p++) { if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f)) @@ -272,8 +272,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertTrue(__rcs.isSeqAssociated(), "Group Annotation colourscheme wasn't sequence associated"); - for (int p = 0, pSize = af.getViewport().getAlignment() - .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++) + for (int p = 0, + pSize = af.getViewport().getAlignment().getWidth(); p < pSize + && (!diffseqcols || !diffgseqcols); p++) { if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null, @@ -1477,7 +1478,11 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertEquals(ov1.getCanvas().getResidueColour(), Color.white); assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow); assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original"); - assertEquals(ov1.getFrameBounds(), new Rectangle(20, 30, 200, 400)); + + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(ov1); + int width = scaling == 1.0 ? 225 : 200; + Rectangle ov1Rectangle = ov1.getFrameBounds(); + assertEquals(ov1Rectangle, new Rectangle(20, 30, width, 400)); assertTrue(ov1.isShowHiddenRegions()); } @@ -1760,8 +1765,13 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertNotNull(af, "Didn't read in the example file correctly."); // FIXME JAL-4281 test made platform dependent to pass, but probably // shouldn't be platform dependent - assertEquals(af.alignPanel.getAlignViewport().getIdWidth(), - Platform.isAMacAndNotJS() ? 144 : 138, + int idWidth = af.alignPanel.getAlignViewport().getIdWidth(); + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); + int expectedWidth = Platform.isMac() ? 144 + : Platform.isLinux() ? scaling == 1.0 ? 131 : 128 : 138; + System.err.println("##### scaling=" + scaling + ", idWidth=" + idWidth + + ", expectedWidth=" + expectedWidth); + assertEquals(idWidth, expectedWidth, "Legacy project import should have fixed ID width"); assertTrue( af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());