Skip to content

Commit e8c4b7f

Browse files
committed
Add table tests.
DEVSIX-470
1 parent 3ee76d1 commit e8c4b7f

File tree

6 files changed

+106
-4
lines changed

6 files changed

+106
-4
lines changed

layout/src/test/java/com/itextpdf/layout/TableTest.java

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public class TableTest extends ExtendedITextTest{
3434
static final public String sourceFolder = "./src/test/resources/com/itextpdf/layout/TableTest/";
3535
static final public String destinationFolder = "./target/test/com/itextpdf/layout/TableTest/";
3636

37+
static final String textContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" +
38+
"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.\n" +
39+
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.\n";
40+
static final String shortTextContent = "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.";
41+
static final String middleTextContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" +
42+
"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.";
43+
44+
3745
@BeforeClass
3846
static public void beforeClass() {
3947
createDestinationFolder(destinationFolder);
@@ -581,18 +589,112 @@ public void simpleTableTest18() throws IOException, InterruptedException {
581589
PdfDocument pdfDoc = new PdfDocument(writer);
582590
Document doc = new Document(pdfDoc);
583591

592+
doc.add(new Paragraph(textContent));
593+
594+
Table table = new Table(new float[]{50, 50, 50})
595+
.addCell(new Cell().add(new Paragraph("cell 1, 1")))
596+
.addCell(new Cell().add(new Paragraph("cell 1, 2")))
597+
.addCell(new Cell().add(new Paragraph("cell 1, 3")));
598+
599+
String longText = "Long text, very long text. ";
600+
for (int i = 0; i < 4; i++) {
601+
longText += longText;
602+
}
603+
table.addCell(new Cell().add(new Paragraph("cell 2.1\n" + longText).setKeepTogether(true)));
604+
table.addCell("cell 2.2\nShort text.");
605+
table.addCell(new Cell().add(new Paragraph("cell 2.3\n" + longText)));
606+
607+
doc.add(table);
608+
doc.close();
609+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
610+
}
611+
612+
@Test
613+
@LogMessages(messages = {
614+
@LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, count = 1)
615+
})
616+
public void simpleTableTest19() throws IOException, InterruptedException {
617+
String testName = "tableTest19.pdf";
618+
String outFileName = destinationFolder + testName;
619+
String cmpFileName = sourceFolder + "cmp_" + testName;
620+
621+
FileOutputStream file = new FileOutputStream(outFileName);
622+
PdfWriter writer = new PdfWriter(file);
623+
PdfDocument pdfDoc = new PdfDocument(writer);
624+
Document doc = new Document(pdfDoc);
625+
626+
Table table = new Table(new float[]{130, 130, 260})
627+
.addCell(new Cell(3, 2).add(new Paragraph("cell 1:2, 1:3\n" + textContent + textContent)))
628+
.addCell(new Cell().add(new Paragraph("cell 1, 3\n" + textContent)))
629+
.addCell(new Cell().add(new Paragraph("cell 2, 3\n" + textContent)))
630+
.addCell(new Cell().add(new Paragraph("cell 3, 3\n" + textContent)))
631+
.addCell(new Cell().add(new Image(ImageFactory.getImage(sourceFolder + "red.png"))))
632+
.addCell(new Cell().add(new Paragraph("cell 4, 2\n" + shortTextContent)))
633+
.addCell(new Cell().add(new Paragraph("cell 4, 3\n" + middleTextContent)))
634+
.addCell(new Cell().add(new Paragraph("cell 5, 1\n" + shortTextContent)))
635+
.addCell(new Cell().add(new Paragraph("cell 5, 2\n" + shortTextContent)))
636+
.addCell(new Cell().add(new Paragraph("cell 5, 3\n" + middleTextContent)))
637+
.addCell(new Cell().add(new Paragraph("cell 6, 1\n" + middleTextContent)))
638+
.addCell(new Cell().add(new Paragraph("cell 6, 2\n" + middleTextContent)))
639+
.addCell(new Cell().add(new Paragraph("cell 6, 3\n" + middleTextContent)));
640+
doc.add(table);
641+
doc.close();
642+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
643+
}
644+
645+
@Test
646+
@LogMessages(messages = {
647+
@LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, count = 1)
648+
})
649+
public void simpleTableTest20() throws IOException, InterruptedException {
650+
String testName = "tableTest20.pdf";
651+
String outFileName = destinationFolder + testName;
652+
String cmpFileName = sourceFolder + "cmp_" + testName;
653+
654+
FileOutputStream file = new FileOutputStream(outFileName);
655+
PdfWriter writer = new PdfWriter(file);
656+
PdfDocument pdfDoc = new PdfDocument(writer);
657+
Document doc = new Document(pdfDoc);
658+
659+
Table table = new Table(new float[]{130, 130, 260})
660+
.addCell(new Cell().add(new Image(ImageFactory.getImage(sourceFolder + "red.png"))))
661+
.addCell(new Cell().add(new Paragraph("cell 4, 2\n" + shortTextContent)))
662+
.addCell(new Cell().add(new Paragraph("cell 4, 3\n" + middleTextContent)))
663+
.addCell(new Cell().add(new Paragraph("cell 5, 1\n" + shortTextContent)))
664+
.addCell(new Cell().add(new Paragraph("cell 5, 2\n" + shortTextContent)))
665+
.addCell(new Cell().add(new Paragraph("cell 5, 3\n" + middleTextContent)))
666+
.addCell(new Cell().add(new Paragraph("cell 6, 1\n" + middleTextContent)))
667+
.addCell(new Cell().add(new Paragraph("cell 6, 2\n" + middleTextContent)))
668+
.addCell(new Cell().add(new Paragraph("cell 6, 3\n" + middleTextContent)));
669+
doc.add(table);
670+
doc.close();
671+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
672+
}
673+
674+
@Test
675+
@LogMessages(messages = {
676+
@LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, count = 1)
677+
})
678+
public void simpleTableTest21() throws IOException, InterruptedException {
679+
String testName = "tableTest21.pdf";
680+
String outFileName = destinationFolder + testName;
681+
String cmpFileName = sourceFolder + "cmp_" + testName;
682+
683+
FileOutputStream file = new FileOutputStream(outFileName);
684+
PdfWriter writer = new PdfWriter(file);
685+
PdfDocument pdfDoc = new PdfDocument(writer);
686+
Document doc = new Document(pdfDoc);
687+
584688
String textContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" +
585689
"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.\n" +
586690
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.\n";
587691
String shortTextContent = "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.";
588692
String middleTextContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" +
589693
"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.";
590694

695+
doc.add(new Paragraph(textContent));
696+
591697
Table table = new Table(new float[]{130, 130, 260})
592-
.addCell(new Cell(3, 2).add(new Paragraph("cell 1:2, 1:3\n" + textContent + textContent)))
593-
.addCell(new Cell().add(new Paragraph("cell 1, 3\n" + textContent)))
594-
.addCell(new Cell().add(new Paragraph("cell 2, 3\n" + textContent)))
595-
.addCell(new Cell().add(new Paragraph("cell 3, 3\n" + textContent)))
596698
.addCell(new Cell().add(new Image(ImageFactory.getImage(sourceFolder + "red.png"))))
597699
.addCell(new Cell().add(new Paragraph("cell 4, 2\n" + shortTextContent)))
598700
.addCell(new Cell().add(new Paragraph("cell 4, 3\n" + middleTextContent)))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)