mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 09:28:25 +08:00
Merge pull request #332 from kasperdaff/xplat-unit-tests
Make unit tests behave cross platform
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
using System.Linq;
|
||||
using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;
|
||||
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;
|
||||
using UglyToad.PdfPig.Fonts.SystemFonts;
|
||||
using Xunit;
|
||||
|
||||
public class DocstrumBoundingBoxesTests
|
||||
@@ -70,10 +71,18 @@
|
||||
}
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[SkippableTheory]
|
||||
[MemberData(nameof(DataExtract))]
|
||||
public void GetBlocks(string name, string[] expected)
|
||||
{
|
||||
if (name == "90 180 270 rotated.pdf")
|
||||
{
|
||||
// The 'TimesNewRomanPSMT' font is used by this particular document. Thus, results cannot be trusted on
|
||||
// platforms where this font isn't generally available (e.g. OSX, Linux, etc.), so we skip it!
|
||||
var font = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPSMT");
|
||||
Skip.If(font == null, "Skipped because the font TimesNewRomanPSMT could not be found in the execution environment.");
|
||||
}
|
||||
|
||||
var options = new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions() { LineSeparator = " " };
|
||||
using (var document = PdfDocument.Open(DlaHelper.GetDocumentPath(name)))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using UglyToad.PdfPig.Fonts.SystemFonts;
|
||||
using UglyToad.PdfPig.Tests.Dla;
|
||||
using Xunit;
|
||||
|
||||
@@ -21,11 +22,15 @@ namespace UglyToad.PdfPig.Tests.Fonts.SystemFonts
|
||||
},
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[SkippableTheory]
|
||||
[MemberData(nameof(DataExtract))]
|
||||
public void GetCorrectBBoxLinux(string name, object[][] expected)
|
||||
{
|
||||
// success on Windows but LinuxSystemFontLister cannot find the 'TimesNewRomanPSMT' font
|
||||
var font = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPSMT");
|
||||
|
||||
Skip.If(font == null, "Skipped because the font TimesNewRomanPSMT could not be found in the execution environment.");
|
||||
|
||||
using (var document = PdfDocument.Open(DlaHelper.GetDocumentPath(name)))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
var result = FileHeaderParser.Parse(scanner, false, log);
|
||||
|
||||
Assert.Equal(1.2m, result.Version);
|
||||
Assert.Equal(9, result.OffsetInFile);
|
||||
Assert.Equal(TestEnvironment.IsUnixPlatform ? 7 : 9, result.OffsetInFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +70,7 @@
|
||||
var result = FileHeaderParser.Parse(scanner, false, log);
|
||||
|
||||
Assert.Equal(1.2m, result.Version);
|
||||
Assert.Equal(13, result.OffsetInFile);
|
||||
Assert.Equal(TestEnvironment.IsUnixPlatform ? 12 : 13, result.OffsetInFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,7 +82,7 @@
|
||||
var result = FileHeaderParser.Parse(scanner, true, log);
|
||||
|
||||
Assert.Equal(1.7m, result.Version);
|
||||
Assert.Equal(13, result.OffsetInFile);
|
||||
Assert.Equal(TestEnvironment.IsUnixPlatform ? 12 : 13, result.OffsetInFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -94,7 +94,7 @@ three %PDF-1.6");
|
||||
var result = FileHeaderParser.Parse(scanner, true, log);
|
||||
|
||||
Assert.Equal(1.6m, result.Version);
|
||||
Assert.Equal(15, result.OffsetInFile);
|
||||
Assert.Equal(TestEnvironment.IsUnixPlatform ? 14 : 15, result.OffsetInFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
9
src/UglyToad.PdfPig.Tests/TestEnvironment.cs
Normal file
9
src/UglyToad.PdfPig.Tests/TestEnvironment.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace UglyToad.PdfPig.Tests
|
||||
{
|
||||
using System;
|
||||
|
||||
public static class TestEnvironment
|
||||
{
|
||||
public static readonly bool IsUnixPlatform = Environment.NewLine.Length == 1;
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user