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.SkipException;
34 import org.testng.annotations.BeforeTest;
35 import org.testng.annotations.DataProvider;
36 import org.testng.annotations.Test;
38 import io.github.classgraph.ClassGraph;
39 import io.github.classgraph.ScanResult;
40 import jalview.gui.Desktop;
41 import jalview.util.Platform;
43 public class HiDPISettingTest2
45 private static final int TIMEOUT = 10;
47 private static class Worker extends Thread
49 private final Process process;
51 private BufferedReader outputReader;
53 private BufferedReader errorReader;
55 private boolean exited;
57 private Worker(Process process)
59 this.process = process;
67 exited = process.waitFor(TIMEOUT, TimeUnit.SECONDS);
68 } catch (InterruptedException ignore)
73 this.process.destroy();
76 public BufferedReader getOutputReader()
81 public void setOutputReader(BufferedReader outputReader)
83 this.outputReader = outputReader;
86 public BufferedReader getErrorReader()
91 public void setErrorReader(BufferedReader errorReader)
93 this.errorReader = errorReader;
97 private static ClassGraph scanner = null;
99 private static String classpath = null;
101 private static String java_exe = null;
103 public synchronized static String getClassPath()
107 scanner = new ClassGraph();
108 ScanResult scan = scanner.scan();
109 classpath = scan.getClasspath();
110 java_exe = System.getProperty("java.home") + File.separator + "bin"
111 + File.separator + "java";
114 while (classpath == null)
119 } catch (InterruptedException x)
127 private Worker getJalviewDesktopRunner(String jvmArgs, String appArgs)
129 String classpath = getClassPath();
130 String cmd = java_exe + " " + " -classpath " + classpath + " " + jvmArgs
131 + " jalview.bin.Jalview " + " "
132 + "-props test/jalview/bin/hidpiTestProps.jvprops " + appArgs;
134 Worker worker = null;
137 proc = Runtime.getRuntime().exec(cmd);
138 } catch (Throwable e)
144 BufferedReader outputReader = new BufferedReader(
145 new InputStreamReader(proc.getInputStream()));
146 BufferedReader errorReader = new BufferedReader(
147 new InputStreamReader(proc.getErrorStream()));
148 worker = new Worker(proc);
150 worker.setOutputReader(outputReader);
151 worker.setErrorReader(errorReader);
156 @BeforeTest(alwaysRun = true)
157 public void initialize()
159 new HiDPISettingTest2();
162 @Test(groups = { "Functional" }, dataProvider = "hidpiScaleArguments")
163 public void testHiDPISettings(int scale)
165 if (!Platform.isLinux())
167 throw new SkipException(
168 "Not linux platform, not testing actual scaling with "
169 + HiDPISetting.scalePropertyName);
172 String jvmArgs = HiDPISetting.getScalePropertyArg(scale);
174 String appArgs = " -open examples/uniref50.fa -nosplash -nonews -noquestionnaire -nousagestats -nowebservicediscovery --debug";
176 Worker worker = getJalviewDesktopRunner(jvmArgs, appArgs);
177 assertNotNull(worker, "worker is null");
181 boolean scaleFound = false;
184 while ((ln = worker.getErrorReader().readLine()) != null)
190 if (ln.contains(Desktop.debugScaleMessage))
192 String number = ln.substring(ln.indexOf(Desktop.debugScaleMessage)
193 + Desktop.debugScaleMessage.length());
194 number = number.substring(0, number.indexOf(' '));
197 double d = Double.valueOf(number);
199 assertEquals(d, scale * 1.0);
201 } catch (NumberFormatException e)
205 "Debug scale message line '" + ln + "' gives number '"
206 + number + "' which could not be parsed");
211 } catch (IOException e)
215 if (worker != null && worker.exited == false)
218 worker.process.destroy();
222 Assert.fail("Did not find Debug scale message line '"
223 + Desktop.debugScaleMessage + "'");
227 @DataProvider(name = "hidpiScaleArguments")
228 public static Object[][] getHiDPIScaleArguments()
230 return new Object[][] { { 1 }, { 2 }, { 4 }, { 10 } };