Move ComputeTest,GraphicsTest,RenderTest and Std140Debug to the tests folder
Also renamed NazaraUnitTests to UnitTests
This commit is contained in:
152
tests/UnitTests/Engine/Utility/FontLoading.cpp
Normal file
152
tests/UnitTests/Engine/Utility/FontLoading.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("Fonts", "[Utility][Font]")
|
||||
{
|
||||
WHEN("Loading default font")
|
||||
{
|
||||
std::shared_ptr<Nz::Font> font = Nz::Font::GetDefault();
|
||||
|
||||
std::shared_ptr<Nz::GuillotineImageAtlas> imageAtlas = std::make_shared<Nz::GuillotineImageAtlas>();
|
||||
imageAtlas->SetMaxLayerSize(1024);
|
||||
|
||||
font->SetAtlas(imageAtlas);
|
||||
|
||||
CHECK(font->GetFamilyName() == "Open Sans");
|
||||
CHECK(font->GetStyleName() == "Regular");
|
||||
|
||||
for (std::size_t i = 0; i < 3; ++i)
|
||||
{
|
||||
WHEN("Inspecting size info")
|
||||
{
|
||||
const auto& sizeInfo24 = font->GetSizeInfo(24);
|
||||
CHECK(sizeInfo24.lineHeight == 33);
|
||||
CHECK(sizeInfo24.spaceAdvance == 6);
|
||||
CHECK(sizeInfo24.underlinePosition == Catch::Approx(-2.40625f));
|
||||
CHECK(sizeInfo24.underlineThickness == Catch::Approx(1.20312f));
|
||||
|
||||
const auto& sizeInfo72 = font->GetSizeInfo(72);
|
||||
CHECK(sizeInfo72.lineHeight == 98);
|
||||
CHECK(sizeInfo72.spaceAdvance == 19);
|
||||
CHECK(sizeInfo72.underlinePosition == Catch::Approx(-7.20312f));
|
||||
CHECK(sizeInfo72.underlineThickness == Catch::Approx(3.59375f));
|
||||
}
|
||||
|
||||
WHEN("Retrieving kerning")
|
||||
{
|
||||
struct Test
|
||||
{
|
||||
unsigned int characterSize;
|
||||
char firstChar;
|
||||
char secondChar;
|
||||
int expectedKerning;
|
||||
};
|
||||
|
||||
std::array<Test, 16> tests{
|
||||
{
|
||||
Test { 16, 'A', 'A', 0 },
|
||||
Test { 24, 'A', 'A', 0 },
|
||||
Test { 32, 'A', 'A', 0 },
|
||||
Test { 48, 'A', 'A', 0 },
|
||||
|
||||
Test { 16, 'A', 'M', 0 },
|
||||
Test { 24, 'A', 'M', 0 },
|
||||
Test { 32, 'A', 'M', 0 },
|
||||
Test { 48, 'A', 'M', 0 },
|
||||
|
||||
Test { 16, 'A', 'T', -1 },
|
||||
Test { 24, 'A', 'T', -2 },
|
||||
Test { 32, 'A', 'T', -2 },
|
||||
Test { 48, 'A', 'T', -3 },
|
||||
|
||||
Test { 16, 'A', 'V', 0 },
|
||||
Test { 24, 'A', 'V', -1 },
|
||||
Test { 32, 'A', 'V', -1 },
|
||||
Test { 48, 'A', 'V', -2 },
|
||||
}
|
||||
};
|
||||
|
||||
for (const Test& test : tests)
|
||||
{
|
||||
INFO("between " << test.firstChar << " and " << test.secondChar << " at character size " << test.characterSize);
|
||||
CHECK(font->GetKerning(test.characterSize, test.firstChar, test.secondChar) == test.expectedKerning);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Retrieving glyphs")
|
||||
{
|
||||
const auto& glyph1 = font->GetGlyph(72, Nz::TextStyle_Regular, 0.f, 'L');
|
||||
REQUIRE(glyph1.valid);
|
||||
CHECK(glyph1.advance == 37);
|
||||
CHECK(glyph1.aabb.IsValid());
|
||||
CHECK(glyph1.atlasRect.IsValid());
|
||||
CHECK(glyph1.fauxOutlineThickness == 0.f);
|
||||
CHECK_FALSE(glyph1.requireFauxBold);
|
||||
CHECK_FALSE(glyph1.requireFauxItalic);
|
||||
|
||||
const auto& glyphYItalic = font->GetGlyph(72, Nz::TextStyle::Italic, 0.f, 'y');
|
||||
REQUIRE(glyphYItalic.valid);
|
||||
CHECK(glyphYItalic.advance == 36);
|
||||
CHECK(glyphYItalic.aabb.IsValid());
|
||||
CHECK(glyphYItalic.atlasRect.IsValid());
|
||||
CHECK(glyphYItalic.fauxOutlineThickness == 0.f);
|
||||
CHECK_FALSE(glyphYItalic.requireFauxBold);
|
||||
CHECK(glyphYItalic.requireFauxItalic);
|
||||
|
||||
const auto& glyphYRegular = font->GetGlyph(72, Nz::TextStyle_Regular, 0.f, 'y');
|
||||
REQUIRE(glyphYRegular.valid);
|
||||
CHECK(glyphYRegular.advance == 36);
|
||||
CHECK(glyphYRegular.aabb == glyphYItalic.aabb);
|
||||
CHECK(glyphYRegular.atlasRect == glyphYItalic.atlasRect);
|
||||
CHECK(glyphYRegular.fauxOutlineThickness == 0.f);
|
||||
CHECK_FALSE(glyphYRegular.requireFauxBold);
|
||||
CHECK_FALSE(glyphYRegular.requireFauxItalic);
|
||||
|
||||
CHECK(font->GetCachedGlyphCount() == 3);
|
||||
CHECK(font->GetAtlas()->GetLayerCount() == 1);
|
||||
CHECK(font->GetAtlas()->GetLayer(0)->GetLevelCount() == 1);
|
||||
}
|
||||
|
||||
WHEN("Precaching a lot of glyphs")
|
||||
{
|
||||
std::string characterSet;
|
||||
for (char c = 'a'; c <= 'z'; ++c)
|
||||
characterSet += c;
|
||||
|
||||
for (char c = 'A'; c <= 'Z'; ++c)
|
||||
characterSet += c;
|
||||
|
||||
for (char c = '0'; c <= '9'; ++c)
|
||||
characterSet += c;
|
||||
|
||||
for (unsigned int fontSize : {24, 36, 48, 72, 140})
|
||||
{
|
||||
for (float outlineThickness : { 0.f, 1.f, 2.f, 5.f })
|
||||
{
|
||||
font->Precache(fontSize, Nz::TextStyle_Regular, outlineThickness, characterSet);
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(font->GetAtlas()->GetLayerCount() > 1);
|
||||
for (std::size_t layerIndex = 0; layerIndex < font->GetAtlas()->GetLayerCount(); ++layerIndex)
|
||||
{
|
||||
CHECK(font->GetAtlas()->GetLayer(layerIndex)->GetLevelCount() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
font->ClearGlyphCache();
|
||||
font->ClearKerningCache();
|
||||
font->ClearSizeInfoCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
tests/UnitTests/Engine/Utility/ImageLoading.cpp
Normal file
41
tests/UnitTests/Engine/Utility/ImageLoading.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("Images", "[Utility][Image]")
|
||||
{
|
||||
WHEN("Loading PNG files")
|
||||
{
|
||||
GIVEN("Logo.png")
|
||||
{
|
||||
std::shared_ptr<Nz::Image> logo = Nz::Image::LoadFromFile(GetAssetDir() / "Logo.png");
|
||||
REQUIRE(logo);
|
||||
|
||||
CHECK(logo->GetWidth() == 765);
|
||||
CHECK(logo->GetHeight() == 212);
|
||||
CHECK(logo->GetLevelCount() == 1);
|
||||
CHECK(logo->GetPixelColor(165, 139) == Nz::Color::FromRGB8(51, 58, 100));
|
||||
CHECK(logo->GetFormat() == Nz::PixelFormat::RGBA8);
|
||||
CHECK(logo->HasAlpha());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Loading JPG files")
|
||||
{
|
||||
GIVEN("stars-background.jpg")
|
||||
{
|
||||
std::shared_ptr<Nz::Image> background = Nz::Image::LoadFromFile(GetAssetDir() / "Utility/stars-background.jpg");
|
||||
REQUIRE(background);
|
||||
|
||||
CHECK(background->GetWidth() == 1920);
|
||||
CHECK(background->GetHeight() == 1200);
|
||||
CHECK(background->GetLevelCount() == 1);
|
||||
CHECK(background->GetPixelColor(1377, 372) == Nz::Color::FromRGB8(171, 152, 233));
|
||||
CHECK(background->GetFormat() == Nz::PixelFormat::RGBA8);
|
||||
CHECK(!background->HasAlpha());
|
||||
}
|
||||
}
|
||||
}
|
||||
166
tests/UnitTests/Engine/Utility/ImageStreamLoading.cpp
Normal file
166
tests/UnitTests/Engine/Utility/ImageStreamLoading.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/ImageStream.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
void CompareFrames(const Nz::ImageStream& gif, std::vector<Nz::UInt8>& frameData, const Nz::Image& referenceImage)
|
||||
{
|
||||
Nz::Vector2ui size = gif.GetSize();
|
||||
REQUIRE(referenceImage.GetSize() == Nz::Vector3ui(size, 1));
|
||||
REQUIRE(referenceImage.GetFormat() == gif.GetPixelFormat()); //< TODO: Convert?
|
||||
|
||||
REQUIRE(frameData.size() == Nz::PixelFormatInfo::ComputeSize(gif.GetPixelFormat(), size.x, size.y, 1));
|
||||
REQUIRE(std::memcmp(frameData.data(), referenceImage.GetConstPixels(), frameData.size()) == 0);
|
||||
}
|
||||
|
||||
SCENARIO("Streamed images", "[Utility][ImageStream]")
|
||||
{
|
||||
std::vector<Nz::UInt8> frameData;
|
||||
|
||||
struct ExpectedFrame
|
||||
{
|
||||
std::shared_ptr<Nz::Image> referenceImage;
|
||||
Nz::UInt64 time;
|
||||
};
|
||||
|
||||
std::filesystem::path resourcePath = GetAssetDir();
|
||||
|
||||
WHEN("Loading GIF files")
|
||||
{
|
||||
GIVEN("canvas_bgnd.gif")
|
||||
{
|
||||
std::array expectedFrames = {
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_bgnd/0.png"),
|
||||
0
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_bgnd/1.png"),
|
||||
1000
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_bgnd/2.png"),
|
||||
2000
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_bgnd/3.png"),
|
||||
3000
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_bgnd/4.png"),
|
||||
4000
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<Nz::ImageStream> gif = Nz::ImageStream::OpenFromFile(resourcePath / "Utility/GIF/canvas_bgnd.gif");
|
||||
REQUIRE(gif);
|
||||
|
||||
Nz::Vector2ui size = gif->GetSize();
|
||||
CHECK(size == Nz::Vector2ui(100, 100));
|
||||
CHECK(gif->GetFrameCount() == expectedFrames.size());
|
||||
CHECK(gif->GetPixelFormat() == Nz::PixelFormat::RGBA8);
|
||||
|
||||
frameData.resize(Nz::PixelFormatInfo::ComputeSize(gif->GetPixelFormat(), size.x, size.y, 1));
|
||||
|
||||
// Decode all frames in order
|
||||
Nz::UInt64 frameTime;
|
||||
for (ExpectedFrame& expectedFrame : expectedFrames)
|
||||
{
|
||||
REQUIRE(expectedFrame.referenceImage);
|
||||
REQUIRE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
|
||||
CHECK(frameTime == expectedFrame.time);
|
||||
|
||||
CompareFrames(*gif, frameData, *expectedFrame.referenceImage);
|
||||
}
|
||||
|
||||
// Decoding the post-the-end frame fails but gives the end frametime
|
||||
REQUIRE_FALSE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
CHECK(frameTime == 5000);
|
||||
|
||||
// Decode frames in arbitrary order, to ensure results are corrects
|
||||
for (std::size_t frameIndex : { 2, 0, 3, 1, 4 })
|
||||
{
|
||||
INFO("Decoding frame " << frameIndex);
|
||||
|
||||
ExpectedFrame& expectedFrame = expectedFrames[frameIndex];
|
||||
gif->Seek(frameIndex);
|
||||
|
||||
REQUIRE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
CHECK(frameTime == expectedFrame.time);
|
||||
|
||||
CompareFrames(*gif, frameData, *expectedFrame.referenceImage);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("canvas_prev.gif")
|
||||
{
|
||||
std::array expectedFrames = {
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_prev/0.png"),
|
||||
0
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_prev/1.png"),
|
||||
100
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_prev/2.png"),
|
||||
1100
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_prev/3.png"),
|
||||
2100
|
||||
},
|
||||
ExpectedFrame{
|
||||
Nz::Image::LoadFromFile(resourcePath / "Utility/GIF/canvas_prev/4.png"),
|
||||
3100
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<Nz::ImageStream> gif = Nz::ImageStream::OpenFromFile(resourcePath / "Utility/GIF/canvas_prev.gif");
|
||||
REQUIRE(gif);
|
||||
|
||||
Nz::Vector2ui size = gif->GetSize();
|
||||
CHECK(size == Nz::Vector2ui(100, 100));
|
||||
CHECK(gif->GetFrameCount() == expectedFrames.size());
|
||||
CHECK(gif->GetPixelFormat() == Nz::PixelFormat::RGBA8);
|
||||
|
||||
frameData.resize(Nz::PixelFormatInfo::ComputeSize(gif->GetPixelFormat(), size.x, size.y, 1));
|
||||
|
||||
// Decode all frames in order
|
||||
Nz::UInt64 frameTime;
|
||||
for (ExpectedFrame& expectedFrame : expectedFrames)
|
||||
{
|
||||
REQUIRE(expectedFrame.referenceImage);
|
||||
REQUIRE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
|
||||
CHECK(frameTime == expectedFrame.time);
|
||||
|
||||
CompareFrames(*gif, frameData, *expectedFrame.referenceImage);
|
||||
}
|
||||
|
||||
// Decoding the post-the-end frame fails but gives the end frametime
|
||||
REQUIRE_FALSE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
CHECK(frameTime == 4100);
|
||||
|
||||
// Decode frames in arbitrary order, to ensure results are corrects
|
||||
for (std::size_t frameIndex : { 2, 0, 3, 1, 4 })
|
||||
{
|
||||
INFO("Decoding frame " << frameIndex);
|
||||
|
||||
ExpectedFrame& expectedFrame = expectedFrames[frameIndex];
|
||||
gif->Seek(frameIndex);
|
||||
|
||||
REQUIRE(gif->DecodeNextFrame(frameData.data(), &frameTime));
|
||||
CHECK(frameTime == expectedFrame.time);
|
||||
|
||||
CompareFrames(*gif, frameData, *expectedFrame.referenceImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
tests/UnitTests/Engine/Utility/MeshLoading.cpp
Normal file
51
tests/UnitTests/Engine/Utility/MeshLoading.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path GetAssetDir();
|
||||
|
||||
SCENARIO("Meshes", "[Utility][Mesh]")
|
||||
{
|
||||
WHEN("Loading OJB files")
|
||||
{
|
||||
GIVEN("Spaceship/spaceship.obj")
|
||||
{
|
||||
std::shared_ptr<Nz::Mesh> spaceship = Nz::Mesh::LoadFromFile(GetAssetDir() / "Utility/Spaceship/spaceship.obj");
|
||||
REQUIRE(spaceship);
|
||||
|
||||
CHECK(!spaceship->IsAnimable());
|
||||
CHECK(spaceship->GetSubMeshCount() == 2);
|
||||
CHECK(spaceship->GetMaterialCount() == 2);
|
||||
CHECK(spaceship->GetTriangleCount() == 6814);
|
||||
CHECK(spaceship->GetVertexCount() == 8713);
|
||||
}
|
||||
|
||||
GIVEN("SpaceStation/space_station.obj")
|
||||
{
|
||||
std::shared_ptr<Nz::Mesh> spacestation = Nz::Mesh::LoadFromFile(GetAssetDir() / "Utility/SpaceStation/space_station.obj");
|
||||
REQUIRE(spacestation);
|
||||
|
||||
CHECK(!spacestation->IsAnimable());
|
||||
CHECK(spacestation->GetSubMeshCount() == 1);
|
||||
CHECK(spacestation->GetMaterialCount() == 1);
|
||||
CHECK(spacestation->GetTriangleCount() == 422);
|
||||
CHECK(spacestation->GetVertexCount() == 516);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Loading MD2 files")
|
||||
{
|
||||
GIVEN("drfreak.md2")
|
||||
{
|
||||
std::shared_ptr<Nz::Mesh> drfreak = Nz::Mesh::LoadFromFile(GetAssetDir() / "Utility/drfreak/drfreak.md2");
|
||||
CHECK(drfreak);
|
||||
|
||||
CHECK(!drfreak->IsAnimable()); //< non-skeletal animations are not supported
|
||||
CHECK(drfreak->GetSubMeshCount() == 1);
|
||||
CHECK(drfreak->GetMaterialCount() == 1);
|
||||
CHECK(drfreak->GetTriangleCount() == 593);
|
||||
CHECK(drfreak->GetVertexCount() == 496);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user