public void DrawsAsUsual() { using var surface = SKSurface.Create(new SKImageInfo(258, 258)); DrawIcon.Draw(surface.Canvas); using var expected = TestRenderingFixture.ThisDirectory.Parent.EnumerateFiles("Icon.png").Single().OpenRead(); using var actual = surface.Snapshot().Encode().AsStream(); Assert.Equal(expected.Length, actual.Length); Assert.True(TestRenderingFixture.StreamsContentsAreEqual(expected, actual)); }
protected void Run <TContent>( string inFile, string latex, string folder, Painter <TCanvas, TContent, TColor> painter, float textPainterCanvasWidth = TextPainter <TCanvas, TColor> .DefaultCanvasWidth) where TContent : class { folder = TestRenderingFixture.GetFolder(folder); var frontEnd = FrontEnd.ToLowerInvariant(); // Prevent black background behind black rendered output in File Explorer preview painter.HighlightColor = painter.UnwrapColor(new Structures.Color(0xF0, 0xF0, 0xF0)); painter.LaTeX = latex; var actualFile = new FileInfo(System.IO.Path.Combine(folder, inFile + "." + frontEnd + ".png")); Assert.False(actualFile.Exists, $"The actual file was not deleted by test initialization: {actualFile.FullName}"); using (var outFile = actualFile.OpenWrite()) DrawToStream(painter, outFile, textPainterCanvasWidth); actualFile.Refresh(); Assert.True(actualFile.Exists, "The actual image was not created successfully."); var expectedFile = new FileInfo(System.IO.Path.Combine(folder, inFile + ".png")); if (!expectedFile.Exists) { if (FileSizeTolerance != 0) { return; // Only let SkiaSharp create the baseline } actualFile.CopyTo(expectedFile.FullName); expectedFile.Refresh(); } Assert.True(expectedFile.Exists, "The expected image was not copied successfully."); using var actualStream = actualFile.OpenRead(); using var expectedStream = expectedFile.OpenRead(); CoreTests.Approximately.Equal(expectedStream.Length, actualStream.Length, expectedStream.Length * FileSizeTolerance); if (FileSizeTolerance == 0) { Assert.True(TestRenderingFixture.StreamsContentsAreEqual(expectedStream, actualStream), "The images differ."); } }