1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.qedeq.kernel.bo.latex; |
19 |
|
|
20 |
|
import java.io.File; |
21 |
|
import java.io.IOException; |
22 |
|
import java.io.InputStream; |
23 |
|
|
24 |
|
import org.qedeq.base.io.IoUtility; |
25 |
|
import org.qedeq.base.test.QedeqTestCase; |
26 |
|
import org.qedeq.base.trace.Trace; |
27 |
|
import org.qedeq.kernel.bo.QedeqBo; |
28 |
|
import org.qedeq.kernel.bo.logic.wf.LogicalCheckException; |
29 |
|
import org.qedeq.kernel.bo.module.InternalKernelServices; |
30 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
31 |
|
import org.qedeq.kernel.bo.service.DefaultModuleAddress; |
32 |
|
import org.qedeq.kernel.bo.service.latex.Qedeq2Latex; |
33 |
|
import org.qedeq.kernel.bo.service.latex.QedeqBoDuplicateLanguageChecker; |
34 |
|
import org.qedeq.kernel.bo.test.KernelFacade; |
35 |
|
import org.qedeq.kernel.common.DefaultSourceFileExceptionList; |
36 |
|
import org.qedeq.kernel.common.ModuleAddress; |
37 |
|
import org.qedeq.kernel.common.ModuleDataException; |
38 |
|
import org.qedeq.kernel.common.SourceFileException; |
39 |
|
import org.qedeq.kernel.common.SourceFileExceptionList; |
40 |
|
import org.xml.sax.SAXParseException; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@author |
47 |
|
|
|
|
| 88,4% |
Uncovered Elements: 25 (215) |
Complexity: 32 |
Complexity Density: 0,17 |
|
48 |
|
public class GenerateLatexTest extends QedeqTestCase { |
49 |
|
|
50 |
|
|
51 |
|
private static final Class CLASS = GenerateLatexTest.class; |
52 |
|
|
53 |
|
|
54 |
|
private File genDir; |
55 |
|
|
56 |
|
|
57 |
|
private File docDir; |
58 |
|
|
|
|
| 76,9% |
Uncovered Elements: 3 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
59 |
16
|
public void setUp() throws Exception {... |
60 |
16
|
super.setUp(); |
61 |
16
|
docDir = new File("../QedeqDoc"); |
62 |
16
|
genDir = new File("../../../qedeq_gen"); |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
16
|
if (!docDir.exists()) { |
67 |
16
|
docDir = getFile("doc"); |
68 |
|
|
69 |
16
|
if (!docDir.exists()) { |
70 |
0
|
throw new IOException("unknown source directory for QEDEQ modules"); |
71 |
|
} |
72 |
16
|
genDir = new File(getOutdir(), "doc"); |
73 |
|
} |
74 |
16
|
KernelFacade.startup(); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
77 |
16
|
public void tearDown() throws Exception {... |
78 |
16
|
super.tearDown(); |
79 |
16
|
KernelFacade.shutdown(); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@throws |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
87 |
2
|
public void testGeneration() throws Exception {... |
88 |
2
|
generate(docDir, "math/qedeq_logic_v1.xml", genDir, false); |
89 |
2
|
generate(docDir, "math/qedeq_sample1.xml", genDir, false); |
90 |
2
|
generate(docDir, "math/qedeq_set_theory_v1.xml", genDir, false); |
91 |
2
|
generate(docDir, "project/qedeq_basic_concept.xml", genDir, false); |
92 |
2
|
generate(docDir, "project/qedeq_logic_language.xml", genDir, true); |
93 |
|
} |
94 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
95 |
2
|
public void testNegative02() throws IOException {... |
96 |
2
|
try { |
97 |
2
|
generate(getIndir(), "qedeq_sample2_error.xml", "de", new File(genDir, "null")); |
98 |
0
|
fail("IllegalModuleDataException expected"); |
99 |
|
} catch (SourceFileExceptionList list) { |
100 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
101 |
2
|
assertEquals(1, ex.size()); |
102 |
2
|
SourceFileException e = ex.get(0); |
103 |
2
|
assertTrue(e.getCause() instanceof ModuleDataException); |
104 |
2
|
assertEquals(10002, e.getErrorCode()); |
105 |
2
|
assertEquals(221, e.getSourceArea().getStartPosition().getLine()); |
106 |
2
|
assertEquals(9, e.getSourceArea().getStartPosition().getColumn()); |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| 91,7% |
Uncovered Elements: 1 (12) |
Complexity: 2 |
Complexity Density: 0,17 |
1
PASS
|
|
110 |
2
|
public void testNegative03() throws IOException {... |
111 |
2
|
try { |
112 |
2
|
generate(getIndir(), "qedeq_sample3_error.xml", "en", new File(genDir, "null")); |
113 |
0
|
fail("IllegalModuleDataException expected"); |
114 |
|
} catch (SourceFileExceptionList list) { |
115 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
116 |
2
|
assertEquals(1, ex.size()); |
117 |
2
|
SourceFileException e = ex.get(0); |
118 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
119 |
2
|
assertEquals(9001, e.getErrorCode()); |
120 |
2
|
assertEquals(313, e.getSourceArea().getStartPosition().getLine()); |
121 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
122 |
2
|
assertEquals(313, e.getSourceArea().getEndPosition().getLine()); |
123 |
2
|
assertEquals(30, e.getSourceArea().getEndPosition().getColumn()); |
124 |
|
} |
125 |
|
} |
126 |
|
|
|
|
| 98,1% |
Uncovered Elements: 1 (54) |
Complexity: 2 |
Complexity Density: 0,04 |
1
PASS
|
|
127 |
2
|
public void testNegative04() throws IOException {... |
128 |
2
|
try { |
129 |
2
|
generate(getIndir(), "qedeq_sample4_error.xml", "en", new File(genDir, "null")); |
130 |
0
|
fail("IllegalModuleDataException expected"); |
131 |
|
} catch (SourceFileExceptionList list) { |
132 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
133 |
2
|
assertEquals(7, ex.size()); |
134 |
2
|
SourceFileException e = ex.get(0); |
135 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
136 |
2
|
assertEquals(9001, e.getErrorCode()); |
137 |
2
|
assertEquals(13, e.getSourceArea().getStartPosition().getLine()); |
138 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
139 |
2
|
assertEquals(13, e.getSourceArea().getEndPosition().getLine()); |
140 |
2
|
assertEquals(13, e.getSourceArea().getEndPosition().getColumn()); |
141 |
2
|
e = ex.get(1); |
142 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
143 |
2
|
assertEquals(9001, e.getErrorCode()); |
144 |
2
|
assertEquals(16, e.getSourceArea().getStartPosition().getLine()); |
145 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
146 |
2
|
assertEquals(16, e.getSourceArea().getEndPosition().getLine()); |
147 |
2
|
assertEquals(16, e.getSourceArea().getEndPosition().getColumn()); |
148 |
2
|
e = ex.get(2); |
149 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
150 |
2
|
assertEquals(9001, e.getErrorCode()); |
151 |
2
|
assertEquals(19, e.getSourceArea().getStartPosition().getLine()); |
152 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
153 |
2
|
assertEquals(19, e.getSourceArea().getEndPosition().getLine()); |
154 |
2
|
assertEquals(15, e.getSourceArea().getEndPosition().getColumn()); |
155 |
2
|
e = ex.get(3); |
156 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
157 |
2
|
assertEquals(9001, e.getErrorCode()); |
158 |
2
|
assertEquals(22, e.getSourceArea().getStartPosition().getLine()); |
159 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
160 |
2
|
assertEquals(22, e.getSourceArea().getEndPosition().getLine()); |
161 |
2
|
assertEquals(15, e.getSourceArea().getEndPosition().getColumn()); |
162 |
2
|
e = ex.get(4); |
163 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
164 |
2
|
assertEquals(9001, e.getErrorCode()); |
165 |
2
|
assertEquals(26, e.getSourceArea().getStartPosition().getLine()); |
166 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
167 |
2
|
assertEquals(26, e.getSourceArea().getEndPosition().getLine()); |
168 |
2
|
assertEquals(23, e.getSourceArea().getEndPosition().getColumn()); |
169 |
2
|
e = ex.get(5); |
170 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
171 |
2
|
assertEquals(9001, e.getErrorCode()); |
172 |
2
|
assertEquals(69, e.getSourceArea().getStartPosition().getLine()); |
173 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
174 |
2
|
assertEquals(69, e.getSourceArea().getEndPosition().getLine()); |
175 |
2
|
assertEquals(47, e.getSourceArea().getEndPosition().getColumn()); |
176 |
2
|
e = ex.get(6); |
177 |
2
|
assertTrue(e.getCause() instanceof SAXParseException); |
178 |
2
|
assertEquals(9001, e.getErrorCode()); |
179 |
2
|
assertEquals(98, e.getSourceArea().getStartPosition().getLine()); |
180 |
2
|
assertEquals(1, e.getSourceArea().getStartPosition().getColumn()); |
181 |
2
|
assertEquals(98, e.getSourceArea().getEndPosition().getLine()); |
182 |
2
|
assertEquals(47, e.getSourceArea().getEndPosition().getColumn()); |
183 |
|
} |
184 |
|
} |
185 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
186 |
2
|
public void testNegative05() throws IOException {... |
187 |
2
|
try { |
188 |
2
|
generate(getIndir(), "qedeq_sample5_error.xml", "en", new File(genDir, "null")); |
189 |
0
|
fail("IllegalModuleDataException expected"); |
190 |
|
} catch (SourceFileExceptionList list) { |
191 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
192 |
2
|
assertEquals(1, ex.size()); |
193 |
2
|
SourceFileException e = ex.get(0); |
194 |
2
|
assertTrue(e.getCause() instanceof LogicalCheckException); |
195 |
2
|
assertEquals(30550, e.getErrorCode()); |
196 |
2
|
assertEquals(168, e.getSourceArea().getStartPosition().getLine()); |
197 |
2
|
assertEquals(15, e.getSourceArea().getStartPosition().getColumn()); |
198 |
|
} |
199 |
|
} |
200 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
201 |
2
|
public void testNegative06() throws IOException {... |
202 |
2
|
try { |
203 |
2
|
generate(getIndir(), "qedeq_sample6_error.xml", "en", new File(genDir, "null")); |
204 |
0
|
fail("IllegalModuleDataException expected"); |
205 |
|
} catch (SourceFileExceptionList list) { |
206 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
207 |
2
|
assertEquals(1, ex.size()); |
208 |
2
|
SourceFileException e = ex.get(0); |
209 |
2
|
assertTrue(e.getCause() instanceof LogicalCheckException); |
210 |
2
|
assertEquals(30590, e.getErrorCode()); |
211 |
2
|
assertEquals(286, e.getSourceArea().getStartPosition().getLine()); |
212 |
2
|
assertEquals(21, e.getSourceArea().getStartPosition().getColumn()); |
213 |
|
} |
214 |
|
} |
215 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
216 |
2
|
public void testNegative07() throws IOException {... |
217 |
2
|
try { |
218 |
2
|
generate(getIndir(), "qedeq_sample7_error.xml", "en", new File(genDir, "null")); |
219 |
0
|
fail("IllegalModuleDataException expected"); |
220 |
|
} catch (SourceFileExceptionList list) { |
221 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
222 |
2
|
assertEquals(1, ex.size()); |
223 |
2
|
SourceFileException e = ex.get(0); |
224 |
2
|
assertTrue(e.getCause() instanceof LogicalCheckException); |
225 |
2
|
assertEquals(30780, e.getErrorCode()); |
226 |
2
|
assertEquals(296, e.getSourceArea().getStartPosition().getLine()); |
227 |
2
|
assertEquals(17, e.getSourceArea().getStartPosition().getColumn()); |
228 |
|
} |
229 |
|
} |
230 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
231 |
2
|
public void testNegative08() throws IOException {... |
232 |
2
|
try { |
233 |
2
|
generate(getIndir(), "qedeq_sample8_error.xml", "en", new File(genDir, "null")); |
234 |
0
|
fail("SourceFileExceptionList expected"); |
235 |
|
} catch (SourceFileExceptionList list) { |
236 |
2
|
DefaultSourceFileExceptionList ex = (DefaultSourceFileExceptionList) list; |
237 |
2
|
assertEquals(1, ex.size()); |
238 |
2
|
SourceFileException e = ex.get(0); |
239 |
2
|
assertTrue(e.getCause() instanceof ModuleDataException); |
240 |
2
|
assertEquals(1001, e.getErrorCode()); |
241 |
2
|
assertEquals(306, e.getSourceArea().getStartPosition().getLine()); |
242 |
2
|
assertEquals(15, e.getSourceArea().getStartPosition().getColumn()); |
243 |
|
} |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
@param |
251 |
|
@param |
252 |
|
@param |
253 |
|
@param |
254 |
|
@throws |
255 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
256 |
5
|
public void generate(final File dir, final String xml, final File destinationDirectory,... |
257 |
|
final boolean onlyEn) throws Exception { |
258 |
5
|
generate(dir, xml, "en", destinationDirectory); |
259 |
5
|
if (!onlyEn) { |
260 |
4
|
generate(dir, xml, "de", destinationDirectory); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
@param |
268 |
|
@param |
269 |
|
@param |
270 |
|
@param |
271 |
|
@throws |
272 |
|
@throws |
273 |
|
|
|
|
| 88,9% |
Uncovered Elements: 4 (36) |
Complexity: 5 |
Complexity Density: 0,18 |
|
274 |
32
|
public void generate(final File dir, final String xml, final String language,... |
275 |
|
final File destinationDirectory) throws IOException, SourceFileExceptionList { |
276 |
32
|
final File xmlFile = new File(dir, xml); |
277 |
32
|
final ModuleAddress address = KernelFacade.getKernelContext().getModuleAddress( |
278 |
|
IoUtility.toUrl(xmlFile)); |
279 |
32
|
final KernelQedeqBo prop = (KernelQedeqBo) KernelFacade.getKernelContext().loadModule( |
280 |
|
address); |
281 |
32
|
if (prop.hasFailures()) { |
282 |
6
|
throw prop.getException(); |
283 |
|
} |
284 |
26
|
KernelFacade.getKernelContext().loadRequiredModules(prop.getModuleAddress()); |
285 |
26
|
if (prop.hasFailures()) { |
286 |
0
|
throw prop.getException(); |
287 |
|
} |
288 |
26
|
KernelFacade.getKernelContext().checkModule(prop.getModuleAddress()); |
289 |
26
|
if (prop.hasFailures()) { |
290 |
6
|
throw prop.getException(); |
291 |
|
} |
292 |
20
|
QedeqBoDuplicateLanguageChecker.check(prop); |
293 |
18
|
if (prop.hasFailures()) { |
294 |
0
|
throw prop.getException(); |
295 |
|
} |
296 |
|
|
297 |
18
|
final String web = "http://qedeq.org/" |
298 |
|
+ KernelFacade.getKernelContext().getKernelVersionDirectory() + "/doc/" + xml; |
299 |
18
|
final InternalKernelServices services = (InternalKernelServices) IoUtility.getFieldContent( |
300 |
|
KernelFacade.getKernelContext(), "services"); |
301 |
18
|
final ModuleAddress webAddress = new DefaultModuleAddress(web); |
302 |
18
|
services.getLocalFilePath(webAddress); |
303 |
18
|
IoUtility.copyFile(xmlFile, services.getLocalFilePath(webAddress)); |
304 |
|
|
305 |
18
|
KernelFacade.getKernelContext().checkModule(webAddress); |
306 |
18
|
final QedeqBo webBo = KernelFacade.getKernelContext().getQedeqBo(webAddress); |
307 |
18
|
final File texFile = new File(destinationDirectory, xml.substring(0, xml.lastIndexOf('.')) |
308 |
|
+ "_" + language + ".tex"); |
309 |
18
|
generate((KernelQedeqBo) webBo, texFile, language, "1"); |
310 |
18
|
final File texCopy = new File(dir, new File(new File(xml).getParent(), texFile.getName()) |
311 |
|
.getPath()); |
312 |
18
|
final File xmlCopy = new File(destinationDirectory, xml); |
313 |
18
|
IoUtility.createNecessaryDirectories(xmlCopy); |
314 |
18
|
IoUtility.copyFile(xmlFile, xmlCopy); |
315 |
18
|
IoUtility.copyFile(texFile, texCopy); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
@param |
322 |
|
@param |
323 |
|
@param |
324 |
|
@param |
325 |
|
@return |
326 |
|
@throws |
327 |
|
|
|
|
| 66,7% |
Uncovered Elements: 7 (21) |
Complexity: 4 |
Complexity Density: 0,21 |
|
328 |
18
|
public String generate(final KernelQedeqBo prop, final File to, final String language,... |
329 |
|
final String level) throws SourceFileExceptionList { |
330 |
18
|
final String method = "generate(String, String, String, String)"; |
331 |
18
|
try { |
332 |
18
|
Trace.begin(CLASS, method); |
333 |
18
|
Trace.param(CLASS, method, "prop", prop); |
334 |
18
|
Trace.param(CLASS, method, "to", to); |
335 |
18
|
Trace.param(CLASS, method, "language", language); |
336 |
18
|
Trace.param(CLASS, method, "level", level); |
337 |
18
|
final InputStream latex = Qedeq2Latex.createLatex(prop, language, level); |
338 |
18
|
if (to != null) { |
339 |
18
|
IoUtility.createNecessaryDirectories(to); |
340 |
18
|
IoUtility.saveFile(latex, to); |
341 |
18
|
return to.getCanonicalPath(); |
342 |
|
} else { |
343 |
0
|
latex.close(); |
344 |
0
|
return prop.getName(); |
345 |
|
} |
346 |
|
} catch (IOException e) { |
347 |
0
|
Trace.trace(CLASS, method, e); |
348 |
0
|
throw new DefaultSourceFileExceptionList(e); |
349 |
|
} catch (RuntimeException e) { |
350 |
0
|
Trace.trace(CLASS, method, e); |
351 |
0
|
throw new DefaultSourceFileExceptionList(e); |
352 |
|
} finally { |
353 |
18
|
Trace.end(CLASS, method); |
354 |
|
} |
355 |
|
} |
356 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
357 |
0
|
public File getGenDir() {... |
358 |
0
|
return genDir; |
359 |
|
} |
360 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
361 |
0
|
public File getDocDir() {... |
362 |
0
|
return docDir; |
363 |
|
} |
364 |
|
|
365 |
|
} |