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.

PDFPageLabelsTestCase.java 3.8KB

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.pdf;
  19. import java.io.ByteArrayOutputStream;
  20. import java.io.IOException;
  21. import org.junit.Test;
  22. import static org.junit.Assert.assertEquals;
  23. import static org.mockito.Mockito.mock;
  24. public class PDFPageLabelsTestCase {
  25. @Test
  26. public void testAddPageLabel() throws IOException {
  27. PDFDocument pdfDoc = mock(PDFDocument.class);
  28. PDFPageLabels pageLabels = new PDFPageLabels();
  29. pageLabels.setDocument(pdfDoc);
  30. int index = 0;
  31. StringBuilder expected = new StringBuilder();
  32. expected.append("[");
  33. expected.append(index + " << /S /r >>");
  34. pageLabels.addPageLabel(index++, "i");
  35. pageLabels.addPageLabel(index++, "ii");
  36. pageLabels.addPageLabel(index++, "iii");
  37. expected.append(" " + index + " << /S /D >>");
  38. pageLabels.addPageLabel(index++, "1");
  39. pageLabels.addPageLabel(index++, "2");
  40. pageLabels.addPageLabel(index++, "3");
  41. pageLabels.addPageLabel(index++, "4");
  42. pageLabels.addPageLabel(index++, "5");
  43. pageLabels.addPageLabel(index++, "6");
  44. pageLabels.addPageLabel(index++, "7");
  45. pageLabels.addPageLabel(index++, "8");
  46. pageLabels.addPageLabel(index++, "9");
  47. pageLabels.addPageLabel(index++, "10");
  48. expected.append(" " + index + " << /S /A >>");
  49. pageLabels.addPageLabel(index++, "A");
  50. pageLabels.addPageLabel(index++, "B");
  51. expected.append(" " + index + " << /S /R /St 100 >>");
  52. pageLabels.addPageLabel(index++, "C");
  53. expected.append(" " + index + " << /S /R /St 500 >>");
  54. pageLabels.addPageLabel(index++, "D");
  55. expected.append(" " + index + " << /S /A /St 5 >>");
  56. pageLabels.addPageLabel(index++, "E");
  57. pageLabels.addPageLabel(index++, "F");
  58. pageLabels.addPageLabel(index++, "G");
  59. expected.append(" " + index + " << /P (aa) >>");
  60. pageLabels.addPageLabel(index++, "aa");
  61. expected.append(" " + index + " << /P (ab) >>");
  62. pageLabels.addPageLabel(index++, "ab");
  63. expected.append(" " + index + " << /P (ac) >>");
  64. pageLabels.addPageLabel(index++, "ac");
  65. expected.append(" " + index + " << /S /a >>");
  66. pageLabels.addPageLabel(index++, "a");
  67. pageLabels.addPageLabel(index++, "b");
  68. expected.append(" " + index + " << /S /R /St 2 >>");
  69. pageLabels.addPageLabel(index++, "II");
  70. expected.append(" " + index + " << /S /R /St 12 >>");
  71. pageLabels.addPageLabel(index++, "XII");
  72. expected.append(" " + index + " <<\n /P (00)\n /S /D\n /St 9\n>>");
  73. pageLabels.addPageLabel(index++, "009");
  74. expected.append(" " + index + " <<\n /P (0)\n /S /D\n /St 10\n>>");
  75. pageLabels.addPageLabel(index++, "010");
  76. pageLabels.addPageLabel(index++, "011");
  77. expected.append("]");
  78. PDFNumsArray nums = pageLabels.getNums();
  79. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  80. nums.output(baos);
  81. assertEquals(expected.toString(), baos.toString());
  82. baos.close();
  83. }
  84. }