Skip to content

Commit c694845

Browse files
ars18wrwiText-CI
authored andcommitted
Improve compression tests
Do not use any cmps. Instead check the difference in sizes between compressed and decompressed pdfs. DEVSIX-3391 Autoported commit. Original commit hash: [8c64bac2d]
1 parent a85c108 commit c694845

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,29 +1132,21 @@ public virtual void StampingTestWithTaggedStructure() {
11321132

11331133
[NUnit.Framework.Test]
11341134
public virtual void StampingTestWithFullCompression01() {
1135-
String outPdf = destinationFolder + "stampingTestWithFullCompression01.pdf";
1136-
String cmpPdf = sourceFolder + "cmp_stampingTestWithFullCompression01.pdf";
1135+
String compressedOutPdf = destinationFolder + "stampingTestWithFullCompression01Compressed.pdf";
1136+
String decompressedOutPdf = destinationFolder + "stampingTestWithFullCompression01Decompressed.pdf";
11371137
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"), new PdfWriter
1138-
(outPdf));
1138+
(compressedOutPdf));
11391139
pdfDoc.Close();
1140-
float result = new FileInfo(outPdf).Length;
1141-
float expected = new FileInfo(cmpPdf).Length;
1142-
float coef = Math.Abs((expected - result) / expected);
1143-
String compareRes = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder);
1144-
NUnit.Framework.Assert.IsTrue(coef < 0.01);
1145-
NUnit.Framework.Assert.IsNull(compareRes);
1146-
}
1147-
1148-
[NUnit.Framework.Test]
1149-
public virtual void StampingTestWithFullCompression02() {
1150-
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"), new PdfWriter
1151-
(destinationFolder + "stampingTestWithFullCompression02.pdf", new WriterProperties().SetFullCompressionMode
1152-
(false)));
1140+
float compressedLength = new FileInfo(compressedOutPdf).Length;
1141+
pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"), new PdfWriter(decompressedOutPdf
1142+
, new WriterProperties().SetFullCompressionMode(false)));
11531143
pdfDoc.Close();
1154-
float result = new FileInfo(destinationFolder + "stampingTestWithFullCompression02.pdf").Length;
1155-
float expected = new FileInfo(sourceFolder + "cmp_stampingTestWithFullCompression02.pdf").Length;
1156-
float coef = Math.Abs((expected - result) / expected);
1157-
NUnit.Framework.Assert.IsTrue(coef < 0.01);
1144+
float decompressedLength = new FileInfo(decompressedOutPdf).Length;
1145+
float coef = compressedLength / decompressedLength;
1146+
String compareRes = new CompareTool().CompareByContent(compressedOutPdf, decompressedOutPdf, destinationFolder
1147+
);
1148+
NUnit.Framework.Assert.IsTrue(coef < 0.7);
1149+
NUnit.Framework.Assert.IsNull(compareRes);
11581150
}
11591151

11601152
[NUnit.Framework.Test]

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d8ecda465d2a1a94c54f3d51be94b46addff6ba7
1+
8c64bac2d21ffb918af4f0d40f9864f787bf5e30

0 commit comments

Comments
 (0)