Skip to content

Commit 376dde3

Browse files
Kate IvanovaiText-CI
authored andcommitted
Add tests on copying page with widget annotations GoTo actions
DEVSIX-6356 Autoported commit. Original commit hash: [6d3b59538]
1 parent 997c30b commit 376dde3

8 files changed

+63
-17
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/copy/PdfAnnotationCopyingTest.cs

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,26 @@ You should have received a copy of the GNU Affero General Public License
3030
using iText.Kernel.Pdf.Navigation;
3131
using iText.Kernel.Utils;
3232
using iText.Test;
33+
using iText.Test.Attributes;
3334

3435
namespace iText.Kernel.Pdf.Copy {
3536
public class PdfAnnotationCopyingTest : ExtendedITextTest {
36-
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
37+
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
3738
+ "/test/itext/kernel/pdf/PdfAnnotationCopyingTest/";
3839

39-
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
40+
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
4041
.CurrentContext.TestDirectory) + "/resources/itext/kernel/pdf/PdfAnnotationCopyingTest/";
4142

4243
[NUnit.Framework.OneTimeSetUp]
4344
public static void BeforeClass() {
44-
CreateOrClearDestinationFolder(destinationFolder);
45+
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
4546
}
4647

4748
[NUnit.Framework.Test]
4849
[NUnit.Framework.Ignore("Unignore when DEVSIX-3585 would be implemented")]
4950
public virtual void TestCopyingPageWithAnnotationContainingPopupKey() {
50-
String inFilePath = sourceFolder + "annotation-with-popup.pdf";
51-
String outFilePath = destinationFolder + "copy-annotation-with-popup.pdf";
51+
String inFilePath = SOURCE_FOLDER + "annotation-with-popup.pdf";
52+
String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-popup.pdf";
5253
PdfDocument originalDocument = new PdfDocument(new PdfReader(inFilePath));
5354
PdfDocument outDocument = new PdfDocument(new PdfWriter(outFilePath));
5455
originalDocument.CopyPagesTo(1, 1, outDocument);
@@ -88,8 +89,8 @@ public virtual void TestCopyingPageWithAnnotationContainingPopupKey() {
8889
[NUnit.Framework.Test]
8990
[NUnit.Framework.Ignore("Unignore when DEVSIX-3585 would be implemented")]
9091
public virtual void TestCopyingPageWithAnnotationContainingIrtKey() {
91-
String inFilePath = sourceFolder + "annotation-with-irt.pdf";
92-
String outFilePath = destinationFolder + "copy-annotation-with-irt.pdf";
92+
String inFilePath = SOURCE_FOLDER + "annotation-with-irt.pdf";
93+
String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-irt.pdf";
9394
PdfDocument originalDocument = new PdfDocument(new PdfReader(inFilePath));
9495
PdfDocument outDocument = new PdfDocument(new PdfWriter(outFilePath));
9596
originalDocument.CopyPagesTo(1, 1, outDocument);
@@ -126,33 +127,62 @@ public virtual void TestCopyingPageWithAnnotationContainingIrtKey() {
126127
[NUnit.Framework.Test]
127128
public virtual void CopySameLinksWithGoToSmartModeTest() {
128129
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
129-
String cmpFilePath = sourceFolder + "cmp_copySameLinksWithGoToSmartMode.pdf";
130-
String outFilePath = destinationFolder + "copySameLinksWithGoToSmartMode.pdf";
130+
String cmpFilePath = SOURCE_FOLDER + "cmp_copySameLinksWithGoToSmartMode.pdf";
131+
String outFilePath = DESTINATION_FOLDER + "copySameLinksWithGoToSmartMode.pdf";
131132
CopyLinksGoToActionTest(outFilePath, true, false);
132-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, destinationFolder
133+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER
133134
));
134135
}
135136

136137
[NUnit.Framework.Test]
137138
public virtual void CopyDiffDestLinksWithGoToSmartModeTest() {
138139
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
139-
String cmpFilePath = sourceFolder + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf";
140-
String outFilePath = destinationFolder + "copyDiffDestLinksWithGoToSmartMode.pdf";
140+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf";
141+
String outFilePath = DESTINATION_FOLDER + "copyDiffDestLinksWithGoToSmartMode.pdf";
141142
CopyLinksGoToActionTest(outFilePath, false, false);
142-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, destinationFolder
143+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER
143144
));
144145
}
145146

146147
[NUnit.Framework.Test]
147148
public virtual void CopyDiffDisplayLinksWithGoToSmartModeTest() {
148149
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
149-
String cmpFilePath = sourceFolder + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf";
150-
String outFilePath = destinationFolder + "copyDiffDisplayLinksWithGoToSmartMode.pdf";
150+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf";
151+
String outFilePath = DESTINATION_FOLDER + "copyDiffDisplayLinksWithGoToSmartMode.pdf";
151152
CopyLinksGoToActionTest(outFilePath, false, true);
152-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, destinationFolder
153+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER
153154
));
154155
}
155156

157+
[NUnit.Framework.Test]
158+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
159+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
160+
public virtual void CopyPagesWithWidgetAnnotGoToActionExplicitDestTest() {
161+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionExplicitDest.pdf";
162+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf";
163+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf";
164+
CopyPages(srcFilePath, outFilePath, cmpFilePath);
165+
}
166+
167+
[NUnit.Framework.Test]
168+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
169+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
170+
public virtual void CopyPagesWithWidgetAnnotGoToActionNamedDestTest() {
171+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionNamedDest.pdf";
172+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionNamedDest.pdf";
173+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionNamedDest.pdf";
174+
CopyPages(srcFilePath, outFilePath, cmpFilePath);
175+
}
176+
177+
[NUnit.Framework.Test]
178+
public virtual void CopyPagesWithScreenAnnotGoToActionExplicitDestTest() {
179+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
180+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithScreenAnnotGoToActionExplicitDest.pdf";
181+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithScreenAnnotGoToActionExplicitDest.pdf";
182+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithScreenAnnotGoToActionExplicitDest.pdf";
183+
CopyPages(srcFilePath, outFilePath, cmpFilePath);
184+
}
185+
156186
private void CopyLinksGoToActionTest(String dest, bool isTheSameLinks, bool diffDisplayOptions) {
157187
PdfDocument destDoc = new PdfDocument(new PdfWriter(dest).SetSmartMode(true));
158188
MemoryStream sourceBaos1 = CreatePdfWithGoToAnnot(isTheSameLinks, diffDisplayOptions);
@@ -162,6 +192,22 @@ private void CopyLinksGoToActionTest(String dest, bool isTheSameLinks, bool diff
162192
destDoc.Close();
163193
}
164194

195+
private void CopyPages(String sourceFile, String outFilePath, String cmpFilePath) {
196+
using (PdfWriter writer = new PdfWriter(outFilePath)) {
197+
using (PdfDocument pdfDoc = new PdfDocument(writer)) {
198+
pdfDoc.AddNewPage();
199+
pdfDoc.AddNewPage();
200+
using (PdfReader reader = new PdfReader(sourceFile)) {
201+
using (PdfDocument srcDoc = new PdfDocument(reader)) {
202+
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdfDoc);
203+
}
204+
}
205+
}
206+
}
207+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER
208+
));
209+
}
210+
165211
private MemoryStream CreatePdfWithGoToAnnot(bool isTheSameLink, bool diffDisplayOptions) {
166212
MemoryStream stream = new MemoryStream();
167213
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(stream));

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
df1b9137637c362913d4064059626b6203ea9b0c
1+
6d3b5953878dac36d284359142b1f0404e6f4016

0 commit comments

Comments
 (0)