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.

AbstractPostScriptTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.render.ps;
  19. import static org.junit.Assert.assertEquals;
  20. import java.io.File;
  21. import java.io.IOException;
  22. import org.apache.xmlgraphics.ps.PSResource;
  23. import org.apache.xmlgraphics.ps.dsc.DSCException;
  24. import org.apache.xmlgraphics.ps.dsc.DSCParser;
  25. import org.apache.xmlgraphics.ps.dsc.events.AbstractResourceDSCComment;
  26. import org.apache.xmlgraphics.ps.dsc.events.DSCComment;
  27. import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
  28. import org.apache.fop.apps.FOUserAgent;
  29. import org.apache.fop.apps.MimeConstants;
  30. import org.apache.fop.render.AbstractRenderingTest;
  31. /**
  32. * Abstract base class for PostScript verification tests.
  33. */
  34. public abstract class AbstractPostScriptTest extends AbstractRenderingTest {
  35. /**
  36. * Renders a test file.
  37. * @param ua the user agent (with override set!)
  38. * @param resourceName the resource name for the FO file
  39. * @param suffix a suffix for the output filename
  40. * @return the output file
  41. * @throws Exception if an error occurs
  42. */
  43. protected File renderFile(FOUserAgent ua, String resourceName, String suffix)
  44. throws Exception {
  45. return renderFile(ua, resourceName, suffix, MimeConstants.MIME_POSTSCRIPT);
  46. }
  47. /**
  48. * Scans for a certain resource DSC comment and checks against a given resource.
  49. * @param parser the DSC parser
  50. * @param comment the comment to scan for
  51. * @param resource the resource to check against
  52. * @throws IOException if an I/O error occurs
  53. * @throws DSCException if a DSC error occurs
  54. */
  55. protected void checkResourceComment(DSCParser parser, String comment, PSResource resource)
  56. throws IOException, DSCException {
  57. AbstractResourceDSCComment resComment;
  58. resComment = (AbstractResourceDSCComment)gotoDSCComment(parser, comment);
  59. assertEquals(resource, resComment.getResource());
  60. }
  61. /**
  62. * Advances the DSC parser to a DSC comment with the given name.
  63. * @param parser the DSC parser
  64. * @param name the name of the DSC comment
  65. * @return the DSC comment
  66. * @throws IOException if an I/O error occurs
  67. * @throws DSCException if a DSC error occurs
  68. */
  69. protected static DSCComment gotoDSCComment(DSCParser parser, String name)
  70. throws IOException, DSCException {
  71. while (parser.hasNext()) {
  72. DSCEvent event = parser.nextEvent();
  73. if (event.isDSCComment()) {
  74. DSCComment comment = event.asDSCComment();
  75. if (comment.getName().equals(name)) {
  76. return comment;
  77. }
  78. }
  79. }
  80. return null;
  81. }
  82. }