Skip to content

Commit 59e665a

Browse files
committed
more tests
1 parent 57bcfce commit 59e665a

File tree

5 files changed

+150
-0
lines changed

5 files changed

+150
-0
lines changed

PdfAValidator.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfAValidatorWebApi", "PdfA
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfAValidatorTestFramework", "PdfAValidatorFrameworkTest\PdfAValidatorTestFramework.csproj", "{F1D60FEF-DF9D-48EB-B94D-1CB1293A0E82}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfAValidatorTestCore2.2", "PdfAValidatorTestCore2.2\PdfAValidatorTestCore2.2.csproj", "{8A1F6818-3854-418B-9ECD-F35EC3558AAC}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
3335
{F1D60FEF-DF9D-48EB-B94D-1CB1293A0E82}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{F1D60FEF-DF9D-48EB-B94D-1CB1293A0E82}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{F1D60FEF-DF9D-48EB-B94D-1CB1293A0E82}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{8A1F6818-3854-418B-9ECD-F35EC3558AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{8A1F6818-3854-418B-9ECD-F35EC3558AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{8A1F6818-3854-418B-9ECD-F35EC3558AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{8A1F6818-3854-418B-9ECD-F35EC3558AAC}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using Xunit;
6+
7+
namespace PdfAValidatorTestCore2._2
8+
{
9+
public static class PdfAValidatorTest
10+
{
11+
[Fact]
12+
public static void ShouldUnpackNewDirectoryInTempdirectory()
13+
{
14+
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
15+
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
16+
{
17+
pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOffice.pdf");
18+
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
19+
}
20+
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());
21+
Assert.Equal(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
22+
}
23+
24+
[Fact]
25+
public static void ShouldDetectCompliantPdfA()
26+
{
27+
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
28+
{
29+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOffice.pdf"));
30+
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOffice.pdf");
31+
Assert.True(result);
32+
}
33+
}
34+
35+
[Fact]
36+
public static void ShouldGetDetailedReportFromPdfA()
37+
{
38+
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
39+
{
40+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOffice.pdf"));
41+
var result = pdfAValidator.ValidateWithDetailedReport(@"./TestPdfFiles/FromLibreOffice.pdf");
42+
Assert.True(result.jobs.job.validationReport.isCompliant);
43+
Assert.True(result.jobs.job.validationReport.profileName == "PDF/A-1A validation profile");
44+
}
45+
}
46+
47+
[Fact]
48+
public static void ShouldDetectNonCompliantPdfA()
49+
{
50+
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
51+
{
52+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
53+
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
54+
Assert.False(result);
55+
}
56+
}
57+
58+
[Fact]
59+
public static void ShouldGetDetailedReportFromNonCompliantPdfA()
60+
{
61+
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
62+
{
63+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
64+
var result = pdfAValidator.ValidateWithDetailedReport(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
65+
Assert.False(result.jobs.job.validationReport.isCompliant);
66+
Assert.True(result.jobs.job.validationReport.profileName == "PDF/A-1B validation profile");
67+
}
68+
}
69+
70+
[Fact]
71+
public static void ShouldWorkWithCustomJavaAndVeraPdfLocation()
72+
{
73+
// Using default ctor to get verapdf and java bins for the test
74+
var listOfDirectoriesInTempWithoutVeraPdf = Directory.GetDirectories(Path.GetTempPath());
75+
using (var pdfAValidatorPrepareBins = new PdfAValidator.PdfAValidator())
76+
{
77+
{
78+
pdfAValidatorPrepareBins.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
79+
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStartScript, pdfAValidatorPrepareBins.PathJava))
80+
{
81+
AssertVeraPdfBinCreation(listOfDirectoriesInTempWithoutVeraPdf, pdfAValidator);
82+
Assert.True(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
83+
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
84+
Assert.False(result);
85+
}
86+
}
87+
}
88+
var listOfDirectoriesInTempAfterVeraPdf = Directory.GetDirectories(Path.GetTempPath());
89+
Assert.Equal(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
90+
}
91+
92+
private static void AssertVeraPdfBinCreation(string[] listOfDirectoriesInTempWithoutVeraPdf, PdfAValidator.PdfAValidator pdfAValidator)
93+
{
94+
var listOfDirectoriesInTempWithVeraPdf = Directory.GetDirectories(Path.GetTempPath());
95+
var newDirectories = listOfDirectoriesInTempWithVeraPdf.Except(listOfDirectoriesInTempWithoutVeraPdf);
96+
97+
Assert.Single(newDirectories);
98+
var scriptPath = pdfAValidator.VeraPdfStartScript;
99+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
100+
{
101+
Assert.Equal(".bat", scriptPath.Substring(scriptPath.Length - 4));
102+
}
103+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
104+
{
105+
Assert.Equal("verapdf", scriptPath.Substring(scriptPath.Length - 7));
106+
}
107+
Assert.True(File.Exists(scriptPath), scriptPath + " does not exist.");
108+
}
109+
}
110+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<RootNamespace>PdfAValidatorTestCore2._2</RootNamespace>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Remove="TestPdfFiles\FromLibreOffice.pdf" />
12+
<None Remove="TestPdfFiles\FromLibreOfficeNonPdfA.pdf" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Content Include="TestPdfFiles\FromLibreOffice.pdf">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</Content>
19+
<Content Include="TestPdfFiles\FromLibreOfficeNonPdfA.pdf">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</Content>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
26+
<PackageReference Include="xunit" Version="2.4.0" />
27+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="..\PdfAValidator\PdfAValidator.csproj" />
32+
</ItemGroup>
33+
34+
</Project>
29 KB
Binary file not shown.
16.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)