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.2KB

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