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.

CrossReferenceTableTestCase.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.pdf.xref;
  19. import java.io.IOException;
  20. import java.util.Arrays;
  21. import java.util.Collections;
  22. import java.util.List;
  23. import org.junit.Test;
  24. public class CrossReferenceTableTestCase extends CrossReferenceObjectTest {
  25. private List<Long> offsets;
  26. @Test
  27. public void testWithNoOffset() throws IOException {
  28. List<Long> emptyList = Collections.emptyList();
  29. runTest(emptyList);
  30. }
  31. @Test
  32. public void testWithOffsets() throws IOException {
  33. runTest(Arrays.asList(0L, 1L, 2L, 3L, 4L));
  34. }
  35. @Test
  36. public void testWithBigOffsets() throws IOException {
  37. runTest(Arrays.asList(0xffL, 0xffffL, 0x7fffffffL));
  38. }
  39. private void runTest(List<Long> offsets) throws IOException {
  40. this.offsets = offsets;
  41. runTest();
  42. }
  43. @Override
  44. protected CrossReferenceObject createCrossReferenceObject() {
  45. return new CrossReferenceTable(trailerDictionary, STARTXREF, offsets);
  46. }
  47. @Override
  48. protected byte[] createExpectedCrossReferenceData() throws IOException {
  49. StringBuilder expected = new StringBuilder(256);
  50. expected.append("xref\n0 ")
  51. .append(offsets.size() + 1)
  52. .append("\n0000000000 65535 f \n");
  53. for (Long objectReference : offsets) {
  54. final String padding = "0000000000";
  55. String s = String.valueOf(objectReference).toString();
  56. String loc = padding.substring(s.length()) + s;
  57. expected.append(loc).append(" 00000 n \n");
  58. }
  59. expected.append("trailer\n<<\n")
  60. .append(" /Root 1 0 R\n")
  61. .append(" /Info 2 0 R\n")
  62. .append(" /ID [<0123456789ABCDEF> <0123456789ABCDEF>]\n")
  63. .append(" /Size ").append(Integer.toString(offsets.size() + 1)).append('\n')
  64. .append(">>\n");
  65. return getBytes(expected);
  66. }
  67. }