Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.bin

File HiDPISettingTest1.java

 

Code metrics

10
30
4
1
140
76
10
0.33
7.5
4
2.5

Classes

Class Line # Actions
HiDPISettingTest1 52 30 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.bin;
22   
23    import static org.testng.Assert.assertEquals;
24   
25    import org.mockito.Mockito;
26    import org.testng.annotations.AfterClass;
27    import org.testng.annotations.BeforeMethod;
28    import org.testng.annotations.Test;
29   
30    import jalview.gui.AlignFrame;
31    import jalview.gui.Desktop;
32    import jalview.gui.JvOptionPane;
33    import jalview.io.DataSourceType;
34    import jalview.io.FileLoader;
35    import jalview.util.Platform;
36   
37    /*
38    * Testing a HiDPI display is difficult without running in a HiDPI display.
39    * The gathering of screen size and resolution performed by jalview.bin.HiDPISetting
40    * is now farmed out into a separate class jalview.bin.ScreenInfo so it can be more
41    * easily Mocked in tests.
42    * Two sets of tests are performed.
43    * 1) testLinuxScalePropertyToActualTransform() sets the property that HiDPISetting
44    * uses (via jalview.bin.Launcher or getdown) to scale up Jalview, and then looks at
45    * the alignment panel graphics2d transform to see if it's been scaled by the same
46    * amount (in this case 4 -- unlikely to happen by accident!).
47    * 2) testHiDPISettingInit() which tests the calculation that HiDPISetting uses to
48    * decide from apparent screen information (mocked using Mockito in the tests) what
49    * scaling factor to set (it doesn't actually set it, just suggests it to
50    * jalview.bin.Launcher)
51    */
 
52    public class HiDPISettingTest1
53    {
54   
55    AlignFrame af = null;
56   
 
57  0 toggle @BeforeMethod(alwaysRun = true)
58    public void setUp()
59    {
60  0 JvOptionPane.setInteractiveMode(false);
61  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62  0 Cache.loadProperties("test/jalview/bin/hidpiTestProps.jvprops");
63  0 Jalview.main(
64    new String[]
65    { "--nosplash", "--nonews", "--noquestionnaire",
66    "--nowebservicediscovery" });
67   
68  0 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
69    DataSourceType.FILE);
70   
71    /*
72    * wait for Consensus thread to complete
73    */
74  0 do
75    {
76  0 try
77    {
78  0 Thread.sleep(50);
79    } catch (InterruptedException x)
80    {
81    }
82  0 } while (af.getViewport().getCalcManager().isWorking());
83    }
84   
 
85  0 toggle @AfterClass(alwaysRun = true)
86    public void tearDown()
87    {
88  0 if (Desktop.instance != null)
89  0 Desktop.instance.closeAll_actionPerformed(null);
90    }
91   
 
92  0 toggle @Test(groups = { "Functional" })
93    public void testHiDPISettingInit()
94    {
95  0 String scalePropertyName = "sun.java2d.uiScale";
96    // ensure scale property is cleared (otherwise it will be re-used)
97  0 System.clearProperty(HiDPISetting.scalePropertyName);
98   
99    { // keep the mock under lock
100    // Ancient monitor -- no property change set
101  0 setMockScreen(1024, 768, 72);
102  0 assertEquals(HiDPISetting.getScalePropertyArg(), null);
103   
104    // Old monitor -- no property change set
105  0 setMockScreen(1200, 800, 96);
106  0 assertEquals(HiDPISetting.getScalePropertyArg(), null);
107   
108    // HD screen -- no property change set
109  0 setMockScreen(1920, 1080, 96);
110  0 assertEquals(HiDPISetting.getScalePropertyArg(), null);
111   
112    // currently HiDPISetting only operates for Linux
113   
114    // 4K screen -- scale by 2
115  0 setMockScreen(3180, 2160, 80);
116  0 assertEquals(HiDPISetting.getScalePropertyArg(),
117  0 Platform.isLinux() ? "-D" + scalePropertyName + "=2" : null);
118   
119    // 4K screen with high dpi -- scale by 3
120  0 setMockScreen(3180, 2160, 450);
121  0 assertEquals(HiDPISetting.getScalePropertyArg(),
122  0 Platform.isLinux() ? "-D" + scalePropertyName + "=3" : null);
123   
124    // stupidly big screen -- scale by 8
125  0 setMockScreen(19200, 10800, 72);
126  0 assertEquals(HiDPISetting.getScalePropertyArg(),
127  0 Platform.isLinux() ? "-D" + scalePropertyName + "=8" : null);
128    }
129    }
130   
 
131  0 toggle private void setMockScreen(int width, int height, int dpi)
132    {
133  0 HiDPISetting.clear();
134  0 ScreenInfo mockScreenInfo = Mockito.spy(HiDPISetting.getScreenInfo());
135  0 Mockito.doReturn(height).when(mockScreenInfo).getScreenHeight();
136  0 Mockito.doReturn(width).when(mockScreenInfo).getScreenWidth();
137  0 Mockito.doReturn(dpi).when(mockScreenInfo).getScreenResolution();
138  0 HiDPISetting.setScreenInfo(mockScreenInfo);
139    }
140    }