From 40707381f63569dd89c5e36a2be5e45f86fc2c77 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sat, 13 Dec 2025 02:17:34 +0100 Subject: [PATCH 1/2] Add tests for SDL_error.cs --- SDL3-CS.Tests/TestError.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SDL3-CS.Tests/TestError.cs diff --git a/SDL3-CS.Tests/TestError.cs b/SDL3-CS.Tests/TestError.cs new file mode 100644 index 0000000..c33b1d1 --- /dev/null +++ b/SDL3-CS.Tests/TestError.cs @@ -0,0 +1,25 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; + +namespace SDL.Tests +{ + [TestFixture] + public class TestError + { + [Test] + public void TestUnsupported() + { + Assert.That((bool)SDL3.SDL_Unsupported(), Is.False); + Assert.That(SDL3.SDL_GetError(), Is.EqualTo("That operation is not supported")); + } + + [Test] + public void TestInvalidParam() + { + Assert.That((bool)SDL3.SDL_InvalidParamError("test"), Is.False); + Assert.That(SDL3.SDL_GetError(), Is.EqualTo("Parameter 'test' is invalid")); + } + } +} From 2b556b39cece9bf62848d06835f6c427cef339d2 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sat, 13 Dec 2025 02:29:00 +0100 Subject: [PATCH 2/2] Ensure that format strings are null-terminated u8 constants are implicitly null-terminated, but it's not really documented. --- SDL3-CS/SDL3/SDL_error.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SDL3-CS/SDL3/SDL_error.cs b/SDL3-CS/SDL3/SDL_error.cs index 749bbbc..82891aa 100644 --- a/SDL3-CS/SDL3/SDL_error.cs +++ b/SDL3-CS/SDL3/SDL_error.cs @@ -8,14 +8,14 @@ namespace SDL [Macro] public static unsafe SDLBool SDL_Unsupported() { - fixed (byte* fmt = "That operation is not supported"u8) + fixed (byte* fmt = "That operation is not supported\0"u8) return SDL_SetError(fmt, __arglist()); } [Macro] public static unsafe SDLBool SDL_InvalidParamError([NativeTypeName("const char *")] byte* param) { - fixed (byte* fmt = "Parameter '%s' is invalid"u8) + fixed (byte* fmt = "Parameter '%s' is invalid\0"u8) return SDL_SetError(fmt, __arglist(param)); } }