55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using Quik.Stb;
|
|
|
|
namespace Quik.StbImage.Tests
|
|
{
|
|
[TestClass]
|
|
public class LoadImage
|
|
{
|
|
[TestMethod("Set Global Options")]
|
|
public void SetGlobals()
|
|
{
|
|
Quik.Stb.StbImage.FlipVerticallyOnLoad = true;
|
|
Quik.Stb.StbImage.UnpremultiplyOnLoad = true;
|
|
}
|
|
|
|
private StbiStreamWrapper PrepareImage(string path, out stbi_io_callbacks cb)
|
|
{
|
|
Stream? str = GetType().Assembly.GetManifestResourceStream(path);
|
|
Assert.IsNotNull(str, $"Could not find test image resource {path}.");
|
|
|
|
StbiStreamWrapper wrapper = new StbiStreamWrapper(str);
|
|
wrapper.CreateCallbacks(out cb);
|
|
return wrapper;
|
|
}
|
|
|
|
[TestMethod("Load a PNG")]
|
|
public unsafe void LoadPng()
|
|
{
|
|
// TODO: Fill these up!
|
|
const int TEST_CHANNELS = 0;
|
|
const int TEST_WIDTH = 0;
|
|
const int TEST_HEIGHT = 0;
|
|
|
|
int x, y, numChannels;
|
|
using StbiStreamWrapper str = PrepareImage("Quik.StbImage.Tests.res.test.png", out stbi_io_callbacks cb);
|
|
byte *image = Stbi.load_from_callbacks(&cb, null, &x, &y, &numChannels, (int)StbiEnum.STBI_default);
|
|
|
|
if (image == null)
|
|
{
|
|
IntPtr reasonPtr = (IntPtr)Stbi.failure_reason();
|
|
string? reason = Marshal.PtrToStringUTF8((IntPtr)reasonPtr);
|
|
Assert.Fail("Could not load image: {0}.", reason ?? "None specified. (stbi_failure_reason() is null)");
|
|
}
|
|
|
|
Assert.AreEqual(TEST_CHANNELS, numChannels, "Channel count does not match.");
|
|
Assert.AreEqual(TEST_WIDTH, x, "Width does not match.");
|
|
Assert.AreEqual(TEST_HEIGHT, y, "Height does not match.");
|
|
|
|
Stbi.image_free(image);
|
|
}
|
|
}
|
|
} |