diff --git a/Quik.StbImage.Tests/LoadFont.cs b/Quik.StbImage.Tests/LoadFont.cs new file mode 100644 index 0000000..c676746 --- /dev/null +++ b/Quik.StbImage.Tests/LoadFont.cs @@ -0,0 +1,72 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.IO; +using System.Runtime.InteropServices; +using Quik.Stb; + +namespace Quik.Stb +{ + [TestClass] + [TestCategory("Load Font")] + public class LoadFont + { + StbFont? font; + + [TestInitialize] + public void Initialize() + { + using (Stream? str = GetType().Assembly.GetManifestResourceStream("Quik.Stb.Tests.res.Varicka.ttf")) + { + Assert.IsNotNull(str, "Test font file not packed."); + font = StbFont.Load(str); + } + } + + [TestCleanup] + public void Deinitialize() + { + font?.Dispose(); + } + + [TestMethod] + public void AscendIsValid() + { + Assert.AreNotEqual(-1, font!.Ascend); + } + + [TestMethod] + public void DescendIsValid() + { + Assert.AreNotEqual(-1, font!.Descend); + } + + [TestMethod] + public void VLineGapIsValid() + { + Assert.AreNotEqual(-1, font!.VerticalLineGap); + } + + [TestMethod] + public void BBoxIsValid() + { + Assert.AreNotEqual(default, font!.BoundingBox); + } + + [TestMethod] + public void KerningTableIsValid() + { + Assert.IsNotNull(font!.KerningTable); + } + + [TestMethod] + public void GetGlyphsForAscii() + { + for (int i = 0; i < 128; i++) + { + int glyph = font!.FindGlyphIndex(i); + + Assert.AreNotEqual(-1, glyph); + } + } + } +} \ No newline at end of file diff --git a/Quik.StbImage.Tests/LoadImage.cs b/Quik.StbImage.Tests/LoadImage.cs new file mode 100644 index 0000000..9a7157e --- /dev/null +++ b/Quik.StbImage.Tests/LoadImage.cs @@ -0,0 +1,45 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; + +namespace Quik.Stb.Tests +{ + [TestClass] + [TestCategory("Load Image")] + public class LoadImage + { + [TestMethod("Set Global Options")] + public void SetGlobals() + { + Quik.Stb.StbImage.FlipVerticallyOnLoad = true; + Quik.Stb.StbImage.UnpremultiplyOnLoad = true; + } + + private Stream GetImage(string path) + { + Stream? str = GetType().Assembly.GetManifestResourceStream(path); + Assert.IsNotNull(str, $"Could not find test image resource {path}."); + return str; + } + + private unsafe void TestImage(string path, int width, int height) + { + StbImage image = StbImage.Load(GetImage(path)); + + Assert.IsNotNull(image); + + Assert.AreEqual(width, image.Width, "Width does not match."); + Assert.AreEqual(height, image.Height, "Height does not match."); + + image.Dispose(); + } + + const int WIDTH = 768; + const int HEIGHT = 512; + + [TestMethod("Load a single frame GIF")] + public unsafe void LoadGif() => TestImage("Quik.Stb.Tests.res.kodim.kodim23.gif", WIDTH, HEIGHT); + [TestMethod("Load a JPEG")] + public unsafe void LoadJpg() => TestImage("Quik.Stb.Tests.res.kodim.kodim23.jpg", WIDTH, HEIGHT); + [TestMethod("Load a PNG")] public unsafe void LoadPng() => TestImage("Quik.Stb.Tests.res.kodim.kodim23.png", WIDTH, HEIGHT); + } +} \ No newline at end of file diff --git a/Quik.StbImage.Tests/Quik.StbImage.Tests.csproj b/Quik.StbImage.Tests/Quik.StbImage.Tests.csproj new file mode 100644 index 0000000..08424f2 --- /dev/null +++ b/Quik.StbImage.Tests/Quik.StbImage.Tests.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + disable + enable + + false + true + True + + + + + + + + + + + + + + + + + + + + + + diff --git a/Quik.StbImage.Tests/res/Varicka.ttf b/Quik.StbImage.Tests/res/Varicka.ttf new file mode 100644 index 0000000..4c16d09 Binary files /dev/null and b/Quik.StbImage.Tests/res/Varicka.ttf differ diff --git a/Quik.StbImage.Tests/res/Varicka.txt b/Quik.StbImage.Tests/res/Varicka.txt new file mode 100644 index 0000000..12337b2 --- /dev/null +++ b/Quik.StbImage.Tests/res/Varicka.txt @@ -0,0 +1,12 @@ +Varicka (Truetype and Opentype with no OT features) + +Based on 'Varick', from "Decorative Condensed Alphabets", by Dan Solo, Page 94. + +Letter spacing is set to balance the letterforms themselves; the space between most adjacent letters is identical to the horizontal space inside such letters as 'O' and 'H'. Kerning is supplied as needed for certain letter combinations, particularly those that have a letter with a projection on the left, such as A, E, F, H, K, P, and R. + +Varicka is superficially similar to Red Rooster's Triple Gothic Condensed, but the Solo book's font has different features and some very different letterforms. + +This font is free and available for all use, personal and commercial, with no restrictions. + + Character + February 13, 2010 \ No newline at end of file diff --git a/Quik.StbImage.Tests/res/kodim/LICENSE.md b/Quik.StbImage.Tests/res/kodim/LICENSE.md new file mode 100644 index 0000000..27c5e1a --- /dev/null +++ b/Quik.StbImage.Tests/res/kodim/LICENSE.md @@ -0,0 +1,3 @@ +Kodak Image Suite Test Images owned by Kodak. Image 23 was taken by Steve Kelly. +The original image file kodim23.png and its derivatives are only included for +test purposes only and should not be redistributed with the software. \ No newline at end of file diff --git a/Quik.StbImage.Tests/res/kodim/kodim23.gif b/Quik.StbImage.Tests/res/kodim/kodim23.gif new file mode 100644 index 0000000..7f521c3 Binary files /dev/null and b/Quik.StbImage.Tests/res/kodim/kodim23.gif differ diff --git a/Quik.StbImage.Tests/res/kodim/kodim23.jpg b/Quik.StbImage.Tests/res/kodim/kodim23.jpg new file mode 100644 index 0000000..4df6938 Binary files /dev/null and b/Quik.StbImage.Tests/res/kodim/kodim23.jpg differ diff --git a/Quik.StbImage.Tests/res/kodim/kodim23.png b/Quik.StbImage.Tests/res/kodim/kodim23.png new file mode 100644 index 0000000..ff22e83 Binary files /dev/null and b/Quik.StbImage.Tests/res/kodim/kodim23.png differ diff --git a/Quik.StbImage.Tests/res/kodim/kodim23.tiff b/Quik.StbImage.Tests/res/kodim/kodim23.tiff new file mode 100644 index 0000000..6df024b Binary files /dev/null and b/Quik.StbImage.Tests/res/kodim/kodim23.tiff differ diff --git a/Quik.StbImage.Tests/res/kodim/kodim23.webp b/Quik.StbImage.Tests/res/kodim/kodim23.webp new file mode 100644 index 0000000..8eda7cd Binary files /dev/null and b/Quik.StbImage.Tests/res/kodim/kodim23.webp differ diff --git a/Quik.StbImage.sln b/Quik.StbImage.sln index 6b44dac..e80bd93 100644 --- a/Quik.StbImage.sln +++ b/Quik.StbImage.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quik.StbImage", "Quik.StbImage.csproj", "{C808B4BC-C3AF-4682-8EDA-EAAC780800C3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quik.StbImage.Tests", "Quik.StbImage.Tests\Quik.StbImage.Tests.csproj", "{6FC081AA-93EA-468C-8C23-C1D7AC459321}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Release|Any CPU.Build.0 = Release|Any CPU + {6FC081AA-93EA-468C-8C23-C1D7AC459321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FC081AA-93EA-468C-8C23-C1D7AC459321}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FC081AA-93EA-468C-8C23-C1D7AC459321}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FC081AA-93EA-468C-8C23-C1D7AC459321}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE