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.

AFPResourceManagerTestCase.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.afp;
  19. import java.io.ByteArrayOutputStream;
  20. import java.io.File;
  21. import java.io.IOException;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import static org.junit.Assert.assertFalse;
  25. import static org.junit.Assert.assertTrue;
  26. import org.apache.xmlgraphics.util.MimeConstants;
  27. import org.apache.fop.apps.io.ResourceResolverFactory;
  28. /**
  29. * Test case for {@link AFPResourceManager}.
  30. */
  31. public class AFPResourceManagerTestCase {
  32. private AFPResourceManager sut;
  33. @Before
  34. public void setUp() throws IOException {
  35. sut = new AFPResourceManager(ResourceResolverFactory.createDefaultInternalResourceResolver(
  36. new File(".").toURI()));
  37. AFPPaintingState paintingState = new AFPPaintingState();
  38. ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  39. DataStream stream = sut.createDataStream(paintingState, outStream);
  40. stream.startPage(0, 0, 0, 10, 10);
  41. }
  42. /**
  43. * Ensures that if tryIncludeObject() is called with a new object, it returns false suggesting
  44. * that we have to create said object. However, if it is called with an object that has already
  45. * been created, it returns true suggesting that we don't have to create that object again.
  46. * Page-segment is false.
  47. *
  48. * @throws IOException if an I/O error occurs
  49. */
  50. @Test
  51. public void testTryIncludeObjectWithPageSegFalse() throws IOException {
  52. AFPDataObjectInfo dataInfo = createAFPDataObjectInfo();
  53. // An empty object needs to be created every time!
  54. assertFalse(sut.tryIncludeObject(dataInfo));
  55. sut.createObject(dataInfo);
  56. assertTrue(sut.tryIncludeObject(dataInfo));
  57. }
  58. /**
  59. * {@code testTryIncludeObjectWithPageSegFalse()} but with page-segment true.
  60. *
  61. * @throws IOException if an I/O error occurs
  62. */
  63. @Test
  64. public void testTryIncludeObjectWithPageSegTrue() throws IOException {
  65. AFPDataObjectInfo dataInfo = createAFPDataObjectInfo();
  66. dataInfo.setCreatePageSegment(true);
  67. // An empty object needs to be created every time!
  68. assertFalse(sut.tryIncludeObject(dataInfo));
  69. sut.createObject(dataInfo);
  70. assertTrue(sut.tryIncludeObject(dataInfo));
  71. }
  72. private AFPDataObjectInfo createAFPDataObjectInfo() {
  73. AFPDataObjectInfo dataInfo = new AFPDataObjectInfo();
  74. dataInfo.setMimeType(MimeConstants.MIME_TIFF);
  75. dataInfo.setData(new byte[1]);
  76. AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(0, 0, 10, 10, 1, 0);
  77. dataInfo.setObjectAreaInfo(objectAreaInfo);
  78. return dataInfo;
  79. }
  80. }