Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
78   183   13   11.14
2   142   0.17   7
7     1.86  
1    
 
  QedeqBoFormalLogicCheckerDirectTest       Line # 54 78 13 93.1% 0.9310345
 
  (5)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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   
16    package org.qedeq.kernel.bo.service.logic;
17   
18    import java.io.File;
19    import java.io.IOException;
20   
21    import javax.xml.parsers.ParserConfigurationException;
22   
23    import org.qedeq.base.io.Parameters;
24    import org.qedeq.base.io.UrlUtility;
25    import org.qedeq.base.trace.Trace;
26    import org.qedeq.base.utility.YodaUtility;
27    import org.qedeq.kernel.bo.logic.common.FormulaChecker;
28    import org.qedeq.kernel.bo.logic.common.LogicalCheckException;
29    import org.qedeq.kernel.bo.module.InternalServiceCall;
30    import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
31    import org.qedeq.kernel.bo.module.QedeqFileDao;
32    import org.qedeq.kernel.bo.service.control.DefaultKernelQedeqBo;
33    import org.qedeq.kernel.bo.service.control.ModuleLabelsCreator;
34    import org.qedeq.kernel.bo.service.control.QedeqVoBuilder;
35    import org.qedeq.kernel.bo.test.DummyPlugin;
36    import org.qedeq.kernel.bo.test.KernelFacade;
37    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
38    import org.qedeq.kernel.se.common.ModuleAddress;
39    import org.qedeq.kernel.se.common.ModuleDataException;
40    import org.qedeq.kernel.se.common.SourceFileException;
41    import org.qedeq.kernel.se.common.SourceFileExceptionList;
42    import org.qedeq.kernel.se.dto.module.QedeqVo;
43    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
44    import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
45    import org.qedeq.kernel.xml.handler.module.QedeqHandler;
46    import org.qedeq.kernel.xml.parser.SaxParser;
47    import org.xml.sax.SAXException;
48   
49    /**
50    * Test logic tests for QEDEQ modules.
51    *
52    * @author Michael Meyling
53    */
 
54    public final class QedeqBoFormalLogicCheckerDirectTest extends QedeqBoTestCase {
55   
56    /** This class. */
57    private static final Class CLASS = FormulaChecker.class;
58    private InternalServiceCall call;
59   
60   
 
61  5 toggle protected void tearDown() throws Exception {
62  5 endServiceCall(call);
63  5 super.tearDown();
64    }
65   
 
66  1 toggle public void testNegative00() throws Exception {
67  1 try {
68  1 check(getFile("qedeq_error_sample_00.xml"));
69  0 fail("SourceFileExceptionList expected");
70    } catch (SourceFileExceptionList ex) {
71  1 Trace.trace(CLASS, this, "testNegative00", ex);
72  1 assertEquals(1, ex.size());
73  1 final SourceFileException check = ex.get(0);
74    // check.printStackTrace();
75  1 assertEquals(9001, check.getErrorCode());
76  1 assertEquals(36, check.getSourceArea().getStartPosition().getRow());
77  1 assertEquals(1, check.getSourceArea().getStartPosition().getColumn());
78  1 assertEquals(36, check.getSourceArea().getEndPosition().getRow());
79  1 assertEquals(20, check.getSourceArea().getEndPosition().getColumn());
80    }
81    }
82   
 
83  1 toggle public void testNegative01() throws Exception {
84  1 try {
85  1 check(getFile("qedeq_error_sample_01.xml"));
86  0 fail("SourceFileExceptionList expected");
87    } catch (SourceFileExceptionList ex) {
88  1 Trace.trace(CLASS, this, "testNegative01", ex);
89  1 assertEquals(1, ex.size());
90  1 final SourceFileException check = ex.get(0);
91  1 assertEquals(9001, check.getErrorCode());
92  1 assertEquals(39, check.getSourceArea().getStartPosition().getRow());
93  1 assertEquals(1, check.getSourceArea().getStartPosition().getColumn());
94  1 assertEquals(39, check.getSourceArea().getEndPosition().getRow());
95  1 assertEquals(35, check.getSourceArea().getEndPosition().getColumn());
96    }
97    }
98   
 
99  1 toggle public void testNegative02() throws Exception {
100  1 try {
101  1 check(getFile("qedeq_error_sample_02.xml"));
102  0 fail("SourceFileExceptionList expected");
103    } catch (SourceFileExceptionList sfl) {
104  1 Trace.trace(CLASS, this, "testNegative02", sfl);
105  1 final Exception e = (Exception) sfl.get(0).getCause();
106  1 Trace.param(CLASS, this, "testNegative02", "name", e.getClass().getName());
107  1 assertTrue(e instanceof LogicalCheckException);
108  1 final LogicalCheckException check = (LogicalCheckException) e;
109  1 assertEquals(30550, check.getErrorCode());
110  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1).getList()", check.getContext().getLocationWithinModule());
111  1 assertNull(check.getReferenceContext());
112    }
113    }
114   
 
115  1 toggle public void testNegative03() throws Exception {
116  1 try {
117  1 check(getFile("qedeq_error_sample_03.xml"));
118  0 fail("SourceFileExceptionList expected");
119    } catch (SourceFileExceptionList sfl) {
120  1 Trace.trace(CLASS, this, "testNegative03", sfl);
121  1 final Exception e = (Exception) sfl.get(0).getCause();
122  1 assertTrue(e instanceof LogicalCheckException);
123  1 final LogicalCheckException check = (LogicalCheckException) e;
124  1 assertEquals(30770, check.getErrorCode());
125  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule());
126  1 assertNull(check.getReferenceContext());
127    }
128    }
129   
 
130  1 toggle public void testNegative04() throws Exception {
131  1 try {
132  1 check(getFile("qedeq_error_sample_04.xml"));
133  0 fail("SourceFileExceptionList expected");
134    } catch (SourceFileExceptionList sfl) {
135  1 Trace.trace(CLASS, this, "testNegative04", sfl);
136  1 final Exception e = (Exception) sfl.get(0).getCause();
137  1 assertTrue(e instanceof LogicalCheckException);
138  1 final LogicalCheckException check = (LogicalCheckException) e;
139  1 assertEquals(30780, check.getErrorCode());
140  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule());
141  1 assertNull(check.getReferenceContext());
142    }
143    }
144   
145    /**
146    * Check logic of QEDEQ module given as XML file.
147    *
148    * @param xmlFile Module file to check.
149    */
 
150  5 toggle public void check(final File xmlFile) throws IOException,
151    ParserConfigurationException, SAXException, ModuleDataException,
152    SourceFileExceptionList, NoSuchFieldException {
153  5 final ModuleAddress context = getServices().getModuleAddress(
154    UrlUtility.toUrl(xmlFile.getAbsoluteFile()));
155  5 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
156  5 QedeqHandler simple = new QedeqHandler(handler);
157  5 handler.setBasisDocumentHandler(simple);
158  5 SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler);
159  5 parser.parse(xmlFile, xmlFile.getPath());
160  3 final QedeqVo qedeq = (QedeqVo) simple.getQedeq();
161  3 final QedeqFileDao loader = new XmlQedeqFileDao();
162  3 loader.setServices(getInternalServices());
163  3 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
164    .getKernelContext().getQedeqBo(context);
165  3 prop.setQedeqFileDao(loader);
166  3 YodaUtility.setFieldContent(prop, "qedeq", qedeq);
167  3 final ModuleLabelsCreator creator = new ModuleLabelsCreator(DummyPlugin.getInstance(),
168    prop);
169  3 call = createServiceCall("check", prop);
170  3 creator.createLabels(call.getInternalServiceProcess());
171  3 prop.setLoaded(QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq),
172    creator.getLabels(), creator.getConverter(), creator.getTextConverter());
173  3 prop.setLoadedImports(new KernelModuleReferenceList());
174  3 prop.setLoadedRequiredModules();
175  3 final WellFormedCheckerPlugin plugin = new WellFormedCheckerPlugin();
176  3 final Parameters parameters = getInternalServices().getConfig().getServiceEntries(plugin);
177  3 plugin.createExecutor(prop, parameters).executePlugin(call, null);
178  3 if (prop.hasErrors()) {
179  3 throw prop.getErrors();
180    }
181    }
182   
183    }