aboutsummaryrefslogtreecommitdiffstats
path: root/test/java
diff options
context:
space:
mode:
authorLuis Bernardo <lbernardo@apache.org>2012-10-17 23:36:43 +0000
committerLuis Bernardo <lbernardo@apache.org>2012-10-17 23:36:43 +0000
commit9772267c98b4996a889fb8bb2e8b628e2026dd09 (patch)
tree0facef43f7fa34ef360c6f298e00e5bf3092f081 /test/java
parent8d775d94555b992aa3986323c0867c2cc82c90e4 (diff)
downloadxmlgraphics-fop-9772267c98b4996a889fb8bb2e8b628e2026dd09.tar.gz
xmlgraphics-fop-9772267c98b4996a889fb8bb2e8b628e2026dd09.zip
bugzilla #54024: rewrote generation of /PageLabels dictionary
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1399483 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r--test/java/org/apache/fop/pdf/PDFPageLabelsTestCase.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/java/org/apache/fop/pdf/PDFPageLabelsTestCase.java b/test/java/org/apache/fop/pdf/PDFPageLabelsTestCase.java
new file mode 100644
index 000000000..e982bf246
--- /dev/null
+++ b/test/java/org/apache/fop/pdf/PDFPageLabelsTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+public class PDFPageLabelsTestCase {
+
+ @Test
+ public void testAddPageLabel() throws IOException {
+ PDFDocument pdfDoc = mock(PDFDocument.class);
+ PDFPageLabels pageLabels = new PDFPageLabels();
+ pageLabels.setDocument(pdfDoc);
+ int index = 0;
+ StringBuilder expected = new StringBuilder();
+ expected.append("[");
+ expected.append(index + " << /S /r >>\n");
+ pageLabels.addPageLabel(index++, "i");
+ pageLabels.addPageLabel(index++, "ii");
+ pageLabels.addPageLabel(index++, "iii");
+ expected.append(" " + index + " << /S /D >>\n");
+ pageLabels.addPageLabel(index++, "1");
+ pageLabels.addPageLabel(index++, "2");
+ pageLabels.addPageLabel(index++, "3");
+ pageLabels.addPageLabel(index++, "4");
+ pageLabels.addPageLabel(index++, "5");
+ pageLabels.addPageLabel(index++, "6");
+ pageLabels.addPageLabel(index++, "7");
+ pageLabels.addPageLabel(index++, "8");
+ pageLabels.addPageLabel(index++, "9");
+ pageLabels.addPageLabel(index++, "10");
+ expected.append(" " + index + " << /S /A >>\n");
+ pageLabels.addPageLabel(index++, "A");
+ pageLabels.addPageLabel(index++, "B");
+ expected.append(" " + index + " << /S /R /St 100 >>\n");
+ pageLabels.addPageLabel(index++, "C");
+ expected.append(" " + index + " << /S /R /St 500 >>\n");
+ pageLabels.addPageLabel(index++, "D");
+ expected.append(" " + index + " << /S /A /St 5 >>\n");
+ pageLabels.addPageLabel(index++, "E");
+ pageLabels.addPageLabel(index++, "F");
+ pageLabels.addPageLabel(index++, "G");
+ expected.append(" " + index + " << /P (aa) >>\n");
+ pageLabels.addPageLabel(index++, "aa");
+ expected.append(" " + index + " << /P (ab) >>\n");
+ pageLabels.addPageLabel(index++, "ab");
+ expected.append(" " + index + " << /P (ac) >>\n");
+ pageLabels.addPageLabel(index++, "ac");
+ expected.append(" " + index + " << /S /a >>\n");
+ pageLabels.addPageLabel(index++, "a");
+ pageLabels.addPageLabel(index++, "b");
+ expected.append(" " + index + " << /S /R /St 2 >>\n");
+ pageLabels.addPageLabel(index++, "II");
+ expected.append(" " + index + " << /S /R /St 12 >>\n");
+ pageLabels.addPageLabel(index++, "XII");
+ expected.append(" " + index + " <<\n /P (00)\n /S /D\n /St 9\n>>\n");
+ pageLabels.addPageLabel(index++, "009");
+ expected.append(" " + index + " <<\n /P (0)\n /S /D\n /St 10\n>>\n");
+ pageLabels.addPageLabel(index++, "010");
+ pageLabels.addPageLabel(index++, "011");
+ expected.append("]");
+
+ PDFNumsArray nums = pageLabels.getNums();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ nums.output(baos);
+ assertEquals(expected.toString(), baos.toString());
+ baos.close();
+ }
+
+}