JAL-4154 Update AlignmentPanelTest to use new forArch method
[jalview.git] / test / jalview / gui / AlignmentPanelTest.java
index 203220a..69dd54e 100644 (file)
@@ -23,6 +23,16 @@ package jalview.gui;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
 
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.SwingUtilities;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import jalview.api.AlignViewportI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -30,45 +40,49 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
+import jalview.util.Platform;
 import jalview.viewmodel.ViewportRanges;
 
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
 public class AlignmentPanelTest
 {
   AlignFrame af;
 
   @BeforeMethod(alwaysRun = true)
-  public void setUp()
+  public void setUp() throws InvocationTargetException, InterruptedException
   {
-    Jalview.main(new String[] { "-nonews", "-props",
-        "test/jalview/testProps.jvprops" });
+    Jalview.main(new String[] { "-nonews", 
+        "-props", "test/jalview/testProps.jvprops",
+        "-jabaws", "none"});
 
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+    Cache.setPropertyNoSave("SHOW_IDENTITY",
             Boolean.TRUE.toString());
     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
             DataSourceType.FILE);
+    
+    /*
+     * ensure the panel has been repainted and so ViewportRanges set
+     */
+    SwingUtilities.invokeAndWait(new Runnable()
+    {
+      @Override
+      public void run()
+      {
+        af.repaint();
+      }
+    });
 
     /*
      * wait for Consensus thread to complete
      */
-    synchronized (this)
+    do
     {
-      while (af.getViewport().getConsensusSeq() == null)
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
       {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
       }
-    }
+    } while (af.getViewport().getCalcManager().isWorking());
   }
 
   /**
@@ -85,22 +99,29 @@ public class AlignmentPanelTest
     af.alignPanel.setScrollValues(-1, 5);
 
     // setting -ve x value does not change residue
+    // no update necessary now
     assertEquals(ranges.getEndRes(), oldres);
 
     af.alignPanel.setScrollValues(0, 5);
 
+    // no update necessary now
     // setting 0 as x value does not change residue
+    // no update necessary now
     assertEquals(ranges.getEndRes(), oldres);
 
     af.alignPanel.setScrollValues(5, 5);
     // setting x value to 5 extends endRes by 5 residues
+    System.out.println(ranges);
+    // no update necessary now
     assertEquals(ranges.getEndRes(), oldres + 5);
 
     // scroll to position after hidden columns sets endres to oldres (width) +
     // position
-    int scrollpos = 60;
+    int scrollpos = 53; // was 60, but this is too high to allow full scrolling
+                        // in Windows
     af.getViewport().hideColumns(30, 50);
     af.alignPanel.setScrollValues(scrollpos, 5);
+    // no update necessary now
     assertEquals(ranges.getEndRes(), oldres + scrollpos);
 
     // scroll to position within hidden columns, still sets endres to oldres +
@@ -111,6 +132,7 @@ public class AlignmentPanelTest
     af.getViewport().showAllHiddenColumns();
     af.getViewport().hideColumns(30, 50);
     af.alignPanel.setScrollValues(scrollpos, 5);
+    // no update necessary now
     assertEquals(ranges.getEndRes(), oldres + scrollpos);
 
     // scroll to position within <width> distance of the end of the alignment
@@ -118,8 +140,9 @@ public class AlignmentPanelTest
     scrollpos = 130;
     af.getViewport().showAllHiddenColumns();
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(ranges.getEndRes(), af.getViewport()
-            .getAlignment().getWidth() - 1);
+    // no update necessary now
+    assertEquals(ranges.getEndRes(),
+            af.getViewport().getAlignment().getWidth() - 1);
 
     // now hide some columns, and scroll to position within <width>
     // distance of the end of the alignment
@@ -127,9 +150,12 @@ public class AlignmentPanelTest
     // columns
     af.getViewport().hideColumns(30, 50);
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(ranges.getEndRes(), af.getViewport()
-            .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
-                                                  // columns
+    // no update necessary now
+    assertEquals(ranges.getEndRes(),
+            af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the
+                                                                  // number of
+                                                                  // hidden
+                                                                  // columns
   }
 
   /**
@@ -183,8 +209,9 @@ public class AlignmentPanelTest
      * note 4 pixels padding are added to the longest sequence name width
      */
     av.setIdWidth(-1); // force recalculation
+    
     d = af.alignPanel.calculateIdWidth();
-    assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
+    assertEquals(d.width, Platform.forArch(166).forWin(172).value().intValue()); // 4 + pixel width of "Q93Z60_ARATH/1-118"
     assertEquals(d.height, 12);
     assertEquals(d.width, av.getIdWidth());
   }
@@ -206,7 +233,7 @@ public class AlignmentPanelTest
      * note 4 pixels 'padding' are added to the longest seq name/annotation label
      */
     Dimension d = af.alignPanel.calculateIdWidth(2000);
-    assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
+    assertEquals(d.width,  Platform.forArch(166).forWin(172).value().intValue()); // 4 + pixel width of "Q93Z60_ARATH/1-118"
     assertEquals(d.height, 12); // fixed value (not used?)
     assertEquals(av.getIdWidth(), 18); // not changed by this method
 
@@ -215,11 +242,14 @@ public class AlignmentPanelTest
      */
     SequenceI seq = af.viewport.getAlignment()
             .findSequenceMatch("Q93Z60_ARATH")[0];
-    seq.setName(seq.getName() + "MMMMM");
+    String orig = seq.getName();
+    seq.setName(orig + "MMMMM");
     d = af.alignPanel.calculateIdWidth(2000);
-    assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
+    assertEquals(d.width, Platform.forArch(211).forWin(219).value().intValue()); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
     assertEquals(d.height, 12);
     assertEquals(av.getIdWidth(), 18); // unchanged
+    // for next test:
+    seq.setName(orig);
 
     /*
      * make the longest annotation name even longer
@@ -230,21 +260,23 @@ public class AlignmentPanelTest
     FontMetrics fmfor = af.alignPanel
             .getFontMetrics(af.alignPanel.getAlabels().getFont());
     // Assumption ID_WIDTH_PADDING == 4
+    // AH! But with those added MMMM above, this was NOT the longest label!
     int expwidth = 4 + fmfor.stringWidth(aa.label);
     d = af.alignPanel.calculateIdWidth(2000);
-    assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED"
+    assertEquals(d.width, expwidth); // 191 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED"
     assertEquals(d.height, 12);
 
     /*
      * override with maxwidth
      * note the 4 pixels padding is added to this value
      */
-    d = af.alignPanel.calculateIdWidth(213);
-    assertEquals(d.width, 217);
+    // BH but we have to be under the max width
+    d = af.alignPanel.calculateIdWidth(180);
+    assertEquals(d.width, 184);
     assertEquals(d.height, 12);
   }
 
-  @Test(groups = "Functional")
+  @Test(groups = { "Functional", "Not-bamboo" })
   public void testGetVisibleWidth()
   {
     /*
@@ -252,7 +284,8 @@ public class AlignmentPanelTest
      */
     int w = af.alignPanel.getVisibleIdWidth(true);
     assertEquals(w, af.alignPanel.getIdPanel().getWidth());
-    assertEquals(w, 115);
+    assertEquals(w, Platform.forArch(115).forWin(112).forMac(115)
+            .forLinux(114).value().intValue());
 
     /*
      * width for offscreen rendering is the same
@@ -272,6 +305,8 @@ public class AlignmentPanelTest
      * preference for auto id width overrides fixed width
      */
     Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
-    assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
+    assertEquals(af.alignPanel.getVisibleIdWidth(false),
+            Platform.forArch(115).forWin(106).forMac(115).forLinux(114)
+                    .value().intValue());
   }
 }