Various implementations in FmtFormatter + tests
This commit is contained in:
177
tests/Extensions/FmtFormatterTest.cpp
Normal file
177
tests/Extensions/FmtFormatterTest.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "Extensions/FmtFormatter.hpp"
|
||||
|
||||
using namespace OpenVulkano;
|
||||
using namespace OpenVulkano::Math;
|
||||
|
||||
TEST_CASE("GLM Vector Formatters", "[fmt]")
|
||||
{
|
||||
SECTION("Vector2f")
|
||||
{
|
||||
Vector2f v(1.2345f, 2.3456f);
|
||||
CHECK(fmt::format("{}", v) == "(1.2345, 2.3456)");
|
||||
CHECK(fmt::format("{:.2f}", v) == "(1.23, 2.35)");
|
||||
}
|
||||
|
||||
SECTION("Vector3f")
|
||||
{
|
||||
Vector3f v(1.2345f, 2.3456f, 3.4567f);
|
||||
CHECK(fmt::format("{}", v) == "(1.2345, 2.3456, 3.4567)");
|
||||
CHECK(fmt::format("{:.2f}", v) == "(1.23, 2.35, 3.46)");
|
||||
}
|
||||
|
||||
SECTION("Vector4f")
|
||||
{
|
||||
Vector4f v(1.2345f, 2.3456f, 3.4567f, 4.5678f);
|
||||
CHECK(fmt::format("{}", v) == "(1.2345, 2.3456, 3.4567, 4.5678)");
|
||||
CHECK(fmt::format("{:.2f}", v) == "(1.23, 2.35, 3.46, 4.57)");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("GLM Matrix Formatters", "[fmt]")
|
||||
{
|
||||
SECTION("Matrix2f")
|
||||
{
|
||||
Matrix2f m = Matrix2f(1.0f);
|
||||
CHECK(fmt::format("{}", m) == "[[1, 0], [0, 1]]");
|
||||
CHECK(fmt::format("{:.1f}", m) == "[[1.0, 0.0], [0.0, 1.0]]");
|
||||
}
|
||||
|
||||
SECTION("Matrix3f")
|
||||
{
|
||||
Matrix3f m = Matrix3f(1.0f);
|
||||
CHECK(fmt::format("{}", m) == "[[1, 0, 0], [0, 1, 0], [0, 0, 1]]");
|
||||
CHECK(fmt::format("{:.1f}", m) == "[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]");
|
||||
}
|
||||
|
||||
SECTION("Matrix4f")
|
||||
{
|
||||
Matrix4f m = Matrix4f(1.0f);
|
||||
CHECK(fmt::format("{}", m) == "[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]");
|
||||
CHECK(fmt::format("{:.1f}", m) == "[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("GLM Quaternion Formatter", "[fmt]")
|
||||
{
|
||||
QuaternionF q(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
CHECK(fmt::format("{}", q) == "(1, 0, 0, 0)");
|
||||
CHECK(fmt::format("{:.2f}", q) == "(1.00, 0.00, 0.00, 0.00)");
|
||||
}
|
||||
|
||||
TEST_CASE("Range Formatter", "[fmt]")
|
||||
{
|
||||
Math::Range<float> range(1.2345f, 2.3456f);
|
||||
CHECK(fmt::format("{}", range) == "[1.2345, 2.3456]");
|
||||
CHECK(fmt::format("{:.2f}", range) == "[1.23, 2.35]");
|
||||
}
|
||||
|
||||
TEST_CASE("Color Format Formatters", "[fmt]")
|
||||
{
|
||||
SECTION("RGB565")
|
||||
{
|
||||
RGB565 color;
|
||||
color.r = 31;
|
||||
color.g = 63;
|
||||
color.b = 31;
|
||||
CHECK(fmt::format("{}", color) == "RGB565(r:31, g:63, b:31)");
|
||||
}
|
||||
|
||||
SECTION("RGBA5551")
|
||||
{
|
||||
RGBA5551 color;
|
||||
color.r = 31;
|
||||
color.g = 31;
|
||||
color.b = 31;
|
||||
color.a = 1;
|
||||
CHECK(fmt::format("{}", color) == "RGBA5551(r:31, g:31, b:31, a:1)");
|
||||
}
|
||||
|
||||
SECTION("RGB10A2")
|
||||
{
|
||||
RGB10A2U color;
|
||||
color.r = 1023;
|
||||
color.g = 1023;
|
||||
color.b = 1023;
|
||||
color.a = 3;
|
||||
CHECK(fmt::format("{}", color) == "RGB10A2(r:1023, g:1023, b:1023, a:3)");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("DenseVector3i Formatter", "[fmt]")
|
||||
{
|
||||
DenseVector3i<int32_t, false, true, 10> vec(1, 2, 3);
|
||||
CHECK(fmt::format("{}", vec) == "DenseVector3i(1, 2, 3)");
|
||||
}
|
||||
|
||||
TEST_CASE("Timestamp Formatter", "[fmt]")
|
||||
{
|
||||
Timestamp ts((uint64_t)1000000);
|
||||
CHECK(fmt::format("{}", ts) == "1000000ns");
|
||||
}
|
||||
|
||||
TEST_CASE("Numeric Type Formatters", "[fmt]")
|
||||
{
|
||||
SECTION("float16")
|
||||
{
|
||||
float16 f(1.5f);
|
||||
std::string formatted = fmt::format("{}", f);
|
||||
CHECK((formatted == "1.5" || formatted == "1.500000"));
|
||||
CHECK(fmt::format("{:.1f}", f) == "1.5");
|
||||
}
|
||||
|
||||
SECTION("int24")
|
||||
{
|
||||
OpenVulkano::int24 i(1000);
|
||||
CHECK(fmt::format("{}", i) == "1000");
|
||||
}
|
||||
|
||||
SECTION("uint24")
|
||||
{
|
||||
OpenVulkano::uint24 u(1000);
|
||||
CHECK(fmt::format("{}", u) == "1000");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ByteSize Formatter", "[fmt]")
|
||||
{
|
||||
SECTION("1000 bytes")
|
||||
{
|
||||
ByteSize size(1000);
|
||||
CHECK(fmt::format("{}", size) == "1e+03 B");
|
||||
}
|
||||
|
||||
SECTION("1024 bytes (1 kiB)")
|
||||
{
|
||||
ByteSize size(1024);
|
||||
CHECK(fmt::format("{}", size) == "1 kiB");
|
||||
}
|
||||
|
||||
SECTION("1 mebibyte")
|
||||
{
|
||||
ByteSize size(1024 * 1024);
|
||||
CHECK(fmt::format("{}", size) == "1 MiB");
|
||||
}
|
||||
|
||||
SECTION("Using unit constructors")
|
||||
{
|
||||
CHECK(fmt::format("{}", ByteSize(1, ByteSizeUnit(ByteSizeUnit::kiB))) == "1 kiB");
|
||||
CHECK(fmt::format("{}", ByteSize(1, ByteSizeUnit(ByteSizeUnit::MiB))) == "1 MiB");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("UUID Formatter", "[fmt]")
|
||||
{
|
||||
UUID uuid = GenerateTimePrefixedCustomUUID();
|
||||
std::string formatted = fmt::format("{}", uuid);
|
||||
CHECK(formatted.length() == 36);
|
||||
CHECK(formatted.find('-') != std::string::npos);
|
||||
}
|
||||
Reference in New Issue
Block a user