Skip to content

Commit e627059

Browse files
author
Kate Ivanova
committed
Add tests for table elements with HorizontalAlignment
DEVSIX-4021
1 parent edf666a commit e627059

File tree

7 files changed

+271
-2
lines changed

7 files changed

+271
-2
lines changed

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

Lines changed: 271 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,249 @@ public void floatsOnlyJustificationTest01() throws IOException, InterruptedExcep
453453
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff_"));
454454
}
455455

456+
@Test
457+
//TODO DEVSIX-4021 update cmp file after fix
458+
public void tableWithAlignmentNextToRightFloatTest() throws IOException, InterruptedException {
459+
String outFileName = destinationFolder + "tableWithAlignmentNextToRightFloat.pdf";
460+
String cmpFileName = sourceFolder + "cmp_tableWithAlignmentNextToRightFloat.pdf";
461+
462+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
463+
464+
Document document = new Document(pdfDocument);
465+
466+
Table table1 = createTable(HorizontalAlignment.RIGHT);
467+
Table table2 = createTable(HorizontalAlignment.LEFT);
468+
Table table3 = createTable(HorizontalAlignment.CENTER);
469+
470+
Div div = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
471+
FloatPropertyValue.RIGHT, UnitValue.createPointValue(200));
472+
473+
Div spaceDiv = new Div();
474+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
475+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
476+
477+
document.add(div);
478+
document.add(table1);
479+
document.add(spaceDiv);
480+
481+
document.add(div);
482+
document.add(table2);
483+
document.add(spaceDiv);
484+
485+
document.add(div);
486+
document.add(table3);
487+
488+
document.close();
489+
490+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
491+
}
492+
493+
@Test
494+
//TODO DEVSIX-4021 update cmp file after fix
495+
public void tableWithAlignmentNextToLeftFloatTest() throws IOException, InterruptedException {
496+
String outFileName = destinationFolder + "tableWithAlignmentNextToLeftFloat.pdf";
497+
String cmpFileName = sourceFolder + "cmp_tableWithAlignmentNextToLeftFloat.pdf";
498+
499+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
500+
501+
Document document = new Document(pdfDocument);
502+
503+
Table table1 = createTable(HorizontalAlignment.RIGHT);
504+
Table table2 = createTable(HorizontalAlignment.LEFT);
505+
Table table3 = createTable(HorizontalAlignment.CENTER);
506+
507+
Div div = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
508+
FloatPropertyValue.LEFT, UnitValue.createPointValue(200));
509+
510+
Div spaceDiv = new Div();
511+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
512+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
513+
514+
document.add(div);
515+
document.add(table1);
516+
document.add(spaceDiv);
517+
518+
document.add(div);
519+
document.add(table2);
520+
document.add(spaceDiv);
521+
522+
document.add(div);
523+
document.add(table3);
524+
525+
document.close();
526+
527+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
528+
}
529+
530+
@Test
531+
//TODO DEVSIX-4021 update cmp file after fix
532+
public void tableWithAlignmentBetweenFloatsTest() throws IOException, InterruptedException {
533+
String outFileName = destinationFolder + "tableWithAlignmentBetweenFloats.pdf";
534+
String cmpFileName = sourceFolder + "cmp_tableWithAlignmentBetweenFloats.pdf";
535+
536+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
537+
538+
Document document = new Document(pdfDocument);
539+
540+
Table table1 = createTable(HorizontalAlignment.RIGHT).setWidth(250);
541+
Table table2 = createTable(HorizontalAlignment.LEFT).setWidth(250);
542+
Table table3 = createTable(HorizontalAlignment.CENTER).setWidth(250);
543+
544+
Div div1 = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
545+
FloatPropertyValue.LEFT, UnitValue.createPointValue(100));
546+
547+
Div div2 = createDiv(ColorConstants.BLUE, ClearPropertyValue.NONE,
548+
FloatPropertyValue.RIGHT, UnitValue.createPointValue(100));
549+
550+
Div spaceDiv = new Div();
551+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
552+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
553+
554+
document.add(div1);
555+
document.add(div2);
556+
document.add(table1);
557+
document.add(spaceDiv);
558+
559+
document.add(div1);
560+
document.add(div2);
561+
document.add(table2);
562+
document.add(spaceDiv);
563+
564+
document.add(div1);
565+
document.add(div2);
566+
document.add(table3);
567+
568+
document.close();
569+
570+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
571+
}
572+
573+
@Test
574+
//TODO DEVSIX-4021 update cmp file after fix
575+
public void tableWithBigLeftMarginAfterFloatTest() throws IOException, InterruptedException {
576+
String outFileName = destinationFolder + "tableWithBigLeftMarginAfterFloat.pdf";
577+
String cmpFileName = sourceFolder + "cmp_tableWithBigLeftMarginAfterFloat.pdf";
578+
579+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
580+
581+
Document document = new Document(pdfDocument);
582+
583+
Table table1 = createTable(HorizontalAlignment.RIGHT);
584+
table1.setMarginLeft(300);
585+
Table table2 = createTable(HorizontalAlignment.LEFT);
586+
table2.setMarginLeft(300);
587+
Table table3 = createTable(HorizontalAlignment.CENTER);
588+
table3.setMarginLeft(300);
589+
590+
Div div = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
591+
FloatPropertyValue.RIGHT, UnitValue.createPointValue(200));
592+
593+
Div spaceDiv = new Div();
594+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
595+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
596+
597+
document.add(div);
598+
document.add(table1);
599+
document.add(spaceDiv);
600+
601+
document.add(div);
602+
document.add(table2);
603+
document.add(spaceDiv);
604+
605+
document.add(div);
606+
document.add(table3);
607+
608+
document.close();
609+
610+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
611+
}
612+
613+
@Test
614+
//TODO DEVSIX-4021 update cmp file after fix
615+
public void tableWithBigRightMarginAfterFloatTest() throws IOException, InterruptedException {
616+
String outFileName = destinationFolder + "tableWithBigRightMarginAfterFloat.pdf";
617+
String cmpFileName = sourceFolder + "cmp_tableWithBigRightMarginAfterFloat.pdf";
618+
619+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
620+
621+
Document document = new Document(pdfDocument);
622+
623+
Table table1 = createTable(HorizontalAlignment.RIGHT);
624+
table1.setMarginRight(300);
625+
Table table2 = createTable(HorizontalAlignment.LEFT);
626+
table2.setMarginRight(300);
627+
Table table3 = createTable(HorizontalAlignment.CENTER);
628+
table3.setMarginRight(300);
629+
630+
Div div = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
631+
FloatPropertyValue.LEFT, UnitValue.createPointValue(200));
632+
633+
Div spaceDiv = new Div();
634+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
635+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
636+
637+
document.add(div);
638+
document.add(table1);
639+
document.add(spaceDiv);
640+
641+
document.add(div);
642+
document.add(table2);
643+
document.add(spaceDiv);
644+
645+
document.add(div);
646+
document.add(table3);
647+
648+
document.close();
649+
650+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
651+
}
652+
653+
@Test
654+
//TODO DEVSIX-4021 update cmp file after fix
655+
public void tableWithSideMarginsBetweenFloatTest() throws IOException, InterruptedException {
656+
String outFileName = destinationFolder + "tableWithSideMarginsBetweenFloat.pdf";
657+
String cmpFileName = sourceFolder + "cmp_tableWithSideMarginsBetweenFloat.pdf";
658+
659+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
660+
661+
Document document = new Document(pdfDocument);
662+
663+
Table table1 = createTable(HorizontalAlignment.RIGHT);
664+
table1.setMarginRight(150)
665+
.setMarginLeft(150);
666+
Table table2 = createTable(HorizontalAlignment.LEFT);
667+
table2.setMarginRight(300);
668+
Table table3 = createTable(HorizontalAlignment.CENTER);
669+
table3.setMarginLeft(300);
670+
671+
Div div1 = createDiv(ColorConstants.GREEN, ClearPropertyValue.NONE,
672+
FloatPropertyValue.LEFT, UnitValue.createPointValue(100));
673+
Div div2 = createDiv(ColorConstants.BLUE, ClearPropertyValue.NONE,
674+
FloatPropertyValue.RIGHT, UnitValue.createPointValue(100));
675+
676+
Div spaceDiv = new Div();
677+
spaceDiv.setProperty(Property.CLEAR, ClearPropertyValue.BOTH);
678+
spaceDiv.add(new Paragraph("Space Div").setFontColor(ColorConstants.BLUE));
679+
680+
document.add(div1);
681+
document.add(div2);
682+
document.add(table1);
683+
document.add(spaceDiv);
684+
685+
document.add(div1);
686+
document.add(div2);
687+
document.add(table2);
688+
document.add(spaceDiv);
689+
690+
document.add(div1);
691+
document.add(div2);
692+
document.add(table3);
693+
694+
document.close();
695+
696+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
697+
}
698+
456699
private Div createParentDiv(HorizontalAlignment horizontalAlignment, ClearPropertyValue clearPropertyValue, UnitValue width) {
457700
Div divParent1 = new Div()
458701
.setBorder(new SolidBorder(5) )
@@ -474,11 +717,37 @@ private static Div createDiv(Color color, HorizontalAlignment horizontalAlignmen
474717
div.setHorizontalAlignment( horizontalAlignment);
475718
div.setProperty( Property.CLEAR, clearPropertyValue);
476719
div.setProperty(Property.FLOAT, floatPropertyValue);
477-
div.add( new Paragraph( "Div with HorizontalAlignment."+ horizontalAlignment
720+
String cont = "Div with HorizontalAlignment."+ horizontalAlignment
478721
+", ClearPropertyValue." +clearPropertyValue
479-
+ ", FloatPropertyValue." +floatPropertyValue) );
722+
+ ", FloatPropertyValue." +floatPropertyValue;
723+
div.add( new Paragraph(cont) );
480724
return div;
481725
}
482726

727+
private static Div createDiv(Color color, ClearPropertyValue clearPropertyValue,
728+
FloatPropertyValue floatPropertyValue, UnitValue width) {
729+
Div div = new Div()
730+
.setBorder(new SolidBorder( color, 1) )
731+
.setBackgroundColor(color, 0.3f)
732+
.setMargins(10, 10, 10, 10)
733+
.setWidth(width);
734+
div.setProperty( Property.CLEAR, clearPropertyValue);
735+
div.setProperty(Property.FLOAT, floatPropertyValue);
736+
String cont = "Div with ClearPropertyValue." +clearPropertyValue
737+
+ ", FloatPropertyValue." +floatPropertyValue;
738+
div.add( new Paragraph(cont) );
739+
return div;
740+
}
741+
742+
private static Table createTable(HorizontalAlignment horizontalAlignment) {
743+
Table table = new Table(3);
744+
table.addCell("Align" + horizontalAlignment.toString());
745+
table.addCell("Cell number two");
746+
table.addCell("Cell number three");
747+
table.setHorizontalAlignment(horizontalAlignment);
748+
749+
return table;
750+
}
751+
483752

484753
}

0 commit comments

Comments
 (0)