mirror of https://github.com/ppy/SDL3-CS.git
Merge pull request #219 from Susko3/add-simple-image-ttf-tests
Add simple tests for SDL_image and SDL_ttf
This commit is contained in:
commit
90ce8877df
|
|
@ -22,6 +22,15 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SDL3-CS\SDL3-CS.csproj"/>
|
||||
<ProjectReference Include="..\SDL3_image-CS\SDL3_image-CS.csproj"/>
|
||||
<ProjectReference Include="..\SDL3_ttf-CS\SDL3_ttf-CS.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\External\SDL_image\test\sample.png">
|
||||
<Link>sample.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
// 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_image;
|
||||
using static SDL.SDL3;
|
||||
|
||||
namespace SDL.Tests
|
||||
{
|
||||
public unsafe class TestImage
|
||||
{
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
SDL_Init(0);
|
||||
|
||||
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();
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// 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_ttf;
|
||||
using static SDL.SDL3;
|
||||
|
||||
namespace SDL.Tests
|
||||
{
|
||||
public unsafe class TestTTF
|
||||
{
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
SDL_Init(0);
|
||||
|
||||
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();
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue