Skip to content

Commit 8c64bac

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
1 parent d8ecda4 commit 8c64bac

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfStampingTest.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,29 +1260,23 @@ public void stampingTestWithTaggedStructure() throws IOException {
12601260

12611261
@Test
12621262
public void stampingTestWithFullCompression01() throws IOException, InterruptedException {
1263-
String outPdf = destinationFolder + "stampingTestWithFullCompression01.pdf";
1264-
String cmpPdf = sourceFolder + "cmp_stampingTestWithFullCompression01.pdf";
1263+
String compressedOutPdf = destinationFolder + "stampingTestWithFullCompression01Compressed.pdf";
1264+
String decompressedOutPdf = destinationFolder + "stampingTestWithFullCompression01Decompressed.pdf";
1265+
12651266
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"),
1266-
new PdfWriter(outPdf));
1267+
new PdfWriter(compressedOutPdf));
12671268
pdfDoc.close();
1268-
float result = new File(outPdf).length();
1269-
float expected = new File(cmpPdf).length();
1270-
float coef = Math.abs((expected - result) / expected);
1271-
String compareRes = new CompareTool().compareByContent(outPdf, cmpPdf, destinationFolder);
1272-
assertTrue(coef < 0.01);
1273-
assertNull(compareRes);
1274-
}
1269+
float compressedLength = new File(compressedOutPdf).length();
12751270

1276-
@Test
1277-
public void stampingTestWithFullCompression02() throws IOException {
1278-
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"),
1279-
new PdfWriter(destinationFolder + "stampingTestWithFullCompression02.pdf",
1280-
new WriterProperties().setFullCompressionMode(false)));
1271+
pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "fullCompressedDocument.pdf"),
1272+
new PdfWriter(decompressedOutPdf, new WriterProperties().setFullCompressionMode(false)));
12811273
pdfDoc.close();
1282-
float result = new File(destinationFolder + "stampingTestWithFullCompression02.pdf").length();
1283-
float expected = new File(sourceFolder + "cmp_stampingTestWithFullCompression02.pdf").length();
1284-
float coef = Math.abs((expected - result) / expected);
1285-
assertTrue(coef < 0.01);
1274+
float decompressedLength = new File(decompressedOutPdf).length();
1275+
1276+
float coef = compressedLength / decompressedLength;
1277+
String compareRes = new CompareTool().compareByContent(compressedOutPdf, decompressedOutPdf, destinationFolder);
1278+
assertTrue(coef < 0.7);
1279+
assertNull(compareRes);
12861280
}
12871281

12881282
@Test

0 commit comments

Comments
 (0)