|
| 1 | +package com.itextpdf.layout; |
| 2 | + |
| 3 | +import com.itextpdf.kernel.color.Color; |
| 4 | +import com.itextpdf.kernel.pdf.PdfDocument; |
| 5 | +import com.itextpdf.kernel.pdf.PdfWriter; |
| 6 | +import com.itextpdf.kernel.utils.CompareTool; |
| 7 | +import com.itextpdf.kernel.xmp.XMPException; |
| 8 | +import com.itextpdf.layout.element.Paragraph; |
| 9 | + |
| 10 | +import java.io.FileOutputStream; |
| 11 | +import java.io.IOException; |
| 12 | + |
| 13 | +import com.itextpdf.layout.element.Text; |
| 14 | +import com.itextpdf.test.ExtendedITextTest; |
| 15 | +import com.itextpdf.test.annotations.type.IntegrationTest; |
| 16 | +import org.junit.Assert; |
| 17 | +import org.junit.BeforeClass; |
| 18 | +import org.junit.Rule; |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.experimental.categories.Category; |
| 21 | +import org.junit.rules.ExpectedException; |
| 22 | + |
| 23 | + |
| 24 | +@Category(IntegrationTest.class) |
| 25 | +public class BackgroundColorTest extends ExtendedITextTest { |
| 26 | + |
| 27 | + public static final String sourceFolder = "./src/test/resources/com/itextpdf/layout/BackgroundColorTest/"; |
| 28 | + public static final String destinationFolder = "./target/test/com/itextpdf/layout/BackgroundColorTest/"; |
| 29 | + public static final String cmpPrefix = "cmp_"; |
| 30 | + |
| 31 | + String fileName; |
| 32 | + String outFileName; |
| 33 | + String cmpFileName; |
| 34 | + |
| 35 | + @BeforeClass |
| 36 | + public static void beforeClass() { |
| 37 | + createDestinationFolder(destinationFolder); |
| 38 | + } |
| 39 | + |
| 40 | + @Rule |
| 41 | + public ExpectedException thrown = ExpectedException.none(); |
| 42 | + |
| 43 | + @Test |
| 44 | + public void shouldAddBackgroundColorAttributeToAccessiblityWhenBackgroundColorIsSet() throws IOException, XMPException, InterruptedException { |
| 45 | + fileName = "simpleBackgroundColorTest.pdf"; |
| 46 | + outFileName = destinationFolder + fileName; |
| 47 | + cmpFileName = sourceFolder + cmpPrefix + fileName; |
| 48 | + |
| 49 | + PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName))); |
| 50 | + pdfDocument.setTagged(); |
| 51 | + Document doc = new Document(pdfDocument); |
| 52 | + |
| 53 | + Text foo = new Text("foo"); |
| 54 | + foo.setBackgroundColor(Color.BLUE); |
| 55 | + doc.add(new Paragraph(foo)); |
| 56 | + |
| 57 | + closeDocumentAndCompareOutputs(doc); |
| 58 | + } |
| 59 | + |
| 60 | + private void closeDocumentAndCompareOutputs(Document document) throws IOException, InterruptedException { |
| 61 | + document.close(); |
| 62 | + String compareResult = new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"); |
| 63 | + if (compareResult != null) { |
| 64 | + Assert.fail(compareResult); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
0 commit comments