You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FOTreeTestSuite.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright 2005 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fotreetest;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.Collection;
  21. import java.util.Iterator;
  22. import org.apache.commons.io.FileUtils;
  23. import org.apache.commons.io.filefilter.AndFileFilter;
  24. import org.apache.commons.io.filefilter.IOFileFilter;
  25. import org.apache.commons.io.filefilter.NameFileFilter;
  26. import org.apache.commons.io.filefilter.PrefixFileFilter;
  27. import org.apache.commons.io.filefilter.SuffixFileFilter;
  28. import org.apache.commons.io.filefilter.TrueFileFilter;
  29. import org.apache.fop.DebugHelper;
  30. import org.apache.fop.layoutengine.LayoutEngineTestSuite;
  31. import junit.framework.Test;
  32. import junit.framework.TestCase;
  33. import junit.framework.TestSuite;
  34. /**
  35. * JUnit test suit for running layout engine test under JUnit control.
  36. */
  37. public final class FOTreeTestSuite {
  38. static {
  39. DebugHelper.registerStandardElementListObservers();
  40. }
  41. private FOTreeTestSuite() {
  42. //don't instantiate!
  43. }
  44. /**
  45. * @return the test suite with all the tests (one for each XML file)
  46. * @throws IOException in case of an I/O problem
  47. */
  48. public static Test suite() throws IOException {
  49. TestSuite suite = new TestSuite();
  50. File mainDir = new File("test/fotree");
  51. final FOTreeTester tester = new FOTreeTester();
  52. IOFileFilter filter;
  53. String single = System.getProperty("fop.fotree.single");
  54. String startsWith = System.getProperty("fop.fotree.starts-with");
  55. if (single != null) {
  56. filter = new NameFileFilter(single);
  57. } else if (startsWith != null) {
  58. filter = new PrefixFileFilter(startsWith);
  59. filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
  60. } else {
  61. filter = new SuffixFileFilter(".fo");
  62. filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
  63. }
  64. Collection files = FileUtils.listFiles(new File(mainDir, "testcases"),
  65. filter, TrueFileFilter.INSTANCE);
  66. String privateTests = System.getProperty("fop.fotree.private");
  67. if ("true".equalsIgnoreCase(privateTests)) {
  68. Collection privateFiles = FileUtils.listFiles(
  69. new File(mainDir, "private-testcases"),
  70. filter, TrueFileFilter.INSTANCE);
  71. files.addAll(privateFiles);
  72. }
  73. Iterator i = files.iterator();
  74. while (i.hasNext()) {
  75. File f = (File)i.next();
  76. addTestCase(suite, tester, f);
  77. }
  78. return suite;
  79. }
  80. private static void addTestCase(TestSuite suite,
  81. final FOTreeTester tester, final File f) {
  82. suite.addTest(new FOTreeTestCase(f.getName()) {
  83. public void runTest() throws Exception {
  84. org.apache.commons.logging.LogFactory.getLog(this.getClass()).info("Starting " + f.getName());
  85. prepare(tester, f);
  86. testMain();
  87. }
  88. });
  89. }
  90. private static class FOTreeTestCase extends TestCase {
  91. private FOTreeTester tester;
  92. private File testFile;
  93. public FOTreeTestCase(String name) {
  94. super(name);
  95. }
  96. public void prepare(FOTreeTester tester, File testFile) {
  97. //super(testFile.getName());
  98. this.tester = tester;
  99. this.testFile = testFile;
  100. }
  101. public void testMain() throws Exception {
  102. tester.runTest(testFile);
  103. }
  104. }
  105. }