Clover icon

Coverage Report

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

File HiDPISettingTest2.java

 

Code metrics

18
65
11
2
232
182
26
0.4
5.91
5.5
2.36

Classes

Class Line # Actions
HiDPISettingTest2 43 55 19
0.00%
HiDPISettingTest2.Worker 47 10 7
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    import static org.testng.Assert.assertNotNull;
25   
26    import java.io.BufferedReader;
27    import java.io.File;
28    import java.io.IOException;
29    import java.io.InputStreamReader;
30    import java.util.concurrent.TimeUnit;
31   
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;
37   
38    import io.github.classgraph.ClassGraph;
39    import io.github.classgraph.ScanResult;
40    import jalview.gui.Desktop;
41    import jalview.util.Platform;
42   
 
43    public class HiDPISettingTest2
44    {
45    private static final int TIMEOUT = 10;
46   
 
47    private static class Worker extends Thread
48    {
49    private final Process process;
50   
51    private BufferedReader outputReader;
52   
53    private BufferedReader errorReader;
54   
55    private boolean exited;
56   
 
57  0 toggle private Worker(Process process)
58    {
59  0 this.process = process;
60    }
61   
 
62  0 toggle @Override
63    public void run()
64    {
65  0 try
66    {
67  0 exited = process.waitFor(TIMEOUT, TimeUnit.SECONDS);
68    } catch (InterruptedException ignore)
69    {
70  0 return;
71    }
72  0 this.interrupt();
73  0 this.process.destroy();
74    }
75   
 
76  0 toggle public BufferedReader getOutputReader()
77    {
78  0 return outputReader;
79    }
80   
 
81  0 toggle public void setOutputReader(BufferedReader outputReader)
82    {
83  0 this.outputReader = outputReader;
84    }
85   
 
86  0 toggle public BufferedReader getErrorReader()
87    {
88  0 return errorReader;
89    }
90   
 
91  0 toggle public void setErrorReader(BufferedReader errorReader)
92    {
93  0 this.errorReader = errorReader;
94    }
95    }
96   
97    private static ClassGraph scanner = null;
98   
99    private static String classpath = null;
100   
101    private static String java_exe = null;
102   
 
103  0 toggle public synchronized static String getClassPath()
104    {
105  0 if (scanner == null)
106    {
107  0 scanner = new ClassGraph();
108  0 ScanResult scan = scanner.scan();
109  0 classpath = scan.getClasspath();
110  0 java_exe = System.getProperty("java.home") + File.separator + "bin"
111    + File.separator + "java";
112   
113    }
114  0 while (classpath == null)
115    {
116  0 try
117    {
118  0 Thread.sleep(10);
119    } catch (InterruptedException x)
120    {
121   
122    }
123    }
124  0 return classpath;
125    }
126   
 
127  0 toggle private Worker getJalviewDesktopRunner(String jvmArgs, String appArgs)
128    {
129  0 String classpath = getClassPath();
130  0 String cmd = java_exe + " " + " -classpath " + classpath + " " + jvmArgs
131    + " jalview.bin.Jalview " + " "
132    + "--props=test/jalview/bin/hidpiTestProps.jvprops " + appArgs;
133  0 Process proc = null;
134  0 Worker worker = null;
135  0 try
136    {
137  0 proc = Runtime.getRuntime().exec(cmd);
138    } catch (Throwable e)
139    {
140  0 e.printStackTrace();
141    }
142  0 if (proc != null)
143    {
144  0 BufferedReader outputReader = new BufferedReader(
145    new InputStreamReader(proc.getInputStream()));
146  0 BufferedReader errorReader = new BufferedReader(
147    new InputStreamReader(proc.getErrorStream()));
148  0 worker = new Worker(proc);
149  0 worker.start();
150  0 worker.setOutputReader(outputReader);
151  0 worker.setErrorReader(errorReader);
152    }
153  0 return worker;
154    }
155   
 
156  0 toggle @BeforeTest(alwaysRun = true)
157    public void initialize()
158    {
159  0 new HiDPISettingTest2();
160    }
161   
 
162  0 toggle @Test(groups = { "Functional" }, dataProvider = "hidpiScaleArguments")
163    public void testHiDPISettings(int scale)
164    {
165  0 if (!Platform.isLinux())
166    {
167  0 throw new SkipException(
168    "Not linux platform, not testing actual scaling with "
169    + HiDPISetting.scalePropertyName);
170    }
171   
172  0 String jvmArgs = HiDPISetting.getScalePropertyArg(scale);
173   
174  0 String appArgs = " --open examples/uniref50.fa --nosplash --nonews --noquestionnaire --nousagestats --nowebservicediscovery";
175   
176  0 Worker worker = getJalviewDesktopRunner(jvmArgs, appArgs);
177  0 assertNotNull(worker, "worker is null");
178   
179  0 String ln = null;
180  0 int count = 0;
181  0 boolean scaleFound = false;
182  0 try
183    {
184  0 while ((ln = worker.getErrorReader().readLine()) != null)
185    {
186  0 if (++count > 150)
187    {
188  0 break;
189    }
190  0 if (ln.contains(Desktop.debugScaleMessage))
191    {
192  0 String number = ln.substring(ln.indexOf(Desktop.debugScaleMessage)
193    + Desktop.debugScaleMessage.length());
194  0 number = number.substring(0, number.indexOf(' '));
195  0 try
196    {
197  0 double d = Double.valueOf(number);
198   
199  0 assertEquals(d, scale * 1.0);
200  0 scaleFound = true;
201    } catch (NumberFormatException e)
202    {
203  0 e.printStackTrace();
204  0 Assert.fail(
205    "Debug scale message line '" + ln + "' gives number '"
206    + number + "' which could not be parsed");
207    }
208  0 break;
209    }
210    }
211    } catch (IOException e)
212    {
213  0 e.printStackTrace();
214    }
215  0 if (worker != null && worker.exited == false)
216    {
217  0 worker.interrupt();
218  0 worker.process.destroy();
219    }
220  0 if (!scaleFound)
221    {
222  0 Assert.fail("Did not find Debug scale message line '"
223    + Desktop.debugScaleMessage + "'");
224    }
225    }
226   
 
227  0 toggle @DataProvider(name = "hidpiScaleArguments")
228    public static Object[][] getHiDPIScaleArguments()
229    {
230  0 return new Object[][] { { 1 }, { 2 }, { 4 }, { 10 } };
231    }
232    }