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.

IFParserTestCase.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.intermediate;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.util.Collection;
  23. import javax.xml.transform.Source;
  24. import javax.xml.transform.dom.DOMResult;
  25. import javax.xml.transform.stream.StreamResult;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.junit.runners.Parameterized;
  29. import org.junit.runners.Parameterized.Parameters;
  30. import org.w3c.dom.Document;
  31. import org.apache.fop.apps.FOUserAgent;
  32. import org.apache.fop.fonts.FontInfo;
  33. import org.apache.fop.layoutengine.LayoutEngineTestUtils;
  34. import org.apache.fop.render.intermediate.IFContext;
  35. import org.apache.fop.render.intermediate.IFDocumentHandler;
  36. import org.apache.fop.render.intermediate.IFParser;
  37. import org.apache.fop.render.intermediate.IFSerializer;
  38. /**
  39. * Tests the intermediate format parser.
  40. */
  41. @RunWith(Parameterized.class)
  42. public class IFParserTestCase extends AbstractIFTestCase {
  43. /**
  44. * Gets the parameters for this test
  45. *
  46. * @return a collection of file arrays containing the test files
  47. * @throws IOException if an error occurs when trying to read the test files
  48. */
  49. @Parameters
  50. public static Collection<File[]> getParameters() throws IOException {
  51. return LayoutEngineTestUtils.getLayoutTestFiles();
  52. }
  53. /**
  54. * Constructor for the test suite that is used for each test file.
  55. * @param testFile the test file to run
  56. * @throws IOException if an I/O error occurs while loading the test case
  57. */
  58. public IFParserTestCase(File testFile) throws IOException {
  59. super(testFile);
  60. }
  61. /** {@inheritDoc} */
  62. @Override
  63. protected void parseAndRender(Source src, OutputStream out) throws Exception {
  64. IFParser parser = new IFParser();
  65. FOUserAgent userAgent = createUserAgent();
  66. IFDocumentHandler documentHandler = userAgent.getRendererFactory().createDocumentHandler(
  67. userAgent, getTargetMIME());
  68. documentHandler.setResult(new StreamResult(out));
  69. documentHandler.setDefaultFontInfo(new FontInfo());
  70. parser.parse(src, documentHandler, userAgent);
  71. }
  72. /** {@inheritDoc} */
  73. @Override
  74. protected Document parseAndRenderToIntermediateFormat(Source src) throws Exception {
  75. IFParser parser = new IFParser();
  76. FOUserAgent userAgent = createUserAgent();
  77. IFSerializer serializer = new IFSerializer();
  78. serializer.setContext(new IFContext(userAgent));
  79. DOMResult domResult = new DOMResult();
  80. serializer.setResult(domResult);
  81. parser.parse(src, serializer, userAgent);
  82. return (Document)domResult.getNode();
  83. }
  84. @Override
  85. @Test
  86. public void runTest() throws Exception {
  87. try {
  88. testParserToIntermediateFormat();
  89. testParserToPDF();
  90. } catch (Exception e) {
  91. org.apache.commons.logging.LogFactory.getLog(this.getClass()).error(
  92. "Error on " + testFile.getName());
  93. throw e;
  94. }
  95. }
  96. }