Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions CI/scripts/Test-SystemAssemblyReferences.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,30 @@ function Get-AssemblyVersion([string] $path) {
finally { $stream.Dispose() }
}

# Lowest assembly version the given package version provides to .NET Framework / netstandard2.0
# consumers. The lib folders can differ (System.Memory 4.6.3: net462 = 4.0.5.0, netstandard2.0 = 4.0.2.0),
# so take the minimum to be safe for every consumer.
function Get-PackageAssemblyVersion([string] $id, [string] $version, [string] $assemblyName) {
# Assembly version the given package version provides to consumers of our $tfm lib folder.
# The package lib folders can differ (System.Memory 4.6.3: net462 = 4.0.5.0, netstandard2.0 = 4.0.2.0).
# - .NET Framework group: the app resolves the package's own .NET Framework lib folder (the highest
# net4x folder not above our target, else netstandard2.0), so check against that one.
# - netstandard2.0 group: it can be consumed from any .NET Framework or netstandard app, so take the
# minimum across those lib folders to be safe for every consumer.
function Get-PackageAssemblyVersion([string] $id, [string] $version, [string] $assemblyName, [string] $tfm) {
$packageDir = Join-Path $PackagesRoot (Join-Path $id.ToLowerInvariant() $version.ToLowerInvariant())
if (-not (Test-Path $packageDir)) {
throw "Package $id $version is not in '$PackagesRoot'. Restore the solution before running this check."
}
$versions = foreach ($lib in 'net462', 'net461', 'net46', 'net45', 'netstandard2.0') {
$dll = Join-Path $packageDir "lib/$lib/$assemblyName.dll"
if (Test-Path $dll) { Get-AssemblyVersion $dll }
$candidates = 'net48', 'net472', 'net471', 'net47', 'net462', 'net461', 'net46', 'net45'
if ($tfm -match '^net4\d+$') {
$ours = [int]($tfm.Substring(3).PadRight(3, '0'))
$lib = @($candidates | Where-Object { [int]($_.Substring(3).PadRight(3, '0')) -le $ours }) + 'netstandard2.0' |
Where-Object { Test-Path (Join-Path $packageDir "lib/$_/$assemblyName.dll") } |
Select-Object -First 1
$versions = if ($lib) { Get-AssemblyVersion (Join-Path $packageDir "lib/$lib/$assemblyName.dll") }
}
else {
$versions = foreach ($lib in $candidates + 'netstandard2.0') {
$dll = Join-Path $packageDir "lib/$lib/$assemblyName.dll"
if (Test-Path $dll) { Get-AssemblyVersion $dll }
}
}
if (-not $versions) {
throw "No .NET Framework / netstandard2.0 assembly found for $id $version in '$packageDir'."
Expand Down Expand Up @@ -129,7 +142,7 @@ foreach ($group in $nuspec.SelectNodes("//*[local-name()='dependencies']/*[local
continue
}
$packageVersion = $declared[$ref.Name]
$provided = Get-PackageAssemblyVersion $ref.Name $packageVersion $ref.Name
$provided = Get-PackageAssemblyVersion $ref.Name $packageVersion $ref.Name $tfm
$status = if ($ref.Version -gt $provided) { 'FAIL' } else { 'ok' }
Write-Host ("[{0}] {1}: {2} {3} -> declared package {4} provides {5} {6}" -f $tfm, $dll.Name, $ref.Name, $ref.Version, $packageVersion, $provided, $status)
if ($status -eq 'FAIL') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.Maui.Graphics" Version="7.0.92" />
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand All @@ -28,6 +26,17 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<!-- IronSoftware.Drawing.Common net462 runs on SkiaSharp 4.x; ImageSharp is referenced here only by the test helpers (Compare.cs). -->
<PackageReference Include="SkiaSharp" Version="4.153.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.13" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net48'">
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IronSoftware.Drawing.Common\IronSoftware.Drawing.Common.csproj" />
<RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void AnyBitmap_should_get_Bytes()
Assert.Equal(expected, resultExport);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void AnyBitmap_should_set_Pixel()
{
Expand Down Expand Up @@ -290,6 +291,7 @@ public void AnyBitmap_should_set_Pixel()
#endif
}
}
#endif

[FactWithAutomaticDisplayName]
public void AnyBitmap_should_get_Stream()
Expand Down Expand Up @@ -339,6 +341,7 @@ public void AnyBitmap_should_ToString()
Assert.Equal(expected, result);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void AnyBitmap_GetPixel_should_not_throw_OutOfMemoryException()
{
Expand Down Expand Up @@ -390,6 +393,7 @@ public void Clone_AnyBitmap()

AssertImageAreEqual("expected.png", "result.png", true);
}
#endif

[FactWithAutomaticDisplayName]
public void Clone_Crop_AnyBitmap()
Expand Down Expand Up @@ -473,6 +477,7 @@ public void CastSKImage_from_AnyBitmap()
AssertImageAreEqual("expected.png", "result.png", true);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CastSixLabors_to_AnyBitmap()
{
Expand Down Expand Up @@ -533,6 +538,7 @@ public void CastSixLabors_from_AnyBitmap_Rgba32(string filename)

AssertImageAreEqual("expected.bmp", "result.bmp", true);
}
#endif

[FactWithAutomaticDisplayName]
public void CastBitmap_to_AnyBitmap_using_FromBitmap()
Expand Down Expand Up @@ -711,6 +717,7 @@ public void Create_Multi_page_Tiff_Paths()
File.Delete(outputImagePath);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffStream_Preserves_Mixed_Orientation()
{
Expand Down Expand Up @@ -753,6 +760,7 @@ public void CreateMultiFrameTiffBytes_Preserves_Per_Page_Dimensions_And_Resoluti
.Should().BeApproximately(150d, 2d);
}
}
#endif

[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffStream_Empty_Sequence_Throws()
Expand All @@ -761,6 +769,7 @@ public void CreateMultiFrameTiffStream_Empty_Sequence_Throws()
act.Should().Throw<ArgumentException>();
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffBytes_PreservesResolution_FromPixelsPerMeterSource()
{
Expand All @@ -777,12 +786,18 @@ public void CreateMultiFrameTiffBytes_PreservesResolution_FromPixelsPerMeterSour
ToDotsPerInch(pages[0].XResolution, pages[0].ResolutionUnit)
.Should().BeApproximately(dpi, 2d);
}
#endif

[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels()
{
string jpgPath = GetRelativeFilePath("mountainclimbers.jpg");
#if NET48
// JPEG decoders differ by a few levels; compare against the same engine's decode of the source.
using var expected = AnyBitmap.FromFile(jpgPath);
#else
using var expected = SixLabors.ImageSharp.Image.Load<Rgb24>(jpgPath);
#endif

using var result = AnyBitmap.CreateMultiFrameTiff(new List<string> { jpgPath });

Expand All @@ -801,14 +816,19 @@ public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels()

foreach (var (x, y) in points)
{
#if NET48
var e = expected.GetPixel(x, y);
#else
Rgb24 e = expected[x, y];
#endif
var a = result.GetPixel(x, y);
a.R.Should().Be(e.R, $"red channel at ({x},{y})");
a.G.Should().Be(e.G, $"green channel at ({x},{y})");
a.B.Should().Be(e.B, $"blue channel at ({x},{y})");
}
}

#if !NET48
[TheoryWithAutomaticDisplayName]
[InlineData("Rgb24")]
[InlineData("Bgr24")]
Expand Down Expand Up @@ -873,6 +893,7 @@ private static AnyBitmap MakeBitmapWithResolution(int width, int height, Rgb24 c
image.Metadata.ResolutionUnits = unit;
return image;
}
#endif

private static List<(int Width, int Height, float XResolution, ResUnit ResolutionUnit)> ReadTiffDirectories(byte[] tiffData)
{
Expand Down Expand Up @@ -913,6 +934,7 @@ private static double ToDotsPerInch(float xResolution, ResUnit unit)
};
}

#if !NET48
[FactWithAutomaticDisplayName]
public void Create_Multi_page_Gif()
{
Expand Down Expand Up @@ -988,6 +1010,7 @@ public void Should_Return_BitsPerPixel()
bitmap = Image.Load<Rgba32>(GetRelativeFilePath("mountainclimbers.jpg"));
Assert.Equal(32, bitmap.BitsPerPixel);
}
#endif

[TheoryWithAutomaticDisplayName]
[InlineData("ScanDev_BW.tif", 1)]
Expand Down Expand Up @@ -1173,6 +1196,7 @@ public void Resize_ShouldPreserveDepthForRepresentableFormats()
}
}

#if !NET48
[TheoryWithAutomaticDisplayName]
[InlineData("A8", "GrayscaleWithAlpha", "Bit8", 16)]
[InlineData("L8", "Grayscale", "Bit8", 8)]
Expand Down Expand Up @@ -1219,6 +1243,7 @@ public void ExportPng_ShouldChooseColorTypeAndBitDepthFromPixelType(
}
Assert.Equal(expectedBitsPerPixel, AnyBitmap.FromBytes(png).BitsPerPixel);
}
#endif

[TheoryWithAutomaticDisplayName]
[InlineData("Palette", "Bit8")]
Expand Down Expand Up @@ -1369,6 +1394,7 @@ public void Should_RotateFlip()
AssertImageAreEqual(GetRelativeFilePath("checkmarkFlip.jpg"), "result_flip.bmp");
}

#if !NET48
[FactWithAutomaticDisplayName]
public void Redact_ShouldRedactRegionWithColor()
{
Expand Down Expand Up @@ -1409,6 +1435,7 @@ public void Redact_ShouldRedactRegionWithColor()
}
}
}
#endif

[FactWithAutomaticDisplayName]
public void TestGetRGBBuffer()
Expand Down Expand Up @@ -1654,6 +1681,7 @@ public void LoadImage_SetPreserveOriginalFormat_ShouldReturnCorrectBitPerPixel(s
}

#if !NET7_0
#if !NET48
[FactWithAutomaticDisplayName]
public void CastAnyBitmap_from_SixLabors()
{
Expand All @@ -1669,6 +1697,7 @@ public void CastAnyBitmap_from_SixLabors()
AssertLargeImageAreEqual("expected.bmp", "result.bmp", true);
}
#endif
#endif


[IgnoreOnAzureDevopsX86Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public void Cast_SKColor_to_Color()
Assert.Equal(176, skColor.Blue);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void Cast_ImageSharp_Color_from_Color()
{
Expand Down Expand Up @@ -557,6 +558,7 @@ public void Should_Return_Argb()
Assert.Equal(bmColor.ToArgb(), rgba32.ToArgb());
Assert.Equal(bmColor.ToArgb(), rgb24.ToArgb());
}
#endif

[FactWithAutomaticDisplayName]
public void Should_Create_FromName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@ protected static void AssertLargeImageAreEqual(string expectedImagePath, string
expectedImageSharp.Mutate(x => x.Resize(100, 100));
actualImageSharp.Mutate(x => x.Resize(100, 100));

#if NET48
// The ImageSharp casts are not available on .NET Framework; go through PNG bytes instead.
AssertImageAreEqual(ToAnyBitmap(expectedImageSharp), ToAnyBitmap(actualImageSharp));
#else
AssertImageAreEqual(expectedImageSharp, actualImageSharp);
#endif
}

#if NET48
private static AnyBitmap ToAnyBitmap(SixLabors.ImageSharp.Image image)
{
using var stream = new MemoryStream();
SixLabors.ImageSharp.ImageExtensions.SaveAsPng(image, stream);
return AnyBitmap.FromBytes(stream.ToArray());
}
#endif

protected static void AssertImageAreEqual(string expectedImagePath, string resultImagePath, bool isCleanAll = false)
{
using var expected = AnyBitmap.FromFile(expectedImagePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void CastRectangle_from_Rectangle()
Assert.Equal(5, rectangle.Y);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CastImageSharp_Rectangle_to_Rectangle()
{
Expand Down Expand Up @@ -137,6 +138,7 @@ public void CastImageSharp_RectangleF_from_Rectangle()
Assert.Equal(5, rectangle.X);
Assert.Equal(5, rectangle.Y);
}
#endif

[FactWithAutomaticDisplayName]
public void CastSKRect_to_Rectangle()
Expand Down Expand Up @@ -411,6 +413,7 @@ public void CastRectangleF_from_RectangleF()
Assert.Equal(5, Rectangle.Y);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CastImageSharp_RectangleF_to_RectangleF()
{
Expand Down Expand Up @@ -443,6 +446,7 @@ public void CastImageSharp_RectangleF_from_RectangleF()
Assert.Equal(5, Rectangle.X);
Assert.Equal(5, Rectangle.Y);
}
#endif

[FactWithAutomaticDisplayName]
public void CastSKRect_to_RectangleF()
Expand Down
Loading