Skip to content

Commit

Permalink
Merge pull request #3 from Codeuctivity/AzurePipelines
Browse files Browse the repository at this point in the history
Azure pipelines found temp paht length bug - Fixed
  • Loading branch information
stesee authored Oct 7, 2019
2 parents 75983bd + 4fd6879 commit 3e160ca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
9 changes: 8 additions & 1 deletion PdfAValidator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfAValidatorWebApi", "PdfA
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfAValidatorTestFramework", "PdfAValidatorFrameworkTest\PdfAValidatorTestFramework.csproj", "{F1D60FEF-DF9D-48EB-B94D-1CB1293A0E82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfAValidatorTestCore2_2", "PdfAValidatorTestCore2_2\PdfAValidatorTestCore2_2.csproj", "{8A1F6818-3854-418B-9ECD-F35EC3558AAC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfAValidatorTestCore2_2", "PdfAValidatorTestCore2_2\PdfAValidatorTestCore2_2.csproj", "{8A1F6818-3854-418B-9ECD-F35EC3558AAC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49D9D2CB-EF79-4962-B4C3-2F1BAFD9DCC8}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
9 changes: 8 additions & 1 deletion PdfAValidator/PdfAValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace PdfAValidator
public class PdfAValidator : IDisposable
{
private const string maskedQuote = "\"";
private const int maxLenghtTempdirectoryThatVeraPdfFitsIn = 206;
private readonly object lockObject = new object();
private string pathVeraPdfDirectory;
private bool disposed;
Expand Down Expand Up @@ -172,7 +173,12 @@ private void IntiPathToVeraPdfBinAndJava()
return;
}

pathVeraPdfDirectory = Path.Combine(Path.GetTempPath(), "VeraPdf" + Guid.NewGuid());
pathVeraPdfDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
if (pathVeraPdfDirectory.Length > maxLenghtTempdirectoryThatVeraPdfFitsIn)
{
throw new PathTooLongException(pathVeraPdfDirectory);
}

Directory.CreateDirectory(pathVeraPdfDirectory);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down Expand Up @@ -230,6 +236,7 @@ private void ExtractBinaryFromManifest(string resourceName)
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}

ZipFile.ExtractToDirectory(pathZipVeraPdf, pathVeraPdfDirectory);
}
}
Expand Down
44 changes: 18 additions & 26 deletions PdfAValidatorFrameworkTest/PdfAValidatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Linq;

namespace PdfAValidatorTest
{
[TestClass]
public class PdfAValidatorTest
{
private string tempPath;

[TestInitialize]
public void InitialThings()
{ tempPath = Path.GetTempPath(); }
private string veraPdfStartScript;

[TestMethod]
public void ShouldUnpackNewDirectoryInTempdirectory()
{
var listOfDirectoriesInTempWithoutVeraPdf = GetListOfDirectoriesInTempExceptDirectoriesCreatedByAppVeyor();
using (var pdfAValidator = new PdfAValidator.PdfAValidator())
{
pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOffice.pdf");
AssertVeraPdfBinCreation(pdfAValidator.VeraPdfStartScript);
veraPdfStartScript = pdfAValidator.VeraPdfStartScript;
AssertVeraPdfBinCreation(veraPdfStartScript);
}
var listOfDirectoriesInTempAfterVeraPdf = GetListOfDirectoriesInTempExceptDirectoriesCreatedByAppVeyor();
Assert.AreEqual(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
AssertVeraPdfGotDisposed();
}

[TestMethod]
Expand Down Expand Up @@ -76,33 +70,36 @@ public void ShouldGetDetailedReportFromNonCompliantPdfA()
public void ShouldWorkWithCustomJavaAndVeraPdfLocation()
{
// Using default ctor to get verapdf and java bins for the test
var listOfDirectoriesInTempWithoutVeraPdf = GetListOfDirectoriesInTempExceptDirectoriesCreatedByAppVeyor();
using (var pdfAValidatorPrepareBins = new PdfAValidator.PdfAValidator())
{
pdfAValidatorPrepareBins.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStartScript, pdfAValidatorPrepareBins.PathJava))
{
pdfAValidatorPrepareBins.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
using (var pdfAValidator = new PdfAValidator.PdfAValidator(pdfAValidatorPrepareBins.VeraPdfStartScript, pdfAValidatorPrepareBins.PathJava))
{
AssertVeraPdfBinCreation(pdfAValidator.VeraPdfStartScript);
Assert.IsTrue(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
Assert.IsFalse(result);
}
AssertVeraPdfBinCreation(pdfAValidator.VeraPdfStartScript);
Assert.IsTrue(File.Exists(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf"));
var result = pdfAValidator.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
Assert.IsFalse(result);
}
AssertVeraPdfGotDisposed();
}
var listOfDirectoriesInTempAfterVeraPdf = GetListOfDirectoriesInTempExceptDirectoriesCreatedByAppVeyor();
Assert.AreEqual(listOfDirectoriesInTempAfterVeraPdf.Length, listOfDirectoriesInTempWithoutVeraPdf.Length);
}

[TestMethod]
public void ShouldNotFailOnMultipleDisposeCalls()
{
var pdfAValidatorPrepareBins = new PdfAValidator.PdfAValidator();
pdfAValidatorPrepareBins.Validate(@"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf");
veraPdfStartScript = pdfAValidatorPrepareBins.VeraPdfStartScript;
pdfAValidatorPrepareBins.Dispose();
AssertVeraPdfGotDisposed();
pdfAValidatorPrepareBins.Dispose();
}

private void AssertVeraPdfGotDisposed()
{
Assert.IsFalse(Directory.Exists(veraPdfStartScript));
}

[TestMethod]
public void ShouldNotFailOnMultipleDisposeCallseWithoutInitialization()
{
Expand All @@ -116,10 +113,5 @@ private static void AssertVeraPdfBinCreation(string scriptPath)
Assert.AreEqual(".bat", scriptPath.Substring(scriptPath.Length - 4));
Assert.IsTrue(File.Exists(scriptPath), scriptPath + " does not exist.");
}

private string[] GetListOfDirectoriesInTempExceptDirectoriesCreatedByAppVeyor()
{
return Directory.GetDirectories(tempPath).Where(_ => !_.Contains("appveyor"))?.ToArray();
}
}
}
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
version: 1.0.{build}
branches:
only:
- master
image: Visual Studio 2017
configuration: Release
nuget:
Expand Down

0 comments on commit 3e160ca

Please sign in to comment.