Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File AlignmentPanelTest.java

 

Code metrics

2
92
7
1
286
154
9
0.1
13.14
7
1.29

Classes

Class Line # Actions
AlignmentPanelTest 45 92 9
0.881188188.1%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertNotEquals;
25   
26    import java.awt.Dimension;
27    import java.awt.Font;
28    import java.awt.FontMetrics;
29    import java.lang.reflect.InvocationTargetException;
30   
31    import javax.swing.SwingUtilities;
32   
33    import org.testng.annotations.BeforeMethod;
34    import org.testng.annotations.Test;
35   
36    import jalview.api.AlignViewportI;
37    import jalview.bin.Cache;
38    import jalview.bin.Jalview;
39    import jalview.datamodel.AlignmentAnnotation;
40    import jalview.datamodel.SequenceI;
41    import jalview.io.DataSourceType;
42    import jalview.io.FileLoader;
43    import jalview.viewmodel.ViewportRanges;
44   
 
45    public class AlignmentPanelTest
46    {
47    AlignFrame af;
48   
 
49  4 toggle @BeforeMethod(alwaysRun = true)
50    public void setUp() throws InvocationTargetException, InterruptedException
51    {
52  4 Jalview.main(new String[] { "-nonews", "-props",
53    "test/jalview/testProps.jvprops" });
54   
55  4 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
56    Boolean.TRUE.toString());
57  4 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
58    DataSourceType.FILE);
59   
60    /*
61    * ensure the panel has been repainted and so ViewportRanges set
62    */
63  4 SwingUtilities.invokeAndWait(new Runnable() {
 
64  4 toggle @Override
65    public void run() {
66  4 af.repaint();
67    }});
68   
69    /*
70    * wait for Consensus thread to complete
71    */
72  4 do
73    {
74  4 try
75    {
76  4 Thread.sleep(50);
77    } catch (InterruptedException x)
78    {
79    }
80  4 } while (af.getViewport().getCalcManager().isWorking());
81    }
82   
83    /**
84    * Test side effect that end residue is set correctly by setScrollValues, with
85    * or without hidden columns
86    */
 
87  1 toggle @Test(groups = "Functional")
88    public void testSetScrollValues()
89    {
90  1 ViewportRanges ranges = af.getViewport().getRanges();
91  1 af.alignPanel.setScrollValues(0, 0);
92   
93  1 int oldres = ranges.getEndRes();
94  1 af.alignPanel.setScrollValues(-1, 5);
95   
96    // setting -ve x value does not change residue
97  1 assertEquals(ranges.getEndRes(), oldres);
98   
99  1 af.alignPanel.setScrollValues(0, 5);
100   
101    // setting 0 as x value does not change residue
102  1 assertEquals(ranges.getEndRes(), oldres);
103   
104  1 af.alignPanel.setScrollValues(5, 5);
105    // setting x value to 5 extends endRes by 5 residues
106  1 assertEquals(ranges.getEndRes(), oldres + 5);
107   
108    // scroll to position after hidden columns sets endres to oldres (width) +
109    // position
110  1 int scrollpos = 60;
111  1 af.getViewport().hideColumns(30, 50);
112  1 af.alignPanel.setScrollValues(scrollpos, 5);
113  1 assertEquals(ranges.getEndRes(), oldres + scrollpos);
114   
115    // scroll to position within hidden columns, still sets endres to oldres +
116    // position
117    // not sure if this is actually correct behaviour but this is what Jalview
118    // currently does
119  1 scrollpos = 40;
120  1 af.getViewport().showAllHiddenColumns();
121  1 af.getViewport().hideColumns(30, 50);
122  1 af.alignPanel.setScrollValues(scrollpos, 5);
123  1 assertEquals(ranges.getEndRes(), oldres + scrollpos);
124   
125    // scroll to position within <width> distance of the end of the alignment
126    // endRes should be set to width of alignment - 1
127  1 scrollpos = 130;
128  1 af.getViewport().showAllHiddenColumns();
129  1 af.alignPanel.setScrollValues(scrollpos, 5);
130  1 assertEquals(ranges.getEndRes(), af.getViewport()
131    .getAlignment().getWidth() - 1);
132   
133    // now hide some columns, and scroll to position within <width>
134    // distance of the end of the alignment
135    // endRes should be set to width of alignment - 1 - the number of hidden
136    // columns
137  1 af.getViewport().hideColumns(30, 50);
138  1 af.alignPanel.setScrollValues(scrollpos, 5);
139  1 assertEquals(ranges.getEndRes(), af.getViewport()
140    .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
141    // columns
142    }
143   
144    /**
145    * Test that update layout reverts to original (unwrapped) values for endRes
146    * when switching from wrapped back to unwrapped mode (JAL-2739)
147    */
 
148  1 toggle @Test(groups = "Functional")
149    public void testUpdateLayout_endRes()
150    {
151    // get details of original alignment dimensions
152  1 ViewportRanges ranges = af.getViewport().getRanges();
153  1 int endres = ranges.getEndRes();
154   
155    // wrap
156  1 af.alignPanel.getAlignViewport().setWrapAlignment(true);
157  1 af.alignPanel.updateLayout();
158   
159    // endRes has changed
160  1 assertNotEquals(ranges.getEndRes(), endres);
161   
162    // unwrap
163  1 af.alignPanel.getAlignViewport().setWrapAlignment(false);
164  1 af.alignPanel.updateLayout();
165   
166    // endRes back to original value
167  1 assertEquals(ranges.getEndRes(), endres);
168    }
169   
170    /**
171    * Test the variant of calculateIdWidth that only recomputes the width if it is
172    * not already saved in the viewport (initial value is -1)
173    */
 
174  1 toggle @Test(groups = "Functional")
175    public void testCalculateIdWidth_noArgs()
176    {
177  1 AlignViewportI av = af.alignPanel.getAlignViewport();
178  1 av.setShowJVSuffix(true);
179  1 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
180   
181  1 av.setIdWidth(0);
182  1 Dimension d = af.alignPanel.calculateIdWidth();
183  1 assertEquals(d.width, 0);
184  1 assertEquals(d.height, 0);
185   
186  1 av.setIdWidth(99);
187  1 d = af.alignPanel.calculateIdWidth();
188  1 assertEquals(d.width, 99);
189  1 assertEquals(d.height, 0);
190   
191    /*
192    * note 4 pixels padding are added to the longest sequence name width
193    */
194  1 av.setIdWidth(-1); // force recalculation
195  1 d = af.alignPanel.calculateIdWidth();
196  1 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
197  1 assertEquals(d.height, 12);
198  1 assertEquals(d.width, av.getIdWidth());
199    }
200   
201    /**
202    * Test the variant of calculateIdWidth that computes the longest of any
203    * sequence name or annotation label width
204    */
 
205  1 toggle @Test(groups = "Functional")
206    public void testCalculateIdWidth_withMaxWidth()
207    {
208  1 AlignViewportI av = af.alignPanel.getAlignViewport();
209  1 av.setShowJVSuffix(true);
210  1 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
211  1 av.setShowAnnotation(false);
212  1 av.setIdWidth(18);
213   
214    /*
215    * note 4 pixels 'padding' are added to the longest seq name/annotation label
216    */
217  1 Dimension d = af.alignPanel.calculateIdWidth(2000);
218  1 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
219  1 assertEquals(d.height, 12); // fixed value (not used?)
220  1 assertEquals(av.getIdWidth(), 18); // not changed by this method
221   
222    /*
223    * make the longest sequence name longer
224    */
225  1 SequenceI seq = af.viewport.getAlignment()
226    .findSequenceMatch("Q93Z60_ARATH")[0];
227  1 seq.setName(seq.getName() + "MMMMM");
228  1 d = af.alignPanel.calculateIdWidth(2000);
229  1 assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
230  1 assertEquals(d.height, 12);
231  1 assertEquals(av.getIdWidth(), 18); // unchanged
232   
233    /*
234    * make the longest annotation name even longer
235    * note this is checked even if annotations are not shown
236    */
237  1 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
238  1 aa.label = "THIS IS A VERY LONG LABEL INDEED";
239  1 FontMetrics fmfor = af.alignPanel
240    .getFontMetrics(af.alignPanel.getAlabels().getFont());
241    // Assumption ID_WIDTH_PADDING == 4
242  1 int expwidth = 4 + fmfor.stringWidth(aa.label);
243  1 d = af.alignPanel.calculateIdWidth(2000);
244  1 assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED"
245  1 assertEquals(d.height, 12);
246   
247    /*
248    * override with maxwidth
249    * note the 4 pixels padding is added to this value
250    */
251  1 d = af.alignPanel.calculateIdWidth(213);
252  1 assertEquals(d.width, 217);
253  1 assertEquals(d.height, 12);
254    }
255   
 
256  0 toggle @Test(groups = { "Functional", "Not-bamboo" })
257    public void testGetVisibleWidth()
258    {
259    /*
260    * width for onscreen rendering is IDPanel width
261    */
262  0 int w = af.alignPanel.getVisibleIdWidth(true);
263  0 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
264  0 assertEquals(w, 115);
265   
266    /*
267    * width for offscreen rendering is the same
268    * if no fixed id width is specified in preferences
269    */
270  0 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
271  0 Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
272  0 assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
273   
274    /*
275    * preference for fixed id width - note 4 pixels padding is added
276    */
277  0 Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
278  0 assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
279   
280    /*
281    * preference for auto id width overrides fixed width
282    */
283  0 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
284  0 assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
285    }
286    }