Compare commits

..

7 Commits

Author SHA1 Message Date
Dan Balasescu 3767eb2ab9
Merge pull request #266 from Susko3/fix-SDL_mixer-friendly-overloads
Fix SDL_mixer friendly overloads not generating
2025-12-13 13:28:34 +09:00
Dan Balasescu 4988d55819
Merge pull request #265 from Susko3/cleanup-error
Add tests for `SDL_error.cs` and ensure u8 constants are explicitly null-terminated
2025-12-13 13:26:29 +09:00
Susko3 3c21f68505 Hard-code string-returning functions in SDL_mixer 2025-12-13 03:11:02 +01:00
Susko3 2c185bf63b Fix SDL_mixer function prefix 2025-12-13 03:09:51 +01:00
Susko3 508573fe62 Add failing tests for SDL_mixer
They don't compile because of missing friendly overloads.
2025-12-13 03:09:01 +01:00
Susko3 2b556b39ce Ensure that format strings are null-terminated
u8 constants are implicitly null-terminated, but it's not really documented.
2025-12-13 02:29:00 +01:00
Susko3 40707381f6 Add tests for SDL_error.cs 2025-12-13 02:17:34 +01:00
6 changed files with 73 additions and 6 deletions

View File

@ -15,7 +15,7 @@ namespace SDL.SourceGeneration
{ {
public readonly Dictionary<string, List<GeneratedMethod>> Methods = new Dictionary<string, List<GeneratedMethod>>(); public readonly Dictionary<string, List<GeneratedMethod>> Methods = new Dictionary<string, List<GeneratedMethod>>();
private static readonly string[] sdlPrefixes = ["SDL_", "TTF_", "IMG_", "Mix_"]; private static readonly string[] sdlPrefixes = ["SDL_", "TTF_", "IMG_", "MIX_"];
/// <summary> /// <summary>
/// Checks whether the method is from any SDL library. /// Checks whether the method is from any SDL library.

View File

@ -0,0 +1,25 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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"));
}
}
}

View File

@ -0,0 +1,41 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using static SDL.SDL3_mixer;
using static SDL.SDL3;
namespace SDL.Tests
{
[TestFixture]
public class TestMixer
{
[Test]
public unsafe void TestBasic()
{
SDL_Init(0);
bool init = MIX_Init();
try
{
Assert.That(init, Is.True, SDL_GetError);
Assert.That(MIX_Version(), Is.EqualTo(SDL_MIXER_VERSION));
Assume.That(MIX_GetNumAudioDecoders() > 0);
string? name = MIX_GetAudioDecoder(0);
Assert.That(name, Is.Not.Null, SDL_GetError);
Assume.That(@"C:\Windows\Media\Windows Logon.wav", Does.Exist);
var decoder = MIX_CreateAudioDecoder(@"C:\Windows\Media\Windows Logon.wav", 0);
Assert.That(decoder != null, SDL_GetError);
MIX_DestroyAudioDecoder(decoder);
}
finally
{
MIX_Quit();
SDL_Quit();
}
}
}
}

View File

@ -8,14 +8,14 @@ namespace SDL
[Macro] [Macro]
public static unsafe SDLBool SDL_Unsupported() 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()); return SDL_SetError(fmt, __arglist());
} }
[Macro] [Macro]
public static unsafe SDLBool SDL_InvalidParamError([NativeTypeName("const char *")] byte* param) 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)); return SDL_SetError(fmt, __arglist(param));
} }
} }

View File

@ -312,7 +312,6 @@ def run_clangsharp(command, header: Header):
"--file", header.input_file(), "--file", header.input_file(),
"--output", header.output_file(), "--output", header.output_file(),
"--libraryPath", header.base, "--libraryPath", header.base,
"--methodClassName", header.base, "--methodClassName", header.base,
] ]
@ -374,6 +373,8 @@ def get_string_returning_functions(sdl_api):
yield "TTF_GetFontFamilyName" yield "TTF_GetFontFamilyName"
yield "TTF_GetFontStyleName" yield "TTF_GetFontStyleName"
yield "MIX_GetAudioDecoder"
def should_skip(solo_headers: list[Header], header: Header): def should_skip(solo_headers: list[Header], header: Header):
if len(solo_headers) == 0: if len(solo_headers) == 0:

View File

@ -79,9 +79,9 @@ namespace SDL
[DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int MIX_GetNumAudioDecoders(); public static extern int MIX_GetNumAudioDecoders();
[DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MIX_GetAudioDecoder", ExactSpelling = true)]
[return: NativeTypeName("const char *")] [return: NativeTypeName("const char *")]
public static extern byte* MIX_GetAudioDecoder(int index); public static extern byte* Unsafe_MIX_GetAudioDecoder(int index);
[DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport("SDL3_mixer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern MIX_Mixer* MIX_CreateMixerDevice(SDL_AudioDeviceID devid, [NativeTypeName("const SDL_AudioSpec *")] SDL_AudioSpec* spec); public static extern MIX_Mixer* MIX_CreateMixerDevice(SDL_AudioDeviceID devid, [NativeTypeName("const SDL_AudioSpec *")] SDL_AudioSpec* spec);