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