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.

UncompressedObjectReferenceTestCase.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 static org.junit.Assert.assertArrayEquals;
  20. import java.io.IOException;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. import org.junit.Test;
  25. public class UncompressedObjectReferenceTestCase extends ObjectReferenceTest {
  26. @Test
  27. public void test1ByteOffsets() throws IOException {
  28. run1ByteOffsetTest(0x0);
  29. run1ByteOffsetTest(0xf);
  30. run1ByteOffsetTest(0x10);
  31. run1ByteOffsetTest(0xff);
  32. }
  33. private void run1ByteOffsetTest(int offset) throws IOException {
  34. runIntegerOffsetTest(Arrays.asList(0, 0, 0, offset));
  35. }
  36. @Test
  37. public void test2ByteOffsets() throws IOException {
  38. runIntegerOffsetTest(Arrays.asList(0, 0, 1, 0xff));
  39. runIntegerOffsetTest(Arrays.asList(0, 0, 0xa0, 0xff));
  40. }
  41. @Test
  42. public void test3ByteOffsets() throws IOException {
  43. runIntegerOffsetTest(Arrays.asList(0, 2, 0x12, 0x34));
  44. runIntegerOffsetTest(Arrays.asList(0, 0xee, 0x56, 0x78));
  45. }
  46. @Test
  47. public void test4ByteOffsets() throws IOException {
  48. runIntegerOffsetTest(Arrays.asList(0x6, 0x12, 0x34, 0x56));
  49. runIntegerOffsetTest(Arrays.asList(0xf1, 0x9a, 0xbc, 0xde));
  50. }
  51. @Test
  52. public void test5ByteOffsets() throws IOException {
  53. runTest(Arrays.asList(0, 0, 0, 0x7, 0x78, 0x9a, 0xbc, 0xde));
  54. runTest(Arrays.asList(0, 0, 0, 0xbf, 0xf0, 0, 0x1, 0x2));
  55. }
  56. @Test
  57. public void test8ByteOffsets() throws IOException {
  58. runTest(Arrays.asList(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8));
  59. runTest(Arrays.asList(0xf9, 0xe8, 0xd7, 0xc6, 0xb5, 0xa4, 0x93, 0x82));
  60. }
  61. private void runIntegerOffsetTest(List<Integer> expectedOffsetBytes) throws IOException {
  62. List<Integer> expectedLongOffset = new ArrayList<Integer>(8);
  63. expectedLongOffset.addAll(Arrays.asList(0, 0, 0, 0));
  64. expectedLongOffset.addAll(expectedOffsetBytes);
  65. runTest(expectedLongOffset);
  66. }
  67. private void runTest(List<Integer> expectedOffsetBytes) throws IOException {
  68. long offset = computeNumberFromBytes(expectedOffsetBytes);
  69. sut = new UncompressedObjectReference(offset);
  70. byte[] expected = createExpectedOutput((byte) 1, expectedOffsetBytes, (byte) 0);
  71. byte[] actual = getActualOutput();
  72. assertArrayEquals(expected, actual);
  73. }
  74. }