diff --git a/binding/Binding/SKPathMeasure.cs b/binding/Binding/SKPathMeasure.cs index e41c02e130..710fb5a5dd 100644 --- a/binding/Binding/SKPathMeasure.cs +++ b/binding/Binding/SKPathMeasure.cs @@ -19,8 +19,13 @@ public SKPathMeasure () } public SKPathMeasure (SKPath path, bool forceClosed = false, float resScale = 1) - : this (SkiaApi.sk_pathmeasure_new_with_path (path == null ? IntPtr.Zero : path.Handle, forceClosed, resScale), true) + : this (IntPtr.Zero, true) { + if (path == null) + throw new ArgumentNullException (nameof (path)); + + Handle = SkiaApi.sk_pathmeasure_new_with_path (path.Handle, forceClosed, resScale); + if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKPathMeasure instance."); } diff --git a/tests/Tests/SKPathMeasureTest.cs b/tests/Tests/SKPathMeasureTest.cs new file mode 100644 index 0000000000..e914eff082 --- /dev/null +++ b/tests/Tests/SKPathMeasureTest.cs @@ -0,0 +1,30 @@ +using System; +using Xunit; + +namespace SkiaSharp.Tests +{ + public class SKPathMeasureTest : SKTest + { + [SkippableFact] + public void ConstructorThrowsOnNullPathArgument() + { + var ex = Assert.Throws(() => new SKPathMeasure(null)); + Assert.Equal("path", ex.ParamName); + } + + [SkippableFact] + public void ConstructorDoesNotThrownOnNonNullPathArgument() + { + var path = new SKPath(); + var pm = new SKPathMeasure(path); + Assert.NotNull(pm); + } + + [SkippableFact] + public void EmptyConstructorDoesNotThrow() + { + var pm = new SKPathMeasure(); + Assert.NotNull(pm); + } + } +}