From 61bef0a01e64db68e98138d8149ffefdc49162fe Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Mon, 31 Dec 2018 11:14:29 +0000 Subject: [PATCH] add unit tests for invalid input (createSkiaDataAsync) --- DeathSocket/ColourServices.fs | 2 - DeathSocket/GridPainter.fs | 8 +-- DeathSocket/ImageServices.fs | 4 +- TestCentre/LibraryTests.fs | 91 +++++++++++++++++++++++++++++++++-- 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/DeathSocket/ColourServices.fs b/DeathSocket/ColourServices.fs index 4fba086..1226438 100644 --- a/DeathSocket/ColourServices.fs +++ b/DeathSocket/ColourServices.fs @@ -2,8 +2,6 @@ open System.Drawing open DeathSocket.Domain - open System - open SkiaSharp let makeBrushFromRGBASpec (spec: RGBASpec) = let a = int spec.alpha diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index fdb7f25..b1df029 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -107,8 +107,8 @@ namespace DeathSocket printfn "%s" ex.Message reraise () - // System.Drawing Functions - // ==================================================================== + (* System.Drawing Functions + ==================================================================== *) /// /// Determines the (Pen) points needed to draw the appropriate number @@ -171,8 +171,8 @@ namespace DeathSocket let makeSolidBrushFromRGBASpec (spec: RGBASpec) = makeBrushFromRGBASpec spec - // SkiaSharp Functions - // ==================================================================== + (* SkiaSharp Functions + ==================================================================== *) // NOT TESTED diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 26ca891..2033b4d 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -8,7 +8,7 @@ open SkiaSharp open System - (* Why the Use of Repeated Code + (* Note on the Use of Repeated Code =========================================================================== In this file, you will find code which seems duplicated. The areas in question are mostly the graphics/drawing parts of the file. Before you @@ -17,7 +17,7 @@ also, means it is difficult to pass/return them from one function to the next. Therefore, the decision made was to accept the duplicated code in exchange for a smaller memory footprint. Several (large) undisposed images - lurking in an end users RAM can grid their computer to a halt. On top of + lurking in an end users RAM can grind their computer to a halt. On top of that, they have no means to make alterations to the code. *) let setLineThickness pDimension aDimension lineWidth = diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index bb00d34..b0a3de0 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -221,11 +221,96 @@ module UnitTests = - open TestingHelpers - open Xunit - open DeathSocket open System open System.IO + open System.Drawing + open Xunit + open DeathSocket + open SkiaSharp + open TestingHelpers + + [] + let ``An empty SKData object is returned when createSKDataAsync cannot find file when using SkiaBuffer`` () = + let result = + SkiaBuffer ({ filePath = "invalid-file-path" + penWidth = float32 1 + skColour = SKColors.Empty + rows = 1 + columns = 1 }) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) + + [] + let ``An empty SKData object is returned when createSKDataAsync cannot find file when using SkiaRGBBuffer`` () = + let result = + SkiaRGBBuffer ({ filePath = "invalid-file-path" + penWidth = float32 1 + red = float32 1 + green = float32 1 + blue = float32 1 + rows = 1 + columns = 1 }) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) + + [] + let ``An empty SKData object is returned when calling createSKDataAsync with SkiaRGB`` () = + let result = + SkiaRGB ({ originalPath = "not needed" + savePath= "not needed" + red = float32 1 + green = float32 1 + blue = float32 1 + penWidth = float32 1 + rows = 1 + columns = 1}) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) + + [] + let ``An empty SKData object is returned when calling createSKDataAsync with Skia`` () = + let result = + Skia ({ originalPath = "not needed" + savePath= "not needed" + skColour = SKColors.Empty + penWidth = float32 1 + rows = 1 + columns = 1 }) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) + + [] + let ``An empty SKData object is returned when calling createSKDataAsync with Brush`` () = + let result = + Brush ({ originalPath = "not needed" + savePath= "not needed" + colour = Brushes.AliceBlue + penWidth = float32 1 + rows = 1 + columns = 1 }) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) + + [] + let ``An empty SKData object is returned when calling createSKDataAsync with RGBA`` () = + let result = + RGBA ({ originalPath = "not needed" + savePath= "not needed" + red = float 1 + green = float 1 + blue = float 1 + alpha = float 1 + penWidth = float32 1 + rows = 1 + columns = 1 }) + |> GridPainter.createSKDataAsync + |> Async.RunSynchronously + Assert.Equal(SKData.Empty, result) [] let ``Can determine image width using SkiaSharp`` () =