2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.Assert.assertEquals;
25 import org.mockito.Mockito;
26 import org.testng.annotations.AfterClass;
27 import org.testng.annotations.BeforeMethod;
28 import org.testng.annotations.Test;
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;
37 * Testing a HiDPI display is difficult without running in a HiDPI display.
38 * The gathering of screen size and resolution performed by jalview.bin.HiDPISetting
39 * is now farmed out into a separate class jalview.bin.ScreenInfo so it can be more
40 * easily Mocked in tests.
41 * Two sets of tests are performed.
42 * 1) testLinuxScalePropertyToActualTransform() sets the property that HiDPISetting
43 * uses (via jalview.bin.Launcher or getdown) to scale up Jalview, and then looks at
44 * the alignment panel graphics2d transform to see if it's been scaled by the same
45 * amount (in this case 4 -- unlikely to happen by accident!).
46 * 2) testHiDPISettingInit() which tests the calculation that HiDPISetting uses to
47 * decide from apparent screen information (mocked using Mockito in the tests) what
48 * scaling factor to set (it doesn't actually set it, just suggests it to
49 * jalview.bin.Launcher)
51 public class HiDPISettingTest1
56 @BeforeMethod(alwaysRun = true)
59 JvOptionPane.setInteractiveMode(false);
60 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61 Cache.loadProperties("test/jalview/bin/hidpiTestProps.jvprops");
64 { "-nosplash", "-nonews", "-noquestionnaire",
65 "-nowebservicediscovery" });
67 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
71 * wait for Consensus thread to complete
78 } catch (InterruptedException x)
81 } while (af.getViewport().getCalcManager().isWorking());
84 @AfterClass(alwaysRun = true)
85 public void tearDown()
87 Desktop.instance.closeAll_actionPerformed(null);
90 @Test(groups = { "Functional" })
91 public void testHiDPISettingInit()
93 String scalePropertyName = "sun.java2d.uiScale";
94 // ensure scale property is cleared (otherwise it will be re-used)
95 System.clearProperty(HiDPISetting.scalePropertyName);
97 { // keep the mock under lock
98 // Ancient monitor -- no property change set
99 setMockScreen(1024, 768, 72);
100 assertEquals(HiDPISetting.getScalePropertyArg(), null);
102 // Old monitor -- no property change set
103 setMockScreen(1200, 800, 96);
104 assertEquals(HiDPISetting.getScalePropertyArg(), null);
106 // HD screen -- no property change set
107 setMockScreen(1920, 1080, 96);
108 assertEquals(HiDPISetting.getScalePropertyArg(), null);
110 // 4K screen -- scale by 2
111 setMockScreen(3180, 2160, 80);
112 assertEquals(HiDPISetting.getScalePropertyArg(),
113 "-D" + scalePropertyName + "=2");
115 // 4K screen with high dpi -- scale by 3
116 setMockScreen(3180, 2160, 450);
117 assertEquals(HiDPISetting.getScalePropertyArg(),
118 "-D" + scalePropertyName + "=3");
120 // stupidly big screen -- scale by 8
121 setMockScreen(19200, 10800, 72);
122 assertEquals(HiDPISetting.getScalePropertyArg(),
123 "-D" + scalePropertyName + "=8");
127 private void setMockScreen(int width, int height, int dpi)
129 HiDPISetting.clear();
130 ScreenInfo mockScreenInfo = Mockito.spy(HiDPISetting.getScreenInfo());
131 Mockito.doReturn(height).when(mockScreenInfo).getScreenHeight();
132 Mockito.doReturn(width).when(mockScreenInfo).getScreenWidth();
133 Mockito.doReturn(dpi).when(mockScreenInfo).getScreenResolution();
134 HiDPISetting.setScreenInfo(mockScreenInfo);