Skip to content

Commit bc77af2

Browse files
Veronika Lisovskayayulian-gaponenko
authored andcommitted
Add test for check resources released after conversion
DEVSIX-2314 Autoported commit. Original commit hash: [635d7abc38]
1 parent 61fdbaa commit bc77af2

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

itext.tests/itext.html2pdf.tests/itext/html2pdf/resolver/font/LocalFontResolverReleaseTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public virtual void TestThatLocalFontIsReleasedAfterConversion() {
3737
HtmlConverter.ConvertToPdf(new FileInfo(workDirHtmlFile), new FileInfo(targetPdfFile));
3838
}
3939
// The resource must be freed after the conversion
40-
FileInfo resourceToBeremoved = new FileInfo(workDirFontFile);
41-
resourceToBeremoved.Delete();
42-
NUnit.Framework.Assert.IsFalse(resourceToBeremoved.Exists);
40+
FileInfo resourceToBeRemoved = new FileInfo(workDirFontFile);
41+
resourceToBeRemoved.Delete();
42+
NUnit.Framework.Assert.IsFalse(resourceToBeRemoved.Exists);
4343
}
4444
}
4545
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.IO;
3+
using iText.Html2pdf;
4+
using iText.Test;
5+
using iText.Test.Attributes;
6+
7+
namespace iText.Html2pdf.Resolver.Resource {
8+
public class LocalImageResolverReleaseTest : ExtendedITextTest {
9+
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
10+
.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/resolver/resource/LocalImageResolverReleaseTest/";
11+
12+
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
13+
+ "/test/itext/html2pdf/resolver/resource/LocalImageResolverReleaseTest/";
14+
15+
[NUnit.Framework.OneTimeSetUp]
16+
public static void BeforeClass() {
17+
CreateOrClearDestinationFolder(destinationFolder);
18+
}
19+
20+
/// <exception cref="System.IO.IOException"/>
21+
[NUnit.Framework.Test]
22+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES, Count = 60)]
23+
public virtual void TestThatSvgIsReleasedAfterConversion() {
24+
String htmlFileName = "testWithSvg.html";
25+
String svgFileName = "imageWithMultipleShapes.svg";
26+
String imageFileName = "image.png";
27+
String sourceHtmlFile = sourceFolder + htmlFileName;
28+
String sourceSvgFile = sourceFolder + svgFileName;
29+
String sourceImageFile = sourceFolder + imageFileName;
30+
String workDir = destinationFolder + "work/";
31+
CreateDestinationFolder(workDir);
32+
String targetPdfFile = workDir + "target.pdf";
33+
String workDirHtmlFile = workDir + htmlFileName;
34+
String workDirSvgFile = workDir + svgFileName;
35+
String workDirImageFile = workDir + imageFileName;
36+
File.Copy(Path.Combine(sourceHtmlFile), Path.Combine(workDirHtmlFile));
37+
File.Copy(Path.Combine(sourceSvgFile), Path.Combine(workDirSvgFile));
38+
File.Copy(Path.Combine(sourceImageFile), Path.Combine(workDirImageFile));
39+
for (int i = 0; i < 10; i++) {
40+
HtmlConverter.ConvertToPdf(new FileInfo(workDirHtmlFile), new FileInfo(targetPdfFile));
41+
}
42+
// The resource must be freed after the conversion
43+
FileInfo resourceToBeRemoved = new FileInfo(workDirSvgFile);
44+
resourceToBeRemoved.Delete();
45+
NUnit.Framework.Assert.IsFalse(resourceToBeRemoved.Exists);
46+
resourceToBeRemoved = new FileInfo(workDirImageFile);
47+
resourceToBeRemoved.Delete();
48+
NUnit.Framework.Assert.IsFalse(resourceToBeRemoved.Exists);
49+
}
50+
}
51+
}
3.75 KB
Loading
Lines changed: 5 additions & 0 deletions
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Example</title>
5+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
6+
</head>
7+
8+
<body>
9+
<h1>images within html</h1>
10+
<p> Example SVG Image</p>
11+
<img src="imageWithMultipleShapes.svg"/>
12+
<p>Example Object1</p>
13+
<object data="imageWithMultipleShapes.svg" type="image/svg+xml"></object>
14+
<p> Example Image</p>
15+
<img src="image.png"/>
16+
</body>
17+
</html>

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fe2dd856e0f77647614a62a231148acdf0d9499e
1+
635d7abc3812b211d8d1f46af80c61e6f7a6f9ba

0 commit comments

Comments
 (0)