3 import static org.testng.Assert.assertEquals;
5 import org.mockito.Mockito;
6 import org.testng.annotations.AfterClass;
7 import org.testng.annotations.BeforeMethod;
8 import org.testng.annotations.Test;
10 import jalview.gui.AlignFrame;
11 import jalview.gui.Desktop;
12 import jalview.gui.JvOptionPane;
13 import jalview.io.DataSourceType;
14 import jalview.io.FileLoader;
17 * Testing a HiDPI display is difficult without running in a HiDPI display.
18 * The gathering of screen size and resolution performed by jalview.bin.HiDPISetting
19 * is now farmed out into a separate class jalview.bin.ScreenInfo so it can be more
20 * easily Mocked in tests.
21 * Two sets of tests are performed.
22 * 1) testLinuxScalePropertyToActualTransform() sets the property that HiDPISetting
23 * uses (via jalview.bin.Launcher or getdown) to scale up Jalview, and then looks at
24 * the alignment panel graphics2d transform to see if it's been scaled by the same
25 * amount (in this case 4 -- unlikely to happen by accident!).
26 * 2) testHiDPISettingInit() which tests the calculation that HiDPISetting uses to
27 * decide from apparent screen information (mocked using Mockito in the tests) what
28 * scaling factor to set (it doesn't actually set it, just suggests it to
29 * jalview.bin.Launcher)
31 public class HiDPISettingTest1
36 @BeforeMethod(alwaysRun = true)
39 JvOptionPane.setInteractiveMode(false);
40 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41 Cache.loadProperties("test/jalview/bin/hidpiTestProps.jvprops");
44 { "-nosplash", "-nonews", "-noquestionnaire",
45 "-nowebservicediscovery" });
47 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
51 * wait for Consensus thread to complete
58 } catch (InterruptedException x)
61 } while (af.getViewport().getCalcManager().isWorking());
64 @AfterClass(alwaysRun = true)
65 public void tearDown()
67 Desktop.instance.closeAll_actionPerformed(null);
70 @Test(groups = { "Functional" })
71 public void testHiDPISettingInit()
73 String scalePropertyName = "sun.java2d.uiScale";
74 // ensure scale property is cleared (otherwise it will be re-used)
75 System.clearProperty(HiDPISetting.scalePropertyName);
77 { // keep the mock under lock
78 // Ancient monitor -- no property change set
79 setMockScreen(1024, 768, 72);
80 assertEquals(HiDPISetting.getScalePropertyArg(), null);
82 // Old monitor -- no property change set
83 setMockScreen(1200, 800, 96);
84 assertEquals(HiDPISetting.getScalePropertyArg(), null);
86 // HD screen -- no property change set
87 setMockScreen(1920, 1080, 96);
88 assertEquals(HiDPISetting.getScalePropertyArg(), null);
90 // 4K screen -- scale by 2
91 setMockScreen(3180, 2160, 80);
92 assertEquals(HiDPISetting.getScalePropertyArg(),
93 "-D" + scalePropertyName + "=2");
95 // 4K screen with high dpi -- scale by 3
96 setMockScreen(3180, 2160, 450);
97 assertEquals(HiDPISetting.getScalePropertyArg(),
98 "-D" + scalePropertyName + "=3");
100 // stupidly big screen -- scale by 8
101 setMockScreen(19200, 10800, 72);
102 assertEquals(HiDPISetting.getScalePropertyArg(),
103 "-D" + scalePropertyName + "=8");
107 private void setMockScreen(int width, int height, int dpi)
109 HiDPISetting.clear();
110 ScreenInfo mockScreenInfo = Mockito.spy(HiDPISetting.getScreenInfo());
111 Mockito.doReturn(height).when(mockScreenInfo).getScreenHeight();
112 Mockito.doReturn(width).when(mockScreenInfo).getScreenWidth();
113 Mockito.doReturn(dpi).when(mockScreenInfo).getScreenResolution();
114 HiDPISetting.setScreenInfo(mockScreenInfo);