Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
34   131   10   8.5
10   68   0.29   4
4     2.5  
1    
 
  GenerateXmlTest       Line # 36 34 10 93.8% 0.9375
 
  (1)
 
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.xml.dao;
17   
18    import java.io.File;
19    import java.io.FileFilter;
20    import java.io.IOException;
21    import java.util.Iterator;
22    import java.util.List;
23   
24    import org.qedeq.base.io.IoUtility;
25    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
26    import org.qedeq.kernel.se.common.SourceFileExceptionList;
27    import org.qedeq.kernel.se.visitor.InterruptException;
28    import org.qedeq.kernel.xml.test.XmlNormalizer;
29    import org.xml.sax.SAXException;
30   
31    /**
32    * Test generating XML files for all known samples.
33    *
34    * @author Michael Meyling
35    */
 
36    public final class GenerateXmlTest extends QedeqBoTestCase {
37   
38    /**
39    * Start main process.
40    *
41    * @throws Exception
42    */
 
43  1 toggle public void testGeneration() throws Exception {
44  1 File docDir = new File("../QedeqDoc");
45  1 File inDir2 = new File("../QedeqKernelBoTest/data");
46  1 File genDir = new File("../../../qedeq_gen");
47    // test if we are in the normal development environment, where a project with name
48    // "../QedeqDoc" exists, otherwise we assume to run within the build process
49  1 if (!docDir.exists()) {
50  1 docDir = new File(getIndir(), "doc");
51  1 genDir = new File(getOutdir(), "doc");
52  1 inDir2 = getIndir();
53  1 if (!docDir.exists()) {
54  0 throw new IOException("unknown source directory for QEDEQ modules");
55    }
56    }
57   
58    // compare directly
59  1 generate(getIndir(), "qedeq_set_theory_compare.xml", genDir, false);
60  1 generate(getIndir(), "qedeq_basic_concept_compare.xml", genDir, false);
61   
62  1 final FileFilter filter = new FileFilter() {
 
63  241 toggle public boolean accept(File pathname) {
64  241 return pathname.isDirectory() || pathname.getName().endsWith(".xml");
65    }
66    };
67   
68    // compare all XML documents in doc directory
69  1 final List docFiles = IoUtility.listFilesRecursively(docDir, filter);
70  1 final Iterator i = docFiles.iterator();
71  11 while (i.hasNext()) {
72  10 generate((File) i.next(), genDir, true);
73    }
74   
75    // compare all XML documents in data directory
76  1 final List dataFiles = IoUtility.listFilesRecursively(inDir2, filter);
77  1 final Iterator j = dataFiles.iterator();
78  132 while (j.hasNext()) {
79  131 try {
80  131 generate((File) j.next(), genDir, true);
81    } catch (SourceFileExceptionList e) {
82    // ignore
83    }
84    }
85   
86    // generate(inDir2, "proof/proof_001.xml", genDir, true);
87    }
88   
89    /**
90    * Call the generation of one XML file and copy XML source to same destination directory.
91    *
92    * @param dir Start directory.
93    * @param xml Relative path to XML file. Must not be <code>null</code>.
94    * @param destinationDirectory Directory path for LaTeX file. Must not be <code>null</code>.
95    * @param normalize Normalize before comparing?
96    * @throws IOException File IO failed.
97    */
 
98  2 toggle private void generate(final File dir, final String xml,
99    final File destinationDirectory, final boolean normalize)
100    throws IOException, SourceFileExceptionList, SAXException, InterruptException {
101  2 generate(new File(dir, xml), destinationDirectory, normalize);
102    }
103   
104    /**
105    * Call the generation of one LaTeX file and copy XML source to same destination directory.
106    *
107    * @param xmlFile XML file. Must not be <code>null</code>.
108    * @param destinationDirectory Directory path for LaTeX file. Must not be <code>null</code>.
109    * @param normalize Normalize before comparing?
110    * @throws IOException File IO failed.
111    */
 
112  143 toggle private void generate(final File xmlFile, final File destinationDirectory, final boolean normalize)
113    throws IOException, SourceFileExceptionList, SAXException, InterruptException {
114  143 final File destination = new File(destinationDirectory, xmlFile.getName() + "_").getAbsoluteFile();
115  143 System.out.println("generation of " + xmlFile + " to " + destination);
116  143 Xml2Xml.generate(getServices(), getInternalServices(), xmlFile, destination);
117  132 if (!normalize) {
118  2 assertEquals(true, IoUtility.compareTextFiles(xmlFile, destination, "UTF-8"));
119    // assertEquals(IoUtility.loadFile(xmlFile.getAbsolutePath(), "UTF-8"),
120    // IoUtility.loadFile(destination.getAbsolutePath(), "UTF-8"));
121    } else {
122  130 final File xmlFile2 = new File(destinationDirectory, xmlFile.getName() + "2_").getAbsoluteFile();
123  130 XmlNormalizer.normalize(xmlFile, xmlFile2);
124  130 final File destination2 = new File(destinationDirectory, xmlFile.getName() + "3_").getAbsoluteFile();
125  130 XmlNormalizer.normalize(destination, destination2);
126  130 System.out.println("comparing " + xmlFile2 + " with " + destination2);
127  130 assertEquals(true, IoUtility.compareTextFiles(xmlFile2, destination2, "UTF-8"));
128    }
129    }
130   
131    }