From 28951012e3efebb3394db5bccf3013906d18945c Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 22 Jun 2025 14:30:20 +0200 Subject: [PATCH 1/2] Add simple tests for SDL_image and SDL_ttf --- SDL3-CS.Tests/SDL3-CS.Tests.csproj | 9 +++++++ SDL3-CS.Tests/TestImage.cs | 43 ++++++++++++++++++++++++++++++ SDL3-CS.Tests/TestTTF.cs | 42 +++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 SDL3-CS.Tests/TestImage.cs create mode 100644 SDL3-CS.Tests/TestTTF.cs diff --git a/SDL3-CS.Tests/SDL3-CS.Tests.csproj b/SDL3-CS.Tests/SDL3-CS.Tests.csproj index db77335..392e88b 100644 --- a/SDL3-CS.Tests/SDL3-CS.Tests.csproj +++ b/SDL3-CS.Tests/SDL3-CS.Tests.csproj @@ -22,6 +22,15 @@ + + + + + + + sample.png + PreserveNewest + diff --git a/SDL3-CS.Tests/TestImage.cs b/SDL3-CS.Tests/TestImage.cs new file mode 100644 index 0000000..545c3bc --- /dev/null +++ b/SDL3-CS.Tests/TestImage.cs @@ -0,0 +1,43 @@ +// 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; +using static SDL.SDL3_image; +using static SDL.SDL3; + +namespace SDL.Tests +{ + public unsafe class TestImage + { + [Test] + public void TestBasic() + { + const IMG_InitFlags flags = IMG_InitFlags.IMG_INIT_PNG; + var actual = IMG_Init(flags); + + try + { + Assert.That(actual, Is.EqualTo(flags), SDL_GetError); + Assert.That(IMG_Version(), Is.EqualTo(SDL_IMAGE_VERSION)); + + Assume.That("sample.png", Does.Exist); + var image = IMG_Load("sample.png"); + + try + { + Assert.That(image != null, SDL_GetError); + Assert.That(image->w, Is.EqualTo(23)); + Assert.That(image->h, Is.EqualTo(42)); + } + finally + { + SDL_DestroySurface(image); + } + } + finally + { + IMG_Quit(); + } + } + } +} diff --git a/SDL3-CS.Tests/TestTTF.cs b/SDL3-CS.Tests/TestTTF.cs new file mode 100644 index 0000000..48fc183 --- /dev/null +++ b/SDL3-CS.Tests/TestTTF.cs @@ -0,0 +1,42 @@ +// 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; +using static SDL.SDL3_ttf; +using static SDL.SDL3; + +namespace SDL.Tests +{ + public unsafe class TestTTF + { + [Test] + public void TestBasic() + { + bool init = TTF_Init(); + + try + { + Assert.That(init, Is.True, SDL_GetError); + Assert.That(TTF_Version(), Is.EqualTo(SDL_TTF_VERSION)); + + Assume.That(@"C:\Windows\Fonts\times.ttf", Does.Exist); + var font = TTF_OpenFont(@"C:\Windows\Fonts\times.ttf", 12f); + + try + { + Assert.That(font != null, SDL_GetError); + string? name = PtrToStringUTF8(TTF_GetFontFamilyName(font)); // TODO: fix Unsafe_ generation + Assert.That(name, Is.EqualTo("Times New Roman")); + } + finally + { + TTF_CloseFont(font); + } + } + finally + { + TTF_Quit(); + } + } + } +} From 5d7ad9a1b8167d0fd3d5881b0361411fb68f8a15 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 23 Jun 2025 22:10:36 +0900 Subject: [PATCH 2/2] Init SDL too --- SDL3-CS.Tests/TestImage.cs | 3 +++ SDL3-CS.Tests/TestTTF.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/SDL3-CS.Tests/TestImage.cs b/SDL3-CS.Tests/TestImage.cs index 545c3bc..845cce2 100644 --- a/SDL3-CS.Tests/TestImage.cs +++ b/SDL3-CS.Tests/TestImage.cs @@ -12,6 +12,8 @@ namespace SDL.Tests [Test] public void TestBasic() { + SDL_Init(0); + const IMG_InitFlags flags = IMG_InitFlags.IMG_INIT_PNG; var actual = IMG_Init(flags); @@ -37,6 +39,7 @@ namespace SDL.Tests finally { IMG_Quit(); + SDL_Quit(); } } } diff --git a/SDL3-CS.Tests/TestTTF.cs b/SDL3-CS.Tests/TestTTF.cs index 48fc183..bb3a625 100644 --- a/SDL3-CS.Tests/TestTTF.cs +++ b/SDL3-CS.Tests/TestTTF.cs @@ -12,6 +12,8 @@ namespace SDL.Tests [Test] public void TestBasic() { + SDL_Init(0); + bool init = TTF_Init(); try @@ -36,6 +38,7 @@ namespace SDL.Tests finally { TTF_Quit(); + SDL_Quit(); } } }