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;
24 import static org.testng.Assert.assertNotNull;
26 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30 import java.util.concurrent.TimeUnit;
32 import org.testng.Assert;
33 import org.testng.annotations.BeforeTest;
34 import org.testng.annotations.DataProvider;
35 import org.testng.annotations.Test;
37 import io.github.classgraph.ClassGraph;
38 import io.github.classgraph.ScanResult;
39 import jalview.gui.Desktop;
41 public class HiDPISettingTest2
43 private static final int TIMEOUT = 10;
45 private static class Worker extends Thread
47 private final Process process;
49 private BufferedReader outputReader;
51 private BufferedReader errorReader;
53 private boolean exited;
55 private Worker(Process process)
57 this.process = process;
65 exited = process.waitFor(TIMEOUT, TimeUnit.SECONDS);
66 } catch (InterruptedException ignore)
71 this.process.destroy();
74 public BufferedReader getOutputReader()
79 public void setOutputReader(BufferedReader outputReader)
81 this.outputReader = outputReader;
84 public BufferedReader getErrorReader()
89 public void setErrorReader(BufferedReader errorReader)
91 this.errorReader = errorReader;
95 private static ClassGraph scanner = null;
97 private static String classpath = null;
99 private static String java_exe = null;
101 public synchronized static String getClassPath()
105 scanner = new ClassGraph();
106 ScanResult scan = scanner.scan();
107 classpath = scan.getClasspath();
108 java_exe = System.getProperty("java.home") + File.separator + "bin"
109 + File.separator + "java";
112 while (classpath == null)
117 } catch (InterruptedException x)
125 private Worker getJalviewDesktopRunner(String jvmArgs, String appArgs)
127 String classpath = getClassPath();
128 String cmd = java_exe + " " + " -classpath " + classpath + " " + jvmArgs
129 + " jalview.bin.Jalview " + " "
130 + "-props test/jalview/bin/hidpiTestProps.jvprops " + appArgs;
132 Worker worker = null;
135 proc = Runtime.getRuntime().exec(cmd);
136 } catch (Throwable e)
142 BufferedReader outputReader = new BufferedReader(
143 new InputStreamReader(proc.getInputStream()));
144 BufferedReader errorReader = new BufferedReader(
145 new InputStreamReader(proc.getErrorStream()));
146 worker = new Worker(proc);
148 worker.setOutputReader(outputReader);
149 worker.setErrorReader(errorReader);
154 @BeforeTest(alwaysRun = true)
155 public void initialize()
157 new HiDPISettingTest2();
160 @Test(groups = { "Functional" }, dataProvider = "hidpiScaleArguments")
161 public void testHiDPISettings(int scale)
163 String jvmArgs = HiDPISetting.getScalePropertyArg(scale);
165 String appArgs = " -open examples/uniref50.fa -nosplash -nonews -noquestionnaire -nousagestats -nowebservicediscovery";
167 Worker worker = getJalviewDesktopRunner(jvmArgs, appArgs);
168 assertNotNull(worker, "worker is null");
172 boolean scaleFound = false;
175 while ((ln = worker.getErrorReader().readLine()) != null)
181 if (ln.contains(Desktop.debugScaleMessage))
183 String number = ln.substring(ln.indexOf(Desktop.debugScaleMessage)
184 + Desktop.debugScaleMessage.length());
185 number = number.substring(0, number.indexOf(' '));
188 double d = Double.valueOf(number);
190 assertEquals(d, scale * 1.0);
192 } catch (NumberFormatException e)
196 "Debug scale message line '" + ln + "' gives number '"
197 + number + "' which could not be parsed");
202 } catch (IOException e)
206 if (worker != null && worker.exited == false)
209 worker.process.destroy();
213 Assert.fail("Did not find Debug scale message line '"
214 + Desktop.debugScaleMessage + "'");
218 @DataProvider(name = "hidpiScaleArguments")
219 public static Object[][] getHiDPIScaleArguments()
221 return new Object[][] { { 1 }, { 2 }, { 4 }, { 10 } };