Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Dec 22, 2024
2 parents 0f01922 + d969e60 commit 9eeb7c2
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public virtual void PdfUA2LinkAnnotationsTest() {

[NUnit.Framework.Test]
public virtual void PdfUA2LinkAnnotNoAltTest() {
String outFile = DESTINATION_FOLDER + "pdfuaLinkAnnotationTest.pdf";
String outFile = DESTINATION_FOLDER + "pdfuaLinkAnnotationNoAltTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfuaLinkAnnotationNoAltTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
CreateSimplePdfUA2Document(pdfDocument);
Expand All @@ -87,10 +88,9 @@ public virtual void PdfUA2LinkAnnotNoAltTest() {
paragraph.Add(link);
new Document(pdfDocument).Add(paragraph);
}
new VeraPdfValidator().ValidateFailure(outFile);
CompareAndValidate(outFile, cmpFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void PdfUA2FileAttachmentAnnotTest() {
String outFile = DESTINATION_FOLDER + "pdfuaFileAttachmentAnnotTest.pdf";
Expand Down Expand Up @@ -154,6 +154,7 @@ public virtual void PdfUA2RubberStampAnnotationsTest() {
[NUnit.Framework.Test]
public virtual void PdfUA2RubberStampNoContentsAnnotationsTest() {
String outFile = DESTINATION_FOLDER + "pdfuaRubberstampNoContentAnnotationTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfuaRubberstampNoContentAnnotationTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
CreateSimplePdfUA2Document(pdfDocument);
Expand All @@ -163,12 +164,12 @@ public virtual void PdfUA2RubberStampNoContentsAnnotationsTest() {
pdfPage.AddAnnotation(stamp);
pdfPage.Flush();
}
new VeraPdfValidator().ValidateFailure(outFile);
CompareAndValidate(outFile, cmpFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void PdfUA2ScreenAnnotationsTest() {
//TODO DEVSIX-8807 Kernel: addAnnotation method doesn't annotate content elements with Annot tag when PDF version is 2.0
String outFile = DESTINATION_FOLDER + "pdfuaScreenAnnotationTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Expand All @@ -179,7 +180,7 @@ public virtual void PdfUA2ScreenAnnotationsTest() {
pdfPage.AddAnnotation(screen);
pdfPage.Flush();
}
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outFile));
NUnit.Framework.Assert.IsNotNull(new VeraPdfValidator().Validate(outFile));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
Expand Down Expand Up @@ -247,6 +248,7 @@ public virtual void PdfUA2RedactionAnnotationsTest() {
[NUnit.Framework.Test]
public virtual void PdfUA2RedactionNoContentsAnnotationsTest() {
String outFile = DESTINATION_FOLDER + "pdfuaRedactionNoContentsAnnotationTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfuaRedactionNoContentsAnnotationTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
CreateSimplePdfUA2Document(pdfDocument);
Expand All @@ -256,14 +258,13 @@ public virtual void PdfUA2RedactionNoContentsAnnotationsTest() {
pdfPage.AddAnnotation(redact);
pdfPage.Flush();
}
new VeraPdfValidator().ValidateFailure(outFile);
CompareAndValidate(outFile, cmpFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void PdfUA23DAnnotationsTest() {
//TODO DEVSIX-8807 Kernel: addAnnotation method doesn't annotate content elements with Annot tag when PDF version is 2.0
String outFile = DESTINATION_FOLDER + "pdfua3DAnnotationTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfua3DAnnotationTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
CreateSimplePdfUA2Document(pdfDocument);
Expand All @@ -272,9 +273,10 @@ public virtual void PdfUA23DAnnotationsTest() {
pdfPage.AddAnnotation(annot);
pdfPage.Flush();
}
CompareAndValidate(outFile, cmpFile);
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void PdfUA23DNoContentsAnnotationsTest() {
String outFile = DESTINATION_FOLDER + "pdfua3DNoContentsAnnotationTest.pdf";
Expand Down Expand Up @@ -392,8 +394,8 @@ public virtual void PdfUA2AltContentDiffAnnotationTest() {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void PdfUA2TabAnnotationsTest() {
//TODO DEVSIX-8807 Kernel: addAnnotation method doesn't annotate content elements with Annot tag when PDF version is 2.0
String outFile = DESTINATION_FOLDER + "pdfuaMultipleAnnotsTabAnnotationTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfuaMultipleAnnotsTabAnnotationTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
CreateSimplePdfUA2Document(pdfDocument);
Expand All @@ -409,9 +411,10 @@ public virtual void PdfUA2TabAnnotationsTest() {
NUnit.Framework.Assert.AreEqual(PdfName.S, pageT);
}
}
CompareAndValidate(outFile, cmpFile);
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void AnnotationInvisibleButNoArtifactTest() {
String outFile = DESTINATION_FOLDER + "pdfuaInvisibleAnnotationTest.pdf";
Expand Down
159 changes: 148 additions & 11 deletions itext.tests/itext.layout.tests/itext/layout/PdfUA2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,46 @@ public virtual void CheckSectionTest() {
public virtual void CheckTableOfContentsTest() {
String outFile = DESTINATION_FOLDER + "tableOfContentsTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_tableOfContentsTestTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
Paragraph paragraph = new Paragraph("Table of Contents");
document.Add(paragraph);
Paragraph tociRef = new Paragraph("The referenced paragraph");
document.Add(tociRef);
TagTreePointer pointer = new TagTreePointer(pdfDocument);
pointer.MoveToKid(1, StandardRoles.P);
Div tocDiv = new Div();
tocDiv.GetAccessibilityProperties().SetRole(StandardRoles.TOC).SetNamespace(new PdfNamespace(StandardNamespaces
.PDF_1_7));
Div firstTociDiv = new Div();
firstTociDiv.GetAccessibilityProperties().SetRole(StandardRoles.TOCI).SetNamespace(new PdfNamespace(StandardNamespaces
.PDF_1_7));
firstTociDiv.Add(new Paragraph("first toci"));
firstTociDiv.GetAccessibilityProperties().AddRef(pointer);
Div secondTociDiv = new Div();
secondTociDiv.GetAccessibilityProperties().SetRole(StandardRoles.TOCI).SetNamespace(new PdfNamespace(StandardNamespaces
.PDF_1_7));
secondTociDiv.Add(new Paragraph("second toci"));
secondTociDiv.GetAccessibilityProperties().AddRef(pointer);
tocDiv.Add(firstTociDiv);
tocDiv.Add(secondTociDiv);
document.Add(tocDiv);
pointer.MoveToParent().MoveToKid(StandardRoles.TOCI);
// We check that TOCI contains the previously added Paragraph ref
NUnit.Framework.Assert.AreEqual(1, pointer.GetProperties().GetRefsList().Count);
NUnit.Framework.Assert.AreEqual(StandardRoles.P, pointer.GetProperties().GetRefsList()[0].GetRole());
}
CompareAndValidate(outFile, cmpFile);
}

[NUnit.Framework.Test]
public virtual void CheckInvalidStructureTableOfContentsTest() {
String outFile = DESTINATION_FOLDER + "invalidStructureTableOfContentsTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
Expand All @@ -249,9 +289,11 @@ public virtual void CheckTableOfContentsTest() {
NUnit.Framework.Assert.AreEqual(1, pointer.GetProperties().GetRefsList().Count);
NUnit.Framework.Assert.AreEqual(StandardRoles.P, pointer.GetProperties().GetRefsList()[0].GetRole());
}
CompareAndValidate(outFile, cmpFile);
// We expect failing validation because TOC and TOCI shall not contain Span tags
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void CreateValidAsideTest() {
String outFile = DESTINATION_FOLDER + "validAsideTest.pdf";
Expand All @@ -264,7 +306,34 @@ public virtual void CreateValidAsideTest() {
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
document.Add(new Paragraph("Section 1:"));
Paragraph section1Content = new Paragraph("Paragraph 1.1");
document.Add(new Paragraph("Paragraph 1.1"));
Div aside = new Div();
aside.GetAccessibilityProperties().SetRole(StandardRoles.ASIDE);
aside.Add(new Paragraph("Additional content related to Section 1."));
document.Add(aside);
document.Add(new Paragraph("Section 2:"));
document.Add(new Paragraph("Paragraph 2.1"));
document.Add(new Paragraph("Paragraph 2.2"));
Div aside2 = new Div();
aside2.GetAccessibilityProperties().SetRole(StandardRoles.ASIDE);
aside2.Add(new Paragraph("Additional content related to Section 2."));
document.Add(aside2);
}
CompareAndValidate(outFile, cmpFile);
}

[NUnit.Framework.Test]
public virtual void CreateInvalidAsideStructureTest() {
String outFile = DESTINATION_FOLDER + "invalidAsideStructureTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
document.Add(new Paragraph("Section 1:"));
Paragraph section1Content = new Paragraph("Paragraph 1.1\n");
Paragraph aside = new Paragraph("Additional content related to Section 1.");
aside.GetAccessibilityProperties().SetRole(StandardRoles.ASIDE);
section1Content.Add(aside);
Expand All @@ -275,11 +344,12 @@ public virtual void CreateValidAsideTest() {
Paragraph aside2 = new Paragraph("Additional content related to Section 2.");
aside2.GetAccessibilityProperties().SetRole(StandardRoles.ASIDE);
document.Add(aside2);
document.Add(new Paragraph("Section 3:"));
}
CompareAndValidate(outFile, cmpFile);
// We expect failing validation because Aside shall not contain Span and P shall not contain Aside
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void CheckParagraphTest() {
String outFile = DESTINATION_FOLDER + "paragraphTest.pdf";
Expand Down Expand Up @@ -332,9 +402,32 @@ public virtual void CheckHeadingTest() {
}

[NUnit.Framework.Test]
public virtual void CheckLabelTest() {
public virtual void CheckLabelInListTest() {
String outFile = DESTINATION_FOLDER + "labelInListTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_labelInListTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
List list = new List();
list.Add("First list element");
list.Add("Second list element");
list.Add("Third list element");
document.Add(list);
TagTreePointer pointer = new TagTreePointer(pdfDocument);
pointer.MoveToKid(StandardRoles.LI);
// We check that a list element contains a bullet with Lbl tag
NUnit.Framework.Assert.AreEqual(StandardRoles.LBL, pointer.GetKidsRoles()[0]);
}
CompareAndValidate(outFile, cmpFile);
}

[NUnit.Framework.Test]
public virtual void CheckInvalidLabelStructureTest() {
String outFile = DESTINATION_FOLDER + "labelTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_labelTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
Expand All @@ -344,12 +437,34 @@ public virtual void CheckLabelTest() {
CreateSimplePdfUA2Document(pdfDocument);
Div lblStructure = new Div();
lblStructure.GetAccessibilityProperties().SetRole(StandardRoles.LBL);
Paragraph labelContent = new Paragraph("Label: ");
Paragraph labelContent = new Paragraph("Label content");
lblStructure.Add(labelContent);
Paragraph targetContent = new Paragraph("Marked content");
targetContent.GetAccessibilityProperties().SetActualText("Marked content");
document.Add(lblStructure);
document.Add(targetContent);
}
// We expect failing validation because Lbl shall not contain P and Document shall not contain Lbl
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void CheckLabelWithLinkContentTest() {
String outFile = DESTINATION_FOLDER + "labelWithLinkContentTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_labelWithLinkContentTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
Paragraph container = new Paragraph();
Div lblStructure = new Div();
lblStructure.GetAccessibilityProperties().SetRole(StandardRoles.LBL);
Paragraph labelContent = new Paragraph("Label with Link content");
labelContent.GetAccessibilityProperties().SetRole(StandardRoles.LINK);
lblStructure.Add(labelContent);
container.Add(lblStructure);
document.Add(container);
}
CompareAndValidate(outFile, cmpFile);
}
Expand Down Expand Up @@ -554,6 +669,26 @@ public virtual void CheckFormulaTest() {
public virtual void CheckBibliographicEntryTest() {
String outFile = DESTINATION_FOLDER + "bibliographicEntryTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_bibliographicEntryTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
Paragraph paragraph = new Paragraph("Bibliography paragraph:\n");
Paragraph bibliography = new Paragraph("1. Author A. Title of Book. Publisher, Year.");
bibliography.GetAccessibilityProperties().SetRole(StandardRoles.BIBENTRY).SetNamespace(new PdfNamespace(StandardNamespaces
.PDF_1_7));
paragraph.Add(bibliography);
document.Add(paragraph);
}
CompareAndValidate(outFile, cmpFile);
}

[NUnit.Framework.Test]
public virtual void CheckInvalidBibliographicStructureEntryTest() {
String outFile = DESTINATION_FOLDER + "invalidBibliographicStructureEntryTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0)))) {
Document document = new Document(pdfDocument);
Expand All @@ -569,9 +704,11 @@ public virtual void CheckBibliographicEntryTest() {
section.Add(bibliography);
document.Add(section);
}
CompareAndValidate(outFile, cmpFile);
// We expect failing validation because Sect shall not contain BibEntry and Span
new VeraPdfValidator().ValidateFailure(outFile);
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
public virtual void CheckMetadataNoTitleTest() {
String outFile = DESTINATION_FOLDER + "pdfuaMetadataNoTitleTest.pdf";
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 9eeb7c2

Please sign in to comment.