1 51 package org.apache.fop.tools.anttasks; 52 53 import org.apache.tools.ant.*; 55 56 import java.io.*; 57 import java.lang.reflect.*; 58 import java.net.URLClassLoader ; 59 import java.net.URL ; 60 import java.net.MalformedURLException ; 61 import java.util.*; 62 63 69 public class RunTest extends Task { 70 String basedir; 71 String testsuite = ""; 72 String referenceJar = ""; 73 String refVersion = ""; 74 75 public RunTest() {} 76 77 public void setTestSuite(String str) { 78 testsuite = str; 79 } 80 81 public void setBasedir(String str) { 82 basedir = str; 83 } 84 85 public void setReference(String str) { 86 referenceJar = str; 87 } 88 89 public void setRefVersion(String str) { 90 refVersion = str; 91 } 92 93 98 public void execute() throws BuildException { 99 runReference(); 100 testNewBuild(); 101 } 102 103 109 protected void testNewBuild() { 110 try { 111 ClassLoader loader = new URLClassLoader (new URL [] { 112 new URL ("file:build/fop.jar") 113 }); 114 HashMap diff = runConverter(loader, "areatree", 115 "reference/output/"); 116 if (diff != null &&!diff.isEmpty()) { 117 System.out.println("===================================="); 118 System.out.println("The following files differ:"); 119 boolean broke = false; 120 for (Iterator keys = diff.keySet().iterator(); keys.hasNext(); ) { 121 Object fname = keys.next(); 122 Boolean pass = (Boolean )diff.get(fname); 123 System.out.println("file: " + fname 124 + " - reference success: " + pass); 125 if (pass.booleanValue()) { 126 broke = true; 127 } 128 } 129 if (broke) { 130 throw new BuildException("Working tests have been changed."); 131 } 132 } 133 } catch (MalformedURLException mue) { 134 mue.printStackTrace(); 135 } 136 } 137 138 145 protected void runReference() throws BuildException { 146 File f = new File(basedir + "/reference/output/"); 148 try { 153 ClassLoader loader = new URLClassLoader (new URL [] { 154 new URL ("file:" + referenceJar) 155 }); 156 boolean failed = false; 157 158 try { 159 Class cla = Class.forName("org.apache.fop.apps.Options", 160 true, loader); 161 Object opts = cla.newInstance(); 162 cla = Class.forName("org.apache.fop.apps.Version", true, 163 loader); 164 Method get = cla.getMethod("getVersion", new Class []{}); 165 if (!get.invoke(null, new Object []{}).equals(refVersion)) { 166 throw new BuildException("Reference jar is not correct version it must be: " 167 + refVersion); 168 } 169 } catch (IllegalAccessException iae) { 170 failed = true; 171 } catch (IllegalArgumentException are) { 172 failed = true; 173 } catch (InvocationTargetException are) { 174 failed = true; 175 } catch (ClassNotFoundException are) { 176 failed = true; 177 } catch (InstantiationException are) { 178 failed = true; 179 } catch (NoSuchMethodException are) { 180 failed = true; 181 } 182 if (failed) { 183 throw new BuildException("Reference jar could not be found in: " 184 + basedir + "/reference/"); 185 } 186 f.mkdirs(); 187 runConverter(loader, "reference/output/", null); 188 } catch (MalformedURLException mue) { 189 mue.printStackTrace(); 190 } 191 } 193 194 202 protected HashMap runConverter(ClassLoader loader, String dest, 203 String compDir) { 204 String converter = "org.apache.fop.tools.TestConverter"; 205 206 HashMap diff = null; 207 try { 208 Class cla = Class.forName(converter, true, loader); 209 Object tc = cla.newInstance(); 210 Method meth; 211 212 meth = cla.getMethod("setBaseDir", new Class [] { 213 String .class 214 }); 215 meth.invoke(tc, new Object [] { 216 basedir 217 }); 218 219 meth = cla.getMethod("runTests", new Class [] { 220 String .class, String .class, String .class 221 }); 222 diff = (HashMap)meth.invoke(tc, new Object [] { 223 testsuite, dest, compDir 224 }); 225 } catch (Exception e) { 226 e.printStackTrace(); 227 } 228 return diff; 229 } 230 231 } 232 | Popular Tags |