1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 78.2% |
Uncovered Elements: 17 (78) |
Complexity: 19 |
Complexity Density: 0.35 |
|
43 |
|
public class HiDPISettingTest2 |
44 |
|
{ |
45 |
|
private static final int TIMEOUT = 10; |
46 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 7 |
Complexity Density: 0.7 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
4 |
private Worker(Process process)... |
58 |
|
{ |
59 |
4 |
this.process = process; |
60 |
|
} |
61 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
62 |
4 |
@Override... |
63 |
|
public void run() |
64 |
|
{ |
65 |
4 |
try |
66 |
|
{ |
67 |
4 |
exited = process.waitFor(TIMEOUT, TimeUnit.SECONDS); |
68 |
|
} catch (InterruptedException ignore) |
69 |
|
{ |
70 |
4 |
return; |
71 |
|
} |
72 |
0 |
this.interrupt(); |
73 |
0 |
this.process.destroy(); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
public BufferedReader getOutputReader()... |
77 |
|
{ |
78 |
0 |
return outputReader; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
4 |
public void setOutputReader(BufferedReader outputReader)... |
82 |
|
{ |
83 |
4 |
this.outputReader = outputReader; |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
164 |
public BufferedReader getErrorReader()... |
87 |
|
{ |
88 |
164 |
return errorReader; |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
4 |
public void setErrorReader(BufferedReader errorReader)... |
92 |
|
{ |
93 |
4 |
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 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
103 |
4 |
public synchronized static String getClassPath()... |
104 |
|
{ |
105 |
4 |
if (scanner == null) |
106 |
|
{ |
107 |
1 |
scanner = new ClassGraph(); |
108 |
1 |
ScanResult scan = scanner.scan(); |
109 |
1 |
classpath = scan.getClasspath(); |
110 |
1 |
java_exe = System.getProperty("java.home") + File.separator + "bin" |
111 |
|
+ File.separator + "java"; |
112 |
|
|
113 |
|
} |
114 |
4 |
while (classpath == null) |
115 |
|
{ |
116 |
0 |
try |
117 |
|
{ |
118 |
0 |
Thread.sleep(10); |
119 |
|
} catch (InterruptedException x) |
120 |
|
{ |
121 |
|
|
122 |
|
} |
123 |
|
} |
124 |
4 |
return classpath; |
125 |
|
} |
126 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
127 |
4 |
private Worker getJalviewDesktopRunner(String jvmArgs, String appArgs)... |
128 |
|
{ |
129 |
4 |
String classpath = getClassPath(); |
130 |
4 |
String cmd = java_exe + " " + " -classpath " + classpath + " " + jvmArgs |
131 |
|
+ " jalview.bin.Jalview " + " " |
132 |
|
+ "--props=test/jalview/bin/hidpiTestProps.jvprops " + appArgs; |
133 |
4 |
Process proc = null; |
134 |
4 |
Worker worker = null; |
135 |
4 |
try |
136 |
|
{ |
137 |
4 |
proc = Runtime.getRuntime().exec(cmd); |
138 |
|
} catch (Throwable e) |
139 |
|
{ |
140 |
0 |
e.printStackTrace(); |
141 |
|
} |
142 |
4 |
if (proc != null) |
143 |
|
{ |
144 |
4 |
BufferedReader outputReader = new BufferedReader( |
145 |
|
new InputStreamReader(proc.getInputStream())); |
146 |
4 |
BufferedReader errorReader = new BufferedReader( |
147 |
|
new InputStreamReader(proc.getErrorStream())); |
148 |
4 |
worker = new Worker(proc); |
149 |
4 |
worker.start(); |
150 |
4 |
worker.setOutputReader(outputReader); |
151 |
4 |
worker.setErrorReader(errorReader); |
152 |
|
} |
153 |
4 |
return worker; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
4 |
@BeforeTest(alwaysRun = true)... |
157 |
|
public void initialize() |
158 |
|
{ |
159 |
4 |
new HiDPISettingTest2(); |
160 |
|
} |
161 |
|
|
|
|
| 70.7% |
Uncovered Elements: 12 (41) |
Complexity: 10 |
Complexity Density: 0.34 |
1PASS
|
|
162 |
4 |
@Test(groups = { "Functional" }, dataProvider = "hidpiScaleArguments")... |
163 |
|
public void testHiDPISettings(int scale) |
164 |
|
{ |
165 |
4 |
if (!Platform.isLinux()) |
166 |
|
{ |
167 |
0 |
throw new SkipException( |
168 |
|
"Not linux platform, not testing actual scaling with " |
169 |
|
+ HiDPISetting.scalePropertyName); |
170 |
|
} |
171 |
|
|
172 |
4 |
String jvmArgs = HiDPISetting.getScalePropertyArg(scale); |
173 |
|
|
174 |
4 |
String appArgs = " --open examples/uniref50.fa --nosplash --nonews --noquestionnaire --nousagestats --nowebservicediscovery"; |
175 |
|
|
176 |
4 |
Worker worker = getJalviewDesktopRunner(jvmArgs, appArgs); |
177 |
4 |
assertNotNull(worker, "worker is null"); |
178 |
|
|
179 |
4 |
String ln = null; |
180 |
4 |
int count = 0; |
181 |
4 |
boolean scaleFound = false; |
182 |
4 |
try |
183 |
|
{ |
184 |
? |
while ((ln = worker.getErrorReader().readLine()) != null) |
185 |
|
{ |
186 |
164 |
if (++count > 150) |
187 |
|
{ |
188 |
0 |
break; |
189 |
|
} |
190 |
164 |
if (ln.contains(Desktop.debugScaleMessage)) |
191 |
|
{ |
192 |
4 |
String number = ln.substring(ln.indexOf(Desktop.debugScaleMessage) |
193 |
|
+ Desktop.debugScaleMessage.length()); |
194 |
4 |
number = number.substring(0, number.indexOf(' ')); |
195 |
4 |
try |
196 |
|
{ |
197 |
4 |
double d = Double.valueOf(number); |
198 |
|
|
199 |
4 |
assertEquals(d, scale * 1.0); |
200 |
4 |
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 |
4 |
break; |
209 |
|
} |
210 |
|
} |
211 |
|
} catch (IOException e) |
212 |
|
{ |
213 |
0 |
e.printStackTrace(); |
214 |
|
} |
215 |
4 |
if (worker != null && worker.exited == false) |
216 |
|
{ |
217 |
4 |
worker.interrupt(); |
218 |
4 |
worker.process.destroy(); |
219 |
|
} |
220 |
4 |
if (!scaleFound) |
221 |
|
{ |
222 |
0 |
Assert.fail("Did not find Debug scale message line '" |
223 |
|
+ Desktop.debugScaleMessage + "'"); |
224 |
|
} |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
1 |
@DataProvider(name = "hidpiScaleArguments")... |
228 |
|
public static Object[][] getHiDPIScaleArguments() |
229 |
|
{ |
230 |
1 |
return new Object[][] { { 1 }, { 2 }, { 4 }, { 10 } }; |
231 |
|
} |
232 |
|
} |