1 17 18 19 20 package org.apache.fop.fotreetest; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import org.apache.commons.io.FileUtils; 28 import org.apache.commons.io.filefilter.AndFileFilter; 29 import org.apache.commons.io.filefilter.IOFileFilter; 30 import org.apache.commons.io.filefilter.NameFileFilter; 31 import org.apache.commons.io.filefilter.PrefixFileFilter; 32 import org.apache.commons.io.filefilter.SuffixFileFilter; 33 import org.apache.commons.io.filefilter.TrueFileFilter; 34 import org.apache.fop.DebugHelper; 35 import org.apache.fop.layoutengine.LayoutEngineTestSuite; 36 37 import junit.framework.Test; 38 import junit.framework.TestCase; 39 import junit.framework.TestSuite; 40 41 44 public final class FOTreeTestSuite { 45 46 static { 47 DebugHelper.registerStandardElementListObservers(); 48 } 49 50 private FOTreeTestSuite() { 51 } 53 54 58 public static Test suite() throws IOException { 59 TestSuite suite = new TestSuite(); 60 61 File mainDir = new File ("test/fotree"); 62 63 final FOTreeTester tester = new FOTreeTester(); 64 65 IOFileFilter filter; 66 String single = System.getProperty("fop.fotree.single"); 67 String startsWith = System.getProperty("fop.fotree.starts-with"); 68 if (single != null) { 69 filter = new NameFileFilter(single); 70 } else if (startsWith != null) { 71 filter = new PrefixFileFilter(startsWith); 72 filter = new AndFileFilter(filter, new SuffixFileFilter(".fo")); 73 } else { 74 filter = new SuffixFileFilter(".fo"); 75 filter = LayoutEngineTestSuite.decorateWithDisabledList(filter); 76 } 77 Collection files = FileUtils.listFiles(new File (mainDir, "testcases"), 78 filter, TrueFileFilter.INSTANCE); 79 String privateTests = System.getProperty("fop.fotree.private"); 80 if ("true".equalsIgnoreCase(privateTests)) { 81 Collection privateFiles = FileUtils.listFiles( 82 new File (mainDir, "private-testcases"), 83 filter, TrueFileFilter.INSTANCE); 84 files.addAll(privateFiles); 85 } 86 Iterator i = files.iterator(); 87 while (i.hasNext()) { 88 File f = (File )i.next(); 89 addTestCase(suite, tester, f); 90 } 91 92 return suite; 93 } 94 95 private static void addTestCase(TestSuite suite, 96 final FOTreeTester tester, final File f) { 97 suite.addTest(new FOTreeTestCase(f.getName()) { 98 public void runTest() throws Exception { 99 org.apache.commons.logging.LogFactory.getLog(this.getClass()).info("Starting " + f.getName()); 100 prepare(tester, f); 101 testMain(); 102 } 103 }); 104 } 105 106 private static class FOTreeTestCase extends TestCase { 107 108 private FOTreeTester tester; 109 private File testFile; 110 111 public FOTreeTestCase(String name) { 112 super(name); 113 } 114 115 public void prepare(FOTreeTester tester, File testFile) { 116 this.tester = tester; 118 this.testFile = testFile; 119 } 120 121 public void testMain() throws Exception { 122 tester.runTest(testFile); 123 } 124 } 125 } 126 | Popular Tags |