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 10, 2023
2 parents c72f1de + bcb61de commit ad7975d
Show file tree
Hide file tree
Showing 36 changed files with 1,577 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using iText.Test;

namespace iText.Commons.Datastructures {
[NUnit.Framework.Category("UnitTest")]
public class Tuple2Test : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void TestTuple2_StringInt() {
Tuple2<String, int> tuple = new Tuple2<String, int>("test", 1);
NUnit.Framework.Assert.AreEqual("test", tuple.GetFirst());
NUnit.Framework.Assert.AreEqual(Convert.ToInt32(1), tuple.GetSecond());
}

[NUnit.Framework.Test]
public virtual void TestTuple2_ToString() {
Tuple2<String, int> tuple = new Tuple2<String, int>("test", 1);
NUnit.Framework.Assert.AreEqual("Tuple2{first=test, second=1}", tuple.ToString());
}

[NUnit.Framework.Test]
public virtual void TestTuple2_TestWithNullFirstValue() {
Tuple2<String, int> tuple = new Tuple2<String, int>(null, 1);
NUnit.Framework.Assert.IsNull(tuple.GetFirst());
NUnit.Framework.Assert.AreEqual(Convert.ToInt32(1), tuple.GetSecond());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.Logs;
using iText.Kernel.Pdf.Filespec;
using iText.Kernel.Pdf.Layer;
using iText.Kernel.Utils;
using iText.Test;
using iText.Test.Attributes;

Expand Down Expand Up @@ -208,7 +209,7 @@ public virtual void PdfDocumentInstanceWriterInfoAndConformanceLevelInitializati

[NUnit.Framework.Test]
public virtual void ExtendedPdfDocumentNoWriterInfoAndConformanceLevelInitialization() {
PdfDocument pdfDocument = new _PdfDocument_247(new PdfReader(SOURCE_FOLDER + "pdfWithMetadata.pdf"));
PdfDocument pdfDocument = new _PdfDocument_251(new PdfReader(SOURCE_FOLDER + "pdfWithMetadata.pdf"));
// This class instance extends pdfDocument
// TODO DEVSIX-5292 These fields shouldn't be initialized during the document's opening
NUnit.Framework.Assert.IsNotNull(pdfDocument.info);
Expand All @@ -218,15 +219,15 @@ public virtual void ExtendedPdfDocumentNoWriterInfoAndConformanceLevelInitializa
NUnit.Framework.Assert.IsNotNull(pdfDocument.reader.pdfAConformanceLevel);
}

private sealed class _PdfDocument_247 : PdfDocument {
public _PdfDocument_247(PdfReader baseArg1)
private sealed class _PdfDocument_251 : PdfDocument {
public _PdfDocument_251(PdfReader baseArg1)
: base(baseArg1) {
}
}

[NUnit.Framework.Test]
public virtual void ExtendedPdfDocumentWriterInfoAndConformanceLevelInitialization() {
PdfDocument pdfDocument = new _PdfDocument_264(new PdfReader(SOURCE_FOLDER + "pdfWithMetadata.pdf"), new PdfWriter
PdfDocument pdfDocument = new _PdfDocument_268(new PdfReader(SOURCE_FOLDER + "pdfWithMetadata.pdf"), new PdfWriter
(new ByteArrayOutputStream()));
// This class instance extends pdfDocument
NUnit.Framework.Assert.IsNotNull(pdfDocument.info);
Expand All @@ -237,8 +238,8 @@ public virtual void ExtendedPdfDocumentWriterInfoAndConformanceLevelInitializati
NUnit.Framework.Assert.IsNotNull(pdfDocument.reader.pdfAConformanceLevel);
}

private sealed class _PdfDocument_264 : PdfDocument {
public _PdfDocument_264(PdfReader baseArg1, PdfWriter baseArg2)
private sealed class _PdfDocument_268 : PdfDocument {
public _PdfDocument_268(PdfReader baseArg1, PdfWriter baseArg2)
: base(baseArg1, baseArg2) {
}
}
Expand Down Expand Up @@ -405,5 +406,40 @@ public virtual void CannotSetEncryptedPayloadToEncryptedDocTest() {
NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.CANNOT_SET_ENCRYPTED_PAYLOAD_TO_ENCRYPTED_DOCUMENT
, exception.Message);
}

[NUnit.Framework.Test]
public virtual void CheckEmptyIsoConformanceTest() {
using (PdfDocument doc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()))) {
NUnit.Framework.Assert.DoesNotThrow(() => doc.CheckIsoConformance());
}
}

[NUnit.Framework.Test]
public virtual void CheckIsoConformanceTest() {
using (PdfDocument doc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()))) {
ValidationContainer container = new ValidationContainer();
PdfDocumentUnitTest.CustomValidationChecker checker = new PdfDocumentUnitTest.CustomValidationChecker();
container.AddChecker(checker);
doc.GetDiContainer().Register(typeof(ValidationContainer), container);
NUnit.Framework.Assert.IsFalse(checker.documentValidationPerformed);
doc.CheckIsoConformance();
NUnit.Framework.Assert.IsTrue(checker.documentValidationPerformed);
}
}

private class CustomValidationChecker : IValidationChecker {
public bool documentValidationPerformed = false;

public bool objectValidationPerformed = false;

public virtual void ValidateDocument(ValidationContext validationContext) {
documentValidationPerformed = true;
}

public virtual void ValidateObject(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream
, Object extra) {
objectValidationPerformed = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using iText.Kernel.Pdf;
using iText.Test;

namespace iText.Kernel.Utils {
[NUnit.Framework.Category("UnitTest")]
public class ValidationContainerTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void ValidateObjectTest() {
ValidationContainer container = new ValidationContainer();
container.Validate(null, IsoKey.FONT, null, null, null);
ValidationContainerTest.CustomValidationChecker checker = new ValidationContainerTest.CustomValidationChecker
();
container.AddChecker(checker);
NUnit.Framework.Assert.IsTrue(container.ContainsChecker(checker));
NUnit.Framework.Assert.IsFalse(checker.objectValidationPerformed);
container.Validate(null, IsoKey.FONT, null, null, null);
NUnit.Framework.Assert.IsTrue(checker.objectValidationPerformed);
}

[NUnit.Framework.Test]
public virtual void ValidateDocumentTest() {
ValidationContainer container = new ValidationContainer();
ValidationContext context = new ValidationContext().WithPdfDocument(null);
container.Validate(context);
ValidationContainerTest.CustomValidationChecker checker = new ValidationContainerTest.CustomValidationChecker
();
container.AddChecker(checker);
NUnit.Framework.Assert.IsFalse(checker.documentValidationPerformed);
container.Validate(context);
NUnit.Framework.Assert.IsTrue(checker.documentValidationPerformed);
}

private class CustomValidationChecker : IValidationChecker {
public bool documentValidationPerformed = false;

public bool objectValidationPerformed = false;

public virtual void ValidateDocument(ValidationContext validationContext) {
documentValidationPerformed = true;
}

public virtual void ValidateObject(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream
, Object extra) {
objectValidationPerformed = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using iText.IO.Source;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Test;

namespace iText.Kernel.Utils {
[NUnit.Framework.Category("UnitTest")]
public class ValidationContextTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void WithDocumentsCheckTest() {
ValidationContext context = new ValidationContext();
NUnit.Framework.Assert.IsNull(context.GetPdfDocument());
context.WithPdfDocument(new PdfDocument(new PdfWriter(new ByteArrayOutputStream())));
NUnit.Framework.Assert.IsNotNull(context.GetPdfDocument());
}

[NUnit.Framework.Test]
public virtual void WithFontsCheckTest() {
ValidationContext context = new ValidationContext();
NUnit.Framework.Assert.IsNull(context.GetFonts());
IList<PdfFont> fonts = new List<PdfFont>();
context.WithFonts(fonts);
NUnit.Framework.Assert.IsNotNull(context.GetFonts());
}
}
}
33 changes: 33 additions & 0 deletions itext.tests/itext.pdfa.tests/itext/pdfa/PdfAFlushingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.IO;
using iText.IO.Image;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Xobject;
using iText.Kernel.Utils;
using iText.Layout;
using iText.Layout.Element;
using iText.Pdfa.Logs;
using iText.Test;
using iText.Test.Attributes;
using iText.Test.Pdfa;

namespace iText.Pdfa {
[NUnit.Framework.Category("IntegrationTest")]
Expand Down Expand Up @@ -110,6 +114,35 @@ public virtual void FlushingTest03() {
CompareResult(outPdf, cmpPdf);
}

[NUnit.Framework.Test]
[LogMessage(PdfALogMessageConstant.PDFA_OBJECT_FLUSHING_WAS_NOT_PERFORMED, LogLevel = LogLevelConstants.WARN
)]
public virtual void TryToFlushFontTest() {
String outPdf = destinationFolder + "tryToFlushFontTest.pdf";
String cmpPdf = sourceFolder + "cmp_tryToFlushFontTest.pdf";
PdfWriter writer = new PdfWriter(outPdf, new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0));
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
PdfADocument pdfDoc = (PdfADocument)new PdfADocument(writer, PdfAConformanceLevel.PDF_A_4, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", @is)).SetTagged();
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
font.MakeIndirect(pdfDoc);
Document document = new Document(pdfDoc);
document.SetFont(font);
List list = new List();
list.Add("123");
// nothing happen (only log message was written)
font.Flush();
document.Add(list);
NUnit.Framework.Assert.AreEqual(PdfVersion.PDF_2_0, pdfDoc.GetTagStructureContext().GetTagStructureTargetVersion
());
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff"
));
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Test]
[LogMessage(PdfALogMessageConstant.PDFA_OBJECT_FLUSHING_WAS_NOT_PERFORMED)]
public virtual void AddUnusedStreamObjectsTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfAFormFieldTest : ExtendedITextTest {
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down Expand Up @@ -559,6 +558,7 @@ public virtual void TestCopyPagesDoesntEmbedHelveticaFont() {
docToCopy.Close();
doc2.Close();
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmp, DESTINATION_FOLDER, "diff_")
);
}
Expand Down
Binary file not shown.
24 changes: 24 additions & 0 deletions itext.tests/itext.pdfua.tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("iText.Pdfua.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Apryse Group NV")]
[assembly: AssemblyProduct("iText")]
[assembly: AssemblyCopyright("Copyright (c) 1998-2023 Apryse Group NV")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("f542854e-7f6b-4207-b6ca-004a5d266e65")]

[assembly: AssemblyVersion("8.0.3.0")]
[assembly: AssemblyFileVersion("8.0.3.0")]
[assembly: AssemblyInformationalVersion("8.0.3-SNAPSHOT")]

#if !NETSTANDARD2_0
[assembly: NUnit.Framework.Timeout(300000)]
#endif
Loading

0 comments on commit ad7975d

Please sign in to comment.