From 03cb53dd11aa10cde4ca4531ee3135cf9747870f Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 2 Sep 2024 18:58:32 +0200 Subject: [PATCH] Add tests for binary representation of SDL_bool --- SDL3-CS.Tests/Program.cs | 3 +++ SDL3-CS.Tests/TestSDLBool.cs | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 SDL3-CS.Tests/TestSDLBool.cs diff --git a/SDL3-CS.Tests/Program.cs b/SDL3-CS.Tests/Program.cs index 9cac63d..0a63be5 100644 --- a/SDL3-CS.Tests/Program.cs +++ b/SDL3-CS.Tests/Program.cs @@ -14,6 +14,9 @@ namespace SDL.Tests if (OperatingSystem.IsWindows()) Console.OutputEncoding = Encoding.UTF8; + Console.WriteLine($"SDL_FALSE is represented as 0x{SDL_OutOfMemory():X} (expected 0x{SDL_bool.SDL_FALSE:X})"); + Console.WriteLine($"SDL_TRUE is represented as 0x{SDL_ClearError():X} (expected 0x{SDL_bool.SDL_TRUE:X})"); + SDL_SetHint(SDL_HINT_WINDOWS_CLOSE_ON_ALT_F4, "null byte \0 in string"u8); Debug.Assert(SDL_GetHint(SDL_HINT_WINDOWS_CLOSE_ON_ALT_F4) == "null byte "); diff --git a/SDL3-CS.Tests/TestSDLBool.cs b/SDL3-CS.Tests/TestSDLBool.cs new file mode 100644 index 0000000..a0413c7 --- /dev/null +++ b/SDL3-CS.Tests/TestSDLBool.cs @@ -0,0 +1,39 @@ +// 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 TestSDLBool + { + private SDL_bool invert(SDL_bool value) => value == SDL_bool.SDL_TRUE ? SDL_bool.SDL_FALSE : SDL_bool.SDL_TRUE; + + [Test] + public void TestFalse() + { + Assert.That(SDL3.SDL_OutOfMemory(), Is.EqualTo(SDL_bool.SDL_FALSE)); + } + + [Test] + public void TestTrue() + { + Assert.That(SDL3.SDL_ClearError(), Is.EqualTo(SDL_bool.SDL_TRUE)); + } + + [Test] + public void TestStoreLoad([Values] SDL_bool value) + { + var props = SDL3.SDL_CreateProperties(); + Assume.That(props, Is.Not.EqualTo(0)); + + var ret = SDL3.SDL_SetBooleanProperty(props, "test", value); + Assume.That(ret, Is.EqualTo(SDL_bool.SDL_TRUE)); + + Assert.That(SDL3.SDL_GetBooleanProperty(props, "test", invert(value)), Is.EqualTo(value)); + + SDL3.SDL_DestroyProperties(props); + } + } +}