Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
100   249   22   6.67
4   194   0.22   15
15     1.47  
1    
 
  FormulaCheckerContextTest       Line # 64 100 22 95% 0.94957983
 
  (12)
 
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.logic.wf;
17   
18    import java.io.File;
19    import java.io.IOException;
20    import java.util.HashMap;
21    import java.util.Map;
22   
23    import javax.xml.parsers.ParserConfigurationException;
24   
25    import org.qedeq.base.io.Parameters;
26    import org.qedeq.base.io.UrlUtility;
27    import org.qedeq.base.trace.Trace;
28    import org.qedeq.base.utility.YodaUtility;
29    import org.qedeq.kernel.bo.common.Element2Utf8;
30    import org.qedeq.kernel.bo.logic.common.FormulaChecker;
31    import org.qedeq.kernel.bo.logic.common.LogicalCheckException;
32    import org.qedeq.kernel.bo.module.InternalModuleServiceCall;
33    import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
34    import org.qedeq.kernel.bo.module.KernelQedeqBo;
35    import org.qedeq.kernel.bo.module.ModuleLabels;
36    import org.qedeq.kernel.bo.module.QedeqFileDao;
37    import org.qedeq.kernel.bo.service.basis.ModuleLabelsCreator;
38    import org.qedeq.kernel.bo.service.basis.QedeqVoBuilder;
39    import org.qedeq.kernel.bo.service.internal.DefaultKernelQedeqBo;
40    import org.qedeq.kernel.bo.service.internal.Element2LatexImpl;
41    import org.qedeq.kernel.bo.service.internal.Element2Utf8Impl;
42    import org.qedeq.kernel.bo.service.logic.WellFormedCheckerExecutor;
43    import org.qedeq.kernel.bo.service.logic.WellFormedCheckerPlugin;
44    import org.qedeq.kernel.bo.test.DummyPlugin;
45    import org.qedeq.kernel.bo.test.KernelFacade;
46    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
47    import org.qedeq.kernel.se.common.ModuleAddress;
48    import org.qedeq.kernel.se.common.ModuleDataException;
49    import org.qedeq.kernel.se.common.SourceFileException;
50    import org.qedeq.kernel.se.common.SourceFileExceptionList;
51    import org.qedeq.kernel.se.dto.module.QedeqVo;
52    import org.qedeq.kernel.se.visitor.InterruptException;
53    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
54    import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
55    import org.qedeq.kernel.xml.handler.module.QedeqHandler;
56    import org.qedeq.kernel.xml.parser.SaxParser;
57    import org.xml.sax.SAXException;
58   
59    /**
60    * Test logic tests for QEDEQ modules.
61    *
62    * @author Michael Meyling
63    */
 
64    public final class FormulaCheckerContextTest extends QedeqBoTestCase {
65   
66    /** This class. */
67    private static final Class CLASS = FormulaChecker.class;
68    private InternalModuleServiceCall call;
69   
70   
 
71  12 toggle protected void tearDown() throws Exception {
72  12 endServiceCall(call);
73  12 super.tearDown();
74    }
75   
 
76  1 toggle public void testNegative00() throws Exception {
77  1 try {
78  1 check(getFile("qedeq_error_sample_00.xml"));
79  0 fail("SourceFileExceptionList expected");
80    } catch (SourceFileExceptionList ex) {
81  1 Trace.trace(CLASS, this, "testNegative00", ex);
82  1 assertEquals(1, ex.size());
83  1 final SourceFileException check = ex.get(0);
84    // check.printStackTrace();
85  1 assertEquals(9001, check.getErrorCode());
86  1 assertEquals(36, check.getSourceArea().getStartPosition().getRow());
87  1 assertEquals(1, check.getSourceArea().getStartPosition().getColumn());
88  1 assertEquals(36, check.getSourceArea().getEndPosition().getRow());
89  1 assertEquals(20, check.getSourceArea().getEndPosition().getColumn());
90    }
91    }
92   
 
93  1 toggle public void testNegative01() throws Exception {
94  1 try {
95  1 check(getFile("qedeq_error_sample_01.xml"));
96  0 fail("SourceFileExceptionList expected");
97    } catch (SourceFileExceptionList ex) {
98  1 Trace.trace(CLASS, this, "testNegative01", ex);
99  1 assertEquals(1, ex.size());
100  1 final SourceFileException check = ex.get(0);
101  1 assertEquals(9001, check.getErrorCode());
102  1 assertEquals(39, check.getSourceArea().getStartPosition().getRow());
103  1 assertEquals(1, check.getSourceArea().getStartPosition().getColumn());
104  1 assertEquals(39, check.getSourceArea().getEndPosition().getRow());
105  1 assertEquals(35, check.getSourceArea().getEndPosition().getColumn());
106    }
107    }
108   
 
109  1 toggle public void testNegative02() throws Exception {
110  1 try {
111  1 check(getFile("qedeq_error_sample_02.xml"));
112  0 fail("SourceFileExceptionList expected");
113    } catch (SourceFileExceptionList sfl) {
114  1 Trace.trace(CLASS, this, "testNegative02", sfl);
115  1 final Exception e = (Exception) sfl.get(0).getCause();
116  1 Trace.param(CLASS, this, "testNegative02", "name", e.getClass().getName());
117  1 assertTrue(e instanceof LogicalCheckException);
118  1 final LogicalCheckException check = (LogicalCheckException) e;
119  1 assertEquals(30550, check.getErrorCode());
120  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1).getList()", check.getContext().getLocationWithinModule());
121  1 assertNull(check.getReferenceContext());
122    }
123    }
124   
 
125  1 toggle public void testNegative03() throws Exception {
126  1 try {
127  1 check(getFile("qedeq_error_sample_03.xml"));
128  0 fail("SourceFileExceptionList expected");
129    } catch (SourceFileExceptionList sfl) {
130  1 Trace.trace(CLASS, this, "testNegative03", sfl);
131  1 final Exception e = (Exception) sfl.get(0).getCause();
132  1 assertTrue(e instanceof LogicalCheckException);
133  1 final LogicalCheckException check = (LogicalCheckException) e;
134  1 assertEquals(30770, check.getErrorCode());
135  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule());
136  1 assertNull(check.getReferenceContext());
137    }
138    }
139   
 
140  1 toggle public void testNegative04() throws Exception {
141  1 try {
142  1 checkViaKernel(getFile("qedeq_error_sample_04.xml"));
143  0 fail("SourceFileExceptionList expected");
144    } catch (SourceFileExceptionList sfl) {
145  1 Trace.trace(CLASS, this, "testNegative04", sfl);
146  1 final Exception e = (Exception) sfl.get(0).getCause();
147  1 assertTrue(e instanceof LogicalCheckException);
148  1 final LogicalCheckException check = (LogicalCheckException) e;
149  1 assertEquals(30780, check.getErrorCode());
150  1 assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule());
151  1 assertNull(check.getReferenceContext());
152    }
153    }
154   
 
155  1 toggle public void testPositive01() throws Exception {
156  1 checkViaKernel(getDocFile("math/qedeq_logic_v1.xml"));
157    }
158   
 
159  1 toggle public void testPositive02() throws Exception {
160  1 checkViaKernel(getDocFile("sample/qedeq_sample1.xml"));
161    }
162   
 
163  1 toggle public void testPositive03() throws Exception {
164  1 checkViaKernel(getDocFile("sample/qedeq_sample2.xml"));
165    }
166   
 
167  1 toggle public void testPositive03b() throws Exception {
168  1 checkViaKernel(getDocFile("sample/qedeq_sample3.xml"));
169    }
170   
 
171  1 toggle public void testPositive04() throws Exception {
172  1 checkViaKernel(getDocFile("math/qedeq_set_theory_v1.xml"));
173    }
174   
 
175  1 toggle public void testPositive05() throws Exception {
176  1 checkViaKernel(getDocFile("project/qedeq_basic_concept.xml"));
177    }
178   
 
179  1 toggle public void testPositive06() throws Exception {
180  1 checkViaKernel(getDocFile("project/qedeq_logic_language.xml"));
181    }
182   
183    /**
184    * Check logic of QEDEQ module given as XML file.
185    *
186    * @param xmlFile Module file to check.
187    */
 
188  4 toggle public void check(final File xmlFile) throws IOException,
189    ParserConfigurationException, SAXException, ModuleDataException,
190    SourceFileExceptionList, NoSuchFieldException {
191  4 final ModuleAddress context = getServices().getModuleAddress(
192    UrlUtility.toUrl(xmlFile.getAbsoluteFile()));
193  4 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
194  4 QedeqHandler simple = new QedeqHandler(handler);
195  4 handler.setBasisDocumentHandler(simple);
196  4 SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler);
197  4 parser.parse(xmlFile, xmlFile.getPath());
198  2 final QedeqVo qedeq = (QedeqVo) simple.getQedeq();
199  2 final QedeqFileDao loader = new XmlQedeqFileDao();
200  2 loader.setServices(getInternalServices());
201  2 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
202    .getKernelContext().getQedeqBo(context);
203  2 prop.setQedeqFileDao(loader);
204  2 YodaUtility.setFieldContent(prop, "qedeq", qedeq);
205  2 final ModuleLabelsCreator creator = new ModuleLabelsCreator(DummyPlugin.getInstance(),
206    prop);
207  2 call = createServiceCall("check", prop);
208  2 final ModuleLabels labels = new ModuleLabels();
209  2 final Element2LatexImpl converter = new Element2LatexImpl(labels);
210  2 final Element2Utf8 textConverter = new Element2Utf8Impl(converter);
211  2 creator.createLabels(call.getInternalServiceProcess(), labels);
212  2 prop.setLoaded(QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq),
213    labels, converter, textConverter);
214  2 prop.setLoadedImports(new KernelModuleReferenceList());
215  2 prop.setLoadedRequiredModules();
216  2 final WellFormedCheckerPlugin plugin = new WellFormedCheckerPlugin();
217  2 final Map parameters = new HashMap();
218  2 parameters.put("checkerFactory", TestFormulaCheckerFactoryImpl.class.getName());
219  2 final WellFormedCheckerExecutor checker = (WellFormedCheckerExecutor) plugin.createExecutor(
220    prop, new Parameters(parameters));
221  2 checker.executePlugin(call, null);
222  2 if (prop.hasErrors()) {
223  2 throw prop.getErrors();
224    }
225    }
226   
227    /**
228    * Check logic of QEDEQ module given as XML file.
229    *
230    * @param xmlFile Module file to check.
231    */
 
232  8 toggle public void checkViaKernel(final File xmlFile) throws SourceFileExceptionList, IOException, InterruptException {
233  8 final ModuleAddress address = getServices().getModuleAddress(
234    UrlUtility.toUrl(xmlFile.getAbsoluteFile()));
235  8 KernelQedeqBo qedeqBo= (KernelQedeqBo) getServices().loadModule(address);
236  8 final WellFormedCheckerPlugin plugin = new WellFormedCheckerPlugin();
237  8 final Map parameters = new HashMap();
238  8 parameters.put("checkerFactory", TestFormulaCheckerFactoryImpl.class.getName());
239  8 final WellFormedCheckerExecutor checker = (WellFormedCheckerExecutor) plugin.createExecutor(
240    qedeqBo, new Parameters(parameters));
241  8 call = createServiceCall("check", qedeqBo);
242  8 checker.executePlugin(call, null);
243  8 if (qedeqBo.hasErrors()) {
244    // qedeqBo.getErrors().get(0).printStackTrace(System.out);
245  1 throw qedeqBo.getErrors();
246    }
247    }
248   
249    }