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.

AbstractBasicTranscoderTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;
  19. import java.io.File;
  20. import java.io.InputStream;
  21. import org.junit.Test;
  22. import static org.junit.Assert.assertTrue;
  23. import org.apache.commons.io.output.ByteArrayOutputStream;
  24. import org.apache.batik.transcoder.Transcoder;
  25. import org.apache.batik.transcoder.TranscoderInput;
  26. import org.apache.batik.transcoder.TranscoderOutput;
  27. import static org.apache.fop.FOPTestUtils.getBaseDir;
  28. /**
  29. * Basic runtime test for FOP's transcoders. It is used to verify that
  30. * nothing obvious is broken after compiling.
  31. */
  32. public abstract class AbstractBasicTranscoderTest {
  33. /**
  34. * Creates the transcoder to test.
  35. * @return the newly instantiated transcoder
  36. */
  37. protected abstract Transcoder createTranscoder();
  38. /**
  39. * Runs the PDF transcoder as if it were called by Batik's rasterizer.
  40. * Without special configuration stuff.
  41. * @throws Exception if a problem occurs
  42. */
  43. @Test
  44. public void testGenericPDFTranscoder() throws Exception {
  45. //Create transcoder
  46. Transcoder transcoder = createTranscoder();
  47. //Setup input
  48. File svgFile = new File(getBaseDir(), "test/resources/fop/svg/text.svg");
  49. InputStream in = new java.io.FileInputStream(svgFile);
  50. try {
  51. TranscoderInput input = new TranscoderInput(in);
  52. //Setup output
  53. ByteArrayOutputStream out = new ByteArrayOutputStream();
  54. try {
  55. TranscoderOutput output = new TranscoderOutput(out);
  56. //Do the transformation
  57. transcoder.transcode(input, output);
  58. } finally {
  59. out.close();
  60. }
  61. assertTrue("Some output expected", out.size() > 0);
  62. } finally {
  63. in.close();
  64. }
  65. }
  66. }