Skip to content

Commit a2d63d7

Browse files
committed
Custom ctor test and fix added
Fixed Bug when using custom ctor for custom java and verapdf locaiton
1 parent 84d55f2 commit a2d63d7

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

PDfAValidatorTest/PdfAValidatorTest.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,10 @@ public static void ShouldUnpackNewDirectoryInTempdirectory()
1313
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
1414
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
1515
{
16-
var listOfDirectoriesInTempWithVeraPdf = Directory.GetDirectories(Path.GetTempPath());
17-
var newDirectories = listOfDirectoriesInTempWithVeraPdf.Except(listOfDirectoriesInTempWithoutVeraPdf);
18-
19-
Assert.Equal(1, newDirectories.Count());
20-
var scriptPath = pdfAValidator.VeraPdfStarterScript;
21-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
22-
{
23-
Assert.Equal(".bat", scriptPath.Substring(scriptPath.Length - 4));
24-
}
25-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
26-
{
27-
Assert.Equal("verapdf", scriptPath.Substring(scriptPath.Length - 7));
28-
}
29-
Assert.True(File.Exists(scriptPath), scriptPath + " does not exist.");
16+
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
3017
}
3118
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());
3219
Assert.Equal(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
33-
3420
}
3521

3622
[Fact]
@@ -78,5 +64,42 @@ public static void ShouldGetDetailedReportFromNonCompliantPdfA()
7864
Assert.True(result.jobs.job.validationReport.profileName == "PDF/A-1B validation profile");
7965
}
8066
}
67+
68+
[Fact]
69+
public static void ShouldWorkWithCustomJavaAndVeraPdfLocation()
70+
{
71+
// Using default ctor to get verapdf and java bins for the test
72+
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
73+
using (var pdfAValidatorPrepareBins = new PdfAValidator.PdfAValidator())
74+
{
75+
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStarterScript, pdfAValidatorPrepareBins.PathJava))
76+
{
77+
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
78+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
79+
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
80+
Assert.False(result);
81+
}
82+
}
83+
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());
84+
Assert.Equal(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
85+
}
86+
87+
private static void AssertVeraPdfBinCreation(string[] listOfDirectoriesInTempWithoutVeraPdf, PdfAValidator.PdfAValidator pdfAValidator)
88+
{
89+
var listOfDirectoriesInTempWithVeraPdf = Directory.GetDirectories(Path.GetTempPath());
90+
var newDirectories = listOfDirectoriesInTempWithVeraPdf.Except(listOfDirectoriesInTempWithoutVeraPdf);
91+
92+
Assert.Single(newDirectories);
93+
var scriptPath = pdfAValidator.VeraPdfStarterScript;
94+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
95+
{
96+
Assert.Equal(".bat", scriptPath.Substring(scriptPath.Length - 4));
97+
}
98+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
99+
{
100+
Assert.Equal("verapdf", scriptPath.Substring(scriptPath.Length - 7));
101+
}
102+
Assert.True(File.Exists(scriptPath), scriptPath + " does not exist.");
103+
}
81104
}
82105
}

PdfAValidator/PdfAValidator.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
using System.Threading.Tasks;
88
using System.Xml.Serialization;
99

10-
// TODOS:
11-
// Fix the generated casing in report.cs
10+
// TODO Fix the generated casing in report.cs
1211

1312
namespace PdfAValidator
1413
{
1514
public class PdfAValidator : IDisposable
1615
{
1716
public void Dispose()
1817
{
19-
Directory.Delete(_pathVeraPdfDirectory, true);
18+
if (!_customVerapdfAndJavaLocations)
19+
Directory.Delete(_pathVeraPdfDirectory, true);
2020
}
2121

2222
/// <summary>
@@ -25,9 +25,9 @@ public void Dispose()
2525
/// <param name="pathToVeraPdfBin"></param>
2626
public PdfAValidator(string pathToVeraPdfBin, string pathToJava)
2727
{
28-
// TODO Test
2928
VeraPdfStarterScript = pathToVeraPdfBin;
3029
PathJava = pathToJava;
30+
_customVerapdfAndJavaLocations = true;
3131
}
3232

3333
/// <summary>
@@ -36,8 +36,12 @@ public PdfAValidator(string pathToVeraPdfBin, string pathToJava)
3636
public PdfAValidator()
3737
{ intiPathToVeraPdfBinAndJava(); }
3838

39+
private const string maskedQuote = "\"";
3940
private string _pathVeraPdfDirectory;
4041
public string PathJava { private set; get; }
42+
43+
private bool _customVerapdfAndJavaLocations;
44+
4145
public string VeraPdfStarterScript { private set; get; }
4246

4347
public bool Validate(string pathToPdfFile)
@@ -47,7 +51,7 @@ public bool Validate(string pathToPdfFile)
4751

4852
public report ValidateWithDetailedReport(string pathToPdfFile)
4953
{
50-
var absolutePathToPdfFile = System.IO.Path.GetFullPath(pathToPdfFile);
54+
var absolutePathToPdfFile = Path.GetFullPath(pathToPdfFile);
5155

5256
if (!File.Exists(absolutePathToPdfFile))
5357
{
@@ -66,7 +70,8 @@ public report ValidateWithDetailedReport(string pathToPdfFile)
6670
process.StartInfo.EnvironmentVariables["JAVACMD"] = PathJava;
6771
}
6872
var startInfo = process.StartInfo;
69-
var arguments = new[] { "\"", absolutePathToPdfFile, "\" " };
73+
// http://docs.verapdf.org/cli/terminal/
74+
var arguments = new[] { maskedQuote, absolutePathToPdfFile, maskedQuote };
7075
startInfo.Arguments = string.Concat(arguments);
7176
process.Start();
7277

@@ -93,7 +98,7 @@ private static string GetStreamOutput(StreamReader stream)
9398
return outputReadTask.Result;
9499
}
95100

96-
static T DeserializeXml<T>(string sourceXML) where T : class
101+
private static T DeserializeXml<T>(string sourceXML) where T : class
97102
{
98103
var serializer = new XmlSerializer(typeof(T));
99104
T result = null;
@@ -106,7 +111,7 @@ static T DeserializeXml<T>(string sourceXML) where T : class
106111
public static void SetLinuxFileExecuteable(string filePath)
107112
{
108113
var chmodCmd = "chmod 700 " + filePath;
109-
var escapedArgs = chmodCmd.Replace("\"", "\\\"");
114+
var escapedArgs = chmodCmd.Replace(maskedQuote, "\\\"");
110115

111116
var process = new Process
112117
{

PdfAValidator/PdfAValidator.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
<License>AGPL</License>
88
<Authors>Stefan Seeland</Authors>
99
<Company>Codeuctivity</Company>
10-
<AssemblyVersion>1.0.0.17</AssemblyVersion>
11-
<FileVersion>1.0.0.17</FileVersion>
12-
<Version>1.0.17</Version>
10+
<AssemblyVersion>1.0.0.18</AssemblyVersion>
11+
<FileVersion>1.0.0.18</FileVersion>
12+
<Version>1.0.18</Version>
1313
<PackageIconUrl>https://avatars3.githubusercontent.com/u/8453155?v=2&amp;s=200</PackageIconUrl>
1414
<PackageProjectUrl>https://github.com/Codeuctivity/PdfAValidatorApi</PackageProjectUrl>
1515
<Description>PdfAValidator is based on VeraPdf and is an open source conformance checker for PDF/A files. It is designed to help archives and libraries check that their PDF/A collections conform to the appropriate ISO 19005 archiving standard specification.</Description>
16+
<PackageLicenseExpression>AGPL</PackageLicenseExpression>
1617
</PropertyGroup>
1718

1819
<ItemGroup>

0 commit comments

Comments
 (0)