diff --git a/.github/docs/maui-ci-facts.md b/.github/docs/maui-ci-facts.md index 2afc93883f17..1230aee3ca5d 100644 --- a/.github/docs/maui-ci-facts.md +++ b/.github/docs/maui-ci-facts.md @@ -325,6 +325,15 @@ error XAGRDL0000: Could not GET '...pkgs.dev.azure.com/.../maven/v1/...' | `error NETSDK1144` | `maui-pr` TrimFull legs | Optimizing assemblies for size failed (often an ILLink warning promoted to error). Check whether the same leg is red on the base branch. | | `XamlC` | `maui-pr` | XAML compiler — usually missing type or bad binding | | `error XAGRDL0000` / `401` / `No local versions` | `maui-pr` or official build | Gradle/Maven feed issue — see above | +| Apple workload install cannot find a `net10.0` SDK pack | `maui-pr` SDK provisioning | The .NET 11 Apple manifests also install .NET 10 compatibility packs. Resolve the exact missing version's feed with `darc get-asset`; the current .NET 11 feed alone may not contain it. Do not copy another branch's compatibility feed without checking its manifest versions. | +| `NETSDK1140` rejects the Apple target platform version | `maui-pr` build/pack | Align current Apple target-framework versions and SDK defaults in `Directory.Build.props` with the selected Apple SDK. net11.0 uses 26.5; the RC2 release branch uses 27.0. Preserve previous-.NET compatibility targets. | +| Xcode 27 rejects native iOS 12.x / mapped macOS 10.15 deployment targets | `maui-pr` native interop archive | On branches using Apple 27, align the native framework and managed iOS minimum to 15.0, already used by app templates. This maps to macOS 12.0 for Mac Catalyst. Do not raise minimums on Apple 26.5 branches solely to match RC2. | +| Apple `bgen.dll` exits 150 requesting a newer .NET runtime | `maui-pr` Apple binding generation | Keep bootstrap (`global.json`), workload provisioning (`MicrosoftNETSdkPackageVersion`), and SDK provenance pins aligned with a compatible host runtime. SDK `11.0.100-rc.2.26470.103` satisfies the Apple 27 generator's `26465.108` requirement and is already selected on net11.0. | +| Resizetizer raster test assertions pass but `Dispose` fails with a Windows sharing violation | Helix Windows unit tests | Keep temporary images under `BaseTest.DestinationDirectory` and reuse its bounded, logged cleanup retries from #38124. Dispose raster tools deterministically; preserve all image assertions and let exhausted cleanup retries fail the test. | +| `Svg.Animation` / `Svg.SceneGraph` `NU1603`, or `SKPathBuilder` `CS0246` | `maui-pr` restore/build | Release merges can preserve old `eng/Versions.props` pins while importing Skia 4 source and packaging changes. Restore the coordinated SkiaSharp/HarfBuzz/SVG dependency versions, not just the first missing package. | +| Required Xcode is missing / requested iOS runtime is unavailable | `maui-pr` macOS provisioning | Select an image or agents providing the branch's required Xcode. net11.0 retains Aces with Xcode 26.5; RC2 needs the MAUI pool's Xcode 27 RC agents. Do not fall back to an unrelated Xcode or purge runtimes to repair a version mismatch. The legacy Provisionator task is unavailable in `dnceng-public`; enabling it prevents pipeline startup. | +| `iOS 27.0 (universal) is not available for download` | `maui-pr` simulator provisioning | Request the `arm64` runtime on Apple Silicon agents; retain `universal` on Intel. Keep all downloads version-pinned. An unavailable download can also return exit code 70, so do not treat every exit 70 as a wedged CoreSimulator or delete installed runtimes. | +| Helix monitor cannot use `NetCore-Svc-Public` | `maui-pr` release branches | The monitor must use the pipeline's selected Helix submission pool, with its Linux image demand, rather than independently selecting an unauthorized pool from the branch name. | | `XHarness timeout` | `maui-pr-devicetests` Helix logs | Test killed by infrastructure; may be transient | | `No test result files found` | `maui-pr-devicetests` Helix logs | Tests never ran or app crashed on launch | | UI test screenshot diff | `maui-pr-uitests` | Visual regression; check baseline images | diff --git a/.github/scripts/Review-PR.Tests.ps1 b/.github/scripts/Review-PR.Tests.ps1 index 582a588b1502..9ecbe6af8e70 100644 --- a/.github/scripts/Review-PR.Tests.ps1 +++ b/.github/scripts/Review-PR.Tests.ps1 @@ -986,12 +986,68 @@ Describe 'Snapshot diff asset publishing' { Describe 'Simulator runtime provisioning contract' { It 'pins every recovery download and smoke test to the selected Xcode version' { $provisionContent | Should -Match ([regex]::Escape( - 'DOWNLOAD_ARGS=(-downloadPlatform iOS -architectureVariant universal -buildVersion "${MAJOR}.${MINOR}")')) + 'DOWNLOAD_ARGS=(-downloadPlatform iOS -architectureVariant "$RUNTIME_ARCHITECTURE" -buildVersion "${MAJOR}.${MINOR}")')) ([regex]::Matches($provisionContent, [regex]::Escape( 'sudo xcodebuild "${DOWNLOAD_ARGS[@]}"'))).Count | Should -Be 3 $provisionContent | Should -Match 'SMOKE_RT=.*--arg req "\$\{MAJOR\}\.\$\{MINOR\}".*== \$req' } + It 'selects simulator downloads on for Xcode ' -TestCases @( + @{ HostArchitecture = 'arm64'; RuntimeArchitecture = 'arm64'; XcodeVersion = '26.5' }, + @{ HostArchitecture = 'x86_64'; RuntimeArchitecture = 'universal'; XcodeVersion = '26.5' }, + @{ HostArchitecture = 'arm64'; RuntimeArchitecture = 'arm64'; XcodeVersion = '27.0' }, + @{ HostArchitecture = 'x86_64'; RuntimeArchitecture = 'universal'; XcodeVersion = '27.0' } + ) -Skip:(-not (Get-Command bash -ErrorAction SilentlyContinue)) { + param($HostArchitecture, $RuntimeArchitecture, $XcodeVersion) + + $selection = [regex]::Match( + $provisionContent, + '(?ms)^\s*RUNTIME_ARCHITECTURE=universal.*?^\s*DOWNLOAD_ARGS=.*?\r?$') + $selection.Success | Should -BeTrue + $script = @' +HOST_ARCH="$1" +uname() { printf '%s\n' "$HOST_ARCH"; } +MAJOR="${2%.*}" +MINOR="${2#*.}" +'@ + "`n" + $selection.Value + "`n" + 'printf "%s\n" "${DOWNLOAD_ARGS[@]}"' + $actual = & bash -c $script -- $HostArchitecture $XcodeVersion + + $LASTEXITCODE | Should -Be 0 + ($actual -join ' ') | Should -Be "-downloadPlatform iOS -architectureVariant $RuntimeArchitecture -buildVersion $XcodeVersion" + } + + It 'handles before simulator recovery' -TestCases @( + @{ Case = 'unavailable 26.5 runtime'; Message = 'iOS 26.5 (arm64) is not available for download.'; DownloadExitCode = 70; ExpectedExitCode = 1 }, + @{ Case = 'unavailable 27.0 runtime'; Message = 'iOS 27.0 (arm64) is not available for download.'; DownloadExitCode = 70; ExpectedExitCode = 1 }, + @{ Case = 'CoreSimulator connection failure'; Message = 'Unable to connect to simulator'; DownloadExitCode = 70; ExpectedExitCode = 0 }, + @{ Case = 'successful download'; Message = 'Download complete'; DownloadExitCode = 0; ExpectedExitCode = 0 } + ) -Skip:(-not (Get-Command bash -ErrorAction SilentlyContinue)) { + param($Case, $Message, $DownloadExitCode, $ExpectedExitCode) + + $download = [regex]::Match( + $provisionContent, + '(?ms)^\s*DOWNLOAD_LOG=\$\(mktemp\).*?(?=^\s*if \[\[ "\$RC" != "0" \]\]; then)') + $download.Success | Should -BeTrue + $script = @' +DOWNLOAD_MESSAGE="$1" +DOWNLOAD_EXIT_CODE="$2" +sudo() { printf '%s\n' "$DOWNLOAD_MESSAGE"; return "$DOWNLOAD_EXIT_CODE"; } +MAJOR=26 +MINOR=5 +RUNTIME_ARCHITECTURE=arm64 +DOWNLOAD_ARGS=(-downloadPlatform iOS) +'@ + "`n" + $download.Value + "`n" + 'echo "RECOVERY_CHECK_RC=$RC"' + $actual = & bash -c $script -- $Message $DownloadExitCode + + $LASTEXITCODE | Should -Be $ExpectedExitCode + if ($ExpectedExitCode -eq 1) { + ($actual -join "`n") | Should -Match 'simulator recovery cannot fix an unavailable download' + ($actual -join "`n") | Should -Not -Match 'RECOVERY_CHECK_RC' + } else { + ($actual -join "`n") | Should -Match "RECOVERY_CHECK_RC=$DownloadExitCode" + } + } + It 'requires a Ready runtime matching Xcode rather than any installed runtime' -Skip:(-not (Get-Command jq -ErrorAction SilentlyContinue)) { $filterMatch = [regex]::Match( $provisionContent, diff --git a/.github/workflows/powershell-script-tests.yml b/.github/workflows/powershell-script-tests.yml index 8a4c0296a928..12411d3cf2c1 100644 --- a/.github/workflows/powershell-script-tests.yml +++ b/.github/workflows/powershell-script-tests.yml @@ -24,6 +24,12 @@ on: - '.github/skills/verify-tests-fail-without-fix/scripts/*.ps1' - '.github/workflows/**' - 'eng/scripts/**' + - 'Directory.Build.props' + - 'global.json' + - 'eng/Versions.props' + - 'eng/Version.Details.xml' + - 'eng/pipelines/arcade/stage-helix-tests.yml' + - 'eng/pipelines/ci.Tests.ps1' - 'eng/pipelines/ci-copilot.yml' - 'eng/pipelines/ci-official.yml' - 'eng/pipelines/ci-official.Tests.ps1' @@ -82,6 +88,7 @@ jobs: '.github/scripts' '.github/skills/run-device-tests/scripts' '.github/skills/verify-tests-fail-without-fix/scripts' + 'eng/pipelines/ci.Tests.ps1' 'eng/pipelines/ci-official.Tests.ps1' 'eng/pipelines/ci-official-release.Tests.ps1' 'eng/scripts/nuget_release_packages.Tests.ps1' diff --git a/eng/pipelines/arcade/stage-helix-tests.yml b/eng/pipelines/arcade/stage-helix-tests.yml index faaed23dbf4f..1b582209ced5 100644 --- a/eng/pipelines/arcade/stage-helix-tests.yml +++ b/eng/pipelines/arcade/stage-helix-tests.yml @@ -104,11 +104,10 @@ stages: displayName: Monitor Helix Jobs timeoutInMinutes: ${{ parameters.helixJobMonitorTimeoutInMinutes }} pool: + name: ${{ parameters.helixPool.name }} ${{ if eq(variables['System.TeamProject'], 'public') }}: - name: $(DncEngPublicBuildPool) demands: ImageOverride -equals build.azurelinux.3.amd64.open ${{ else }}: - name: $(DncEngInternalBuildPool) demands: ImageOverride -equals build.azurelinux.3.amd64 steps: - checkout: self diff --git a/eng/pipelines/ci.Tests.ps1 b/eng/pipelines/ci.Tests.ps1 new file mode 100644 index 000000000000..582036e3b988 --- /dev/null +++ b/eng/pipelines/ci.Tests.ps1 @@ -0,0 +1,84 @@ +#Requires -Modules Pester + +Describe 'CI provisioning' { + BeforeAll { + $provision = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot 'common/provision.yml') -Raw + $helixStage = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot 'arcade/stage-helix-tests.yml') -Raw + } + + Describe 'SDK alignment' { + BeforeAll { + [xml]$buildProps = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot '../../Directory.Build.props') -Raw + [xml]$versions = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot '../Versions.props') -Raw + [xml]$versionDetails = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot '../Version.Details.xml') -Raw + $globalJson = Get-Content -LiteralPath ( + Join-Path $PSScriptRoot '../../global.json') -Raw | ConvertFrom-Json + } + + It 'keeps the bootstrap, workload provisioning, and provenance SDK pins aligned' { + $sdkVersion = $versions.SelectSingleNode( + '/Project/PropertyGroup/MicrosoftNETSdkPackageVersion').InnerText + $globalJson.tools.dotnet | Should -Be $sdkVersion + $versionDetails.SelectSingleNode( + "/Dependencies/ProductDependencies/Dependency[@Name='Microsoft.NET.Sdk']").Version | + Should -Be $sdkVersion + } + + It 'aligns target frameworks with the selected Apple SDK' -TestCases @( + @{ Platform = 'Ios'; SdkAlias = 'MicrosoftiOSSdkPackageVersion' } + @{ Platform = 'Tvos'; SdkAlias = 'MicrosofttvOSSdkPackageVersion' } + @{ Platform = 'MacCatalyst'; SdkAlias = 'MicrosoftMacCatalystSdkPackageVersion' } + @{ Platform = 'Macos'; SdkAlias = 'MicrosoftmacOSSdkPackageVersion' } + ) { + param($Platform, $SdkAlias) + + $reference = $versions.SelectSingleNode("/Project/PropertyGroup/$SdkAlias").InnerText + $referenceMatch = [regex]::Match($reference, '^\$\((?[A-Za-z0-9_]+)\)$') + $referenceMatch.Success | Should -BeTrue + $sdkProperty = $referenceMatch.Groups['property'].Value + $sdkVersion = $versions.SelectSingleNode("/Project/PropertyGroup/$sdkProperty").InnerText + [version]$version = ($sdkVersion -split '-')[0] + $platformVersion = "$($version.Major).$($version.Minor)" + + $buildProps.SelectSingleNode( + "/Project/PropertyGroup/${Platform}TargetFrameworkVersionSdkDefault").InnerText | + Should -Be $platformVersion + $buildProps.SelectSingleNode( + "/Project/PropertyGroup/${Platform}TargetFrameworkVersion").InnerText | + Should -Be $platformVersion + } + } + + It 'fails before simulator setup when the required Xcode is missing' { + $missingXcodeMatch = [regex]::Match( + $provision, + '(?s)if \[\[ -z "\$XCODE_PATH" \]\]; then.*?\r?\n fi') + + $missingXcodeMatch.Success | Should -BeTrue + $missingXcodeMatch.Value | Should -Match 'task\.logissue type=error' + $missingXcodeMatch.Value | Should -Match 'Update the macOS agent image' + $missingXcodeMatch.Value | Should -Match '(?m)^\s*exit 1\r?$' + $missingXcodeMatch.Value | Should -Not -Match 'LATEST_XCODE' + } + + It 'runs the Helix monitor in the submission pool with the appropriate Linux image' { + $monitorMatch = [regex]::Match( + $helixStage, + '(?ms)^ - job: HelixJobMonitor\r?\n.*?(?=^ steps:)') + + $monitorMatch.Success | Should -BeTrue + $monitorMatch.Value | Should -Match ( + [regex]::Escape('name: ${{ parameters.helixPool.name }}')) + $monitorMatch.Value | Should -Not -Match 'DncEng(Public|Internal)BuildPool' + $monitorMatch.Value | Should -Match ( + '(?s)eq\(variables\[''System.TeamProject''\], ''public''\).*?' + + 'demands: ImageOverride -equals build\.azurelinux\.3\.amd64\.open') + $monitorMatch.Value | Should -Match ( + '(?s)\$\{\{ else \}\}:.*?demands: ImageOverride -equals build\.azurelinux\.3\.amd64\r?\n') + } +} diff --git a/eng/pipelines/common/provision.yml b/eng/pipelines/common/provision.yml index 73b74399897c..433519f18ab0 100644 --- a/eng/pipelines/common/provision.yml +++ b/eng/pipelines/common/provision.yml @@ -169,19 +169,10 @@ steps: done if [[ -z "$XCODE_PATH" ]]; then - echo "WARNING: No exact match for requested Xcode version ${ORIGINAL_VERSION}" + echo "##vso[task.logissue type=error]Required Xcode ${ORIGINAL_VERSION} is not installed on this agent. Update the macOS agent image before building with the pinned Apple SDK." echo "Tried: ${VERSIONS_TO_TRY[*]}" - echo "Falling back to latest available Xcode on this agent..." - # Find the latest Xcode by sorting version numbers - LATEST_XCODE=$(ls -1d /Applications/Xcode_*.app 2>/dev/null | sed 's|/Applications/Xcode_||;s|\.app||' | sort -t. -k1,1n -k2,2n -k3,3n | tail -1) - if [[ -n "$LATEST_XCODE" ]]; then - XCODE_VERSION="$LATEST_XCODE" - XCODE_PATH="/Applications/Xcode_${LATEST_XCODE}.app" - echo "Using latest available Xcode: ${XCODE_VERSION} at ${XCODE_PATH}" - else - echo "ERROR: No Xcode installations found in /Applications" - exit 1 - fi + echo "Installed Xcode versions: ${XCODE_LIST[*]}" + exit 1 fi sudo xcode-select -s "$XCODE_PATH" @@ -218,8 +209,12 @@ steps: exit 1 fi + RUNTIME_ARCHITECTURE=universal + if [[ "$(uname -m)" == "arm64" ]]; then + RUNTIME_ARCHITECTURE=arm64 + fi # Keep recovery downloads pinned too: a runtime newer than Xcode can break actool/ibtool. - DOWNLOAD_ARGS=(-downloadPlatform iOS -architectureVariant universal -buildVersion "${MAJOR}.${MINOR}") + DOWNLOAD_ARGS=(-downloadPlatform iOS -architectureVariant "$RUNTIME_ARCHITECTURE" -buildVersion "${MAJOR}.${MINOR}") # `simctl runtime list --json` reports disk images (including stuck # "(Deleting)" images), unlike `simctl list runtimes -j`, which reports @@ -251,8 +246,15 @@ steps: printf '%s\n' "${counts%%$'\t'*}" } - RC=0 - sudo xcodebuild "${DOWNLOAD_ARGS[@]}" || RC=$? + DOWNLOAD_LOG=$(mktemp) || exit 1 + sudo xcodebuild "${DOWNLOAD_ARGS[@]}" 2>&1 | tee "$DOWNLOAD_LOG" + RC=${PIPESTATUS[0]} + if grep -Fq "is not available for download." "$DOWNLOAD_LOG"; then + rm -f "$DOWNLOAD_LOG" + echo "##vso[task.logissue type=error]iOS ${MAJOR}.${MINOR} (${RUNTIME_ARCHITECTURE}) is unavailable for download. Check the selected Xcode and runtime architecture; simulator recovery cannot fix an unavailable download." + exit 1 + fi + rm -f "$DOWNLOAD_LOG" if [[ "$RC" != "0" ]]; then echo "First attempt failed with exit code $RC, deleting all simulator runtimes and trying again..." # Exit code 70 ("Unable to connect to simulator") means CoreSimulatorService is diff --git a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpRasterToolsTests.cs b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpRasterToolsTests.cs index 480ed83c41f5..df2534697372 100644 --- a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpRasterToolsTests.cs +++ b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpRasterToolsTests.cs @@ -2,36 +2,31 @@ using System.IO; using SkiaSharp; using Xunit; +using Xunit.Abstractions; namespace Microsoft.Maui.Resizetizer.Tests { public class SkiaSharpRasterToolsTests { - public class Resize : IDisposable + public class Resize : BaseTest { readonly string DestinationFilename; readonly TestLogger Logger; - public Resize() + public Resize(ITestOutputHelper output) : base(output) { - DestinationFilename = Path.GetTempFileName(); + Directory.CreateDirectory(DestinationDirectory); + DestinationFilename = Path.Combine(DestinationDirectory, "output.png"); Logger = new TestLogger(); } - public void Dispose() - { - //Logger.Persist(); - //File.Copy(DestinationFilename, "output.png", true); - File.Delete(DestinationFilename); - } - [Fact] public void BasicNoScaleNoResizeReturnsOriginalSize() { var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.Resize = false; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -50,7 +45,7 @@ public void BasicNoScaleReturnsOriginalSize() { var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -69,7 +64,7 @@ public void BasicWithDownScaleReturnsDownScaledSize() { var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 0.5m); tools.Resize(dpiPath, DestinationFilename); @@ -88,7 +83,7 @@ public void BasicWithColorsKeepsColors() { var info = new ResizeImageInfo(); info.Filename = "images/camera_color.png"; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -110,7 +105,7 @@ public void WithBaseSizeResizes() var info = new ResizeImageInfo(); info.Filename = "images/camera_color.png"; info.BaseSize = new SKSize(512, 512); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -132,7 +127,7 @@ public void WithBaseSizeAndScaleResizes() var info = new ResizeImageInfo(); info.Filename = "images/camera_color.png"; info.BaseSize = new SKSize(512, 512); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 0.5m); tools.Resize(dpiPath, DestinationFilename); @@ -154,7 +149,7 @@ public void ColorizedReturnsColored() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.TintColor = SKColors.Red; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -174,7 +169,7 @@ public void ColorizedWithAlphaReturnsColored() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.TintColor = SKColors.Red.WithAlpha(127); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -194,7 +189,7 @@ public void ColorizedWithNamedReturnsColored() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.TintColor = SKColors.Red; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -214,7 +209,7 @@ public void ColorizedWithColorsReplacesColors() var info = new ResizeImageInfo(); info.Filename = "images/camera_color.png"; info.TintColor = SKColors.Red; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -236,7 +231,7 @@ public void ColorizedWithAlphaWithColorsReplacesColors() var info = new ResizeImageInfo(); info.Filename = "images/camera_color.png"; info.TintColor = SKColors.Red.WithAlpha(127); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -253,31 +248,26 @@ public void ColorizedWithAlphaWithColorsReplacesColors() } } - public class ResizeQualityTests : IDisposable + public class ResizeQualityTests : BaseTest { readonly string DestinationFilename; readonly string DestinationFilename2; readonly TestLogger Logger; - public ResizeQualityTests() + public ResizeQualityTests(ITestOutputHelper output) : base(output) { - DestinationFilename = Path.GetTempFileName(); - DestinationFilename2 = Path.GetTempFileName(); + Directory.CreateDirectory(DestinationDirectory); + DestinationFilename = Path.Combine(DestinationDirectory, "output.png"); + DestinationFilename2 = Path.Combine(DestinationDirectory, "output2.png"); Logger = new TestLogger(); } - public void Dispose() - { - File.Delete(DestinationFilename); - File.Delete(DestinationFilename2); - } - [Fact] public void DefaultQualityMapsToLinearMipmapSampling() { var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); Assert.Equal( new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.Linear), @@ -290,7 +280,7 @@ public void AutoQualityMapsToLinearMipmapSampling() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.Quality = ResizeQuality.Auto; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); Assert.Equal( new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.Linear), @@ -303,7 +293,7 @@ public void BestQualityMapsToMitchellCubicSampling() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.Quality = ResizeQuality.Best; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); Assert.Equal( new SKSamplingOptions(SKCubicResampler.Mitchell), @@ -316,7 +306,7 @@ public void FastestQualityMapsToNearestNeighborSampling() var info = new ResizeImageInfo(); info.Filename = "images/camera.png"; info.Quality = ResizeQuality.Fastest; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); Assert.Equal( new SKSamplingOptions(SKFilterMode.Nearest, SKMipmapMode.None), @@ -330,7 +320,7 @@ public void ResizeWithFastestQualityProducesValidImage() info.Filename = "images/camera.png"; info.Quality = ResizeQuality.Fastest; info.BaseSize = new SKSize(100, 100); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -347,7 +337,7 @@ public void ResizeWithBestQualityProducesValidImage() info.Filename = "images/camera.png"; info.Quality = ResizeQuality.Best; info.BaseSize = new SKSize(100, 100); - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename); @@ -364,7 +354,7 @@ public void DefaultQualityProducesIdenticalOutputToExplicitAuto() var infoDefault = new ResizeImageInfo(); infoDefault.Filename = "images/camera.png"; infoDefault.BaseSize = new SKSize(200, 200); - var toolsDefault = new SkiaSharpRasterTools(infoDefault, Logger); + using var toolsDefault = new SkiaSharpRasterTools(infoDefault, Logger); var dpiPath = new DpiPath("", 1); toolsDefault.Resize(dpiPath, DestinationFilename); @@ -373,7 +363,7 @@ public void DefaultQualityProducesIdenticalOutputToExplicitAuto() infoAuto.Filename = "images/camera.png"; infoAuto.BaseSize = new SKSize(200, 200); infoAuto.Quality = ResizeQuality.Auto; - var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); + using var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); toolsAuto.Resize(dpiPath, DestinationFilename2); // Pixel-by-pixel comparison: must be identical @@ -403,14 +393,14 @@ public void DifferentQualitiesProduceDifferentPixelOutput() infoFastest.Filename = "images/camera.png"; infoFastest.BaseSize = new SKSize(100, 100); infoFastest.Quality = ResizeQuality.Fastest; - var toolsFastest = new SkiaSharpRasterTools(infoFastest, Logger); + using var toolsFastest = new SkiaSharpRasterTools(infoFastest, Logger); toolsFastest.Resize(dpiPath, DestinationFilename); var infoAuto = new ResizeImageInfo(); infoAuto.Filename = "images/camera.png"; infoAuto.BaseSize = new SKSize(100, 100); infoAuto.Quality = ResizeQuality.Auto; - var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); + using var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); toolsAuto.Resize(dpiPath, DestinationFilename2); using var bmpFastest = SKBitmap.Decode(DestinationFilename); @@ -433,14 +423,14 @@ public void BestQualityProducesDifferentPixelOutputThanAuto() infoBest.Filename = "images/camera.png"; infoBest.BaseSize = new SKSize(100, 100); infoBest.Quality = ResizeQuality.Best; - var toolsBest = new SkiaSharpRasterTools(infoBest, Logger); + using var toolsBest = new SkiaSharpRasterTools(infoBest, Logger); toolsBest.Resize(dpiPath, DestinationFilename); var infoAuto = new ResizeImageInfo(); infoAuto.Filename = "images/camera.png"; infoAuto.BaseSize = new SKSize(100, 100); infoAuto.Quality = ResizeQuality.Auto; - var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); + using var toolsAuto = new SkiaSharpRasterTools(infoAuto, Logger); toolsAuto.Resize(dpiPath, DestinationFilename2); using var bmpBest = SKBitmap.Decode(DestinationFilename); @@ -464,7 +454,7 @@ public void AllQualitiesProduceCorrectlySizedOutput(string qualityName) info.Filename = "images/camera.png"; info.BaseSize = new SKSize(256, 256); info.Quality = quality; - var tools = new SkiaSharpRasterTools(info, Logger); + using var tools = new SkiaSharpRasterTools(info, Logger); var dpiPath = new DpiPath("", 1); tools.Resize(dpiPath, DestinationFilename);