Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 01:47:57 UTC
169   559   34   7.35
22   279   0.2   23
23     1.48  
1    
 
  LoadRequiredModulesTest       Line # 29 169 34 89.3% 0.89252335
 
  (14)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15    package org.qedeq.kernel.bo.service.basis;
16   
17    import org.qedeq.kernel.bo.service.internal.DefaultInternalKernelServices;
18    import org.qedeq.kernel.bo.service.logic.SimpleProofFinderPlugin;
19    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
20    import org.qedeq.kernel.se.common.DefaultModuleAddress;
21    import org.qedeq.kernel.se.common.ModuleAddress;
22    import org.qedeq.kernel.se.common.SourceFileExceptionList;
23   
24    /**
25    * For testing of loading required QEDEQ modules.
26    *
27    * @author Michael Meyling
28    */
 
29    public class LoadRequiredModulesTest extends QedeqBoTestCase {
30   
31    /**
32    * Load following dependencies:
33    * <pre>
34    * 011 -> 012
35    * 011 -> 013 -> 012
36    * </pre>
37    *
38    * Should be OK.
39    *
40    * @throws Exception
41    */
 
42  1 toggle public void testLoadRequiredModules_01() throws Exception {
43  1 final ModuleAddress address = new DefaultModuleAddress(getFile("loadRequired/LRM011.xml"));
44  1 if (!getServices().loadRequiredModules(address)) {
45  0 fail("loading should be successful");
46    }
47    }
48   
49    /**
50    * Load following dependencies:
51    * <pre>
52    * 021 -> 021
53    * </pre>
54    *
55    * Should be not OK.
56    *
57    * @throws Exception
58    */
 
59  1 toggle public void testLoadRequiredModules_02() throws Exception {
60  1 final ModuleAddress address = new DefaultModuleAddress(
61    getFile("loadRequired/LRM021.xml"));
62  1 if (getServices().loadRequiredModules(address)) {
63  0 fail("021 -> 021 cycle");
64    } else {
65  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
66  1 assertEquals(1, e.size());
67  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
68  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
69  1 assertEquals(90722, e.get(0).getErrorCode());
70  1 assertTrue(e.get(0).getDescription().endsWith(
71    "Recursive import of modules is forbidden, label: \"LRM021\""));
72    }
73    }
74   
75    /**
76    * Load following dependencies:
77    * <pre>
78    * 031 -> 032 -> 031
79    * </pre>
80    *
81    * Should be not OK.
82    *
83    * @throws Exception
84    */
 
85  1 toggle public void testLoadRequiredModules_03() throws Exception {
86  1 final ModuleAddress address = new DefaultModuleAddress(
87    getFile("loadRequired/LRM031.xml"));
88  1 getServices().loadRequiredModules(address);
89  1 if (getServices().loadRequiredModules(address)) {
90  0 fail("031 -> 032 -> 031 cycle");
91    } else {
92  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
93  1 assertEquals(1, e.size());
94  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
95  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
96  1 assertEquals(90722, e.get(0).getErrorCode());
97    // System.out.println(e.get(0).getDescription());
98  1 assertTrue(e.get(0).getDescription().endsWith(
99    "Recursive import of modules is forbidden, label: \"LRM032\" -> \"LRM031\""));
100    }
101    }
102   
103    /**
104    * Load following dependencies:
105    * <pre>
106    * 041 -> 042 -> 043
107    * 041 -> 043 -> 044
108    * 041 -> 044 -> 042
109    * </pre>
110    *
111    * Should be not OK.
112    *
113    * @throws Exception
114    */
 
115  1 toggle public void testLoadRequiredModules_04() throws Exception {
116  1 final ModuleAddress address = new DefaultModuleAddress(
117    getFile("loadRequired/LRM041.xml"));
118  1 getServices().loadRequiredModules(address);
119  1 if (getServices().loadRequiredModules(address)) {
120  0 fail("041 -> 042 -> 043 -> 044 -> 042 cycle\n"
121    + "041 -> 043 -> 044 -> 042 -> 043 cycle\n"
122    + "041 -> 044 -> 042 -> 043 -> 044 cycle");
123    } else {
124  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
125  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
126  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
127  1 assertEquals(90722, e.get(0).getErrorCode());
128  1 assertTrue(e.get(0).getDescription().endsWith("Recursive import of modules is forbidden, label: " +
129    "\"LRM042\" -> \"LRM043\" -> \"LRM044\" -> \"LRM042\""));
130  1 assertEquals(3, e.size());
131  1 assertEquals(38, e.get(1).getSourceArea().getStartPosition().getRow());
132  1 assertEquals(15, e.get(1).getSourceArea().getStartPosition().getColumn());
133  1 assertEquals(90722, e.get(1).getErrorCode());
134  1 assertTrue(e.get(1).getDescription().endsWith("Recursive import of modules is forbidden, label: " +
135    "\"LRM043\" -> \"LRM044\" -> \"LRM042\" -> \"LRM043\""));
136  1 assertEquals(45, e.get(2).getSourceArea().getStartPosition().getRow());
137  1 assertEquals(15, e.get(2).getSourceArea().getStartPosition().getColumn());
138  1 assertEquals(90722, e.get(2).getErrorCode());
139  1 assertTrue(e.get(2).getDescription().endsWith("Recursive import of modules is forbidden, label: " +
140    "\"LRM044\" -> \"LRM042\" -> \"LRM043\" -> \"LRM044\""));
141    }
142    }
143   
144    /**
145    * Load following dependencies:
146    * <pre>
147    * 051 -> 052 -> 053 -> 056
148    * 051 -> 052 -> 054 -> 056
149    * 051 -> 052 -> 055 -> 053 -> 056
150    * 051 -> 052 -> 055 -> 057
151    * 051 -> 053 -> 056
152    * 051 -> 054 -> 056
153    * 051 -> 055 -> 057
154    * </pre>
155    *
156    * Should be OK.
157    *
158    * @throws Exception
159    */
 
160  1 toggle public void testLoadRequiredModules_05() throws Exception {
161  1 final ModuleAddress address = new DefaultModuleAddress(
162    getFile("loadRequired/LRM051.xml"));
163  1 if (!getServices().loadRequiredModules(address)) {
164  0 fail("loading should be successful");
165    }
166    }
167   
168    /**
169    * Load following dependencies:
170    * <pre>
171    * 061 -> 062 -> 063 -> 066 -> 067
172    * 061 -> 062 -> 064 -> 066 -> 067
173    * 061 -> 062 -> 065 -> 063 -> 066 -> 067
174    * 061 -> 062 -> 065 -> 067
175    * 061 -> 063 -> 066 -> 067
176    * 061 -> 064 -> 066 -> 067
177    * 061 -> 065 -> 067
178    * </pre>
179    *
180    * Should be OK.
181    *
182    * @throws Exception
183    */
 
184  1 toggle public void testLoadRequiredModules_06() throws Exception {
185    // setTraceOn();
186  1 final ModuleAddress address = new DefaultModuleAddress(getFile("loadRequired/LRM061.xml"));
187  1 if (!getServices().loadRequiredModules(address)) {
188  0 System.out.println(getServices().getKernelQedeqBo(address).getErrors().toString());
189  0 fail("loading should be successful");
190    }
191    }
192   
193    /**
194    * Load following dependencies:
195    * <pre>
196    * 071 -> 072 -> 073 -> 076 -> 077
197    * 071 -> 072 -> 073 -> 076 -> 071 c
198    * 071 -> 072 -> 073 -> 075 -> 073 c
199    * 071 -> 072 -> 073 -> 075 -> 077
200    * 071 -> 072 -> 074 -> 076 -> 077
201    * 071 -> 072 -> 074 -> 076 -> 071 c
202    * 071 -> 072 -> 075 -> 073 -> 076 -> 077
203    * 071 -> 072 -> 075 -> 073 -> 075 c
204    * 071 -> 072 -> 075 -> 077
205    * 071 -> 073 -> 076 -> 077
206    * 071 -> 073 -> 076 -> 071 c
207    * 071 -> 073 -> 075 -> 073 c
208    * 071 -> 074 -> 076 -> 077
209    * 071 -> 074 -> 076 -> 071 c
210    * 071 -> 075 -> 073 -> 076 -> 077
211    * 071 -> 075 -> 073 -> 076 -> 071 c
212    * 071 -> 075 -> 073 -> 075 - >073 c
213    * </pre>
214    *
215    * Should be not OK.
216    *
217    * @throws Exception
218    */
 
219  1 toggle public void testLoadRequiredModules_07() throws Exception {
220  1 final ModuleAddress address = new DefaultModuleAddress(
221    getFile("loadRequired/LRM071.xml"));
222  1 if (getServices().loadRequiredModules(address)) {
223  0 fail("see test method description");
224    } else {
225  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
226    // e.printStackTrace(System.out);
227  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
228  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
229  1 assertEquals(90722, e.get(0).getErrorCode());
230  1 assertTrue(e.get(0).getDescription().endsWith("Recursive import of modules is forbidden, label: "
231    + "\"LRM072\" -> \"LRM073\" -> \"LRM076\" -> \"LRM071\""));
232  1 assertEquals(4, e.size());
233  1 assertEquals(38, e.get(1).getSourceArea().getStartPosition().getRow());
234  1 assertEquals(15, e.get(1).getSourceArea().getStartPosition().getColumn());
235  1 assertEquals(90722, e.get(1).getErrorCode());
236  1 assertTrue(e.get(1).getDescription().endsWith("Recursive import of modules is forbidden, label: "
237    + "\"LRM073\" -> \"LRM076\" -> \"LRM071\""));
238  1 assertEquals(45, e.get(2).getSourceArea().getStartPosition().getRow());
239  1 assertEquals(15, e.get(2).getSourceArea().getStartPosition().getColumn());
240  1 assertEquals(90722, e.get(2).getErrorCode());
241  1 assertTrue(e.get(2).getDescription().endsWith("Recursive import of modules is forbidden, label: "
242    + "\"LRM074\" -> \"LRM076\" -> \"LRM071\""));
243  1 assertEquals(52, e.get(3).getSourceArea().getStartPosition().getRow());
244  1 assertEquals(15, e.get(3).getSourceArea().getStartPosition().getColumn());
245  1 assertEquals(90722, e.get(3).getErrorCode());
246  1 assertTrue(e.get(3).getDescription().endsWith("Recursive import of modules is forbidden, label: "
247    + "\"LRM075\" -> \"LRM073\" -> \"LRM076\" -> \"LRM071\""));
248    }
249    }
250   
251    /**
252    * Load following dependencies:
253    * <pre>
254    * 081 -> 082 -> 083 -> 084 -> 085 -> 086 -> 087 -> 089
255    * </pre>
256    *
257    * Should be OK.
258    *
259    * @throws Exception
260    */
 
261  1 toggle public void testLoadRequiredModules_08() throws Exception {
262  1 final ModuleAddress address = new DefaultModuleAddress(getFile("loadRequired/LRM081.xml"));
263  1 if (!getServices().loadRequiredModules(address)) {
264  0 fail("loading should be successful");
265    }
266  1 assertEquals(0, getServices().getQedeqBo(address).getErrors().size());
267  1 assertTrue(!getServices().getQedeqBo(address).hasBasicFailures());
268    }
269   
270    /**
271    * Load following dependencies:
272    * <pre>
273    * 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 099 -> 091
274    * </pre>
275    *
276    * Should be not OK.
277    *
278    * @throws Exception
279    */
 
280  1 toggle public void testLoadRequiredModules_09() throws Exception {
281  1 final ModuleAddress address = new DefaultModuleAddress(
282    getFile("loadRequired/LRM091.xml"));
283  1 if (getServices().loadRequiredModules(address)) {
284  0 fail("091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 098 -> 099 -> 091 cycle\n");
285    } else {
286  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
287  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
288  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
289  1 assertEquals(90722, e.get(0).getErrorCode());
290  1 assertEquals(1, e.size());
291    // System.out.println(e.get(0).getDescription());
292  1 assertTrue(e.get(0).getDescription().endsWith("Recursive import of modules is forbidden, label: "
293    + "\"LRM092\" -> \"LRM093\" -> \"LRM094\" -> \"LRM095\" -> \"LRM096\" -> "
294    + "\"LRM097\" -> \"LRM098\" -> \"LRM099\" -> \"LRM091\"" ));
295    }
296    }
297   
298    /**
299    * Load following dependencies:
300    * <pre>
301    * 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 099 -> 091
302    * </pre>
303    *
304    * Should be not OK.
305    *
306    * @throws Exception
307    */
 
308  1 toggle public void testLoadRequiredModules_09b() throws Exception {
309  1 final ModuleAddress address1 = new DefaultModuleAddress(
310    getFile("loadRequired/LRM091.xml"));
311  1 final DefaultInternalKernelServices services = getServices();
312  1 final Thread thread1 = new Thread() {
 
313  1 toggle public void run() {
314    // System.out.println("1 running");
315  1 services.loadRequiredModules(address1);
316    // SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
317    // System.out.println("1 " + e1);
318    // System.out.println("1 stopped");
319    }
320    };
321  1 thread1.setDaemon(true);
322   
323  1 final ModuleAddress address2 = new DefaultModuleAddress(
324    getFile("loadRequired/LRM096.xml"));
325  1 final Thread thread2 = new Thread() {
 
326  1 toggle public void run() {
327    // System.out.println("2 running");
328  1 services.loadRequiredModules(address2);
329    // SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
330    // System.out.println("2 " + e2);
331    // System.out.println("2 stopped");
332    }
333    };
334  1 thread2.setDaemon(true);
335   
336  1 thread1.start();
337  1 thread2.start();
338   
339  1 thread1.join();
340  1 thread2.join();
341   
342  1 SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
343  1 SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
344   
345  1 assertEquals(1, e1.size());
346  1 assertEquals(1, e2.size());
347    // 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 098 -> 099 -> 091 cycle\n");
348    }
349   
350    /**
351    * Load following dependencies:
352    * <pre>
353    * 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 099 -> 091
354    * </pre>
355    *
356    * Should be not OK.
357    *
358    * @throws Exception
359    */
 
360  1 toggle public void testLoadRequiredModules_09c() throws Exception {
361  1 final ModuleAddress address1 = new DefaultModuleAddress(
362    getFile("loadRequired/LRM091.xml"));
363  1 final DefaultInternalKernelServices services = getServices();
364  1 final Thread thread1 = new Thread() {
 
365  1 toggle public void run() {
366    // System.out.println("1 running");
367  1 services.loadRequiredModules(address1);
368    // SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
369    // System.out.println("1 " + e1);
370    // System.out.println("1 stopped");
371    }
372    };
373  1 thread1.setDaemon(true);
374   
375  1 final ModuleAddress address2 = new DefaultModuleAddress(
376    getFile("loadRequired/LRM096.xml"));
377  1 final Thread thread2 = new Thread() {
 
378  1 toggle public void run() {
379    // System.out.println("2 running");
380  1 services.loadRequiredModules(address2);
381    // SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
382    // System.out.println("2 " + e2);
383    // System.out.println("2 stopped");
384    }
385    };
386  1 thread2.setDaemon(true);
387   
388  1 final ModuleAddress address3 = new DefaultModuleAddress(
389    getFile("loadRequired/LRM095.xml"));
390  1 final Thread thread3 = new Thread() {
 
391  1 toggle public void run() {
392    // System.out.println("3 running");
393  1 services.loadRequiredModules(address3);
394    // SourceFileExceptionList e3 = services.getQedeqBo(address3).getErrors();
395    // System.out.println("3 " + e3);
396    // System.out.println("3 stopped");
397    }
398    };
399  1 thread3.setDaemon(true);
400   
401  1 thread1.start();
402  1 thread2.start();
403  1 thread3.start();
404   
405  1 thread1.join();
406  1 thread2.join();
407  1 thread3.join();
408    // System.out.println("******************************************");
409  1 SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
410  1 SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
411  1 SourceFileExceptionList e3 = services.getQedeqBo(address3).getErrors();
412   
413  1 assertEquals(1, e1.size());
414    // System.out.println("e2: " + e2);
415    // System.out.println("e2.size(): " + e2.size());
416  1 assertEquals(1, e2.size());
417    // System.out.println("e3: " + e3);
418    // System.out.println("e3.size(): " + e3.size());
419  1 assertEquals(1, e3.size());
420    // 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 098 -> 099 -> 091 cycle\n");
421    }
422   
423    /**
424    * Load following dependencies:
425    * <pre>
426    * 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 099 -> 091
427    * </pre>
428    *
429    * Should be not OK.
430    *
431    * @throws Exception
432    */
 
433  1 toggle public void testLoadRequiredModules_09d() throws Exception {
434  1 final ModuleAddress address1 = new DefaultModuleAddress(
435    getFile("loadRequired/LRM091.xml"));
436  1 final DefaultInternalKernelServices services = getServices();
437  1 final Thread thread1 = new Thread() {
 
438  1 toggle public void run() {
439    // System.out.println("1 running");
440  1 testFind(address1);
441    // SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
442    // System.out.println("1 " + e1);
443    // System.out.println("1 stopped");
444    }
445    };
446  1 thread1.setDaemon(true);
447   
448  1 final ModuleAddress address2 = new DefaultModuleAddress(
449    getFile("loadRequired/LRM096.xml"));
450  1 final Thread thread2 = new Thread() {
 
451  1 toggle public void run() {
452    // System.out.println("2 running");
453  1 testFind(address2);
454    // SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
455    // System.out.println("2 " + e2);
456    // System.out.println("2 stopped");
457    }
458    };
459  1 thread2.setDaemon(true);
460   
461  1 final ModuleAddress address3 = new DefaultModuleAddress(
462    getFile("loadRequired/LRM095.xml"));
463  1 final Thread thread3 = new Thread() {
 
464  1 toggle public void run() {
465    // System.out.println("3 running");
466  1 testFind(address3);
467    // SourceFileExceptionList e3 = services.getQedeqBo(address3).getErrors();
468    // System.out.println("3 " + e3);
469    // System.out.println("3 stopped");
470    }
471    };
472  1 thread3.setDaemon(true);
473   
474  1 thread1.start();
475  1 thread2.start();
476  1 thread3.start();
477   
478  1 thread1.join();
479  1 thread2.join();
480  1 thread3.join();
481    // System.out.println("******************************************");
482  1 SourceFileExceptionList e1 = services.getQedeqBo(address1).getErrors();
483  1 SourceFileExceptionList e2 = services.getQedeqBo(address2).getErrors();
484  1 SourceFileExceptionList e3 = services.getQedeqBo(address3).getErrors();
485   
486  1 assertEquals(1, e1.size());
487  1 assertEquals(1, e2.size());
488  1 assertEquals(1, e3.size());
489    // 091 -> 092 -> 093 -> 094 -> 095 -> 096 -> 097 -> 098 -> 099 -> 091 cycle\n");
490    }
491   
492    /**
493    * Find a proof.
494    *
495    * @throws Exception
496    */
 
497  3 toggle public void testFind(final ModuleAddress address) {
498  3 getServices().executePlugin(SimpleProofFinderPlugin.class.getName(), address, null);
499    }
500   
501   
502    /**
503    * Load following dependencies:
504    * <pre>
505    * 101 -> 102
506    * 101 -> notThere
507    * 101 -> 103
508    * 101 -> alsoNotThere
509    * 101 -> 104
510    * </pre>
511    *
512    * Should be not OK.
513    *
514    * @throws Exception
515    */
 
516  1 toggle public void testLoadRequiredModules_10() throws Exception {
517  1 final ModuleAddress address = new DefaultModuleAddress(
518    getFile("loadRequired/LRM101.xml"));
519  1 if (getServices().loadRequiredModules(address)) {
520  0 fail("two imports don't exist: \"notThere\" and \"alsoNotThere\"\n");
521    } else {
522  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
523  1 assertEquals(38, e.get(0).getSourceArea().getStartPosition().getRow());
524  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
525  1 assertEquals(90710, e.get(0).getErrorCode());
526  1 assertTrue(0 <= e.get(0).getDescription().indexOf(
527    "import of module with label \"notThere\" failed: Loading module from local file "
528    + "failed.; file not readable: "));
529  1 assertEquals(2, e.size());
530  1 assertEquals(90710, e.get(1).getErrorCode());
531    }
532    }
533   
534    /**
535    * Load following dependencies:
536    * <pre>
537    * 111 -> 112
538    * 112 -> 113 and 113 doesn't exist
539    * </pre>
540    *
541    * Should be not OK.
542    *
543    * @throws Exception
544    */
 
545  1 toggle public void testLoadRequiredModules_11() throws Exception {
546  1 final ModuleAddress address = new DefaultModuleAddress(getFile("loadRequired/LRM111.xml"));
547  1 if (getServices().loadRequiredModules(address)) {
548  0 fail("loading should be not be successful");
549    }
550  1 SourceFileExceptionList e = getServices().getQedeqBo(address).getErrors();
551  1 assertEquals(1, e.size());
552  1 assertEquals(90723, e.get(0).getErrorCode());
553    // System.out.println(e);
554  1 assertTrue(0 <= e.get(0).getDescription().indexOf("Import of module failed, label: \"LRM112\""));
555  1 assertEquals(31, e.get(0).getSourceArea().getStartPosition().getRow());
556  1 assertEquals(15, e.get(0).getSourceArea().getStartPosition().getColumn());
557    }
558   
559    }