1 2 3 package org.quilt.framework; 4 5 import java.io.File ; 6 import java.util.Enumeration ; 7 import java.util.Hashtable ; 8 import java.util.Properties ; 9 import java.util.Vector ; 10 11 import org.apache.tools.ant.Project; 12 14 import org.quilt.reports.*; 15 16 23 public class QuiltTest implements Cloneable { 24 25 26 private String name = null; 27 28 31 32 private boolean checkCoverage = false; 33 34 40 private String checkExcludes; 41 42 46 private String checkIncludes; 47 48 49 private String errorProperty; 50 51 52 private String failureProperty; 53 54 55 private boolean filtertrace = true; 56 57 58 private boolean fork = false; 59 60 61 private Vector formatters = new Vector (); 62 63 64 private boolean haltOnError = false; 65 66 67 private boolean haltOnFailure = false; 68 69 70 private String ifProperty = null; 71 72 73 private boolean mockTestRun = false; 74 75 76 private String outfile = null; 77 78 79 private Properties props = new Properties (); 80 81 85 private boolean showOutput = false; 86 87 88 private File todir = null; 89 90 91 private String unlessProperty = null; 92 93 95 public QuiltTest() { } 96 97 102 public QuiltTest(String name) { 103 this.name = name; 104 } 105 110 private long errors = (long) 0; 111 private long failures = (long) 0; 112 private long runs = (long) 0; 113 private long runTime = (long) 0; 114 115 public void setCounts (long runs, long failures, long errors) { 116 this.errors = errors; 117 this.failures = failures; 118 this.runs = runs; 119 } 120 public long errorCount () { return errors; } 121 public long failureCount() { return failures; } 122 public long runCount () { return runs; } 123 125 126 public Properties getProperties() { return props; } 127 133 134 public void setProperties (Hashtable val) { 135 Enumeration e = val.keys(); 136 props.clear(); 137 while (e.hasMoreElements() ) { 138 Object key = e.nextElement(); 139 props.put(key, val.get(key)); 140 } 141 } 142 public long getRunTime() { return runTime; } 143 public void setRunTime (long val) { runTime = val; } 144 145 149 151 public void addFormattersTo(Vector v) { 152 for (int j = 0; j < formatters.size(); j++){ 153 v.addElement(formatters.elementAt(j)); 154 } 155 } 156 157 public boolean getCheckCoverage() { return checkCoverage; } 159 public void setCheckCoverage(boolean b) { checkCoverage = b; } 160 161 public String getCheckExcludes() { return checkExcludes; } 162 public String [] getCheckExcludesArray() { 163 String [] val = null; 164 if (checkExcludes != null) { 165 val = checkExcludes.split(","); 166 } 167 return val; 168 } 169 public void setCheckExcludes(String val) { checkExcludes = val; } 170 171 public String getCheckIncludes() { return checkIncludes; } 172 public String [] getCheckIncludesArray() { 173 String [] val = null; 174 if (checkIncludes != null) { 175 val = checkIncludes.split(","); 176 } 177 return val; 178 } 179 public void setCheckIncludes(String val) { checkIncludes = val; } 180 181 public String getErrorProperty() { return errorProperty; } 182 public void setErrorProperty(String eP) { errorProperty = eP; } 183 184 public String getFailureProperty() { return failureProperty; } 185 public void setFailureProperty(String fP) { failureProperty = fP; } 186 187 public boolean getFiltertrace() { return filtertrace; } 188 public void setFiltertrace(boolean b) { filtertrace = b; } 189 190 public boolean getFork() { return fork; } 191 public void setFork(boolean b) { fork = b; } 192 193 public void addFormatter(FmtSelector elem) { 194 formatters.addElement(elem); 195 } 196 public Vector getFormatters () { return formatters; } 197 198 public boolean getHaltOnError() { return haltOnError; } 199 public void setHaltOnError(boolean b) { haltOnError = b; } 200 201 public boolean getHaltOnFailure() { return haltOnFailure; } 202 public void setHaltOnFailure(boolean b) { haltOnFailure = b; } 203 204 public String getIfProperty () { return ifProperty; } 206 public void setIf(String name) { ifProperty = name; } 207 208 public boolean getMockTestRun() { return mockTestRun; } 209 public void setMockTestRun(boolean b) { mockTestRun = b; } 210 211 public String getName() { return name; } 212 public void setName (String val) { name = val; } 213 214 public String getOutfile() { return outfile; } 215 public void setOutfile (String val) { outfile = val; } 216 217 public boolean getShowOutput() { return showOutput; } 218 public void setShowOutput(boolean b) { showOutput = b; } 219 220 public String getTodir(){ 221 if (todir != null){ 222 return todir.getAbsolutePath(); 223 } 224 return null; 225 } 226 public void setTodir(File dir) { this.todir = dir; } 227 228 public String getUnlessProperty () { return unlessProperty; } 230 public void setUnless(String name) { unlessProperty = name; } 231 232 238 public Object clone() { 239 QuiltTest t = new QuiltTest(); 240 t.name = name; 241 242 244 t.checkCoverage = checkCoverage; 245 t.checkExcludes = checkExcludes; 246 t.checkIncludes = checkIncludes; 247 t.errorProperty = errorProperty; 248 t.failureProperty = failureProperty; 249 t.filtertrace = filtertrace; 250 t.formatters = (Vector ) formatters.clone(); 251 t.fork = fork; 252 t.haltOnError = haltOnError; 253 t.haltOnFailure = haltOnFailure; 254 t.ifProperty = ifProperty; 255 t.mockTestRun = mockTestRun; 256 t.outfile = outfile; 257 t.showOutput = showOutput; 258 t.todir = todir; 259 t.unlessProperty = unlessProperty; 260 261 Properties props = getProperties(); 263 if (props != null) { 264 t.setProperties( (Properties ) props.clone() ); 265 } 266 return t; 267 } 268 public String toString() { 270 String fmtStr = ""; 271 for (int i = 0; i < formatters.size(); i++) 272 fmtStr += formatters.elementAt(i) + " "; 273 274 String pStr; 275 if (props != null) { 276 pStr = ""; 277 Enumeration e = props.keys(); 278 while (e.hasMoreElements()) { 279 String name = (String ) e.nextElement(); 280 String value = (String ) props.getProperty(name); 281 pStr += "\n (" + name + " --> " + value + ")"; 282 } 283 } else { 284 pStr = "<none>"; 285 } 286 String s = 287 " test name: " + name 288 289 + "\n checkCoverage: " + checkCoverage 290 + "\n checkExcludes: " + (checkExcludes == null? "" 291 : checkExcludes) 292 + "\n checkIncludes: " + (checkIncludes == null? "" 293 : checkIncludes) 294 + "\n errorProperty: " + errorProperty 295 + "\n failureProperty: " + failureProperty 296 + "\n filtertrace: " + filtertrace 297 + "\n fork: " + fork 298 + "\n formatters: " + fmtStr 299 + "\n haltOnError: " + haltOnError 300 + "\n haltOnFailure: " + haltOnFailure 301 + "\n ifProperty: " + ifProperty 302 + "\n mockTestRun: " + mockTestRun 303 + "\n outfile: " + outfile 304 + "\n showOutput: " + showOutput 305 + "\n todir: " + todir 306 + "\n unlessProperty: " + unlessProperty 307 308 + "\n errors: " + errors 310 + "\n failures: " + failures 311 + "\n runs: " + runs 312 313 + "\n other properties:" + pStr; 314 return s; 315 } 316 323 public boolean runMe (Project p) { 324 if (ifProperty != null) { 325 if (p.getProperty(ifProperty) == null) 326 return false; 327 } 328 if (unlessProperty != null) { 329 if (p.getProperty(ifProperty) != null) 330 return false; 331 } 332 return true; 333 } 334 } 335 | Popular Tags |