Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
35   160   16   4.38
14   77   0.46   8
8     2  
1    
 
  QedeqTestCase       Line # 34 35 16 63.2% 0.6315789
 
  (242)
 
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.base.test;
17   
18    import java.io.File;
19    import java.net.URL;
20   
21    import junit.framework.TestCase;
22   
23    import org.apache.log4j.Level;
24    import org.apache.log4j.Logger;
25    import org.apache.log4j.helpers.Loader;
26    import org.apache.log4j.xml.DOMConfigurator;
27    import org.qedeq.base.io.UrlUtility;
28   
29    /**
30    * Basis class for all tests.
31    *
32    * @author Michael Meyling
33    */
 
34    public abstract class QedeqTestCase extends TestCase {
35   
 
36  168 toggle static {
37    // init Log4J watchdog
38  168 try {
39  168 final File logConfig = new File(System.getProperty("qedeq.test.log4j",
40    "../../../qedeq_gen/config/log4j.xml"));
41  168 URL url = null;
42  168 if (logConfig.canRead()) {
43  0 url = UrlUtility.toUrl(logConfig);
44    }
45  168 if (url == null) {
46  168 url = Loader.getResource("config/log4j.xml");
47    }
48  168 if (url == null) {
49    // try development environment
50  0 url = UrlUtility.toUrl(new File("../QedeqBuild/resources/config/log4j.xml"));
51    }
52    // System.out.println(url);
53  168 if (url != null) {
54    // set properties and watch file every 15 seconds
55  168 DOMConfigurator.configureAndWatch(url.getPath(), 15000);
56    } else {
57  0 Logger.getRootLogger().setLevel(Level.ERROR);
58    }
59    } catch (Exception e) {
60    // we ignore this
61    }
62    }
63   
64    /** Destination directory for generated output files. */
65    private final File outdir;
66   
67    /** Source directory for input files. */
68    private final File indir;
69   
70    /** Should the methods of this class execute fast? */
71    private final boolean fast;
72   
73    /**
74    * Constructor.
75    *
76    * @param name Test case name.
77    */
 
78  292 toggle public QedeqTestCase(final String name) {
79  292 super(name);
80  292 outdir = new File(System.getProperty("qedeq.test.outdir", "../../../qedeq_gen"));
81  292 indir = new File(System.getProperty("qedeq.test.indir", "data"));
82  292 fast = "true".equalsIgnoreCase(System.getProperty("qedeq.test.fast", "true"));
83    }
84   
85    /**
86    * Constructor.
87    */
 
88  1591 toggle public QedeqTestCase() {
89  1591 super();
90  1591 outdir = new File(System.getProperty("qedeq.test.outdir", "../../../qedeq_gen"));
91  1591 indir = new File(System.getProperty("qedeq.test.indir", "data"));
92  1591 fast = "true".equalsIgnoreCase(System.getProperty("qedeq.test.fast", "true"));
93    }
94   
95    /**
96    * Get output directory for test output. Might be set initially by setting the system property
97    * <code>qedeq.test.outdir</code>.
98    *
99    * @return Directory for test output.
100    */
 
101  1078 toggle public File getOutdir() {
102  1078 return outdir;
103    }
104   
105    /**
106    * Get input directory for test input data. Might be set initially by setting the system
107    * property <code>qedeq.test.indir</code>.
108    *
109    * @return Directory for test input.
110    */
 
111  747 toggle public File getIndir() {
112  747 return indir;
113    }
114   
115    /**
116    * Get test input data file. Get file relative to {@link #getIndir()}.
117    *
118    * @param fileName Relative file path.
119    * @return Test data file.
120    */
 
121  622 toggle public File getFile(final String fileName) {
122  622 return new File(getIndir(), fileName);
123    }
124   
125    /**
126    * Should the test case be finished fast?
127    *
128    * @return Should the test case be finished fast?
129    */
 
130  4 toggle private boolean fast() {
131  4 return fast;
132    }
133   
134    /**
135    * Should a slow test method be executed?. Also prints name of current method
136    * to System.out.
137    * The test case should ask this method at the begin of long running test methods.
138    *
139    * @return Should even slow test methods be executed?
140    */
 
141  4 toggle public boolean slow() {
142  4 if (fast()) {
143  0 final StackTraceElement[] st = new Exception().getStackTrace();
144  0 final StackTraceElement e = st[1];
145    // find test method
146  0 String name = e.getMethodName();
147  0 for (int i = 1; i < st.length; i++) {
148  0 if (st[i].getMethodName().startsWith("test")) {
149  0 name = st[i].getMethodName();
150  0 break;
151    }
152    }
153  0 System.out.println("skipping slow test "
154    + e.getClassName() + "." + name);
155  0 return false;
156    }
157  4 return true;
158    }
159   
160    }