@@ -22,12 +22,19 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .kernel .pdf ;
24
24
25
+ import com .itextpdf .io .logs .IoLogMessageConstant ;
26
+ import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
27
+ import com .itextpdf .kernel .exceptions .PdfException ;
25
28
import com .itextpdf .kernel .utils .CompareTool ;
29
+ import com .itextpdf .test .AssertUtil ;
26
30
import com .itextpdf .test .ExtendedITextTest ;
31
+ import com .itextpdf .test .LogLevelConstants ;
32
+ import com .itextpdf .test .annotations .LogMessage ;
33
+ import com .itextpdf .test .annotations .LogMessages ;
27
34
import com .itextpdf .test .annotations .type .IntegrationTest ;
28
35
36
+ import java .io .ByteArrayOutputStream ;
29
37
import java .io .IOException ;
30
-
31
38
import org .junit .AfterClass ;
32
39
import org .junit .Assert ;
33
40
import org .junit .BeforeClass ;
@@ -37,23 +44,45 @@ This file is part of the iText (R) project.
37
44
@ Category (IntegrationTest .class )
38
45
public class PdfXrefTableTest extends ExtendedITextTest {
39
46
40
- public static final String sourceFolder = "./src/test/resources/com/itextpdf/kernel/pdf/PdfXrefTableTest/" ;
41
- public static final String destinationFolder = "./target/test/com/itextpdf/kernel/pdf/PdfXrefTableTest/" ;
47
+ public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/kernel/pdf/PdfXrefTableTest/" ;
48
+ public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/kernel/pdf/PdfXrefTableTest/" ;
42
49
43
50
@ BeforeClass
44
51
public static void beforeClass () {
45
- createOrClearDestinationFolder (destinationFolder );
52
+ createOrClearDestinationFolder (DESTINATION_FOLDER );
46
53
}
47
54
48
55
@ AfterClass
49
56
public static void afterClass () {
50
- CompareTool .cleanup (destinationFolder );
57
+ CompareTool .cleanup (DESTINATION_FOLDER );
58
+ }
59
+
60
+ @ Test
61
+ @ LogMessages (messages = {
62
+ @ LogMessage (messageTemplate = IoLogMessageConstant .XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT , logLevel = LogLevelConstants .ERROR )
63
+ })
64
+ public void openInvalidDocWithHugeRefTest () {
65
+ String inputFile = SOURCE_FOLDER + "invalidDocWithHugeRef.pdf" ;
66
+ AssertUtil .doesNotThrow (() -> new PdfDocument (new PdfReader (inputFile )));
51
67
}
52
-
68
+
69
+ @ Test
70
+ @ LogMessages (messages = {
71
+ @ LogMessage (messageTemplate = IoLogMessageConstant .XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT , logLevel = LogLevelConstants .ERROR )
72
+ })
73
+ public void openWithWriterInvalidDocWithHugeRefTest () {
74
+ String inputFile = SOURCE_FOLDER + "invalidDocWithHugeRef.pdf" ;
75
+ ByteArrayOutputStream outputStream = new com .itextpdf .io .source .ByteArrayOutputStream ();
76
+
77
+ Exception e = Assert .assertThrows (PdfException .class , () ->
78
+ new PdfDocument (new PdfReader (inputFile ), new PdfWriter (outputStream )));
79
+ Assert .assertEquals (KernelExceptionMessageConstant .XREF_STRUCTURE_SIZE_EXCEEDED_THE_LIMIT , e .getMessage ());
80
+ }
81
+
53
82
@ Test
54
83
public void testCreateAndUpdateXMP () throws IOException {
55
- String created = destinationFolder + "testCreateAndUpdateXMP_create.pdf" ;
56
- String updated = destinationFolder + "testCreateAndUpdateXMP_update.pdf" ;
84
+ String created = DESTINATION_FOLDER + "testCreateAndUpdateXMP_create.pdf" ;
85
+ String updated = DESTINATION_FOLDER + "testCreateAndUpdateXMP_update.pdf" ;
57
86
PdfDocument pdfDocument = new PdfDocument (CompareTool .createTestPdfWriter (created ));
58
87
pdfDocument .addNewPage ();
59
88
@@ -93,9 +122,9 @@ public void testCreateAndUpdateXMP() throws IOException {
93
122
94
123
@ Test
95
124
public void testCreateAndUpdateTwiceXMP () throws IOException {
96
- String created = destinationFolder + "testCreateAndUpdateTwiceXMP_create.pdf" ;
97
- String updated = destinationFolder + "testCreateAndUpdateTwiceXMP_update.pdf" ;
98
- String updatedAgain = destinationFolder + "testCreateAndUpdateTwiceXMP_updatedAgain.pdf" ;
125
+ String created = DESTINATION_FOLDER + "testCreateAndUpdateTwiceXMP_create.pdf" ;
126
+ String updated = DESTINATION_FOLDER + "testCreateAndUpdateTwiceXMP_update.pdf" ;
127
+ String updatedAgain = DESTINATION_FOLDER + "testCreateAndUpdateTwiceXMP_updatedAgain.pdf" ;
99
128
PdfDocument pdfDocument = new PdfDocument (CompareTool .createTestPdfWriter (created ));
100
129
pdfDocument .addNewPage ();
101
130
0 commit comments