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 Oct 16, 2024
2 parents 1710ff9 + 21c37b5 commit 09ef468
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 194 deletions.
59 changes: 7 additions & 52 deletions itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 System.Collections.Generic;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Image;
Expand All @@ -32,6 +33,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.Pdf.Annot;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Filespec;
using iText.Kernel.Pdf.Layer;
using iText.Kernel.Pdf.Navigation;
using iText.Kernel.Pdf.Tagging;
using iText.Kernel.Pdf.Xobject;
Expand Down Expand Up @@ -530,60 +532,13 @@ public virtual void GetDefaultConformanceLevelTest() {
NUnit.Framework.Assert.IsFalse(document.GetConformance().IsPdfAOrUa());
}

//TODO DEVSIX-8490 remove this test when implemented
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.DUPLICATE_ENTRIES_IN_ORDER_ARRAY_REMOVED)]
public virtual void RemoveDuplicatesInOrderArrayTest() {
String inputPdf = "removeDuplicatesInOrderArray.pdf";
String outputPdf = "removedDuplicateInOrderArray.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter
(DESTINATION_FOLDER + outputPdf));
//Need to update OCProperties
doc.GetCatalog().GetOCProperties(false);
public virtual void OcgWithTwoParentsTest() {
String inputPdf = "ocgWithTwoParents.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf));
IList<PdfLayer> layerList = doc.GetCatalog().GetOCProperties(false).GetLayers();
NUnit.Framework.Assert.AreEqual(2, layerList[4].GetParents().Count);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + outputPdf, SOURCE_FOLDER
+ "cmp_" + outputPdf, DESTINATION_FOLDER));
}

//TODO DEVSIX-8490 remove this test when implemented
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.DUPLICATE_ENTRIES_IN_ORDER_ARRAY_REMOVED)]
public virtual void RemoveNestedDuplicatesInOrderArrayTest() {
String inputPdf = "removeNestedDuplicatesInOrderArray.pdf";
String outputPdf = "removedNestedDuplicatesInOrderArray.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), new PdfWriter(DESTINATION_FOLDER
+ outputPdf));
//Need to update OCProperties
doc.GetCatalog().GetOCProperties(false);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + outputPdf, SOURCE_FOLDER
+ "cmp_" + outputPdf, DESTINATION_FOLDER));
}

//TODO DEVSIX-8490 remove this test when implemented
[NUnit.Framework.Test]
public virtual void RemoveDuplicatesHasChildInOrderArrayTest() {
String inputPdf = "removeDuplicatesHasChildInOrderArray.pdf";
String outputPdf = "removedDuplicatesHasChildInOrderArray.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter
(DESTINATION_FOLDER + outputPdf));
PdfCatalog catalog = doc.GetCatalog();
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => catalog.GetOCProperties(false));
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER
, "4 0 R"), e.Message);
}

//TODO DEVSIX-8490 remove this test when implemented
[NUnit.Framework.Test]
public virtual void RemoveNestedDuplicatesHasChildInOrderArrayTest() {
String inputPdf = "removeNestedDuplicatesHasChildInOrderArray.pdf";
String outputPdf = "removedNestedDuplicatesHasChildInOrderArray.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + inputPdf), CompareTool.CreateTestPdfWriter
(DESTINATION_FOLDER + outputPdf));
PdfCatalog catalog = doc.GetCatalog();
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => catalog.GetOCProperties(false));
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_REMOVE_DUPLICATE_LAYER
, "27 0 R"), e.Message);
}

[NUnit.Framework.Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Utils;
using iText.IO.Font.Constants;
using iText.IO.Source;
using iText.Kernel.Exceptions;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
Expand Down Expand Up @@ -466,21 +465,69 @@ public virtual void TestReadOcgFromApAnnotation() {
}
}

//TODO DEVSIX-8490 remove this test when implemented
[NUnit.Framework.Test]
public virtual void AddSecondParentlayerTest() {
using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
using (PdfDocument doc = new PdfDocument(new PdfWriter(outputStream))) {
PdfLayer childLayer = new PdfLayer("childLayer", doc);
PdfLayer parentLayer1 = new PdfLayer("firstParentLayer", doc);
PdfLayer parentLayer2 = new PdfLayer("secondParentLayer", doc);
parentLayer1.AddChild(childLayer);
PdfIndirectReference @ref = childLayer.GetIndirectReference();
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => parentLayer2.AddChild(childLayer));
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNABLE_TO_ADD_SECOND_PARENT_LAYER
, @ref.ToString()), e.Message);
}
}
public virtual void NestedLayerTwoParentsTest() {
String outPdf = destinationFolder + "nestedLayerTwoParents.pdf";
String cmpPdf = sourceFolder + "cmp_nestedLayerTwoParents.pdf";
PdfDocument pdfDoc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf));
PdfFont font = PdfFontFactory.CreateFont();
PdfLayer parentLayer1 = new PdfLayer("Parent layer 1", pdfDoc);
PdfLayer parentLayer2 = new PdfLayer("Parent layer 2", pdfDoc);
PdfLayer nestedLayer = new PdfLayer("Nested layer 1", pdfDoc);
parentLayer1.AddChild(nestedLayer);
parentLayer2.AddChild(nestedLayer);
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
canvas.SetFontAndSize(font, 12);
PdfLayerTestUtils.AddTextInsideLayer(parentLayer1, canvas, "Parent layer 1 text", 50, 750);
PdfLayerTestUtils.AddTextInsideLayer(parentLayer2, canvas, "Parent layer 2 text", 50, 700);
PdfLayerTestUtils.AddTextInsideLayer(nestedLayer, canvas, "Nested layer 1 text", 100, 650);
canvas.Release();
pdfDoc.Close();
PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
}

[NUnit.Framework.Test]
public virtual void NestedLayerTwoParentsWithOneParentTest() {
String outPdf = destinationFolder + "nestedLayerTwoParentsWithOneParent.pdf";
String cmpPdf = sourceFolder + "cmp_nestedLayerTwoParentsWithOneParent.pdf";
PdfDocument pdfDoc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf));
PdfFont font = PdfFontFactory.CreateFont();
PdfLayer parentLayer = new PdfLayer("Parent layer", pdfDoc);
PdfLayer layer1 = new PdfLayer("Layer 1", pdfDoc);
PdfLayer layer2 = new PdfLayer("Layer 2", pdfDoc);
PdfLayer nestedLayer = new PdfLayer("Nested layer 1", pdfDoc);
layer1.AddChild(nestedLayer);
layer2.AddChild(nestedLayer);
parentLayer.AddChild(layer1);
parentLayer.AddChild(layer2);
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
canvas.SetFontAndSize(font, 12);
PdfLayerTestUtils.AddTextInsideLayer(parentLayer, canvas, "Parent layer text", 50, 750);
PdfLayerTestUtils.AddTextInsideLayer(layer1, canvas, "layer 1 text", 100, 700);
PdfLayerTestUtils.AddTextInsideLayer(layer2, canvas, "layer 2 text", 100, 650);
PdfLayerTestUtils.AddTextInsideLayer(nestedLayer, canvas, "Nested layer text", 150, 600);
canvas.Release();
pdfDoc.Close();
PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
}

[NUnit.Framework.Test]
public virtual void DuplicatedNestedLayersTest() {
String outPdf = destinationFolder + "duplicatedNestedLayers.pdf";
String cmpPdf = sourceFolder + "cmp_duplicatedNestedLayers.pdf";
PdfDocument pdfDoc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf));
PdfFont font = PdfFontFactory.CreateFont();
PdfLayer parentLayer = new PdfLayer("Parent layer", pdfDoc);
PdfLayer nestedLayer1 = new PdfLayer("Nested layer", pdfDoc);
parentLayer.AddChild(nestedLayer1);
parentLayer.AddChild(nestedLayer1);
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
canvas.SetFontAndSize(font, 12);
PdfLayerTestUtils.AddTextInsideLayer(parentLayer, canvas, "Parent layer text", 50, 750);
PdfLayerTestUtils.AddTextInsideLayer(nestedLayer1, canvas, "Nested layer text", 100, 700);
canvas.Release();
pdfDoc.Close();
PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
}
}
}
Loading

0 comments on commit 09ef468

Please sign in to comment.