@@ -41,6 +41,7 @@ source product.
41
41
42
42
*/
43
43
using System ;
44
+ using iText . IO . Util ;
44
45
using iText . Kernel . Pdf . Xobject ;
45
46
using iText . Kernel . Utils ;
46
47
using iText . Test ;
@@ -53,8 +54,8 @@ public class PdfStreamTest : ExtendedITextTest {
53
54
public static readonly String destinationFolder = NUnit . Framework . TestContext . CurrentContext . TestDirectory
54
55
+ "/test/itext/kernel/pdf/PdfStreamTest/" ;
55
56
56
- [ NUnit . Framework . SetUp ]
57
- public virtual void Before ( ) {
57
+ [ NUnit . Framework . OneTimeSetUp ]
58
+ public static void Before ( ) {
58
59
CreateOrClearDestinationFolder ( destinationFolder ) ;
59
60
}
60
61
@@ -89,5 +90,77 @@ public virtual void RunLengthEncodingTest01() {
89
90
NUnit . Framework . Assert . AreEqual ( imgBytes1 , cmpImgBytes1 ) ;
90
91
NUnit . Framework . Assert . AreEqual ( imgBytes2 , cmpImgBytes2 ) ;
91
92
}
93
+
94
+ [ NUnit . Framework . Test ]
95
+ public virtual void IndirectRefInFilterAndNoTaggedPdfTest ( ) {
96
+ String inFile = sourceFolder + "indirectRefInFilterAndNoTaggedPdf.pdf" ;
97
+ String outFile = destinationFolder + "destIndirectRefInFilterAndNoTaggedPdf.pdf" ;
98
+ PdfDocument srcDoc = new PdfDocument ( new PdfReader ( inFile ) ) ;
99
+ PdfDocument outDoc = new PdfDocument ( new PdfReader ( inFile ) , new PdfWriter ( outFile ) ) ;
100
+ outDoc . Close ( ) ;
101
+ PdfDocument doc = new PdfDocument ( new PdfReader ( outFile ) ) ;
102
+ PdfStream outStreamIm1 = doc . GetFirstPage ( ) . GetResources ( ) . GetResource ( PdfName . XObject ) . GetAsStream ( new PdfName
103
+ ( "Im1" ) ) ;
104
+ PdfStream outStreamIm2 = doc . GetFirstPage ( ) . GetResources ( ) . GetResource ( PdfName . XObject ) . GetAsStream ( new PdfName
105
+ ( "Im2" ) ) ;
106
+ PdfStream cmpStreamIm1 = srcDoc . GetFirstPage ( ) . GetResources ( ) . GetResource ( PdfName . XObject ) . GetAsStream ( new
107
+ PdfName ( "Im1" ) ) ;
108
+ PdfStream cmpStreamIm2 = srcDoc . GetFirstPage ( ) . GetResources ( ) . GetResource ( PdfName . XObject ) . GetAsStream ( new
109
+ PdfName ( "Im2" ) ) ;
110
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareStreamsStructure ( outStreamIm1 , cmpStreamIm1 ) ) ;
111
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareStreamsStructure ( outStreamIm2 , cmpStreamIm2 ) ) ;
112
+ srcDoc . Close ( ) ;
113
+ outDoc . Close ( ) ;
114
+ }
115
+
116
+ [ NUnit . Framework . Test ]
117
+ public virtual void IndirectFilterInCatalogTest ( ) {
118
+ // TODO DEVSIX-1193 remove junitExpectedException and expected NullPointerException after fix
119
+ String inFile = sourceFolder + "indFilterInCatalog.pdf" ;
120
+ PdfDocument doc = new PdfDocument ( new PdfReader ( inFile ) , new PdfWriter ( destinationFolder + "indFilterInCatalog.pdf"
121
+ ) ) ;
122
+ NUnit . Framework . Assert . That ( ( ) => {
123
+ doc . Close ( ) ;
124
+ }
125
+ , NUnit . Framework . Throws . InstanceOf < NullReferenceException > ( ) )
126
+ ;
127
+ }
128
+
129
+ [ NUnit . Framework . Test ]
130
+ public virtual void IndirectFilterFlushedBeforeStreamTest ( ) {
131
+ // TODO DEVSIX-1193 remove junitExpectedException after fix
132
+ String inFile = sourceFolder + "indFilterInCatalog.pdf" ;
133
+ String @out = destinationFolder + "indirectFilterFlushedBeforeStreamTest.pdf" ;
134
+ PdfDocument pdfDoc = new PdfDocument ( new PdfReader ( inFile ) , new PdfWriter ( @out ) ) ;
135
+ // Simulate the case in which filter is somehow already flushed before stream.
136
+ // Either directly by user or because of any other reason.
137
+ PdfObject filterObject = pdfDoc . GetPdfObject ( 6 ) ;
138
+ filterObject . Flush ( ) ;
139
+ NUnit . Framework . Assert . That ( ( ) => {
140
+ pdfDoc . Close ( ) ;
141
+ }
142
+ , NUnit . Framework . Throws . InstanceOf < NullReferenceException > ( ) )
143
+ ;
144
+ }
145
+
146
+ [ NUnit . Framework . Test ]
147
+ public virtual void IndirectFilterMarkedToBeFlushedBeforeStreamTest ( ) {
148
+ // TODO DEVSIX-1193 remove junitExpectedException after fix
149
+ String inFile = sourceFolder + "indFilterInCatalog.pdf" ;
150
+ String @out = destinationFolder + "indirectFilterMarkedToBeFlushedBeforeStreamTest.pdf" ;
151
+ PdfWriter writer = new PdfWriter ( @out ) ;
152
+ PdfDocument pdfDoc = new PdfDocument ( new PdfReader ( inFile ) , writer ) ;
153
+ // Simulate the case when indirect filter object is marked to be flushed before the stream itself.
154
+ PdfObject filterObject = pdfDoc . GetPdfObject ( 6 ) ;
155
+ filterObject . GetIndirectReference ( ) . SetState ( PdfObject . MUST_BE_FLUSHED ) ;
156
+ // The image stream will be marked as MUST_BE_FLUSHED after page is flushed.
157
+ pdfDoc . GetFirstPage ( ) . GetPdfObject ( ) . GetIndirectReference ( ) . SetState ( PdfObject . MUST_BE_FLUSHED ) ;
158
+ NUnit . Framework . Assert . That ( ( ) => {
159
+ writer . FlushWaitingObjects ( JavaCollectionsUtil . EmptySet < PdfIndirectReference > ( ) ) ;
160
+ pdfDoc . Close ( ) ;
161
+ }
162
+ , NUnit . Framework . Throws . InstanceOf < NullReferenceException > ( ) )
163
+ ;
164
+ }
92
165
}
93
166
}
0 commit comments