From cc9c7f4a740c5f4097ab02aec9afb43ebfa28e83 Mon Sep 17 00:00:00 2001 From: hansonr Date: Mon, 26 Aug 2019 22:05:31 -0500 Subject: [PATCH] JAL-3423 testNG fixes for Windows - \r\n, slightly differerent font metrics --- test/jalview/analysis/TestAlignSeq.java | 21 +++++++++++++++++---- test/jalview/gui/SeqCanvasTest.java | 27 +++++++++++++++++---------- test/jalview/math/RotatableMatrixTest.java | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/test/jalview/analysis/TestAlignSeq.java b/test/jalview/analysis/TestAlignSeq.java index e2e5594..955cca7 100644 --- a/test/jalview/analysis/TestAlignSeq.java +++ b/test/jalview/analysis/TestAlignSeq.java @@ -108,13 +108,19 @@ public class TestAlignSeq public void testPrintAlignment() { AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, s3, AlignSeq.PEP); + + // s1 = new Sequence("Seq1", "ASDFAQQQRRRSSS"); + // s1.setStart(3); + // s1.setEnd(18); + // s3 = new Sequence("Seq3", "SDFAQQQSSS"); + // final StringBuilder baos = new StringBuilder(); PrintStream ps = new PrintStream(System.out) { @Override public void print(String x) { - baos.append(x); + baos.append(x.replaceAll("\r", "")); } @Override @@ -125,10 +131,17 @@ public class TestAlignSeq }; as.printAlignment(ps); - String expected = "Score = 320.0\nLength of alignment = 10\nSequence Seq1/4-13 (Sequence length = 14)\nSequence Seq3/1-10 (Sequence length = 10)\n\n" + String expected = "Score = 320.0\n" + "Length of alignment = 10\n" + + "Sequence Seq1/4-13 (Sequence length = 14)\n" + + "Sequence Seq3/1-10 (Sequence length = 10)\n" + "\n" + "Seq1/4-13 SDFAQQQRRR\n" + " ||||||| \n" - + "Seq3/1-10 SDFAQQQSSS\n\n" + "Percentage ID = 70.00\n\n"; - assertEquals(expected, baos.toString()); + + "Seq3/1-10 SDFAQQQSSS\n" + "\n" + "Percentage ID = 70.00\n" + + "\n"; + + String s = baos.toString(); + System.out.println(s); + + assertEquals(expected, s); } } diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index 7d0e256..b2a1209 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -26,6 +26,7 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.util.Platform; import java.awt.Font; import java.awt.FontMetrics; @@ -64,8 +65,8 @@ public class SeqCanvasTest av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - assertEquals(charHeight, 17); - assertEquals(charWidth, 12); + assertEquals(charHeight, Platform.isMac() ? 17 : 19); + assertEquals(charWidth, Platform.isMac() ? 12 : 11); /* * first with scales above, left, right @@ -76,7 +77,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 + assertEquals(labelWidth, + Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth); /* * width 400 pixels leaves (400 - 2*labelWidth) for residue columns @@ -198,7 +200,7 @@ public class SeqCanvasTest canvasWidth += 2; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, 24); // 2px not enough + assertEquals(wrappedWidth, Platform.isMac() ? 24 : 25); // 2px not enough canvasWidth += 1; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); @@ -232,9 +234,10 @@ public class SeqCanvasTest av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - assertEquals(charHeight, 17); - assertEquals(charWidth, 12); - + + assertEquals(charHeight, Platform.isMac() ? 17 : 19); + assertEquals(charWidth, Platform.isMac() ? 12 : 11); + SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; /* @@ -244,9 +247,12 @@ public class SeqCanvasTest av.setScaleAboveWrapped(true); av.setScaleLeftWrapped(true); av.setScaleRightWrapped(true); + FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; - assertEquals(labelWidth, 39); // 3 x 9 + charWidth + assertEquals(labelWidth, + Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth); + int annotationHeight = testee.getAnnotationHeight(); /* @@ -334,8 +340,9 @@ public class SeqCanvasTest av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - assertEquals(charHeight, 17); - assertEquals(charWidth, 12); + // Windows h=19, w=11. + assertEquals(charHeight, Platform.isMac() ? 17 : 19); + assertEquals(charWidth, Platform.isMac() ? 12 : 11); int canvasWidth = 400; int canvasHeight = 300; diff --git a/test/jalview/math/RotatableMatrixTest.java b/test/jalview/math/RotatableMatrixTest.java index 31b47aa..e04df85 100644 --- a/test/jalview/math/RotatableMatrixTest.java +++ b/test/jalview/math/RotatableMatrixTest.java @@ -41,7 +41,7 @@ public class RotatableMatrixTest PrintStream ps = new PrintStream(os, true); rm.print(ps); String result = new String(os.toByteArray()); - assertEquals(result, expected); + assertEquals(result.replaceAll("\r", ""), expected); } @Test(groups = "Functional") -- 1.7.10.2